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_add(type){
	var err_found = false;
	var err_msg = "\n\nto continue, please complete the highlighted entries:\n\n";


	// first let's call some xajax to validate the abp_id
	//xajax_Misc.validateABPCode( document.getElementById('abp_id').value );
	// this sets an innerHTML for id abp_check_results
	// so get that value and proceed from there
	var abp_result	= document.getElementById('abp_check_result').value;
	if (abp_result == "0"){
		err_found = true;
	}

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

	switch (type){
	case "purchase_esap":
		var required_inputs = new Array(
			'first_name',
			'last_name',
			'email',
			'password_do_purchase',
			'street',
			'city',
			'state',
			'zip',
			'age',
			'gender',
			'education_level_id',
			'occupation_id',
			'income_range_id',
			'ethnicity_id',
			'nationality',
			'cc_number',
			'cc_exp_month',
			'cc_exp_year',
			'phone',
			'organization',
			'abp_id'
		);
		if(document.getElementById('ethnicity_id').value == "8"){
		required_inputs[required_inputs.length]	= 'ethnicity_other';
		}

		break;
	case "login":
		var required_inputs = new Array(
			'username',
			'password'
		);

		break;
	
	}
		

	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;
		}
	}

	if (type=="purchase_esap"){
		// verify emails match shall we
		var input1 = document.getElementById('email');
		var input2 = document.getElementById('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 = '';
		}

	
		var input3 = document.getElementById('password_do_purchase');
		var input4 = document.getElementById('password2');
		if(input3.value != "" && (input3.value != input4.value) ) {
			err_found = true;
			err_msg += "** ALSO - please ensure your passwords match";
			input3.style.backgroundColor = background_color;
			input3.style.borderColor = border_color;
			input3.style.borderWidth = border_width;
			input4.style.backgroundColor = background_color;
			input4.style.borderColor = border_color;
			input4.style.borderWidth = border_width;
		} else {
			if(input3.value != ""){
				input3.style.backgroundColor = '';
				input3.style.borderColor = '';
				input3.style.borderWidth = '';
			}
			input4.style.backgroundColor = '';
			input4.style.borderColor = '';
			input4.style.borderWidth = '';
		}
	
	
	
	}

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

		/// ## OK,now we show a verification screen as needed
		switch (type){
		case "purchase_esap":
			// get values for verfication
			var entry_ids	= new Array(
				'first_name',
				'last_name',
				'email',
				'street',
				'city',
				'state',
				'zip',
				'age',
				'gender',
				'education_level_id',
				'occupation_id',
				'income_range_id',
				'ethnicity_id',
				'nationality',
				'cc_number',
				'cc_exp_month',
				'cc_exp_year',
				'phone',
				'organization',
				'abp_id'
				);
				

				var the_value		= "";
				var values_array	= "";
				for (i=0;i<entry_ids.length;i++){
					the_value = document.getElementById(entry_ids[i]).value;

					if(
						entry_ids[i]	== "education_level_id" ||
						entry_ids[i] == "ethnicity_id"  ||
						entry_ids[i] == "occupation_id" ||
						entry_ids[i] == "income_range_id"
						){
						values_array	= the_value.split(":::");
						the_value		= values_array[1];
					}
					
					document.getElementById('verify_'+entry_ids[i]).innerHTML = the_value;
				}

			// hide n unhide necessary stuff

			document.getElementById('purchase_esap_input').style.display = "none";
			document.getElementById('purchase_esap_verify').style.display = "";
			$('#process_purchase').val('true');
			document.go_buy_esap.action = "purchase.php";
			break;
		default:
			//alert('submit');
			//document.form.name.submit();
			return true;
			break;
		}
	}
}
function fix_esap_purchase(){
	document.getElementById('purchase_esap_input').style.display = "";
	document.getElementById('purchase_esap_verify').style.display = "none";
}

function input_test(who){
	switch (who){
	case "e":
		document.getElementById('first_name').value	= "Rick";
		document.getElementById('last_name').value	= "Hammett";
		document.getElementById('email').value	= "rick@eitri.org";
		document.getElementById('email2').value	= "rick@eitri.org";
		document.getElementById('street').value	= "PO Box 271877";
		document.getElementById('city').value	= "Corpus Christi";
		document.getElementById('state').value	= "TX";
		document.getElementById('zip').value	= "78427-1877";
		document.getElementById('age').value	= "";
		document.getElementById('gender').value	= "Male";
		document.getElementById('education_level_id').value	= "5:::Master\'s degree";
		document.getElementById('occupation_id').value	= "6:::President";
		document.getElementById('ethnicity_id').value	= "6:::White";
		document.getElementById('nationality').value	= "";
		document.getElementById('cc_number').value	= "4111111111111111";
		document.getElementById('cc_exp_month').value	= "10";
		document.getElementById('cc_exp_year').value	= "10";
		document.getElementById('phone').value	= "1-888-680-7983";
		document.getElementById('organization').value	= "EI Learning Systems, Inc.";
		break;
	case "r":
		document.getElementById('first_name').value	= "Rick";
		document.getElementById('last_name').value	= "Forristall";
		document.getElementById('email').value	= "rick@4in10.com";
		document.getElementById('email2').value	= "rick@4in10.com";
		document.getElementById('street').value	= "18892 S 186th Dr.";
		document.getElementById('city').value	= "Queen Creek";
		document.getElementById('state').value	= "AZ";
		document.getElementById('zip').value	= "85142";
		document.getElementById('age').value	= "48";
		document.getElementById('gender').value	= "Male";
		document.getElementById('education_level_id').value	= "5:::Master\'s degree";
		document.getElementById('occupation_id').value	= "6:::President";
		document.getElementById('ethnicity_id').value	= "6:::White";
		document.getElementById('nationality').value	= "Irish";
		document.getElementById('cc_number').value	= "4111111111111111";
		document.getElementById('cc_exp_month').value	= "10";
		document.getElementById('cc_exp_year').value	= "10";
		document.getElementById('phone').value	= "480.656.8923";
		document.getElementById('organization').value	= "4 in 10 Enterprises, LLC";
		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(){


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


});
function get_client_esps_4_ABP() {
	$("#processing_abp_esaps").show('slow');
	xajax_ESAP.getClientESAPsForABP( $('#user_guid_4_esps').val() );
	//alert($('#user_guid').val()) ;

}
function get_client_4_vp() {
	$("#processing_client_vp").show('slow');
	xajax_User.getClientForVP($("#user_guid_4_vp").val() );
	//alert($('#user_guid').val()) ;

}
function set_client_vp_option() {
	$("#processing_client_vp_update").show('slow');
	xajax_User.setClientVPOption($("#vp_edit_user_guid").val(), $("#view_print_option_id").val() );
	//alert($('#user_guid').val()) ;
}

function set_my_own_vp_option() {
	$("#processing_my_own_vp_update").show('slow');
	xajax_User.setMyOwnVPOption( $("#my_own_print_option_id").val() );
	//alert($('#user_guid').val()) ;
}

function set_abp_default_vp_option() {
	$("#processing_default_vp_update").show('slow');
	xajax_User.setABPDefaultVPOption($("#default_vp_option_id").val() );
	//alert($('#user_guid').val()) ;
}

