/*if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	window.attachEvent("onload", alphaBackgrounds);
}*/

function fnIntcptEnter(sButton,evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	if (keyCode==13) {
		try {		
			document.getElementById(sButton).focus();
			document.getElementById(sButton).click();
			return false;
		} catch(e) { }
	}
}

function setCookie(name, value, expiry) {
	var today = new Date();
	//expiry = new Date(today.getTime() + 3 * 24 * 60 * 60 * 1000); 
	if (value != null && value != "") {
		if(expiry!=null) {
			document.cookie=name + "=" + escape(value) + ";path=/; expires=" + expiry.toGMTString();
		} else {
			document.cookie=name + "=" + escape(value) + ";path=/; ";
		}
	}
}

function getCookie(name) {
	// use: getCookie("name");
	bikky = document.cookie;
	var index = bikky.indexOf(name + "=");
	if (index == -1) return null;
	index = bikky.indexOf("=", index) + 1;
	var endstr = bikky.indexOf(";", index);
	if (endstr == -1) endstr = bikky.length;
	
	return unescape(bikky.substring(index, endstr));
}


function alphaBackgrounds() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	for (i=0; i<document.all.length; i++){
		var bg = document.all[i].currentStyle.backgroundImage;
		if (itsAllGood && bg){
			if (bg.match(/\.png/i) != null){
				var mypng = bg.substring(5,bg.length-2);
				document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
				document.all[i].style.backgroundImage = "url('images/x.gif')";
			}
		}
	}
}

/*if (window.addEventListener) {
	window.addEventListener("load", fixLayout, false);
	window.addEventListener("resize", fixLayout, false);
}*/

function fixLayout() {
	var d = document.getElementById("bgdiv");
	
	if (d) {
		d.style.minHeight = document.documentElement.clientHeight + "px";
	}
}

function expand(thistag) {
	styleObj=document.getElementById(thistag).style;
	if(styleObj.display=='none') { styleObj.display=''; }
	else { styleObj.display='none'; }
}

function printpage() {
	if (window.print) {
		window.print();
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);
	}
}

function SetFocus() {
	document.getElementById('hdnCalBtnClicked').value = "1";
	document.getElementById('AvailAndBook1_txtDate').focus();
}





/* *** BEGIN Haven web team changes *** */

// for matching regions on park pages - match only relies on first 5 characters or less of park or region
var parkRegionsArray = [
	"Lakeland : Blackpool and The Lakes",
	"Marton Mere : Blackpool and The Lakes",
	"Devon Cliffs : Devon and Cornwall",
	"Perran Sands : Devon and Cornwall",
	"Littlesea : Dorset",
	"Rockley Park : Dorset",
	"Seaview : Dorset",
	"Caister : Norfolk and Essex",
	"The Orchards : Norfolk and Essex",
	"Wild Duck : Norfolk and Essex",
	"Greenacres : North Wales",
	"Hafan Y Mor : North Wales",
	"Presthaven Sands : North Wales",
	"Haggerston Castle : Northumberland",
	"Craig Tara : Scotland",
	"Seton Sands : Scotland",
	"Burnham-on-Sea : Somerset",
	"Kiln Park : South Wales",
	"Blue Dolphin : Yorkshire and Lincolnshire",
	"Golden Sands : Yorkshire and Lincolnshire",
	"Primrose Valley : Yorkshire and Lincolnshire",
	"Reighton Sands : Yorkshire and Lincolnshire",
	"Thorpe Park : Yorkshire and Lincolnshire"
]


// 2010/05/21 - wislam :: Booking Panel - remove 'Tourer Length' field if Tent is selected.
$("#availability-book").ready(function() {
	//autoChangeTentLength();
	autoSelectRegionPark();
});


function autoChangeTentLength() {
	if(!$("#availability-book").length > 0)
		return;
	
	// if availability-book element exists on page, then all other elements within should also exist (tourer type / length / etc).
	if($("#availability-book #ucBook_tourerType").val().toUpperCase() == "TENT") {
		$("#availability-book #ucBook_tourerLength")[0].selectedIndex = 1;
		//$("#availability-book .tourer-length").hide();
	}
	
	$("#availability-book #ucBook_tourerType").change(function() {
		if($(this).val() == "Tent") {
			$("#availability-book #ucBook_tourerLength")[0].selectedIndex = 1;
			//$("#availability-book .tourer-length").hide();
		} else {
			$("#availability-book #ucBook_tourerLength")[0].selectedIndex = 0;
			//$("#availability-book .tourer-length").show();
		}
	});
}


function autoSelectRegionPark() {

	// auto select region / park 
	if($("#main h1").length > 0 && $("#availability-book").length > 0 && document.URL.indexOf("our_parks") != -1) {
		var isPark = false;
		var region = "";
		var region_park = jQuery.trim($("#main h1").text()).toUpperCase();
		var splitIndex = (region_park.length < 7)? region_park.length : 7;
		
		
		for(i = 0; i < parkRegionsArray.length; i++) {
			var temp = parkRegionsArray[i].split(" : ");
			if(temp[0].substr(0,splitIndex).toUpperCase() == region_park.substr(0,splitIndex)) {
				region = temp[1].toUpperCase();
				isPark = true;
				break;
			}
		}
		
		// fix: when selecting Devon, Cornwall & Somerset region, Devon is also chosen from park drop-down.
		if(region_park == 'DEVON, CORNWALL & SOMERSET')
			isPark = false;
		
		
		//check park match first...
		if(isPark) {
			$("#availability-book #ucBook_drpAvailBookPark option").each(function(index) {
				dropdownPark = jQuery.trim($(this).html()).toUpperCase();
				
				if(region_park.substr(0,splitIndex) == dropdownPark.substr(0,splitIndex))
					this.selected = true;
				
				
			});
		}
		
		// check region match...
		$("#availability-book #ucBook_drpAvailBookRegion option").each(function(index) {
			dropdownRegion = jQuery.trim($(this).html()).toUpperCase();
			
			if(region_park.substr(0,splitIndex) == dropdownRegion.substr(0,splitIndex) ||
			   region.substr(0,splitIndex) == dropdownRegion.substr(0,splitIndex)) {
				this.selected = true;
			}
		});
		
	}
}

/* *** END Haven changes *** */


