
var numb = '0123456789';
var space= ' ';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function isValid(parm,val) {
	if (parm.value == "")
	{
		return true;
	}
	for (i=0; i<parm.value.length; i++) 
	{
		if (val.indexOf(parm.value.charAt(i),0) == -1) 
		{
			return false;
		}
	}
	return true;
}
function isAlpha(parm) {
	return isValid(parm,lwr+upr+space);
}

function isNumber(parm) {return isValid(parm,numb);}

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}
function ValidateEmail(email){
	var atCharPresent = false;
	var dotPresent = false;

	for ( var Idx = 0; Idx < email.value.length; Idx++ ){
		if ( email.value.charAt ( Idx ) == '@' )
			atCharPresent = true;
		if ( email.value.charAt ( Idx ) == '.' )
			dotPresent = true;
	}
	if ( !atCharPresent || !dotPresent ){
		return false;
		}
return true;
}

function trimAll()
{

   document.contact_form.firstName.value = trim(document.contact_form.firstName.value);
   document.contact_form.Email.value = trim(document.contact_form.Email.value);
   document.contact_form.lastName.value = trim(document.contact_form.lastName.value);  
}

function trimTellAll()
{

   document.contactTell_form.yourname.value = trim(document.contactTell_form.yourname.value);
   document.contactTell_form.youremail.value = trim(document.contactTell_form.youremail.value);
   document.contactTell_form.yourphone.value = trim(document.contactTell_form.yourphone.value);
   document.contactTell_form.friendname.value = trim(document.contactTell_form.friendname.value);  
   document.contactTell_form.friendemail.value = trim(document.contactTell_form.friendemail.value); 
   document.contactTell_form.friendphone.value = trim(document.contactTell_form.friendphone.value); 
}

function trimEmail()
{

   document.email_form.name.value = trim(document.email_form.name.value);
   document.email_form.email.value = trim(document.email_form.email.value);
   document.email_form.name1.value = trim(document.email_form.name1.value);   
}
function trimFeedback()
{

   document.contact_index_form.name.value = trim(document.contact_index_form.name.value);
   document.contact_index_form.email.value = trim(document.contact_index_form.email.value);
   document.contact_index_form.name1.value = trim(document.contact_index_form.name1.value);   
   document.contact_index_form.companyname.value = trim(document.contact_index_form.companyname.value);  
}
function trimAffiliate()
{

   document.affiliate_form.name.value = trim(document.affiliate_form.name.value);
   document.affiliate_form.email.value = trim(document.affiliate_form.email.value);
   document.affiliate_form.name1.value = trim(document.affiliate_form.name1.value);   
   document.affiliate_form.companyname.value = trim(document.affiliate_form.companyname.value);  
}

function trimContactCall()
{

   document.contactCall_form.yourname.value = trim(document.contactCall_form.yourname.value);   
   document.contactCall_form.yourphone.value = trim(document.contactCall_form.yourphone.value);   
   
}

function vaidateForm(){
	var errorMessage = "";
	var check = 0;
	trimAll();
	chk = document.contact_form;
	if(chk.firstName.value == ""){
		check = check + 1;
		errorMessage += "Please enter First Name."+"\n";
		if (check == 1){
			chk.firstName.focus();
		}
	}else if(!isAlpha(chk.firstName))
	{
		check = check + 1;
		errorMessage += "First Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.firstName.focus();
		}
	}
	if(chk.lastName.value == ""){
		check = check + 1;
		errorMessage += "Please enter Last Name."+"\n";
		if (check == 1){
			chk.lastName.focus();
		}
	}else if(!isAlpha(chk.lastName))
	{
		check = check + 1;
		errorMessage += "Last Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.lastName.focus();
		}
	}
	if(chk.dayArea.value == "" ){
		check = check + 1;
		errorMessage += "Please enter Phone Number."+"\n";
		if (check == 1){
			chk.dayArea.focus();
		}
	}else if(chk.dayPrefix.value == ""){
		check = check + 1;
		errorMessage += "Please enter Phone Number."+"\n";
		if (check == 1){
			chk.dayPrefix.focus();
		}
	}else if(chk.daySuffix.value == ""){
		check = check + 1;
		errorMessage += "Please enter Phone Number."+"\n";
		if (check == 1){
			chk.daySuffix.focus();
		}
	}else if(chk.dayArea.value <100)
	{
		
		check = check + 1;
		errorMessage += "Phone Number must be 10 digits."+"\n";
		if (check == 1)
		{
			chk.dayArea.focus();
		}
	}
	else if(chk.dayPrefix.value <100)
	{
		check = check + 1;
		errorMessage += "Phone Number must be 10 digits."+"\n";
		if (check == 1)
		{
			chk.dayPrefix.focus();
		}
	}
	else if(chk.daySuffix.value <1000)
	{
		check = check + 1;
		errorMessage += "Phone Number must be 10 digits."+"\n";
		if (check == 1)
		{
			chk.daySuffix.focus();
		}
	}else if(!isNumber(chk.dayArea))
 	{
 		check = check + 1;
 		errorMessage += "Phone Number must be numeric."+"\n";
 		if (check == 1)
 		{
 			chk.dayArea.focus();
 		}
	}else if(!isNumber(chk.dayPrefix))
 	{
 		check = check + 1;
 		errorMessage += "Phone Number must be numeric."+"\n";
 		if (check == 1)
 		{
 			chk.dayPrefix.focus();
 		}
	}else if(!isNumber(chk.daySuffix))
 	{
 		check = check + 1;
 		errorMessage += "Phone Number must be numeric."+"\n";
 		if (check == 1)
 		{
 			chk.daySuffix.focus();
 		}
	}
	
	if(chk.Email.value == ""){
			check = check + 1;
			errorMessage += "Email address is required."+"\n";
			if (check == 1){
				chk.Email.focus();
		}
	}else if(! ValidateEmail(chk.Email)){
			check = check + 1;
			errorMessage += "Invalid Email address. Format of email address should be name@domain.com."+"\n";
			if (check == 1){
				chk.Email.focus();
		}
	}
	
	if(chk.state.value == ""){
			check = check + 1;
			errorMessage += "Please select the State of Residence."+"\n";
			if (check == 1){
				chk.state.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors.\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {		
		return true;
	}
}

function vaidateTellForm()
{
	var errorMessage = "";
	var check = 0;
	trimTellAll();
	chk = document.contactTell_form;
	if(chk.yourname.value == "")
	{
	}
	else if(!isAlpha(chk.yourname))
	{
		check = check + 1;
		errorMessage += "Your Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.firstName.focus();
		}
	}
	if(chk.youremail.value == "")
	{
	}
	else if(! ValidateEmail(chk.youremail))
	{
		check = check + 1;
		errorMessage += "Your email address is an invalid email address."+"\n";
		if (check == 1)
		{
			chk.youremail.focus();
		}
	}
	
	if(chk.yourphone.value == "")
	{
	}
	else if(!isNumber(chk.yourphone))
	{
		check = check + 1;
		errorMessage += "Your phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}else if(chk.yourphone.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}
	
	if(chk.friendname.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your friends name."+"\n";
		if (check == 1)
		{
			chk.friendname.focus();
		}
	}else if(!isAlpha(chk.friendname))
	{
		check = check + 1;
		errorMessage += "Friends name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.friendname.focus();
		}
	}
	if(chk.friendemail.value == ""){
		check = check + 1;
		errorMessage += "Please enter your friends email address."+"\n";
		if (check == 1)
		{
			chk.friendemail.focus();
		}
	}else if(! ValidateEmail(chk.friendemail))
	{
	
		check = check + 1;
		errorMessage += "Your friends email address is invalid."+"\n";
		if (check == 1){
			chk.friendemail.focus();
		}
	}
	
	if(chk.friendphone.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your friends phone number."+"\n";
		if (check == 1)
		{
			chk.friendphone.focus();
		}
	}else if(!isNumber(chk.friendphone))
	{
		check = check + 1;
		errorMessage += "Friends phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.friendphone.focus();
		}
	}else if(chk.friendphone.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your friend phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.friendphone.focus();
		}
	}	
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}



function vaidateEmailForm()
{
	var errorMessage = "";
	var check = 0;
	trimEmail();
	chk = document.email_form;

	if(chk.name.value == ""){
		check = check + 1;
		errorMessage += "Please enter your Name."+"\n";
		if (check == 1){
			chk.name.focus();
		}
	}else if(!isAlpha(chk.name))
	{
		check = check + 1;
		errorMessage += "Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.name.focus();
		}
	}
	if(chk.email.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your Email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}else if(! ValidateEmail(chk.email))
	{
		check = check + 1;
		errorMessage += "Email address is an invalid email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}

	if(chk.name1.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your phone number."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(!isNumber(chk.name1))
	{
		check = check + 1;
		errorMessage += "Phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(chk.name1.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}



function vaidateaffiliateForm()
{
	var errorMessage = "";
	var check = 0;
	trimAffiliate();
	chk = document.affiliate_form;

	if(chk.name.value == ""){
		check = check + 1;
		errorMessage += "Please enter your Name."+"\n";
		if (check == 1){
			chk.name.focus();
		}
	}else if(!isAlpha(chk.name))
	{
		check = check + 1;
		errorMessage += "Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.name.focus();
		}
	}
	if(chk.email.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your Email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}else if(! ValidateEmail(chk.email))
	{
		check = check + 1;
		errorMessage += "Email address is an invalid email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}

	if(chk.name1.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your phone number."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(!isNumber(chk.name1))
	{
		check = check + 1;
		errorMessage += "Phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(chk.name1.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}
	
	if(chk.companyname.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your company name."+"\n";
		if (check == 1)
		{
			chk.companyname.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}

function vaidatefeedbackForm()
{
	var errorMessage = "";
	var check = 0;
	trimFeedback();
	chk = document.contact_index_form;

	if(chk.name.value == ""){
		check = check + 1;
		errorMessage += "Please enter your Name."+"\n";
		if (check == 1){
			chk.name.focus();
		}
	}else if(!isAlpha(chk.name))
	{
		check = check + 1;
		errorMessage += "Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.name.focus();
		}
	}
	if(chk.email.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your Email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}else if(! ValidateEmail(chk.email))
	{
		check = check + 1;
		errorMessage += "Email address is an invalid email address."+"\n";
		if (check == 1)
		{
			chk.email.focus();
		}
	}

	if(chk.name1.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your phone number."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(!isNumber(chk.name1))
	{
		check = check + 1;
		errorMessage += "Phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}else if(chk.name1.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.name1.focus();
		}
	}
	
	if(chk.companyname.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your company name."+"\n";
		if (check == 1)
		{
			chk.companyname.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}

function validateCallMeForm()
{
	var errorMessage = "";
	var check = 0;
	trimContactCall();
	chk = document.contactCall_form;

	if(chk.yourname.value == ""){
		check = check + 1;
		errorMessage += "Please enter your Name."+"\n";
		if (check == 1){
			chk.yourname.focus();
		}
	}else if(!isAlpha(chk.yourname))
	{
		check = check + 1;
		errorMessage += "Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.yourname.focus();
		}
	}
	
	if(chk.yourphone.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your phone number."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}else if(!isNumber(chk.yourphone))
	{
		check = check + 1;
		errorMessage += "Phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}else if(chk.yourphone.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}

function validateContactMeForm()
{
	var errorMessage = "";
	var check = 0;
	trimContactCall();
	chk = document.contactCall_form;

	if(chk.yourname.value == ""){
		check = check + 1;
		errorMessage += "Please enter your Name."+"\n";
		if (check == 1){
			chk.yourname.focus();
		}
	}else if(!isAlpha(chk.yourname))
	{
		check = check + 1;
		errorMessage += "Name should be only alpha characters (A to Z)."+"\n";
		if (check == 1)
		{
			chk.yourname.focus();
		}
	}
	
	if(chk.yourphone.value == "")
	{
		check = check + 1;
		errorMessage += "Please enter your phone number."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}else if(!isNumber(chk.yourphone))
	{
		check = check + 1;
		errorMessage += "Phone number must be numeric."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}else if(chk.yourphone.value.length != 10)
	{
		check = check + 1;
		errorMessage += "Your phone number must be 10 digits long."+"\n";
		if (check == 1)
		{
			chk.yourphone.focus();
		}
	}
	
	if (errorMessage.length != 0)
	{
		errorMessage = "Please correct the following errors."+ "\n" + errorMessage; 
		alert(errorMessage);
		return false;
	} else {
		return true;
	}
}
