 $(document).ready(function(){
     $("#form-submit").click(function(event){
         var errorstring = "";
         $(":input").each(function(i) {
             name = $(this).attr("name");
             value = $(this).val();

             switch(name)
             {
                 case "Name":
                     if(value == "")
                       errorstring += "Please enter your name.\r\n";
                     break;
                 case "Telephone":
                     if(!isPhoneNumber(value))
                        errorstring += "Please enter a valid telephone number.\r\n";
                     break;
                 case "Email":
                     if(!isEmail(value))
                        errorstring += "Please enter a valid email address.\r\n";
                     break;
                 case "contact-about":
                     if(value == "unselected")
                         errorstring += "Please select the product you are interested in from the list.\r\n";
                     break;
             }
           
         });
         if(errorstring)
             alert(errorstring);
         else
            $("form:first").submit();
    });

    // contact us form
         $("#contact-us-submit").click(function(event){
         var errorstring = "";
         $(":input").each(function(i) {
             name = $(this).attr("name");
             value = $(this).val();

             switch(name)
             {
                 case "Name":
                     if(value == "")
                       errorstring += "Please enter your name.\r\n";
                     break;
                 case "Telephone":
                     if(!isPhoneNumber(value))
                        errorstring += "Please enter a valid telephone number.\r\n";
                     break;
                 case "Email":
                     if(!isEmail(value))
                        errorstring += "Please enter a valid email address.\r\n";
                     break;
                 case "Comments":
                     if(value == "")
                         errorstring += "Please enter your comments.\r\n";
                     break;
             }
           
         });
         if(errorstring)
             alert(errorstring);
         else
            $("#contact-us-form").submit();
    });
    
    
 });
 
function isEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

 function isPhoneNumber(TheNumber) {
	var valid = 1
	var GoodChars = "0123456789()-+ "
	var i = 0
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
			valid = 0
		} // End if statement
	} // End for loop
	return valid
}
 
 

