function form_validate(theForm)
{
if (theForm.friendname.value == "")
  {
    alert("Please enter a value for the \"Friends Name\" field.");
    theForm.friendname.focus();
    return (false);
  }
if (theForm.friendname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \Friends Name\" field.");
    theForm.friendname.focus();
    return (false);
  }
  
  if (theForm.vistoremail.value == "")
  {
    alert("Please enter a value for the \"Your E-mail address\" field.");
    theForm.vistoremail.focus();
    return (false);
  }

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

  if (theForm.vistoremail.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Your E-mail address\" field.");
    theForm.vistoremail.focus();
    return (false);
  }
  if (echeck(theForm.vistoremail.value)==false)
  {
  theForm.vistoremail.value=""
		theForm.vistoremail.focus()
		return (false);
  } 
  if (theForm.friendemail.value == "")
  {
    alert("Please enter a value for the \"Friends E-mail address required.\" field.");
    theForm.friendemail.focus();
    return (false);
  }

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

  if (theForm.friendemail.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Friends E-mail address required.\" field.");
    theForm.friendemail.focus();
    return (false);
  }
  
  if (echeck(theForm.friendemail.value)==false)
  {
  theForm.friendemail.value=""
		theForm.friendemail.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.edit_user_pass2.value == "")
  {
    alert("Code cannot be blank");
    theForm.edit_user_pass2.focus();
    return (false);
  }
  
  if (BothFieldsIdenticalCaseSensitive(theForm.edit_user_pass.value, theForm.edit_user_pass2.value)==false)
  {  
  theForm.edit_user_pass2.value=""
		theForm.edit_user_pass2.focus()
		return (false);
  } 
					
	}//  end function
	
	
	
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);
		 }
		 
		 } //end function
		 
		 function BothFieldsIdenticalCaseSensitive(str1, str2) {
var one = str1;
var another = str2;
if(one != another) { 
alert("Oops, both codes must be identical.");
return (false);
}
}
