// Email Validation Function
function email_valid(src) 
{
	var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$";
    var regex = new RegExp(emailReg);
    return regex.test(src);
}

function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) {
		if (isChecked) {
			txtPaymentFirstName.value  = txtShippingFirstName.value;
			txtPaymentLastName.value   = txtShippingLastName.value;
			txtPaymentAddress1.value   = txtShippingAddress1.value;
			txtPaymentAddress2.value   = txtShippingAddress2.value;
			txtPaymentPhone.value      = txtShippingPhone.value;
			txtPaymentState.value      = txtShippingState.value;			
			txtPaymentCity.value       = txtShippingCity.value;
			txtPaymentPostalCode.value = txtShippingPostalCode.value;
			
			txtPaymentFirstName.readOnly  = true;
			txtPaymentLastName.readOnly   = true;
			txtPaymentAddress1.readOnly   = true;
			txtPaymentAddress2.readOnly   = true;
			txtPaymentPhone.readOnly      = true;
			txtPaymentState.readOnly      = true;			
			txtPaymentCity.readOnly       = true;
			txtPaymentPostalCode.readOnly = true;			
		} else {
			txtPaymentFirstName.readOnly  = false;
			txtPaymentLastName.readOnly   = false;
			txtPaymentAddress1.readOnly   = false;
			txtPaymentAddress2.readOnly   = false;
			txtPaymentPhone.readOnly      = false;
			txtPaymentState.readOnly      = false;			
			txtPaymentCity.readOnly       = false;
			txtPaymentPostalCode.readOnly = false;			
		}
	}
}


function checkShippingAndPaymentInfo()
{
	with (window.document.frmCheckout) {
		if (isEmpty(txtShippingFirstName, 'Enter first name')) {
			return false;
		} else if (isEmpty(txtShippingLastName, 'Enter last name')) {
			return false;
		} else if (isEmpty(txtShippingAddress1, 'Enter shipping address')) {
			return false;
		} else if (isEmpty(txtShippingPhone, 'Enter phone number')) {
			return false;
		} else if (isEmpty(txtShippingState, 'Enter shipping address state')) {
			return false;
		} else if (isEmpty(txtShippingCity, 'Enter shipping address city')) {
			return false;
		} else if (isEmpty(txtShippingPostalCode, 'Enter the shipping address postal/zip code')) {
			return false;
		} else if (isEmpty(txtPaymentFirstName, 'Enter first name')) {
			return false;
		} else if (isEmpty(txtPaymentLastName, 'Enter last name')) {
			return false;
		} else if (isEmpty(txtPaymentAddress1, 'Enter Payment address')) {
			return false;
		} else if (isEmpty(txtPaymentPhone, 'Enter phone number')) {
			return false;
		} else if (isEmpty(txtPaymentState, 'Enter Payment address state')) {
			return false;
		} else if (isEmpty(txtPaymentCity, 'Enter Payment address city')) {
			return false;
		} else if (isEmpty(txtPaymentPostalCode, 'Enter the Payment address postal/zip code')) {
			return false;
		} else {
			return true;
		}
	}
}

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("txtShippingAddress2").value = document.getElementById("txtBillAddress2").value;
		document.getElementById("ddlShippingState").value = document.getElementById("ddlBillState").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("txtShippingEmail").value = document.getElementById("txtBillEmail").value;
	}
	else
	{
		document.getElementById("txtShippingFirstName").value = "";
		document.getElementById("txtShippingLastName").value = "";
		document.getElementById("txtShippingAddress").value = "";
		document.getElementById("txtShippingAddress2").value = "";
		document.getElementById("ddlShippingState").value = "";
		document.getElementById("txtShippingCity").value = "";
		document.getElementById("txtShippingZipCode").value = "";
		document.getElementById("txtShippingPhone").value = "";
		document.getElementById("txtShippingEmail").value = "";
	}
}


function chkCheckout()
{
	var dom = document.form1;
	var rad_val;
	var flag ='no';
	
	
	//**************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 State
	if(dom.ddlBillState.value == "")
	{
		alert("Please enter billing state");
		dom.ddlBillState.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
	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;
	}
	
	// Email Validation
	var validate = email_valid(trim(dom.txtBillEmail.value));
	if(validate == false)
	{
		alert("Please Enter Valid Billing Email Address");
		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 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
	if(dom.txtShippingPhone.value == "")
	{
		alert("Please enter shipping phone no");
		dom.txtShippingPhone.focus();
		return false;
	}
	
	// Shipping Email
	validate = email_valid(trim(dom.txtShippingEmail.value));
	if(validate == false)
	{
		alert("Please Enter Valid Shipping Email Address");
		dom.txtShippingEmail.focus();
		return false;	
	}
	
	//**************SHIPPING FIELDS VALIDATION ENDS**************//
	
	if(dom.chkAgree.checked == false)
	{
		alert("Please agree to our Terms and Conditions.");
		dom.chkAgree.focus();
		return false;
	}
	
	for(i=0; i< dom.rdPaymentOption.length; i++)		
	{
		if(dom.rdPaymentOption[i].checked == true)
		{
			flag = 'yes';
		}
	}
	if(flag != 'yes')
	{
		alert("Please select payment method");
		dom.rdPaymentOption[0].focus();
		return false;
	}
}
//*****************************Function For Check Out Form Ends*****************************//
