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

  if (theNews.firstname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"First Name required.\" field.");
    theNews.firstname.focus();
    return (false);
  }
  
  if (theNews.lastname.value == "")
  {
    alert("Please enter a value for the \"Last Name required.\" field.");
    theNews.lastname.focus();
    return (false);
  }

  if (theNews.lastname.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Last Name required.\" field.");
    theNews.lastname.focus();
    return (false);
  }
  
 

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

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

  if (theNews.email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"E-mail adress required.\" field.");
    theNews.email.focus();
    return (false);
  }
 if (echeck(theNews.email.value)==false){
  theNews.email.value=""
		theNews.email.focus()
		return (false);
  } 
 if (theNews.result_code.value == "")
  {
    alert("Please enter a value for the CODE field.");
    theNews.result_code.focus();
    return (false);
  }
 if (BothFieldsIdenticalCaseInsensitive(theNews.random_code.value, theNews.result_code.value)==false){
  theNews.result_code.value=""
		theNews.result_code.focus()
		return (false);
		  }

}

function BothFieldsIdenticalCaseInsensitive() {
var one = document.theNews.random_code.value.toLowerCase();
var another = document.theNews.result_code.value.toLowerCase();
if(one == another) { return true; }
alert("Oops, both fields must be identical.");
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);
		 }
					
	}

