// JavaScript Document
//var xmlhttp = null;
//var attractid;
//var passedValue;
function opennewsletter(){
emailwindow=dhtmlmodal.open('ComfirmBox', 'div', 'PopUpBox', 'Special Delivery', 'width=600px,height=150px,center=1,resize=0,scrolling=1')
}


	function pausecomp(millis){ 
		 var date = new Date(); 
		 var curDate = null; 
			 do { curDate = new Date(); } 
			 while(curDate-date < millis); 
	} 
//***END OF
//	End pausecomp(millis)


	function createXMLHTTPRequest() {
	    var request = null;
	    try {request = new XMLHttpRequest();}/* Firefox */
	    catch (err1){ 			    
	        try {request = new ActiveXObject('Msxml2.XMLHTTP');} // some IE's
	        catch (err2) {
	            try {request = new ActiveXObject('Microsoft.XMLHTTP'); } // some IE's
				catch (err3) { request = false;}
	        }
		}
	    return request;
	} 
//***END OF
//	createXMLHTTPRequest() | end getXMLHTTPRequest


	function visitDateCurrencyChange(thisAttractId, str){
		var attractid;
		var xmlhttp;
		xmlhttp = createXMLHTTPRequest();
		if (xmlhttp!=null) {		
			showSplashScreen();
			attractid = thisAttractId;
			passedValue = str;

			formName="form"+attractid; 
			
			//d = new Date(document.forms[formName].visitdate.value);	
			d = new Date(document.getElementById('visitdate' + attractid).value);
			//alert(d);
			if (d == "Invalid Date" || d == "NaN") d = new Date();
			var VTixMonth = d.getMonth()+1;
			var VTixDay = d.getDate();
			var VTixYear = d.getFullYear();
			
			var chooseCurrencyType =  document.forms[formName].currencyType.value;			
			var queryString = "?attractId=" + attractid + "&VTixMonth=" + VTixMonth + "&VTixDay=" + VTixDay +
						  "&VTixYear=" + VTixYear + "&chooseCurrencyType=" + chooseCurrencyType;
			var url = "ticketTypePriceInfo.cfm";
			url = url + queryString;
			//window.alert(url);
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=function() {onDateResponse(xmlhttp,attractid);}; 
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);			
		}
		else {
			alert("Your browser does not support XMLHTTP.");			
		}
	} 
//***END OF
//	End visitDateCurrencyChange(thisAttractId, str)



	function onDateResponse(xmlhttp, attractid){
		if(xmlhttp.readyState!=4) return;
		if(xmlhttp.status!=200) {
			alert("Problem retrieving XML data");
			return;
		}			
		x = xmlhttp.responseXML.documentElement.getElementsByTagName("ticket_types");
		//~~	if (x.length == 0)
		if (x.length == 0){
			//if (document.getElementById('visitdate' + attractid).value != '' && document.getElementById('visitdate' + attractid).value != 'Select Date')
				window.alert("There are no tickets available on the date chosen, Please try another day."	);
		}
		else {	
			var txt6 = "";
			for (i=0; i<x.length; i++){ 
				xx=x[i].getElementsByTagName("ticket_type");
				if (xx[0].firstChild != null) txt1 = xx[0].firstChild.nodeValue; else txt1="";					
				xx=x[i].getElementsByTagName("standard_price");
				if (xx[0].firstChild != null) txt2 = xx[0].firstChild.nodeValue; else txt2="";										
				xx=x[i].getElementsByTagName("our_price");
				if (xx[0].firstChild != null) txt3 = xx[0].firstChild.nodeValue; else txt3="";							
				xx=x[i].getElementsByTagName("currency_code");
				if (xx[0].firstChild != null) txt4 = xx[0].firstChild.nodeValue; else txt4="";										
				xx=x[i].getElementsByTagName("standard_price_converted");
				if (xx[0].firstChild != null) txt5 = xx[0].firstChild.nodeValue; else txt5="";										
				xx=x[i].getElementsByTagName("bookfee");
				if (xx[0].firstChild != null) txt6 = xx[0].firstChild.nodeValue; else txt6="";										
				//window.alert('showTicketType' + attractid + (i+1));
				if (document.getElementById('showTicketType' + attractid + (i+1)) != null){
					document.getElementById('showTicketType' + attractid + (i+1)).innerHTML = txt1;
				}
				if (document.getElementById('showStandardPrice' + attractid + (i+1)) != null){
					document.getElementById('showStandardPrice' + attractid + (i+1)).innerHTML = txt2;
				}
				if (document.getElementById('showOurPrice' + attractid + (i+1)) != null){
					document.getElementById('showOurPrice' + attractid + (i+1)).innerHTML = txt3;
				}
				if (document.getElementById('showStandardPrice_converted' + attractid + (i+1)) != null){
					document.getElementById('showStandardPrice_converted' + attractid + (i+1)).innerHTML = txt5;
				}
				if (document.getElementById('Booking_converted' + attractid + (i+1)) != null){
					//alert("Booking Converted: "+txt6);
					document.getElementById('Booking_converted' + attractid + (i+1)).innerHTML = txt6;
				}
				
			}
			//alert('done');
			if (document.getElementById('processRate' + attractid ) != null){
				xx=xmlhttp.responseXML.documentElement.getElementsByTagName("feeMessage");
				if (xx[0].firstChild != null)
					document.getElementById('processRate' + attractid ).innerHTML = xx[0].firstChild.nodeValue;
				}
			if (document.getElementById('linkProcess' + attractid ) != null){
				if (xx[0].firstChild != null)
					document.getElementById('linkProcess' + attractid ).title = xx[0].firstChild.nodeValue;
				}
			y = xmlhttp.responseXML.documentElement.getElementsByTagName("show_time");
			z = xmlhttp.responseXML.documentElement.getElementsByTagName("ticket_id");
			if (document.getElementById('availableTime' + attractid) != null){			
				var origtime
				timeindex = document.getElementById('availableTime' + attractid).selectedIndex;
				//~~	if (timeindex >= 0)
				if (timeindex >= 0){
					origtime = document.getElementById('availableTime' + attractid).options[document.getElementById('availableTime' + attractid).selectedIndex].text;
					//alert(origtime);
				}
				//~~	for (i=document.getElementById('availableTime' + attractid).options.length-1; i>0; i--)
				for (i=document.getElementById('availableTime' + attractid).options.length-1; i>0; i--){
					document.getElementById('availableTime' + attractid).removeChild(document.getElementById('availableTime' + attractid).options[i]);
				}
				document.getElementById('availableTime' + attractid).options[0] = new Option('','');
				sel_index = 0;
				for (i=0; i<y.length; i++){
					txt_y = y[i].firstChild.nodeValue; 
					txt_z = z[i].firstChild.nodeValue; 
					if (origtime==txt_y){
						txt_sel = true;
						sel_index = i+1;
						//~~	}else
					}
					else{
						txt_sel = false;
						//~~
					}
					//document.getElementById('availableTime' + attractid).options[i].innerHTML = txt_y;
					document.getElementById('availableTime' + attractid).options[i+1] = new Option(txt_y,txt_z,txt_sel);
				}	
				document.getElementById('availableTime' + attractid).selectedIndex = sel_index;
			}
				
		} //End If
					
		if (document.getElementById('currencyTypeCodeFace' + attractid) != null){
			document.getElementById('currencyTypeCodeFace' + attractid).innerHTML = document.forms['form' + attractid].elements['currencyType'].value;
		}
		
		if (document.getElementById('Booking' + attractid) != null){
			//alert("Booking Att: "+attractid);
			document.getElementById('Booking' + attractid).innerHTML = document.forms['form' + attractid].elements['currencyType'].value;
		}		
		if (document.getElementById('currencyTypeCode' + attractid) != null){
			document.getElementById('currencyTypeCode' + attractid).innerHTML = document.forms['form' + attractid].elements['currencyType'].value;
		}					
		//Hardcoded for London eye - Seniors not avail in July/Aug or weekends
		if (document.forms['form' + attractid].elements['num3'] != null) {
			//visitTixMonth = document.forms['form' + attractid].VTixMonth.options[document.forms['form' + attractid].VTixMonth.selectedIndex].value;		
			//visitTixDay = document.forms['form' + attractid].VTixDay.options[document.forms['form' + attractid].VTixDay.selectedIndex].value;		
			//visitTixYear = document.forms['form' + attractid].VTixYear.options[document.forms['form' + attractid].VTixYear.selectedIndex].value;		
			//visitdate = new Date(visitTixYear, visitTixMonth-1, visitTixDay,0,0,0,0);
			visitdate = new Date(document.getElementById('visitdate' + attractid).value);	
				if (attractid == 303 && (visitdate.getMonth() == 6 || visitdate.getMonth() == 7 || visitdate.getDay() == 0 || visitdate.getDay() == 6)){
						if (document.forms['form' + attractid].elements['num3'].selectedIndex > 0){
							window.alert('Senior Discounts are not available in July & August and on weekends!  Please choose Adults instead.');
						}
					document.forms['form' + attractid].elements['num3'].selectedIndex = 0;
					document.forms['form' + attractid].elements['num3'].disabled = true;
					//~~	}else
				}
				else{
					document.forms['form' + attractid].elements['num3'].disabled = false;
				}
				//~~
		}
		hideSplashScreen();
	}
//***END OF
//	onDateResponse(xmlhttp, attractid)



	jQuery(document).ready(function(){
		//document.getElementById('myImageButton').click();
			var domBodySetup = '<div id="jqbody-curtain" style="display:none"></div>\n';
				domBodySetup+= '<div class="jqprogress" style="display:none">\n';
				domBodySetup+= '	<img src="splash.jpg" alt="Price is updating..." style="margin-top:0; margin-left:0">\n';
				domBodySetup+= '</div>\n';
		jQuery('body').prepend(domBodySetup);
	});
//***END OF
//	jQuery(document)	



	function showSplashScreen(){
		var hpos = ((jQuery('body').width()/2)-100);
		if(jQuery.browser.msie){ var vpos =  document.body.scrollTop;}else{ var vpos = window.pageYOffset; }
		vpos+=200;
		jQuery('.jqprogress').css({ left:hpos, top:vpos }).show();
		jQuery('#jqbody-curtain').height(document.body.scrollHeight).show();
	}
//***END OF
//	showSplashScreen()	



	function hideSplashScreen(){
		jQuery('.jqprogress').hide();
		jQuery('#jqbody-curtain').hide();
	}
//***END OF
//	hideSplashScreen()



//******************************************************
//	Trim String
		function trimAll(sString) {

		while (sString.substring(0,1) == ' '){
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' '){
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
//***END OF
//	trimAll(sString)



//******************************************************
//	Validate ticket quantity and departure date from UK
//	var thisAttractid;

	function validateQuantityDepartureDate(str){
		var thisAttractid;
		thisAttractid = str;
		var ticketQuantity=0; 
		var quantityVolid = false;
		var quantityLen;
		var d = new Date();		
			todayutc = Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),0,0,0,0);

/*
for (x = 1; x <= 8; x++ ){
	if ( document.forms['form' + thisAttractid].elements['num' + x ] != null ){
		quantityLen = x;
	}
}		
for ( x = 1; x <=quantityLen; x++){
	ticketQuantity = document.forms['form' + thisAttractid].elements['num' + x ].selectedIndex;
	if ( ticketQuantity != 0 ){
		quantityVolid = true;
	}
}
if (quantityVolid ==false){
	alert ( "Please select the number of tickets you would like." );
	return false;
}
*/

			for (x = 1; x <= 8; x++ ){
				if ( document.forms['form' + thisAttractid].elements['num' + x ] != null ){
					ticketQuantity = ticketQuantity + document.forms['form' + thisAttractid].elements['num' + x ].selectedIndex;
				}
			}		
				if (ticketQuantity == 0){
						alert ( "Please select the number of tickets you would like." );
					return false;
				}
				
		//visitTixMonth = document.forms['form' + thisAttractid].VTixMonth.options[document.forms['form' + thisAttractid].VTixMonth.selectedIndex].value;		
		//visitTixDay = document.forms['form' + thisAttractid].VTixDay.options[document.forms['form' + thisAttractid].VTixDay.selectedIndex].value;		
		//visitTixYear = document.forms['form' + thisAttractid].VTixYear.options[document.forms['form' + thisAttractid].VTixYear.selectedIndex].value;
			
		tmpvisitdate = new Date(document.getElementById('visitdate' + thisAttractid).value);
		//window.alert(tmpvisitdate);
		if (tmpvisitdate == 'NaN' || tmpvisitdate == 'Invalid Date') {
			alert("You entered an invalid date format for the Visit Date, please use the popup calendar to choose date.");		
			return false;
		}
		visitTixMonth = tmpvisitdate.getMonth();
		visitTixDay = tmpvisitdate.getDate();
		visitTixYear = tmpvisitdate.getFullYear();
		visitdate = Date.UTC( visitTixYear, visitTixMonth, visitTixDay,0,0,0,0);	
		//return false	
		//window.alert(todayutc + ' - ' + visitdate);
			if (visitdate < todayutc){
				alert("You choose an incorrect date.  The date must be in the future.");			
				return false;
			}

		stopdays = document.forms['form' + thisAttractid].stopsellingdays.value;
		stopsellingdate = todayutc + stopdays*24*60*60*1000;

		stoptime = document.forms['form' + thisAttractid].stopsellingtime.value;
		stophour = stoptime.split(":")[0];
		stopmin = stoptime.split(":")[1];
		stoptimeutc = Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),stophour,stopmin,0,0);
		todayutctime = Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),d.getUTCHours(),d.getUTCMinutes(),d.getUTCSeconds(),d.getMilliseconds());
		
			if (todayutctime > stoptimeutc) {
				stopsellingdate = stopsellingdate + 24*60*60*1000;//add 1 day if after stopselling time
			}		
				if (visitdate < stopsellingdate){
						dt = new Date(stopsellingdate);
						alert("You chose an date that is no longer available.  The first available date is: " + dt.toUTCString());			
					return false;
				}
/*	
*********** Check to make sure there is an amount for the order (the didn't choose all infants)  ***********
<cfquery name="tixamount" datasource="#dsname#">
	select	(AttractTix.Sell1*#Val(Num1)# + AttractTix.Sell2*#Val(Num2)# + AttractTix.Sell3*#Val(Num3)# + AttractTix.Sell4*#Val(Num4)# + AttractTix.Sell5*#Val(Num5)# + AttractTix.Sell6*#Val(Num6)# + AttractTix.Sell7*#Val(Num7)#+ AttractTix.Sell8*#Val(Num8)#) as total	
	from AttractTix
	WHERE AttractTix.TixID = #TixToOrder#
</cfquery>
<CFIF tixamount.recordcount eq 0 or tixamount.total lte 0>
	<script language="JavaScript1.2" type="text/javascript">
		alert("<cfoutput>#noTotalMessage#</cfoutput>")
		history.back();
	</script>
		<div align="center"><h2 style="color:red"><cfoutput>#noTotalMessage#</cfoutput> Please Press your back Button and Correct the Error!</h2></div>
	<cfabort>
</CFIF>				
*/
			
		
		
		if (document.getElementById('departdate' + thisAttractid) != null){
			tmpdepartdate = new Date(document.forms['form' + thisAttractid].departdate.value);
			if (tmpdepartdate == 'NaN' || tmpdepartdate == 'Invalid Date') {
				alert("You entered an invalid date format for the Departure Date, please use the popup calendar to choose date.");		
				return false;
			}
			
			departureTixMonth = tmpdepartdate.getMonth();
			departureTixDay = tmpdepartdate.getDate();
			departureTixYear = tmpdepartdate.getFullYear();
			departdate = Date.UTC( departureTixYear, departureTixMonth, departureTixDay,0,0,0,0);		
			//departureTixMonth = document.forms['form' + thisAttractid].DTixMonth.options[document.forms['form' + thisAttractid].DTixMonth.selectedIndex].value;
			//departureTixDay = document.forms['form' + thisAttractid].DTixDay.options[document.forms['form' + thisAttractid].DTixDay.selectedIndex].value;
			//departureTixYear = document.forms['form' + thisAttractid].DTixYear.options[document.forms['form' + thisAttractid].DTixYear.selectedIndex].value;		
		
			//if (document.forms['form' + thisAttractid].elements['DTixMonth'].selectedIndex != 0 && 
				//document.forms['form' + thisAttractid].elements['DTixDay'].selectedIndex != 0 && 
				//document.forms['form' + thisAttractid].elements['DTixYear'].selectedIndex != 0 ){
				if (document.forms['form' + thisAttractid].departdate.value.length > 0) {
						departureTime = Date.UTC( departureTixYear, departureTixMonth, departureTixDay,0,0,0,0);
						mindepartureTime = todayutc + 7*24*60*60*1000 //add 7 days
						mindeBuyTime = todayutc + 12*24*60*60*1000 //add 7 days
							if ( departureTime > visitdate){
									alert("The Depart date shoud be earlier than your Visit date. please choose the correct departure time");
								return false;
							}else if (departureTime < mindepartureTime) {
									alert("Date of Departure must be a minimum of 7 days from date of booking.");
								return false;								
							}	
							
								if ( departureTime < mindeBuyTime){
								//opennewsletter();
								//bTime = false;
								var bTime = confirm("Regular Delivery takes at least 14 days. \nSince your date of departure is less than 14 days Regular Delivery is not option. You may request special delivery at an extra cost.  Click OK to Request Special Delivery or Cancel to go back.");
									if (bTime == true){
										document.getElementById("comfirmBox" + thisAttractid).value = "true";
										
										bTime = true;
									}else{
										//document.getElementById("comfirmBox").value = "false";
										bTime = false;
									}
								return bTime;
								}
			}else{	
					alert("Please choose a departure date!");
				return false;
			}
		}		

		if( document.getElementById('availableTime'+thisAttractid) != null){  
		 	var temp=document.getElementById('availableTime'+thisAttractid).value;
				if(temp.length < 1){
					//if(document.forms['form' + thisAttractid].elements['availableTime'+thisAttractid].selectedIndex == 0) {
						alert("Please choose the show time!");
					return false;
				}
		}		


		//if( document.getElementById('loption') != null){
		if( document.forms['form' + thisAttractid].loption != null && document.forms['form' + thisAttractid].formoptlabel != null){
			var e = document.forms['form' + thisAttractid].elements['loption'];
			var labelname = document.forms['form' + thisAttractid].elements['formoptlabel'].value
			//alert(e.type);
				if (e.type == 'text' && e.value == ""){
							alert("Please choose " + labelname + "!");
						return false;			
				}else if (document.forms['form' + thisAttractid].elements['loption'].selectedIndex == 0) {
							alert("Please choose " + labelname + "!");
						return false;
				}
		}		
		return true;

	}
//***END OF
//	validateQuantityDepartureDate(str)

	
