/* BUTTONS
-------------------------------------------------------------- */
	$(document).ready(function() {
		//$('.bookattraction,.checkout,.clearbasket,.backfrombooking,.sendenquiry,.bookpackage,.moredetails,.moreflights,.submitform,.searchagain').append('<span class="hover"></span>').each(function () {
//	  		var $span = $('> span.hover', this).css('opacity', 0);
//	  		$(this).hover(function () {
//	    		$span.stop().fadeTo(500, 1);
//	 		}, function () {
//	   	$span.stop().fadeTo(500, 0);
//	  		});
//		});
		$("a.submitform, a.bookticket,a.bookpackage, a.sendenquiry,a.signup,a.unsubscribe").click(function(){
			var boolSubmitok = true;
			if($(this).parents("form").attr("class")=="groupbooking"){
				var intMinForGroupBooking = 15;
				var intGroup = parseInt((IsNumeric($("#GroupAdults").val())?$("#GroupAdults").val():0)) + parseInt((IsNumeric($("#GroupChildren1").val())?$("#GroupChildren1").val():0)) + parseInt((IsNumeric($("#GroupChildren2").val())?$("#GroupChildren2").val():0)) + parseInt((IsNumeric($("#GroupInfants").val())?$("#GroupInfants").val():0)) + parseInt((IsNumeric($("#GroupSeniors").val())?$("#GroupSeniors").val():0));
				if(intGroup<intMinForGroupBooking){
					alert("Please note a group booking is 15 paying passengers or more. If your group is less than 15 passengers, please make your booking online at www.hovertravel.com");
					boolSubmitok = false;
				}
			}
			if(boolSubmitok){
				$(this).parents("form").submit();
			}else{
				return false;
			}
		});
	});

	function IsNumeric(n) {
		return !isNaN(parseFloat(n)) && isFinite(n);
	}

$(document).ready(function() {

	$("body").delegate(".ownstockselect" , "change", function() {
		UpdateOwnStockTotal();
	});
	$("body").delegate("a.addownstock" , "click", function() {
		var intTicketsSelected = 0;
		var intEventID = $(this).attr("id").split("_")[1];
		$(".ownstockselect").each(function(){
			intTicketsSelected += $(this).val();
		});
		if(intTicketsSelected>0){
			OwnStockBookingTask("AddOwnStock",intEventID)
		}else{
			alert("Please choose at least 1 ticket to add to your basket");
		}
	});


	$("body").delegate(".ownstockselectcart" , "change", function() {
		var strSelectName = $(this).attr("name");
		var intTicketsSelected = $(this).val();
		if(intTicketsSelected>0){
		}else{
			boolconfirm = confirm("Please Note - this ticket will be removed from your basket");
			if(!boolconfirm){
				CartRefresh("Y");
				return false;
			}
		}
		OwnStockCartTask("UpdateStock",strSelectName,intTicketsSelected)
	});


	$("a.validatepromo").live("click",function(){
		$("#PromoTask").val("availability");
		$("#Addpromo").val("N");
		$("#RevertPromo").val("N");
		$(this).parents("form").submit();
	});

	$("a.Addpromo").live("click",function(){
		$("#promocode").val("xxx");
		$("#PromoTask").val("");
		$("#Addpromo").val("Y");
		$("#RevertPromo").val("N");
		$(this).parents("form").submit();
	});

	$("a.RevertPromo").live("click",function(){
		$("#promocode").val("xxx");
		$("#PromoTask").val("");
		$("#Addpromo").val("N");
		$("#RevertPromo").val("Y");
		$(this).parents("form").submit();
	});

	$("body").delegate("#UpdateMethodSMS", "change", function() {
		if($(this).attr("checked")){
			if($("#MobileNumber").val()=="000"){
				$("#MobileNumber").val("");
			}
			$("#SMSMobileNumberDiv").show();
		}else{
			$("#SMSMobileNumberDiv").hide();
			$("#MobileNumber").val("000");
		}
	});

	$("body").delegate("#UpdateMethodEmail", "change", function() {
		if($(this).attr("checked")){
			if($("#email").val()=="xxx@xxx.com"){
				$("#email").val("");
			}
			$("#SMSEmailDiv").show();
		}else{
			$("#SMSEmailDiv").hide();
			$("#email").val("xxx@xxx.com");
		}
		
	});


	$("body").delegate("#ShowUnsubscribeChoices", "change", function() {
		$(".alertmessage").hide();
		if($(this).attr("checked")){
//			alert("Please note - In order to unsubscribe you, we will need your email address and/or mobile number to identify your details in our database.\nPlease enter the details below before submitting this form.");
			$("#UpdateChoice").hide();
			$("#SMSEmailDiv").hide();
			$("#SMSMobileNumberDiv").hide();
			$("#nosubhide").hide();
			$("#unsubscribesubmit").show();
			$("#UnsubEmailDiv").show();
			$("#UnsubMobileNumberDiv").show();
			$(".nosubhide").hide();
		}else{
			boolUpdateMethodEmail = $("#UpdateMethodEmail").attr("checked");
			boolUpdateMethodSMS = $("#UpdateMethodSMS").attr("checked");
			$("#UpdateChoice").show();
			if(boolUpdateMethodEmail){
				if($("#email").val()=="xxx@xxx.com"){
					$("#email").val("");
				}
				$("#SMSEmailDiv").show();
			}else{
				$("#email").val("xxx@xxx.com");
			}

			if(boolUpdateMethodSMS){
				if($("#MobileNumber").val()=="000"){
					$("#MobileNumber").val("");
				}
				$("#SMSMobileNumberDiv").show();
			}else{
				$("#MobileNumber").val("000");
			}
			$("#unsubscribesubmit").hide();
			$("#UnsubEmailDiv").hide();
			$("#UnsubMobileNumberDiv").hide();
			$(".nosubhide").show();
		}
	});

	$("#searchagain-session").live("click",function(){
		var strWindowLocation = window.location.toString();
		var RedirectURL =  ( strWindowLocation.indexOf("localhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/" : (strWindowLocation.indexOf("prowebgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/" : "http://www.hovertravel.co.uk/" ));
		top.location.href=RedirectURL;//redirection
		return false;
	});

	$("body").delegate(".MinOne", "change", function() {
		var arrNamesToCheck = new Array();
		var intNamesToCheckCount = 0;
		$(".MinOne").each(function(){
			var strTestName = $(this).attr("name");
			arrNamesToCheck[intNamesToCheckCount] = strTestName;
			intNamesToCheckCount = intNamesToCheckCount+1;
		});
		arrNamesToCheck = arrunique(arrNamesToCheck);
		for ( var intarrNamesToCheckCount=0, len=arrNamesToCheck.length; intarrNamesToCheckCount<len; ++intarrNamesToCheckCount ){
			var strTestName = arrNamesToCheck[intarrNamesToCheckCount];
			var strsubmitVal = ""
			$("[name="+strTestName+"]").each(function(){
				if($(this).is(':checkbox')){
					if($(this).attr("checked")){
						strThisVal = $(this).val();
						strsubmitVal = strsubmitVal + "," + strThisVal;
					}
				}else{
					strThisVal = $(this).attr("id") + "|" + $(this).val();
					strsubmitVal = strsubmitVal + "," + strThisVal;
				}
			});

//			alert("strTestName - " + strTestName)
//			alert("replace val - " + strsubmitVal.replace(/(^,)|(,$)/g, ""))

			$("#Arr" + strTestName).val(strsubmitVal.replace(/(^,)|(,$)/g, ""));
		}
	});


	function arrunique(arrayName){
		var newArray=new Array();
		label:for(var i=0; i<arrayName.length;i++ ){
			for(var j=0; j<newArray.length;j++ ){
				if(newArray[j]==arrayName[i])
				continue label;
			}
			newArray[newArray.length] = arrayName[i];
		}
		return newArray;
	}

	$("#flightwait").hide();
	$(".FlightSearchSubmitSearching").hide();
	$(".flighttablediv").hide();

	//ONLY FOR YESPAY TESTING...
	$("body").delegate("#amount", "change", function() {
		var MTR = $("#MTR").val();
		var pwd = $("#pwd").val();
		var amount = $("#amount").val();
		$.ajax({
			url:"./XML/Digest.txt",
			beforeSend: function(){
			},
			success: function(data){
				$("#digest").val(data);
				alert("Test Amount Updated, new digest = " + data);
			},
			data:{
				MTR:MTR,
				pwd:pwd,
				amount:amount
			},
			async:false
		});
	});

	$("body").delegate("#CardType", "change", function() {
		updatecardcharge();
	});

	$("body").delegate(".hoursearch", "change", function() {
		var callingID = $(this).attr("id");
		var strTravelRoute = ( $("#travelroute_1").is(":visible") ? $("#travelroute_1").val() : $("#travelroute_2").val() );
		var strTravelRouteClass = ( $("#attractionsearch_1").is(":visible") ? $("#attractionsearch_1").attr("class") : $("#attractionsearch_2").attr("class") );
		strFOFA = ($("#FALI").attr("class")=="active"?"FA":"FO");
		if(strFOFA=="FO"){
			ob_dateFA = $("#ob_date").val();
			ib_dateFA = $("#ib_dateFO").val();
			ob_hour_current = $("#ob_hour").val();
			ob_minute_current = $("#ob_minute").val();
			ib_hour_current = $("#ib_hour").val();
			ib_minute_current = $("#ib_minute").val();
		}else{
			ob_dateFA = $("#ob_dateFA").val();
			ib_dateFA = $("#ib_dateFA").val();
			ob_hour_current = $("#ob_hourFA").val();
			ob_minute_current = $("#ob_minuteFA").val();
			ib_hour_current = $("#ib_hourFA").val();
			ib_minute_current = $("#ib_minuteFA").val();
		}
		CheckExcludedDateTimes(ob_dateFA,ib_dateFA,strTravelRoute,strTravelRouteClass,ob_hour_current,ob_minute_current,ib_hour_current,ib_minute_current,callingID);
	});
	$("body").delegate(".travelroute", "change", function() {
		$("#attractionsearch_2").attr("disabled","disabled");
		$("#attractionsearch_1").attr("disabled","disabled");
		$("#attractionsummarylinkcontainer").hide();
		$("#attractionsummaryNolinkcontainer").hide();
		$("#attractionsummaryimgerr").hide();
		$("#attractionsummaryimgspin").show();
		var strTravelRoute = ( $("#travelroute_1").is(":visible") ? $("#travelroute_1").val() : $("#travelroute_2").val() );
		var strTravelRouteClass = ( $("#attractionsearch_1").is(":visible") ? $("#attractionsearch_1").attr("class") : $("#attractionsearch_2").attr("class") );
		strFOFA = ($("#FALI").attr("class")=="active"?"FA":"FO");
		if(strFOFA=="FO"){
			ob_dateFA = $("#ob_date").val();
			ib_dateFA = $("#ib_dateFO").val();
			ob_hour_current = $("#ob_hour").val();
			ob_minute_current = $("#ob_minute").val();
			ib_hour_current = $("#ib_hour").val();
			ib_minute_current = $("#ib_minute").val();
		}else{
			ob_dateFA = $("#ob_dateFA").val();
			ib_dateFA = $("#ib_dateFA").val();
			ob_hour_current = $("#ob_hourFA").val();
			ob_minute_current = $("#ob_minuteFA").val();
			ib_hour_current = $("#ib_hourFA").val();
			ib_minute_current = $("#ib_minuteFA").val();
		}
		CheckExcludedDateTimes(ob_dateFA,ib_dateFA,strTravelRoute,strTravelRouteClass,ob_hour_current,ob_minute_current,ib_hour_current,ib_minute_current,"travelroute");
		updateattractions(ob_dateFA,strTravelRoute,strTravelRouteClass,"travelroute");
		if(strTravelRoute != ""){
			$(this).css({'borderLeft':'1px solid #999999'});
			$(this).css({'borderTop':'1px solid #999999'});
			$(this).css({'borderRight':'1px solid #999999'});
			$(this).css({'borderBottom':'1px solid #999999'});
		}else{
			$(this).css({'borderLeft':'2px solid #FF0000'});
			$(this).css({'borderTop':'2px solid #FF0000'});
			$(this).css({'borderRight':'2px solid #FF0000'});
			$(this).css({'borderBottom':'2px solid #FF0000'});
		}
	});

	CheckExcludedDateTimes = function(strtestdate_ob,strtestdate_ib,strtesttravelroute,strtestTravelRouteClass,test_ob_hour_current,test_ob_minute_current,test_ib_hour_current,test_ib_minute_current,strcalledfrom){
		booldebug = false;
		$.ajax({
			type: "post",
			url: "ExcludedFlightCheck.php",
			beforeSend: function(){
				if(strcalledfrom == "travelroute"){
					$("#ob_hour").html("");
					$("#ob_minute").html("");
					$("#ib_hour").html("");
					$("#ib_minute").html("");
					$("#ob_hourFA").html("");
					$("#ob_minuteFA").html("");
					$("#ib_hourFA").html("");
					$("#ib_minuteFA").html("");
				}
			},
			success: function(data){
				boolErrorDetected = false;
				if(data.substring(0,5) == "Error"){
					boolErrorDetected = true;
					if(booldebug){
//						alert("DEBUGGING : " + data);
					}
				}
				if(!boolErrorDetected){
					var str_ob_hour_new = data.split("######")[0];
					var str_ob_minute_new = data.split("######")[1];
					var str_ib_hour_new = data.split("######")[2];
					var str_ib_minute_new = data.split("######")[3];

					$("#ob_hour").html(str_ob_hour_new);
					$("#ob_minute").html(str_ob_minute_new);
					$("#ib_hour").html(str_ib_hour_new);
					$("#ib_minute").html(str_ib_minute_new);
					$("#ob_hourFA").html(str_ob_hour_new);
					$("#ob_minuteFA").html(str_ob_minute_new);
					$("#ib_hourFA").html(str_ib_hour_new);
					$("#ib_minuteFA").html(str_ib_minute_new);
				}
			},
			data:{
				strTravelRoute:strtesttravelroute,
				strtestdate_ob:strtestdate_ob,
				strtestdate_ib:strtestdate_ib,
				strTravelRouteClass:strtestTravelRouteClass,
				test_ob_hour_current:test_ob_hour_current,
				test_ob_minute_current:test_ob_minute_current,
				test_ib_hour_current:test_ib_hour_current,
				test_ib_minute_current:test_ib_minute_current
			},
			async:true
		});
		return false;
	}

	updateattractions = function(strtestdate,strtesttravelroute,strtestTravelRouteClass,strcalledfrom){
		$.ajax({
			type: "post",
			url: "attractionavailability.php",
			beforeSend: function(){
			},
			success: function(data){
//				alert(data);
				var intResponse1 = data.split("######")[1];
				var strResponse1 = data.split("######")[2];
				var intResponse2 = data.split("######")[3];
				var strResponse2 = data.split("######")[4];
//				alert("intResponse1 - " + intResponse1 + "\n" + "strResponse1 - " + strResponse1 + "\n" + "intResponse2 - " + intResponse2 + "\n" + "strResponse2 - " + strResponse2);
				$("#AttractionsDropDown_" + intResponse1).html(strResponse1);
				$("#AttractionsDropDown_" + intResponse2).html(strResponse2);
				intResponse1 = parseInt(intResponse1 + 2);
				intResponse2 = parseInt(intResponse2 + 2);

				$("#AttractionsDropDown_" + intResponse1).html(strResponse1);
				$("#AttractionsDropDown_" + intResponse2).html(strResponse2);

				if(strtesttravelroute == "Ryde to Southsea"){
					$("#AttractionsDropDown_2,#AttractionsDropDown_4").hide();
					$("#AttractionsDropDown_1,#AttractionsDropDown_3").show();
					$("#attractionsearch_2").attr("disabled","disabled");
					$("#attractionsearch_1").attr("disabled","");
				}else{
					$("#AttractionsDropDown_1,#AttractionsDropDown_3").hide();
					$("#AttractionsDropDown_2,#AttractionsDropDown_4").show();
					$("#attractionsearch_1").attr("disabled","disabled");
					$("#attractionsearch_2").attr("disabled","");
				}
				$("#attractionsummaryimgspin").hide();
				if(strcalledfrom == "travelroute"){
					$("#attractionsummaryNolinkcontainer").show();
				}
				if(strcalledfrom == "date"){
					$("#attractionsummaryimgerr").hide();
					$("#attractionsummarylinkcontainer").hide();
					$("#attractionsummaryNolinkcontainer").show();
				}
			},
			data:{
				strTravelRoute:strtesttravelroute,
				ob_dateFA:strtestdate,
				strTravelRouteClass:strtestTravelRouteClass
			},
			async:true
		});
		return false;
	}

	updatecardcharge = function(){
		var MTR = $("#MTR").val();
		var pwd = $("#pwd").val();
		var dblCCPerTrans = $("#dblCCPerTrans").val();
		var dblDCPerTrans = $("#dblDCPerTrans").val();
		var dblhbchoiceval = $("#hbchoice").val();
		var strSelectedCardType = $("#CardType").val();
		if(strSelectedCardType == "Visa Debit"||strSelectedCardType == "Visa Electron"||strSelectedCardType == "Maestro"){
			var dblCPerTrans = dblDCPerTrans;
		}else{
			var dblCPerTrans = dblCCPerTrans;
		}
		$("#dblCPerTrans").val(dblCPerTrans);
		var dblgtOrig = $("#dblgtOrig").val();
		var amount = parseFloat(parseFloat(dblgtOrig) + parseFloat(dblCPerTrans) + parseFloat(dblhbchoiceval)).toFixed(2);


//alert("dblgtOrig = " + dblgtOrig);
//alert("dblCPerTrans = " + dblCPerTrans);
//alert("dblhbchoiceval = " + dblhbchoiceval);
//alert("amount = " + amount);

		var strHBChoice = $("#hbchoice" + " option:selected").html();
		if(strHBChoice == "No Thanks" || dblhbchoiceval == 0){
			strHBChoiceForDB = "none";
		}else{
			strHBChoiceForDB = strHBChoice;
		}
		$("#strHBChoice").val(strHBChoiceForDB);
		$("#decHBTotal").val(parseFloat(dblhbchoiceval).toFixed(2));
		$("#amount").val(parseFloat(amount*100).toFixed(0));//#############################UNCOMMENT THIS WHEN REAL CARDS NEED TO BE USED
		$("#dblgt").html(amount);

		amount = parseFloat(amount*100).toFixed(0);

		dtNow = new Date();
		unixNow = dtNow.getTime();
		$.ajax({
			url:"./XML/Digest.txt",
			beforeSend: function(){
			},
			success: function(data){
				var strmsg = "MTR:" + MTR + "\npwd:" + pwd + "\namount:" + amount + "\ndigest.val 1:" + $("#digest").val();
//				alert(strmsg);
				$("#digest").val(data);//#############################UNCOMMENT THIS WHEN REAL CARDS NEED TO BE USED
				var strmsg = "MTR:" + MTR + "\npwd:" + pwd + "\namount:" + amount + "\ndigest.val 2:" + $("#digest").val();
//				alert(strmsg);
			},
			error: function(jqXHR, textStatus, errorThrown){
				objFakeImg = new Image();
				objFakeImg.src = "./XML/ErrorImage"+unixNow+".jpg";
			},
			data:{
				MTR:MTR,
				pwd:pwd,
				amount:amount,
				time: unixNow
			},
			async:false
		});
	}

	$("body").delegate(".attractionsearch, .attractionsearchWide" , "change", function() {
		AttractionSearchChange($(this).attr("id"),$(this).attr("class"),false);
		if($("#travelroute_2").val()==""){
			$("#travelroute_2").css({'borderLeft':'2px solid #FF0000'});
			$("#travelroute_2").css({'borderTop':'2px solid #FF0000'});
			$("#travelroute_2").css({'borderRight':'2px solid #FF0000'});
			$("#travelroute_2").css({'borderBottom':'2px solid #FF0000'})
		}else{
			$("#travelroute_2").css({'borderLeft':'1px solid #999999'});
			$("#travelroute_2").css({'borderTop':'1px solid #999999'});
			$("#travelroute_2").css({'borderRight':'1px solid #999999'});
			$("#travelroute_2").css({'borderBottom':'1px solid #999999'})
		}
		
		
	});

	$("body").delegate(".attractionsearchRES" , "change", function() {
		$("#attractionsummarydivRES").html();
		var intID = $(this).val();
		var intThisID = $(this).attr("id");

		var strAttractionName = $("#" + intThisID + " option[value='" + intID + "']").text();
		var ob_dateFA = $("#ob_dateFA").val();
		$.ajax({
			type: "post",
			url: "attractionsummary.php",
			beforeSend: function(){
//				$(".attractionsummaryimgspin").show();
			},
			success: function(data){
				var strResponse1 = data.split("######")[0];
				var strResponse2 = data.split("######")[1];
				var strResponse3 = data.split("######")[2];
				strResponse1 = (strResponse1 == "none" ? "" : strResponse1);
				if(!$("#strrouteblock").length == 0){
					$("#strrouteblock").val(strResponse1);
				}
//				$(".attractionsummaryimgspin").hide();
				$("#attractionsummarydivRES").html(strResponse3);
				if( strResponse3.indexOf("PLEASE SELECT AN ATTRACTION") !== -1 ){
				}else{
					if( strResponse3.indexOf("PLEASE CHOOSE AN ATTRACTION") !== -1 ){
					}else{
//						$("#attractionsummaryimgspin").hide();
					}
				}
				if(strResponse2 == "y"){
					var dblpax_a = parseFloat($("#pax_a").val()) * parseFloat($("#APKGA_" + intID).val());
					var dblpax_c = parseFloat($("#pax_c").val()) * parseFloat($("#APKGC_" + intID).val());
	//				var dblpax_i = parseFloat($("#pax_i").val()) * parseFloat($("#APKGC_" + intID).val());
					var dblpax_i = 0;
					var dblpax_sen = ($("#pax_sen").length==0?0:parseFloat($("#pax_sen").val()) * parseFloat($("#APKGA_" + intID).val()));
					var dblpax_stu = ($("#pax_stu").length==0?0:parseFloat($("#pax_stu").val()) * parseFloat($("#APKGA_" + intID).val()));
					var dbltotal = parseFloat(parseFloat(dblpax_a) + parseFloat(dblpax_c) + parseFloat(dblpax_i) + parseFloat(dblpax_sen) + parseFloat(dblpax_stu)).toFixed(2);

//					var dbltotal = parseFloat(parseFloat(dblpax_a) + parseFloat(dblpax_c) + parseFloat(dblpax_i)).toFixed(2);

					$(".ticketprice").each(function () {
						$(this).html("Total Price: &pound;" + dbltotal);
					});




					$(".bookpackage").each(function () {
						if(!$(this).is(":visible")){
							$(this).fadeIn('slow');
						}
					});
					$(".searchinfostickylink").each(function () {
						if(!$(this).is(":visible")){
							$(this).fadeIn('slow');
						}
					});
				}else{
					alert("PLEASE NOTE: This attraction (" + strAttractionName + ") is not open during your requested search date.");
					$(".ticketprice").each(function () {
						$(this).html("Select Attraction");
					});
					$(".bookpackage").each(function () {
						if($(this).is(":visible")){
							$(this).fadeOut('slow');
						}
					});
					$(".searchinfostickylink").each(function () {
						if($(this).is(":visible")){
							$(this).fadeOut('slow');
						}
					});
				}
			},
			data:{
				intID:intID,
				ob_dateFA:ob_dateFA,
				boolAddIds:"Y"
			},
			async:true
		});
		return false;
	});


	$("body").delegate(".moreflights" , "click", function() {
		$("#showmoreflights").hide();
		$("#showlessflights").show();
		$(".flighttablediv_more").each(function(){
			$(this).slideDown(2000);
		});
		return false;
	});

	$("body").delegate(".lessflights" , "click", function() {
		$("#showlessflights").hide();
		$("#showmoreflights").show();
		$(".flighttablediv_more").each(function(){
			$(this).slideUp(2000);
		});
		return false;
	});

	$("body").delegate(".placesselect" , "change", function() {
		var intplaces = $(this).val();
		var cart_task = $(this).attr("id");
		cart_task += "_" + String(intplaces);
		var strtask = $(this).attr("id").split("_")[0];
		var intsummary_id = $(this).attr("id").split("_")[2];
		$('#paxa_a_' + intsummary_id).hide();
		$('#paxc_a_' + intsummary_id).hide();
		$('#paxsen_a_' + intsummary_id).hide();
		$('#paxstu_a_' + intsummary_id).hide();
		$('#spinplaces_a_' + intsummary_id).show();
		$('#spinplaces_c_' + intsummary_id).show();
		$('#spinplaces_sen_' + intsummary_id).show();
		$('#spinplaces_stu_' + intsummary_id).show();
		$.ajax({
			type: "post",
			url: "cart.php",
			beforeSend: function(){
//				alert(
//					"cart_task - " + cart_task + "\n" + 
//					"intsummary_id - " + intsummary_id + "\n"
//				);
			},
			success: function(data){
				$("#cart_container").html(data);
				$("#cartmsg").delay(2000).fadeOut('slow');
				$('#spinplaces_a_' + intsummary_id).hide();
				$('#spinplaces_c_' + intsummary_id).hide();
				$('#spinplaces_sen_' + intsummary_id).hide();
				$('#spinplaces_stu_' + intsummary_id).hide();
				$('#paxa_a_' + intsummary_id).show();
				$('#paxc_a_' + intsummary_id).show();
				$('#paxsen_a_' + intsummary_id).show();
				$('#paxstu_a_' + intsummary_id).show();
			},
			data:{
				cart_task:cart_task
			},
			async:false
		});
		return false;
	});

	$("#boolCopyCCAddress").click(function(){
		if($("#boolCopyCCAddress").attr("checked") == true){
			$("#addLine1").val($("#ContactAddLine1").val());
			$("#addLine2").val($("#ContactAddLine2").val());
			$("#city").val($("#ContactCity").val());
			$("#state").val($("#ContactState").val());
			$("#postcode").val($("#ContactPostCode").val());
			$("#country").val($("#BillingCountry").val());
		}
	});

	$("a.backfrombooking").click(function(){
		var strWindowLocation = window.location.toString();
		var RedirectURL = (strWindowLocation.indexOf("localhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/basket.php" : (strWindowLocation.indexOf("prowebgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/basket.php" : "http://www.hovertravel.co.uk/basket.php" ));
		top.location.href=RedirectURL;//redirection
		return false;
	});

	$("body").delegate("a.add,.clearcart, a.bookattraction, .del", "click", function() {
		var intAID = "";
		var boolDontKnowSelected = false;
		var boolPKGWithATTRAlreadyAdded = false;
		var boolPKGAdd = false;
		var dblpax_a = 0;
		var dblpax_c = 0;
		var dblpax_sen = 0;
		var dblpax_stu = 0;
		var strAURL = "";
		var strAName = "";
		var cart_task = $(this).attr("id");
		if(cart_task.substring(cart_task.length - 5,cart_task.length) == "_Link"){
			cart_task = substring(0,cart_task.length - 5);
		}
		if(cart_task.substring(cart_task.length - 4,cart_task.length) == "_PKG"){//From FA search
			boolPKGAdd = true;
			intAID = $("#APKGID").val();
			strAURL = $("#APKGURL").attr("href");
			strAName = $("#APKGName").html();
			dblpax_a = $("#APKGA_" + intAID).val();//Adult PRICE
			dblpax_c = $("#APKGC_" + intAID).val();//Child PRICE
			dblpax_sen = $("#APKGA_" + intAID).val();//Adult PRICE
			dblpax_stu = $("#APKGA_" + intAID).val();//Adult PRICE
			cart_task = cart_task.substring(0,cart_task.length - 4);
			var arrTmptask = $(this).attr("id");
			var strTmpID = $.trim(arrTmptask.split("_")[2]);
			var strTmpAltID = ( !($("#alt_" + strTmpID).length==0) && $("#alt_" + strTmpID).val()!="" ? $("#alt_" + strTmpID).val() : "");
//			alert("OLD ID" + strTmpID + "\n" + "NEW ID" + strTmpAltID)
			cart_task = cart_task.replace(strTmpID,strTmpAltID);
			cart_task = cart_task.replace("_FO","_FA");
			$(this).attr("id",$(this).attr("id").replace(strTmpID,strTmpAltID));
			$(this).attr("id",$(this).attr("id").replace("FO_","FA_"));
			
		}
		if(cart_task.substring(cart_task.length - 11,cart_task.length) == "_PKGAInCart"){//From FO Day Return with Attr already in the cart
			boolPKGWithATTRAlreadyAdded = true;
			strdebugmess = "";
			boolPKGAdd = true;
			intAID = $("#APKGIDCart").val();
		strdebugmess += "intAID:" + intAID + "\n";
			strAURL = $("#APKGURLCart").val();
		strdebugmess += "strAURL:" + strAURL + "\n";
			strAName = $("#APKGNameCart").val();
		strdebugmess += "strAName:" + strAName + "\n";
			dblpax_a = $("#APKGA_" + intAID).val();
		strdebugmess += "dblpax_a:" + dblpax_a + "\n";
			dblpax_c = $("#APKGC_" + intAID).val();
		strdebugmess += "dblpax_c:" + dblpax_c + "\n";
			dblpax_sen = $("#APKGA_" + intAID).val();
		strdebugmess += "dblpax_sen:" + dblpax_sen + "\n";
			dblpax_stu = $("#APKGA_" + intAID).val();
		strdebugmess += "dblpax_stu:" + dblpax_stu + "\n";
			cart_task = cart_task.substring(0,cart_task.length - 11);
		strdebugmess += "cart_task:" + cart_task + "\n";
//		alert("strdebugmess: \n" + strdebugmess)
			$(".bookpackage").each(function(){
				var arrTmptask = $(this).attr("id");
				var strTmpID = $.trim(arrTmptask.split("_")[2]);
				var strTmpAltID = ( !($("#alt_" + strTmpID).length==0) && $("#alt_" + strTmpID).val()!="" ? $("#alt_" + strTmpID).val() : "");
	//							alert("OLD ID" + intsummary_id + "\n" + "NEW ID" + strTmpAltID)
				cart_task = cart_task.replace(strTmpID,strTmpAltID);
				cart_task = cart_task.replace("_FO","_FA");
				$(this).attr("id",$(this).attr("id").replace(strTmpID,strTmpAltID));
				$(this).attr("id",$(this).attr("id").replace("_FO","_FA"));
			});
		}


		if(cart_task.substring(cart_task.length - 6,cart_task.length) == "_PKGDN"){//FO day return search 
			boolDontKnowSelected = true;
			boolPKGAdd = true;
			cart_task = cart_task.substring(0,cart_task.length - 6);
			arrcart_task = cart_task.split("#");
			intarrcart_task_count = arrcart_task.length;
			intAID = arrcart_task[intarrcart_task_count-1];
			intIDlen = intAID.length;
			cart_task = cart_task.substring(0,cart_task.length - (intIDlen+1));
			strAURL = $("#APKGURL_"+intAID).attr("href");
			strAName = $("#APKGName_"+intAID).html();
			dblpax_a = $("#APKGA_" + intAID).val();//PRICE
			dblpax_c = $("#APKGC_" + intAID).val();//PRICE
			dblpax_sen = $("#APKGA_" + intAID).val();//PRICE
			dblpax_stu = $("#APKGA_" + intAID).val();//PRICE
		}

		if(cart_task.substring(cart_task.length - 8,cart_task.length) == "_PKGDNDN"){//don't know attr selected 
			boolDontKnowSelected = true;
			boolPKGAdd = true;
			cart_task = cart_task.substring(0,cart_task.length - 8);
			arrcart_task = cart_task.split("#");
			intarrcart_task_count = arrcart_task.length;
			intAID = arrcart_task[intarrcart_task_count-1];
			intIDlen = intAID.length;
			cart_task = cart_task.substring(0,cart_task.length - (intIDlen+1));
			strAURL = $("#APKGURL_"+intAID).attr("href");
			strAName = $("#APKGName_"+intAID).html();
			dblpax_a = $("#APKGA_" + intAID).val();//PRICE
			dblpax_c = $("#APKGC_" + intAID).val();//PRICE
			dblpax_sen = $("#APKGA_" + intAID).val();//PRICE
			dblpax_stu = $("#APKGA_" + intAID).val();//PRICE
			$(".bookpackage").each(function(){
				var arrTmptask = $(this).attr("id");
				var strTmpID = $.trim(arrTmptask.split("_")[2]);
				var strTmpAltID = ( !($("#alt_" + strTmpID).length==0) && $("#alt_" + strTmpID).val()!="" ? $("#alt_" + strTmpID).val() : "");
//							alert("OLD ID" + intsummary_id + "\n" + "NEW ID" + strTmpAltID)
				cart_task = cart_task.replace(strTmpID,strTmpAltID);
				cart_task = cart_task.replace("_FO","_FA");
				$(this).attr("id",$(this).attr("id").replace(strTmpID,strTmpAltID));
				$(this).attr("id",$(this).attr("id").replace("_FO","_FA"));
			});

		}

		//Product count
		if( !($("#IPC").length == 0)){
			var IPC = $("#IPC").val().split(" ")[0];
		}else{
			var IPC = "0";
		}
		
		var IPC_attr = $("#IPC_attr").val();
		var IPC_flt = $("#IPC_flt").val();
		var IPC_ownstock = $("#IPC_ownstock").val();



		var strtask = $(this).attr("id").split("_")[0];
		var strproducttype = $(this).attr("id").split("_")[1];
		var intsummary_id = (strtask == "a" ? $(this).attr("id").split("_")[2] : (strtask == "d" ? $(this).attr("id").split("_")[3] : ""));

		var del_id = (strtask == "d" ? $(this).attr("id").split("_")[2] : "");
		var varURL = ( strproducttype == "a" && strtask != "d" ? $("#varURL").val().replace("_",escape("_")) : "" );
		var varName = ( strproducttype == "a" && strtask != "d" ? $("#varName").val().replace("_",escape("_")) : "" );
		if(boolPKGAdd == false){
			cart_task += "_" + varName + "_" + varURL;
		}
		var strCartReplaceMess = "";
		var cart_task_rep = ""
		var cart_task_rep_tmp = ""

//		alert("TESTING\nstrproducttype - " + strproducttype + "\nstrtask - " + strtask + "\nIPC_attr - " + IPC_attr + "\n" + "IPC_flt - " + IPC_flt + "\n" + "IPC_ownstock - " + IPC_ownstock + "\n");

		if(strtask == "a"){
			if(strproducttype == "f" && IPC_flt == 1 && IPC_attr == 0 ){
				strCartReplaceMess = "You already have a flight in your basket. Please press ok to confirm that you wish to replace that flight with the selected ";
				if(boolPKGAdd){
					strCartReplaceMess += " package.";
					cart_task_rep_tmp = "F_FA";
				}else{
					strCartReplaceMess += " flight.";
					cart_task_rep_tmp = "F_F";
				}
				boolConfirmAdd = (boolDontKnowSelected ? true : confirm(strCartReplaceMess) );
				if(boolConfirmAdd){
					cart_task_rep = cart_task_rep_tmp;
				}else{
					return false;
				}
			}
			if(strproducttype == "f" && IPC_attr == 1 && IPC_flt == 0){
				strCartReplaceMess = "You already have an attraction in your basket. Please press ok to confirm that you wish to replace that attraction with the selected ";
				strCartReplaceMess += ""
				if(boolPKGAdd){
					strCartReplaceMess += " package.";
					cart_task_rep_tmp = "A_FA";
					if(!boolPKGWithATTRAlreadyAdded){
						boolConfirmAdd = confirm(strCartReplaceMess);
					}else{
						boolConfirmAdd = true;
					}
					if(boolConfirmAdd){
						cart_task_rep = cart_task_rep_tmp;
					}else{
						return false;
					}
				}else{
					//Thats fine - normal flight added to attraction
				}
			}
			if(strproducttype == "f" && IPC_attr == 1 && IPC_flt == 1){//Already a package
				strCartReplaceMess = "You already have a flight / attraction package in your basket. Please press ok to confirm that you wish to replace ";
				if(boolPKGAdd){
					strCartReplaceMess += " that package with your new package choice.";
					cart_task_rep_tmp = "FA_FA";
				}else{
					strCartReplaceMess += " the flight portion of that package with your new flight choice.";//(NEED TO CHECK IF FLIGHT BEING ADDED IS DAY RETURN AT THIS POINT";
					cart_task_rep_tmp = "FA_F";
				}
				boolConfirmAdd = confirm(strCartReplaceMess);
				if(boolConfirmAdd){
					cart_task_rep = cart_task_rep_tmp;
				}else{
					return false;
				}
			}
			if(strproducttype == "a" && IPC_attr == 1 && IPC_flt == 1){//Already a package
				strCartReplaceMess = "You already have a flight / attraction package in your basket. Please press ok to confirm that you wish to replace ";
				strCartReplaceMess += " the attraction portion of that package with your new attraction choice.";// (NEED TO CHECK IF Attraction BEING ADDED IS THE RIGHT LOCATION";
				boolConfirmAdd = confirm(strCartReplaceMess);
				if(boolConfirmAdd){
					cart_task_rep = "FA_A";
				}else{
					return false;
				}
			}
			if(strproducttype == "a" && IPC_attr == 1 && IPC_flt == 0){//Already an attraction
				strCartReplaceMess = "You already have an attraction in your basket. Please press ok to confirm that you wish to replace ";
				strCartReplaceMess += " that attraction with your new attraction choice.";
				boolConfirmAdd = confirm(strCartReplaceMess);
				if(boolConfirmAdd){
					cart_task_rep = "A_A";
				}else{
					return false;
				}
			}
			$('#action_' + intsummary_id).hide();
			$('#noaction_' + intsummary_id).hide();
			$('#spinadding_' + intsummary_id).show();
		}
		if(strtask == "d"){
			$('#delaction_' + del_id).hide();
			$('#spindeleting_' + del_id).show();
		}
		if(strtask == "c"){
			
//			$('#c_cart_4u_x').hide();
//			$('#SpinClearCart').show();
		}
		var strURL = ( !($("#ABSOLUTEPATH").length == 0) ? $("#ABSOLUTEPATH").val() : "./" ) + "cart.php";
		var boolOneWay = ( !($("#searchsummarytxt").length == 0) && $("#searchsummarytxt").html().indexOf("OneWay") > 0 ? true : false );
		var boolDayReturn = ( !($("#searchsummaryobtxt").length == 0) && !($("#searchsummaryibtxt").length == 0) && $("#searchsummaryobtxt").html() == $("#searchsummaryibtxt").html() ? true : false );
		var boolShowAttractionUpsell = ( boolDontKnowSelected || (boolPKGAdd && !boolOneWay) ? "N" : ( cart_task.substring(0,3) == "a_f" && boolDayReturn? "Y" : "N" ) );
		$.ajax({
			url:strURL,
			beforeSend: function(){
			},
			success: function(data){
				if(strtask == "a"){
					$('#spinadding_' + intsummary_id).hide();
					$('#action_' + intsummary_id).hide();
					$('#noaction_' + intsummary_id).show();
					$("#cart_container").show();
					$('#flightresults_div').hide();
					$('#flightresults_searchagain').hide();
					if(boolShowAttractionUpsell == "Y"){
						$(".bookpackage").each(function(){
							var arrTmptask = $(this).attr("id");
							var strTmpID = $.trim(arrTmptask.split("_")[2]);
							var strTmpAltID = ( !($("#alt_" + intsummary_id).length==0) && $("#alt_" + intsummary_id).val()!="" ? $("#alt_" + intsummary_id).val() : "");
//							alert("OLD ID" + intsummary_id + "\n" + "NEW ID" + strTmpAltID)
							$(this).attr("id",$(this).attr("id").replace(strTmpID,strTmpAltID));
							$(this).attr("id",$(this).attr("id").replace("_FO","_FA"));
						});
						$('#attractionupselldiv').show();
					}else{
						$('#attractionupselldiv').hide();
					}
					UpdateTravelRoute();
				}
				var boolCartUpdate = true;
				if(strtask == "d"){
					if($("#IPC").val() == "1 Item"){
						boolCartUpdate = false;
						var strWindowLocation = window.location.toString();
						var RedirectURL =  ( strWindowLocation.indexOf("localhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/" : (strWindowLocation.indexOf("prowebgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/" : "http://www.hovertravel.co.uk/" ));
						top.location.href=RedirectURL;//redirection
					}else{
						$('#delaction_' + del_id).hide();
						$('#action_' + intsummary_id).show();
						$('#noaction_' + intsummary_id).hide();
						UpdateTravelRoute();
					}
				}
				if(strtask == "c"){
					var strWindowLocation = window.location.toString();
					var RedirectURL =  ( strWindowLocation.indexOf("localhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/" : (strWindowLocation.indexOf("prowebgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/" : "http://www.hovertravel.co.uk/" ));
					top.location.href=RedirectURL;//redirection
					UpdateTravelRoute();
					return false;
				}

				if(!($("#cart_container").length==0) && boolCartUpdate){
					$('html,body').animate({scrollTop: $("#cart_container").offset().top}, 1000);
					$("#cart_container").html(data);
					$("#cartmsg").delay(2000).fadeOut('slow');
				}

				if( !($("#IPC").length == 0)){
					IPC = $("#IPC").val().split(" ")[0];
				}else{
					IPC = "0";
				}

				if(IPC == "0"){
					var strBasketSummary = 'You have 0 items in your basket';
					$("#intProductCountUpdate").html(strBasketSummary);
					collapse($('.item'));
				}else{
					var intItems = $("#IPC").val().split(" ")[0];
					var strItems = $("#IPC").val().split(" ")[1];
					var strBasketSummary = '<a href="basket.php">You have <span id="intProductCount">'+$("#IPC").val()+' in your basket</span> </a> | <a href="#" id="c_cart_4u_x" class="clearcart">Empty Basket</a>';
					$("#intProductCountUpdate").html(strBasketSummary);
				}
				$('#pagetitlewide-basket').animate({marginTop:"40px"})
			},
			data:{
				cart_task:cart_task,
				cart_task_rep:cart_task_rep,
				boolPKGAdd:(boolPKGAdd?"Y":"N"),
				intAID:intAID,
				dblpax_a:dblpax_a,
				dblpax_c:dblpax_c,
				dblpax_sen:dblpax_sen,
				dblpax_stu:dblpax_stu,
				strAURL:strAURL,
				strAName:strAName,
				boolShowAttractionUpsell:boolShowAttractionUpsell
			},
			async:false
		});
		return false;
	});


	$("body").delegate(".slide-button-search, #searchagain-search, #searchagain-upsell, #searchagain-cart", "click", function() {
		$('html,body').animate({scrollTop: $("#header").offset().top}, 1000);
		if($(this).attr("id") == "close-button") {
			$("#testZone2").slideUp(1000);
			$("#pagetitlewide-search").animate({marginTop:"40px"}, 1000);
			$("#close-button").hide();
			$("#open-button").show();
		} else {
			$('.FlightSearchSubmitSearching').hide();
			$('.FlightSearchSubmitImg').show();
			$("#testZone2").slideDown(1000);
			$("#pagetitlewide-search").animate({marginTop:"0px"}, 1000);
			$("#open-button").hide();
			$("#close-button").show();
		}
	});

	$("#CardExpMonth").change(function() {
		//alert("CardExpMonthtest1");
		$("#expiryDate").val(String($("#CardExpMonth").val()) + String($("#CardExpYear").val()));
		//alert("CardExpMonthtest2");
	});


	$("#CardExpYear").change(function() {
		$("#expiryDate").val(String($("#CardExpMonth").val()) + String($("#CardExpYear").val()));
	});

	$("body").delegate("#CardFromMonth", "change", function() {
		$("#startDate").val(String($("#CardFromMonth").val()) + String($("#CardFromYear").val()));
	});

	$("body").delegate("#CardFromYear", "change", function() {
		$("#startDate").val(String($("#CardFromMonth").val()) + String($("#CardFromYear").val()));
	});

	$("#startDate").val(String($("#CardFromMonth").val()) + String($("#CardFromYear").val()));

	$("#bookingform").validate({
		groups: {
			allpax: "pax_a pax_c pax_i pax_sen pax_stu",
			allpaxFA: "pax_aFA pax_cFA pax_iFA pax_senFA pax_stuFA"
		},
		errorPlacement: function(error, element) {  
			$(element).attr({"title": error.append()});
		},
		rules: {
			attractionsearch_1: {
				required: function(element) {
					if ($("#searchtype").val() == "FA" && $("#travelroute_1").val() == "Ryde to Southsea"){
						if($("#attractionsearch_1").val()==""){
							$("#attractionsummarylinkcontainer").hide();
							$("#attractionsummaryNolinkcontainer").hide();
							$("#attractionsummaryimgerr").show();
//							alert("theme.php 1");
						}else{
							if($("#attractionsearch_1").val()=="DN"){
								$("#attractionsummaryimgerr").hide();
								$("#attractionsummaryNolinkcontainer").show();
//								alert("theme.php 2");
							}else{
//								alert("val - " + $("#attractionsearch_2").val());
								$("#attractionsummaryimgerr").hide();
								$("#attractionsummaryNolinkcontainer").hide();
								$("#attractionsummarylinkcontainer").show();
//								alert("theme.php 3");
							}
						}
					}else{
					}
					return ($("#searchtype").val() == "FA" && $("#travelroute_1").val() == "Ryde to Southsea");
				}
			},
			attractionsearch_2: {
				required: function(element) {
					if ($("#searchtype").val() == "FA" && $("#travelroute_2").val() == "Southsea to Ryde"){
						if($("#attractionsearch_2").val()==""){
							$("#attractionsummaryNolinkcontainer").hide();
							$("#attractionsummarylinkcontainer").hide();
							$("#attractionsummaryimgerr").show();
//							alert("theme.php 4");
						}else{
							if($("#attractionsearch_2").val()=="DN"){
								$("#attractionsummaryimgerr").hide();
								$("#attractionsummarylinkcontainer").hide();
								$("#attractionsummaryNolinkcontainer").show();
//								alert("theme.php 5");
							}else{
								$("#attractionsummaryNolinkcontainer").hide();
								$("#attractionsummaryimgerr").hide();
								$("#attractionsummarylinkcontainer").show();
//								alert("theme.php 6");
							}
						}
					}else{
					}
					return ($("#searchtype").val() == "FA" && $("#travelroute_2").val() == "Southsea to Ryde");
				}
			},
			travel_route:{
				required: function(element) {
					if ($("#searchtype").val() == "FA"){
						if( $("#travelroute_2").val() != ""){
							$("#travelroute_2").css({'borderLeft':'1px solid #999999'});
							$("#travelroute_2").css({'borderTop':'1px solid #999999'});
							$("#travelroute_2").css({'borderRight':'1px solid #999999'});
							$("#travelroute_2").css({'borderBottom':'1px solid #999999'});
						}else{
							$("#travelroute_2").css({'borderLeft':'2px solid #FF0000'});
							$("#travelroute_2").css({'borderTop':'2px solid #FF0000'});
							$("#travelroute_2").css({'borderRight':'2px solid #FF0000'});
							$("#travelroute_2").css({'borderBottom':'2px solid #FF0000'})
						}
					}else{
						if( $("#travelroute_1").val() != ""){
							$("#travelroute_1").css({'borderLeft':'1px solid #999999'});
							$("#travelroute_1").css({'borderTop':'1px solid #999999'});
							$("#travelroute_1").css({'borderRight':'1px solid #999999'});
							$("#travelroute_1").css({'borderBottom':'1px solid #999999'});
						}else{
							$("#travelroute_1").css({'borderLeft':'2px solid #FF0000'});
							$("#travelroute_1").css({'borderTop':'2px solid #FF0000'});
							$("#travelroute_1").css({'borderRight':'2px solid #FF0000'});
							$("#travelroute_1").css({'borderBottom':'2px solid #FF0000'})
						}
					}
					return ( $("#searchtype").val() == "FA" && $("#travelroute_2").val() == "" || $("#searchtype").val() == "FO" && $("#travelroute_1").val() == "") ;
				}
			},
			pax_a:  {
				required: function(element) {
//					return ($("select[name=pax_c]").val() < 1);
					return ($("select[name=pax_c]").val() < 1 && $("select[name=pax_sen]").val() < 1);
//					return ($("select[name=pax_c]").val() < 1 && $("select[name=pax_sen]").val() < 1 && $("select[name=pax_stu]").val() < 1);
				},
				min: function(element) {
//					return (($("select[name=pax_c]").val() < 1) ? 1 : 0);
					return (($("select[name=pax_c]").val() < 1 && $("select[name=pax_sen]").val() < 1) ? 1 : 0);
//					return (($("select[name=pax_c]").val() < 1 && $("select[name=pax_sen]").val() < 1 && $("select[name=pax_stu]").val() < 1) ? 1 : 0);
				}
			},
			pax_c:  {
				required: function(element) {
//					return ($("select[name=pax_a]").val() < 1);
					return ($("select[name=pax_a]").val() < 1 && $("select[name=pax_sen]").val() < 1);
//					return ($("select[name=pax_a]").val() < 1 && $("select[name=pax_sen]").val() < 1 && $("select[name=pax_stu]").val() < 1);
				},
				min: function(element) {
//					return (($("select[name=pax_a]").val() < 1) ? 1 : 0);
					return (($("select[name=pax_a]").val() < 1 && $("select[name=pax_sen]").val() < 1) ? 1 : 0);
//					return (($("select[name=pax_a]").val() < 1 && $("select[name=pax_sen]").val() < 1 && $("select[name=pax_stu]").val() < 1) ? 1 : 0);
				}
			},
			pax_aFA:  {
				required: function(element) {
//					return ($("#searchtype").val() == "FA" && $("select[name=pax_cFA]").val() < 1);
					return ($("#searchtype").val() == "FA" && $("select[name=pax_cFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1);
//					return ($("#searchtype").val() == "FA" && $("select[name=pax_cFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1 && $("select[name=pax_stuFA]").val() < 1);
				},
				min: function(element) {
//					return ($("#searchtype").val() == "FA" && ($("select[name=pax_cFA]").val() < 1) ? 1 : 0);
					return ($("#searchtype").val() == "FA" && ($("select[name=pax_cFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1) ? 1 : 0);
//					return ($("#searchtype").val() == "FA" && ($("select[name=pax_cFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1 && $("select[name=pax_stuFA]").val() < 1) ? 1 : 0);
				}
			},
			pax_cFA:  {
				required: function(element) {
//					return ($("#searchtype").val() == "FA" && $("select[name=pax_aFA]").val() < 1);
					return ($("#searchtype").val() == "FA" && $("select[name=pax_aFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1);
//					return ($("#searchtype").val() == "FA" && $("select[name=pax_aFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1 && $("select[name=pax_stuFA]").val() < 1);
				},
				min: function(element) {
//					return ($("#searchtype").val() == "FA" && ($("select[name=pax_aFA]").val() < 1) ? 1 : 0);
					return ($("#searchtype").val() == "FA" && ($("select[name=pax_aFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1) ? 1 : 0);
//					return ($("#searchtype").val() == "FA" && ($("select[name=pax_aFA]").val() < 1 && $("select[name=pax_senFA]").val() < 1 && $("select[name=pax_stuFA]").val() < 1) ? 1 : 0);
				}
			}
		},
		submitHandler: function(form) {
			$('.FlightSearchSubmitImg').hide();
			$('.FlightSearchSubmitSearching').show();
			form.submit();
		}
	});

	$("#BookingForm").validate({
		rules: {
			ContactVerifyEmail: {
				equalTo: "#ContactEmail"
			}
		},
		submitHandler: function(form) {
			var boolShowAlerts = false;
			var strWindowLocation = window.location.toString();
			var RedirectURL = (strWindowLocation.indexOf("lhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/booking.php" : (strWindowLocation.indexOf("webgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/booking.php" : "https://www.hovertravel.co.uk/booking.php" ));
			$('#submit4u').hide();
			$('#SpinSubmitCart').show();
			var rqbkflt = $("#rqbkflt").val();
			var rqpmt = $("#rqpmt").val();
			var strPmtURL = $("#strPmtURL").val();
			var strFltURL = $("#strFltURL").val();
			var strOwnStockURL = $("#strOwnStockURL").val();
			var varCCAddress1 = $("#addLine1").val();
			var varCCPostCode = $("#postcode").val();
			//First check status of previous linked stock bookings
			$.ajax({
				type: "post",
				url: "ownstockprevious.php",
				beforeSend: function(){
					if(boolShowAlerts){
						alert("Checking Stock Booking Status...")
					}
				},
				data:{
					varCCAddress1:varCCAddress1,
					varCCPostCode:varCCPostCode
				},
				success: function(data){
					if(data!=""){
						$('#SpinSubmitCart').hide();
						$('#submit4u').show();
						alert(data);
						return false;
					}else{//Continue booking as normal
						if(rqbkflt){
							$("#BookingForm").attr("action",strFltURL);
//							boolRequestBookFlight = confirm("Request Flight Booking (TESTING)");
							boolRequestBookFlight = true;
							if(boolRequestBookFlight){
								if(boolShowAlerts){
									alert("Flight Booking Request attempting (TESTING)");
								}
								$(form).ajaxSubmit({
									beforeSerialize: function($form, options) {
										$(".noentee").attr("disabled","disabled");
									},
									target:"#flightconfirm",
									success: function(data){
										if(boolShowAlerts){
											alert("response received")
										}
										if(data.substring(0,7) == "Errors:" && data.indexOf("OK:OK") == -1){
											var strEnteeFailDesc = data;
											$.ajax({
												type: "post",
												url: "cart.php",
												beforeSend: function(){
													if(boolShowAlerts){
														alert("Flight booking error...")
													}
												},
												success: function(data){
													$(".noentee").attr("disabled","");
													$('#SpinSubmitCart').hide();
													$('#submit4u').show();
													$('#flightconfirm').hide();
													$('html,body').animate({scrollTop: $("#cart_container").offset().top}, 1000);
													$("#cart_container").html(data);
												},
												data:{
													strEnteeFailDesc:strEnteeFailDesc
												},
												async:false
											});
											return false;
										}else{
											$(".noentee").attr("disabled","");
											if(boolShowAlerts){
												alert("rqpmt test");
											}
											if(rqpmt){
												var boolYesPayTestRequestSuccess = YesPayTestRequest();
												if(boolShowAlerts){
													alert("boolYesPayTestRequestSuccess - " + boolYesPayTestRequestSuccess)
												}
												if(boolYesPayTestRequestSuccess == "yes"){
													if(boolShowAlerts){
														alert("rqpmt to "+strPmtURL);
													}
													$("#BookingForm").attr("action",strPmtURL);
													$(".nopay").attr("disabled","disabled");
													var queryString = $('#BookingForm').formSerialize();
													if(boolShowAlerts){
														alert("queryString - " + queryString)
													}
													form.submit();
													return false;
												}else{
													if(boolYesPayTestRequestSuccess == "no"){
														top.location.href=RedirectURL + "?result=999999";//redirection
														return false;
													}else{
														if(boolYesPayTestRequestSuccess == "noflight"){
															top.location.href=RedirectURL + "?result=999998";//redirection
															return false;
														}else{
															if(boolYesPayTestRequestSuccess == "noURL"){
																top.location.href=RedirectURL + "?result=999997";//redirection
																return false;
															}else{
																if(boolYesPayTestRequestSuccess == "noajax"){
																	top.location.href=RedirectURL + "?result=999996";//redirection
																	return false;
																}else{
																	top.location.href=RedirectURL + "?result=999999";//redirection
																	return false;
																}
															}
														}
													}
												}
											}else{
												if(boolShowAlerts){
													alert("Payment Request NOT attempted (TESTING)");
													$('#SpinSubmitCart').hide();
													$('#submit4u').show();
												}
												return false;
											}
										}
									}
								});
							}else{
								if(boolShowAlerts){
									alert("Flight Booking Request NOT attempted (TESTING)");
									$('#SpinSubmitCart').hide();
									$('#submit4u').show();
								}
								return false;
							}
						}else{
							if(rqpmt){
								$("#BookingForm").attr("action",strOwnStockURL);
								if(boolShowAlerts){
									alert("Own Stock details to session (TESTING)");
								}
								$(form).ajaxSubmit({
									beforeSerialize: function($form, options) {
										$(".noentee").attr("disabled","disabled");
									},
									target:"#flightconfirm",
									success: function(data){
										$(".noentee").attr("disabled","");
										if(boolShowAlerts){
											alert("Own Stock details to session  (TESTING) complete")
										}
										$("#BookingForm").attr("action",strPmtURL);
										if(boolShowAlerts){
											boolRequestPayment = confirm("Request Payment (TESTING)");
										}else{
											boolRequestPayment = true;
										}
										if(boolRequestPayment){
											var boolYesPayTestRequestSuccess = YesPayTestRequest();
											if(boolYesPayTestRequestSuccess == "yes"){
												if(boolShowAlerts){
													alert("Payment Request attempting (TESTING)");
												}
												$(".nopay").attr("disabled","disabled");
												var queryString = $('#BookingForm').formSerialize();
												if(boolShowAlerts){
													alert("queryString - " + queryString)
												}
												form.submit();
												return false;
											}else{
												if(boolYesPayTestRequestSuccess == "no"){
													top.location.href=RedirectURL + "?result=999999";//redirection
													return false;
												}else{
													if(boolYesPayTestRequestSuccess == "noflight"){
														top.location.href=RedirectURL + "?result=999998";//redirection
														return false;
													}else{
														if(boolYesPayTestRequestSuccess == "noURL"){
															top.location.href=RedirectURL + "?result=999997";//redirection
															return false;
														}else{
															if(boolYesPayTestRequestSuccess == "noajax"){
																top.location.href=RedirectURL + "?result=999996";//redirection
																return false;
															}else{
																top.location.href=RedirectURL + "?result=999999";//redirection
																return false;
															}
														}
													}
												}
											}
										}else{
											if(boolShowAlerts){
												alert("Payment Request NOT attempted (TESTING)");
												$('#SpinSubmitCart').hide();
												$('#submit4u').show();
											}
											return false;
										}
									}
								});
							}else{
								if(boolShowAlerts){
									alert("Flight Booking Request NOT attempted (TESTING)");
									alert("Payment Request NOT attempted (TESTING)");
									$('#SpinSubmitCart').hide();
									$('#submit4u').show();
								}
								return false;
							}
						}
					}
				},
				async:false
			});
		}
	});


	$('#PromoForm').validate({
		submitHandler: function(form) {
			var boolShowAlerts = false;
			$('#validatepromo').hide();
			$('#Spinvalidatepromo').show();
			$(form).ajaxSubmit({
				beforeSend: function(){
					if(boolShowAlerts){
					}
					$("#validatepromoresponse").html('<div class="noticebooking" style="margin-top:15px; margin-bottom:0px; padding:5px;"><div style="width:40px; float:left;"><img height="23" width="23" style="margin-right:5px;" alt="Promotion code searching..." src="images/icon-info-hover.gif"></div><div style="float:left; padding:5px;"><p style="color:#009900;" > We are searching for discounted flights matching your promotional code and search criteria. Please wait a moment...</p></div></div>');
				},
				beforeSerialize: function($form, options) {
				},
				target:"#validatepromoresponse",
				success: function(data){
					if(data.substring(0,28) == "PromoProductAddedRefreshCart" || data.substring(0,31) == "PromoProductRevertedRefreshCart"){
						$("#validatepromoresponse").html("");
						$("#promocode").val("");
						PromoFormRefresh();
						CartRefresh("N");

						updatecardcharge();
//var strWindowLocation = window.location.toString();
//						var RefreshURL = (strWindowLocation.indexOf("lhost") > 0 ? "http://localhost/dev.hovertravel.co.uk/wwwroot/booking.php" : (strWindowLocation.indexOf("webgroup") > 0 ? "http://hovertravel.dev.prowebgroup.co.uk/booking.php" : "https://www.hovertravel.co.uk/booking.php" ));
//						top.location.href=RefreshURL;//refresh the cart...
						return false;
					}
					if(boolShowAlerts){
//						alert("SUCCESS FUNCTION...DATA:" + data)
					}
					$('#validatepromo').show();
					$('#Spinvalidatepromo').hide();
				}
			});
		}
	});

	$("#checkout4u").live("click",function() {
		$('#checkout4u').hide();
		$('#SpinCheckout').show();
	});

	$("a.copytoall").live("click",function() {
		var cart_task = $(this).attr("id");
		var attendeeID = cart_task.split("_")[1];
		var cartID = cart_task.split("_")[2];
		var copyval = $("#p_" + attendeeID + "_" + cartID).val();
		$(".attendee_" + attendeeID).val(copyval);
		return false;
	});

	$("#boolCopyCCAddress").click(function(){
		if($("#boolCopyCCAddress").attr("checked") == true){
			$("#CardAdd1").val($("#BillingAdd1").val());
			$("#CardAdd2").val($("#BillingAdd2").val());
			$("#CardTownCity").val($("#BillingTownCity").val());
			$("#CardPCode").val($("#BillingPCode").val());
			$("#CardCountry").val($("#BillingCountry").val());
		}
	});


	FlightSrch = function(){
	//	alert("5 second delay should have occured")
		$.ajax({
			data:{
				boolDisplayResults:"y"
			},
			type:"post",
			url:"XML/SearchRequest.php",
			beforeSend: function(){
	//			FlightSrchAjaxBefore();
				$.ajax({url:"XML/SearchRequest_pkg.php",type:"post",async:false});
			},
			success: function(data){
				FlightSrchAjaxSuccess();
				$('#searchresults_div').html(data);
//				Shadowbox.setup($("a[rel=shadowbox]"));
				if( ( (!($("#APKGID").length==0) && $("#APKGID").val()!="") || (!($("#APKGIDCart").length==0)  && $("#APKGIDCart").val()!=""))){
					if(!($("#APKGID").length==0) && $("#APKGID").val()!=""){
						var intID = $("#APKGID").val();
					}else{
						var intID = $("#APKGIDCart").val();
					}
					var dblpax_a = parseFloat($("#pax_a").val()) * parseFloat($("#APKGA_" + intID).val());
					var dblpax_c = parseFloat($("#pax_c").val()) * parseFloat($("#APKGC_" + intID).val());
	//				var dblpax_i = parseFloat($("#pax_i").val()) * parseFloat($("#APKGC_" + intID).val());
					var dblpax_i = 0;
					var dblpax_sen = ($("#pax_sen").length==0?0:parseFloat($("#pax_sen").val()) * parseFloat($("#APKGA_" + intID).val()));
					var dblpax_stu = ($("#pax_stu").length==0?0:parseFloat($("#pax_stu").val()) * parseFloat($("#APKGA_" + intID).val()));
					var dbltotal = parseFloat(parseFloat(dblpax_a) + parseFloat(dblpax_c) + parseFloat(dblpax_i) + parseFloat(dblpax_sen) + parseFloat(dblpax_stu)).toFixed(2);
//					var dbltotal = parseFloat(parseFloat(dblpax_a) + parseFloat(dblpax_c) + parseFloat(dblpax_i)).toFixed(2);

			//alert("intID - " + intID)

				$(".ticketprice").each(function () {
						$(this).html("Total Price: &pound;" + dbltotal);
					});
				}

				$(".flighttablediv" ).each(function(){
					$(this).slideDown(2000);
				});
				$(".add_status" ).each(function(){
					var intsummary_id = $(this).attr("id").split("_")[2];
					if( data.indexOf( "add_status_" +  intsummary_id + "_1") !== -1 ){
						$('#noaction_' + intsummary_id).hide();
						$('#action_' + intsummary_id).show();
					}else{
						$('#action_' + intsummary_id).hide();
						$('#noaction_' + intsummary_id).show();
					}
					//PACKAGE MATCH...
					$.ajax({
						data:{
							strSessVar:"arrSearchResults",
							intsummary_id:intsummary_id
						},
						type:"post",
						url:"XML/SearchMatchPkg.php",
						beforeSend: function(){
	//						$('#pguidewait_' + intsummary_id).show();
						},
						success: function(data){
							if(data.substring(0,2) == "No"){
								$("#flighttablediv_" + intsummary_id).hide();
							}else{
//								$('#pguidewait_' + intsummary_id).hide();
//								$('#pguide_' + intsummary_id).html(data);
//								$('#pguide_' + intsummary_id).slideDown(2000);
								$('#alt_' + intsummary_id).val(data);
							}
						},
						async:true
					});
				});
			},
			async:true
		});
	}

});

function UpdateTravelRoute(){//Update the travel route dropdown based on cart content
	$.ajax({
		type: "post",
		url: "updatetravelroute.php",
		beforeSend: function(){
			$(".FlightSearchSubmitImg").hide();
			$(".FlightSearchSubmitSearching").show();
		},
		success: function(data){
			strrouteblock = data;
			
//			alert("strrouteblock (updateTravelRoute) - " + strrouteblock)
			
			$(".travelroute").each(function(){

//alert("test UpdateTravelRoute 1021 js.js");

				if(strrouteblock == "2"){
					$("#" + $(this).attr('id') + " option").remove();
					$("#" + $(this).attr('id')).attr('options')[0] = new Option('Southsea to Ryde', 'Southsea to Ryde', true, true);
					if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
						$("#attractionsummarylinkcontainer").hide();
						$("#attractionsummaryNolinkcontainer").show();
					}else{
						$("#attractionsummaryNolinkcontainer").hide();
						$("#attractionsummarylinkcontainer").show();
					}
					$("#attractionsearch_1").attr("disabled","disabled");
					$("#attractionsearch_2").attr("disabled","");
					$("#AttractionsDropDown_1").hide();
					$("#AttractionsDropDown_2").show();
					
				}else{
					if(strrouteblock == "1"){
						$("#" + $(this).attr('id') + " option").remove();
						$("#" + $(this).attr('id')).attr('options')[0] = new Option('Ryde to Southsea', 'Ryde to Southsea', true, true);
						if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
							$("#attractionsummarylinkcontainer").hide();
							$("#attractionsummaryNolinkcontainer").show();
						}else{
							$("#attractionsummaryNolinkcontainer").hide();
							$("#attractionsummarylinkcontainer").show();
						}
						$("#attractionsearch_2").attr("disabled","disabled");
						$("#attractionsearch_1").attr("disabled","");
						$("#AttractionsDropDown_2").hide();
						$("#AttractionsDropDown_1").show();
					}else{
						$("#" + $(this).attr('id') + " option").remove();
						$("#" + $(this).attr('id')).attr('options')[1] = new Option('Southsea to Ryde', 'Southsea to Ryde', boolDefaultSelect, boolDefaultSelect);
						$("#" + $(this).attr('id')).attr('options')[2] = new Option('Ryde to Southsea', 'Ryde to Southsea', !boolDefaultSelect, !boolDefaultSelect);
						if(boolDefaultSelect){
							if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
								$("#attractionsummarylinkcontainer").hide();
								$("#attractionsummaryNolinkcontainer").show();
							}else{
								$("#attractionsummaryNolinkcontainer").hide();
								$("#attractionsummarylinkcontainer").show();
							}
							$("#attractionsearch_1").attr("disabled","disabled");
							$("#attractionsearch_2").attr("disabled","");
							$("#AttractionsDropDown_1").hide();
							$("#AttractionsDropDown_2").show();
						}else{
							if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
								$("#attractionsummarylinkcontainer").hide();
								$("#attractionsummaryNolinkcontainer").show();
							}else{
								$("#attractionsummaryNolinkcontainer").hide();
								$("#attractionsummarylinkcontainer").show();
							}
							$("#attractionsearch_2").attr("disabled","disabled");
							$("#attractionsearch_1").attr("disabled","");
							$("#AttractionsDropDown_2").hide();
							$("#AttractionsDropDown_1").show();
						}
					}
				}
			});
			$(".FlightSearchSubmitSearching").hide();
			$(".FlightSearchSubmitImg").show();
		},
		async:true
	});
	return false;
}

function AttractionSearchChange(intThisID,strThisClass,boolReset){
	var intID = $("#" + intThisID).val();
	$("#" + intThisID).attr("disabled","disabled");
	$("#attractionsummaryimgerr").hide();
	$("#attractionsummarylinkcontainer").hide();
	$("#attractionsummaryNolinkcontainer").hide();
	$("#attractionsummaryimgspin").show();
	var strAttractionName = $("#" + intThisID + " option:selected").html();
	$("#attractionsummaryimg").attr("alt",strAttractionName);
	$.ajax({
		type: "post",
		url: "attractionsummary.php",
		beforeSend: function(){
			$(".FlightSearchSubmitImg").hide();
			$(".FlightSearchSubmitSearching").show();
		},
		success: function(data){
			var strResponse1 = data.split("######")[0];
			var strResponse2 = data.split("######")[1];
			var strResponse3 = data.split("######")[2];
			strResponse1 = (strResponse1 == "none" ? "" : strResponse1);

			if(!$("#strrouteblock").length == 0){
				$("#strrouteblock").val(strResponse1);
			}
			$("#attractionsummaryimgspin").hide();
			if(strThisClass == "attractionsearchWide"){
				$("#attractionsummarydivWide").html(strResponse3);
			}else{
				$("#attractionsummarydiv").html(strResponse3);
			}
			if( strResponse3.indexOf("PLEASE SELECT AN ATTRACTION") !== -1 ){
				$("#attractionsummaryNolinkcontainer").hide();
				$("#attractionsummarylinkcontainer").hide();
				$("#attractionsummaryimgerr").show();
			}else{
				if( strResponse3.indexOf("PLEASE CHOOSE AN ATTRACTION") !== -1 ){
					$("#attractionsummarylinkcontainer").hide();
					$("#attractionsummaryNolinkcontainer").show();
				}else{
					$("#attractionsummaryimgerr").hide();
					$("#attractionsummaryimgspin").hide();
					$("#attractionsummarylinkcontainer").show();
				}
			}
			$("#" + intThisID).attr("disabled","");
			if(intID == "" && strAttractionName != "Select Attraction" && strAttractionName !=""){
				alert("PLEASE NOTE: This attraction (" + strAttractionName + ") is not open during your requested search date.");
			}
			strrouteblock = ( !$("#strrouteblock").length == 0 ? $("#strrouteblock").val() : "" );
			$(".travelroute").each(function(){
				if(strrouteblock == "2"){
					$("#" + $(this).attr('id') + " option").remove();
					$("#" + $(this).attr('id')).attr('options')[0] = new Option('Southsea to Ryde', 'Southsea to Ryde', true, true);
					if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
						$("#attractionsummarylinkcontainer").hide();
						$("#attractionsummaryNolinkcontainer").show();
					}else{
						$("#attractionsummaryNolinkcontainer").hide();
						$("#attractionsummarylinkcontainer").show();
					}
					$("#attractionsearch_1").attr("disabled","disabled");
					$("#attractionsearch_2").attr("disabled","");
					$("#AttractionsDropDown_1").hide();
					$("#AttractionsDropDown_2").show();
				}else{
					if(strrouteblock == "1"){
						$("#" + $(this).attr('id') + " option").remove();
						$("#" + $(this).attr('id')).attr('options')[0] = new Option('Ryde to Southsea', 'Ryde to Southsea', true, true);
						if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
							$("#attractionsummarylinkcontainer").hide();
							if(!$("#attractionsummaryimgerr").is(":visible")){
								$("#attractionsummaryNolinkcontainer").show();
							}
						}else{
							$("#attractionsummaryNolinkcontainer").hide();
							if(!$("#attractionsummaryimgerr").is(":visible")){
								$("#attractionsummarylinkcontainer").show();
							}
						}
						$("#attractionsearch_2").attr("disabled","disabled");
						$("#attractionsearch_1").attr("disabled","");
						$("#AttractionsDropDown_2").hide();
						$("#AttractionsDropDown_1").show();
					}else{
						$("#" + $(this).attr('id') + " option").remove();
						boolDefaultSelect = ( $("#AttractionsDropDown_2").is(":visible") ? (!boolReset ? true : false) : false );
						$("#" + $(this).attr('id')).attr('options')[0] = new Option('Please Select', '', boolReset, boolReset);
						$("#" + $(this).attr('id')).attr('options')[1] = new Option('Southsea to Ryde', 'Southsea to Ryde', boolDefaultSelect, boolDefaultSelect);
						boolDefaultSelect2 = ( boolReset ? false : !boolDefaultSelect );
						$("#" + $(this).attr('id')).attr('options')[2] = new Option('Ryde to Southsea', 'Ryde to Southsea', boolDefaultSelect2, boolDefaultSelect2);


						if(boolDefaultSelect){
							if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
								$("#attractionsummarylinkcontainer").hide();
								if(!$("#attractionsummaryimgerr").is(":visible")){
									$("#attractionsummaryNolinkcontainer").show();
								}
							}else{
								$("#attractionsummaryNolinkcontainer").hide();
								if(!$("#attractionsummaryimgerr").is(":visible")){
									$("#attractionsummarylinkcontainer").show();
								}
							}
							$("#attractionsearch_1").attr("disabled","disabled");
							$("#attractionsearch_2").attr("disabled","");
							$("#AttractionsDropDown_1").hide();
							$("#AttractionsDropDown_2").show();
						}else{
							if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
								$("#attractionsummarylinkcontainer").hide();
								if(!$("#attractionsummaryimgerr").is(":visible")){
									$("#attractionsummaryNolinkcontainer").show();
								}
							}else{
								$("#attractionsummaryNolinkcontainer").hide();
								if(!$("#attractionsummaryimgerr").is(":visible")){
									$("#attractionsummarylinkcontainer").show();
								}
							}
							$("#attractionsearch_2").attr("disabled","disabled");
							$("#attractionsearch_1").attr("disabled","");
							$("#AttractionsDropDown_2").hide();
							$("#AttractionsDropDown_1").show();
						}
					}
				}
			});
			$(".FlightSearchSubmitSearching").hide();
			$(".FlightSearchSubmitImg").show();
		},
		data:{
			intID:intID,
			boolAddIds:"N"
		},
		async:true
	});
	return false;
}

YesPayTestRequest = function() {//Check that the YesPay server is available... AND that a flight has been booked and still exists in the session.
	var boolSuccessfulTest = "yes";
	var strPmtURL = $("#strPmtURL").val();
//	alert("testing yes-pay service: " + strPmtURL);
	$.ajax({
		type: "post",
		url: "TestPay.php",
		beforeSend: function(){
		},
		success: function(data){
//			alert("data - " + data)
			if(data.indexOf("noflight") > 0){
				boolSuccessfulTest = "noflight";
			}else{
				if(data.indexOf("noURL") > 0){
					boolSuccessfulTest = "noURL";
				}else{
					if(data.indexOf("MTR=null") == -1){
						boolSuccessfulTest = "no";
					}
				}
			}
		},
		error:function (xhr, ajaxOptions, thrownError){
//			alert("status - " + xhr.status);
//			alert("thrownError - " + thrownError);
			boolSuccessfulTest = "noajax";
		},
		data:{
			strPmtURL:strPmtURL
		},
		async:false
	});
//alert("boolSuccessfulTest-" + boolSuccessfulTest)
	return boolSuccessfulTest;
}

//OWN STOCK START

UpdateOwnStockTotal = function(){
	var dblTotal = 0;
	$(".ownstockselect").each(function(){
		var inttmpid = $(this).attr("name").split("_")[1];
		dblTotal += ($(this).val()*$("#dblRetailPrice_" + inttmpid).val());
	});
	$("#OwnStockTotal").html(parseFloat(dblTotal).toFixed(2));
}

OwnStockCartTask = function(strOwnStockBookingTask,strSelectName,intTicketsSelected){
	var reqEventintID = strSelectName.split("_")[1];
	var intTicketID = strSelectName.split("_")[2];
	var strTargetID = "OwnStockTicketsBooking_" + reqEventintID;
	var arrTicketData=new Array();
	arrTicketData.push(intTicketsSelected + "_" + intTicketID);
	$.ajax({
		type: "post",
		url: "ownstockbooking.php",
		beforeSend: function(){
		},
		error: function(jqXHR, textStatus, errorThrown){
			//alert(errorThrown);
		},
		success: function(data){
			$("#" + strTargetID).html(data);
			UpdateOwnStockTotal();
			CartRefresh("Y");
		},
		data:{
			strOwnStockBookingTask: strOwnStockBookingTask,
			reqEventintID:reqEventintID,
			arrTicketData:arrTicketData
		},
		async:true
	});
}


OwnStockBookingTask = function(strOwnStockBookingTask,reqEventintID){
	var strTargetID = "OwnStockTicketsBooking_" + reqEventintID;
	var arrTicketData=new Array();
	if(strOwnStockBookingTask == "AddOwnStock"){
		$(".ownstockselect").each(function(){
			var inttmpid = $(this).attr("name").split("_")[1];
			if(parseFloat($(this).val())>0){
				arrTicketData.push($(this).val() + "_" + inttmpid);
			}
		});
	}else{
	}
	$.ajax({
		type: "post",
		url: "ownstockbooking.php",
		beforeSend: function(){
		},
		error: function(jqXHR, textStatus, errorThrown){
			//alert(errorThrown);
		},
		success: function(data){
			$("#" + strTargetID).html(data);
			UpdateOwnStockTotal();
			if(strOwnStockBookingTask == "AddOwnStock"){
				CartRefresh("Y");
			}
		},
		data:{
			strOwnStockBookingTask: strOwnStockBookingTask,
			reqEventintID:reqEventintID,
			arrTicketData:arrTicketData
		},
		async:true
	});
}

CartRefresh = function(strShowCartUpdateOptions){
	var strURL = ( !($("#ABSOLUTEPATH").length == 0) ? $("#ABSOLUTEPATH").val() : "./" ) + "cart.php";
	$.ajax({
		type:"post",
		url:strURL,
		beforeSend: function(){
		},
		success: function(data){
			var boolCartUpdate = true;
			if(!($("#cart_container").length==0) && boolCartUpdate){
				$('html,body').animate({scrollTop: $("#cart_container").offset().top}, 1000);
				$("#cart_container").html(data);
				$("#cartmsg").delay(2000).fadeOut('slow');
			}

			if( !($("#IPC").length == 0)){
				IPC = $("#IPC").val().split(" ")[0];
			}else{
				IPC = "0";
			}

			if(IPC == "0"){
				var strBasketSummary = 'You have 0 items in your basket';
				$("#intProductCountUpdate").html(strBasketSummary);
				collapse($('.item'));
			}else{
				var intItems = $("#IPC").val().split(" ")[0];
				var strItems = $("#IPC").val().split(" ")[1];
				var strBasketSummary = '<a href="basket.php">You have <span id="intProductCount">'+$("#IPC").val()+' in your basket</span> </a> | <a href="#" id="c_cart_4u_x" class="clearcart">Empty Basket</a>';
				$("#intProductCountUpdate").html(strBasketSummary);
			}
		},
		data:{
			strCartTask:"CartRefresh",
			strShowCartUpdateOptions:strShowCartUpdateOptions
		},
		async:false
	});
}
//OWN STOCK END

PromoFormRefresh = function(){
	var strURL = ( !($("#ABSOLUTEPATH").length == 0) ? $("#ABSOLUTEPATH").val() : "./" ) + "promoform.php";
	$.ajax({
		type: "post",
		url:strURL,
		beforeSend: function(){
		},
		success: function(data){
			$("#promoformdiv").html(data);
		},
		data:{
		},
		async:false
	});
}


FlightSrchAjaxBefore = function() {
	$('#searchresults_div').html("");
	$('#testZone2').hide();
	$(".banner").hide();
	$("#cart_container").hide();
	$("#flightwait").show();
	$('html,body').animate({scrollTop: $("#header").offset().top}, 1000);
	return false;
};
FlightSrchAjaxSuccess = function() {
	$("#flightwait").hide();
	$(".banner").show();
	$('html,body').animate({scrollTop: $("#searchresults_div").offset().top}, 1000);
	$('.FlightSearchSubmitSearching').hide();
	$('.FlightSearchSubmitImg').show();
	return false;
//	$('.adminerr').show();
//	$('.adminsucc').show().delay(2000).fadeOut('slow');
};


/* GOOGLE FONTS
-------------------------------------------------------------- */
//	      WebFontConfig = {
//	        google: { families: [ 'Droid Sans', 'IM Fell DW Pica', 'Tangerine:regular,bold' ] }
//	      };
//	      (function() {
//			document.getElementsByTagName("html")[0].setAttribute("class","wf-loading")
//			//  NEEDED to push the wf-loading class to your head
//			document.getElementsByTagName("html")[0].setAttribute("className","wf-loading") 
//	      	// for IE...
//	        var wf = document.createElement('script');
//	        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
//	            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
//	        wf.type = 'text/javascript';
//	        wf.async = 'false';
//	        var s = document.getElementsByTagName('script')[0];
//	        s.parentNode.insertBefore(wf, s);
//	      })();


/* SEARCH BOOKING SLIDER
-------------------------------------------------------------- */
(function($){
	
	$.fn.slideBox = function(params){
	
		var content = $(this).html();
		var defaults = {
			width: "100%",
			height: "200px",
			position: "top"// Possible values : "top", "bottom"
		}
		
		// extending the fuction
		if(params) $.extend(defaults, params);
		
		var divPanel = $("<div class='slide-panel'>");
		var divContent = $("<div class='content'>");
	
		$(divContent).html(content);
		$(divPanel).addClass(defaults.position);
		$(divPanel).css("width", defaults.width);
		
		// centering the slide panel
		$(divPanel).css("sliderleft", (100 - parseInt(defaults.width))/2 + "%");
	
		// if position is top we're adding 
		if(defaults.position == "top")
			$(divPanel).append($(divContent));
		
		// adding buttons
		if ( !($("#boolSeachCompleted").length==0) && $("#boolSeachCompleted").val() == "Y"){
			$(divPanel).append("<div class='slide-button slide-button-open'><img src='images/button-slider-up-new.png' /></div>");
		} else {
			$(divPanel).append("<div class='slide-button slide-button-open'><img src='images/button-slider-up.png' /></div>");
		}
		$(divPanel).append("<div style='display: none' id='close-button' class='slide-button slide-button-open'><img src='images/button-slider-down.png' /></div>");
		
		if( !$("#boolHideWideSearch").length==0 && $("#boolHideWideSearch").val() == "1"){
			$(divContent).css("height",200);
			$(divContent).css("z-index",0);
		}
		if(defaults.position == "bottom")
			$(divPanel).append($(divContent));
		
		$(this).replaceWith($(divPanel));
		
		// Buttons action
		$(".slide-button").click(function(){
			if($(this).attr("id") == "close-button") {
				if( !$("#boolHideWideSearch").length==0 && $("#boolHideWideSearch").val() == "1"){
//					alert("slide1")
					$(divContent).slideDown(1000);
				}else{
					$(divContent).animate({height: "0px"}, 1000);
				}
			} else {
				if( !$("#boolHideWideSearch").length==0 && $("#boolHideWideSearch").val() == "1"){
//					alert("slide2")
//					alert($(divContent).attr("id"))
					$(divContent).show();
//					$(divContent).slideUp(1000);
				}else{
					$(divContent).animate({height: defaults.height}, 1000);
				}
			}
			$(".slide-button").toggle();
		});
		$(".newsearch,.newsearchcart,.searchagaincart,.newsearchupsell").live("click",function(){
			$('html,body').animate({scrollTop: $("#header").offset().top}, 1000);
			if( !$("#boolHideWideSearch").length==0 && $("#boolHideWideSearch").val() == "1"){
//				alert("slide3")
				$(divContent).slideUp(1000);
			}else{
				$(divContent).animate({height: defaults.height}, 1000);
			}
			$(".slide-button").toggle();
			return false;
		});
	};
	
})(jQuery);

/* NAVIGATION
-------------------------------------------------------------- */
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

var validator = $(".newsletter").validate({
 onblur: function(el)
 {
  if(validator.check(el))
   $(el).removeClass(validator.settings.errorClass);
  else
   $(el).addClass(validator.settings.errorClass);
 },
 onkeyup: function(el)
 {
  if(validator.check(el))
   $(el).removeClass(validator.settings.errorClass);
  else
   $(el).addClass(validator.settings.errorClass);
 }
});


/* SEARCH BOX TABS
-------------------------------------------------------------- */
$(document).ready(function() {
	//Default Action
	$('.FlightSearchSubmitSearching').hide();
	$(".booking_tab_content").hide(); //Hide all content
	var boolFASeachCompleted = ( !$("#boolFASeachCompleted").length == 0 ? $("#boolFASeachCompleted").val() : "FO" );
	var strInitialTabType = ( boolFASeachCompleted == "Y" ? "last" : "first" );
	$("ul.bookingtabs li:" + strInitialTabType + ",ul.bookingtabs_wide li:" + strInitialTabType).addClass("active").show(); //Activate tab
	$(".booking_tab_content:" +  strInitialTabType).show(); //Show  tab content
	var activeTab = $(".booking_tab_content:" + strInitialTabType).attr("id"); //Find the rel attribute value to identify the active tab + content
	if(activeTab == "bookingtab1" || activeTab == "bookingtab3"){//FO
		$(".searchtype_FA").attr("disabled","disabled");
		$(".searchtype_FO").attr("disabled","");
		$("#FARadio").attr("checked","");
		$("#FORadio").attr("checked","checked");
	}else{//FA
		$(".searchtype_FA").attr("disabled","");
		$(".searchtype_FO").attr("disabled","disabled");
		$("#FORadio").attr("checked","");
		$("#FARadio").attr("checked","checked");
	}
	$("#searchtype").val((activeTab == "bookingtab1" || activeTab == "bookingtab3" ? "FO" : "FA"));
	strTravelRoute = (activeTab == "bookingtab1" || activeTab == "bookingtab3" ? $("#travelroute_1").val() : $("#travelroute_2").val());;

	$("#attractionsummaryimgerr").hide();

	if(strTravelRoute == "Ryde to Southsea"){
		$("#AttractionsDropDown_2").hide();
		$("#AttractionsDropDown_1").show();
		$("#attractionsearch_2").attr("disabled","disabled");
		$("#attractionsearch_1").attr("disabled","");
		strDefaultAttractionSearchId = "attractionsearch_1";
		if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
			$("#attractionsummaryNolinkcontainer").show();
		}else{
			$("#attractionsummarylinkcontainer").show();
		}
	}else{
		$("#AttractionsDropDown_1").hide();
		$("#AttractionsDropDown_2").show();
		$("#attractionsearch_1").attr("disabled","disabled");
		$("#attractionsearch_2").attr("disabled","");
		strDefaultAttractionSearchId = "attractionsearch_2";
		if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
			$("#attractionsummaryNolinkcontainer").show();
		}else{
			$("#attractionsummarylinkcontainer").show();
		}
	}
	if(activeTab == "bookingtab1" || activeTab == "bookingtab2"){//Not Wide
		AttractionSearchChange(strDefaultAttractionSearchId,"attractionsearch",true);
	}else{
		AttractionSearchChange(strDefaultAttractionSearchId,"attractionsearchWide",true);//Wide
	}

	$("#FARadio").live("click",function() {
		$("#FORadio").attr("checked","");
		$("#FARadio").attr("checked","checked");
	});

	$("#FORadio").live("click",function() {
		$("#FARadio").attr("checked","");
		$("#FORadio").attr("checked","checked");
	});



	$("ul.bookingtabs li,ul.bookingtabs_wide li").live("click",function() {
		$("ul.bookingtabs li, ul.bookingtabs_wide li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".booking_tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active content
		if(activeTab == "#bookingtab1" || activeTab == "#bookingtab3"){
			$(".searchtype_FA").attr("disabled","disabled");
			$(".searchtype_FO").attr("disabled","");
		}else{
			$(".searchtype_FA").attr("disabled","");
			$(".searchtype_FO").attr("disabled","disabled");
		}

		$("#searchtype").val((activeTab == "#bookingtab1" || activeTab == "#bookingtab3" ? "FO" : "FA"));
		var strTravelRoute = $("#travelroute_2").val();

		$("#attractionsummaryimgerr").hide();

		if(strTravelRoute == "Ryde to Southsea"){
			$("#AttractionsDropDown_2").hide();
			$("#AttractionsDropDown_1").show();
			$("#attractionsearch_2").attr("disabled","disabled");
			$("#attractionsearch_1").attr("disabled","");
			if($("#attractionsearch_1").val() == "DN" || $("#attractionsearch_1").val() == ""){
				$("#attractionsummaryNolinkcontainer").show();
			}else{
				$("#attractionsummarylinkcontainer").show();
			}
		}else{
			$("#AttractionsDropDown_1").hide();
			$("#AttractionsDropDown_2").show();
			$("#attractionsearch_1").attr("disabled","disabled");
			$("#attractionsearch_2").attr("disabled","");
			if($("#attractionsearch_2").val() == "DN" || $("#attractionsearch_2").val() == ""){
				$("#attractionsummaryNolinkcontainer").show();
			}else{
				$("#attractionsummarylinkcontainer").show();
			}
		}
		if(activeTab == "#bookingtab1" || activeTab == "#bookingtab3"){
			$("#FORadio").attr("checked","checked");
			$("#FARadio").attr("checked","");
		}else{
			$("#FARadio").attr("checked","checked");
			$("#FORadio").attr("checked","");
		}
		return false;
	});
	
	//On Click Event
	$("ul.bookingtabs_wide li").live("click",function() {
		$("ul.bookingtabs_wide li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".booking_tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active content
		return false;
	});
});
