// JavaScript Document

//Discoutn Updateion validation
function updt_disc_validt()
{
	  if (document.buy_form.varVouchercode.value== "" )
		 { 
			 alert ("Please Enter the Vouchercode");
			 document.buy_form.varVouchercode.focus();
			 return false;
		 }
		 
	 document.buy_form.submit();
	 document.buy_form.action="pay.php";
	 
}

//script for Subscriber validation 
function subscriber_validation()
{
		 if (document.CustomersForm.varName.value== "" )
		 { 
			 alert ("Please Enter the Name");
			 document.CustomersForm.varName.focus();
			 return false;
		 }
		if (document.CustomersForm.varEmail.value== "" )
		 { 
			 alert ("Please Enter the E-mail Address");
			 document.CustomersForm.varEmail.focus();
			 return false;
		 }
		  if (!validateEmail(document.CustomersForm.varEmail.value,1,1)) 
		 {
		 document.CustomersForm.varEmail.focus();
		 return false;
		 }
		
}

//script for Subscriber validation 
function contact_validate()
{
		 if (document.contactfrm.varName.value== "" )
		 { 
			 alert ("Please Enter the Name");
			 document.contactfrm.varName.focus();
			 return false;
		 }
		if (document.contactfrm.varEmail.value== "" )
		 { 
			 alert ("Please Enter the E-mail Address");
			 document.contactfrm.varEmail.focus();
			 return false;
		 }
		  if (!validateEmail(document.contactfrm.varEmail.value,1,1)) 
		 {
		 document.contactfrm.varEmail.focus();
		 return false;
		 }
		
}


//script for Subscriber validation 
function paymentoption_validt()
{
		 if (document.paymentoption.payoption[0].checked == false && document.paymentoption.payoption[1].checked == false)
		 { 
			 alert ("Please choose the  PAYPAL or 2CHECKOUT payment type");
			 document.paymentoption.payoption[0].focus();
			 return false;
		 }
			
}


//script for PAY FORM validation 
function buyfrm_validation()
{
		  if (document.buy_form.varCompany.value== "" )
		 { 
			 alert ("Please Enter the Company Name");
			 document.buy_form.varCompany.focus();
			 return false;
		 }
		 if (document.buy_form.varFName.value== "" )
		 { 
			 alert ("Please Enter the First Name");
			 document.buy_form.varFName.focus();
			 return false;
		 }
		  if (document.buy_form.varSurname.value== "" )
		 { 
			 alert ("Please Enter the Surname");
			 document.buy_form.varSurname.focus();
			 return false;
		 }
		 if (document.buy_form.varEmail.value== "" )
		 { 
			 alert ("Please Enter the E-mail Address");
			 document.buy_form.varEmail.focus();
			 return false;
		 }
		  if (!validateEmail(document.buy_form.varEmail.value,1,1)) 
		 {
		 document.buy_form.varEmail.focus();
		 return false;
		 }
		 if (document.buy_form.varConfirmemail.value== "" )
		 { 
			 alert ("Please Enter the Confirm E-mail Address");
			 document.buy_form.varConfirmemail.focus();
			 return false;
		 }
		  if (document.buy_form.varConfirmemail.value !=  document.buy_form.varEmail.value)
		 { 
			 alert ("Email and Confirm E-mail Address must be same. Please enter the same email address");
			 document.buy_form.varConfirmemail.focus();
			 return false;
		 }
		  if (document.buy_form.varCountry.value== "Choose" )
		 { 
			 alert ("Please Choose the Country Name");
			 document.buy_form.varCountry.focus();
			 return false;
		 }
		  if (document.buy_form.textfield.value == "0" || document.buy_form.textfield.value == "" )
		 { 
			 alert ("Please enter the valide Quantity Retail sale system");
			 document.buy_form.textfield.focus();
			 return false;
		 }
		  if (document.buy_form.textfield3.value == "" )
		 { 
			 alert ("Please enter the valide Quantity for Extra Multi user");
			 document.buy_form.textfield3.focus();
			 return false;
		 }
		   if (document.buy_form.textfield.value == "0" && document.buy_form.textfield3.value == "0" || document.buy_form.textfield.value == "" && document.buy_form.textfield3.value == "" )
		 { 
			 alert ("Please enter the valide Quantity ");
			 document.buy_form.textfield.focus();
			 return false;
		 }
		 
		document.buy_form.action="payinsert.php";
		document.buy_form.submit();
}

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 tabOnEnter (field, evt) {
       var keyCode = document.layers ? evt.which : document.all ?
     evt.keyCode : evt.keyCode;
       if (keyCode != 13 && keyCode !=9)
         return true;
       else {
         var el=getNextElement(field);
         if (el.type!='hidden')
            el.focus(); 
         else
            while (el.type=='hidden')
               el=getNextElement(el); 
            el.focus(); 
         return false;
       }
     }
function getNextElement (field) {
       var form = field.form;
       for (var e = 0; e < form.elements.length; e++) { 
         if (field == form.elements[e])
             break;
       }
       return form.elements[++e % form.elements.length];
     }
