// JavaScript Document

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: wsabstract.com | http://www.wsabstract.com */
function checkrequired(which) {
  var pass=true;
  for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
    if (tempobj.name.substring(0,8)=="required") {
      if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
        pass=false;
        break;
      }
    }
  }
  if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("The "+shortFieldName+" field is a required field.");
    return false;
  } else {
	  
  return true;
  }
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}


 var phone_len=0;
function nextTab(obj,evnt,len,next_obj) {
	if (evnt == "down") 
	{
		phone_len=obj.value.length;
	}
	else if (evnt == "up") {
		if (obj.value.length != phone_len) {
			phone_len=obj.value.length;
			if (phone_len == len) 
			{
				next_obj.focus();
			}
		}
	}
} 

function checkEmail(which,ffield)
{
  var pass=true;
  if (ffield.value.length == 0) {
  	 alert('Please enter a valid Email Address');
     return false;
  }
  if (ffield.value.length > 0) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = ffield.value;
    if(reg.test(address) == false) {
	  ffield.focus();
      alert('Please enter a valid Email Address');
      return false;
    }
  }
}


  function checkRegistrationRequiredFields(which) {  
   
   if (which.first_name.value.length <= 0)  {
		which.first_name.focus();
        alert("Please enter your first and last name");
        return false;
   }
   if (which.last_name.value.length <= 0)  {
		which.last_name.focus();
        alert("Please enter your first and last name");
        return false;
   }
   if (checkEmail(which,which.webtolead_email1) == false)
  		return false;
   if ((which.phoneAC.value.length != 3) || (IsNumeric(which.phoneAC.value) == false)) {
		which.phoneAC.focus();
        alert("Please enter a valid [phone #] area code");
        return false;
   }
   if ((which.phone1.value.length != 3) || (IsNumeric(which.phone1.value) == false)) {
   	
		which.phone1.focus();
        alert("Please enter a valid [phone #]");
        return false;
   }
   if ((which.phone2.value.length != 4) || (IsNumeric(which.phone2.value) == false)) {
		which.phone2.focus();
        alert("Please enter a valid [phone #]");
        return false;
   }
   if ((which.phoneExt.value.length > 0) || (IsNumeric(which.phoneExt.value) == false)) {
		which.phoneExt.focus();
        alert("Please enter a valid [phone extension #]");
        return false;
   }
	var phone = which.phoneAC.value;
	phone += "-"+which.phone1.value;
	phone += "-"+which.phone2.value;
	if (which.phoneExt.value.length > 0)
		phone += " x"+which.phoneExt.value;
	which.phone_work.value = phone;
	return true;
  }
