﻿function ClearTextbox(textbox, initalValue)
{
    if (textbox.value == initalValue)
    {
        textbox.value = "";
    }
}

function SetDepartureDate(day, month, year, form)
{
   if( (day != "") && (month != "") && (form.DepartureDay.value =="") && (form.DepartureMonth.value == "") )
   {
    var departureDate = new Date(year, month - 1, day);
    departureDate.setDate(departureDate.getDate() + 1);
    form.DepartureDay.selectedIndex = departureDate.getDate();
    form.DepartureMonth.selectedIndex = departureDate.getMonth() + 1;
   }
   
}


function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

// stretches the last element in a column to reach the bottom of the parent container (or image in the case of the twoColContent)
// for the grey boxes mainly. Needs to be a bit cleverer than the stand match height function
function setElementStretch()
{
    if( !document.lastChild || !document.getElementById || !document.firstChild ) return;
    
    var left = document.getElementById("leftColumn");
    var right = document.getElementById("rightColumn");
    
    if( !left || !right ) return;

    var leftChildPos = left.className.match( "twoCol" ) ? "first" : "last";
    

    if( document.nodeName && document.removeChild )
    {    
        while( left[ leftChildPos + "Child"].nodeName == "#text" )
            left.removeChild( left[ leftChildPos + "Child"] );
    
        while( right.lastChild.nodeName == "#text" )
            right.removeChild( right.lastChild );
    }

    var leftChild = left[ leftChildPos + "Child"];
    var rightChild = right.lastChild;
    
    if( leftChildPos == "last" )
    {   
        leftChild.className = leftChild.className.replace( /\s*greyBottomCorner/g , "" );
        rightChild.className = rightChild.className.replace( /\s*greyBottomCorner/g , "" );
    }
    
    var otLeft = getOffsetTop( leftChild );
    var obLeft = otLeft + leftChild.offsetHeight;

    var otRight = getOffsetTop( rightChild );
    var obRight = otRight + rightChild.offsetHeight;
    
    
    var sLower = obRight < obLeft ? [ "Left" , "Right" ] : [ "Right" , "Left" ];
    var elToChange = eval( sLower[1].toLowerCase() + "Child" );

//    if( obRight > obLeft && leftChildPos == "first" ) return;
    if( !elToChange.className.match( "box_" ) ) return; // only stretch if it is one of the 'box' components

    var diff = eval( "ot" + sLower[1] ) - eval( "ob" + sLower[0] );

    elToChange.style.paddingBottom = 0;

    var testHeight = elToChange.offsetHeight;
    elToChange.style.minHeight = Math.abs(diff) + 'px';

    /* test for < ie6 - which doesn't have minHeight */
    if( testHeight == elToChange.offsetHeight )
        elToChange.style.height = Math.abs(diff) + 'px';
}

function getOffsetTop( el )
{
    var ot = 0;
    while( !el.className.match("page_content") && el.tagName != "BODY" )
    {
        ot += el.offsetTop;
        el = el.offsetParent;
    }
    
    return ot;
}

// In order to get some divs to be the same height, we'll need to work out which div is the tallest, and set the others to be the same height
function setDivHeight() {
    var i,j=0,x,a=setDivHeight.arguments;
    document.div_args = new Array;
    for(i=0;i<(a.length);i++) {
		if ((x=MM_findObj(a[i]))!=null){
			document.div_args[j++]=x;
		}
	}
	
	var theheight = 0;
	for(i=0;i<(document.div_args.length);i++){
        if(document.div_args[i].offsetHeight > theheight) {
            theheight = document.div_args[i].offsetHeight;
        }
	}
	
	for(i=0;i<(document.div_args.length);i++){
	    if (navigator.userAgent.toLowerCase().indexOf('msie')) {
	        document.div_args[i].style.height = theheight;
	    }
        document.div_args[i].style.minHeight = theheight + 'px';
	}
}

// setDivHeightSpecial adds together some divs to give a total height should 1 div be layed out beside 2 divs.
// Check out the Specials page to see what I mean.
function setDivHeightSpecial() {
    // the first argument is always the div we're going to resize, anything after that we're adding together
    var i,j=0,x,a=setDivHeightSpecial.arguments;
    document.div_args = new Array;
    for(i=0;i<(a.length);i++) {
		if ((x=MM_findObj(a[i]))!=null){
			document.div_args[j++]=x;
		}
	}
	
    var theheight = 0;
	for(i=1;i<(document.div_args.length);i++){
	    theheight = theheight + document.div_args[i].offsetHeight;
	}
	
	if (navigator.userAgent.toLowerCase().indexOf('msie')) {
        document.div_args[0].style.height = theheight;
    }
    document.div_args[0].style.minHeight = theheight + 'px';
}

// 'Borrowed' from DreamWeaver
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function PopCalendar(type, form)
{
    // nb: the value for the variabel 'calFormPath' is set serverside
    var thisForm = document.aspnetForm;
    
    var arguments = "&aday=" + thisForm.elements["ArrivalDay"].selectedIndex;
    arguments += "&amonth=" + thisForm.elements["ArrivalMonth"].selectedIndex;
    arguments += "&ayear=" + '2007';
    arguments += "&dday=" + thisForm.elements["DepartureDay"].selectedIndex;
    arguments += "&dmonth=" + thisForm.elements["DepartureMonth"].selectedIndex;
    arguments += "&dyear=" + '2007';
    
    var resourceWindow = open("http://" + calFormPath + "?type=" + type + arguments, "Calendar","resizable=1,width=260,height=270,status=0,scrollbars=0,location=0");
    if (resourceWindow.opener == null)
    {
        resourceWindow.opener = self;
    }
}

function PopMap() 
{
    // nb: the value for the variabel 'mapFormPath' is set serverside
    var winProps="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=374,height=400,screenX=110,screenY=50,left=110,top=50"
    window.open("http://" + mapFormPath,"mapWin",winProps)
}

function OpenSuiteWindow(hotelName){
    
    var resourceWindow = open("/Popups/cs_popup.aspx?hotel=" + hotelName, "HotelSuites","resizable=1,width=700,height=300,status=1,scrollbars=1,location=0");
	if (resourceWindow.opener == null)
	{
	    resourceWindow.opener = self;
	}
}

function SetSearchLocation(location)
{
    var searchForm = document.aspnetForm;
    searchForm.HotelSelect.value = location;
}

function OpenMap()
{
    var resourceWindow = open("/Popups/Map.aspx?type=", "Map","resizable=1,width=327,height=400,status=1,scrollbars=0,location=0");
	if (resourceWindow.opener == null)
	{
	    resourceWindow.opener = self;
	}
}

function OpenPrivacyPolicy( path ){
    
    if( !path ) path = "../Popups/PrivacyPolicy.aspx"
    var resourceWindow = open( path , "PrivacyPolicy","resizable=1,width=570,height=590,status=1,scrollbars=1,location=0");
	if (resourceWindow.opener == null)
	{
	    resourceWindow.opener = self;
	}
	return false;
}

function SetDate(type, day, month)
{
    var searchForm = document.aspnetForm;
  
    switch (type)
    {
        case "Arrival":
            searchForm.ArrivalDay.selectedIndex = day;
            searchForm.ArrivalMonth.selectedIndex = month;
            SetDepartureDate(day, month, 2007, searchForm); // rwn :: 08/01/07 :: changed to 2007 
        break;
        
        case "Departure":
            searchForm.DepartureDay.selectedIndex = day;
            searchForm.DepartureMonth.selectedIndex = month;
        break;
    }

}

function OpenWindow(url, width, height, name)
{
    var arguments = "resizable=1,width=" + width + ",height=" + height + ",status=1,scrollbars=1,location=0"
    var win = window.open(url,name,arguments);
    return !win;
}



function DisplayFlash(path, width, height, bgColor, alt)
{
    document.write('<object type="application/x-shockwave-flash" data="' + path + '" width="' + width + '" height="' + height + '">');
    document.write('<param name="movie" value="' + path + '" width="' + width + '" height="' + height + '"/>');
    document.write('<param name="WMode" value="opaque"/>');
    document.write('<param name="Loop" value="-1"/>');
    document.write('<param name="Quality" value="High"/>');
    document.write('<param name="SAlign" value=""/>');
    document.write('<param name="Menu" value="-1"/>');
    document.write('<param name="Base" value=""/>');
    document.write('<param name="AllowScriptAccess" value="always"/>');
    document.write('<param name="Scale" value="noscale"/>');
    document.write('<param name="DeviceFont" value="0"/>');
    document.write('<param name="EmbedMovie" value="0"/>');
    document.write('<param name="BGColor" value="' + bgColor + '"/>');
    document.write('<param name="SWRemote" value=""/>');
    document.write('<param name="MovieData" value=""/>');
    document.write(alt);
    document.write('</object>');
}


function SetVisibility(id, visibility)
{
    document.getElementById(id).style.visibility = visibility;
}

function btnCalendar_OnClick()
{
    HideMap();
    SetVisibility("cal", "visible");
    SetVisibility(ddlRooms, "hidden");
    SetVisibility(ddlAdults, "hidden");
    SetVisibility(ddlChildren, "hidden");
    SetVisibility(ddlInfants, "hidden");
}

function CalendarClose()
{
    HideCalendar();
    SetVisibility(ddlRooms, "visible");
    SetVisibility(ddlAdults, "visible");
    SetVisibility(ddlChildren, "visible");
    SetVisibility(ddlInfants, "visible");
}

function HideCalendar()
{
    SetVisibility("cal", "hidden");
}

function SetDate_Other(day, month, year)
{
    var currentValue = document.getElementById(ddlMonth).value;
    var newvalue = month+year;
    
    document.getElementById(ddlDay).value = day;
    if(currentValue != newvalue)
    {
        document.getElementById(ddlMonth).value = month+year;
        setTimeout('__doPostBack(\'' + ddlMonth.replace("_", "$") +'\',\'\')', 0);
    }
    
    CalendarClose();
}

function btnMap_OnClick()
{
    HideCalendar();
    SetVisibility("mapOverlay", "visible");
    SetVisibility(ddlDay, "hidden");
    SetVisibility(ddlMonth, "hidden");
    SetVisibility(ddlNights, "hidden")
    SetVisibility(ddlRooms, "hidden");
    SetVisibility(ddlAdults, "hidden");;
    SetVisibility(ddlChildren, "hidden");
    SetVisibility(ddlInfants, "hidden");
}

function SetLocation(hotelCode)
{
    document.getElementById(ddlHotel).value = hotelCode;
 //   CloseMap();
}

function CloseMap()
{
    HideMap();
    SetVisibility(ddlDay, "visible");
    SetVisibility(ddlMonth, "visible");
    SetVisibility(ddlNights, "visible")
    SetVisibility(ddlRooms, "visible");
    SetVisibility(ddlAdults, "visible");;
    SetVisibility(ddlChildren, "visible");
    SetVisibility(ddlInfants, "visible");
}

function HideMap()
{
    SetVisibility("mapOverlay", "hidden");
}

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 ""
}