// JavaScript Document

function emailCheck(s1) {
emailStr=s1;

		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)&lt;>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) 
		{

			alert("Email address seems incorrect (check @ and .'s)")
			return false
		}
return true;
}

//*****************************Function For Check Out Form Starts*****************************//
function setText()
{
	if(document.getElementById("ddlBillCountry").value == "US")
	{
		var str = document.getElementById("txtHidden1").value;
		document.getElementById("BillState").innerHTML = str;
		document.getElementById("BillCountry").innerHTML = "";
	}
	if(document.getElementById("ddlBillCountry").value == "other")
	{
		var str = document.getElementById("txtHidden2").value;
		document.getElementById("BillState").innerHTML = str;
		str = document.getElementById("txtHidden3").value;
		document.getElementById("BillCountry").innerHTML = str;
	}
}

function swapData()
{
	if(document.getElementById("chkSame").checked == true)
	{
		document.getElementById("txtShippingFirstName").value = document.getElementById("txtBillFirstName").value;
		document.getElementById("txtShippingLastName").value = document.getElementById("txtBillLastName").value;
		document.getElementById("txtShippingAddress").value = document.getElementById("txtBillAddress").value;
		document.getElementById("txtShippingCity").value = document.getElementById("txtBillCity").value;
		document.getElementById("txtShippingZipCode").value = document.getElementById("txtBillZipCode").value;
		document.getElementById("txtShippingPhone").value = document.getElementById("txtBillPhone").value;
		document.getElementById("txtShippingMobile").value = document.getElementById("txtBillMobile").value;
		document.getElementById("txtShippingEmail").value = document.getElementById("txtBillEmail").value;
	}
	else
	{
		document.getElementById("txtShippingFirstName").value = "";
		document.getElementById("txtShippingLastName").value = "";
		document.getElementById("txtShippingAddress").value = "";
		document.getElementById("txtShippingCity").value = "";
		document.getElementById("txtShippingState").value = "";
		document.getElementById("txtShippingZipCode").value = "";
		document.getElementById("txtShippingPhone").value = "";
		document.getElementById("txtShippingMobile").value = "";
		document.getElementById("txtShippingEmail").value = "";
	}
}

function chkCheckout()
{
	var dom = document.form1;
	
	//**************BILLING FIELDS VALIDATION STARTS**************//
	// Bill First Name
	if(dom.txtBillFirstName.value == "")
	{
		alert("Please enter billing First Name");
		dom.txtBillFirstName.focus();
		return false;
	}
	
	// Bill Last Name
	if(dom.txtBillLastName.value == "")
	{
		alert("Please enter billing Last Name");
		dom.txtBillLastName.focus();
		return false;
	}
	
	// Bill Address
	if(dom.txtBillAddress.value == "")
	{
		alert("Please enter billing address");
		dom.txtBillAddress.focus();
		return false;
	}
	
	// Bill country
	if(dom.ddlBillCountry.value == "")
	{
		alert("Please enter billing country");
		dom.ddlBillCountry.focus();
		return false;
	}

	// Bill State
	if(dom.ddlBillCountry.value == "US")
	{
		if(dom.ddlBillState.value == "")
		{
			alert("Please enter billing state");
			dom.ddlBillState.focus();
			return false;
		}
	}
	
	if(dom.ddlBillCountry.value == "US")
	{
		if(dom.ddlBillState.value == "")
		{
			alert("Please enter billing state");
			dom.ddlBillState.focus();
			return false;
		}
	}
	
	if(dom.ddlBillCountry.value == "other")
	{
		if(dom.txtBillCountry.value == "")
		{
			alert("Please enter billing country");
			dom.txtBillCountry.focus();
			return false;
		}
		if(dom.txtBillState.value == "")
		{
			alert("Please enter billing state");
			dom.txtBillState.focus();
			return false;
		}
	}
	
	// Bill City
	if(dom.txtBillCity.value == "")
	{
		alert("Please enter billing city");
		dom.txtBillCity.focus();
		return false;
	}

	// Bill Zipcode
	if(dom.txtBillZipCode.value == "")
	{
		alert("Please enter billing zipcode");
		dom.txtBillZipCode.focus();
		return false;
	}
	// Bill Phone No
	if(dom.txtBillPhone.value == "")
	{
		alert("Please enter billing phone no.");
		dom.txtBillPhone.focus();
		return false;
	}
	
	// Bill Email
	if(dom.txtBillEmail.value == "")
	{
		alert("Please enter billing email");
		dom.txtBillEmail.focus();
		return false;
	}
	
	if(!emailCheck(dom.txtBillEmail.value))
	{
			dom.txtBillEmail.focus();
			return false;
	}
	//**************BILLING FIELDS VALIDATION ENDS**************//
	
	
	
	//**************SHIPPING FIELDS VALIDATION STARTS**************//
	// Shipping First Name
	if(dom.txtShippingFirstName.value == "")
	{
		alert("Please enter shipping First Name");
		dom.txtShippingFirstName.focus();
		return false;
	}
	
	// Shipping Last Name
	if(dom.txtShippingLastName.value == "")
	{
		alert("Please enter shipping Last Name");
		dom.txtShippingLastName.focus();
		return false;
	}
	
	// Shipping Address
	if(dom.txtShippingAddress.value == "")
	{
		alert("Please enter shipping address");
		dom.txtShippingAddress.focus();
		return false;
	}
	
	// Shipping country
	if(dom.ddlShippingCountry.value == "")
	{
		alert("Please enter shipping country");
		dom.ddlShippingCountry.focus();
		return false;
	}
			
	// Shipping State
	if(dom.ddlShippingState.value == "")
	{
		alert("Please enter shipping state");
		dom.ddlShippingState.focus();
		return false;
	}
	
	// Shipping City
	if(dom.txtShippingCity.value == "")
	{
		alert("Please enter shipping city");
		dom.txtShippingCity.focus();
		return false;
	}
	
	// Shipping Zipcode
	if(dom.txtShippingZipCode.value == "")
	{
		alert("Please enter shipping zipcode");
		dom.txtShippingZipCode.focus();
		return false;
	}
	// Shipping Phone No
	if(dom.txtShippingPhone.value == "")
	{
		alert("Please enter shipping phone no.");
		dom.txtShippingPhone.focus();
		return false;
	}
	// Shipping Email
	if(dom.txtShippingEmail.value == "")
	{
		alert("Please enter shipping email");
		dom.txtShippingEmail.focus();
		return false;
	}
	
	if(!emailCheck(dom.txtShippingEmail.value))
	{
			dom.txtShippingEmail.focus();
			return false;
	}	
	
	if(dom.chkAgree.checked == false)
	{
		alert("Please check I agree with the shipping terms and conditions check box to make sure you have read terms and conditions and agree to them.");
		dom.chkAgree.focus();
		return false;
	}		
	//**************SHIPPING FIELDS VALIDATION ENDS**************//
	
	
	if(dom.rdPaymentOption[0].checked == false && dom.rdPaymentOption[1].checked == false && dom.rdPaymentOption[2].checked == false && dom.rdPaymentOption[3].checked == false)
	{
		alert("Please select payment method");
		dom.rdPaymentOption[0].focus();
		return false;
	}
}
//*****************************Function For Check Out Form Ends*****************************//
