// JavaScript Document
// ------------- This is Script For Admin Pages----------------------//


// Valid Email  Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:,?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

function checkout_validation()
{

	if(document.checkoutformout_frm.varEmail.value == "")
	{
		alert("Please enter the Email Address");
		document.checkoutformout_frm.varEmail.focus();
		return false;
	}
	if (!validateEmail(document.checkoutformout_frm.varEmail.value,1,1)) 
	 {
	 document.checkoutformout_frm.varEmail.focus();
	 return false;
	 }
	if(document.checkoutformout_frm.ConfirmEmail.value == "")
	{
		alert("Please enter the Confirm - Email Address");
		document.checkoutformout_frm.ConfirmEmail.focus();
		return false;
	}
	if(document.checkoutformout_frm.varEmail.value!= document.checkoutformout_frm.ConfirmEmail.value)
	{
		alert("Please enter correct Confirm - Email Address");
		document.checkoutformout_frm.ConfirmEmail.focus();
		return false;
	}
//------script for billing address --------------------------//
	if(document.checkoutformout_frm.varFirstName.value == "")
	{
		alert("Please enter the First Name");
		document.checkoutformout_frm.varFirstName.focus();
		return false;
	}
	if(document.checkoutformout_frm.varLastName.value == "")
	{
		alert("Please enter the LastName");
		document.checkoutformout_frm.varLastName.focus();
		return false;
	}
	if(document.checkoutformout_frm.varAddress.value == "")
	{
		alert("Please enter the  Address");
		document.checkoutformout_frm.varAddress.focus();
		return false;
	}
	if(document.checkoutformout_frm.varCity.value == "")
	{
		alert("Please enter the City");
		document.checkoutformout_frm.varCity.focus();
		return false;
	}
	if(document.checkoutformout_frm.varCountry.value =="Choose")
	{
		alert("Please choose the Country");
		document.checkoutformout_frm.varCountry.focus();
		return false;
	}
/*	if(document.checkout_frm.varState.value == "")
	{
		alert("Please enter the State");
		document.checkout_frm.varState.focus();
		return false;
	}
	
*/	
	if(document.checkoutformout_frm.varPostcode.value =="")
	{
		alert("Please enter the Zip code");
		document.checkoutformout_frm.varPostcode.focus();
		return false;
	}	
	if(isNaN(document.checkoutformout_frm.varPostcode.value))
	{
		alert("Zip Code Must be Numeric");
		document.checkoutformout_frm.varPostcode.focus();
		return false;
	}
	if(document.checkoutformout_frm.varPhoneNo.value == "")
	{
		alert("Please enter the Phone Number");
		document.checkoutformout_frm.varPhoneNo.focus();
		return false;
	}
// 	if(isNaN(document.checkout_frm.varPhoneNo.value))
// 	{
// 		alert("Phone Number Must ber Numeric");
// 		document.checkout_frm.varPhoneNo.focus();
// 		return false;
// 	}
//--------------Code for shipping address section-------------------//
	if(document.checkoutformout_frm.varShipFirstName.value == "")
	{
		alert("Please enter the First Name");
		document.checkoutformout_frm.varShipFirstName.focus();
		return false;
	}
	if(document.checkout_frm.varShipLastName.value == "")
	{
		alert("Please enter the LastName");
		document.checkoutformout_frm.varShipLastName.focus();
		return false;
	}
	
	if(document.checkoutformout_frm.varShipAddress.value == "")
	{
		alert("Please enter the  Address");
		document.checkoutformout_frm.varShipAddress.focus();
		return false;
	}
	if(document.checkoutformout_frm.varShipCity.value == "")
	{
		alert("Please enter the City");
		document.checkoutformout_frm.varShipCity.focus();
		return false;
	}
	if(document.checkoutformout_frm.varShipCountry.value == "")
	{
		alert("Please enter the Country");
		document.checkoutformout_frm.varShipCountry.focus();
		return false;
	}
/*	if(document.checkout_frm.varShipState.value =="")
	{
		alert("Please enter the State");
		document.checkout_frm.varShipState.focus();
		return false;
	}
*/	
	if(document.checkoutformout_frm.varShipZip.value =="")
	{
		alert("Please enter the Zip code");
		document.checkoutformout_frm.varShipZip.focus();
		return false;
	}	
	if(isNaN(document.checkoutformout_frm.varShipZip.value))
	{
		alert("Zip Code Must be Numeric");
		document.checkoutformout_frm.varShipZip.focus();
		return false;
	}
	if(document.checkoutformout_frm.varShipPhone.value == "")
	{
		alert("Please enter the Phone Number");
		document.checkoutformout_frm.varShipPhone.focus();
		return false;
	}
// 	if(isNaN(document.checkout_frm.varShipPhone.value))
// 	{
// 		alert("Phone Number Must ber Numeric");
// 		document.checkout_frm.varShipPhone.focus();
// 		return false;
// 	}
}
//script for Subscriber validation 
function subscriber_validation()
{
		 if (document.CustomersForm.varName.value== "" )
		 { 
			 alert ("Please Enter your Name");
			 document.CustomersForm.varName.focus();
			 return false;
		 }
		 if (document.CustomersForm.varEmail.value== "" )
		 { 
			 alert ("Please Enter Your E-mail Address");
			 document.CustomersForm.varEmail.focus();
			 return false;
		 }
		  if (!validateEmail(document.CustomersForm.varEmail.value,1,1)) 
		 {
		 document.CustomersForm.varEmail.focus();
		 return false;
		 }
		
}


