function validateFields() {
var frmEl = document.getElementById('regform');
var firstname = document.getElementById('firstname');
var lastname = document.getElementById('lastname');
var street = document.getElementById('street');
var city = document.getElementById('city');
var state = document.getElementById('state');
var zipcode = document.getElementById('zipcode');
var phone = document.getElementById('phone');
var email = document.getElementById('email');

var flag="noerror";
var message="";
 
       
          
            if(!isDigit(zipcode.value))
	     {

                 message += "Not A valide Zipcode \n";
                 flag="error";
             }    
            if(!isDigit(phone.value)) 
           {

              message += "Not A valide mobile number \n";
              flag="error";       
            }
            if(!isEmail(email.value))
	    {
  
                 message += "Email Address is not valid \n";
                 flag="error";
	   
            }
            
	   if(flag == "error")
	   {
		   alert(message);
		   return false;
	   }


        return true;	
 
	  
}

function isAlpha(str) {
   
    return /^\[a-z]+$/.test(str);
}
function isDigit(digit) {
             return /^\d+$/.test(digit);
}

function isEmail(emailid) {
       return /^([\w]+)(\.[\w]+)*@([\w\-]+)(\.[\w]{2,4})(\.[a-z]{2})?$/i.test(emailid);
}



function addevents() {
var frmEl = document.getElementById('regform');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load', addevents, false);



function isNull(eid) {
	var val = document.getElementById(eid).value;

	if(val == ""){
		alert("You can not leave this field blank");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
	}
	return true;
}

function verifyEmail(eid){
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

	 if (document.getElementById(eid).value.search(emailRegEx) == -1) {
		alert("Please enter a valid email address.");
		document.getElementById(eid).style.border = '1px solid #990000';
		document.getElementById(eid).focus();
		return false;
     }
     return true;
}

function validateSpecialOfferForm () {
	if(document.getElementById('companySelectCmb').value == -99){
		alert("You Must Select A Company To Sumbit");
		document.getElementById('companySelectCmb').focus();
		return false;
	}else{
		//validate if the given email is empty or not
		if(isNull('nameTxt')){
	
			//validate if the given email is empty or not
			if(isNull('emailTxt')){
				
				//validate if the given email address is valid or not
				if(verifyEmail('emailTxt')){
					
					//validate if the given password is empty or not
					if(isNull('phoneTxt')){
						
						// return true indicates that the form has been 
						// validated successfully
						return true;
					}
				}
			}
		}
	}
	return false;
}