
 var phone_field_length=0;

 function TabNext(obj,event,len,next_field){if(event == "down"){phone_field_length=obj.value.length;}else if(event == "up"){if(obj.value.length != phone_field_length){phone_field_length=obj.value.length;if(phone_field_length == len){ next_field.focus(); } } } } 

 function InitializeFieldColor() {       
    var validationColorWhite = '#ffffff'; 
    var elements = document.getElementsByTagName("form")[0];                           
    for (var i = 0; i < elements.length; i++) {  
                 if (  (elements[i].id.indexOf('Name')>-1) || (elements[i].id.indexOf('EMailFrom')>-1) || (elements[i].id.indexOf('Address_1')>-1) || (elements[i].id.indexOf('City')>-1) || 
                    (elements[i].id.indexOf('ddlState')>-1) || (elements[i].id.indexOf('Zip')>-1) || (elements[i].id.indexOf('Phone')>-1)  ){  
                            document.getElementById(elements[i].id).style.backgroundColor=validationColorWhite; 
                 }  
                 
     }                            
 }                                
 function checkFields() {  
 
    InitializeFieldColor(); 
    var validationMsg = '';var validationColor = '#ffeeee'; 
    if ((document.getElementById('Name').value.length==0) || (document.getElementById('Name').value.length==0)) {		validationMsg += "\nPlease enter your first and last name.";	document.getElementById('Name').style.backgroundColor=validationColor;document.getElementById('Name').style.backgroundColor=validationColor;}   
    if ((document.getElementById('EMailFrom').value.length<1) ||(!(isEmail(document.getElementById('EMailFrom').value)))) {		validationMsg += '\nPlease enter valid email address.';	document.getElementById('EMailFrom').style.backgroundColor=validationColor; }   
    if (document.getElementById('Address_1').value.length<1) {		validationMsg += '\nPlease enter your postal address.';	document.getElementById('Address_1').style.backgroundColor=validationColor;}   
    if (document.getElementById('City').value.length<1) {		validationMsg += '\nPlease enter your city.';	document.getElementById('City').style.backgroundColor=validationColor;}   
    if (document.getElementById('ddlState').selectedIndex<1) {		validationMsg += '\nPlease select your state.';	}   
    if (document.getElementById('Zip').value.length<1) { validationMsg += '\nPlease enter your  zip code.';	document.getElementById('Zip').style.backgroundColor=validationColor;}   
    else {   if (!(isValidUSPostalCode(document.getElementById('Zip').value))){  validationMsg += '\nPlease enter a valid U.S. zip code.'; document.getElementById('Zip').style.backgroundColor=validationColor; }		}                                                                      
    
    if ((document.getElementById('Phone').value.length<6)) {		
        validationMsg += '\nPlease enter a valid phone number - example: (234) 345-6789';	document.getElementById('Phone').style.backgroundColor=validationColor;  
    }   
    else{                             
        var phoneVal = document.getElementById('Phone').value;
        if (!(isPhoneNumber(phoneVal))){ validationMsg += '\nPlease enter a valid home phone number - example: (234) 345-6789 ';      }                                                     
    }                                   
                               
    if (validationMsg.length>0){ 		alert(validationMsg); 		return false; 		} 	return true; 
 }  
 
 function isEmail(strValue){ 
     var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; return objRegExp.test(strValue); 
  }    

  function isPhoneNumber(s) { 
    rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/); 
    return rePhoneNumber.test(s); 
  }
  function isValidUSPostalCode(elementValue) { 
    var zipCodePattern = new RegExp(/^\d{5}$|^\d{5}-\d{4}$/); 
    return zipCodePattern.test(elementValue); 
}




function checkSignup() {  
 
    InitializeFieldColor(); 
    var validationMsg = '';var validationColor = '#ffeeee'; 
    if ((document.getElementById('FirstName').value.length==0) || (document.getElementById('FirstName').value.length==0)) {		validationMsg += "\nPlease enter your first name.";	document.getElementById('FirstName').style.backgroundColor=validationColor;document.getElementById('FirstName').style.backgroundColor=validationColor;}   
   if ((document.getElementById('LastName').value.length==0) || (document.getElementById('LastName').value.length==0)) {		validationMsg += "\nPlease enter your last name.";	document.getElementById('LastName').style.backgroundColor=validationColor;document.getElementById('LastName').style.backgroundColor=validationColor;}    
    if ((document.getElementById('email').value.length<1) ||(!(isEmail(document.getElementById('email').value)))) {		validationMsg += '\nPlease enter valid email address.';	document.getElementById('email').style.backgroundColor=validationColor; }   
    if (document.getElementById('Address1').value.length<1) {		validationMsg += '\nPlease enter your postal address.';	document.getElementById('Address1').style.backgroundColor=validationColor;}   
    if (document.getElementById('City').value.length<1) {		validationMsg += '\nPlease enter your city.';	document.getElementById('City').style.backgroundColor=validationColor;}   
    if (document.getElementById('ddlState').selectedIndex<1) {		validationMsg += '\nPlease select your state.';	}   
    if (document.getElementById('Zip').value.length<1) { validationMsg += '\nPlease enter your zip code.';	document.getElementById('Zip').style.backgroundColor=validationColor;}   
    else {   if (!(isValidUSPostalCode(document.getElementById('Zip').value))){  validationMsg += '\nPlease enter a valid U.S. zip code.'; document.getElementById('Zip').style.backgroundColor=validationColor; }		}                                                                      
    
    if ((document.getElementById('PrimaryPhone').value.length<6)) {		
        validationMsg += '\nPlease enter a valid phone number - example: (234) 345-6789 ';	document.getElementById('PrimaryPhone').style.backgroundColor=validationColor;  
    }   
    else{                             
        var phoneVal = document.getElementById('PrimaryPhone').value;
        if (!(isPhoneNumber(phoneVal))){ validationMsg += '\nPlease enter a valid home phone number - example: (234) 345-6789 ';      }                                                     
    }                                   
                               
    if (validationMsg.length>0){ 		alert(validationMsg); 		return false; 		} 	return true; 
 }  

