﻿
function StartIt() {
    var firstpos=location.href.lastIndexOf('/')+1;
    var current_location = window.parent.location.href;
    
    // Check the pops up to initialise only once
    
    var countPop1 = GetCookie('CountPop1');
    var countPop2 = GetCookie('CountPop2');
	var countPop3 = GetCookie('CountPop3');
	var countPop4 = GetCookie('CountPop4');
    
    if (location.href.substring(firstpos,location.href.length) == "")
        current_location = 'default.aspx';
        
    if ((current_location.indexOf('default.aspx')!= -1 && (countPop1 == 0)) || 
    (current_location.indexOf('weddings.aspx')!= -1 && countPop2 == 0) ||
	(current_location.indexOf('conferences.aspx')!= -1 && countPop3 == 0) ||
	(current_location.indexOf('christmas_and_new_year.aspx')!= -1 && countPop4 == 0))
    {
        doShowPopUp();
        
        if (current_location.indexOf('default.aspx')!= -1 && countPop1 == 0)
            SetCookie('CountPop1', 1);
            
        if (current_location.indexOf('weddings.aspx')!= -1 && countPop2 == 0)                    
            SetCookie('CountPop2', 1);
			
	    if (current_location.indexOf('conferences.aspx')!= -1 && countPop3 == 0)                    
        SetCookie('CountPop3', 1);
        
        if (current_location.indexOf('christmas_and_new_year.aspx')!= -1 && countPop4 == 0)                    
        SetCookie('CountPop4', 1);
    }
    else
        doHidePopUp();
    
        
    externalLinks();
    RandomImage();
    
}
window.onload = StartIt;

function externalLinks() { 
	if (!document.getElementsByTagName) return; 
 	var anchors = document.getElementsByTagName("a"); 
 	for (var i=0; i<anchors.length; i++) { 
   		var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
     			anchor.target = "_blank"; 
	 } 
} 

function ShowEmail(user, domain, anchor) {
	var OutText = '';
	OutText += '<a href="mailto:' + user + '@' + domain + '">';
	if (anchor != '') OutText += anchor;
	else OutText += user + '@' + domain;
	OutText  += '</a>';
	document.write(OutText);
}

function ShowEmailGoogleTracker(user, domain, anchor) {
	var OutText = '';
	OutText += "<a href='mailto:" + user + "@" + domain + "' onClick=\"pageTracker._trackEvent('email-link', 'clicked', 'email-us');\">";
	if (anchor != '') OutText += anchor;
	else OutText += user + '@' + domain;
	OutText  += '</a>';
	document.write(OutText);
}


function ShowSubMenu()
{
    //SYNTAX: ddtabmenu.definemenu("tab_menu_id", integer OR "auto")
    
    var current_location = window.parent.location.href;
    if (current_location.indexOf('promotions')!= -1)
        ddtabmenu.definemenu("ddtabs1", 5)             
    else if (current_location.indexOf('accommodation')!= -1 && current_location.indexOf('weddings_accommodation') == -1)
        ddtabmenu.definemenu("ddtabs1", 0)
    else if (current_location.indexOf('leisure')!= -1)
        ddtabmenu.definemenu("ddtabs1", 1)    
    else if (current_location.indexOf('conferences')!= -1)
        ddtabmenu.definemenu("ddtabs1", 2)            
    else if (current_location.indexOf('weddings')!= -1)
        ddtabmenu.definemenu("ddtabs1", 3)
    else if (current_location.indexOf('dining')!= -1)
        ddtabmenu.definemenu("ddtabs1", 4)        
    else
        ddtabmenu.definemenu("ddtabs1", "auto")//initialize Tab Menu #1 with 1st tab selected
}

var images = new Array("boxLeisure", "boxDining", "boxConference", "boxWeddings");

function RandomImage() {
    var l = images.length;
    var rnd_no1 = Math.round((l-1)*Math.random());
    var rnd_no2 = rnd_no1;
    do {
        rnd_no2 = Math.round((l-1)*Math.random());
    } while (rnd_no2 == rnd_no1);

    theElem1 = document.getElementById(images[rnd_no1]);
    theElem2 = document.getElementById(images[rnd_no2]);

    for (var i=0; i<l; i++)
    {
        theElem = document.getElementById(images[i]);
        
        if (theElem != null)
        {
            if ((images[i] == images[rnd_no1]) || (images[i] == images[rnd_no2]))
                theElem.style.display = "";
            else
                theElem.style.display = "none";
        }
    }
}

function ShowTour(page)
{
    document.getElementById('box').innerHTML = '<iframe src="e-tour/' + page + '.htm" id="tourframe" width="360" height="240" frameborder="0" scrolling="no"></iframe>';
}

function ShowImage(img)
{
    document.getElementById('box').innerHTML = '<img src="i/etour/' + img + '" alt="" />';
}

var MONTH_NAMES=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function handleOnChange(dd1, dd2)
{
    var idx = dd1.selectedIndex;
    //var val = dd1[idx].text; // Get dropdown text
    var val = dd1[idx].value; // Get dropdown value
    var splitVal = val.split("/")

    switch (splitVal[0]){
        case "01":
        case "03":
        case "05":
        case "07":
        case "08":
        case "10": 
        case "12": 
            fillDropDown(31, dd2)
            break;
        case "02": 
        {
            if (isLeapyear(splitVal[1]))
                fillDropDown(29, dd2)
            else
                fillDropDown(28, dd2)                
        }   
            break;
        case "04":
        case "06":
        case "09":
        case "11": 
            fillDropDown(30, dd2)
        break;
    }
  
}

function fillDropDown(no_of_days, dd2) {
    var objDropdown = dd2;

    while(objDropdown.hasChildNodes()){
        objDropdown.removeChild(objDropdown.childNodes[0])
    }

    for(i=1; i<=no_of_days; i++) {
        var objOption = new Option(i,i);
        objDropdown.options[objDropdown.length] = objOption;
    }
}

function isLeapyear(year)
{
    return year%400 ==0 || (year%100 != 0 && year%4 == 0);
}

function doHidePopUp() {
    popdiv=document.getElementById("divpopup")
    if (popdiv != null)
	{
	    popdiv.style.visibility="hidden"
	}
}
	
function doShowPopUp(){
	popdiv=document.getElementById("divpopup")
	
	if (popdiv != null)
	{
	    popdiv.style.left="45%"
	    popdiv.style.marginLeft="-223px"
	    if ((is_ie5up) && (is_mac)){ //fix for ie-mac does not accept popdiv.style.top="50%"
		    popdiv.style.top="0px"
		    popdiv.style.marginTop="0px"
	    }else{
		    popdiv.style.top="22%"
		    popdiv.style.marginTop="-132px"
	    }
	    popdiv.style.visibility="visible"
	}
}
	
function SetCookie(name,value){
    cookiestring=name+"="+escape(value)+";";
    document.cookie=cookiestring;
    if(!GetCookie(name)){
        return false;
    }
    else{
        return true;
    }
}

function GetCookie(cookiename) {
    var cookiestring=""+document.cookie;
    var index1=cookiestring.indexOf(cookiename);
    if (index1==-1 || cookiename=="") return ""; 
    var index2=cookiestring.indexOf(';',index1);
    if (index2==-1) index2=cookiestring.length; 
    return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}




