var conObj = {0:new Array(),1:new Array(),2:new Array()};
var stp = 0;

conObj[0].ag = jQuery.pureology.gup('ag'); // age
conObj[0].of = jQuery.pureology.gup('of'); // often color
conObj[0].ep = jQuery.pureology.gup('ep'); // ethnic profile
conObj[1].hc = jQuery.pureology.gup('hc'); // hair condition
conObj[1].pn = jQuery.pureology.gup('pn'); // primary need
conObj[2].dr = jQuery.pureology.gup('dr'); // desired result
conObj[2].hd = jQuery.pureology.gup('hd'); // hold desired

run(jQuery.pureology.consultation);

jQuery('.con_next').click(function() {
	nextClick(false);
	return false;
});

jQuery('.con_sub').click(function() {
	nextClick(true);
	return false;
});

jQuery('.con_prev').click(function() {
	showPrev();
	return false;
});

function nextClick(sub) {
	var qs=0,as=0;
	jQuery('.con_'+stp).find('.question').each(function() {
		qs++;
		jQuery(this).find('input').each(function() {
			if (jQuery(this).attr('checked')) {
				conObj[stp][jQuery(this).attr("name")] = jQuery(this).attr("value");
				as++;
			};
		});
	});
	if (as < qs) {
		jQuery('.con_'+stp).find('.con_err').show('fast');
		return false;
	}
	jQuery('.con_'+stp).find('.con_err').hide();
	if (!sub) {
		showNext();
	} else {
		submitQuery();
	}
	return false;
}

function chkUrlValues() {
	jQuery('.con_'+stp).find('.question').each(function(){
		jQuery(this).find('input[value='+conObj[stp][(jQuery(this).find('input:first').attr('name'))]+']').attr('checked','true');
	});
}

function showPrev() {
	jQuery('.con_'+stp).hide();
	stp--;
	chkUrlValues()
	jQuery('.con_'+stp).show();
}

function showNext() {
	jQuery('.con_'+stp).hide();
	stp++;
	chkUrlValues()
	jQuery('.con_'+stp).show();
}

function submitQuery() {
	var query='',first=true;
	for (i=0;i<3;i++) {
		for (q in conObj[i]) {
			if(!first) query += '&';
			query += q+'='+conObj[i][q];
			first = false;
		}
	}
	window.location = '/consultation/results.aspx?'+query;
}

/*
	for (q in conObj[stp]) {
		jQuery('.con_'+stp).find('input[name='+q+'][value='+conObj[stp][q]+']').attr('checked');
	}
*/