$(document).ready(function(){

	$(".DeleteShipment").click(function(){
		var dodelete = confirm("Are you sure you want to delete this shipment?");
		if (dodelete) {
			return true;
		}
		return false;
	});


	//$("#shipmentPickupDate").datepicker({ showAnim: 'slideDown' });
	//$("#destinationDate").datepicker({ showAnim: 'slideDown' });
	
	/*
	$("#pickupLocation").autocomplete("/search.php", {
		width: 260,
		selectFirst: false
	});
	*/
	
	$("#transportationCalculator").submit(function(event){
		event.preventDefault();
		var str = $("#transportationCalculator").serialize();

			$.ajax({
  				type: "GET",
				url: "/ajax_shipping_rate.php",
				data: str,
				cache: false,
				success: function(msg){
					$("#CostCalculatorRate").html(msg);
				}
 			});

	});
	
	$("#captchaImageLink").click(function(event){
		event.preventDefault();
		randomchar = Math.random();
		$("#captchaImageSRC").attr("src","/captcha.jpg?" + randomchar);
		$("#captcha").val("");
		$("#captcha").focus();
	});
	
	$("#addShipment").validate({
		rules: {
			horses: "required",
			shipmentPickupDate: "required",
			shipmentContactName: "required",
			shipmentAddress: "required",
			shipmentCity: "required",
			shipmentState: "required",
			shipmentZip: "required",
			
			destinationPickupDate: "required",
			destinationContactName: "required",
			destinationAddress: "required",
			destinationCity: "required",
			destinationState: "required",
			destinationZip: "required"
			
		},
		messages: {
			horses: "Enter the # of horses that will be included in this shipment",
			shipmentPickupDate: "Enter a shipment pickup date",
			shipmentContactName: "Enter a contact name",
			shipmentAddress: "Enter the address where the horses are located",
			shipmentCity: "Enter the city where the horses are located",
			shipmentState: "Enter the state where the horses are located",
			shipmentZip: "Enter the zip where the horses are located",
			
			destinationPickupDate: "Enter a deliver by date",
			destinationContactName: "Enter a contact name",
			destinationAddress: "Enter the address where the horses will be shipped to",
			destinationCity: "Enter the city where the horses will be shipped to",
			destinationState: "Enter the state where the horses will be shipped to",
			destinationZip: "Enter the zip where the horses will be shipped to"
			
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next() );
				
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent().next() );
			else
				error.appendTo( element.parent().add() );
		},
		errorElement: "div"
	});
	
	$("#ShipperSignup").validate({
		rules: {
			firstName: "required",
			lastName: "required",
			email: {
				required: true,
				email: true
			},
			emailConfirm: {
				required: true,
				equalTo: "#email"
			},
			accountpassword: {
				required: true,
				minlength: 5
			},
			accountpasswordConfirm: {
				required: true,
				equalTo: "#accountpassword"
			},
			captcha: {
				required: true,
				remote: "/signup_captcha.php"
			}
			
		},
		messages: {
			firstName: "Please enter your first name",
			lastName: "Please enter your last name",
			email: {
				email: "Enter a valid email address",
				required: "Enter a valid email address"
			},
			emailConfirm: {
				required: "Please re-enter your email address",
				equalTo: "Your email address does not match"
			},
			accountpassword: {
				required: "Please choose an account password",
				minlength: "Password is too short. Must be atleast 5 characters"
			},
			accountpasswordConfirm: {
				required: "Please retype your password",
				equalTo: "Passwords do not match"	
			},
			captcha: {
				required: "Please enter the text that appears in the image above",
				remote: "The text you entered did not match what is in the image"
			}
			
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next() );
				
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent().next() );
			else
				error.appendTo( element.parent().add() );
		},
		errorElement: "div"
	});
	
	
	
	$("#TransporterSignup").validate({
		rules: {
			company: "required",
			companyAddress: "required",
			companyCity: "required",
			companyState: "required",
			companyZip: "required",
			dotNumber: "required",
			firstName: "required",
			lastName: "required",
			email: {
				required: true,
				email: true
			},
			emailConfirm: {
				required: true,
				equalTo: "#email"
			},
			accountpassword: {
				required: true,
				minlength: 5
			},
			accountpasswordConfirm: {
				required: true,
				equalTo: "#accountpassword"
			},
			captcha: {
				required: true,
				remote: "/signup_captcha.php"
			}
			
		},
		messages: {
			company: "Please enter your company name",
			companyAddress: "Please enter your company address",
			companyCity: "Please enter your company city",
			companyState: "Please enter your company state",
			companyZip: "Please enter your company zip",
			dotNumber: "Please enter your DOT number",
			
			firstName: "Please enter your first name",
			lastName: "Please enter your last name",
			email: {
				email: "Enter a valid email address",
				required: "Enter a valid email address"
			},
			emailConfirm: {
				required: "Please re-enter your email address",
				equalTo: "Your email address does not match"
			},
			accountpassword: {
				required: "Please choose an account password",
				minlength: "Password is too short. Must be atleast 5 characters"
			},
			accountpasswordConfirm: {
				required: "Please retype your password",
				equalTo: "Passwords do not match"	
			},
			captcha: {
				required: "Please enter the text that appears in the image above",
				remote: "The text you entered did not match what is in the image"
			}
			
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next() );
				
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent().next() );
			else
				error.appendTo( element.parent().add() );
		},
		errorElement: "div"
	});
	
	  
});
