// JavaScript Document
function disableField() {
	document.qform.OtherTypeDesc.value='';
	document.qform.OtherTypeDesc.disabled=true;
}
function enableField() {
	document.qform.OtherTypeDesc.disabled=false;
}

window.onload = disableField;

$(document).ready(function(){
	$('#submit').hover(
	function(){ // Change the input image's source when we "roll on"
	$(this).attr({ src : '../siteimages/submit_btn_sel.gif'});
	},
	function(){ // Change the input image's source back to the default on "roll off"
	$(this).attr({ src : '../siteimages/submit_btn.gif'});
	});

// add code to group error messages
/*	
	$("#qform").validate({
		groups: {
			ServiceType: "ServiceType"
		},
		errorPlacement: function(error, element) {
			if (element.attr("id") == "ServiceType_Truckload"
							 || element.attr("id") == "ServiceType_LTL"
							 || element.attr("id") == "ServiceType_Rail"
							 || element.attr("id") == "ServiceType_Intl")
				error.insertAfter("#ServiceType_Intl");
			else
				error.insertAfter(element);
		},
			debug:true
	 });
*/
	
});

// Form Validation

//$.validator.setDefaults({
//	submitHandler: function() { alert("submitted!"); }
//});

$().ready(function() {
	// validate the comment form when it is submitted
	// $("#qform").validate();
	
	// validate signup form on keyup and submit
	$("#qform").validate({
		rules: {
			Company: "required",
			Contact: "required",
			Phone: "required",
			Email: {
				required: true,
				email: true
			},
			ServiceType: "required",
			EquipType: "required",
			OriginAddress: "required",
			OriginCity: "required",
			OriginState: "required",
			OriginZip: "required",
			DestAddress: "required",
			DestCity: "required",
			DestState: "required",
			DestZip: "required",
			ShipDate: "required",
			Weight: "required",
			NoPallets: "required"
		},
		messages: {
			Company: "Please enter your company.",
			Contact: "Please enter your name.",
			Phone: "Please enter your phone number.",
			Email: "Please enter a valid email address.",
			ServiceType: "Please pick a service type.",
			EquipType: "Please specify equipment type.",
			
			OriginAddress: "Please enter the origin address.",
			OriginCity: "Please enter the origin city.",
			OriginState: "Please enter the origin state.",
			OriginZip: "Please enter the origin zip.",
			
			DestAddress: "Please enter the destination address.",
			DestCity: "Please enter the destination city.",
			DestState: "Please enter the destination state.",
			DestZip: "Please enter the destination zip.",
			
			ShipDate: "Please enter a ship date.",
			Weight: "Please enter the cargo weight.",
			NoPallets: "Please enter the # of pallets."
		},
		errorPlacement: function(error, element) {
			
			if (element.attr("id") == "Phone")
				error.insertAfter("#Fax");
			
			else if (element.attr("id") == "ServiceType_Truckload"
							 || element.attr("id") == "ServiceType_LTL"
							 || element.attr("id") == "ServiceType_Rail"
							 || element.attr("id") == "ServiceType_Intl")
				error.insertAfter("label#ServiceType");
				
			else if (element.attr("id") == "EquipType_DryVan"
							 || element.attr("id") == "EquipType_Flatbed"
							 || element.attr("id") == "EquipType_Refridge"
							 || element.attr("id") == "EquipType_Other"
							 || element.attr("id") == "EquipType_OtherDesc")
				error.insertAfter("#EquipType_OtherDesc");
				
			else if (element.attr("id") == "OriginState"
							 || element.attr("id") == "OriginZip")
				error.insertAfter("#OriginZip");
				
			else if (element.attr("id") == "DestState"
							 || element.attr("id") == "DestZip")
				error.insertAfter("#DestZip");
				
			else if (element.attr("id") == "Weight"
							 || element.attr("id") == "NoPallets")
				error.insertAfter("#NoPallets");
				
			else
				error.insertAfter(element);
			}
		
		
	});

});
