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() { //This is the name of the function
if (document.form1.contactname.value == "") { //This checks to make sure the field is not empty
   alert("Name is required to process this form."); //Informs user of empty field
   document.form1.contactname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
if (document.form1.contactemail.value == "") { //This checks to make sure the field is not empty
   alert("Email is required to process this form."); //Informs user of empty field
   document.form1.contactemail.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     
if (echeck(document.form1.contactemail.value)==false){
	document.form1.contactemail.value="";
	document.form1.contactemail.focus();
	return false;
	}
 if (document.form1.captcha.value == "") { //This checks to make sure the field is not empty
   alert("captcha is required to process this form."); //Informs user of empty field
   document.form1.captcha.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   document.form1.action="church-referral-program.cfm?p=3";   
}
function refreshCaptcha()
{
	document.form1.action = "church-referral-program.cfm?p=2&reinit=true";
	document.form1.submit();
}
