
Date.prototype.currentCulture = "en-CA";
Date.prototype.setCurrentCulture = function( culture ){ this.currentCultureIndex = -1; this.currentCulture = culture; };
Date.prototype.cultures = [ "en-CA", "fr-CA" ];

Date.prototype.monthNames = new Array(2);
Date.prototype.monthNames[ 0 ] = ["January","February","March","April","May","June","July","August","September","October","November","December"];
Date.prototype.monthNames[ 1 ] = ["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"];

Date.prototype.dayNames = new Array(2);
Date.prototype.dayNames[ 0 ] = ["S","M","T","W","T","F","S"];
Date.prototype.dayNames[ 1 ] = ["S","M","T","W","T","F","S"];

Date.prototype.monthYearFormat = new Array(2);
Date.prototype.monthYearFormat[ 0 ] = ['M Y'];
Date.prototype.monthYearFormat[ 1 ] = ['Y M'];

Date.getFormatCode = function(character) { switch (character) { case "d": return "String.leftPad(this.getDate(), 2, '0') "; case "D": return "Date.dayNames[this.getDay()].substring(0, 3) "; case "j": return "this.getDate() "; case "l": return "Date.dayNames[this.getDay()] ";case "S": return "this.getSuffix() "; case "w": return "this.getDay() "; case "z": return "this.getDayOfYear() "; case "W": return "this.getWeekOfYear() "; case "F": return "Date.monthNames[this.getMonth()] "; case "m": return "String.leftPad(this.getMonth() + 1, 2, '0') "; case "M": return "this.getCurrentMonthName(  ) "; case "n": return "(this.getMonth() + 1) "; case "t":  return "this.getDaysInMonth() ";  case "L": return "(this.isLeapYear() ? 1 : 0) "; case "Y": return "this.getFullYear() "; case "y": return "('' + this.getFullYear()).substring(2, 4) "; case "a": return "(this.getHours() < 12 ? 'am' : 'pm') "; case "A": return "(this.getHours() < 12 ? 'AM' : 'PM') "; case "g": return "((this.getHours() %12) ? this.getHours() % 12 : 12) "; case "G": return "this.getHours() "; case "h": return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') "; case "H": return "String.leftPad(this.getHours(), 2, '0') "; case "i": return "String.leftPad(this.getMinutes(), 2, '0') "; case "s": return "String.leftPad(this.getSeconds(), 2, '0') "; case "O": return "this.getGMTOffset() "; case "T": return "this.getTimezone() "; case "Z": return "(this.getTimezoneOffset() * -60) "; default: return "'" + String.escape(character) + "' "; } }

Date.prototype.getFormatedDate = function ( format ) { var code = ''; var formatLength = format.toString().length; for( var i = 0; i < formatLength; i++ ) { code += eval(Date.getFormatCode(format.toString().substr(i, 1)) ); } return code; }
Date.prototype.getCurrentFormatedDate = function ( ){ return this.getFormatedDate( this.monthYearFormat[ this.getCurrentCultureIndex() ] ); }

Date.prototype.currentCultureIndex = -1;
Date.prototype.getCurrentCultureIndex = function (){ if ( this.currentCultureIndex < 0 ) { for( var i = 0; i < this.cultures.length; i++ ) { if ( this.cultures[ i ] == this.currentCulture ) this.currentCultureIndex = i; } } return this.currentCultureIndex;};
Date.prototype.getCurrentMonthName = function ( ) { return this.monthNames[ this.getCurrentCultureIndex() ][ this.getMonth() ]; }
Date.prototype.getMonthName = function ( month ) { return this.monthNames[ this.getCurrentCultureIndex() ][ month ]; }

Date.prototype.getCurrentDayName = function ( ) { return this.dayNames[ this.getCurrentCultureIndex() ][ this.getDay() ]; }
Date.prototype.getDayName = function ( day ) { return this.dayNames[ this.getCurrentCultureIndex() ][ day ]; }

Date.prototype.getMonthYear = function ( ) { return this.dayNames[ this.getCurrentCultureIndex() ][ day ]; }
        
String.escape = function(string) { return string.replace(/('|\\)/g, "\\$1"); }

String.leftPad = function (val, size, ch) { var result = new String(val); if (ch == null) { ch = " "; } while (result.length < size) { result = ch + result; } return result; }


function popUpEmailOffers(baseUrl, cultureName)
{                     
	window.location.href = baseUrl + 'aspx/EmailOffers.aspx?put=eo&lang='+ cultureName;
	//window.open(baseUrl + 'aspx/EmailOffers.aspx?put=eo&lang='+ cultureName,'Emailoffers','menubar=0,resizable=0,scrollbars=1,width=640,height=830');	
}
function popUpFPCGuestServicesTeam(baseUrl)
{                     
//	window.open(baseUrl + 'aspx/FPCGuestServiceTeam.aspx?put=fpcst' ,'InYourOpinion','menubar=0,resizable=1,scrollbars=1,width=640,height=830');
    openPopUp(baseUrl + 'aspx/FPCGuestServiceTeam.aspx?put=fpcst' ,'InYourOpinion',0,1,1,700,830);
}

function popUpYourOpinion(baseUrl, hotelCode)
{                    
     //aspx/YourOpinion.aspx
     if(hotelCode == undefined)
        hotelCode = "";
	//window.open(baseUrl + '&hc=' + hotelCode ,'InYourOpinion','menubar=0,resizable=1,scrollbars=1,width=640,height=830');
	openPopUp(baseUrl + '&hc=' + hotelCode ,'InYourOpinion',0,1,1,700,830);
}

function popUpFeedback(baseUrl)
{                     
//	window.open(baseUrl + 'aspx/Feedback.aspx' ,'Feedback','menubar=0,resizable=1,scrollbars=1,width=640,height=830');
    openPopUp(baseUrl + 'aspx/Feedback.aspx' ,'Feedback',0,1,1,700,830);
}
function popUpContactUs(baseUrl)
{                     
//	window.open(baseUrl + 'aspx/ContactUs.aspx' ,'ContactUs','menubar=0,resizable=1,scrollbars=1,width=640,height=830');
    openPopUp(baseUrl + 'aspx/ContactUs.aspx' ,'ContactUs',0,1,1,700,830);
}

function popUpRoomrate(pageUrl )
{
    openPopUp( pageUrl,'RoomRate', 0, 1, 1, 675, 850 );  
}

function popUpRoomview(pageUrl)
{
    openPopUp( pageUrl,'RoomView', 0, 1, 1, 700, 850);    
}

function popUpMoreInfo(pageUrl)
{                     
	openPopUp(pageUrl,'MoreInfo', 0, 1, 1, 700, 850);
}

function popUpTravelTool(pageUrl, title)
{                     
    openPopUp(pageUrl,'TravelTools', 0, 1, 0, 700, 520);
}

function popUpSendEPostCard(url)
{                    
    //Changed:
    //Author: Rahul Sharma
    //Date: 26 June, 2008
    //Reason: Changed width of the pop up window to show whole content,
    //and show the scroll bars 
	openPopUp( url, 'SendEPostCard', 0, 0, 0, 700, 600);
}

function popUpPropertyPhoto(pageUrl)
{                     
    openPopUp(pageUrl,'PropertyPhoto', 0, 1, 0, 960, 600);
}

function openPopUp(pageUrl, title, menubar, resizable, scrollbars, width, height)
{
    if ( pageUrl.indexOf( "?" ) < 0 )
        pageUrl += "?";
    else
        pageUrl += "&";
         
     //menubar = 0;
     //resizable = 0;
     scrollbars = 1;
     //width = 700;
     height = 600;
     
   var leftVal = (screen.width - width) / 2;
   var topVal = (screen.height - height) / 2;
       
  window.open(pageUrl + 'DisplayType=popup',title,'menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',width=' + width + ' ,height=' + height + ',Left=30,Top=90');
}

//Added by Sabir(RSI) to implement search functionality in 404 error page
 function searchResult()
 {
   var qsValue = document.getElementById("txtSearch").value;
   location.href= "http://www.fairmont.com/EN_FA/search/searchresults?k="+qsValue;    
 }
 
function OpenWindow(address, heigth, width, title)   
{   
 var winl = (screen.width-width)/2;   
 var wint = (screen.height-heigth)/2;   
 var options = "width=" + width;   
 options += ",height=" + heigth;   
 options += ",top=" + wint;   
 options += ",left=" + winl;   
 options += ",location=yes,toolbar=yes, menubar=yes, scrollbars=1, resizable";   
  
 window.open(address, title, options);   
}

function openPopUpMore(pageUrl, title, menubar, resizable, scrollbars, width, height)
{
   var leftVal = (screen.width - width) / 2;
   var topVal = (screen.height - height) / 2;
       
  window.open(pageUrl,title,'menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',width=' + width + ' ,height=' + height + ' ,left='+ leftVal +' ,top=' + topVal);
  return false;
}

function popupNeedhelp(url)
{
 openPopUp(url, 'Help', 0, 0, 0, 700, 600 );
}

function findPositionX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPositionY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function popUpResvWait(obj1, top, left)
{
    if ( obj1 == "" )
        return;
        
    var popup = document.getElementById(obj1);
    if ( !popup )
        return;
    
	if (top && left) {
	    popup.style.top = top;
	    popup.style.left = left;
	    popup.style.display = "block";
	} else {
	  	var popupX = popupY = 0;
	    var targetX = targetY = 0;
	    var moveToX = moveToY = 0;
	    var offsetLeft = offsetTop = 0;  
	    var myWidth = myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        } else {
            //Error
            return;
        }
        
        popup.style.display = "block";
        
        popupX = findPositionX(popup);
        popupY = findPositionY(popup);
        
        targetX = ((myWidth / 2) - (popup.offsetWidth / 2));
        targetY = ((myHeight / 2) - (popup.offsetHeight / 2));
        
        moveX = ( targetX - popupX );
        moveY = ( targetY - popupY );
       
        popup.style.left = moveX + 'px';
        popup.style.top = moveY + 'px';
	}
	
    showHideDropdowns("hidden");
}

function encodeHtml(value) {
     encodedHtml = escape(value);
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
   } 

function CloseWindow()
{
    var windowObject = window.self; 
    windowObject.opener = window.self; 
    windowObject.close();
}
function hideMenu(obj, img1)
{
    if ( obj != "" )
    {
	    var el = document.getElementById(obj);
	    if ( el ) { el.style.display = "none"; }
	}
	
	if (img1 != "")
	{
	    var im1 = document.getElementById(img1);
    	if (im1) im1.style.display = "none";
    }
}

function switchMenu(obj, img1, img2)
{
	var el = document.getElementById(obj);
	var im1 = document.getElementById(img1);
	var im2 = document.getElementById(img2);
	
	if (el.style.display != "none")
	{
		el.style.display = "none";
	}
	else
	{
		el.style.display = "inline";
	}
	
	if (im1.style.display != "none")
	{
		im1.style.display = "none";
		im2.style.display = "inline";
	}
	else
	{
		im2.style.display = "none";
		im1.style.display = "inline";
	}
}

function switchTabs(obj1, obj2)
{
    var tab1 = document.getElementById(obj1);
    if ( tab1 != null && typeof( tab1 ) != 'undefined' )
        tab1.style.display = "inline";
        
     var elTravel = document.getElementById('TravelTools');
     var tab2 = document.getElementById(obj2);
     
    if ( tab2 != null && typeof( tab2 ) != 'undefined' )
    {
        tab2.style.display = "none";
        if(elTravel!=undefined)
        elTravel.style.display="inline";
    }
}

function CallReservation(obj1, obj2)
{
    if ( typeof( document.getElementById(obj1) ) != 'undefined' )
        document.getElementById(obj1).style.display = "none";
    if ( typeof( document.getElementById(obj2) ) != 'undefined' )
        document.getElementById(obj2).style.display = "block";
}

function toggleDropdown(propertyDropdown)
{        
    var tempDropdown = document.getElementById(propertyDropdown);
    
    if (tempDropdown.style.display == "inline")
    {
        showHideDropdowns("visible");
        tempDropdown.style.display = "none";
        document.onclick = null;
    }
    else
    {
        if (cal) document.getElementById(cal.id + "Container").style.display = "none";
        showHideDropdowns("hidden");
        tempDropdown.style.display = "inline";
    }
}

function showHideDropdowns(status)
{

    if (document.getElementById && document.createTextNode)
	{
	    var elIdArray = new Array();
	    var elNum = 0;
	    
	    if(document.getElementById("checkAvailability"))
	    {
	        elIdArray[elNum] = "checkAvailability";
	        elNum++;
	    } 
	    else if(document.getElementById("arrivalDate"))
	    {
	        elIdArray[elNum] = "arrivalDate";
	        elNum++;
	    } 
	    else if(document.getElementById("wizard"))
	    {
	        elIdArray[elNum] = "wizard";
	        elNum++;
	    }
	    if(document.getElementById("packageFinder"))
	    {
	        elIdArray[elNum] = "packageFinder";
	        elNum++;
	    }
	   
	    for (elID=0; elID < elIdArray.length; elID++) {
	        var selects = document.getElementById(elIdArray[elID]).getElementsByTagName("select");
	        for (var i = 0; i < selects.length; i++)
	        {
		        selects[i].style.visibility = status;
	        }
	        var spans = document.getElementById(elIdArray[elID]).getElementsByTagName("span");
	        for (var i = 0; i < spans.length; i++)
	        {
	            if (spans[i].id.indexOf("_txtDayOfWeek") > -1)
		            spans[i].style.visibility = status;
	        }
	      
	        
        }
	}
}

function selectHotel(id, hotel, propertyDropdown, propertyBox, propertyText)
{        
    document.getElementById(propertyBox).value = id;
    document.getElementById(propertyText).value = " " + hotel;
    toggleDropdown(propertyDropdown);
    if(enabledhotelautopostback)
    {
        __doPostBack(hoteleventtarget, id);
    }
}

function createTableRolls()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables = document.getElementsByTagName("table");
		for (var i = 0; i < tables.length; i++)
		{
			if(tables[i].className == "ruler")
			{
				var trs = tables[i].getElementsByTagName("tr");
				for(var j = 0; j < trs.length; j++)
				{
					if(trs[j].parentNode.nodeName == "TBODY" && trs[j].className != "region")
					{
						trs[j].onmouseover = function(){this.className = "roll"; return false}
						trs[j].onmouseout = function(){this.className = ""; return false}
					}
				}
			}
		}
	}
}

function toggleCalendar(type)
{
    if ( cal )
    {
        var calContainer = document.getElementById(cal.id + "Container");
        if ( calContainer == null || typeof( calContainer ) == 'undefined' )
            return;
            
        if (calContainer.style.display == "inline" && cal.targetType == type)
        {
            calContainer.style.display = "none";
        }
        else
        {
	       	if (cal.id == "calendar")
            {
                    calContainer.style.width = "160px";
                    calContainer.style.marginLeft = "55px";
	        }                                    
            calContainer.style.display = "none";
            calContainer.className = "calendarContainer" + type;
            calContainer.style.display = "inline";
            calContainer.targetType = type;
            
            targetDate = new Date(cal[type + "Month"].value + "/" + cal[type + "Day"].value + "/" + cal[type + "Year"].value);
            targetDate = '<%=%>';
            setCalendar();
        }
    }
}

function generateArray(start, end)
{
    var tempArr = new Array();
    
    if (start > end) return false;
    
    for (var i = start; i <= end; i++)
    {
        tempArr.push(i);
    }
    
    return tempArr;
}

function populateDropdown(obj, opts, sel)
{
    if (typeof obj == "string") obj = document.getElementById(obj);
    
    if (obj!=null){
        for (var q = obj.options.length; q >= 0; q--)
        {
            obj.options[q] = null;
        }
        
        var s = 0;
        
        for (var item in opts)
        {
            var tempOpt = document.createElement("option");
            var tempTxt = document.createTextNode(opts[item]);
            
            tempOpt.value = (typeof opts[item] == "string") ? getMonthNumber(opts[item]) : opts[item];
            tempOpt.appendChild(tempTxt);
            
            obj.appendChild(tempOpt);
            
            if (opts[item] == sel) obj.selectedIndex = s;
            
            s++;
        }
    }
}

function selectDropdown(obj, sel)
{
    if (typeof obj == "string") obj = document.getElementById(obj);
    
    for (var s = obj.options.length - 1; s >= 0; s--)
    {
        if (obj.options[s] && obj.options[s].value == sel)
        {
            obj.selectedIndex = s;
            break;
        }
    }
}

// CALENDAR
// Default target date to today
var targetDate = new Date();

// This function updates the calendar display to reflect the current target date

function setCalendar()
{
    var el, tableEl, rowEl, cellEl, linkEl;
    var tmpDate, tmpDate2;
    var i, j;

    if (cal != null)
    {

        // Update month name
        el = document.getElementById(cal.id + "Header").firstChild;
        el.nodeValue = targetDate.getCurrentMonthName() + "\u00a0" + targetDate.getFullYear();
        
        var prevLink = document.getElementById(cal.id + "PrevLink");
        var currentDate = new Date();
        if ( prevLink )
        {
            if ((targetDate.getMonth() - 1) < currentDate.getMonth() && targetDate.getFullYear() == currentDate.getFullYear()) 
                prevLink.firstChild.firstChild.nodeValue = "";
            else 
                prevLink.firstChild.firstChild.nodeValue = "<<";
        }
	if(isNaN(targetDate))
		targetDate = new Date();

        // Start with the first day of the month and go back if necessary to
        // the previous Sunday
        tmpDate = new Date(Date.parse(targetDate));
        tmpDate.setDate(1);
        while (tmpDate.getDay() != 0)
        {
            tmpDate.addDays(-1);
        }

        tableEl = cal;
        
        if (!tableEl.targetType) tableEl.targetType = "Arrival";

        // Go through each calendar day cell in the table and update it
        for (i = 2; i <= 7; i++)
        {
            rowEl = tableEl.rows[i];

            // Hide row if it contains no dates in the current month
            tmpDate2 = new Date(Date.parse(tmpDate));
            tmpDate2.addDays(6);
            
            if (tmpDate.getMonth()  != targetDate.getMonth() && tmpDate2.getMonth() != targetDate.getMonth()) rowEl.className = "empty";
            else rowEl.className = "";
            
            // Loop through a week
            for (j = 0; j < rowEl.cells.length; j++)
            {
                cellEl = rowEl.cells[j];
                linkEl = cellEl.firstChild;

                if (tmpDate.getMonth() == targetDate.getMonth())
                {
                    linkEl.date = new Date(Date.parse(tmpDate));
                    s = tmpDate.toString().split(" ");
                    linkEl.title = s[0] + " " + s[1] + " " + s[2] + ", " + s[s.length - 1];
                    linkEl.firstChild.nodeValue = tmpDate.getDate();
                    linkEl.style.visibility = "";
                    linkEl.onclick = function ()
                    {
                        targetDate = new Date(Date.parse(this.date));
                        setCalendar();
                        displayDate();
                        return false;
                    }
                }
                else
                {
                    linkEl.style.display = "none";
                    linkEl.firstChild.nodeValue = "";
                }
                
                // Highlight the current date
                if (cellEl.oldClass == null) cellEl.oldClass = cellEl.className;
                var now = new Date();
                if ((now.getFullYear() == tmpDate.getFullYear()) &&
                    (now.getDate() == tmpDate.getDate()) &&
                    (now.getMonth() == tmpDate.getMonth()))
                {
                    cellEl.className = cellEl.oldClass + " target";
                }
                else cellEl.className = cellEl.oldClass;

                // Go to the next day
                tmpDate.addDays(1);
            }
        }

    }
}

// Event handlers for the calendar elements

function addMonths(n)
{
    // Advance the calendar month and update the display
    targetDate.addMonths(n);
    setCalendar();
}

function addYears(n)
{
    // Advance the calendar year and update the display
    targetDate.addYears(n);
    setCalendar();
}

function displayDate()
{
    // Display the current target date as a formatted string
    updateDateFields(targetDate, cal.targetType);
    validateDates(cal.targetType);
    toggleCalendar(cal.targetType);
}

function updateDateFields(date, type)
{
    if(cal[type + "Month"] == undefined || cal[type + "Day"] == undefined || cal[type + "Year"] == undefined)
	return;
    var tempMonth = date.getMonth() + 1;
    if (tempMonth < 10) tempMonth = "0" + tempMonth;
    selectDropdown(cal[type + "Day"], date.getDate());
    selectDropdown(cal[type + "Month"], tempMonth);
    selectDropdown(cal[type + "Year"], date.getFullYear());
    updateDayName(type);
}

function updateNumberOfNights()
{
    if (cal["NumberOfNights"] != undefined && cal["NumberOfNights"] != null)
    {
        var arrivalDate = new Date(cal.ArrivalMonth.value + "/" + cal.ArrivalDay.value + "/" + cal.ArrivalYear.value);
        var departureDate = new Date(cal.DepartureMonth.value + "/" + cal.DepartureDay.value + "/" + cal.DepartureYear.value);
        var numberOfNights = Math.ceil((departureDate.getTime() - arrivalDate.getTime()) / (1000 * 60 * 60 * 24));
        
        if (numberOfNights > 10) numberOfNights = 11;
        selectDropdown(cal.NumberOfNights, numberOfNights);
    }
}

function updateDayName(type)
{
    if (cal[type + "DayName"] != undefined && cal[type + "DayName"] != null)
    {
        var date = new Date(cal[type + "Month"].value + "/" + cal[type + "Day"].value + "/" + cal[type + "Year"].value);
        cal[type + "DayName"].value = daysArray[date.getDay()];
    }
}

function getMonthNumber(month)
{
    for (var i in monthsArray)
    {
        if (monthsArray[i] == month)
        {
            i++;
            if (i < 10) i = "0" + i;
            return i;
        }
    }
}

function validateDates(type)
{
    if(cal.DepartureMonth == undefined)
	return;
    var arrivalDate = new Date(cal.ArrivalMonth.value + "/" + cal.ArrivalDay.value + "/" + cal.ArrivalYear.value);
    var departureDate = new Date(cal.DepartureMonth.value + "/" + cal.DepartureDay.value + "/" + cal.DepartureYear.value);
    var currentDate = new Date();
    
    arrivalDate = YearChange(arrivalDate);
    
    updateDateFields(arrivalDate, "Arrival");
    updateDateFields(departureDate, "Departure");
    
    if (type == "NumberOfNights")
    {
        arrivalDate.setDate(arrivalDate.getDate() + Number(cal.NumberOfNights.value));
        updateDateFields(arrivalDate, "Departure");
    }
    else
    {      
        if (type == "Arrival")
        {        
            if ((departureDate <= arrivalDate))
            {            
                departureDate = arrivalDate;
                if (cal.NumberOfNights)
                {
                    departureDate.setDate(departureDate.getDate() + Number(cal.NumberOfNights.value));                
                }
                else
                {
                    departureDate.setDate(departureDate.getDate() + 1);
                }
                updateDateFields(departureDate, "Departure");
            }
        }
        else if (type == "Departure")
        {
            if ((arrivalDate >= departureDate))
            {
                arrivalDate = departureDate;

               if (cal.NumberOfNights)
                {
                    arrivalDate.setDate(arrivalDate.getDate() - Number(cal.NumberOfNights.value));
                }
                else
                {
                    arrivalDate.setDate(arrivalDate.getDate() - 1);
                }
                updateDateFields(arrivalDate, "Arrival");
            }
        }
        
        updateNumberOfNights();
        updateDayName(type);
    }
}

//Check if month is past, date show next year.
function YearChange(dateCheck)
{   
   	var now = new Date();
	var dayNow = now.getDate();
	var monthNow = now.getMonth();
	var yearNow = now.getFullYear();

	var dayCheck =  dateCheck.getDate();
	var monthCheck = dateCheck.getMonth();
	var yearCheck  = dateCheck.getFullYear();
	var dateReturn; 
    var dayDiff;
	var Minute = 60*1000;
	var Hour = Minute * 60;
	var Day = Hour * 24;

	dayDiff = (dateCheck - now)/Day

	if ((yearNow == yearCheck) && (monthNow != monthCheck) && (monthNow > monthCheck) && (dayDiff < 1))
	{
       yearCheck = parseInt(yearCheck) + 1;
	}
	
	var  d = new Date(yearCheck, monthCheck, dayCheck);
	
	return d;
}

// Add new properties and methods to the Date object

Date.prototype.addDays      = dateAddDays;
Date.prototype.addMonths    = dateAddMonths;
Date.prototype.addYears     = dateAddYears;

// getMonthName(): Returns the name of the date's month

function dateGetMonthName()
{
    return this.monthNames[this.getMonth()];
}

// getDays(): Returns the number of days in the date's month

function dateGetDays()
{
    var tmpDate, d, m;

    tmpDate = new Date(Date.parse(this));
    m = tmpDate.getMonth();
    d = 28;
    do
    {
        d++;
        tmpDate.setDate(d);
    } while (tmpDate.getMonth() == m);

    return d - 1;
}

// addDays(n): Adds the specified number of days to the date

function dateAddDays(n)
{
    // Add the specified number of days
    this.setDate(this.getDate() + n);

    // Reset the new day of month.
    this.savedDate = this.getDate();
}

// addMonths(n): Adds the specified number of months to the date, adjusting
// the day of the month if necessary

function dateAddMonths(n)
{
    // Save the day of month if not already set
    if (this.savedDate == null)
    this.savedDate = this.getDate();

    // Set the day of month to the first to avoid rolling
    this.setDate(1);

    // Add the specified number of months
    this.setMonth(this.getMonth() + n);

    // Restore the saved day of month, if possible
    this.setDate(Math.min(this.savedDate, this.getDays()));
}

// addYears(n): Adds the specified number of years to the date, adjusting the
// day of the month for leap years

function dateAddYears(n)
{
    // Save the day of month if not already set
    if (this.savedDate == null)
    this.savedDate = this.getDate();

    // Set the day of month to the first to avoid rolling
    this.setDate(1);

    // Add the specified number of years
    this.setFullYear(this.getFullYear() + n);

    // Restore the saved day of month, if possible
    this.setDate(Math.min(this.savedDate, this.getDays()));
}

//Show/ Hide link associated script for <div> tags
function toggleLayer(whichLayer)
{
     if (document.getElementById)
     {
          // this is the way the standards work
          var style2 = document.getElementById(whichLayer).style;
          style2.display = style2.display? "":"block";
     }
     else if (document.all)
     {
          // this is the way old msie versions work
          var style2 = document.all[whichLayer].style;
          style2.display = style2.display? "":"block";
     }
     else if (document.layers)
     {
          // this is the way nn4 works
          var style2 = document.layers[whichLayer].style;
          style2.display = style2.display? "":"block";
     }
}

//To get control list by passing the controlID prefix
 function getElementsById(sId)
 {
    var outArray = new Array();	
	if(typeof(sId)!='string' || !sId)
	{
		return outArray;
	};
	
	if(document.evaluate)
	{
		var xpathString = "//*[@id='" + sId.toString() + "']"
		var xpathResult = document.evaluate(xpathString, document, null, 0, null);
		while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
		outArray.pop();
	}
	else if(document.all)
	{
		
		for(var i=0,j=document.all[sId].length;i<j;i+=1){
		outArray[i] =  document.all[sId][i];}
		
	}else if(document.getElementsByTagName)
	{
		var aEl = document.getElementsByTagName( '*' );	
		for(var i=0,j=aEl.length;i<j;i+=1){
		
			if(aEl[i].id == sId )
			{
				outArray.push(aEl[i]);
			};
		};	
		
	};
	
	return outArray;
 }
 
 function getQueryValue(url, queuryStringKey)
 {
  var keyStartPos = url.indexOf("?" + queryStringKey + "=");
  if (keyStartPos < 0)
    keyStartPos = url.indexOf("&" + queryStringKey + "=");


  var stringEndPos = url.indexOf("&" + keyStartPos + "=");
  if (stringEndPos < 0)
    stringEndPos = url.length;

  return url.substr(keyStartPos + 5, stringEndPos  - (keyStartPos + 5));
 }

//IE button hover
sfHover = function() {
	var sfEls = document.getElementsByTagName("input");
	for (var i=0; i<sfEls.length; i++) {
		var type = sfEls[i].getAttribute('type').toLowerCase();
		var cssClass = sfEls[i].className;
		var tag = sfEls[i].className;
		if ((type == 'submit' || type == 'button' || type == 'reset') && (cssClass == "button" || cssClass == 'arrow')) { 
		    // and apply a class to the buttons
		    sfEls[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function ValidatePromoCodeForRATE(source,args)
{
    var txtPromoCode = document.getElementById(source.controltovalidate);
    if (txtPromoCode.value.toUpperCase() == "RATE")
        args.IsValid = false;
    else
        args.IsValid = true;
        
    return;
}

function ValidatePromoCode(source,args)
{   
    var txtPromoCode = document.getElementById(source.controltovalidate);
    //var prefix = txtPromoCode.value.substr(0, 2).toUpperCase();
    //if (prefix == "PR" || prefix == "GR" || prefix == "FA")
    //    args.IsValid = true;
    //else
    //    args.IsValid = false;
    args.IsValid = true;
    if(txtPromoCode.value.toUpperCase() == 'NFAF')
    { 
      
      args.IsValid = false;
    }

	    
    return;
}

/*Nilesh */
function PopUpRedirectToHotel(strDropDown)
{
    var strUrl = document.getElementById(strDropDown).value;    
    if(strUrl=='select')
        return false;
    else
    {
    window.open(strUrl,"_self");
        return true;
    }
    
}
function RedirectPosting(strUrl)
{
    if(strUrl=='')
        return false;
    else
    {
        window.open(strUrl,"_self");
        return true;
    }
    
}
/*Nilesh*/
/*Arvind */
 function expandAvailabilityControl()
    {
        var el = document.getElementById('reservationDetails');
//	    var im1 = document.getElementById('collapseButton');
//	    var im2 = document.getElementById('openButton');
	    
    
        if (el)	
	        el.style.display = "inline";
    	
//    	if (im2)
//	        im2.style.display = "none";
//	        
//	    if (im1)
//	        im1.style.display = "inline";
	    
    }
    
    function ShowDetails()
    {
        
       // var el = document.getElementById('ReservationDetailSearch');
        var elCollBtn = document.getElementById('collapseButton');
        var elOpenBtn = document.getElementById('openButton');
        var elCollpase = document.getElementById('Collapsible');
        var elTravel = document.getElementById('TravelTools');
	    
	       // el.style.display = "block";
	        if(elOpenBtn!=undefined)
	           elOpenBtn.style.display="none";
	        if(elCollBtn!=undefined)
	           elCollBtn.style.display="block";
	        if(elCollpase!=undefined)
	           elCollpase.style.display="inline";
	        if(elTravel!=undefined)
	            elTravel.style.display="none";
	 
	   
    }
    
    function HideDetails()
    {
       
        //var el = document.getElementById('ReservationDetailSearch');
        var elCollBtn = document.getElementById('collapseButton');
        var elOpenBtn = document.getElementById('openButton');
	      var elCollpase = document.getElementById('Collapsible');
	      var elTravel = document.getElementById('TravelTools');
	      var elCancelReservation=document.getElementById('hlkCancelReservation');
	        //el.style.display = "none";
	        if(elOpenBtn!=undefined)
	        {
	        elOpenBtn.style.display="block";
	        elOpenBtn.style.display="inline";
	        }
	        if(elCollBtn!=undefined)
	         elCollBtn.style.display="none";
	        if(elCollpase!=undefined)
	         elCollpase.style.display="none";
	        if(elTravel!=undefined)
    	        elTravel.style.display="inline";
        
    }
    
 // Function To add row style on every table.   
function paintAlternateRowStyle(containerID)
{ 
    
    var j;
    var k;
    var tables = document.getElementsByTagName(containerID);
    for(j=0; j<tables.length; j++)
    {
        
        if (tables[j].className.indexOf('alternateRowStyle') > -1) // if the classname includes 'AlternateRowStyle'
        {
            //debugger;
            //alert(tables[j].className.indexOf('alternateRowStyle') );
            tables[j].rows[0].className='clmnHeading';
            for (k=1; k<tables[j].rows.length; k=k+1)
            {
                tables[j].rows[k].className='even'; 
                k=k+1;
                if ((k != tables[j].rows.length ))// To check if this row exists
                    {
                    tables[j].rows[k].className='odd';
                    }
            }
        }
    }    
}
