// Submit search form (needed to override the usual .NET postback)
function dosearch(query)
{
	document.location.href = "/info/important/search_results/?search_query=" + escape(query);
	// Strangely, if this next line isn't present, in older browsers (IE<5.5, Opera<7.5) the 'return false' doesn't cancel the form submit.
	// If it's present, the form doesn't submit and the browser goes to the above URL. Wierd.
	document.forms[0].action = "/info/important/search_results/default.aspx?search_query=" + escape(query);
	return false;	// Cancels the form submit
}

// open window script for 360 VRs
function openBW (url) {
	var winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=390,height=446,";
	remote = window.open(url,"vr",winopts);
	remote.focus();
}

// Florida version of the same script?
function openVR( pin )
{
	var winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=390,height=446,";
	remote = window.open( "http://display.maxvr.com/newdisplay.asp?pin=" + pin, "vr", winopts );
	remote.focus();
}
// Ski version of the same script?
function openBWski (url) {
	var winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=305,height=293,";
	var fullUrl = "/brochures/ski/_assets/vrgallery/"+url+".htm";
	remote = window.open(fullUrl,"pabrowse",winopts);
	remote.focus();
}

// Block the <Enter> key from submitting a form
// add to text box, etc: onkeypress="return blockenter(event)"
function blockenter(e) {
	if(window.event) return e.keyCode != 13;
	else if(e.which) return e.which != 13;
}


function genericPopup(url,name,w,h,resize,bars,status)
{
	window.open(url,name,'width=' + w + ',height=' + h + ',resizable=' + resize + ',scrollbars=' + bars + ',status=' + status);
}


//////////////////////////////////////////////////////////////////////////////
// Image Swap functions
//////////////////////////////////////////////////////////////////////////////
function swapImage(id,src) {
	document.getElementById(id).src=src;
}


//////////////////////////////////////////////////////////////////////////////
// Generic cookie functions
//////////////////////////////////////////////////////////////////////////////
function setCookie(name, value, expires, path) {

	var thisCookie = new String(escape(name) + '=' + escape(value)),
		days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
		months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

	if (expires) {
		expires = new Date(expires);
		thisCookie += ';EXPIRES=' +
						days[expires.getUTCDay()] + ', ' +
						(expires.getUTCDate() < 10 ? '0' : '') + expires.getUTCDate() + '-' +
						months[expires.getUTCMonth()] + '-' +
						String(expires.getUTCFullYear()).substring(1) + ' ' +
						(expires.getUTCHours() < 10 ? '0' : '') + expires.getUTCHours() + ':' +
						(expires.getUTCMinutes() < 10 ? '0' : '') + expires.getUTCMinutes() + ':' +
						(expires.getUTCSeconds() < 10 ? '0' : '') + expires.getUTCSeconds() +
						' GMT';
	}

	if (path) {
		thisCookie += ';PATH=' + path;
	}

	document.cookie = thisCookie;
}


function getCookie(name) {

	var c = new String(document.cookie).split(/; /),
		p;

	for (var i = 0; i < c.length; i++) {
		p = c[i].split('=');
		if (p[0] == escape(name)) return unescape(String(p[1]).replace(/\+/g, ' '));
	}
	return '';
}


function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

//////////////////////////////////////////////////////////////////////////////
// Generic Flash movie controls
//////////////////////////////////////////////////////////////////////////////
function thisMovie(movie) {
	// IE and Netscape refer to the movie object differently.
	// This function returns the appropriate syntax depending on the browser.
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return document.getElementById(movie)
	} else {
		return document[movie]
	}
}

function restartMovie(movieName) {
	if (movieIsLoaded(thisMovie(movieName))) {
  		thisMovie(movieName).Rewind();
		thisMovie(movieName).Play();
	}
}

function stopMovie(movieName) {
	if (movieIsLoaded(thisMovie(movieName))) {
		thisMovie(movieName).StopPlay();
	}
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
// First make sure the movie's defined.
	if (typeof(theMovie) != "undefined") {
			// If it is, check how much of it is loaded.
			return theMovie.PercentLoaded() == 100;
		} else {
			// If the movie isn't defined, it's not loaded.
			return false;
	}
}

//////////////////////////////////////////////////////////////////////////////
// HEIGHT FIX
//////////////////////////////////////////////////////////////////////////////
function resetHeight(){
	/*
		This script is called in the footer. If the left hand column is longer 
		than the main column we resize the main column so that the footer isn't 
		squashed.
		NOTE: IE actually performs okay when the left column is too long.  
		Unfortunately it also has a bug whereby document.getElementById gets
		a with name="main" rather than the div with id="main"
	*/
	
	
	var lheight=0;
	var rheight=0;
	var mainheight=10;
	var newheight=0;
	
	// update values of lheight and rheight from document
	if (document.getElementById('left')) {
		lheight=document.getElementById('left').clientHeight;
	}
	if (document.getElementById('right')) {
		rheight=document.getElementById('right').clientHeight;
	}
	
	// update value for main height from document
	if (document.getElementById('centreColumn')) {
		var mainheight=document.getElementById('centreColumn').clientHeight;
	} else {
		// make sure main exists before we use it (was throwing error on homepage)
		if (document.getElementById('main')) {
			var mainheight=document.getElementById('main').clientHeight;
		}
	}
	
	// check which is the highest
	if (lheight>rheight) {
		newheight = lheight;
	} else {
		newheight = rheight;
	}

	// reset height of main if new height is higher
	if (newheight>mainheight && mainheight>0){
		//alert("original content height: "+document.getElementById('main').clientHeight+ "\nlheight: "+lheight + "\nrheight: " + rheight + "\nnewheight: " + newheight);
		if (document.getElementById('centreColumn')) {
			document.getElementById('centreColumn').style.height = newheight + "px";
		} else {
			document.getElementById('main').style.height = newheight + "px";
		}
	}
}

/* Stuff for the SEARCH SUMMARY PANEL - show/hide detail */
function Expand(id) {
	document.getElementById(id).className = String(document.getElementById(id).className).replace('contracted', 'expanded');
}
function Contract(id) {
	document.getElementById(id).className = String(document.getElementById(id).className).replace('expanded', 'contracted');
}
function WriteExpandCss()
{
	// For people with JS, we hide the 'extra' detail. For others, it's shown by default.
	document.write('<style type="text/css">\n.expanded .cntrct, .contracted .expnd { display: none; }\n</style>');
}


//////////////////////////////////////////////////////////////////////////////
// Stuff for the show/hide help panel (availability page)
//////////////////////////////////////////////////////////////////////////////
function openHelp(helpboxid,posdiv){
	var checknodes = document.getElementById("main").getElementsByTagName("div");
	for (var i=0;i<checknodes.length;i++){
		if (checknodes[i].className == "helpcontainer"){
			checknodes[i].childNodes[0].innerHTML = "";
			checknodes[i].childNodes[0].className = "";
			//set z-index back to 0 for repeaters
			var repeaterNode = checknodes[i].parentNode.parentNode.parentNode;
			if (repeaterNode.className=="result_item"){
				repeaterNode.style.zIndex = 0;
			}
		}
	}	
	document.getElementById(posdiv).firstChild.innerHTML=document.getElementById(helpboxid).innerHTML;
	document.getElementById(posdiv).firstChild.className="helpbox";
	document.getElementById(posdiv).parentNode.parentNode.parentNode.style.zIndex=100;
}
function closeHelp(helpid){
	var element = helpid + "title";
	document.getElementById(element).parentNode.innerHTML="";
	document.getElementById(element).parentNode.className="hide";
}


