﻿/*
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();
    
        
   
    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);
}

/*-----------------START-PopUpWithCookie----------------------------*/

function showPopUp(c_name) { 
	
	popupseen=getCookie(c_name);
	if (popupseen==null || popupseen=="")
	{
		setTimeout("document.getElementById('divpopup').style.display = 'block';",3000);
	}
} 

function Seen(c_name)
{
	popupseen='PopUpSeen';
	if (popupseen!=null && popupseen!="")
	{
		setCookie(c_name,popupseen,1);
	}	
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return ""
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toUTCString());
}

function doHidePngPopUp(selectedDiv,c_name) {
	popdiv=document.getElementById(selectedDiv)
	popdiv.style.visibility="hidden";
	Seen(c_name);
}

/*-----------------END-PopUpWithCookie----------------------------*/

 window.onload = externalLinks;


