<!--
$(document).ready(function() {
	//Date
	$(function() {
		var dates = $('#start, #end').datepicker({
			defaultDate: 0,
			changeMonth: true,
			dateFormat: 'yy-mm-dd',
			minDate: 0,
			onSelect: function(selectedDate) {
				var option = this.id == "start" ? "minDate" : "maxDate";
				var instance = $(this).data("datepicker");
				var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
				dates.not(this).datepicker("option", option, date);
			}
		});
	});
	
	//validate email
	function isValidEmailAddress( emailAddress ) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test( emailAddress );
}

	
	// Sidebar tab links
	$("a.tab").click(function () {		
		//clear error/success messages
		$('.errormessage').html("").show();
		//get dates
		var startDate = $("input#start").val();
		var endDate = $("input#end").val();
		var email = $("input#e_mail").val();
		var depart = $("select#dept").val();
		//if itinerary is clicked, we need dates
		if ( startDate == '' || endDate == '' ) {
			$('.errormessage').html('<h2>You need to add some dates first</h2>').fadeOut(4000);	
		} else if ( email == '' ) {
			$('.errormessage').html('<h2>You need to add an email address</h2>').fadeOut(4000);	
		} else if ( !isValidEmailAddress( email ) ) {
			$('.errormessage').html('<h2>Email address does not appear to be valid</h2>').fadeOut(4000);	
		} else if ( depart == '' && $(this).attr("title") != 'flights' && $(this).attr("title") != 'pax' ){
			$('.errormessage').html('<h2>You need to select a Departure point</h2>').fadeOut(4000);	
		} else {
						
			// switch all tabs off
			$(".active").removeClass("active");		
			// switch this tab on
			$(this).addClass("active");		
			// slide all content up
			$(".tqcontent").hide();		
			// show content 
			var content_show = $(this).attr("title");
				 
			
			if ( $(this).attr("id") == 'itintab' ) {
				$("#"+content_show).show();
				//date diff
				var minutes = 1000*60;
				var hours = minutes*60;
				var days = hours*24;
				
				var foo_date1 = getDateFromFormat(startDate, "y-M-d");
				var foo_date2 = getDateFromFormat(endDate, "y-M-d");
				
				var diff_date = Math.round((foo_date2 - foo_date1)/days);
				var dataString = 'days='+ diff_date;
				$.ajax({
					type: "POST",
					url: "wp-content/plugins/trip-quoter/queries/process.php",
					data: dataString,
					success: function(reponse){ 
						var data = reponse;
						$("#"+content_show).show();
						$('#itin').html(data);
				  	}
				});
	
			} else {
				$("#"+content_show).show();
			}
		}
	});
});

-->
