// JavaScript Document

/* 
1) Make sure the pulldown value isnt 0
2) Make sure the front image isnt empty
*/

function fill_ship_state()
{
	myOption = -1;
	
	for (i=document.frm_payment.bstate.length-1; i > -1; i--)           // 2 - 0 
	{
		if(document.frm_payment.bstate[i].selected) 
		{
			document.frm_payment.sstate[i].selected = true;
			
			//myOption = i;   i = -1;
		}
	}	
}



function fill_ship(billing)
{
	var myarray = new Array();
	
	myarray['bname'] = 'sname';
	myarray['bname_last'] = 'sname_last';
	myarray['bcompany'] = 'scompany';
	myarray['bcountry'] = 'scountry';
	myarray['baddress'] = 'saddress';
	myarray['baddress2'] = 'saddress2';
	myarray['bcity'] = 'scity';
	myarray['bstate'] = 'sstate';
	myarray['bzip'] = 'szip';
	myarray['bphone'] = 'sphone';
	myarray['bemail'] = 'semail';
	
	myOption = -1;
	
	for (i=document.frm_payment.duplicateShipping.length-1; i > -1; i--)           // 2 - 0 
	{
		if(document.frm_payment.duplicateShipping[i].checked) 
		{						
			if(document.frm_payment.duplicateShipping[i].value == "true")
			{
				document.getElementById(myarray[billing]).value = document.getElementById(billing).value;
				
			}
			
			//myOption = i;   i = -1;
		}
	}	
	
	return true;	
}

function testing(){
	alert("Testing");
}

function IsNumeric(sText){
   
   var ValidChars = "0123456789.";
   var IsNumber= true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}//end function



function validateUpload(){
	
	//alert("called()");
	
	var status = true;
	
	var pulldown = document.getElementById("details").value;
	var front = document.getElementById("front").value;
	
	
	if(pulldown == '' || pulldown == 0){
		status = false
	}
	
	if(front == ''){
		status = false;
	}
	
	return status;
}//end function


/*function copyShipping(element){   alert(element);

	if(element.checked == true){
	document.getElementById('bcompany').value = document.getElementById('scompany').value;
		document.getElementById('bname').value = document.getElementById('sname').value;
			document.getElementById('baddress').value = document.getElementById('saddress').value;
				document.getElementById('baddress2').value = document.getElementById('saddress2').value;
					document.getElementById('bcity').value = document.getElementById('scity').value;
						document.getElementById('bstate').selectedIndex = document.getElementById('sstate').selectedIndex;
						//document.getElementById('bstate').value = document.getElementById('sstate').value;
							document.getElementById('bzip').value = document.getElementById('szip').value;
								document.getElementById('bphone').value = document.getElementById('sphone').value;
									document.getElementById('bemail').value = document.getElementById('semail').value;
	}
	else{
		document.getElementById('bcompany').value = '';
			document.getElementById('bname').value =  '';
				document.getElementById('baddress').value =  '';
					document.getElementById('baddress2').value =  '';
						document.getElementById('bcity').value =  '';
							document.getElementById('bstate').value =  '';
								document.getElementById('bzip').value =  '';
									document.getElementById('bphone').value =  '';
										document.getElementById('bemail').value =  '';
		
		
	}//end if-else
}//end function*/

function copyShipping(element){   //alert(element);

	if(element == 1){
		
		document.getElementById('scompany').value = document.getElementById('bcompany').value;
		document.getElementById('sname').value = document.getElementById('bname').value;
		document.getElementById('sname_last').value = document.getElementById('bname_last').value;
		document.getElementById('saddress').value = document.getElementById('baddress').value;
		document.getElementById('saddress2').value = document.getElementById('baddress2').value;
		document.getElementById('scity').value = document.getElementById('bcity').value;
		//document.getElementById('scountry').selectedIndex = document.getElementById('bcountry').selectedIndex;
		//document.getElementById('scountry').selectedIndex = document.getElementById('bcountry').selectedIndex;
		//document.getElementById('sstate').selectedIndex = document.getElementById('bstate').selectedIndex;
		document.getElementById('sstate').value = document.getElementById('bstate').value;
		document.getElementById('szip').value = document.getElementById('bzip').value;
		document.getElementById('sphone').value = document.getElementById('bphone').value;
		document.getElementById('semail').value = document.getElementById('bemail').value;	
		document.getElementById('div_shipping').style.display = 'block';   // 26_03_09
			
		document.getElementById('scompany').readOnly=true;
		document.getElementById('sname').readOnly=true;
		document.getElementById('sname_last').readOnly=true;
		document.getElementById('saddress').readOnly=true;
		document.getElementById('saddress2').readOnly=true;
		document.getElementById('scity').readOnly=true;
		
		//document.getElementById('scountry').disabled=true;
		//document.getElementById('sstate').disabled=true;
		//document.getElementById('sstate').readOnly=true;
		//document.getElementById('scountry').readOnly=false;
		//document.getElementById('sstate').readOnly=false;
		document.getElementById('szip').readOnly=true;
		document.getElementById('sphone').readOnly=true;
		document.getElementById('semail').readOnly=true;	
			
		//document.getElementById('bname_last').value = document.getElementById('sname_last').value;
	
		//document.getElementById('scompany').readOnly=true;
		//document.getElementById('sname').readOnly=true;
		//document.getElementById('scountry').readOnly=true;
		
		//disabled="disabled"
						
		//document.getElementById('scompany').readOnly=true;
	
	}
	else{

		/*document.getElementById('scompany').value = '';
		document.getElementById('sname').value =  '';
		document.getElementById('sname_last').value =  '';
		document.getElementById('saddress').value =  '';
		document.getElementById('saddress2').value =  '';
		document.getElementById('scity').value =  '';
		//document.getElementById('scountry').value =  '';	
		document.getElementById('sstate').value =  '';
		document.getElementById('szip').value =  '';
		document.getElementById('sphone').value =  '';
		document.getElementById('semail').value =  '';
		document.getElementById('div_shipping').style.display = 'block';
		document.getElementById('scompany').readOnly=false;
		document.getElementById('sname').readOnly=false;
		document.getElementById('sname_last').readOnly=false;
		document.getElementById('saddress').readOnly=false;
		document.getElementById('saddress2').readOnly=false;
		document.getElementById('scity').readOnly=false;
		//document.getElementById('scountry').disabled=false;
		//document.getElementById('sstate').disabled=false;
		//document.getElementById('sstate').readOnly=false;
		//document.getElementById('scountry').readOnly=false;
		//document.getElementById('sstate').readOnly=false;
		document.getElementById('szip').readOnly=false;
		document.getElementById('sphone').readOnly=false;
		document.getElementById('semail').readOnly=false;*/
	
		document.getElementById('scompany').value = document.getElementById('hdn_scompany').value;
		document.getElementById('sname').value =  document.getElementById('hdn_sname').value;
		document.getElementById('sname_last').value =  document.getElementById('hdn_sname_last').value;
		document.getElementById('saddress').value =  document.getElementById('hdn_saddress').value;
		document.getElementById('saddress2').value = document.getElementById('hdn_saddress2').value;
		document.getElementById('scity').value =  document.getElementById('hdn_scity').value;
		//document.getElementById('scountry').value =  document.getElementById('scompany').value;	
		document.getElementById('sstate').value =  document.getElementById('hdn_sstate').value;
		document.getElementById('szip').value =  document.getElementById('hdn_szip').value;
		document.getElementById('sphone').value =  document.getElementById('hdn_sphone').value;
		document.getElementById('semail').value =  document.getElementById('hdn_semail').value;
		document.getElementById('div_shipping').style.display = 'block';
		document.getElementById('scompany').readOnly=false;
		document.getElementById('sname').readOnly=false;
		document.getElementById('sname_last').readOnly=false;
		document.getElementById('saddress').readOnly=false;
		document.getElementById('saddress2').readOnly=false;
		document.getElementById('scity').readOnly=false;
		document.getElementById('scountry').disabled=false;
		document.getElementById('sstate').disabled=false;
		document.getElementById('sstate').readOnly=false;
		document.getElementById('scountry').readOnly=false;
		document.getElementById('sstate').readOnly=false;
		document.getElementById('szip').readOnly=false;
		document.getElementById('sphone').readOnly=false;
		document.getElementById('semail').readOnly=false;						
		
	}//end if-else
}//end function


function validateCheckOut(){
	
	//alert("Function called");
	
	var status = true;
	
	var myarray = new Array();

	myarray[0] = 'bname';
	myarray[1] = 'bname_last';
	//myarray[2] = 'bcompany';
	myarray[2] = 'bcountry';
	myarray[3] = 'baddress';
	//myarray[5] = 'baddress2';
	myarray[4] = 'bcity';
	myarray[5] = 'bstate';
	myarray[6] = 'bzip';
	myarray[7] = 'bphone';
	myarray[8] = 'bemail';	
	myarray[9] = 'sname';
	myarray[10] = 'sname_last';
	//myarray[13] = 'scompany';
	myarray[11] = 'scountry';
	myarray[12] = 'saddress';
	//myarray[16] = 'saddress2';
	myarray[13] = 'scity';
	myarray[14] = 'sstate';
	myarray[15] = 'szip';
	myarray[16] = 'sphone';
	myarray[17] = 'semail';
	//myarray[18]	= 'password';	

	var alert_arr = new Array;
	
	alert_arr['sname'] = "Enter Shipping First Name";
	alert_arr['sname_last'] = "Enter Shipping Last Name";
	alert_arr['bname'] = "Enter Billing First Name";
	alert_arr['bname_last'] = "Enter Billing Last Name";
	alert_arr['saddress'] = "Enter Shipping Address";
	alert_arr['baddress'] = "Enter Billing Address";
	alert_arr['scity'] = "Enter Shipping City";
	alert_arr['bcity'] = "Enter Billing City";
	alert_arr['semail'] = "Enter Shipping E-Mail";
	alert_arr['bemail'] = "Enter Billing E-Mail";	
	alert_arr['bcountry'] = "Enter Billing Country";
	alert_arr['scountry'] = "Enter Shipping Country";
	alert_arr['bzip'] = "Enter Billing Zip";
	alert_arr['szip'] = "Enter Shipping Zip";
	alert_arr['bstate'] = "Enter Billing State";
	alert_arr['sstate'] = "Enter Shipping State";
	alert_arr['bphone'] = "Enter Billing Phone";
	alert_arr['sphone'] = "Enter Shipping Phone";
	
	//alert_arr['bcompany'] = "Enter Billing Company";
	//alert_arr['baddress2'] = "Enter Billing Address 2";
	//alert_arr['scompany'] = "Enter Shipping Company";
	//alert_arr['saddress2'] = "Enter Shipping Address 2";
	
	//alert_arr['password'] = "Enter Password";	
	
	//document.getElementById(myarray[i]).value
	
	//Cycle though the array to find empty values

	for(i=0;i<myarray.length;i++){       //alert(myarray[i]);
		
		if(document.getElementById(myarray[i]).value == '')
		{
			alert(alert_arr[document.getElementById(myarray[i]).name]);
			document.getElementById(myarray[i]).focus();
			status = false;
			
			return false;
			
		}//end if
	}//end loop
	
	
	/*var cctype = document.getElementById('cc_type').value
	if(cctype == 0){
		status = false;
		alert("Select a credit card type");
		document.getElementById('cc_type').focus();
		return false;
	}*/
	
	//Check the credit card number. Check its length and make sure its all numbers
	/*var cc_num = document.getElementById('cc_numb').value;
	if(cc_num.length < 15){
		alert("CC not enough numbers");
		status = false;
		return false;
	}*/
	
	
	/*if(!IsNumeric(cc_num)){
		alert("Your credit card can only contain numbers");
		status = false;
		return false;
	}*/
	
	
	//Check the credit card security nuumber
	
	
	/*if(!IsNumeric(cc_code)){
		alert("Your security card number is not valid, must be 3 digits")
		status = false;
		return false;
	}*/
	
	//Make sure they have selected a month and year for the credit card number
	/*var cc_month = document.getElementById('cc_month').value;
	var cc_year = document.getElementById('cc_year').value;
	
	if(cc_month == 0){
		alert("Please select a month for your credit card expiration date")
		status = false;
		return false;
	}
	if(cc_year == 0){
		alert("Please select a year for your credit card expiration date")
		status = false;
		return false;
	}*/
	
	/*if(document.getElementById('shipping_type').value == 0){
		status = false;
		alert("You must select a shipping method");
		return false;
	}*/
	
	
	
	/*if(!IsNumeric(zip_length)){
		status = false;
		alert("Your zip code can only contain numbers");
		return false;
	}*/
	
		
	
	
	/*if(shipping_cost < 1 || !IsNumeric(shipping_cost)){
		staus = false;
		alert("Your shipping cost is invalid");
		return false;
	}*/
	
	return status;
	
}//end function



function updateInvoice(element){
	

	
	if(element.id == 'invoice0'){
		document.getElementById('invoice1').checked = false;
	}
	else{
		document.getElementById('invoice0').checked = false;
	}
}//end function
		
	
