// JavaScript Document

//Save the general information from the user
function save_general(){
	
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var email2 = document.getElementById('email2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var agree = document.getElementById('agree');
	var market = document.getElementById('market');
	
	if(!reStr.test(name_f.value)){
		alert('Please enter your name');
		name_f.select();
		name_f.focus();
		return false;
	}
	
	if(!reStr.test(name_l.value)){
		alert('Please enter your name');
		name_l.select();
		name_l.focus();
		return false;
	}
	
	if(!reStrAlpha.test(address1.value)){
		alert('Please enter a valid address');
		address1.select();
		address1.focus();
		return false;
		
	}
	
	if(!reStr.test(city.value)){
		
		alert('Please enter a valid city');
		city.select();
		city.focus();
		return false;
		
	}
	
	if(!reStr.test(state.value)){
		alert('Please enter a valid two letter sate code');
		state.select();
		state.focus()
		return false;
	}
	
	if(!reNumber.test(zip.value)){
		alert('Please enter a valid zip code');
		zip.select();
		zip.focus();
		return false;
		
	}
	
	if(!reEmail.test(email.value)){
		alert('Please enter a valid email address');
		email.select();
		email.focus();
		return false;
	}
	
	if(email.value != email2.value) {
	
		alert('Sorry email addresses do not match');
		email2.select();
		email2.focus();
		return false;
		
	}
	
	/*
	if(phone1.value !='' || phone2.value!='' || phone3.value != '' &&(!reNumber.test(phone1.value) || !reNumber.test(phone2.value) || !reNumber.test(phone3.value))){
		alert('Please enter a valid phone number');
		phone1.select();
		phone1.focus();
		return false;
		
	}
	*/
	
	if(agree.checked != true){ alert('You must agree to the terms before you can continue'); agree.select(); agree.focus(); }
	if(market.checked ==true) var mark = 1; else var mark = 0; if(agree.checked ==true) var ag = 1; else var ag = 0; 
	
	var query = 'name_f='+encodeURI(name_f.value)+'&name_l='+encodeURI(name_l.value)+'&address='+encodeURI(address1.value)+'&address2='+encodeURI(address2.value)+'&city='+encodeURI(city.value)+'&state='+encodeURI(state.value)+'&zip='+encodeURI(zip.value)+'&email='+encodeURI(email.value)+'&email2='+encodeURI(email2.value)+'&phone1='+encodeURI(phone1.value)+'&phone2='+encodeURI(phone2.value)+'&phone3='+encodeURI(phone3.value)+'&agree='+encodeURI(ag)+'&market='+encodeURI(mark);
	
	var file = 'modules/aj/save_user_info.php';
	ajaxCall2(file,query,'billing');

	
}

//Return to the option page
function return_options(){
	
	var file = 'modules/aj/title_list1.php';
	var query = '?return=1';
	ajaxCall(file,query,'billing');
}
//Load the credit card form
function load_credit(){
	
	var file = 'modules/aj/credit_form.php';
	var query = '';
	ajaxCall(file,query,'billing');
}

//Copy information from the general contact form to the payment info form if it all validates correctly
function copy_info(prefix){
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var new_name_f = document.getElementById(prefix+'_name_f');
	var new_name_l = document.getElementById(prefix+'_name_l');
	var new_address1 = document.getElementById(prefix+'_address');
	var new_address2 = document.getElementById(prefix+'_address2');
	var new_city = document.getElementById(prefix+'_city');
	var new_state = document.getElementById(prefix+'_state');
	var new_zip = document.getElementById(prefix+'_zip');
	
			if(!reStr.test(name_f.value)){
				alert('Please enter your name');
				name_f.select();
				name_f.focus();
				return false;
			}
			
			if(!reStr.test(name_l.value)){
				alert('Please enter your name');
				name_l.select();
				name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(address1.value)){
				alert('Please enter a valid address');
				address1.select();
				address1.focus();
				return false;
				
			}
			
			if(!reStr.test(city.value)){
				
				alert('Please enter a valid city');
				city.select();
				city.focus();
				return false;
				
			}
			
			if(!reStr.test(state.value)){
				alert('Please enter a valid two letter sate code');
				state.select();
				state.focus();
				return false;
			}
			
			if(!reNumber.test(zip.value)){
				alert('Please enter a valid zip code');
				zip.select();
				zip.focus();
				return false;
				
			}
			
			if(new_name_f.value =='') new_name_f.value = name_f.value; else new_name_f.value = '';
			if(new_name_l.value =='') new_name_l.value = name_l.value; else new_name_l.value = '';
			if(new_address1.value=='') new_address1.value = address1.value; else new_address1.value = '';
			if(new_address2.value=='') new_address2.value = address2.value; else new_address2.value = '';
			if(new_city.value =='') new_city.value = city.value; else new_city.value='';
			if(new_state.selectedIndex =='') new_state.selectedIndex = state.selectedIndex; else new_state.selectedIndex='';
			if(new_zip.value =='') new_zip.value = zip.value; else new_zip.value ='';
	
}


//Send Credit card information
function send_card(prefix){
	
	
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var email2 = document.getElementById('email2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var cnumber = document.getElementById('cnumber');
	var ctype = document.getElementById('card_type');
	var cvv = document.getElementById('cvv');
	var exp_mon = document.getElementById('exp_mon');
	var exp_year = document.getElementById('exp_year');
	var billing_name_f = document.getElementById(prefix+'_name_f');
	var billing_name_l = document.getElementById(prefix+'_name_l');
	var billing_address1 = document.getElementById(prefix+'_address');
	var billing_address2 = document.getElementById(prefix+'_address2');
	var billing_city = document.getElementById(prefix+'_city');
	var billing_state = document.getElementById(prefix+'_state');
	var billing_zip = document.getElementById(prefix+'_zip');
	
	var market = document.getElementById('market');
	if(market.checked ==true) var mark = 1; else var mark = 0;
	
	//Validate the card holder contact info here

		
			if(!reStr.test(name_f.value)){
				alert('Please enter your name');
				name_f.select();
				name_f.focus();
				return false;
			}
			
			if(!reStr.test(name_l.value)){
				alert('Please enter your name');
				name_l.select();
				name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(address1.value)){
				alert('Please enter a valid address');
				address1.select();
				address1.focus();
				return false;
				
			}
			
			if(!reStr.test(city.value)){
				
				alert('Please enter a valid city');
				city.select();
				city.focus();
				return false;
				
			}
			
			if(!reStr.test(state.value)){
				alert('Please enter a valid two letter sate code');
				state.select();
				state.focus();
				return false;
			}
			
			if(!reNumber.test(zip.value)){
				alert('Please enter a valid zip code');
				zip.select();
				zip.focus();
				return false;
				
			}	
			
			if(!reEmail.test(email.value)){
				alert('Please enter a valid email address');
				email.select();
				email.focus();
				return false;
			}
			

			
			if(!reStr.test(billing_name_f.value)){
				alert('All Card Holder information is required');
				billing_name_f.select();
				billing_name_f.focus();
				return false;
			}
			
			if(!reStr.test(billing_name_l.value)){
				alert('All Card holder information is required');
				billing_name_l.select();
				billing_name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(billing_address1.value)){
				alert('All Card holder information is required');
				billing_address1.select();
				billing_address1.focus();
				return false;
				
			}
			
			if(!reStr.test(billing_city.value)){
				
				alert('All Card Holder informaton is required');
				billing_city.select();
				billing_city.focus();
				return false;
				
			}
			
			if(!reStr.test(billing_state.value)){
				alert('All Card Holder information is required');
				billing_state.select();
				billing_state.focus();
				return false;
			}
			
			if(!reNumber.test(billing_zip.value)){
				alert('All Card Holder information is required');
				billing_zip.select();
				billing_zip.focus();
				return false;
				
			}
	
	//Validate the actual card information here
	
	if(!reNumber.test(cnumber.value)){
		alert('Please enter a valid card number');
		cnumber.focus();
		cnumber.select();
		return false;
	}
	if(!reNumber.test(cvv.value)){
		alert('Please enter the cvv number for this card');
		cvv.focus();
		cvv.select();
		return false;
	}
	
	if(!reNumber.test(exp_mon.value)){
		alert('Please select the expiration date for your card');
		return false;
	}
	
	if(!reNumber.test(exp_year.value)){
		alert('Please select the expiration date for yout card');
		return false;
	}
	
	
	document.getElementById('working_credit').style.display='inline';
	
	var file = 'modules/aj/process_payment.php';
	var query = 'name_f='+encodeURI(name_f.value)+'&name_l='+encodeURI(name_l.value)+'&address='+encodeURI(address1.value)+'&address2='+encodeURI(address2.value)+'&city='+encodeURI(city.value)+'&state='+encodeURI(state.value)+'&zip='+encodeURI(zip.value)+'&email='+encodeURI(email.value)+'&email2='+encodeURI(email2.value)+'&billing_name_f='+encodeURI(billing_name_f.value)+'&billing_name_l='+encodeURI(billing_name_l.value)+'&billing_address='+encodeURI(billing_address1.value)+'&billing_address_2='+encodeURI(billing_address2.value)+'&billing_city='+encodeURI(billing_city.value)+'&billing_state='+encodeURI(billing_state.value)+'&billing_zip='+encodeURI(billing_zip.value)+'&cnumber='+encodeURI(cnumber.value)+'&ctype='+encodeURI(ctype.value)+'&cvv='+encodeURI(cvv.value)+'&exp_mon='+encodeURI(exp_mon.value)+'&exp_year='+encodeURI(exp_year.value)+'&pay_type='+encodeURI('credit')+'&phone1='+encodeURI(phone1.value)+'&phone2='+encodeURI(phone2.value)+'&phone3='+encodeURI(phone3.value)+'&market='+encodeURI(mark);
	

	ajaxCall2(file,query,'billing');
	
	
	
	
}

//Load the paypal form
function load_check(){
	
	var file = 'modules/aj/check_form.php';
	var query = '';
	ajaxCall(file,query,'billing');
}


//Send Credit card information
function send_check(prefix){
	
	
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var email2 = document.getElementById('email2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var same = document.getElementById('same');
	var bname = document.getElementById('bname');
	var baccount = document.getElementById('baccount');
	var broute = document.getElementById('broute');
	var dl = document.getElementById('dl');
	var dl_state = document.getElementById('dlstate');
	var billing_name_f = document.getElementById(prefix+'_name_f');
	var billing_name_l = document.getElementById(prefix+'_name_l');
	var billing_address1 = document.getElementById(prefix+'_address');
	var billing_address2 = document.getElementById(prefix+'_address2');
	var billing_city = document.getElementById(prefix+'_city');
	var billing_state = document.getElementById(prefix+'_state');
	var billing_zip = document.getElementById(prefix+'_zip');
	
	var market = document.getElementById('market');
	if(market.checked ==true) var mark = 1; else var mark = 0;
	
	//Validate the card holder contact info here

		
			if(!reStr.test(name_f.value)){
				alert('Please enter your name');
				name_f.select();
				name_f.focus();
				return false;
			}
			
			if(!reStr.test(name_l.value)){
				alert('Please enter your name');
				name_l.select();
				name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(address1.value)){
				alert('Please enter a valid address');
				address1.select();
				address1.focus();
				return false;
				
			}
			
			if(!reStr.test(city.value)){
				
				alert('Please enter a valid city');
				city.select();
				city.focus();
				return false;
				
			}
			
			if(!reStr.test(state.value)){
				alert('Please enter a valid two letter sate code');
				state.select();
				state.focus();
				return false;
			}
			
			if(!reNumber.test(zip.value)){
				alert('Please enter a valid zip code');
				zip.select();
				zip.focus();
				return false;
				
			}	
		
				if(!reStr.test(billing_name_f.value)){
				alert('All Card Holder information is required');
				billing_name_f.select();
				billing_name_f.focus();
				return false;
			}
			
			if(!reStr.test(billing_name_l.value)){
				alert('All Card holder information is required');
				billing_name_l.select();
				billing_name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(billing_address1.value)){
				alert('All Card holder information is required');
				billing_address1.select();
				billing_address1.focus();
				return false;
				
			}
			
			if(!reStr.test(billing_city.value)){
				
				alert('All Card Holder informaton is required');
				billing_city.select();
				billing_city.focus();
				return false;
				
			}
			
			if(!reStr.test(billing_state.value)){
				alert('All Card Holder information is required');
				billing_state.select();
				billing_state.focus();
				return false;
			}
			
			if(!reNumber.test(billing_zip.value)){
				alert('All Card Holder information is required');
				billing_zip.select();
				billing_zip.focus();
				return false;
				
			}
	
	//Validate the actual card information here
	
	if(!reStr.test(bname.value)){
		alert('Please enter a valid Bank Name');
		bname.focus();
		bname.select();
		return false;
	}
	if(!reNumber.test(baccount.value)){
		alert('Please enter your chacking account number');
		baccount.focus();
		baccount.select();
		return false;
	}
	
	if(!reNumber.test(broute.value)){
		alert('Please enter your routing number');
		broute.select();
		broute.focus();
		return false;
	}
	
	if(!reStrAlpha.test(dl.value)){
		alert('Please enter your Identifacation either drivers license or DMV issues ID');
		dl.select();
		dl.focus();
		return false;
	}
	if(!reStr.test(dl_state.value)){
		
		alert('Please enter a valid issuing state');
		dl_state.focus();
		dl_state.select();
		return false;
	}
	
	if(phone1.value !='' || phone2.value!='' || phone3.value != '' &&(!reNumber.test(phone1.value) || !reNumber.test(phone2.value) || !reNumber.test(phone3.value))){
		alert('Please enter a valid phone number');
		phone1.select();
		phone1.focus();
		return false;
		
	}	
	
	document.getElementById('working_check').style.display='inline';
	
	var file = 'modules/aj/process_payment.php';
	var query = 'name_f='+encodeURI(name_f.value)+'&name_l='+encodeURI(name_l.value)+'&address='+encodeURI(address1.value)+'&address2='+encodeURI(address2.value)+'&city='+encodeURI(city.value)+'&state='+encodeURI(state.value)+'&zip='+encodeURI(zip.value)+'&email='+encodeURI(email.value)+'&email2='+encodeURI(email2.value)+'&billing_name_f='+encodeURI(billing_name_f.value)+'&billing_name_l='+encodeURI(billing_name_l.value)+'&billing_address='+encodeURI(billing_address1.value)+'&billing_address2='+encodeURI(billing_address2.value)+'&billing_city='+encodeURI(billing_city.value)+'&billing_state='+encodeURI(billing_state.value)+'&billing_zip='+encodeURI(billing_zip.value)+encodeURI(bname.value)+'&baccount='+encodeURI(baccount.value)+'&broute='+encodeURI(broute.value)+'&dl='+encodeURI(dl.value)+'&dl_state='+encodeURI(dl_state.value)+'&pay_type='+encodeURI('echeck')+'&phone1='+encodeURI(phone1.value)+'&phone2='+encodeURI(phone2.value)+'&phone3='+encodeURI(phone3.value)+'&market='+encodeURI(mark);
	

	ajaxCall2(file,query,'billing');
	
	
	
	
}



//Load the mail forum
function load_mail(){
	
	var file = 'modules/aj/mail_form.php';
	var query = '';
	ajaxCall(file,query,'billing');
}

//Send the Pay by mail information to the server
function send_pay_mail(){
	
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var email2 = document.getElementById('email2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	
	var market = document.getElementById('market');
	if(market.checked ==true) var mark = 1; else var mark = 0;
	
				if(!reStr.test(name_f.value)){
				alert('Please enter your name');
				name_f.select();
				name_f.focus();
				return false;
			}
			
			if(!reStr.test(name_l.value)){
				alert('Please enter your name');
				name_l.select();
				name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(address1.value)){
				alert('Please enter a valid address');
				address1.select();
				address1.focus();
				return false;
				
			}
			
			if(!reStr.test(city.value)){
				
				alert('Please enter a valid city');
				city.select();
				city.focus();
				return false;
				
			}
			
			if(!reStr.test(state.value)){
				alert('Please enter a valid two letter sate code');
				state.select();
				state.focus();
				return false;
			}
			
			if(!reNumber.test(zip.value)){
				alert('Please enter a valid zip code');
				zip.select();
				zip.focus();
				return false;
				
			}
			
			if(!reEmail.test(email.value)){
				alert('Please enter a valid email address');
				email.select();
				email.focus();
				return false;
			}
			
			if(!reEmail.test(email2.value)){
				alert('Please enter a valid email address');
				email2.select();
				email2.focus();
				return false;
			}
			if(email.value != email2.value){
				alert('Email addresses do not match');
				email2.select()
				email2.focus();
				return false;
			}
	/*
	if(phone1.value !='' || phone2.value!='' || phone3.value != '' &&(!reNumber.test(phone1.value) || !reNumber.test(phone2.value) || !reNumber.test(phone3.value))){
		alert('Please enter a valid phone number');
		phone1.select();
		phone1.focus();
		return false;
		
	}			
	*/
		document.getElementById('working_mail').style.display='inline';
	
	var file = 'modules/aj/process_payment.php';
	var query = 'name_f='+encodeURI(name_f.value)+'&name_l='+encodeURI(name_l.value)+'&address='+encodeURI(address1.value)+'&address2='+encodeURI(address2.value)+'&city='+encodeURI(city.value)+'&state='+encodeURI(state.value)+'&zip='+encodeURI(zip.value)+'&email='+encodeURI(email.value)+'&email2='+encodeURI(email2.value)+'&pay_type='+encodeURI('mail')+'&phone1='+encodeURI(phone1.value)+'&phone2='+encodeURI(phone2.value)+'&phone3='+encodeURI(phone3.value)+'&market='+encodeURI(mark);
	

	ajaxCall2(file,query,'billing');
}
//Load the google form
function load_google(){
	
	var file = 'modules/aj/google_form.php';
	var query = '';
	ajaxCall(file,query,'billing');
}

//Send the PAstdue information to the server
function send_pastdue(){
	
	
	var name_f = document.getElementById('name_f');
	var name_l = document.getElementById('name_l');
	var address1 = document.getElementById('address');
	var address2 = document.getElementById('address2');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var email = document.getElementById('email');
	var email2 = document.getElementById('email2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var notice = document.getElementById('notice');
	var source = document.getElementById('source');
	
	
				if(!reStr.test(name_f.value)){
				alert('Please enter your name');
				name_f.select();
				name_f.focus();
				return false;
			}
			
			if(!reStr.test(name_l.value)){
				alert('Please enter your name');
				name_l.select();
				name_l.focus();
				return false;
			}
			
			if(!reStrAlpha.test(address1.value)){
				alert('Please enter a valid address');
				address1.select();
				address1.focus();
				return false;
				
			}
			
			if(!reStr.test(city.value)){
				
				alert('Please enter a valid city');
				city.select();
				city.focus();
				return false;
				
			}
			
			if(!reStr.test(state.value)){
				alert('Please enter a valid two letter sate code');
				state.select();
				state.focus();
				return false;
			}
			
			if(!reNumber.test(zip.value)){
				alert('Please enter a valid zip code');
				zip.select();
				zip.focus();
				return false;
				
			}
			
			if(!reEmail.test(email.value)){
				alert('Please enter a valid email address');
				email.select();
				email.focus();
				return false;
			}
			
			if(!reEmail.test(email2.value)){
				alert('Please enter a valid email address');
				email2.select();
				email2.focus();
				return false;
			}
			if(email.value != email2.value){
				alert('Email addresses do not match');
				email2.select()
				email2.focus();
				return false;
			}
	
	/*
	if(!reNumber.test(phone1.value) || !reNumber.test(phone2.value) || !reNumber.test(phone3.value)){
		alert('Please enter a valid phone number');
		phone1.select();
		phone1.focus();
		return false;
		
	}
		*/
		
		
		document.getElementById('working_pastdue').style.display='inline';
	
	var file = 'modules/aj/pastdue.php';
	var query = 'name_f='+encodeURI(name_f.value)+'&name_l='+encodeURI(name_l.value)+'&address='+encodeURI(address1.value)+'&address2='+encodeURI(address2.value)+'&city='+encodeURI(city.value)+'&state='+encodeURI(state.value)+'&zip='+encodeURI(zip.value)+'&email='+encodeURI(email.value)+'&email2='+encodeURI(email2.value)+'&pay_type='+encodeURI('mail')+'&phone1='+encodeURI(phone1.value)+'&phone2='+encodeURI(phone2.value)+'&phone3='+encodeURI(phone3.value)+'&notice='+encodeURI(notice.value)+'&source='+encodeURI(source.value);
	

	ajaxCall2(file,query,'billing');
	
	//setTimeout("window.top.location='?mod=signin'",1000);
}

