function form_validate(theForm)
{
if (theForm.fromvisitor.value == "")
  {
    alert("Please enter a value for the \" Name.\" field.");
    theForm.fromvisitor.focus();
    return (false);
  }

    
  if (theForm.vistoremail.value == "")
  {
    alert("Please enter a value for the \"E-mail address required.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }

  if (theForm.vistoremail.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"E-mail address to short.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }

  if (theForm.vistoremail.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"E-mail address to long.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }


if (echeck(theForm.vistoremail.value)==false){
  theForm.vistoremail.value=""
		theForm.vistoremail.focus()
		return (false);
  }
if (theForm.mess.value.length < 10)
  {
    alert("Please enter at most 10 characters in the \"Message\" field.");
    theForm.mess.focus();
    return (false);
  }
  
  if (theForm.mess.value.value == "")
  {
    alert("Please enter a value for the \"Message required.\" field.");
    theForm.mess.focus();
    return (false);
  }
  
  if (theForm.result_code.value == "")
  {
    alert("Code cannot be blank");
    theForm.result_code.focus();
    return (false);
  }
  
  if (BothFieldsIdenticalCaseSensitive(theForm.result_code.value, theForm.random_code.value)==false)
  {  
  theForm.result_code.value=""
		theForm.result_code.focus()
		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);
		 }
					
	}
	
	function BothFieldsIdenticalCaseSensitive(str1, str2) {
var one = str1;
var another = str2;
if(one != another) { 
alert("Oops, both passwords must be identical.");
return (false);
}
}




