

var isIE = false;	

if (navigator.userAgent.indexOf('MSIE') > 0)
	isIE = true;

var Timer = null;

function resizeLeftNav()
{
	var mainContainer = document.getElementById("MainContainer");
	
	if (mainContainer == null)
	    mainContainer = document.getElementById('MainContainerNoSideNav');
	
    if (mainContainer != null)	    
    {
	    var sideNavBar = document.getElementById("SideNavBar");

        if (sideNavBar != null)
        {
	        if (isIE)
	        {
		        if ((mainContainer.offsetHeight - 55) > 0)
			        sideNavBar.style["height"] = mainContainer.offsetHeight - 57; //the 57 pixels are for the web search box
	        }
	        else
	        {
		        if ((mainContainer.offsetHeight - 60) > 0)
		        {
			        sideNavBar.style["height"] = mainContainer.offsetHeight - 50 + "px"; //the 60 pixels are for the web search box
		        }
	        }
        }

        if (!isIE)
        {
   	        var pageOutline = document.getElementById("PageTemplate");
            pageOutline.style["height"] = mainContainer.offsetHeight + 110 + "px"; //the 60 pixels are for the web search box
        }
    }
}

function ResizeRightColumn()
{
     var RightColumn = document.getElementById("RightColumn");
     var LeftColumn = document.getElementById("LeftColumn");
     if (RightColumn !=null && LeftColumn !=null)
     {
         if (RightColumn.offsetHeight < LeftColumn.offsetHeight)
         {
            RightColumn.style["height"] = LeftColumn.offsetHeight + "px"
         }
         else 
         {
          RightColumn.style["height"] = RightColumn.offsetHeight + 10 + "px"
         }
     }
}

function showLayer(layerName, showAsBlock)
{
	var layer = document.getElementById(layerName);
	if (layer.style["display"] == "none")
	{
		if (showAsBlock)
			layer.style["display"] = "block";
		else
			layer.style["display"] = "inline";
	}
	else
		layer.style["display"] = "none";
}

function URLEncode(x)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = x;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function webSearch(engine, x)
{
	window.open(engine+x);
}

function launchHelp()
{
	//maximise main window first
	window.moveTo(0,0); 
	if (isIE)
		window.resizeTo(screen.availWidth,screen.availHeight); 
	else 
	{
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{ 
			top.window.outerHeight = screen.availHeight; 
			top.window.outerWidth = screen.availWidth; 
		}
	}

	var winWidth = 280; 
	var winLeft = screen.availWidth - winWidth;
	var winFeatures = "resizable=yes,top=0,width="+(winWidth-5)+",height="+(screen.availHeight - 28)+",left="+winLeft+",scrollbars=1";
	
	if (isIE)
		window.resizeTo((screen.availWidth - (winWidth-5)), screen.availHeight+5);
	else
		window.outerWidth = screen.availWidth - (winWidth+3);
	
	var HelpSystem = window.open("./default.aspx?pageid=31", "HelpSystem", winFeatures);
	HelpSystem.focus();
}

function ResizeOpener()
{
	if (isIE)
		opener.resizeTo(screen.availWidth, screen.availHeight);
	else
		opener.outerWidth = screen.availWidth;
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgName = (img.name) ? "name='" + img.name + "' " : ""
            var imgSrc = (img.src) ? "src='" + img.src + "' " : ""
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle + imgName
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
	     }
      }
   }    
}

function querystring(key) 
{ 
	var value = null; 
	for (var i=0;i<querystring.keys.length;i++) 
	{ 
		if (querystring.keys[i]==key) 
		{ 
			value = querystring.values[i]; 
			break; 
		} 
	} 
	return value; 
} 


querystring.keys = new Array(); 
querystring.values = new Array(); 

function querystring_Parse() 
{ 
	var query = window.location.search.substring(1); 
	var pairs = query.split("&"); 

	for (var i=0;i<pairs.length;i++) 
	{ 
		var pos = pairs[i].indexOf('='); 
		if (pos >= 0) 
		{ 
			var argname = pairs[i].substring(0,pos); 
			var value = pairs[i].substring(pos+1); 
			querystring.keys[querystring.keys.length] = argname; 
			querystring.values[querystring.values.length] = value; 
		} 
	} 
} 

querystring_Parse(); 

function IsValidEmail(str)
{
    var apos = str.indexOf("@");
    var dpos = str.indexOf(".");
    var epos = str.indexOf("]");
    var fpos = str.indexOf("[");

    if (apos<=0 || dpos<=0 || epos>0 || fpos>0)
      return false;

    if (dpos+1>=str.length)
      return false;

    var s = str.toLowerCase();
    var c;

    for (i=0;i< s.length;i++){
        c = s.charAt(i);
        if (c==' ') 
            return false;
        if ((i==(s.length-1)) &&(c=="."))
            return false;   
        if (i==apos)
            dpos = 0;
        if (c==".")
            dpos = i;
    }

    if (dpos==0)
        return false;

    return true;
}

function IsAscii(str)
{
    var l = str.length;
    for (i=0;i<l;i++){
        //alert(str.charAt(i));
        if (str.charCodeAt(i)>127){
            //alert(str.txtTestcharAt(i) + " Not Ascii");
            i = l + 1;
            return false;
        }
    }
    return true;
}

function CheckCharacters(x, err)
{
    var item = document.getElementById(x)

    if (IsAscii(item.value))
    {
        return true;
    }
    else
    {
        alert(err);
        return false;
    }
    
    return false;
}

function checkBookingForm(conf)
{
    
    return false;    
}



// Resize rotation box height
function ResizeRotateBoxHeight(id)
{   
    //get all rotate box ads
    var boxList = getelementsbyPrefix(id,document.documentElement);
    var maxH = xHeight(id+"0");
  
    //get max height
    for(var i=0;i<boxList.length;i++)
    {
      maxH = Math.max(xHeight(id+i), maxH);
    }
    //set each box with the max height
    for(var i=0;i<boxList.length;i++)
    {
      xHeight(id+i, maxH);   
    }
    xHeight("RotateMainBox",maxH); 

}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
         newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}