function checkfields() {

   strfield1 = document.contactform.firstname.value;
   strfield2 = document.contactform.lastname.value;
   strfield3 = document.contactform.areacode.value;
   strfield4 = document.contactform.localcode.value;
   strfield5 = document.contactform.phonenumber.value;
   strfield6 = document.contactform.email.value;
   strfield7 = document.contactform.street.value;
   strfield8 = document.contactform.city.value;
   strfield9 = document.contactform.state.value;
   strfield10 = document.contactform.zip.value;
   strfield11 = document.contactform.comments.value;
   strfield12 = document.contactform.random.value;

   if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') {

      alert("\"First name\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.firstname.focus();
      ElementPosition ( document.getElementsByName("firstname") );
      return false;

   } else if (strfield2 == "" || strfield2 == null || !isNaN(strfield2) || strfield2.charAt(0) == ' ') {

      alert("\"Last name\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.lastname.focus();
      ElementPosition ( document.getElementsByName("lastname") );
      return false;

   } else if (strfield3 == "" || strfield3 == null || isNaN(strfield3) || strfield3.charAt(0) == ' ') {

      alert("\"Phone Number\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.areacode.focus();
      ElementPosition ( document.getElementsByName("areacode") );
      return false;

   } else if (strfield4 == "" || strfield4 == null || isNaN(strfield4) || strfield4.charAt(0) == ' ') {

      alert("\"Phone Number\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.localcode.focus();
      ElementPosition ( document.getElementsByName("localcode") );
      return false;

   } else if (strfield5 == "" || strfield5 == null || isNaN(strfield5) || strfield5.charAt(0) == ' ') {

      alert("\"Phone Number\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.phonenumber.focus();
      ElementPosition ( document.getElementsByName("phonenumber") );
      return false;

   } else if ( !isValidEmail(strfield6) ) {

      return false;

   } else if (strfield7 == "" || strfield7 == null || !isNaN(strfield7) || strfield7.charAt(0) == ' ') {

      alert("\"Address\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.street.focus();
      ElementPosition ( document.getElementsByName("street") );
      return false;

   } else if (strfield8 == "" || strfield8 == null || !isNaN(strfield8) || strfield8.charAt(0) == ' ') {

      alert("\"Address\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.city.focus();
      ElementPosition ( document.getElementsByName("city") );
      return false;

   } else if (strfield9 == "" || strfield9 == null || !isNaN(strfield9) || strfield9.charAt(0) == ' ') {

      alert("\"Address\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.state.focus();
      ElementPosition ( document.getElementsByName("state") );
      return false;

   } else if (strfield10 == "" || strfield10 == null || isNaN(strfield10) || strfield10.charAt(0) == ' ') {

      alert("\"Address\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.zip.focus();
      ElementPosition ( document.getElementsByName("zip") );
      return false;

   } else if (strfield11 == "" || strfield11 == null || !isNaN(strfield11) || strfield11.charAt(0) == ' ') {

      alert("\"Comments\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.comments.focus();
      ElementPosition ( document.getElementsByName("comments") );
      return false;

   } else if (strfield12 == "" || strfield12 == null || strfield12.charAt(0) == ' ') {

      alert("\"Verification\" is a mandatory field.\nPlease amend and retry.");
      document.contactform.random.focus();
      ElementPosition ( document.getElementsByName("random") );
      return false;

   }

   return true;

}

function isValidEmail(strEmail){

   validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
   strEmail = document.contactform.email.value;

   // search email text for regular exp matches
   if (strEmail.search(validRegExp) == -1) {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      document.contactform.email.focus();
      ElementPosition ( document.getElementsByName("email") );
      return false;
   } 
   return true; 

}		     

function ElementPosition(errorElement){  

    elemPosX = errorElement.offsetLeft;  
    elemPosY = errorElement.offsetTop;  
    theElement = errorElement.offsetParent;  
    while(theElement != null){  
      elemPosY += theElement.offsetTop;  
      theElement = theElement.offsetParent;  
    }  
    window.scrollTo(0,elemPosY);  

}

function CheckAreaCode(obj) {

   if (obj.value.length == 3) {

      document.contactform.localcode.focus();

   }

}

function CheckPrefix(obj) {

   if (obj.value.length == 3) {

      document.contactform.phonenumber.focus();

   }

}
