$(document).ready(function(){
						   
	//Removed classes to avoid conflicts
	$("#fax").removeClass("short"); 
	$("#fax").removeClass("txtbox");
	
	
	//Validations for the contact form
	$("form#cform").submit(function(){
		
		//Make sure the user select one of the radio button before moving on
		if($("input:radio[name=requests]:checked").length < 1){
			$("input:radio[@name=requests]").css("border", "1px solid red");
			$("#submit_error").text("Please select your inquiry");
			$("#submit_error").fadeTo("fast", 1);
			$("#submit_error").fadeTo(3000, 0.01);
			
			$(this).click(function(){
				$("input:radio[@name=requests]").css("border", "none");				   
			});
			return false;
		} else {
			
			//Function to be reuse throughout the validation process
			//fieldId is the ID of the field
			//e_msg is the second arrgument that displays the error message
			function error(fieldId, e_msg){
				fieldId.focus(function(){
					fieldId.css("border", "1px solid #dddddd");					  
				});
				$("#submit_error").empty();
				fieldId.css("border", "1px solid #dddddd");
				$("#submit_error").text(e_msg);
				$("#submit_error").fadeTo("fast", 1);
				$("#submit_error").fadeTo(3000, 0.01);
				fieldId.css("border", "1px solid red");
			}
			
			//Validation the name field, make sure it is filled and at least has 5 characters
			if($("#name").val() == '' || $("#name").val().length <= 5){
				error($("#name"), "Please fill out your full name");
				return false;
			}
			
			//Regular Express for a valid email address
			emailReg = /^[\w\.=-]+@[\w\.-]+\.[\w]{2,3}$/;
			
			//Validate email address to make sure it is filled and has the @ sign and a domain name
			if($("#email").val() == '' || $("#email").val().match(emailReg) == null){
				error($("#email"), "Please enter a valid email");
				return false;
			}
			
			//Validate the address field make sure it is not empty and have at least 10 characters
			if($("#address1").val() == '' || $("#address1").val().length <= 10){
				error($("#address1"), "Please enter your full street address");
				return false;
			}
			
			//Validate the city field that it is not empty and more than 2 characters long
			if($("#city").val() == '' || $("#city").val().length <= 2){
				error($("#city"), "Please enter city");
				return false;
			}
			
			//Make sure the state field is not empty
			if($("#state").val() == ''){
				error($("#state"), "Please enter a state");
				return false;
			}
			
			//Array for a list of 52 states
			var states = ["AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NC","ND","NM","OK","OH","OR","PA","RI","NY","SC","SD","TN","TX","VA","WA","WI","WY"];
			
			//Make sure it is at least 1 char long, convert the input to uppercase and it is in the array above
			if($("#state").val().length <= 1 || jQuery.inArray($("#state").val().toUpperCase(), states) == -1){
				error($("#state"), "Please enter a valid state abbreviation");
				return false;
			}
			
			//Make sure zip code is not empty
			if($("#zip").val() == ''){
				error($("#zip"), "Please enter your zip code");
				return false;
			}
			
			//Make sure zip code is numbers only
			if(isNaN($("#zip").val()/1)){
				error($("#zip"), "Please enter numbers only!");
				return false;
			}
			
			//Make sure it is not less than 5 digits
			if($("#zip").val().length < 5){
				error($("#zip"), "Please enter a valid 5 digits zip code");
				return false;
			}
			
			//Validate phone # is not empty
			if($("#phone").val() == ''){
				error($("#phone"), "Please enter your phone number");
				return false;
			}
			
			//Regular Expression to validate a phone #
			var phoneReg = /((\(\d{3}\) ?)|(\d{3}[- \.]))?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/;
			
			//Make sure the phone # long enough to have area code and matches the regular expression
			if($("#phone").val().length <= 7 || $("#phone").val().match(phoneReg) == null){
				error($("#phone"), "Please enter your phone number!  Ex: 123-456-4567 x123");
				return false;
			}
			
			//If all above conditions are all met, the form will be sent
			return true;
		}
	
	
	});

});