// prepare the form when the DOM is ready 
$(document).ready(function() { 
	var options = { 
	//target:        '#QuoteForm',   // target element(s) to be updated with server response 
	//beforeSubmit:  validate,  // pre-submit callback 
	success:       showResponse,  // post-submit callback 
				 
	// other available options: 
	//url:       url         // override for form's 'action' attribute 
	//type:      type        // 'get' or 'post', override for form's 'method' attribute 
	//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
	//clearForm: true        // clear all form fields after successful submit 
	resetForm: true        // reset the form after successful submit 
				 
	// $.ajax options can be used here too, for example: 
	//timeout:   3000 
	};
				    
	$('#domestic-submit').click(function(){
		// Validate Quote Form
		var errors = '';
		if ( $("#name").val() == '') 
		{
			errors += 'Please enter your Name.\n';
			$("#name").css('border', '1px solid #f00');
		}
		if ( !$("#email").val().match(/^.+@.+/)) 
		{
			errors += 'Please enter your Email Address.\n';
			$("#email").css('border', '1px solid #f00');
		}
		if ( $("#phone").val() == '') 
		{
			errors += 'Please enter your Phone Number.\n';
			$("#phone").css('border', '1px solid #f00');
		}
		if ( $("#datepicker").val() == '') 
		{
			errors += 'Please enter your Ship Date.\n';
			$("#datepicker").css('border', '1px solid #f00');
		}
		if ( $("#pickupzip").val() == '') 
		{
			errors += 'Please enter your Pickup Zip.\n';
			$("#pickupzip").css('border', '1px solid #f00');
		}
		if ( $("#dropoffzip").val() == '') 
		{
			errors += 'Please enter your Delivery Zip.\n';
			$("#dropoffzip").css('border', '1px solid #f00');
		}
		if ( $("#vehicleyear").val() == '') 
		{
			errors += 'Please enter your Vehicle Year.\n';
			$("#vehicleyear").css('border', '1px solid #f00');
		}
		if ( $("#vehiclemake").val() == '') 
		{
			errors += 'Please enter your Vehicle Make.\n';
			$("#vehiclemake").css('border', '1px solid #f00');
		}
		if ( $("#vehiclemodel").val() == '') 
		{
			errors += 'Please enter your Vehicle Model.\n';
			$("#vehiclemodel").css('border', '1px solid #f00');
		}
		if ( $("#carriertype").val() == '') 
		{
			errors += 'Please enter your Carrier Type.\n';
			$("#carriertype").css('border', '1px solid #f00');
		}
		if ( errors == '')
		{
			$("#DomesticQuoteForm").ajaxSubmit(options);
			return true;
		}else 
		{
			alert(errors);
			return false;
		}
		
					
				     
		// !!! Important !!! 
		// always return false to prevent standard browser submit and page navigation 
	return false; 
				     
	});
	
	$('#international-submit').click(function(){
		// Validate Quote Form
		var errors = '';
		if ( $("#name2").val() == '') 
		{
			errors += 'Please enter your Name.\n';
			$("#name2").css('border', '1px solid #f00');
		}
		if ( !$("#email2").val().match(/^.+@.+/)) 
		{
			errors += 'Please enter your Email Address.\n';
			$("#email2").css('border', '1px solid #f00');
		}
		if ( $("#phone2").val() == '') 
		{
			errors += 'Please enter your Phone Number.\n';
			$("#phone2").css('border', '1px solid #f00');
		}
		if ( $("#datepicker2").val() == '') 
		{
			errors += 'Please enter your Ship Date.\n';
			$("#datepicker2").css('border', '1px solid #f00');
		}
		if ( $("#pickupzip2").val() == '') 
		{
			errors += 'Please enter your Pickup Zip.\n';
			$("#pickupzip2").css('border', '1px solid #f00');
		}
		if ( $("#dropoffcountry").val() == '') 
		{
			errors += 'Please enter your Drop Off Country.\n';
			$("#dropoffcountry").css('border', '1px solid #f00');
		}
		if ( $("#vehicleyear2").val() == '') 
		{
			errors += 'Please enter your Vehicle Year.\n';
			$("#vehicleyear2").css('border', '1px solid #f00');
		}
		if ( $("#vehiclemake2").val() == '') 
		{
			errors += 'Please enter your Vehicle Make.\n';
			$("#vehiclemake2").css('border', '1px solid #f00');
		}
		if ( $("#vehiclemodel2").val() == '') 
		{
			errors += 'Please enter your Vehicle Model.\n';
			$("#vehiclemodel2").css('border', '1px solid #f00');
		}
		if ( errors == '')
		{
			$("#InternationalQuoteForm").ajaxSubmit(options);
			return true;
		}else 
		{
			alert(errors);
			return false;
		}
		// !!! Important !!! 
			// always return false to prevent standard browser submit and page navigation 
		return false; 
		
	 });
	 
	 $('#moving-submit').click(function(){
	 	// Validate Quote Form
	 	var errors = '';
	 	if ( $("#name3").val() == '') 
	 	{
	 		errors += 'Please enter your Name.\n';
	 		$("#name3").css('border', '1px solid #f00');
	 	}
	 	if ( !$("#email3").val().match(/^.+@.+/)) 
	 	{
	 		errors += 'Please enter your Email Address.\n';
	 		$("#email3").css('border', '1px solid #f00');
	 	}
	 	if ( $("#phone3").val() == '') 
	 	{
	 		errors += 'Please enter your Phone Number.\n';
	 		$("#phone3").css('border', '1px solid #f00');
	 	}
	 	if ( $("#datepicker3").val() == '') 
	 	{
	 		errors += 'Please enter your Move Date.\n';
	 		$("#datepicker3").css('border', '1px solid #f00');
	 	}
	 	if ( $("#fromzip").val() == '') 
	 	{
	 		errors += 'Please enter your Pickup Zip.\n';
	 		$("#fromzip").css('border', '1px solid #f00');
	 	}
	 	if ( $("#tozip").val() == '') 
	 	{
	 		errors += 'Please enter your Drop Off Country.\n';
	 		$("#tozip").css('border', '1px solid #f00');
	 	}
	 	if ( $("#bedrooms").val() == '') 
	 	{
	 		errors += 'Please enter your the Number of Bedrooms.\n';
	 		$("#bedrooms").css('border', '1px solid #f00');
	 	}
	 	if ( errors == '')
	 	{
	 		$("#MovingQuoteForm").ajaxSubmit(options);
	 		return true;
	 	}else 
	 	{
	 		alert(errors);
	 		return false;
	 	}
	 	// !!! Important !!! 
	 		// always return false to prevent standard browser submit and page navigation 
	 	return false; 
	 	
	  });
});
				
function validate(formData, jqForm, options) { 
	    // formData is an array of objects representing the name and value of each field 
	    // that will be sent to the server;  it takes the following form: 
	    // 
	    // [ 
	    //     { name:  username, value: valueOfUsernameInput }, 
	    //     { name:  password, value: valueOfPasswordInput } 
	    // ] 
	    // 
	    // To validate, we can examine the contents of this array to see if the 
	    // username and password fields have values.  If either value evaluates 
	    // to false then we return false from this method. 
	 
	    /*for (var i=0; i < formData.length; i++) { 
	        if (!formData[i].value) { 
	            alert('Please enter a value for both Username and Password'); 
	            return false; 
	        } 
	    } 
	    alert('Both fields contain values.'); 
	}*/
	
		alert("Submitted Successfully!");
	}
	// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  { 
	    // for normal html responses, the first argument to the success callback 
	    // is the XMLHttpRequest object's responseText property 
	 
	    // if the ajaxSubmit method was passed an Options Object with the dataType 
	    // property set to 'xml' then the first argument to the success callback 
	    // is the XMLHttpRequest object's responseXML property 
	 
	    // if the ajaxSubmit method was passed an Options Object with the dataType 
	    // property set to 'json' then the first argument to the success callback 
	    // is the json data object returned by the server 
	 
	    alert("Submitted Successfully!");
	    //setTimeout(function(){
	        $('#dialog').fadeOut(2000).dialog('close');
	         // }, 600); 
	} 

