function checkSubmit()
{
	data = document.learnmore;
	if (!checkfield(data.firstname,'First Name')) return;
	if (!checkfield(data.lastname,'Last Name')) return;
	if (!checkfield(data.company,'Company')) return;
	if (!ValidateEMail(data.email,'Email Address')) return;
	if (!checkfield(data.phone,'Phone')) return;
	data.submit();
}

function checkSubmit2()
{
	data = document.referral;
 	if (!checkfield(data.contactname,'Vendor Contact Name')) return;
	if (!checkfield(data.title,'Vendor Title')) return;
	if (!checkfield(data.company,'Vendor Company')) return;
	if (!checkfield(data.address,'Vendor Address')) return;
	if (!checkfield(data.city,'Vendor City')) return;
 	if (!checkfield(data.state,'Vendor State')) return;
	if (!checkfield(data.zip,'Zip')) return;
	if (!ValidateEMail(data.email,'Vendor Email Address')) return;
	if (!checkfield(data.phone,'Vendor Phone')) return;
 	if (!checkfield(data.fax,'Vendor Fax')) return;
	if (!checkfield(data.relationship,'Vendor Relationship')) return;
	if (!checkfield(data.industry,'Vendor Industry')) return;
	if (!checkfield(data.description,'Description')) return;
	if (!checkfield(data.referrename,'Your Contact Name')) return;
 	if (!checkfield(data.referreCompany,'Your Company')) return;
	if (!checkfield(data.referreAddress,'Your Address')) return;
	if (!checkfield(data.referreCity,'Your City')) return;
	if (!checkfield(data.referreState,'Your State')) return;
	if (!checkfield(data.referreZip,'Your Zip')) return;
	if (!ValidateEMail(data.referreEmail,'Your Email Address')) return;
	if (!checkfield(data.referrePhone,'Your Phone')) return;
	if (!checkfield(data.referreFax,'Your Fax')) return;

	data.submit();
}

function checkfield(fieldname, fieldLabel)
{
	if (trimVar(fieldname.value) == '')
	  {
	  	alert('Please enter your '+fieldLabel+' in order to continue');
		fieldname.focus();
		return false;
	  }
	return true;
}

function trimVar(txt)
{
	// trim leading spaces
	while(''+txt.charAt(0)==' ')
		txt=txt.substring(1,txt.length);		
		
	// trim trailing spaces
	while(''+txt.charAt(txt.length-1)==' ')
		txt=txt.substring(0,txt.length-1);
			
	return 	txt;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEMail(emailID){
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
