﻿//--------Page initialization code

//window.onload = initPage;  
// Make sure that no other javscripts assign a fuction to window.onload
// There can be only one window.onload at a time

function initPage() {
//check selected stylesheet saved in cookie
 // function(e) {
 // var cookie = readCookie("style");
 // var title = cookie ? cookie : getPreferredStyleSheet();
 // setActiveStyleSheet(title);
  
//}
  // place here any other code you wish to run when the page loads.
   
   domTableEnhance();
   initPopupLinks();
//   alert("here");
}

//--------Tell-a-friend popup code

function popTAFwin() {
theUrl = '../pop/tellafriend.asp?refer='+ window.location + '&title=' +document.title+ '&';
window.open(theUrl,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=385,height=360');
}
function openPopup(name, url, height, width, menubar, location, toolbar, scrollbars, resizable){
	var tmpPopup;
	var strProperties = "menubar=" + menubar + ",location=" + location + ",toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",width=" + width + ",height=" + height;
	tmpPopup = window.open(url, name, strProperties);
	tmpPopup.focus();
}

//--------DHTML and CSS window pop code
var deckheight = screen.height;

var popupLinkConfig = new Array;
// popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
popupLinkConfig["TAFpopup"]    = new Array ( "tell-a-friend", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=355,height=300");
popupLinkConfig["deckpop"] = new Array ( "deckplans", "width=550, height=+'deckheight'+=,resizable=yes,scrollbars=yes");
popupLinkConfig["cabinpop"] = new Array ( "cabin", "width=450,height=500,resizable=yes, scrollbars=yes");
popupLinkConfig["explorepop"] = new Array ( "explore", "width=750,height=450,resizable=yes");
popupLinkConfig["destpop"] = new Array ( "destination", "width=460,height=560,resizable=yes");
popupLinkConfig["destpop2"] = new Array ( "destination", "width=460,height=500,resizable=no,scrollbars=no");
popupLinkConfig["mappop"] = new Array ( "map", "width=490,height=400,resizable=yes");
popupLinkConfig["CCpop"] = new Array ( "CC", "width=270,height=560,resizable=yes");
popupLinkConfig["FlashVidpop"] = new Array ( "FV", "width=412,height=350,resizable=yes");
popupLinkConfig["Oceania"] = new Array ( "OC", "width=800,height=800,resizable=yes");


function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
//          alert("here");
          pageLinks[i].onclick = popUp;
        }
      }
    
    }
  }
//  return true;
  
  var pageLinks2 =  document.getElementsByTagName("area");
  for (var i2 = 0; i2 < pageLinks2.length; i2++) 
  {
    if (((pageLinks2[i2].className != null) && 
         (pageLinks2[i2].className != "")) ||
        ((pageLinks2[i2].parentNode.className != null) && 
         (pageLinks2[i2].parentNode.className != "")))
    {
      var linkClass2 = " " + pageLinks2[i2].className + " ";
      if ((linkClass2 == "  ") && (pageLinks2[i2].parentNode.className != ""))
      {
        linkClass2 = " " + pageLinks2[i2].parentNode.className + " ";
      }
      for (var theKey2 in popupLinkConfig) 
      {
        if (linkClass2.indexOf(" " + theKey2 + " ") > -1)
        {
          if ((pageLinks2[i2].target == "") || (pageLinks2[i2].target == null))
          {
            pageLinks2[i2].target = (popupLinkConfig[theKey2][0] != "") ? popupLinkConfig[theKey2][0] : theKey2;
          }
          pageLinks2[i2].settings = popupLinkConfig[theKey2][1];
//         alert("here");
          pageLinks2[i2].onclick = popUp;
        }
      }
    
    }
  }
  return true;
}

function popUp()
{

  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

//--------Enhanced table code

function domTableEnhance()
{
	if(!document.createTextNode){return;}
	var tableClass='enhancedtable';
	var colourClass='enhancedtablecolouredrow';
	var hoverClass='enhancedtablerowhover';
	var activeClass='enhancedtableactive';
	var alltables,bodies,i,j,k,addClass,trs,c,a;
	alltables=document.getElementsByTagName('table');
	for (k=0;k<alltables.length;k++)
	{
		if(!alltables[k].className.match(tableClass)){continue;}
		bodies=alltables[k].getElementsByTagName('tbody');
		for (i=0;i<bodies.length;i++)
		{
			trs=bodies[i].getElementsByTagName('tr')
			for (j=0;j<trs.length;j++)
			{
				if(trs[j].getElementsByTagName('td').length>0)
				{
					addClass=j%2==0?' '+colourClass:'';
					trs[j].className=trs[j].className+addClass;
					
					trs[j].onmouseover=function()
					{
						this.className=this.className+' '+hoverClass;
					}
					trs[j].onmouseout=function()
					{
						var rep=this.className.match(' '+hoverClass)?' '+hoverClass:hoverClass;
						this.className=this.className.replace(rep,'');
					}
				}
			}
		}
	}		
} 

//--------Print Window code

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

//--------Change Stylesheets code

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  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;
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//--------begin DeepMetrix Script


