function checkForm() {

        var isGood = true;

	var fname = document.getElementById("firstname").value;
	var lname = document.getElementById("lastname").value;
	var company = document.getElementById("company").value;
	var phone = document.getElementById("phone").value;
	var email = document.getElementById("email").value;

	if (fname == "" || lname == "" || company == "" || phone == "" || email == "" ) {
		alert("All form should be completed in order to submit.");
		return false;
	}

	if (!IsEmail(email)) {
		alert("Invalid email.  Email address should be in this format: user@domain.com");
		return false;
	}

	if (!IsAlpha(fname)) {
		alert("Invalid name.  Name should contain only letters.");
		return false;
	}
	if (!IsAlpha(lname)) {
		alert("Invalid name.  Name should contain only letters.");
		return false;
	}

        return isGood;

}

function IsAlpha(name) {

return(name.match(/^[a-zA-Z\s+]+$/));

}

function IsAlphaa(company) {

return(company.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();
	}

}

