/* Javascript
// Created by Andrew Nemeth <andrewn@xpl.com.au>
// File Created: 18 July 2007
// File Updated: Tuesday 07 August 2007, 11:18am
*/



// <![CDATA[



function history_backfrom( spagefrom )
{

window.document.location.href = 'back.php?referer=' + spagefrom;
/*
// Read cookie "page1|page2|...", split it into page name arrays, 
// set history according to index of first page which doesn't match 
// 'spagefrom'.  Works well, but doesn't if the current page has been 
// refreshed.  This is because PHP logs every creation of a page, but 
// the JS history array _doesn't_ record refreshes!


var scookieval = myReadCookie( 'xpl_history' );
scookieval = unescape( scookieval );

var apages = scookieval.split( '|' );
var ivar = 0;
var ndx = 0;
for ( var i=0 ; i<apages.length ; i++ )
	{
	if ( -1 != apages[i].indexOf( spagefrom ) )
		{ ndx = -(i+1); }
	else
		{ ivar = i; break; }
	}

// Special case for booking: always assemble default URL
if ( -1 != apages[ ivar ].indexOf( 'booking.php' ) )
	{ 
	var sbkid = myReadCookie( 'xpl_bookid' );
	window.document.location.href = 'booking.php?bkid='+sbkid;
	}
else
	{
	history.go( ndx );
	}
*/
/*
// http://docs.sun.com/source/816-6408-10/history.htm

In theory we could use the "history.go(url)"" form of the function
to lookup the most recent history item containing the 'url' string.  
Would be great, but unfortunately doesn't work in Firefox or other 
modern browsers!

// http://www.thescripts.com/forum/thread94332.html

Also IE requires an exact full-URL match!

// http://www.codingforums.com/archive/index.php?t-4906.html

history.go( apages[ ndx+1 ] );
*/

}



function myReadCookie( name ) 
{

// http://www.quirksmode.org/js/cookies.html

var nameEQ = name + "=";
var ca = document.cookie.split(';');

for( var i=0 ; i<ca.length ; i++ ) 
	{
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

return null;

}



//--------------------------------------------------------------------------------------



/* -- Following methods are used if page refreshes are also tracked.  Need
to change each file's <body> tag to:

<body onLoad="JavaScript:checkRefresh();" onUnload="JavaScript:prepareForRefresh();"> 

... and also need to call "disableRefreshDetection()" from each form-submit 
to prevent submits from being counted as refreshes!
*/



//--------------------------------------------------------------------------------------



function refresh_truncateCookie()
{
// A page refresh has been detected, so remove the extraneous
// first element in the history-cookie written by the PHP script

var scookieval = myReadCookie( 'xpl_history' );
scookieval = unescape( scookieval );

var apages = scookieval.split( '|' );
var snewval = '';

for ( var i=1 ; i<apages.length ; i++ )
	{ snewval += apages[i] + '%7C'; }

myEraseCookie( 'xpl_history' );

myCreateCookie( 'xpl_history', snewval, 1 );

}



function myEraseCookie( name ) 
{

// http://www.quirksmode.org/js/cookies.html

myCreateCookie( name, "", -1 );
}



function myCreateCookie( name, value, days ) 
{

// http://www.quirksmode.org/js/cookies.html

if ( days )
	{
	var date = new Date();
	date.setTime( date.getTime()+(days*24*60*60*1000) );
	var expires = "; expires="+date.toGMTString();
	}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";

}



// By default, turn refresh detection on
var grefresh_prepare = 1;



function checkRefresh()
{

// http://www.tedpavlic.com/post_detect_refresh_with_javascript.php

// Get the time now and convert to UTC seconds
var today = new Date();
var now = today.getUTCSeconds();

// Get the cookie
var cookie = document.cookie;
var cookieArray = cookie.split('; ');

// Parse the cookies: get the stored time
for( var loop=0; loop < cookieArray.length; loop++ )
{
	var nameValue = cookieArray[loop].split('=');
	// Get the cookie time stamp
	if( nameValue[0].toString() == 'SHTS' )
	{
		var cookieTime = parseInt( nameValue[1] );
	}
	// Get the cookie page
	else if( nameValue[0].toString() == 'SHTSP' )
	{
		var cookieName = nameValue[1];
	}
}

if( cookieName &&
	cookieTime &&
	cookieName == escape(location.href) &&
	Math.abs(now - cookieTime) < 5 )
	{
	// Refresh detected

	refresh_truncateCookie();
	}	

}



function prepareForRefresh()
{

// http://www.tedpavlic.com/post_detect_refresh_with_javascript.php

if ( grefresh_prepare > 0 )
	{
	// Turn refresh detection on so that if this
	// page gets quickly loaded, we know it's a refresh
	var today = new Date();
	var now = today.getUTCSeconds();
	document.cookie = 'SHTS=' + now + ';';
	document.cookie = 'SHTSP=' + escape(location.href) + ';';
	}
else
	{
	// Refresh detection has been disabled
	document.cookie = 'SHTS=;';
	document.cookie = 'SHTSP=;';
	}
}



function disableRefreshDetection()
{

// http://www.tedpavlic.com/post_detect_refresh_with_javascript.php

// The next page will look like a refresh but it actually
// won't be, so turn refresh detection off.
grefresh_prepare = 0;

// Also return true so this can be placed in onSubmits
// without fear of any problems.
return true;

} 



// ]]>
/** Start JavaScript **/
// 07JAN09 PCS Only applicable for IE 6 and below

if (window.XMLHttpRequest) {
// IE 7, mozilla, safari, opera 9
} else {
    ieHover = function() {
      var ieULs = document.getElementById('nav').getElementsByTagName('ul');
      // IE script to cover <select> elements with <iframe>s
      for (j=0; j<ieULs.length; j++) {
        ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
           var ieMat = ieULs[j].firstChild;
              ieMat.style.width=ieULs[j].offsetWidth+"px";
              ieMat.style.height=ieULs[j].offsetHeight+"px";    
              ieULs[j].style.zIndex="99";
      }
      // IE script to change class on mouseover
         var ieLIs = document.getElementById('nav').getElementsByTagName('li');
         for (var i=0; i<ieLIs.length; i++) {
           if (ieLIs[i]) {
                ieLIs[i].onmouseover=function() {this.className+=" iehover";}
                ieLIs[i].onmouseout=function()  {this.className=this.className.replace(' iehover', '');}
           }
      }
    }

    // IE Load Event
    if (window.attachEvent) window.attachEvent('onload', ieHover);
}
/** Start JavaScript **//** Start JavaScript **/

subMenuIcons = function() {
	 var ieLIs = document.getElementById('nav').getElementsByTagName('li');
	 for (var i=0; i<ieLIs.length; i++) {
	   if (ieLIs[i].childNodes.length > 2){
	     if (ieLIs[i].parentNode.id != 'nav'){
	       ieLIs[i].childNodes[0].className='subMenu';
	     }
	   }
  }
}

// IE Load Event
if (window.attachEvent) window.attachEvent('onload', subMenuIcons);

// Mozilla Load Event
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", subMenuIcons, false);
}

/** Start JavaScript **/