﻿var moreResults = true;
var totalHotels;
var waitDuration = 62000;
var repeatCallDuration = 0;
//var isSelectHotelTabGoogleMapReloaded = false;


function fetchHotels(firstTimeCall)
{   
    var paramList = "MethodToCall=GetAvailableHotels";
    paramList += "&FirstTimeCall=" + encodeURI(firstTimeCall);
    var async = true;
    var method = "POST";
    getDataFromServer(requestUrl, callBackFetchHotels, async, method, paramList);
}
function updateIE6MessageStatus(firstTimeCall)
{
    var paramList = "MethodToCall=updateIE6MessageStatus";
    paramList += "&FirstTimeCall=" + encodeURI(firstTimeCall);
    var async = true;
    var method = "POST";
    getDataFromServer(requestedUrl, callBackFetchHotels, async, method, paramList);
}

function ValueToTab()
{
     $fn(_endsWith("sT")).value='Tab3';
}
/*
function SetTab(divObj,tab)
//function SetTab(firstTimeCall)
{
    var paramList = "MethodToCall=TabInSelectHotel";
    paramList += "&SelectedDiv=" + divObj;
    paramList += "&SelectedTab=" + tab;
    var async = true;
    var method = "POST";
//    getDataFromServer(requestedUrl, DummyMethod, async, method, paramList);
    getDataFromServer(requestedUrl, DummyMethod, async, method, paramList);
}
*/
function stillHotelToFetch()
{
    var paramList = "MethodToCall=TabInSelectHotel";
    paramList += "&stillHotelToFetch=" + "true";    
    var async = true;
    var method = "POST";
    getDataFromServer(requestedUrl, DummyMethod, async, method, paramList);
    return fetchStatus;
}

//This is just to handle the response.
function DummyMethod()
{
}

function stillHotelToFetchResult()
{
    
    var value = this.req.responseText;    
    var xDoc = loadXMLDoc(value);
    var xmlNodes = xDoc.getElementsByTagName("value");
    if(null != fetchStatus)
    {
        fetchStatus = xmlNodes;
    }    
}

function callBackFetchHotels()
{
    var value = this.req.responseText;    
    var data;        
    var xDoc = loadXMLDoc(value);  

    var xmlNodes = xDoc.getElementsByTagName("hotels");
    var errorMessage;
    
    if(xmlNodes.length == 0)
    {
		xmlNodes = xDoc.getElementsByTagName("error");
        
        //RK: Hide the tab if there are no hotels available and also, edit stay module shld be visible
            if($fn(_endsWith("TabStructure")) != null)
            $fn(_endsWith("TabStructure")).style.display="none";
               var totalHotel=0;
            UpdateTotalHotelResultsInSearch(totalHotel);
        if($('#yourStayMod05 div.regular div.modifyDetail') != null)
        {
            var chDet = $("#yourStayMod05 div.regular div.changedDetail");
		    var moDet = $("#yourStayMod05 div.regular div.modifyDetail");
		    var moBrd = $("#yourStayMod05 div.regular div.broadBrd");
            chDet.hide();
		    moDet.show();
		    moBrd.hide();
        }    
        if (xmlNodes.length > 0)
        {
			if (xmlNodes[0].getAttribute("redirect") == "true")
	        {
	            pageurl = xmlNodes[0].getAttribute("pageurl");
	            window.location.href = pageurl;
	        }
			else
			{
			    $fn(_endsWith("divNoAvailabilityMessage")).innerHTML = xmlNodes[0].firstChild.nodeValue;
	            $fn(_endsWith("alertDiv")).style.display = 'block';
	            if(null !=$fn(_endsWith("subHeader")))
	            {
	                $fn(_endsWith("subHeader")).innerHTML = "";
	            }
	            if(null != $fn(_endsWith("allHotels")))
	            {
	                $fn(_endsWith("allHotels")).innerHTML = "";
	            }
	            if(null != $fn(_endsWith("footerContainer")))
	            {
	                $fn(_endsWith("footerContainer")).innerHTML = "";
	            }
	            hidePaginationSearch();
			}
        }
    }
    else
    {
        xmlNodes = xDoc.getElementsByTagName("hotel");
        totalHotels = xDoc.getElementsByTagName("hotels")[0].getElementsByTagName('totalhotels')[0].firstChild.nodeValue;
        // Display the error message if returned in the hotel response in the top block of the page
		var errorTag = xDoc.getElementsByTagName("hotels")[0].getElementsByTagName('error')[0];
        if (errorTag)
        {
			var errorMessage = errorTag.firstChild.nodeValue;
            $fn(_endsWith("divNoAvailabilityMessage")).innerHTML = errorMessage;
            //498702:Error message is not displayed correctly.
            $fn(_endsWith("alertDiv")).style.display = 'block';
        }
        
        //Commented due to (359402 | Map | Search List and Google map are not displayed in the search result page.)
        //This is no more required
        /*
        // R1.4 Marketting City
        // if alCityHotelTag is true then hide the divAvailability of ReservationInformationContainer  
        var altCityHotelTag = xDoc.getElementsByTagName("hotels")[0].getElementsByTagName('altCityHotelsfound')[0]
        if (altCityHotelTag)
        {
			var errorMessage = errorTag.firstChild.nodeValue;
            $fn(_endsWith("divAvailability")).innerHTML = "";
        }
        */

        var hotelCount = xmlNodes.length;
	    if ( hotelCount > 0 )
	    {
			hotelParent  = $fn(_endsWith('allHotels'));
			if(hotelParent != null)
			{
			    hotelParent.innerHTML = '';
			}
	        for(ctr=0; ctr<hotelCount && ctr<pageSize; ctr++)
	        {
	            if(xmlNodes[ctr].childNodes.length > 0)
	            {
	                if(xmlNodes[ctr].getElementsByTagName("displayed")[0].firstChild.nodeValue == "0")
	                {
	                    hotel = GetHotel(xmlNodes[ctr]);
	                    /* Uncomment Raj*/
	                    AddHotel(hotel, hotelParent);	                    
	                }
	            }
	        }

	        if (ctr==pageSize) {
	            showPaginationSearch();
            }
	    }    	

	    if(xDoc.getElementsByTagName("hotels")[0].getElementsByTagName('morehotelstofetch')[0].firstChild.nodeValue == "true")
	    {	
	        setTimeout('fetchHotels(false)', 500);
	    }
	    else 
	    {
            data = "<div class=\"clear\">&nbsp;</div>";
            addData(data);
	        SetPageStrs();
	        SetPagination();
	        hidePaginationSearch();
	        RefreshGoogleMapIframe(); // Using Iframe
	        UpdateTotalHotelResultsInSearch(totalHotels);
//	        RefreshGoogleMapTimer(); // Using Updatepanel
	    }
    }
}

function GetHotel(hotelXML)
{

    hotel = new HotelDetails();
    hotel.ID            = getStringFromNode(hotelXML.getElementsByTagName("code")[0]);
    hotel.imageSrc      = getStringFromNode(hotelXML.getElementsByTagName("image")[0]);
    if (!hotel.imageSrc) 
        hotel.imageSrc = "/Templates/Booking/Images/noimage.gif";
    hotel.imageAlt      = getStringFromNode(hotelXML.getElementsByTagName("name")[0]);
	hotel.hotelUrl		= getStringFromNode(hotelXML.getElementsByTagName("url")[0]);
	hotel.hotelName		= getStringFromNode(hotelXML.getElementsByTagName("name")[0]);
	hotel.rateTitle		= getStringFromNode(hotelXML.getElementsByTagName("rateTitle")[0]);
	hotel.price			= getStringFromNode(hotelXML.getElementsByTagName("rate")[0]);
	hotel.perNight		= getStringFromNode(hotelXML.getElementsByTagName("prpn")[0]);
	hotel.selectHotel	= getStringFromNode(hotelXML.getElementsByTagName("sH")[0]);
	hotel.address		= getStringFromNode(hotelXML.getElementsByTagName("address")[0]);
	hotel.teaser		= getStringFromNode(hotelXML.getElementsByTagName("description")[0]);
	hotel.distance		= getStringFromNode(hotelXML.getElementsByTagName("distance")[0]);
	hotel.direction		= getStringFromNode(hotelXML.getElementsByTagName("direction")[0]);
	hotel.drivingTime	= getStringFromNode(hotelXML.getElementsByTagName("drivingTime")[0]);
	// R1.4 Marketting city
	hotel.distanceText		= getStringFromNode(hotelXML.getElementsByTagName("distanceText")[0]);
	hotel.directionText		= getStringFromNode(hotelXML.getElementsByTagName("directionText")[0]);
	//R2.0 | Iteration 2
	hotel.drivingTimeText	= getStringFromNode(hotelXML.getElementsByTagName("drivingTimeText")[0]);
	hotel.fullDescriptionText	= getStringFromNode(hotelXML.getElementsByTagName("fulldescription")[0]);
	hotel.imageGalleryText	= getStringFromNode(hotelXML.getElementsByTagName("imagegallery")[0]);
	hotel.fromText	= getStringFromNode(hotelXML.getElementsByTagName("fromText")[0]);		
	//Defect Id-430452 (Change the font of Bonus Cheque rate displayed in Select Hotel page.) -parvathi 
	hotel.HotelSearch = getStringFromNode(hotelXML.getElementsByTagName("HotelSearch")[0]);
	//RK: R2.0 - CR - Unblock Rooms - this property says whether rooms have to be unblocked.
	hotel.IsUnblockRequired = getStringFromNode(hotelXML.getElementsByTagName("IsUnblockRequired")[0]);	
	if(hotel.IsUnblockRequired == "False")
	{
	    hotel.IsUnblockRequired = "false";
	}
	else
	{
	    hotel.IsUnblockRequired = "true";
	}
	//RK: EndOfUnblock Rooms
	return hotel;
}

function HotelDetails()
{
	this.ID				= null;
	this.imageSrc		= null;
	this.imageAlt		= null;
	this.hotelUrl		= null;
	this.hotelName		= null;
	this.rateTitle		= null;
	this.price			= null;
	this.perNight		= null;
	this.selectHotel	= null;
	this.address		= null;
	this.teaser			= null;
	this.distance = null;
	this.direction = null;
	this.drivingTime = null;
	// R1.4 Marketting City
	this.distanceText = null;
	this.directionText = null;
	this.drivingTimeText = null;
	this.fullDescriptionText = null;
	this.imageGalleryText = null;
	this.fromText = null;	
	//Defect Id-430452 (Change the font of Bonus Cheque rate displayed in Select Hotel page.) -parvathi 
	this.HotelSearch = null;
	this.IsUnblockRequired = false;
}

function AddHotel(hotel, parent)
{
    hotelDetailBody	= $.DIV({className:'hotelInfoCnt'});
    imgHolder		= $.DIV({className:'imageHolder'});
    sprite			= $.DIV({className:'hd sprite'});
    $(imgHolder).append(sprite);
    cnt			= $.DIV({className:'cnt'});
    image			= $.IMG({'src':hotel.imageSrc, 'alt':hotel.imageAlt, 'width':'226', 'height':'148'});
    $(cnt).append(image);
    $(imgHolder).append(cnt);
    ftsprite		= $.DIV({className:'ft sprite'});
    $(imgHolder).append(ftsprite);
    $(hotelDetailBody).append(imgHolder);
    //------
    desc			= $.DIV({className:'desc'});
    hotelName			= $.H2({},hotel.hotelName);
    $(desc).append(hotelName);
    address			= $.P({},$.SPAN({},$.A({href:hotel.hotelUrl},hotel.address)));
    $(desc).append(address);
    teaser			= $.P({},hotel.teaser);
    $(desc).append(teaser);
    ULelement 		= $.UL({className:'links'});
    //Release R2.0 - Bhavya to Fix navigation to hotel landing page not happening error.
    Li1			= $.LI({},$.A({className:'goto spriteIcon',href:hotel.hotelUrl},hotel.fullDescriptionText));
    $(ULelement).append(Li1);
//    scandic.windowpopup();
    //Image Gallery Implementation
      //Li2			= $.LI({},$.A({title:'Image gallery',className:'overlay jqModal spriteIcon',href:requestUrl+"?methodToCall=GetImageGallery&HotelID="+hotel.ID},hotel.imageGalleryText));
      Li2			= $.LI({},$.A({href:'#',className:'overlay jqModal spriteIcon',rel:requestUrl+"?methodToCall=GetImageGallery&HotelID="+hotel.ID +"&HotelName="+hotel.hotelName},hotel.imageGalleryText));
   // Li2			= $.LI({},$.A({title:'Image gallery',className:'overlay jqModal spriteIcon',href:'javascript:GetImageData('+ x + ');'},hotel.imageGalleryText));
    $(ULelement).append(Li2);
    $(desc).append(ULelement);
    $(hotelDetailBody).append(desc);
    ratesholder	= $.DIV({className:'ratesHolder'});
    rates		= $.DIV({className:'rates'});
    
    //artf1167579 : Corporate Identifier not present in Select Hotel listing :Rajneesh
    if(hotel.rateTitle)
    {
    ratesHolderContainer = $.DIV({className:'ratesHolderContainer ratesDNumber'});
    }
    else
    {
    ratesHolderContainer = $.DIV({className:'ratesHolderContainer'});
    }
    ratesHolderTop = $.DIV({className:'ratesHolderTop'});
    ratesHolderBottom = $.DIV({className:'ratesHolderBottom'}); 
    $(ratesHolderContainer).append(ratesHolderTop);
    
    
    //artf1167579 : Corporate Identifier not present in Select Hotel listing-Rajneesh
    if (hotel.rateTitle)
	{
	   var str = hotel.rateTitle;
	   if(str.length >= 14)
	   {
	    str = (str.substring(0,14)) + "...";
	    
	   }
	   parrateTitle = $.P({},$.SPAN({className:'ratetitleclass'},str));
	   $(rates).append(parrateTitle);
	} 
    
    para1		= $.P({},$.SPAN({},hotel.fromText));
    $(rates).append(para1);
    
    //Defect Id-430452 (Change the font of Bonus Cheque rate displayed in Select Hotel page.) -parvathi 
    if(hotel.HotelSearch == 'BONUSCHEQUE' || hotel.HotelSearch == 'REDEMPTION' )
        para2		= $.P({className:'ratesFont'},$.STRONG({},hotel.price));
    else
    {
        para2       =$.P({className:'rates'},$.STRONG({},hotel.price));
    }
    $(rates).append(para2);
    hr1		= $.HR({className:'HR'});
    $(rates).append(hr1);
    para3		= $.P({className:'rateText'},hotel.perNight);
    $(rates).append(para3);
    $(ratesholder).append(rates);
  
	wrapper=$.DIV({className:'actionBtnContainer'});
    acnBtn      = $.DIV({className:'actionBtn sprite'});

    //RK: R2.0 - CR - Unblock Rooms - to decide whether different hotel is selected for search, will be used to make the decision whether reserved rooms have to be unblocked
    a1          = $.A({className:'buttonInner sprite',href:'javascript:UpdateSHListSelection();RedirectToSelectRate('+hotel.ID+','+''+hotel.IsUnblockRequired+''+');'},hotel.selectHotel);
    $(acnBtn).append(a1);
    a2          = $.A({className:'buttonRt sprite noText',href:'javascript:RedirectToSelectRate('+hotel.ID+','+''+hotel.IsUnblockRequired+''+');'},hotel.selectHotel);
    $(acnBtn).append(a2);
    //RK: R2.0 - CR - End - Unblock Rooms 
    $(wrapper).append(acnBtn);
    $(ratesholder).append(wrapper);       
       //Rajneesh
       $(ratesHolderContainer).append(ratesholder);
       $(ratesHolderContainer).append(ratesHolderBottom);
        $(hotelDetailBody).append(ratesHolderContainer);
       
       //$(hotelDetailBody).append(ratesholder);
       $(parent).append(hotelDetailBody);
	
}

function addData(data)
{
    $fn("hotelDetailContainer").innerHTML = $fn("hotelDetailContainer").innerHTML + data;
}

var totalPages;
var pageDetails = new Array();
var headerDtMsg1;
var val1;
var availabity1;
var valHdnAlert;
function SetPageStrs()
{
    

    //parvathi- defect id 430682 Appropriate search result text is not displayed in select hotel page.
    headerDtMsg1 = $fn(_endsWith("headerDtMsg"));
    val1 = $fn(_endsWith("txtAvailabilityMsg1"));
    headerDtMsg1.innerHTML = "<strong>"+totalHotels +" "+ val1.value +"</>";
    availabity1 =  $fn(_endsWith("txtAvailabilityMsg2"));
    availabity1.value = headerDtMsg1.innerHTML
    if (totalHotels > pageSize)
        totalPages = Math.ceil(totalHotels/pageSize)
    else
        totalPages = 1;   

    var startVal = 1;
    for (i = 0; i < totalPages; i++)
    {
        var endVal = startVal + pageSize - 1;
        if (endVal > totalHotels)
            endVal = totalHotels;
        if (startVal == endVal)
            pageDetails[i] = startVal;
        else
            pageDetails[i] = startVal + "-" + endVal;
        startVal = endVal + 1;
    }
    //artf1153012 : Bonus Cheque booking is not possible for 99 nights 
    valHdnAlert = $fn(_endsWith("infoAlert"));
    valHdnAlert.style.display = "block";
    
    return pageDetails;
}

var currentPage;
var paginationDiv; 
var headerDtMsg2;
var val2;
var availabity2;
var val1HdnAlert;
function SetPagination()
{
    //artf1153012 : Bonus Cheque booking is not possible for 99 nights 
    val1HdnAlert = $fn(_endsWith("infoAlert"));
    val1HdnAlert.style.display = "block";
    
    //parvathi- defect id 430682 Appropriate search result text is not displayed in select hotel page.
    headerDtMsg2 = $fn(_endsWith("headerDtMsg"));
    val2 = $fn(_endsWith("txtAvailabilityMsg1"));
    headerDtMsg2.innerHTML = "<strong>"+totalHotels +" "+ val2.value+"</>";
    availabity2 =  $fn(_endsWith("txtAvailabilityMsg2"));
    availabity2.value = headerDtMsg2.innerHTML
    if(totalPages == 1)
    {
        var hotelFooter = $fn("hotelFooterContainer");
        if (hotelFooter)
        {
            hotelFooter.innerHTML = "";
        }   
    }
    else
    {
        currentPage = $fn(_endsWith("txtPageNo")).value;
        paginationDiv = $fn("pageListing"); 
        var pD = "";

        pD = pD + "<span class=\"prevLink\">";
        if (currentPage != 1)
        {
	        pD = pD + "<a href=\"javascript:SelectPagination(1);\">" + prv + "</a>";
        } 
        else
        {
            pD = pD + prv;
        }
        pD = pD + "</span>";

        for (i=0; i<pageDetails.length; i++)
        {
            pD = pD + " | ";
            pD = pD + "<span class=\"pageItem\">";
            if (currentPage != i+1) {
                pD = pD + "<a href=\"javascript:SelectPagination(" + (i+1) + ");\">" + pageDetails[i] + "</a>";
            }
            else {
                pD = pD + "<span class=\"pageItemSelected\">" + pageDetails[i] + "</span>"
            }
            pD = pD + "</span>"
        }

        pD = pD + " | ";
        pD = pD + "<span class=\"nextLink\">";
        if (currentPage != totalPages)
        {
	        pD = pD + "<a href=\"javascript:SelectPagination(" + ((currentPage*1)+1) + ");\">" + nxt + "</a>";
        }
        else
        {
            pD = pD + nxt;
        }
        pD = pD + "</span>";

        paginationDiv.innerHTML = pD;
    }
}

function SelectPagination(pn)
{
    $fn(_endsWith("txtPageNo")).value = pn;
    var SelectPagination = $fn(_endsWith('SelectPagination'));
    eval(SelectPagination.href);
    
}

function RefreshGoogleMapIframe()
{
    //Remove the load indicator in the select a hotel page.			
	RemoveMyOverlay();
	
	
	var googleMapIframe = document.getElementById('SelectHotelGoogleMapIframe');
	// As the reloading works only if the loading succeeded !!!!! Assign newly.
	//googleMapIframe.contentWindow.location.reload(true);
    googleMapIframe.src = "/Templates/Scanweb/Pages/Booking/BookingGoogleMapPage.aspx";
	
	//isSelectHotelTabGoogleMapReloaded = true;
	
	var rdoPerNight = $fn(_endsWith('rdoPerNightMap'));
    rdoPerNight.disabled = false;
    var rdoPerStay = $fn(_endsWith('rdoPerStayMap'));
    rdoPerStay.disabled = false;
	
    // document.getElementById('SelectHotelGoogleMapIframe').contentDocument.location.reload(true);
    // var f = document.getElementById('iframe1');
    // f.src = f.src;
}

function RefreshGoogleMapTimer()
{
    if (typeof RefreshGoogleMap == 'function')
    {
        RefreshGoogleMap();
    }
    else
    {
        setTimeout('RefreshGoogleMapTimer();', 100);
    }
}

function RedirectToSelectRate(hotelCode,isUnblockRequired)
{
    var TxtHotelId = $fn(_endsWith('txtHotelId'));
    TxtHotelId.value = hotelCode;
    var SelectOneHotel = $fn(_endsWith('SelectOneHotel'));
    eval(SelectOneHotel.href);
    //RK: R2.0 - CR - Unblock Rooms - unblocks the rooms if blocked rooms are no longer required.
    if(!isUnblockRequired)
    {        
        ClearBlockedRooms();
    }
    //RK: End Of Unblock Rooms 
}
//RK: R2.0 - CR - Unblock Rooms - to release the blocked rooms.
function ClearBlockedRooms()
{
    var paramList = "MethodToCall=ClearBlockedRooms";
    var async = true;
    var method = "POST";
    getDataFromServer(requestUrl, null, async, method, paramList);
}
//RK: End Of Unblock Rooms 

function RedirectToBookDetail(roomCategoryID, rateCategory, roomNumber)
{
//bug id: 462312 : called appropriate method to display overlay while transitionaing to the next room tab
//defect id: artf1150702 added delay switch
selectRatemoveRoom(roomNumber, false,false);
    $fn(_endsWith("txtRoomCategoryID")).value = roomCategoryID;
    $fn(_endsWith("txtRateCategory")).value = rateCategory;
    $fn(_endsWith("txtRoomNumber")).value = roomNumber;
    $fn(_endsWith("txtPerStay")).value = "";
    bordfy(roomNumber,1);
     //R2.0 Bug id:441792-Ashish Following Commented
   // theForm.submit();
   //End R2.0 Bug id:441792-Ashish
  
}
//Bhavya - this is not required as the value selection of perstay/pernight should not impact the rate displayed for individual rooms in confirmation page.
//R2.0 -Parvathi:artf1149148: Price per night/stay
function setPerNightSelectedOnSelectRatePage(value)
{
    var val = $fn(_endsWith("txtPerStay"));
    if(val != null)
    {
        $fn(_endsWith("txtPerStay")).value = value;
    }
   // alert($fn(_endsWith("txtPerStay")).value);
}
function FindDestinationByName(InputDestination,flag)
{
    var destArray;
    var matchingCityDestinations;
    var totalCities;    
    //If non bookable hotels need to be included in type ahead dropDown then following will execute.
    if(flag)
    {
        matchingCityDestinations = getMatchingDestinations(nonBookableHotelList, InputDestination, true);
    }
    else
    {
        //This will execute in normal flow.
        matchingCityDestinations = getMatchingDestinations(masterCityList, InputDestination, true);
    }
    if (matchingCityDestinations != null)
    {
        totalCities = matchingCityDestinations.length;
        destArray = new Array(totalCities);
        
        for(ctr = 0; ctr < totalCities; ctr++)
        {
            destArray[ctr] = new Array(2);
            
            destArray[ctr][0] = matchingCityDestinations[ctr].ID + "#$:~" + matchingCityDestinations[ctr].name;
            if(matchingCityDestinations[ctr].hotels != null)
            {
                destArray[ctr][1] = new Array(matchingCityDestinations[ctr].hotels.length);
                for(ctrHotel = 0; ctrHotel < matchingCityDestinations[ctr].hotels.length; ctrHotel++)
                {
                    destArray[ctr][1][ctrHotel] = matchingCityDestinations[ctr].hotels[ctrHotel].ID + "#$:~" + matchingCityDestinations[ctr].hotels[ctrHotel].name;
                }
            }
        }    
    }
    return destArray;
}

// Please do not delete this block for now. -Himansu
//***********************************************************************************************************
//var destArray;
//function FindDestinationByName(InputDestination)
//{
//    //destArray = new Array();
//    var paramList = "MethodToCall=FindDestinationByName";
//    paramList +=  "&InputDestination=" + encodeURI(InputDestination);
//    var async = false;
//    var method = "POST";

//    getDataFromServer(requestUrl, callBackFindDestinationByName, async, method, paramList);
//    return destArray;
//}

//function callBackFindDestinationByName()
//{
//    var value = this.req.responseText;    

//    var xDoc = loadXMLDoc(value);
//    var xmlNodes = xDoc.getElementsByTagName("error");
//    var errorMessage;

//    if(xmlNodes.length > 0)
//    {
//        /*if (xmlNodes[0].getAttribute("redirect") == "true")
//            window.location.href = "Error.aspx?ErrMsg=" + xmlNodes[0].firstChild.nodeValue;
//        else        */
//            $fn(_endsWith(errorDivID)).innerHTML = xmlNodes[0].text;
//    }
//    else
//    {
//        xmlNodes = xDoc.getElementsByTagName("destination");
//        destArray = new Array(xmlNodes.length);
//        
//        for(ctr=0; ctr < xmlNodes.length; ctr++)
//	    {	        
//	        destArray[ctr] = new Array(2);
//	        var xmlCityNode = xmlNodes[ctr].getElementsByTagName("city");
//	        destArray[ctr][0] = xmlCityNode[0].getAttribute("code") + ":" + getStringFromNode(xmlCityNode[0]);
//	        
//	        var xmlHotelNode = xmlNodes[ctr].getElementsByTagName("hotel");
//	        destArray[ctr][1] = new Array(xmlHotelNode.length);
//	        for(ctrHotel=0; ctrHotel < xmlHotelNode.length; ctrHotel++)
//	        {	            
//	            destArray[ctr][1][ctrHotel] = xmlHotelNode[ctrHotel].getAttribute("code") + ":" + getStringFromNode(xmlHotelNode[ctrHotel]);
//	        }
//	    }
//	}
//	return destArray;
//}
//***********************************************************************************************************


function SetHideUnHide()
{
    var sA = $fn(_endsWith("txtShowAll"));
    if (sA.value == "TRUE") sA.value = "FALSE";
    else sA.value = "TRUE";
    //artf1045294 -Start
    if(null != $fn(_endsWith("txtRoomCategoryID")))
    {
        $fn(_endsWith("txtRoomCategoryID")).value = "";
    }
    if(null != $fn(_endsWith("txtRateCategory")))
    {    
        $fn(_endsWith("txtRateCategory")).value = "";
    }
    //artf1045294 -End
}

function SetHideUnHideListingControl()
{
    var sA = $fn(_endsWith("txtShowAll"));
    if (sA.value == "TRUE") sA.value = "FALSE";
    else sA.value = "TRUE";    
}

function SetViewPricePerStay()
{
    var perStay = $fn(_endsWith("txtPerStay"));
    if (perStay.value == "TRUE") perStay.value = "FALSE";
    else perStay.value = "TRUE";
    
    $fn(_endsWith("txtRoomCategoryID")).value = "";
    $fn(_endsWith("txtRateCategory")).value = "";
}

//Method for full description 
function fullDescriptionPopup(url)
{
    window.open(url,'full description','height=600px,width=600px,resizable=yes');
    
}
//Release R2.0 - Bhavya - Availability Calendar - method to fetch the availability Calender on Select Rate page load
function FetchAvailabilityCalenders(firstTimeCall)
{

    var paramList = "MethodToCall=GetAvailabilityCalendars";
    paramList += "&FirstTimeCall=" + encodeURI(firstTimeCall);
    var async = true;
    var method = "POST";
    getDataFromServer(requestUrl, callBackFetchAvailabilityCalenders, async, method, paramList);
}
//Release R2.0 - Bhavya - - Availability Calendar - method to fetch the availability Calender on Select Rate page load
function callBackFetchAvailabilityCalenders()
{
  var value = this.req.responseText;  
  var xDoc = loadXMLDoc(value);
  var notAvailable = $fn(_endsWith("hdnNotAvailableString")).value;
  if (xDoc != null)
  {      
      if (xDoc.documentElement!=null)
      {          
          if (xDoc.documentElement.hasChildNodes)
          {          
              var availabilityCalenderXmlNodes = xDoc.documentElement.getElementsByTagName("AvailabilityCalenderItem");  
              var availabilityCalenderItemsCount = availabilityCalenderXmlNodes.length;               
                          
              for (var iterator = 0; iterator < availabilityCalenderItemsCount; iterator++)
              {              
                  var minRate = "";
                  var arrivalDate ="";
                  var searchState = "";
                  if ($.browser.msie)
                  {
                    minRate = availabilityCalenderXmlNodes[iterator].getElementsByTagName("MinRateString")[0].text;           
                    arrivalDate =  availabilityCalenderXmlNodes[iterator].getElementsByTagName("ArrivalDate")[0].text;  
                    searchState = xDoc.documentElement.getElementsByTagName("SearchState")[0].text; 
                  } 
                  else
                  {
                    minRate = availabilityCalenderXmlNodes[iterator].getElementsByTagName("MinRateString")[0].textContent;           
                    arrivalDate =  availabilityCalenderXmlNodes[iterator].getElementsByTagName("ArrivalDate")[0].textContent; 
                    searchState = xDoc.documentElement.getElementsByTagName("SearchState")[0].textContent;  
                  }   
                  if (arrivalDate != null && minRate != null)
                  {                  
                    var spnMinimumRate = $("#my_carousel .carouselData li .cnt p .arrivalDate:contains('"+arrivalDate+"')").parent().parent().find('.minimumRate');                    
                    if (spnMinimumRate.text()=="" || spnMinimumRate.text()==null)
                    {                      
                       spnMinimumRate.append(minRate);                                             
                    } 
                  }
                }
                // Stop ajax call when search status is complete or the execution duration exceeds the specified time.
                if (searchState != "COMPLETED" && repeatCallDuration < waitDuration)
                {        
                    repeatCallDuration = repeatCallDuration + 500;  
                    setTimeout('FetchAvailabilityCalenders(false);', 500);  
                }
                else 
                {  
                    // After a set wait time populate rate as NotAvailable for all those arrival dates where rates are not fetched from opera.             
                      for (var liIterator = 0; liIterator < availabilityCalenderItemsCount; liIterator++)
                      {
                          var arrivalDateNORate ="";
                          if ($.browser.msie)
                          {                    
                            arrivalDateNORate =  availabilityCalenderXmlNodes[liIterator].getElementsByTagName("ArrivalDate")[0].text;                     
                          } 
                          else
                          {
                            arrivalDateNORate =  availabilityCalenderXmlNodes[liIterator].getElementsByTagName("ArrivalDate")[0].textContent; 
                          }                      
                         if (arrivalDateNORate != null)
                         {
                             var spnUnPopulatedMinimumRate = $("#my_carousel .carouselData li .cnt p .arrivalDate:contains('"+arrivalDateNORate+"')").parent().parent().find('.minimumRate');                    
                             if (spnUnPopulatedMinimumRate.text()=="" || spnUnPopulatedMinimumRate.text()==null)
                             {                                                      
                                spnUnPopulatedMinimumRate.text(notAvailable); 
                                                          
                             }
                         } 
                      }
                }
                //Disable click event on the div if minimum rate is not available.
                var parentDivObj=$("#my_carousel .carouselData .minimumRate:contains('"+notAvailable+"')").parent().parent(); 
                parentDivObj.attr('onclick',"");   
            }
        }
    }
}


