function fcheck(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      alert('Invalid E-mail ID');
      return false;
   }
}

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 validateForm(form) { //This is the name of the function

if (form.companyname.value == "") { //This checks to make sure the field is not empty
   alert("Company is required to process this form."); //Informs user of empty field
   form.companyname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (form.firstname.value == "") { //This checks to make sure the field is not empty
   alert("First Name is required to process this form."); //Informs user of empty field
   form.firstname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

if (form.lastname.value == "") { //This checks to make sure the field is not empty
   alert("A Last Name is required to process this form."); //Informs user of empty field
   form.lastname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (form.address1.value == "") { //This checks to make sure the field is not empty
   alert("An address is required to process this form."); //Informs user of empty field
   form.address1.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (form.areacode.value == "") { //This checks to make sure the field is not empty
   alert("A Phone Number (Area Code) is required to process this form."); //Informs user of empty field
   form.areacode.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

if (form.prefix.value == "") { //This checks to make sure the field is not empty
   alert("A Phone Number (Prefix) is required to process this form."); //Informs user of empty field
   form.prefix.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (form.suffix.value == "") { //This checks to make sure the field is not empty
   alert("A Phone Number (Suffix) is required to process this form."); //Informs user of empty field
   form.suffix.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (form.faxareacode.value == "") { //This checks to make sure the field is not empty
   alert("A Fax number (Area Code) is required to process this form"); //Informs user of empty field
   form.faxareacode.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

if (form.faxprefix.value == "") { //This checks to make sure the field is not empty
   alert("A Fax number (Prefix) is required to process this form"); //Informs user of empty field
   form.faxprefix.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

if (form.faxsuffix.value == "") { //This checks to make sure the field is not empty
   alert("A Fax number (Suffix) is required to process this form"); //Informs user of empty field
   form.faxsuffix.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
if (form.captcha.value == "") { //This checks to make sure the field is not empty
   alert("The image value is to be entered "); //Informs user of empty field
   form.captcha.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

if (form.email.value == "") { //This checks to make sure the field is not empty
   alert("An email address is required to process this form."); //Informs user of empty field
   form.email.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
if (echeck(form.email.value)==false){
	form.email.value=""
	form.email.focus()
	return false;
	}

if (fcheck('form1', 'email')==false){
	form.email.value=""
	form.email.focus()
	return false;
	}

   if (form.username.value == "") { //This checks to make sure the field is not empty
   alert("A username is required to process this form."); //Informs user of empty field
   form.username.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
   if (form.password.value == "") { //This checks to make sure the field is not empty
   alert("A password is required to process this form."); //Informs user of empty field
   form.password.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function SubmitAgreement()
{
document.form2.action ="/registration/3/";
document.form2.submit();
}


