/*  */
var level = 0;
var current = 0;
function showbilling()
{
	if(document.getElementById('sameaddress').checked)
	{
		document.getElementById('billing').style.display="block";
	}
	else
	{
		document.getElementById('billing').style.display="none";
	}
}
function showcredit()
{
	document.getElementById('credit_details').style.display="block";
	document.getElementById('btn_express').style.display="none";
}
function showexpress()
{
	document.getElementById('error3').style.display="none";
	document.getElementById('credit_details').style.display="none";
	document.getElementById('btn_express').style.display="block";
}
function shippingservicesubmit()
{
	var head="<div id='errormessage'><div class='error_panel'><div class='error'><h2 style='color:white;padding:5px 0 0 15px;'>Sorry, Please Try Again!</h2>";
	var str="";
	var type="";
	var valid;
	if(document.frm_customer.ship_type.value=="")
		str+="<p>Shipping Type(Required)</p>";
	if(document.frm_customer.cost_dollor.value=="")
		str+="<p>Shipping Cost(Required)</p>";
	var foot="</div></div></div>";	
	if(str!="")
	{
		document.getElementById('error2').innerHTML=head+str+foot;
		document.getElementById('error2').style.display="block";
		document.getElementById('errormessage').style.display="none";
	}
	else
	{
		show_hide(2);
		var url = '/ajax/add_service.php';
		//var ship_type=document.getElementById('ship_type').value;
		var ship_cost=document.getElementById('cost_dollor').value;
			new Ajax.Request(url, {	parameters:	{	cost: ship_cost
									},
									onCreate: function(transport) {
									},
									onSuccess:function(transport) {
									var result = transport.responseText.split('~');		
									$('ups').innerHTML = result[0];
									$('total').innerHTML = result[1];
									},
									onFailure: function(transport) {
									alert(transport.responseText);
									}
								}
							);
	}
}

function display_details(id)
{
level=3;
current=id;
for(var i=1;i<=3;i++)
	{
		document.getElementById('tab_'+i).style.display="none";
		if(id==i)
		{
			document.getElementById('details_'+id).style.display="none";
			document.getElementById('form_'+id).style.display="block";
		}
		else
		{
			document.getElementById('details_'+i).style.display="block";
			document.getElementById('form_'+i).style.display="none";
		}
	}
}
function creditcardsubmit(){
	var head="<div id='errormessage'><div class='error_panel'><div class='error'><h2 style='color:white;padding:5px 0 0 15px;'>Sorry, Please Try Again!</h2>";
	var str="";
	var type="";
	var valid;
	if(document.frm_customer.cc_type.value=="")
		str+="<p>Credit Type(Required)</p>";
	if(document.frm_customer.cc_number.value=="")
		str+="<p>Credit Number(Required)</p>";
	else
	{
		switch(document.frm_customer.cc_type.value){
			case 'MasterCard':
				valid =/^5[1-5][0-9]{14}$/;
				if(!valid.test(document.frm_customer.cc_number.value))
				str+= 'Invalid MasterCard number';
				break;
			case 'Visa':
				valid =/^4[0-9]{12}([0-9]{3})?$/;
				if(!valid.test(document.frm_customer.cc_number.value))
				str+= 'Invalid VISA card number';
				break;
			case 'Discover':
				valid =/^3(0[0-5]|[68][0-9])[0-9]{11}$/;
				if(!valid.test(document.frm_customer.cc_number.value))
				str+= 'Invalid Discover card number';
				break;
			case 'Amex':
				valid =/^3[47][0-9]{13}$/;
				if(!valid.test(document.frm_customer.cc_number.value))
				str+= 'Invalid American Express card number';
				break;
			default:
				str+= 'Insert a valid credit card number';
				return false;
		}

		
	}
	if(document.frm_customer.cc_exp_month.value=="")
		str+="<p>select your credit card expiration month</p>";
	if(document.frm_customer.cc_exp_year.value=="")
		str+="<p>select your credit card expiration year</p>";
	if(document.frm_customer.cc_number.value=="")
		str+="<p>Credit Number(Required)</p>";
	else
	{
		if(document.frm_customer.cc_type.value=='Amex')
		{
			valid =/^[0-9]{4}$/;
			if(!valid.test(document.frm_customer.cvs.value))
			str+= "<p>Your Credit verification code must be valid.</p>";
		}
		else
		{
			valid =/^[0-9]{3}$/;
			if(!valid.test(document.frm_customer.cvs.value))
			str+= "<p>Your Credit verification code must be valid.</p>";
		}
	}
	var foot="</div></div></div>";	
	if(str!="")
	{
		document.getElementById('error3').innerHTML=head+str+foot;
		document.getElementById('error3').style.display="block";
	}
	else
	{
		document.getElementById('error3').style.display="none";
		show_hide(3);
		var url = '/ajax/add_credit.php';
		new Ajax.Request(url, {	parameters:	{	type: document.frm_customer.cc_type.value,
								number: document.frm_customer.cc_number.value,
								month: document.frm_customer.cc_exp_month.value,
								year: document.frm_customer.cc_exp_year.value,
								cvs: document.frm_customer.cvs.value
								},
								onCreate: function(transport) {
								},
								onSuccess:function(transport) {
								$('credit').innerHTML=document.frm_customer.cc_type.value;
								$('c_num').innerHTML=document.frm_customer.cc_number.value;
								},
								onFailure: function(transport) {
								}
							}
						);
	}

	
}
var location_address = "";
function shippingsubmit(){
var head="<div id='errormessage'><div class='error_panel'><div class='error'><h2 style='color:white;padding:5px 0 0 15px;'>Sorry, Please Try Again!</h2>";
var str="";
			if(!document.frm_customer.sameaddress.checked){
				document.frm_customer.first_name.value = document.frm_customer.sfirst_name.value;
				document.frm_customer.last_name.value = document.frm_customer.slast_name.value;
				document.frm_customer.company.value = document.frm_customer.scompany.value;
				document.frm_customer.phone.value = document.frm_customer.sphone.value;
				document.frm_customer.address1.value = document.frm_customer.saddress1.value;
				document.frm_customer.address2.value = document.frm_customer.saddress2.value;
				document.frm_customer.city.value = document.frm_customer.scity.value;
				document.frm_customer.state.value = document.frm_customer.sstate.value;
				document.frm_customer.zipcode.value = document.frm_customer.szipcode.value;
				document.frm_customer.email.value = document.frm_customer.semail.value;
				document.frm_customer.cemail.value = document.frm_customer.scemail.value;
				document.frm_customer.country.value = document.frm_customer.scountry.value;
				if(document.frm_customer.sfirst_name.value=="")
					str+="<p>First name(Required)</p>";
				if(document.frm_customer.slast_name.value=="")
					str+="<p>Last name(Required)</p>";
				if(document.frm_customer.sphone.value=="")
					str+="<p>Phone Number(Required)</p>";
				else
				{
					var PhoneExp=/^[a-zA-Z]*$/;
					if(PhoneExp.test(document.frm_customer.sphone.value))
					str+="Enter a valid phone number\n";
				}
				if(document.frm_customer.saddress1.value=="")
					str+="<p>Shipping Address1(Required)</p>";
				if(document.frm_customer.scity.value=="")
					str+="<p>City(Required)</p>";
				if(document.frm_customer.sstate.value=="")
					str+="<p>State(Required)</p>";
				if(document.frm_customer.szipcode.value=="")
					str+="<p>Zipcode(Required)</p>";
				else
				{
					var PhoneExp=/^[0-9]{5}$/;
					if(!PhoneExp.test(document.frm_customer.szipcode.value))
					str+="<p>Enter a valid zipcode</p>";
				}
				if(document.frm_customer.semail.value=="")
					str+="<p>Email(Required)</p>";
				else
				{
					var PhoneExp=/^([._a-zA-Z0-9-]){1,255}@([._a-zA-Z0-9-]){1,255}\.([a-zA-Z]){2,4}$/;
					if(!PhoneExp.test(document.frm_customer.semail.value))
					str+="<p>Enter a valid email</p>";
				}
				if(document.frm_customer.scemail.value=="")
					str+="<p>Confirm Email(Required)</p>";
				else
				{
					if(document.frm_customer.scemail.value!=document.frm_customer.semail.value)
					str+="<p>Email and Confirm Email must be same";
				}
				if(document.frm_customer.scountry.value=="")
					str+="<p>Country(Required)</p>";
			}
			else
			{
				if(document.frm_customer.sfirst_name.value=="")
					str+="<p>Shipping First name(Required)</p>";
				if(document.frm_customer.slast_name.value=="")
					str+="<p>Shipping Last name(Required)</p>";
				if(document.frm_customer.sphone.value=="")
					str+="<p>Shipping Phone Number(Required)</p>";
				else
				{
					var PhoneExp=/^[a-zA-Z]*$/;
					if(PhoneExp.test(document.frm_customer.sphone.value))
					str+="Enter a valid phone number\n";
				}
				if(document.frm_customer.saddress1.value=="")
					str+="<p>Shipping Address1(Required)</p>";
				if(document.frm_customer.scity.value=="")
					str+="<p>Shipping City(Required)</p>";
				if(document.frm_customer.sstate.value=="")
					str+="<p>Shipping State(Required)</p>";
				if(document.frm_customer.szipcode.value=="")
					str+="<p>Shipping Zipcode(Required)</p>";
				else
				{
					var PhoneExp=/^[0-9]{5}$/;
					if(!PhoneExp.test(document.frm_customer.szipcode.value))
					str+="<p>Enter a valid Shipping zipcode</p>";
				}
				if(document.frm_customer.semail.value=="")
					str+="<p>Shipping Email(Required)</p>";
				else
				{
					var PhoneExp=/^([._a-zA-Z0-9-]){1,255}@([._a-zA-Z0-9-]){1,255}\.([a-zA-Z]){2,4}$/;
					if(!PhoneExp.test(document.frm_customer.semail.value))
					str+="<p>Enter a valid Shipping email</p>";
				}
				if(document.frm_customer.scemail.value=="")
					str+="<p>Shipping Confirm Email(Required)</p>";
				else
				{
					if(document.frm_customer.scemail.value!=document.frm_customer.semail.value)
					str+="<p>Email and Confirm Email must be same in Shipping info";
				}
				if(document.frm_customer.scountry.value=="")
					str+="<p>Shipping Country(Required)</p>";
				if(document.frm_customer.first_name.value=="")
					str+="<p>Billing First name(Required)</p>";
				if(document.frm_customer.last_name.value=="")
					str+="<p>Billing Last name(Required)</p>";
				if(document.frm_customer.phone.value=="")
					str+="<p>Billing Phone Number(Required)</p>";
				else
				{
					var PhoneExp=/^[a-zA-Z]*$/;
					if(PhoneExp.test(document.frm_customer.sphone.value))
					str+="Enter a valid phone number\n";
				}
				if(document.frm_customer.address1.value=="")
					str+="<p>Billing Address1(Required)</p>";
				if(document.frm_customer.city.value=="")
					str+="<p>Billing City(Required)</p>";
				if(document.frm_customer.state.value=="")
					str+="<p>Billing State(Required)</p>";
				if(document.frm_customer.zipcode.value=="")
					str+="<p>Billing Zipcode(Required)</p>";
				else
				{
					var PhoneExp=/^[0-9]{5}$/;
					if(!PhoneExp.test(document.frm_customer.szipcode.value))
					str+="<p>Enter a valid Billing zipcode</p>";
				}
				if(document.frm_customer.email.value=="")
					str+="<p>Billing Email(Required)</p>";
				else
				{
					var PhoneExp=/^([._a-zA-Z0-9-]){1,255}@([._a-zA-Z0-9-]){1,255}\.([a-zA-Z]){2,4}$/;
					if(!PhoneExp.test(document.frm_customer.semail.value))
					str+="<p>Enter a valid Billing email</p>";
				}
				if(document.frm_customer.cemail.value=="")
					str+="<p>Billing Confirm Email(Required)</p>";
				else
				{
					if(document.frm_customer.cemail.value!=document.frm_customer.email.value)
					str+="<p>Email and Confirm Email must be same in Billing info";
				}
				if(document.frm_customer.country.value=="")
					str+="<p>Billing Country(Required)</p>";
			}
var foot="</div></div></div>";	
	if(str!="")
	{alert("hai2");
		document.getElementById('error1').innerHTML=head+str+foot;
		document.getElementById('error1').style.display="block";
		location_address = window.location+"";
		url = location_address.split("#");
		window.location = url[0] + "#pointer-1";
	}
	else
	{
		document.getElementById('pname').innerHTML=document.frm_customer.sfirst_name.value+" "+document.frm_customer.slast_name.value;
		document.getElementById('address1').innerHTML=document.frm_customer.saddress1.value;
		document.getElementById('state').innerHTML=document.frm_customer.sstate.value;
		document.getElementById('zipcode').innerHTML=document.frm_customer.szipcode.value;
		
		document.getElementById('error1').style.display="none";
		show_hide(1);
		var url = '/ajax/add_shipping_address.php';
		new Ajax.Request(url, {	parameters:	{	sfname: document.frm_customer.sfirst_name.value,
								fname: document.frm_customer.first_name.value,
								slname: document.frm_customer.slast_name.value,
								lname: document.frm_customer.last_name.value,
								scompany:document.frm_customer.scompany.value,
								company:document.frm_customer.company.value,
								sphone:document.frm_customer.sphone.value,
								phone:document.frm_customer.phone.value,
								saddress1:document.frm_customer.saddress1.value,
								address1:document.frm_customer.address1.value,
								saddress2:document.frm_customer.saddress2.value,
								address2:document.frm_customer.address2.value,
								scity: document.frm_customer.scity.value,
								city: document.frm_customer.city.value,
								sstate: document.frm_customer.sstate.value,
								state: document.frm_customer.state.value,
								szip: document.frm_customer.szipcode.value,
								zip: document.frm_customer.zipcode.value,
								semail: document.frm_customer.semail.value,
								email: document.frm_customer.email.value,
								scountry: document.frm_customer.scountry.value,
								country: document.frm_customer.country.value
								},
								onCreate: function(transport) {
								},
								onSuccess:	function(transport) {
								var result = transport.responseText.split('~');
								if(result[0]!=1){
								get_service(result[0],result[1]);}
								},
								onFailure: function(transport) {
								}
							}
						);
		
		

	}
}



function ship_info_submit(val){

if(val==""){
				alert('Please Calculate Shipping Cost.');
				return false;
	}else{
				document.frm_customer.submit();
				return true;
	} 
}

function CartSubmit(page,cat_id){ alert("hai");
	
	window.location='customer_details.php?page='+page+'&cat_id='+cat_id;
				
}
function edit_show(id) {
	if(current > level)
		document.getElementById('tab_'+current).style.display="block";
	else
		document.getElementById('details_'+current).style.display="block";
	document.getElementById('form_'+current).style.display="none";
	document.getElementById('details_'+id).style.display="none";
	document.getElementById('form_'+id).style.display="block";
	current = id;
}function show_hide(id) {
	if(id>level) {
		level = id;
	}
	current = level + 1;
	document.getElementById('tab_'+id).style.display="none";
	document.getElementById('details_'+id).style.display="block";
	document.getElementById('form_'+id).style.display="none";
	document.getElementById('tab_'+(level+1)).style.display="none";
	document.getElementById('form_'+(level+1)).style.display="block";
}
