// JavaScript Document
function phpads_deliverActiveX(content)
{
	document.write(content);	
}

sfHover = function() 
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//Validate Date Function

	function y2k(number) 
	{ 
		return (number < 1000) ? number + 1900 : number;
	}
	
	function isDate (day,month,year) 
	{
	// checks if date passed is valid
	// will accept dates in following format:
	// isDate(dd,mm,ccyy), or
	// isDate(dd,mm) - which defaults to the current year, or
	// isDate(dd) - which defaults to the current month and year.
	// Note, if passed the month must be between 1 and 12, and the
	// year in ccyy format.
	
		var today = new Date();
		year = ((!year) ? y2k(today.getYear()):year);
		month = ((!month) ? today.getMonth():month-1);
		if (!day) return false
		var test = new Date(year,month,day);
		if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
			return true;
		else
			return false
	}

//End validation of date


//Validate Landing Page Forms
		var d = new Date();
		
		function changedate()
		{
			var thisDate = new String;
			var dateElem;
			thisDate = document.tick1.bdate.value;
			dateElem = thisDate.split("/");
			setDateDropdown(dateElem[0], dateElem[1], dateElem[2])
		}
		
		function setDateDropdown(day, month, year)
		{
			document.tick1.day.options[(day - 1)].selected = true;
			document.tick1.month.options[(month - 1)].selected = true;
			document.tick1.year.options[(year - 2005)].selected = true;
		}
				
		function setDate(dayDate, monthDate, yearDate, FormName)
		{
			var form = eval("document." + FormName);
			form.bdate.value=dayDate + "-" + literalMonth(monthDate, form) + "-" + yearDate;
		}
		
		function literalMonth(month, form)
		{
			var shortMonth = new String();
			var numericMonth = new Number();
		
			numericMonth = month;
		
			if (numericMonth == 1) {shortMonth = "Jan"}
			if (numericMonth == 2) {shortMonth = "Feb"}
			if (numericMonth == 3) {shortMonth = "Mar"}
			if (numericMonth == 4) {shortMonth = "Apr"}
			if (numericMonth == 5) {shortMonth = "May"}
			if (numericMonth == 6) {shortMonth = "Jun"}
			if (numericMonth == 7) {shortMonth = "Jul"}
			if (numericMonth == 8) {shortMonth = "Aug"}
			if (numericMonth == 9) {shortMonth = "Sep"}
			if (numericMonth == 10) {shortMonth = "Oct"}
			if (numericMonth == 11) {shortMonth = "Nov"}
			if (numericMonth == 12) {shortMonth = "Dec"}
		
			return shortMonth;
		}
		
		function checkForm(thisForm)
		{
		
			if	(thisForm.ticketbookA_0.value==0 && thisForm.ticketbookC_0.value==0)
			{
				alert("You did not enter the number of tickets you require");
				return false;
			}
			if (thisForm.cont.value=='N')
			{
				alert("The date you are trying to book is not available for this attraction");
				return false;
			}
				
			if (isDate(thisForm.day.value, thisForm.month.value, thisForm.year.value) == false)
			{
				alert ("The date entered ("+thisForm.day.value+"/"+thisForm.month.value+"/"+thisForm.year.value+") is invalid. Please select a new date and press the 'Search' button.");
				
				return false;
			}
			
			var chosenDate = thisForm.day.value+" "+literalMonth(thisForm.month.value)+" "+thisForm.year.value;
			var date = new Date(chosenDate);
			var now = new Date();
			var diff = date.getTime() - now.getTime();
			var days = Math.floor(diff / (1000 * 60 * 60 * 24));
			if (days < 0) {
				alert("Please choose a date in the future");
				return false;
			}
			
			{
		   
			
			}  
			return true;
		}

// End Landing Page Validation






//Begin Search Form validation
function changeSearchdate()
{
	var thisDate = new String;
	var dateElem;
	thisDate = document.bookingStage1.checkindate.value;
	dateElem = thisDate.split("/");
	setDateDropdown(dateElem[0], dateElem[1], dateElem[2])
}

function setSearchDateDropdown(day, month, year)
{
	document.bookingStage1.day.options[(day - 1)].selected = true;
	document.bookingStage1.month.options[(month - 1)].selected = true;
	document.bookingStage1.year.options[(year - 2005)].selected = true;
}

function setSearchDate(dayDate, monthDate, yearDate)
{
	document.bookingStage1.checkindate.value = dayDate + "-" + literalMonth(monthDate) + "-" + yearDate;
}


function checkSearchForm(thisForm)
{
		
	if (isDate(thisForm.day.value, thisForm.month.value, thisForm.year.value) == false)
	{
		alert ("The date entered ("+thisForm.day.value+"/"+thisForm.month.value+"/"+thisForm.year.value+") is invalid. Please select a new date and press the 'Search' button.");
		
		return false;
	}
	
	var chosenDate = thisForm.day.value+" "+literalMonth(thisForm.month.value)+" "+thisForm.year.value;
	var date = new Date(chosenDate);
	var now = new Date();
	var diff = date.getTime() - now.getTime();
	var days = Math.floor(diff / (1000 * 60 * 60 * 24));
	if (days < 0) {
		alert("Please choose a date in the future");
		return false;
	}
	
	if (days < 3) {
		alert("The date you have selected is within three days, please phone us on 0870 705 5000");
		return false;
	}

{
    if (thisForm.destination_id.value == "des_0")
	{
       alert("Please select your destination.");
	   return false;
	}


	
}  
	return true;
}
// End Search Validation

// Used to pop up the window for the video clips
function genericpopwin(windowURL, windowWidth, windowHeight, scrollBars, reSizable)	{
if (scrollBars)	{
	//
} else	{
	scrollBars = 'no'
}

if (reSizable)	{
	//
} else	{
	reSizable = 'no'
}
var windowName = "generic" + Math.round(Math.random(1)*1000);
var windowOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scrollBars + ",resizable=" + reSizable + ",width=" + windowWidth + ",height=" + windowHeight;
var mywin = window.open(windowURL,windowName,windowOptions);
}


function toggleLayer(whichLayer) {
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
}

//function showPriceCalendar(contract,dropdtls,form)
//{
//	xmlHttp=GetXmlHttpObject()
//	if (xmlHttp==null)
//	{
//		//alert ("Browser does not support HTTP Request")
//	return
//	} 
//	var url="include/allocation-popup-ajax.asp"
//	url=url+"?contract="+contract+"&dropdtls="+dropdtls+"&form="+form
//	url=url+"&sid="+Math.random()
//	xmlHttp.onreadystatechange=stateChangedCalendar
//	xmlHttp.open("GET",url,true)
//	xmlHttp.send(null)
//	
//	function stateChangedCalendar() 
//	{ 	
//		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
//		{ 
//			document.getElementById("Allocation"+form).innerHTML=xmlHttp.responseText
//			toggleLayer("CalendarForm"+form);
//		} 
//	} 
//}

function showPriceCalendar(contract, product, dropdtls, form, qty, ticketType) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        //alert ("Browser does not support HTTP Request")
        return
    }
    var url = "ajax/allocation.aspx";
    url = url + "?contract=" + contract + "&dropdtls=" + dropdtls + "&form=" + form;
    if (product != '') {
        url += "&product=" + product;
    }
    url += "&qty=" + qty;
    url += "&ttype=" + ticketType;
    url = url + "&sid=" + Math.random();
    xmlHttp.onreadystatechange = stateChangedCalendar;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

    function stateChangedCalendar() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById("Allocation" + form).innerHTML = xmlHttp.responseText
            toggleLayer("CalendarForm" + form);
        }
    }
}


function showPriceDC(month, year, contracts, contractname, services, navigation, form, ticketType) {
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        //alert ("Browser does not support HTTP Request")
        return
    }
    var url = "ajax/allocation.aspx"
    url = url + "?seldate=" + year + " " + month + "&contract=" + contracts + "&contractname=" + contractname + "&service=" + services + "&Navigation=" + navigation + "&form=" + form + "&style=2"
    url += "&dropdtls=" + year + "-" + month;
    url += "&ttype=" + ticketType;
    url = url + "&sid=" + Math.random()
    //xmlHttp.onreadystatechange = stateChangedDC
    xmlHttp.onreadystatechange = stateChangedCalendarDC
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)

    function stateChangedCalendarDC() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById("Allocation" + form).innerHTML = xmlHttp.responseText
            //toggleLayer("CalendarForm" + form);
        }
    }
}

function showPriceMulti(month, year, contracts, contractname, productId, navigation, form, ticketType, siteAttribute, siteId) {
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        //alert ("Browser does not support HTTP Request")
        return
    }
    var url = "ajax/allocation-multi.aspx"
    url = url + "?seldate=" + year + " " + month + "&contract=" + contracts + "&contractname=" + contractname + "&productId=" + productId + "&Navigation=" + navigation + "&form=" + form + "&style=2"
    url += "&dropdtls=" + year + "-" + month;
    url += "&ttype=" + ticketType;
    url += "&siteId=" + siteId;
    url += "&siteAttribute=" + siteAttribute;
    url = url + "&sid=" + Math.random()
    //xmlHttp.onreadystatechange = stateChangedDC
    xmlHttp.onreadystatechange = stateChangedCalendarMulti
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)

    function stateChangedCalendarMulti() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById("Allocation" + form).innerHTML = xmlHttp.responseText
            //toggleLayer("CalendarForm" + form);
        }
    }
}



//function showPriceMulti(month, year, contracts, contractname, services, navigation, form, ticketType) {
//    xmlHttp = GetXmlHttpObject()
//    if (xmlHttp == null) {
//        //alert ("Browser does not support HTTP Request")
//        return
//    }
//    var url = "ajax/allocation-multi.aspx"
//    url = url + "?seldate=" + year + " " + month + "&contract=" + contracts + "&contractname=" + contractname + "&service=" + services + "&Navigation=" + navigation + "&form=" + form + "&style=2"
//    url += "&dropdtls=" + year + "-" + month;
//    url += "&ttype=" + ticketType;
//    url = url + "&sid=" + Math.random()
//    //xmlHttp.onreadystatechange = stateChangedDC
//    xmlHttp.onreadystatechange = stateChangedCalendarMulti
//    xmlHttp.open("GET", url, true)
//    xmlHttp.send(null)

//    function stateChangedCalendarMulti() {
//        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
//            document.getElementById("Allocation" + form).innerHTML = xmlHttp.responseText
//            //toggleLayer("CalendarForm" + form);
//        }
//    }
//}



//function showPriceDC(month, year, dropdtls, contracts, contractname, services, navigation, formnumber) {
//    xmlHttp = GetXmlHttpObject()
//    if (xmlHttp == null) {
//        //alert ("Browser does not support HTTP Request")
//        return
//    }
//    var url = "ajax/allocation.aspx"
//    url = url + "?seldate=" + year + " " + month + "&contracts=" + contracts + "&contractnames=" + contractname + "&services=" + services + "&Navigation=" + navigation + "&formnumber=" + formnumber
//    url = url + "&sid=" + Math.random()
//    xmlHttp.onreadystatechange = stateChangedDC
//    xmlHttp.open("GET", url, true)
//    xmlHttp.send(null)
//}



function showPoll(poll,value)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		//alert ("Browser does not support HTTP Request")
	return
	} 
	var url="include/poll-ajax.asp"
	url=url+"?poll="+poll+"&value="+value
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedPoll
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
	function stateChangedPoll() 
	{ 	
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById("customer_poll").innerHTML=xmlHttp.responseText
		} 
	} 
}

function stateChangedDC() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var responseArray=xmlHttp.responseText.split("XX");
		document.getElementById("Allocation"+responseArray[0]).innerHTML=responseArray[1];
	} 
}

function showPrice(day, month, year, contract, formnumber, ttype, attrVal) {
    if (isDate(day, month, year) == false) {
        alert("Please enter a valid date (date entered does not exist)");
    }
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        //alert ("Browser does not support HTTP Request")
        return
    }
    var url = "ajax/calendar-price.aspx";
    url = url + "?day=" + day + "&month=" + month + "&year=" + year + "&contract=" + contract + "&formnumber=" + formnumber;
    url += "&ttype=" + ttype;
    url += "&contrID=" + attrVal;
    url = url + "&sid=" + Math.random();
    xmlHttp.onreadystatechange = stateChanged
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)

}

function stateChanged() { 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	    var responseArray = xmlHttp.responseText.split("X");

	    var id = (responseArray.length) - 1;

	    if (document.getElementById("adultAjax" + responseArray[id]) != null)
	        document.getElementById("adultAjax" + responseArray[id]).innerHTML = responseArray[0];

	    if (document.getElementById("childAjax" + responseArray[id]) != null)
	        document.getElementById("childAjax" + responseArray[id]).innerHTML = responseArray[1];

	    if (document.getElementById("ageAjax" + responseArray[id]) != null)
	        document.getElementById("ageAjax" + responseArray[id]).innerHTML = responseArray[2];

	    if (document.frmBooking.ChildAge.value != null)
	        document.frmBooking.ChildAge.value = responseArray[3];


	    var str = responseArray[0];
	    var bookingButton = document.getElementById("bookingButton" + responseArray[id]);
	    if (str == "&pound;N/A") {
	        bookingButton.style.visibility = 'hidden';
	    }
	    else {
	        bookingButton.style.visibility = 'visible';
	    }
	} 
} 

function GetXmlHttpObject(handler)
{
    var objXmlHttp=null
 
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        //alert("Opera not supported...")
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        if (navigator.appVersion.indexOf("MSIE 7.0")>=1)
		{
			try
        	{
            	objXmlHttp=new XMLHttpRequest()
            	//objXmlHttp.onreadystatechange=handler
            	return objXmlHttp
        	}
        	catch(e)
        	{
            	//alert("Error. Scripting for XML might be disabled")
            	return
        	}
		}
		else
		{
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			}
			try
			{
				objXmlHttp=new ActiveXObject(strName)
				//objXmlHttp.onreadystatechange=handler
				return objXmlHttp
			}
			catch(e)
			{
				//alert("Error. Scripting for ActiveX might be disabled")
				return
			}
		}
    }
	
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
} 

//function SetCalendarValue(thisForm, FormDay, FormMonth, FormYear, contract)
//{
//	document.getElementById("tick"+thisForm).day.value=FormDay;
//	document.getElementById("tick"+thisForm).month.value=FormMonth;
//	document.getElementById("tick"+thisForm).year.value=FormYear;
//	showPrice(FormDay,FormMonth,FormYear,contract,thisForm)
//}

function SetCalendarValue(thisForm, FormDay, FormMonth, FormYear, contract) {
    document.getElementById("tick" + thisForm).day.value = FormDay;
    document.getElementById("tick" + thisForm).month.value = FormMonth;
    document.getElementById("tick" + thisForm).year.value = FormYear;
    showPrice(FormDay, FormMonth, FormYear, contract, thisForm, document.frmBooking.TicketType.value, document.frmBooking.SiteAttribute.value)
}

 function CreateBookmarkLink(url)
 {
	title = "AttractionTix - Pay, Print, Present"; 	

	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external)
	{ // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{ // Opera Hotlist
		return true;
	}
}


