function view1_order(order_id){
	switch (order_id){
	case "none":
		$(".order_row2").fadeOut('fast');
		break;
	case "all":
		$(".order_row2").fadeIn('fast');
		break;
	default:
		//$("#order_" + order_id + "_1a").slideDown();
		$(".order_row2").fadeOut('fast');
		$("#order_" + order_id + "_2").fadeIn();
		break;
	
	}
	if (order_id == "all"){
	} else {

	}
}
function do_process(){
	$("#go_status").html('<b style="font-size:20px">processing ... please wait</b>');
	xajax_Purchase.process(xajax.getFormValues('order_entry_form') )
}

function shipping_is_billing(is_true) {
	if (is_true == "yes"){
		$("#shipping_first_name").val( $("#billing_first_name").val() );
		$("#shipping_last_name").val( $("#billing_last_name").val() );
		$("#shipping_street").val( $("#billing_street").val() );
		$("#shipping_city").val( $("#billing_city").val() );
		$("#shipping_state").val( $("#billing_state").val() );
		$("#shipping_zip").val( $("#billing_zip").val() );
	} else {
		$(".shipping_info").val('');
	}
	
}

function prep_order(id){
	// calc item subtotal
	var item_subtotal = "";
	var qty			= parseFloat( $("#qty_" + id).val() );
	var price		= parseFloat( $("#price_" + id).val() );
	item_subtotal1	= qty * price;
	item_subtotal	= item_subtotal1.toFixed(2);

	// now let's display the item subtotal on order form
	$("#item_subtotal_" + id).text(item_subtotal);

	// need to calculate order subtotal now
	// we get the values of all the item subtotals and sum them

	var current_order_total	= parseFloat( $("#order_total_value").val()  );
	var new_order_total		= current_order_total + item_subtotal1;
	$("#order_total_value").val(new_order_total);
	$("#ordertotal_view").text( new_order_total.toFixed(2) );
	$("#subtotal_view").text( new_order_total.toFixed(2) );



	// we need to check and see the total number of ordered items
	// if it's >= 6, then we need to do some price reductions
	var total_quantity = parseFloat( $("#total_quantity").val() );
	var new_quantity	= total_quantity + qty;
	$("#total_quantity").val(new_quantity);

	if (new_quantity >= 6){
		$(".price_value").val('3.50');
		$(".price_view").text('3.50');
	} else {
		$(".price_value").val('5.00');
		$(".price_view").text('5.00');

	}
}






















function can_we_pay(invoice_id){
	var required_inputs = new Array(
		'check_date_' + invoice_id,
		'check_number_' + invoice_id
	);
	var err_found = false;

	err_found = validate_cycle(required_inputs);


	if (err_found) {

		$('#btn_pay_' + invoice_id).addClass('esap_button_small_disabled');
		$('#btn_pay_' + invoice_id).removeClass('esap_button_small');
		$('#btn_pay_' + invoice_id).attr('disabled','disabled');

	} else {
		
		$('#btn_pay_' + invoice_id).addClass('esap_button_small');
		$('#btn_pay_' + invoice_id).removeClass('esap_button_small_disabled');
		$('#btn_pay_' + invoice_id).attr('disabled','');

	}
}


function get_background_color(){
	var background_color	= "#FFDA56";
	return background_color;
}
function get_border_color(){
	var border_color		= "#153F6F";
	return border_color;
}
function get_border_width(){
	var border_width		= "1px";
	return border_width;
	
}
function validate_cycle(required_inputs){

	var background_color	= get_background_color();
	var border_color		= get_border_color();
	var border_width		= get_border_width();

	var err_found = false;
	for (i=0;i<required_inputs.length;i++){
		document.getElementById(required_inputs[i]).style.backgroundColor = '';
		document.getElementById(required_inputs[i]).style.borderColor = '';
		document.getElementById(required_inputs[i]).style.borderWidth = '';
	}
	for (i=0;i<required_inputs.length;i++)
	{
		if (document.getElementById(required_inputs[i]).value == "") {
			err_found = true;
			document.getElementById(required_inputs[i]).style.backgroundColor = background_color;
			document.getElementById(required_inputs[i]).style.borderColor = border_color;
			document.getElementById(required_inputs[i]).style.borderWidth = border_width;
		}
	}
	
	return err_found;
}


function validate_generate_invoice(){

	var required_inputs = new Array(
		'user_guid',
		'esap_invoice_month',
		'esap_invoice_year'
	);
	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";

	err_found = validate_cycle(required_inputs);


	if (err_found) {

		$('#btn_generate_invoice').addClass('esap_button_disabled');
		$('#btn_generate_invoice').removeClass('esap_button');
		$('#btn_generate_invoice').attr('disabled','disabled');

	} else {
		
		$('#btn_generate_invoice').addClass('esap_button');
		$('#btn_generate_invoice').removeClass('esap_button_disabled');
		$('#btn_generate_invoice').attr('disabled','');

	}

}






function verify_refer_it(){

	var required_inputs = new Array(
		'refer_name',
		'refer_email'
	);
	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";

	err_found = validate_cycle(required_inputs);


	if (err_found) {
		//document.getElementById('processing_' + action).style.display = "none";
		alert(err_msg);
		return false;

	} else {
		$('#get_refer_form_results').text("Sending Email ...");
		$('#get_refer_form_results').show("slow");

		xajax_User.doReferIt(xajax.getFormValues('go_refer_it') )
		//alert('do_abp_add');
	}

}





function verify_add_edit_abp(action){


	document.getElementById('processing_' + action).style.display = "";

	switch (action){
	case "edit":
		var required_inputs = new Array(
			'first_name_' + action,
			'last_name_' + action,
			'email_' + action,
			'website_' + action,
			'street_' + action,
			'city_' + action,
			'state_' + action,
			'zip_' + action,
			'phone_' + action,
			'organization_' + action,
			'view_print_option_id_' + action,
			'commission_dollars_' + action,
			'commission_cents_' + action
		);
		var next_index	= required_inputs.length;
		if (document.getElementById('new_password_edit').value != ""){ // if submitted new password
			required_inputs[next_index] = "password_edit";
		}
		break;

	
	case "add":
		var required_inputs = new Array(
			'first_name_' + action,
			'last_name_' + action,
			'email_' + action,
			'password_' + action,
			'website_' + action,
			'street_' + action,
			'city_' + action,
			'state_' + action,
			'zip_' + action,
			'phone_' + action,
			'organization_' + action,
			'commission_dollars_' + action,
			'commission_cents_' + action
		);
		break;
	
	}

	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";

	err_found = validate_cycle(required_inputs);


	if (err_found) {
		document.getElementById('processing_' + action).style.display = "none";
		alert(err_msg);
		return false;

	} else {
		switch (action){
		case "add":
			document.do_abp_add.action = "do_abp_add.php";
			xajax_User.createABP(xajax.getFormValues('do_abp_add') )
			//document.do_abp_add.submit();
			//return true;
			//return false;
			//alert('do_abp_add');
			break;
		case "edit":
			document.do_abp_edit.action = "do_abp_add.php";
			xajax_User.updateABP(xajax.getFormValues('do_abp_edit') )
			//document.do_abp_edit.submit();
			//return true;
			//return false;
			//alert('do_abp_edit');
			break;
		
		}
	}

}
function verify_login(){

	document.getElementById('checking_login').style.display = "";


	var required_inputs = new Array(
		'email',
		'password'
	);
	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";

	err_found = validate_cycle(required_inputs);


	if (err_found) {
		document.getElementById('checking_login').style.display = "none";
		alert(err_msg);
		return false;

	} else {
		document.do_login.action = "do_login.php";
		return true;
		//document.do_login.submit();
	}
}

function do_ie_adjust(passed_version) {
	document.getElementById('sublink_about').style.top = "21px";
	document.getElementById('sublink_candidates').style.top = "21px";
	document.getElementById('sublink_clients').style.top = "21px";
	if( passed_version == "MSIE 6.0" ) {
		alert('passed: '+passed_version);

		document.getElementById('main_nav_holder').style.height = "28px";
		document.getElementById('main_nav').style.height = "24px";
	} else {
		document.getElementById('main_nav_holder').style.height = "28px";
		document.getElementById('main_nav').style.height = "28px";

	}
}

function zinko9(ba,aa,ap,dl,st,by){
	var a,b,c,aaa,ppp,ds,db,e
	//ba=stuff before the <at>;  //aa=stuff after the <at>;  //ap=stuff after the <period>
	//dl=text to display as link;  //st=subject in case you want to predefine it
	//by=body in case you want to predefine it
	a = '<a href=\"mai'
	c = '\">'
	aaa = '@'
	ppp = '.'
	if (st){
		ds = '?sub'
		ds += 'ject=\''
		ds += st+'\''
		} else {
		ds = ''
	}
	if (by){
		db = '&bo'
		db += 'dy=\''
		db += by+'\''
		} else {
		db = ''
	}
	a += 'lto:'
	a += ba
	a += aaa
	a += aa
	a += ppp
	a += ap
	e='</a>'
	b += aa
	b += '.'
	b += ap
	if (!dl) {
		dl = ba+aaa+aa+ppp+ap
	}
	//document.write(a+ds+db+c+dl+e)

	var zookie9 = a+ds+db+c+dl+e; 
	return zookie9;

///// *********************************////
/// -- DON'T EDIT ANYTHING ABOVE HERE ---//
///// *********************************////

// instructions - inside each '' pair in the zinko9('','','','','',''); below enter
//   first '' pair: the stuff before the <at> symbol in your email address
//   second '' pair: the stuff after the <at> symbol in your email address
//   third '' pair: the stuff after the first <period> in your email address
//   fourth '' pair: what you want as the displayed link - leave blank and your email address will be link
//   fifth '' pair: if you want to have an automatic subject - enter here - otherwise leave the ''
//   sixth '' pair: if you want to have an automatic body - enter here - otherwise leave the ''
// sample below:
// zinko9('your.name','DomainName','net','Your Name','this is the subject','this is the body');
}


function reset_cs(){
	var q_ids	= new Array(
			'manual',
			'e_checks',
			'needle',
			'redflag',
			'msds',
			'training',
			'posters',
			'hepb'
		);

	for (i=0;i<q_ids.length ;i++ ){
		document.getElementById(q_ids[i]+'_y').style.borderColor	= ""
		document.getElementById(q_ids[i]+'_y').style.backgroundColor = "";
		document.getElementById(q_ids[i]+'_y').style.padding		= ""
		document.getElementById(q_ids[i]+'_y').style.borderWidth	= ""
		document.getElementById(q_ids[i]+'_y').style.borderStyle	= ""

		document.getElementById(q_ids[i]+'_n').style.borderColor	= ""
		document.getElementById(q_ids[i]+'_n').style.backgroundColor = "";
		document.getElementById(q_ids[i]+'_n').style.padding		= ""
		document.getElementById(q_ids[i]+'_n').style.borderWidth	= ""
		document.getElementById(q_ids[i]+'_n').style.borderStyle	= ""
	}
	document.getElementById('cs_needed').style.display = "none";

}
function check_cs(answer,passed_id){
	var q_ids	= new Array(
			'manual',
			'e_checks',
			'needle',
			'redflag',
			'msds',
			'training',
			'posters',
			'hepb'
		);

	switch (answer){
	case "n":
		document.getElementById(passed_id+'_no').value = "true";

		document.getElementById(passed_id+'_n').style.backgroundColor = "yellow";
		document.getElementById(passed_id+'_n').style.padding		= "1px"
		document.getElementById(passed_id+'_n').style.borderWidth	= "2px"
		document.getElementById(passed_id+'_n').style.borderStyle	= "solid"
		document.getElementById(passed_id+'_n').style.borderColor	= "#4040FF"

		document.getElementById(passed_id+'_y').style.borderColor	= ""
		document.getElementById(passed_id+'_y').style.backgroundColor = "";
		document.getElementById(passed_id+'_y').style.padding		= ""
		document.getElementById(passed_id+'_y').style.borderWidth	= ""
		document.getElementById(passed_id+'_y').style.borderStyle	= ""
		break;
	case "y":
		document.getElementById(passed_id+'_no').value = "false";

		document.getElementById(passed_id+'_y').style.backgroundColor = "yellow";
		document.getElementById(passed_id+'_y').style.padding		= "1px"
		document.getElementById(passed_id+'_y').style.borderWidth	= "2px"
		document.getElementById(passed_id+'_y').style.borderStyle	= "solid"
		document.getElementById(passed_id+'_y').style.borderColor	= "#4040FF"

		document.getElementById(passed_id+'_n').style.borderColor	= ""
		document.getElementById(passed_id+'_n').style.backgroundColor = "";
		document.getElementById(passed_id+'_n').style.padding		= ""
		document.getElementById(passed_id+'_n').style.borderWidth	= ""
		document.getElementById(passed_id+'_n').style.borderStyle	= ""
		break;
	}

	var any_nos	= false;

	for (i=0;i<q_ids.length ;i++ ){
		if (document.getElementById(q_ids[i]+'_no').value == "true"){
			any_nos = true;
		}
	}
	if (any_nos){
		document.getElementById('cs_needed').style.display = "";
	} else {
		document.getElementById('cs_needed').style.display = "none";
	}

}



/* ////////////////////////////////////////////////////////////////// */


function verify_order(){
	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";


	var border_color		= "#153F6F";
	var border_width		= "1px";
	var background_color	= "#FFDA56";

	var required_inputs = new Array(
		'billing_first_name',
		'billing_last_name',
		'billing_email',
		'billing_street',
		'billing_city',
		'billing_state',
		'billing_zip',
		'cc_number',
		'cc_exp_month',
		'cc_exp_year',
		'billing_phone',
		'shipping_first_name',
		'shipping_last_name',
		'shipping_street',
		'shipping_city',
		'shipping_state',
		'shipping_zip'
	);
		

	for (i=0;i<required_inputs.length;i++){
		document.getElementById(required_inputs[i]).style.backgroundColor = '';
		document.getElementById(required_inputs[i]).style.borderColor = '';
		document.getElementById(required_inputs[i]).style.borderWidth = '';
	}
	for (i=0;i<required_inputs.length;i++)
	{
		if (document.getElementById(required_inputs[i]).value == "") {
			err_found = true;
			document.getElementById(required_inputs[i]).style.backgroundColor = background_color;
			document.getElementById(required_inputs[i]).style.borderColor = border_color;
			document.getElementById(required_inputs[i]).style.borderWidth = border_width;
		}
	}

	// verify emails match shall we
	var input1 = document.getElementById('billing_email');
	var input2 = document.getElementById('billing_email2');

	if(input1.value != "" && (input1.value != input2.value) ) {
		err_found = true;
		err_msg += "** ALSO - please ensure your emails match";
		input1.style.backgroundColor = background_color;
		input1.style.borderColor = border_color;
		input1.style.borderWidth = border_width;
		input2.style.backgroundColor = background_color;
		input2.style.borderColor = border_color;
		input2.style.borderWidth = border_width;
	} else {
		if(input1.value != ""){
			input1.style.backgroundColor = '';
			input1.style.borderColor = '';
			input1.style.borderWidth = '';
		}
		input2.style.backgroundColor = '';
		input2.style.borderColor = '';
		input2.style.borderWidth = '';
	}

	
	
	

	if (err_found) {
		alert(err_msg);
		return false;
	} else {

		/// ## OK,now we show a verification screen as needed
				
		$("#verify_billing_name").html( $("#billing_first_name").val() + ' ' + $("#billing_last_name").val() );
		$("#verify_billing_email").html( $("#billing_email").val() );
		$("#verify_billing_address").html( $("#billing_street").val() + '<br />' + $("#billing_city").val() + ', ' +  $("#billing_state").val() + ' ' +  $("#billing_zip").val() );
		$("#verify_cc_number").html( $("#cc_number").val() );
		$("#verify_cvv").html( $("#cvv_number").val() );
		$("#verify_expiration").html( '<b>MONTH:</b> ' + $("#cc_exp_month").val() + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>YEAR:</b> ' + $("#cc_exp_year").val());
		$("#verify_phone").html( $("#billing_phone").val() );

		$("#verify_shipping_name").html( $("#shipping_first_name").val() + ' ' + $("#shipping_last_name").val() );
		$("#verify_shipping_address").html( $("#shipping_street").val() + '<br />' + $("#shipping_city").val() + ', ' +  $("#shipping_state").val() + ' ' +  $("#shipping_zip").val() );

		
		// hide n unhide necessary stuff

		$('#table_input_billing').slideUp('fast');
		$('#table_input_shipping').slideUp('fast');
		$('#btn_verify_order').slideUp('fast');
		$('#verify_text').fadeOut();

		$('#table_input_billing_verify').fadeIn();
		$('#table_input_shipping_verify').fadeIn();
		$('#btn_fix_order').fadeIn();
		$('#btn_submit_order').fadeIn();
		$('#verify_order_text').fadeIn();

	}
}
function fix_order(){
	$('#table_input_billing').fadeIn('fast');
	$('#table_input_shipping').fadeIn('fast');
	$('#btn_verify_order').fadeIn('fast');
		$('#verify_text').fadeIn();

	$('#table_input_billing_verify').hide();
	$('#table_input_shipping_verify').hide();
	$('#btn_fix_order').hide();
	$('#btn_submit_order').hide();
	$('#verify_order_text').hide();
}

function input_test(who){
	switch (who){
	case "r":
		$('#billing_first_name').val('Rick');
		$('#billing_last_name').val("Forristall");
		$('#billing_email').val("rick@4in10.com");
		$('#billing_email2').val("rick@4in10.com");
		$('#billing_street').val("18892 S 186th Dr.");
		$('#billing_city').val("Queen Creek");
		$('#billing_state').val("AZ");
		$('#billing_zip').val("85142");
		$('#cc_number').val("4111111111111111");
		$('#cc_exp_month').val("10");
		$('#cc_exp_year').val("10");
		$('#billing_phone').val("555.555.5555");
		$('#cvv_number').val("111");
		$('#testit').html('<INPUT TYPE="HIDDEN" NAME="x_test_request" VALUE="TRUE">');
		break;
	
	}
}

function show_ethnicity_other(dowhat){
	switch (dowhat)	{
		case "show":
			document.getElementById('ethnicity_other_holder').style.display = "";
			document.getElementById('ethnicity_other').style.backgroundColor = "#D7E3F3";
			document.getElementById('ethnicity_other').focus();
			break;
		case "hide":
			document.getElementById('ethnicity_other_holder').style.display = "none";
			document.getElementById('ethnicity_other').style.backgroundColor = "";
			document.getElementById('ethnicity_other').value = "";
			break;
	}
}
function go_process_purchase(){
	document.getElementById('do_purchase_go').style.display = "none";
	document.getElementById('processing_purchase').style.display = "";
}

function process_length(p,min,max){
	//var too_short	= false;
	//var too_long	= false;
	var the_length	= "";

	if (p.length > max){
		//too_long = true;
		//too_short = false;
		the_length	= "too_long";
	}
	if (p.length < min){
		//too_short = true;
		//too_long = false;
		the_length	= "too_short";
	}

	return the_length;

}
// check_plength - multi-purpose - pass the id to manipulate
// warning tags containing too-long or too-short warnings
function check_plength(passed_id, is_new){
	if(!is_new){
		is_new = 'false';
	}

	var password_id = "";
	if (is_new == "true"){
		password_id	= "new_password_" + passed_id;
	} else {
		var password_id	= "password_" + passed_id;
	}

	var p			= document.getElementById(password_id).value;
	var min			= 8; // minimum length
	var max			= 12; // maximum length
	var the_length	= process_length(p,min,max);

	if (p.length > 0){

		if (the_length == "too_short" || the_length == "too_long")		{
				document.getElementById('btn_' + passed_id).style.display = "none";
				document.getElementById(passed_id + '_fix_password').style.display = "";
				document.getElementById('good_plength_' + passed_id).style.display = "none";
			if (the_length == "too_short"){
				document.getElementById('too_short_length_' + passed_id).style.display = "";
				document.getElementById('too_long_length_' + passed_id).style.display = "none";
			}
			if (the_length == "too_long"){
				document.getElementById('too_long_length_' + passed_id).style.display = "";
				document.getElementById('too_short_length_' + passed_id).style.display = "none";
			}
		} else {

				document.getElementById('good_plength_' + passed_id).style.display = "";
				document.getElementById('too_short_length_' + passed_id).style.display = "none";
				document.getElementById('too_long_length_' + passed_id).style.display = "none";
				document.getElementById('btn_' + passed_id).style.display = "";
				document.getElementById(passed_id + '_fix_password').style.display = "none";
		}



	}
}

function set_esap_response(selection,value){

	var selections	= new Array(
		'm',
		's',
		'l');


	for (i=0;i<selections.length;i++){
		document.getElementById('esap_response_'+selections[i]).className = "esap_response";
	}
	for (i=0;i<selections.length;i++)
	{
		if (selections[i] == selection) {
			document.getElementById('esap_response_'+selections[i]).className = "esap_response_selected";
		}
	}
	// now set the chosen response as this question's value for m, s, or l
	document.getElementById('esap_response_value').value = value;
	document.getElementById('esap_question_next').style.display = "";
		
		
}
function set_n_go_esap_question(esap_id){
	document.getElementById('esap_id').value = esap_id;
	document.get_esap_question.submit();

}


function hide_n_seek(section,show_id){

	switch (section){
	case "abps":
		var ids = new Array(
			'add_abp',
			'edit_abp',
			'archive_abp'
			);
		break;
	case "invoices":
		var ids = new Array(
			'view_paid_invoices',
			'all_unpaid_invoices_list',
			'unpaid_invoice_list'
			);
		break;

	}
	for (i=0; i < ids.length; i++ ){
		if (show_id == ids[i]){
			//document.getElementById(ids[i] + '_holder').style.display = "";
			$('#' + ids[i] + '_holder').show('slow');

		} else {
			$('#' + ids[i] + '_holder').hide('slow');
			//document.getElementById(ids[i] + '_holder').style.display = "none";
		}
	}
}

// ################## jQuery ################################

function rewrite(id,new_text){

	$(id).text(new_text);

}
// STUFF THAT AUTOMATICALLY LOADS WHEN DOC IS READY TO BE MANIPULATE
$(document).ready(function(){


	// let's load the facebox stuff
	$('a[rel*=facebox]').facebox()

	// shipping <-- billing info
	$("#same_as_billing").click(function() {
		if ( $('#same_as_billing').is(':checked') ) {
			shipping_is_billing('yes');
			//alert('checked');
		} else {
			shipping_is_billing('no');
		}
	});

	// order verification screen
	$("#same_as_billing").click(function() {
		if ( $('#same_as_billing').is(':checked') ) {
			shipping_is_billing('yes');
			//alert('checked');
		} else {
			shipping_is_billing('no');
		}
	});

	$("#testfill").click(function() {
		input_test('r');
	});

	$("#btn_fix_order").click(function() {
		fix_order();
	});

fix_order
    $('.slideshow').cycle({
		fx:			'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	    speed:		500,      // speed of the transition (any valid fx speed value) 
		timeout:	1300    // milliseconds between slide transitions (0 to disable auto advance) 

	});


	$("#aarrgg").click(function() {
		alert('here');
		//rewrite('referred_first_name_fb',$("#refer_name_fb").value);
	});


});
