// JavaScript Document
// BOV - quick quote processing w/ jquery
// jquery based form checking - qq.js
// emm 06.23.09
$(document).ready(function() {

	startit() ; // slideshow
	//initTip();	// tool tip
	/*
	 * not using rounded 
	if(!NiftyCheck())	// rounded corners
		return;
	
	Rounded("div#contentBlock h1","top","#FFF","#A4C3DF"); // "#77b3dc");
	Rounded("div#contentBlock","bottom" ,"#fff","transparent");	
	Rounded("div#boxDestinations h2","top","#FFF","#A4C3DF");
	Rounded("div#boxDestinations","bottom","#fff","#ebf5f8"); 	
	Rounded("div#boxExperience h2","top","#FFF","#A4C3DF"); 
	Rounded("div#boxExperience","bottom","#FFF","#ebf5f8");
	*/
	
	// datepicker
	$(function() {
		$("#fromDate").datepicker();
		$("#toDate").datepicker();
	});

	// validate signup form on keyup and submit
	var valid_form = $("#qq").validate({
		submitHandler: function(form) {
  			var dataString = $("#qq").serialize(); 
   			$.ajax({
			      type: "POST",
			      url: "./scripts/dispatch.php",
			      data: dataString ,
			      dataType: "json" ,
			      success: function(json_return) {
					  	// alert('json return  = ' + json_return.status_code);
			      		if ( json_return.status_code == '1') {
			      			$('#message').fadeIn(1500, function () {
			      				$('#message').addClass('checked') ;
				      			$('#message').html("<h3>Your enquiry has been processed.</h3>")
					        		.append('<p style="padding:5px">Please add us (mainsail@blueodysseyvacations.com) to your contact list so you will be sure to see our response.</p>') ;
		                	});	
			      		}
			      		else {
			      			// alert('error:  json return = '+json_return.status_code)
			      			$('#message').fadeIn(1500, function () {
			      				$('#message').html("<h3>There was an error forwarding your information to the Blue Odyssey Vacations.</h3>")
					        	.append("Please contact us by email (mainsail@blueodysseyvacations.com) or phone us (888-706-7393) and we'll be happy to assist you.</p>")
		                	});
			      		}				        
				  },
				  beforeSend: function(){$("p#loading").show("fast");}, // show loading just when link is clicked 
                  complete: function(){ $("p#loading").hide("fast");},  // process is complete
                  error: function(XMLHttpRequest, textStatus, errorThrown) { 
	                  	//alert('error in ajax send'+textStatus);
	                  	if ( textStatus == 'timeout') {
	                  		$('#message').addClass('unchecked') ;
	                  		$('#message').fadeIn(1500, function () {
								//alert(textStatus+' = status');
								$('#message').html("<h3>There was an error in our processing of your enquiry.</h3>" +
						        	"<p>The processing of your form has timed out on our server.  Please try resubmitting the form, contact us by email (mainsail@blueodysseyvacations.com) or phone us (888-706-7393) and we'll be happy to assist you.</p>")
			                	});                		
	                  	}
	                  	else { // textStatus == 'parsererror' or other
	                  		//alert(textStatus+' = status');
	                  		$('#message').addClass('unchecked') ;
	                  		$('#message').fadeIn(1500, function () {
								$('#message').html("<h3>There was an error in our processing of your enquiry.</h3>" +
						        "<p>We apologize:  there was an error forwarding your information.  Please contact us by email (mainsail@blueodysseyvacations.com) or phone us (888-706-7393) and we'll be happy to assist you.</p>")
			                	});                   		
			        	} // if/else
	             } // error handling
			 }); // ajax
		}, // submit handler
		debug: false ,
		errorElement: 'span' ,
		rules: {
			source: "required",
			contactName: "required",
			fromDate: {
				required: true ,
				date: true
			}, 
			toDate: {
				required: true ,
				date: true
			}, 
			boattype: "required",
			email: {
				required: true ,
				email: true 
			},
			passengers: {
				required: true , 
				range: [1,12]
			},
			location: "required"
		},
		messages: {
			source: "Please specify the <strong>source of your referral</strong>.",
			contactName: "Please enter a valid <strong>contact name</strong>.",
			fromDate: "Please enter valid <strong>\"From\"</strong> dates for your trip",
			toDate: "Please enter valid <strong>\"To\"</strong> dates for your trip.",
			passengers: "Please enter the number of passengers traveling.",
			boattype: "Please select the type of yacht.",
			eMail: {
				required: "Please enter your email so we may contact you.",
				email: "Please enter a valid email address, for example: 'a@abc.com'."
			}
		}
	});	
	valid_form.resetForm();

});// JavaScript Document