sfHover = function() {
	var sfEls = document.getElementById("header").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function checkForm() {

        var isGood = true;

	var name = document.getElementById("name").value;
	var name2 = document.getElementById("name2").value;
	var wp1 = document.getElementById("wp1").value;
	var wp2 = document.getElementById("wp2").value;
	var wp3 = document.getElementById("wp3").value;
	var email = document.getElementById("email").value;

	if (name == "" || name == "Name" || name2 == "Lastname" || email == "Email" || wp1 == "" || wp2 == "" || wp3 == "") {
		alert("All form should be completed in order to submit.");
		return false;
	}

	if (!IsNumeric(wp1) || !IsNumeric(wp2) || !IsNumeric(wp3)) {
		alert("Invalid phone number.  This field should contain only numbers.");
		return false;
	}

	if (!IsEmail(email)) {
		alert("Invalid email.  Email address should be in this format: user@domain.com");
		return false;
	}

	if (!IsAlpha(name)) {
		alert("Invalid name.  Name should contain only letters.");
		return false;
	}
	if (!IsAlphaa(name2)) {
		alert("Invalid lastname.  Lastname should contain only letters.");
		return false;
	}

        return isGood;

}

function IsAlpha(alpha) {

return(alpha.match(/^[a-zA-Z]+$/));

}

function IsAlphaa(alphaa) {

return(alphaa.match(/^[a-zA-Z]+$/));

}

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;
   
}

function IsEmail(emailString) {

return(emailString.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/));

}


function switch_image(image, which_image) {

	if (which_image == "submit") {
		image.src = "images/getEstimate_bottom_green.jpg";	
	}
	else if (which_image == "getEstimate") {
		image.src = "images/getEstimate_bottom_over_Green.jpg";	
	}


}

function validate_and_submit() {


	if (checkForm()) {
		document.fm.submit();
	}

}
