﻿
//----------global variables
var arrRestaurants = [];
var newTable;
var newTableBody;
var arrPageIndicators = [];
var checkboxObjArr = [];
var arrCuisineTypesAndCounts = [];
var arrPriceAndCounts = [];
var arrFeaturesAndCounts = [];
var sortedOrder = "unsorted"; // possible values "distance_asc", "distance_desc", "price_asc", "price_desc", "name_asc", "name_desc", "rating_asc", "rating_desc"
var g_rowsPerPage = 20;
var siteUrl = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1);

//---------------- Modal Dialog begins 
var maskpanel = function() {
    this.divobj;
    this.show = function() {
        //;
        if (!document.getElementById("menumama_divMasking")) {

            var divEle = document.createElement('div');
            divEle.setAttribute("id", "menumama_divMasking");
            document.body.appendChild(divEle);
            var divSty = document.getElementById("menumama_divMasking").style;
            divSty.position = "absolute"; divSty.top = "0px"; divSty.left = "0px";
            divSty.zIndex = "46";
            divSty.opacity = ".50"; divSty.backgroundColor = "#AAA";
            divSty.filter = "alpha(opacity=25)";

            var divFram = document.createElement('iframe');
            divFram.setAttribute("id", "menumama_maskFrame");
            document.body.appendChild(divFram);
            divSty = document.getElementById("menumama_maskFrame").style;
            divSty.position = "absolute"; divSty.top = "0px"; divSty.left = "0px";

            divSty.zIndex = "45"; divSty.border = "none"; divSty.filter = "alpha(opacity=0)";
        }

        this.divobj = document.getElementById("menumama_divMasking");
        this.waitifrm = document.getElementById("menumama_maskFrame");

        var dsh = document.documentElement.scrollHeight;
        var dch = document.documentElement.clientHeight;
        var dsw = document.documentElement.scrollWidth;
        var dcw = document.documentElement.clientWidth;

        var bdh = (dsh > dch) ? dsh : dch;
        var bdw = (dsw > dcw) ? dsw : dcw;

        this.waitifrm.style.height = this.divobj.style.height = bdh + 'px';
        this.waitifrm.style.width = this.divobj.style.width = bdw + 'px';
        this.waitifrm.style.display = this.divobj.style.display = "block";
    };

    this.hide = function() {
        this.waitifrm.style.display = this.divobj.style.display = "none";
    };
}

var menumama_mask;
function viewmaskpanel() {
    menumama_mask = new maskpanel();
    menumama_mask.show();
    var menumama_divPopup = document.getElementById("menumama_divPopup");
    if (menumama_divPopup == null) return;
    menumama_divPopup.style.display = "block";
    menumama_divPopup.style.top = (((document.documentElement.clientHeight / 2) + document.documentElement.scrollTop) - (menumama_divPopup.offsetHeight / 2)) + 'px';
    menumama_divPopup.style.left = (((document.documentElement.clientWidth / 2) + document.documentElement.scrollLeft) - (menumama_divPopup.offsetWidth / 2)) + 'px';

    //setTimeout("hidemaskpanel()",5000);
    //sleep(5000);
    //setTimeout("",5000);
}

function hidemaskpanel() {
    if (document.getElementById("menumama_divPopup") == null) return;
    document.getElementById("menumama_divPopup").style.display = "none";
    if (menumama_mask != null && typeof (menumama_mask) != "undefined")
        menumama_mask.hide();
}

//---------------- Modal Dialog ends

//---------- Restaurant object begins
function getRestaurantDiv(e)
{
    var element = typeof e.srcElement != "undefined" ? e.srcElement : e.target;
    //debugger;
    while(element != null && typeof element != "undefined" && element.id.toString().indexOf("restaurantDiv",0) == -1)
        element = typeof element.parentElement != "undefined" ? element.parentElement : element.parentNode;;
        
    return element;
}
function restaurantDivOnmouseoverEven(e) {
    //debugger;
    if (!e) e = window.event;
    var restaurantDiv = getRestaurantDiv(e);
    if (restaurantDiv == null || typeof restaurantDiv == "undefined") return;
    if(restaurantDiv.id.toString().indexOf("restaurantDiv",0) == -1) return;
    restaurantDiv.setAttribute('className', 'restaurantMouseOverEven');
    restaurantDiv.setAttribute('class', 'restaurantMouseOverEven');
    (typeof e.cancelBubble != "undefined")?e.cancelBubble = true:e.stopPropagation();
};

function restaurantDivOnmouseoutEven(e) 
{
    if (!e) e = window.event;
    var restaurantDiv   = getRestaurantDiv(e);
    if(restaurantDiv.id.toString().indexOf("restaurantDiv",0) == -1) return;
    restaurantDiv.setAttribute('className', 'restaurantNormalEven');
    restaurantDiv.setAttribute('class', 'restaurantNormalEven');
    (typeof e.cancelBubble != "undefined")?e.cancelBubble = true:e.stopPropagation();
};

function restaurantDivOnmouseoverOdd(e) 
{
    if (!e) e = window.event;
    var restaurantDiv   = getRestaurantDiv(e);
    if(restaurantDiv.id.toString().indexOf("restaurantDiv",0) == -1) return;
    restaurantDiv.setAttribute('className', 'restaurantMouseOverOdd');
    restaurantDiv.setAttribute('class', 'restaurantMouseOverOdd');
    (typeof e.cancelBubble != "undefined")?e.cancelBubble = true:e.stopPropagation();
};

function restaurantDivOnmouseoutOdd(e) 
{
    if (!e) e = window.event;
    var restaurantDiv   = getRestaurantDiv(e);
    if(restaurantDiv.id.toString().indexOf("restaurantDiv",0) == -1) return;
    restaurantDiv.setAttribute('className', 'restaurantNormalOdd');
    restaurantDiv.setAttribute('class', 'restaurantNormalOdd');
    (typeof e.cancelBubble != "undefined")?e.cancelBubble = true:e.stopPropagation();
    
};

// Changes the cursor to an hourglass
function cursor_wait() {
document.body.style.cursor = 'wait';
}

// Returns the cursor to the default pointer
function cursor_clear() {
document.body.style.cursor = 'default';
}

// this Restaurant object holds restaurant data
//function Restaurant(restaurantID, restaurantName, locationID, Address1, Address2, City, State, Zip, Phone, stwebsiteURL, stTimeZoneID, Distance, OpenFrom1, OpenTo1, OpenFrom2, OpenTo2, Cuisines, Rating, Attributes) {
function Restaurant(restaurantID, restaurantName, locationID, Address1, Address2, City, State, Zip, Phone, stwebsiteURL, Distance, Cuisines, Rating, Attributes) {
    //            debugger;
    this._restaurantID = restaurantID;
    this._restaurantName = restaurantName;
    this._locationID = locationID;
    this._address1 = Address1;
    this._address2 = Address2;
    this._city = City;
    this._state = State;
    this._phone = Phone;
    this._zip = Zip;
    this._distance = parseFloat(Distance);
    //this._openFrom1 = OpenFrom1;
    //this._openTo1 = OpenTo1;
    //this._openFrom2 = OpenFrom2;
    //this._openTo2 = OpenTo2;
    this._cuisines = Cuisines;
    this._totalRating = Rating.split("|")[0];
    this._avgRating = Rating.split("|")[1];
    this._Rating = Rating;
    this._attributes = Attributes;
    //attributes = PriceRange Online HasMenu DoesDelivery Rating OpenLate WifiAvailable Alcohol_Served Reservation_Preferred BYOB OutDoor_Seating WheelChair_Accessible Glutten_Free_Menu Kid_Friendly hasCoupon romantic
    
    this._priceRange = parseInt(Attributes.substring(0, 1));
    this._Online = parseInt(Attributes.substring(1, 2));
    this._HasMenu = parseInt(Attributes.substring(2, 3));
    this._DoesDelivery = parseInt(Attributes.substring(3, 4));
    //this._Rating = parseInt(Attributes.substring(4,5));
    //this._OpenLate = parseInt(Attributes.substring(4, 5));
    this._WifiAvailable = parseInt(Attributes.substring(4, 5));
    this._Alcohol_Served = parseInt(Attributes.substring(5, 6));
    //this._Reservation_Preferred = parseInt(Attributes.substring(6, 7));
    this._BYOB = parseInt(Attributes.substring(6, 7));
    this._OutDoor_Seating = parseInt(Attributes.substring(7, 8));
    this._WheelChair_Accessible = parseInt(Attributes.substring(8, 9));
    this._Glutten_Free_Menu = parseInt(Attributes.substring(9, 10));
    this._Kid_Friendly = parseInt(Attributes.substring(10, 11)); //Attributes[13]
    this._hasCoupons = parseInt(Attributes.substring(11, 12));
    this._romantic = parseInt(Attributes.substring(12, 13));
    this._HasGC = parseInt(Attributes.substring(13, 14));
    //--------
    this._FilteredByCuisine = 'N'; //N for not filtered- by default; T for filterd and returned TRUE; F for filtered and returned FALSE
    this._FilteredByFeature = 'N'; //N for not filtered- by default; T for filterd and returned TRUE; F for filtered and returned FALSE
    this._InsideRadius      = true;
    //--------
    this._toshow = true;

    this.createRestaurantDiv = function(rowNum) {
        var isEven = false;
        if (rowNum % 2 == 0) isEven = true;
        //debugger;
        var restaurantDiv = document.createElement('div');
        restaurantDiv.setAttribute("id", "restaurantDiv" + rowNum);
        if (isEven == true) {
            restaurantDiv.setAttribute("class", "restaurantNormalEven");
            restaurantDiv.setAttribute("className", "restaurantNormalEven");
            restaurantDiv.setAttribute("onmouseover", "restaurantDivOnmouseoverEven(event);");
            restaurantDiv.setAttribute("onmouseout", "restaurantDivOnmouseoutEven(event);");
            if (BrowserDetect.browser == "Explorer" && (BrowserDetect.version == "7" || BrowserDetect.version == "6")) {
                restaurantDiv.onmouseover = function() { restaurantDivOnmouseoverEven(event) };
                restaurantDiv.onmouseout = function() { restaurantDivOnmouseoutEven(event) };
            }
        }
        else {
            restaurantDiv.setAttribute("class", "restaurantNormalOdd");
            restaurantDiv.setAttribute("className", "restaurantNormalOdd");
            restaurantDiv.setAttribute("onmouseover", "restaurantDivOnmouseoverOdd(event);");
            restaurantDiv.setAttribute("onmouseout", "restaurantDivOnmouseoutOdd(event);");
            if (BrowserDetect.browser == "Explorer" && (BrowserDetect.version == "7" || BrowserDetect.version == "6")) {
                restaurantDiv.onmouseover = function() { restaurantDivOnmouseoverOdd(event) };
                restaurantDiv.onmouseout = function() { restaurantDivOnmouseoutOdd(event) };
            }
        }
        //restaurantDiv.innerHTML = "testin createRestaurantDiv_Even";

        var restaurantTable = document.createElement('table');
        var restaurantTableTbody = document.createElement('tbody');

        restaurantTableTbody.setAttribute("id", "restaurantTable" + rowNum);
        restaurantTableTbody.setAttribute("width", "100%");
        restaurantTableTbody.setAttribute("border", "0px");

        var tr = document.createElement('tr');

        //left side TD starts here------------------------------------------------------


        //left side TD for restaurant name, price, distance, address, ONLINE ORDER etc
        var left_TD = document.createElement('td');
        left_TD.setAttribute("id", "left_TD");
        left_TD.setAttribute("width", "325px");
        //;
        //
        var leftTable = document.createElement('table');
        var leftTableTbody = document.createElement('tbody');

        leftTableTbody.setAttribute("id", "leftTable");
        leftTableTbody.setAttribute("width", "100%");
        leftTableTbody.setAttribute("border", "0px");


        //first row for restaurant name, price, distance
        var leftTable_TR1 = document.createElement('tr');
        var leftTable_TR1_TD1 = document.createElement('td');
        leftTable_TR1_TD1.setAttribute("colspan", "2");
        var alinkRestaurantName = document.createElement("a"); ///restaurant Name here
        //alinkRestaurantName.setAttribute("href","http://www.menumama.com");
        var stRest = "restID=" + this._restaurantID + "&locID=" + this._locationID;
        alinkRestaurantName.onclick = function() {
            //;
            var stURL = document.location.href;
            var pos = stURL.indexOf("SearchResults.aspx");
            stURL = stURL.substring(0, pos);
            this.href = stURL + "RestuarantInfo.aspx?" + stRest;

        };
        alinkRestaurantName.setAttribute("class", "restaurantName");
        alinkRestaurantName.setAttribute("className", "restaurantName");
        var atextRestaurantName = document.createTextNode(this._restaurantName);
        alinkRestaurantName.appendChild(atextRestaurantName);
        var labelPrice = document.createElement('label'); //restaurant Price here
        labelPrice.setAttribute("class", "restaurentPrice");
        labelPrice.setAttribute("className", "restaurentPrice");
        //labelPrice.innerHTML="($$)";
        var stPriceRange = "  ";

        switch (this._priceRange) {
            case 1: stPriceRange = ' ($) '; break; case 2: stPriceRange = " ($$) "; break; case 3: stPriceRange = " ($$$) "; break; case 4: stPriceRange = " ($$$$) "; break; case 5: stPriceRange = " ($$$$$) "; break;
        }

        labelPrice.innerHTML = stPriceRange;
        var labelDistance = document.createElement('label'); //restaurant Price here
        labelDistance.setAttribute("class", "restaurentNormalText");
        labelDistance.setAttribute("className", "restaurentNormalText");
        //labelDistance.innerHTML="100 miles away";
        if (this._distance != null && this._distance.toString() > 0)
            labelDistance.innerHTML = "&nbsp;" + this._distance + " miles away";

        leftTable_TR1_TD1.appendChild(alinkRestaurantName);
        leftTable_TR1_TD1.appendChild(labelPrice);
        leftTable_TR1_TD1.appendChild(labelDistance);
        leftTable_TR1.appendChild(leftTable_TR1_TD1);
        leftTableTbody.appendChild(leftTable_TR1);


        //second row for restaurant address
        var leftTable_TR2 = document.createElement('tr');
        var leftTable_TR2_TD1 = document.createElement('td');
        leftTable_TR2_TD1.setAttribute("colspan", "2");
        leftTable_TR2_TD1.setAttribute("class", "restaurentNormalText");
        leftTable_TR2_TD1.setAttribute("className", "restaurentNormalText");
        //leftTable_TR2_TD1.innerHTML = "123 main st, easton, pa"; // address here
        var stAddress = this._address1;
        if (this._address2 != null && typeof (this._address2) != 'undefined' && this._address2.length > 1) stAddress = stAddress + ', ' + this._address2;
        if (this._city != null && typeof (this._city) != 'undefined' && this._city.length > 1) stAddress = stAddress + ', ' + this._city;
        if (this._state != null && typeof (this._state) != 'undefined' && this._state.length > 1) stAddress = stAddress + ', ' + this._state;
        if (this._zip != null && typeof (this._zip) != 'undefined' && this._zip.length > 1) stAddress = stAddress + ' ' + this._zip;
        if (this._phone != null && typeof (this._phone) != 'undefined' && this._phone.length > 1) stAddress = stAddress + '<div> ' + this._phone + '</div>';
        leftTable_TR2_TD1.innerHTML = stAddress;
        leftTable_TR2.appendChild(leftTable_TR2_TD1);
        leftTableTbody.appendChild(leftTable_TR2);


        /* temporary blocked
        
        //third row for closing time and ONLINE ORDER
        var leftTable_TR3 = document.createElement('tr');
        var leftTable_TR3_TD1 = document.createElement('td');
        leftTable_TR3_TD1.setAttribute("colspan", "1");
        leftTable_TR3_TD1.setAttribute("class", "restaurentClosing");
        leftTable_TR3_TD1.setAttribute("className", "restaurentClosing");
        leftTable_TR3_TD1.innerHTML = "(Closing in 31 Minutes)"; // closing time here
        //leftTable_TR3.appendChild(leftTable_TR3_TD1);
        var leftTable_TR3_TD2 = document.createElement('td');
        leftTable_TR3_TD2.setAttribute("colspan", "1");
        leftTable_TR3_TD2.setAttribute("class", "restaurentOrderOnline");
        leftTable_TR3_TD2.setAttribute("className", "restaurentOrderOnline");
        var alinkOrderOnline = document.createElement("a");
        alinkOrderOnline.setAttribute("href", "http://www.menumama.com");
        var atextOrderOnline = document.createTextNode("order online"); // order online here
        alinkOrderOnline.appendChild(atextOrderOnline);
        leftTable_TR3_TD2.appendChild(alinkOrderOnline);
        //leftTable_TR3.appendChild(leftTable_TR3_TD2);
        leftTableTbody.appendChild(leftTable_TR3);
        
        */

        //
        leftTable.appendChild(leftTableTbody);
        left_TD.appendChild(leftTable);
        tr.appendChild(left_TD);
        //left side TD ends here------------------------------------------------------


        /*
        <td id="longBar1" class="longDivider"></td>
        */

        var longBar1 = document.createElement('td');
        //longBar1.setAttribute("id", "longBar1");
        longBar1.setAttribute("class", "longDivider");
        longBar1.setAttribute("className", "longDivider");
        tr.appendChild(longBar1);

        //middle TD starts here------------------------------------------------------
        /*
        <td id="middle_TD" style="width:100px">
        <table id="middleTable" width="100%" border="0px">
        <tr id="middleTable_TR1" >
        </tr>
        <tr id="middleTable_TR2" >
        <td id="menuTD" style="width:32%"><img alt="see menu" src="img/menu_logo.png" /><div>menu</div></td>
        <td id="dividerTD1" class="shortDivider"></td>
        <td id="savingTD" style="width:32%"><img alt="savings" src="img/savings_logo.png" /><div>savings</div></td>
        <td id="dividerTD2" class="shortDivider"></td>
        <td id="deliveryTD" style="width:32%"><img alt="delivery" src="img/delivery_logo.png" /><div>delivery</div></td>
        </tr>
        <tr id="middleTable_TR3" >
        </tr>
        </table>
        </td>
        */

        //middle TD for restaurant menu, savings and delivery
        var middle_TD = document.createElement('td');
        middle_TD.setAttribute("id", "middle_TD");
        middle_TD.setAttribute("width", "160px");
        //   

        //
        var middleTable = document.createElement('table');
        var middleTableTbody = document.createElement('tbody');

        middleTableTbody.setAttribute("id", "middleTable");
        middleTableTbody.setAttribute("width", "100%");
        middleTableTbody.setAttribute("border", "0px");
        var middleTable_TR1 = document.createElement('tr');
        var middleTable_TR2 = document.createElement('tr');
        var middleTable_TR3 = document.createElement('tr');
        //

        var menuTD = document.createElement('td'); //menu logo section
        menuTD.setAttribute("width", "40px");
        if (this._HasMenu) 
        {
            var imgMenu = document.createElement('img');
            imgMenu.setAttribute("alt", "see menu");

            if (isEven == true)
                imgMenu.setAttribute("src", "img/menu_icon_gray.png");
            else
                imgMenu.setAttribute("src", "img/menu_icon.png");

            menuTD.appendChild(imgMenu);

            //var divMenu = document.createElement('div');
            //divMenu.innerHTML = "menu";
            //menuTD.appendChild(divMenu);
        }
        middleTable_TR2.appendChild(menuTD);

//        var dividerTD1 = document.createElement('td');
//        dividerTD1.setAttribute("class", "shortDivider");
//        dividerTD1.setAttribute("className", "shortDivider");
//        middleTable_TR2.appendChild(dividerTD1);

//        var savingTD = document.createElement('td'); //savings logo section
//        savingTD.setAttribute("width", "40px");
//        if (this._Has_Coupons) {
//            var imgSaving = document.createElement('img');
//            imgSaving.setAttribute("alt", "saving");
//            if (isEven == true)
//                imgSaving.setAttribute("src", "img/savings_logo_gray.png");
//            else
//                imgSaving.setAttribute("src", "img/savings_logo.png");
//            savingTD.appendChild(imgSaving);
//            var divSaving = document.createElement('div');
//            divSaving.innerHTML = "saving";
//            savingTD.appendChild(divSaving);
//        }
//        middleTable_TR2.appendChild(savingTD);

        var dealsTD = document.createElement('td'); //savings logo section
        dealsTD.setAttribute("width", "40px");
        if (this._HasGC) 
        {
            var imgDeals = document.createElement('img');
            imgDeals.setAttribute("alt", "Deals");
            if (isEven == true)
                imgDeals.setAttribute("src", "img/deals_icon_gray.png");
            else
                imgDeals.setAttribute("src", "img/deals_icon.png");
            dealsTD.appendChild(imgDeals);
//            var divSaving = document.createElement('div');
//            divSaving.innerHTML = "saving";
//            savingTD.appendChild(divSaving);
        }
        middleTable_TR2.appendChild(dealsTD);

//        var dividerTD2 = document.createElement('td');
//        dividerTD2.setAttribute("class", "shortDivider");
//        dividerTD2.setAttribute("className", "shortDivider");
//        middleTable_TR2.appendChild(dividerTD2);
//        /**/

        var deliveryTD = document.createElement('td'); //delivery logo section
        deliveryTD.setAttribute("style", "width:33%");
        if (this._DoesDelivery) {
            var imgDelivery = document.createElement('img');
            imgDelivery.setAttribute("alt", "delivery");
            if (isEven == true)
                imgDelivery.setAttribute("src", "img/delivery_icon_gray.png");
            else
                imgDelivery.setAttribute("src", "img/delivery_icon.png");
            deliveryTD.appendChild(imgDelivery);
            //var divDelivery = document.createElement('div');
            //divDelivery.innerHTML = "delivery";
            //deliveryTD.appendChild(divDelivery);
        }
        middleTable_TR2.appendChild(deliveryTD);

        //middleTable.appendChild(middleTable_TR1);
        middleTableTbody.appendChild(middleTable_TR2);
        //middleTableTbody.appendChild(middleTable_TR3);

        middleTable.appendChild(middleTableTbody);
        middle_TD.appendChild(middleTable);
        tr.appendChild(middle_TD);

        //middle TD ends here------------------------------------------------------


        /*
        <td id="longBar1" class="longDivider"></td>
        */

        var longBar2 = document.createElement('td');
        //longBar2.setAttribute("id", "longBar2");
        longBar2.setAttribute("class", "longDivider");
        longBar2.setAttribute("className", "longDivider");
        tr.appendChild(longBar2);

        //right side TD 'Rating' starts here------------------------------------------------------
        var right_TD = document.createElement('td');
        right_TD.setAttribute("id", "right_TD");
        right_TD.setAttribute("width", "90px");
        //debugger;
        //var rightTable = this.CreateRatings(this._Rating);
        var rightTable = createRatingStars(parseInt(this._totalRating), parseFloat(this._avgRating), this._restaurantID, this._locationID);
        //var rightTable = createRatingStars(3, 2.5, this._restaurantID, this._locationID);


        right_TD.appendChild(rightTable);
        tr.appendChild(right_TD);
        //right side TD ends here------------------------------------------------------

        restaurantTableTbody.appendChild(tr);
        restaurantTable.appendChild(restaurantTableTbody);
        restaurantDiv.appendChild(restaurantTable);
        //
        var divRestaurantList = document.getElementById("divRestaurantList");
        divRestaurantList.appendChild(restaurantDiv);

    }
    this.GetDistance = function() {
        return this._distance;
    }
    this.GetPriceRange = function() {
        //if(typeof(this._priceRange)!="undefined" || this._priceRange<=0)
        return this._priceRange;
    }
    this.GetToShow = function() {
        return this._toshow;
    }
    this.SetToShow = function(value) {
        this._toshow = value;
    }
    this.GetCuisines = function() {
        return this._cuisines;
    }
    this.GetFilteredByCuisine = function() {
        return this._FilteredByCuisine;
    }
    this.SetFilteredByCuisine = function(value) {
        this._FilteredByCuisine = value;
    }
    this.GetFilteredByFeature = function() {
        return this._FilteredByFeature;
    }
    this.SetFilteredByFeature = function(value) {
        this._FilteredByFeature = value;
    }
    //---------attributes
    this.GetOnline = function() {
        return this._Online;
    }
    this.GetHasMenu = function() {
        return this._HasMenu;
    }
    this.GetDoesDelivery = function() {
        return this._DoesDelivery;
    }
    this.GetTotalRating = function() {
        return this._totalRating;
    }
    this.GetAvgRating = function() {
        return this._avgRating;
    }
//    this.GetOpenLate = function() {
//        return this._OpenLate;
//    }
    this.GetWifiAvailable = function() {
        return this._WifiAvailable;
    }
    this.GetAlcohol_Served = function() {
        return this._Alcohol_Served;
    }
//    this.GetReservation_Preferred = function() {
//        return this._Reservation_Preferred;
//    }
    this.GetBYOB = function() {
        return this._BYOB;
    }
    this.GetOutDoor_Seating = function() {
        return this._OutDoor_Seating;
    }
    this.GetWheelChair_Accessible = function() {
        return this._WheelChair_Accessible;
    }
    this.GetGlutten_Free_Menu = function() {
        return this._Glutten_Free_Menu;
    }
    this.GetKid_Friendly = function() {
        return this._Kid_Friendly;
    }
    this.GetHas_Coupons = function() {
        return this._Has_Coupons;
    }
    this.GetRomantic = function() {
        return this._romantic;
    }
    this.GetInsideRadius = function(){
        return this._InsideRadius;
    }
    this.SetInsideRadius = function(value)
    {
        this._InsideRadius = value;
    }
}

function sortRestaurantsByDistance() {
    document.getElementById('hdSortBy').value = 'DISTANCE';
    ShowSortedRestaurants();
    }
function sortRestaurantsByName() {
    document.getElementById('hdSortBy').value = 'RESTAURANTNAME';
    ShowSortedRestaurants();
    
}

function sortRestaurantsByPrice() {
    document.getElementById('hdSortBy').value = 'PRICE_RANGE';
    ShowSortedRestaurants();

}

function sortRestaurantsByRating() {
    document.getElementById('hdSortBy').value = 'AVG_RATING';
    ShowSortedRestaurants();
}

function ShowSortedRestaurants()
{
    document.getElementById('hdPageNumber').value = "1";
    
    if(document.getElementById('hdSortOrientation').value == "")
        document.getElementById('hdSortOrientation').value = "DESC"
    else if(document.getElementById('hdSortOrientation').value == "ASC")
        document.getElementById('hdSortOrientation').value = "DESC"
    else if(document.getElementById('hdSortOrientation').value == "DESC")
        document.getElementById('hdSortOrientation').value = "ASC"
    
    LoadSearchPageCenter();
}

function showRestaurants(from, to)
{
    clearRestaurantsDiv();

    for (i = from; i <= to; i++) {
        if (arrRestaurants[i] == null || typeof (arrRestaurants[i]) == "undefined" || arrRestaurants[i].GetToShow() == false)
            continue;
        arrRestaurants[i].createRestaurantDiv(i);
    }
    hidemaskpanel();
    SaveSnapshot();
}

function SaveSnapshot()
{
    var snapShot = "";
    snapShot += "hdRowsPerPage:"+document.getElementById("hdRowsPerPage").value;
    snapShot += "¦hdPagesPerGroup:"+document.getElementById("hdPagesPerGroup").value;
    snapShot += "¦hdcachedTableName:"+document.getElementById("hdcachedTableName").value;
    snapShot += "¦hdRadius:"+document.getElementById("hdRadius").value;
    snapShot += "¦hdRestaurantNameToSearch:"+document.getElementById("hdRestaurantNameToSearch").value;
    snapShot += "¦hdCityToSearch:"+document.getElementById("hdCityToSearch").value;
    snapShot += "¦hdStateToSearch:"+document.getElementById("hdStateToSearch").value;
    snapShot += "¦hdSortOrientation:"+document.getElementById('hdSortOrientation').value;
    snapShot += "¦hdSortBy:"+document.getElementById('hdSortBy').value;
    snapShot += "¦hdPageNumber:"+document.getElementById('hdPageNumber').value;
    snapShot += "¦hdFeatureFilters:"+ document.getElementById('hdFeatureFilters').value;
    snapShot += "¦hdCuisineFilters:"+ document.getElementById('hdCuisineFilters').value;
    snapShot += "¦hdStartingPageNbr:"+document.getElementById('hdStartingPageNbr').value;
    snapShot += "¦hdPageCount:"+ document.getElementById('hdPageCount').value;
    snapShot += "¦hdRestaurantCount:"+document.getElementById('hdRestaurantCount').value;
    
    var expDate = new Date(); 
    expDate.setMinutes(expDate.getMinutes() + 20);
    CookieUtil.unset("SEARCH_PAGE_SNAPSHOT"); 
    CookieUtil.set("SEARCH_PAGE_SNAPSHOT", snapShot , expDate);
    
}

function LoadSnapshot()
{
    var snapShot = CookieUtil.get("SEARCH_PAGE_SNAPSHOT");
    if( snapShot == null || typeof snapShot == "undefined") return false;
    var controlValues = snapShot.split('¦');
    if(controlValues.length == 0 ) return false;
    for( i=0; i< controlValues.length; i++)
    {
        document.getElementById(controlValues[i].split(":")[0]).value = controlValues[i].split(":")[1];
    }
    return true;
}

function SetSelectedRadius()
{
    var hdRadius = document.getElementById("hdRadius").value;
    var rdDistance = document.getElementById("rdDistance"+hdRadius.split(".")[0]);
    if( rdDistance != null && typeof rdDistance != "undefined")
        rdDistance.checked="checked";
}

function clearRestaurantsDiv() {
    var divRestaurantList = document.getElementById('divRestaurantList');
    if (divRestaurantList != null && typeof (divRestaurantList) != "undefined")
        divRestaurantList.innerHTML = "";
}
//---------- Restaurant object ends


//---------- Page Indicator object Begins
function pageIndicator(pageNumber) {
    this._pageNumber = pageNumber;
    //this._from = from;
    //this._to = to;
    this._tooltip = "Page " + pageNumber.toString();
    this._currentFocus = false;

    this.Create = function() {
        var _pageDiv = document.createElement("a");
        if(this._pageNumber == "prev" ) _pageDiv.innerHTML = "&lt;&lt;Prev";
        else if(this._pageNumber == "more") _pageDiv.innerHTML = "More&gt;&gt;";
        else _pageDiv.innerHTML = this._pageNumber.toString();
        _pageDiv.value = this._pageNumber.toString();
        _pageDiv.setAttribute("id", "page" + this._pageNumber.toString());
        _pageDiv.setAttribute("pageNumber", this._pageNumber.toString());
        {
            _pageDiv.setAttribute("class", "divPageBlur");
            _pageDiv.setAttribute("className", "divPageBlur");
        }
        _pageDiv.setAttribute("align", "center");
        _pageDiv.setAttribute("tabindex", this._pageNumber.toString());
        
        _pageDiv.setAttribute("onclick","on_divPageClick(event)");
        
        _pageDiv.setAttribute("onmouseover","on_divPageMouseOver(event)");
        
        _pageDiv.setAttribute("onmouseout","on_divPageMouseOut(event)");
        
        return _pageDiv;

    }

}

function on_divPageClick(event) 
{
    //debugger;
    if(event == null || typeof event == "undefined") event = window.event;
    
    var divPage             = typeof event.srcElement != "undefined"? event.srcElement : event.target;
    var pageNumber          = divPage.getAttribute("pageNumber");
    var pagesPerGroup       = parseInt(document.getElementById("hdPagesPerGroup").value);
    var hdStartingPageNbr   = parseInt(document.getElementById('hdStartingPageNbr').value);
    if(pageNumber == "prev" )
    {
        hdStartingPageNbr -= pagesPerGroup;
        if(hdStartingPageNbr <1) hdStartingPageNbr = 1;
        document.getElementById('hdStartingPageNbr').value = hdStartingPageNbr;
        document.getElementById('hdPageNumber').value = hdStartingPageNbr+pagesPerGroup-1;
        createPageIndicators(hdStartingPageNbr);
        showPageIndicators();
    }
    else if(pageNumber == "more")
    {
        var pageCount = parseInt(document.getElementById('hdPageCount').value);
        hdStartingPageNbr += pagesPerGroup;
        if(hdStartingPageNbr >pageCount) hdStartingPageNbr = pageCount;
        document.getElementById('hdStartingPageNbr').value = hdStartingPageNbr;
        document.getElementById('hdPageNumber').value = hdStartingPageNbr;
        createPageIndicators(hdStartingPageNbr);
        showPageIndicators();
    }
    else
    {
        document.getElementById('hdPageNumber').value = pageNumber;
        setCurrentPage();
    }
    LoadSearchPageCenter();    
    
    return false;
    
}

function on_divPageMouseOver(event) {
    if(event == null || typeof event == "undefined") event = window.event;
    var divPage = typeof event.srcElement != "undefined"? event.srcElement : event.target;
    ReplaceClass(divPage, "divPageBlur", "divPageFocus");
}

function on_divPageMouseOut(event) {
    if(event == null || typeof event == "undefined") event = window.event;
    var divPage = typeof event.srcElement != "undefined"? event.srcElement : event.target;
    ReplaceClass(divPage, "divPageFocus", "divPageBlur");
}

function setPageCounts(msg)
{
    var _pageCnt        = parseInt(msg.split("|")[0]);
    var _restaurantCnt  = parseInt(msg.split("|")[1]);
    document.getElementById('hdPageCount').value = _pageCnt;
    document.getElementById('hdRestaurantCount').value = _restaurantCnt;
    var lblTotalRestaurants = document.getElementById('lblTotalRestaurants');
    lblTotalRestaurants.innerHTML = "We have [<label style='font-size:20px; font-weight:bold; color:Red'>&nbsp;" + _restaurantCnt + "&nbsp;</label>] restaurants that fit your criteria";
    
    createPageIndicators(1);
}

function createPageIndicators(from) {
    var _arrPos         = 0 ;
    var pagesPerGroup   = parseInt(document.getElementById("hdPagesPerGroup").value);
    var _pageCnt = parseInt(document.getElementById('hdPageCount').value);
    if (arrPageIndicators.length > 0)
        Array.clear(arrPageIndicators);
        
     if( (from) >1)
        arrPageIndicators[_arrPos++] = new pageIndicator("prev");
     for(var i=0; i<pagesPerGroup && (from+i) <=_pageCnt ;i++)
     {
         arrPageIndicators[_arrPos++] = new pageIndicator(from + i);
     }
    
     if( (from+pagesPerGroup) < _pageCnt)
         arrPageIndicators[_arrPos] = new pageIndicator("more");
    

}

function showPageIndicators() {
    var newTable = document.createElement("table");
    newTable.setAttribute("id", "pageIndicatorTable");
    //newTable.setAttribute("border", "1");
    var newTableBody = document.createElement("tbody");
    var newRow = document.createElement("tr");

    if (arrPageIndicators.length > 1) {
        for (i in arrPageIndicators) {
            if (arrPageIndicators == null || typeof (arrPageIndicators[i]) == "undefined") break;
            var newCol = document.createElement("td");
            newCol.appendChild(arrPageIndicators[i].Create());
            newRow.appendChild(newCol);
        }
    }
    
    newTableBody.appendChild(newRow);
    newTable.appendChild(newTableBody);
    
    var divPageIndicators = document.getElementById("divPageIndicators");
    if (divPageIndicators != null && typeof (divPageIndicators) != "undefined") {
        //divPageIndicators.removeChild(divPageIndicators.lastChild);
        divPageIndicators.innerHTML = "";
        divPageIndicators.appendChild(newTable);
    }
	setCurrentPage();
}

function setCurrentPage()
{
	var hdPageNumber = document.getElementById('hdPageNumber').value;
	var pageIndicatorTable = document.getElementById('pageIndicatorTable');

    //debugger;	
	var oldFocus = getChildByClassName(pageIndicatorTable, 'a', 'divPageCurrent');
	if(oldFocus != null && typeof oldFocus != "undefined")
	{
	    oldFocus.setAttribute("class", "divPageBlur");
        oldFocus.setAttribute("className", "divPageBlur");
	}
	var currentFocus = getChildByID(pageIndicatorTable, 'a', 'page'+hdPageNumber);
	if(currentFocus != null && typeof currentFocus != "undefined")
	{
	    AppendClass( currentFocus, "divPageCurrent");
    }
	
	
}
//---------- Page Indicator object Ends

//---------- left side check boxes begins
var CheckBoxClass = function(value, attributeType, text, checked, count) {
    this._checked = false;
    this._checked = checked;
    this._text = text;
    this._count = 0;
    this._count = count;
    this._value = 0;
    this._value = value;
    //this._toShow = true;
    this._attributeType = attributeType; //cuisine or features or price


    this.Create = function() {
        //if (this._toShow == false) return null;

        var mCheckBox = document.createElement('input');
        mCheckBox.type = "checkbox";
        mCheckBox.value = this._text;
        mCheckBox.id = this._attributeType +'|'+ this._value;
        //mCheckBox.checked = this._checked;
        mCheckBox.className = this._attributeType;
        //debugger;
        mCheckBox.setAttribute("onclick","filterRestaurantsByCheckBox(event)");
        if (BrowserDetect.browser == "Explorer" && (BrowserDetect.version == "7" || BrowserDetect.version == "6")) {
                mCheckBox.onclick = function() { filterRestaurantsByCheckBox(event); };
            }
        mCheckBox.setAttribute("attributeType", attributeType);

        var mText = document.createTextNode(' ' + this._text);
        var mfontTxt = document.createElement("font");
        mfontTxt.setAttribute("class", "checkClass");
        mfontTxt.setAttribute("className", "checkClass");
        mfontTxt.appendChild(mText);
        //debugger;
        if( typeof this._count != "undefined" && this._count != null && this._count != "")
        {
            var mCountText = document.createTextNode(' (' + this._count + ')');
            var mfont = document.createElement("font");
            mfont.setAttribute("class", "countClass");
            mfont.setAttribute("className", "countClass");
            mfont.appendChild(mCountText);
        }
        var mBr = document.createElement("br");
        var mDiv = document.createElement('div');

        mDiv.appendChild(mCheckBox);
        mDiv.appendChild(mText);
        mDiv.appendChild(mfontTxt);
        if( typeof mfont != "undefined" && mfont )
            mDiv.appendChild(mfont);
        mDiv.appendChild(mBr);

        return mDiv;
    }

    /* this.GetToShow = function() {
        return this._toShow;
    } */
    this.GetAttributeType = function() {
        return this._attributeType;
    }
    this.CompareAttributeType = function(att) {
        if (this._attributeType.toLowerCase() == att.toLowerCase())
            return true;
        return false;
    }
}


/* function showCheckBoxes() {
    //-----show cuisine check boxes
    var divCuisineCheckBoxes = document.getElementById('divCuisineCheckBoxes');
    if (divCuisineCheckBoxes != null && typeof (divCuisineCheckBoxes) != 'undefined') {
        divCuisineCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("cuisine") == true)
                divCuisineCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
    }
    //-----show price check boxes
    //;
    var divPriceCheckBoxes = document.getElementById('divPriceCheckBoxes');
    if (divPriceCheckBoxes != null && typeof (divPriceCheckBoxes) != 'undefined') {
        divPriceCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("price") == true)
                divPriceCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
    }
    //-----show feature check boxes
    //;
    var divFeatureCheckBoxes = document.getElementById('divFeatureCheckBoxes');
    if (divFeatureCheckBoxes != null && typeof (divFeatureCheckBoxes) != 'undefined') {
        divFeatureCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("feature") == true)
                divFeatureCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
    }
} */

function showCuisineCheckBoxes() {
    //-----show cuisine check boxes
    var divCuisineCheckBoxes = document.getElementById('divCuisineCheckBoxes');
    if (divCuisineCheckBoxes != null && typeof (divCuisineCheckBoxes) != 'undefined') {
        divCuisineCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("cuisine") == true)
                divCuisineCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
		
		setSelectedCuisineCheckBoxes();
    }
}

function setSelectedCuisineCheckBoxes(){
	var cuisineFilter = document.getElementById('hdCuisineFilters').value;
	if(cuisineFilter.length ==0)return;
	cuisineFilter = cuisineFilter.substring(0, cuisineFilter.length-1);
	var checkedCuisines = cuisineFilter.split("|");
	
	var arrCuisineCheckBoxes = [];
    arrCuisineCheckBoxes = getElementsByClassName('cuisine');
    for (i in arrCuisineCheckBoxes) {
		arrCuisineCheckBoxes[i].checked = false;
		for(j in checkedCuisines)
		{
			if (trim(arrCuisineCheckBoxes[i].id) == "cuisine|"+checkedCuisines[j]) {
				arrCuisineCheckBoxes[i].checked = true;
			}
			
		}
    }
	
}

function showPriceCheckBoxes() {
    //-----show price check boxes
    var divPriceCheckBoxes = document.getElementById('divPriceCheckBoxes');
    if (divPriceCheckBoxes != null && typeof (divPriceCheckBoxes) != 'undefined') {
        divPriceCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("price") == true)
                divPriceCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
    }
}

function showFeatureCheckBoxes() {
    //-----show feature check boxes
    var divFeatureCheckBoxes = document.getElementById('divFeatureCheckBoxes');
    if (divFeatureCheckBoxes != null && typeof (divFeatureCheckBoxes) != 'undefined') {
        divFeatureCheckBoxes.innerHTML = "";
        for (i in checkboxObjArr) {
            if (checkboxObjArr[i].CompareAttributeType("feature") == true)
                divFeatureCheckBoxes.appendChild(checkboxObjArr[i].Create());
        }
		
		setSelectedFeatureCheckBoxes();
    }
}

//function setSelectedFeatureCheckBoxes(){

//	var featureFilter = document.getElementById('hdFeatureFilters').value;
//	var checkedFeatures = featureFilter.split("|");
//	
//	var arrFeatureCheckBoxes = [];
//    arrFeatureCheckBoxes = getElementsByClassName('feature');
//    for (i in arrFeatureCheckBoxes) {
//		arrFeatureCheckBoxes[i].checked = false;
//		for(j in checkedFeatures)
//		{
//			if (arrFeatureCheckBoxes[i].id == "cuisine|"+checkedFeatures[j]) {
//				arrFeatureCheckBoxes[i].checked = true;
//			}
//			
//		}
//    }
//	
//}

function setSelectedFeatureCheckBoxes(){
	var featureFilter = document.getElementById('hdFeatureFilters').value;
	if(featureFilter.length ==0)return;
	featureFilter = featureFilter.replace(/ or /g,"|");
	var checkedFeatures = featureFilter.split("|");
	
	var arrFeatureCheckBoxes = [];
    arrFeatureCheckBoxes = getElementsByClassName('feature');
    for (i in arrFeatureCheckBoxes) {
		arrFeatureCheckBoxes[i].checked = false;
		for(j in checkedFeatures)
		{
			if (trim(arrFeatureCheckBoxes[i].id) == "feature|"+checkedFeatures[j].split("=")[0]) {
				arrFeatureCheckBoxes[i].checked = true;
			}
		}
    }
}

//stClassName is class name of element; cuisine or features or price
//returns a array of objects
function getElementsByClassName(stClassName) {
    body = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + stClassName + '\\b');
    var els = body.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
        if (re.test(els[i].className)) a.push(els[i]);
    return a;
}
//---------- left side check boxes ends

function createCuisineCheckBox(itemNbr, cuisineName, checked, cuisineCount) {
    checkboxObjArr[checkboxObjArr.length] = new CheckBoxClass(itemNbr, 'cuisine', cuisineName, checked, cuisineCount);
}
function createCuisineCheckBoxes(msg) {

    var FeatureID = "";
    var FeatureDescription = "";
    var FeatureCount = "";

    //debugger;
    for (var idx in msg) {
        if (msg[idx].FeatureType != "cuisine") continue;
        FeatureID           = msg[idx].FeatureID;
        FeatureDescription  = msg[idx].FeatureDescription;
        FeatureCount        = msg[idx].FeatureCount;
        createCuisineCheckBox(FeatureID, FeatureDescription, false, FeatureCount);
        
    }

}
//---------- Cuisines Types Check Boxes ends

//---------- Feature Check Boxes begins
var FeaturesAndCountClass = function(Feature, nCount) {
    this._feature = "";
    this._feature = Feature;
    this._restaurantCount = nCount;

    this.CompareFeature = function(Feature) {
        if (this._feature.toLowerCase() == Feature.toLowerCase())
            return 1;
        return 0;
    }
    this.IncreaseRestaurantCount = function(nbr) {
        this._restaurantCount += parseInt(nbr);
    }
    this.GetFeature = function() {
        return this._feature;
    }
    this.GetRestaurantCount = function() {
        return this._restaurantCount;
    }

}
function createFeatureCheckBoxes(msg) {
    //Array.clear(arrFeaturesAndCounts);
    var FeatureID           = "";
    var FeatureDescription  = "";
    var FeatureCount        = "";

    //debugger;
    for (var idx in msg) {
        if (msg[idx].FeatureType != "feature") continue;
        FeatureID           = msg[idx].FeatureID;
        FeatureDescription  = msg[idx].FeatureDescription;
        FeatureCount        = msg[idx].FeatureCount;
        //arrFeaturesAndCounts[Feature] = new FeaturesAndCountClass(Feature, parseInt(FeatureCount));
        //debugger;
        createFeatureCheckBox(FeatureID, FeatureDescription, false, FeatureCount);
    }
}

function createFeatureCheckBox(itemNbr, feature, checked, cnt) {
    checkboxObjArr[checkboxObjArr.length] = new CheckBoxClass(itemNbr, 'feature', feature, checked, cnt);
}
//---------- Feature Check Boxes Ends

//---------- Price Check Boxes Begins

//function createPriceCheckBoxes() {

//    var nRestCount = parseInt(arrRestaurants.length);
//    arrPriceAndCounts[0] = nRestCount;
//    arrPriceAndCounts[1] = 0;
//    arrPriceAndCounts[2] = 0;
//    arrPriceAndCounts[3] = 0;
//    arrPriceAndCounts[4] = 0;
//    var i = 0;
//    for (i = 0; i < nRestCount; i++) {
//        if (arrRestaurants[i].GetToShow() == false) continue; //just calculate restaurantes it will show
//        if (arrRestaurants[i].GetPriceRange() > 0)
//            arrPriceAndCounts[arrRestaurants[i].GetPriceRange()]++;
//    }
//    //;
//    createPriceCheckBox(2000, "All Prices", true, arrPriceAndCounts[0]);
//    createPriceCheckBox(2001, "$", false, arrPriceAndCounts[1]);
//    createPriceCheckBox(2002, "$$", false, arrPriceAndCounts[2]);
//    createPriceCheckBox(2003, "$$$", false, arrPriceAndCounts[3]);
//    createPriceCheckBox(2004, "$$$$", false, arrPriceAndCounts[4]);

//}
//function createPriceCheckBox(itemNbr, cuisineName, checked, cuisineCount) {
//    checkboxObjArr[checkboxObjArr.length] = new CheckBoxClass(itemNbr, 'price', cuisineName, checked, cuisineCount);
//}

function SetIframeURL(stIFrameName, stURL) {
    var iframe = window.frames[stIFrameName];
    if (iframe != null) //IE
        iframe.location.href = stURL;
    else {
        iframe = document.getElementById(stIFrameName);
        iframe.setAttribute("src", stURL);
    }
}
//---------- Price Check Boxes Ends

//---------- Ajax call begins
function OnSearchRestaurantsCompleted(result) {
    hidemaskpanel();
    var CachedTable = document.getElementById('hdcachedTableName').value;
    if (CachedTable == null || CachedTable == 'undefined') return;
    g_rowsPerPage = document.getElementById("hdRowsPerPage").value;
    if (g_rowsPerPage == null || g_rowsPerPage == 'undefined' || parseInt(g_rowsPerPage) == 'NaN') g_rowsPerPage = 25;
    document.getElementById('hdPageNumber').value = 1;
    document.getElementById('hdSortBy').value = 'DISTANCE';
    document.getElementById('hdSortOrientation').value = "";
    document.getElementById('hdFeatureFilters').value = "";
    document.getElementById('hdCuisineFilters').value = "";
    document.getElementById("hdRadius").value = "30";
    var stRestaurantNameToSearch = document.getElementById('hdRestaurantNameToSearch').value;
    
    if (stRestaurantNameToSearch != null && stRestaurantNameToSearch.length > 0)
        LoadSearchPageCenter();
    LoadSearchPageLeft();
    LoadSearchPageIndicators();
}

function LoadRestaurantsFromCache() {
    hidemaskpanel();
    if(!LoadSnapshot()) return false;
    
    LoadSearchPageCenter();
    LoadSearchPageLeft();
    LoadSearchPageIndicatorsFromCache();
    SetSelectedRadius();
    return true;
}

function showFeatureListLoadingMask(){
    var height = document.getElementById('searchPageLeftDiv').offsetHeight;
    //height = parseInt(document.body.clientHeight)-parseInt(height);
    var divFeatureListLoading = document.getElementById('divFeatureListLoading');
    divFeatureListLoading.style.height = height;
    divFeatureListLoading.style.opacity = ".50"; 
    divFeatureListLoading.style.backgroundColor = "#AAA";
    divFeatureListLoading.style.filter = "alpha(opacity=25)";
    divFeatureListLoading.style.display = '';
}

function hideFeatureListLoadingMask(){
    var divFeatureListLoading = document.getElementById('divFeatureListLoading');
    divFeatureListLoading.style.display = 'none';
    
}

function LoadSearchPageLeft() {
    //showFeatureListLoadingMask();
    var CachedTable = document.getElementById('hdcachedTableName').value;
    var Radius = document.getElementById('hdRadius').value;
    if (CachedTable == null || typeof (CachedTable) == "undefined" || CachedTable.length == 0) return;
    SearchPage.RestLocationService.get_searchedFeatures(CachedTable, Radius, OnGetSearchedFeaturesCompleted);
    SearchPage.RestLocationService.get_searchedCuisines(CachedTable, Radius, OnGetSearchedCuisinesCompleted);
    //
    Array.clear(checkboxObjArr);
}

function OnGetSearchedFeaturesCompleted(result) {
    //hideFeatureListLoadingMask();
    //Array.clear(checkboxObjArr);
    createFeatureCheckBoxes(result);
    showFeatureCheckBoxes();
}

function OnGetSearchedCuisinesCompleted(result) {
    //hideFeatureListLoadingMask();
    //Array.clear(checkboxObjArr);
    createCuisineCheckBoxes(result);
    showCuisineCheckBoxes();
}


function LoadSearchPageCenter() {
    showFeatureListLoadingMask();
    var CachedTable = document.getElementById('hdcachedTableName').value;
    var Radius = document.getElementById('hdRadius').value;
    var RowsPerPage = document.getElementById('hdRowsPerPage').value;
    var PageNumber = document.getElementById('hdPageNumber').value;
    var SortBy = document.getElementById('hdSortBy').value;
    var SortOrientation = document.getElementById('hdSortOrientation').value;
    var FeatureFilters = document.getElementById('hdFeatureFilters').value;
    var CuisineFilters = document.getElementById('hdCuisineFilters').value;

    //debugger;
    if(PageNumber == null || typeof PageNumber == "undefined" || PageNumber.length == 0) PageNumber = "1";
    if (CachedTable == null || typeof (CachedTable) == "undefined" || CachedTable.length == 0) return;
    Array.clear(arrRestaurants);
    
    SearchPage.RestLocationService.get_SearchedRestaurants(CachedTable, Radius, RowsPerPage, PageNumber, SortBy, SortOrientation, FeatureFilters, CuisineFilters, OnGetSearchedRestaurantsCompleted);
    var imgRestaurantListLoading = document.getElementById('imgRestaurantListLoading');
    if(imgRestaurantListLoading != null && typeof imgRestaurantListLoading != 'undefined')
        imgRestaurantListLoading.style.display = '';
    else
    {
        var divRestaurantList = document.getElementById('divRestaurantList');
        divRestaurantList.innerHTML = '<img id="imgRestaurantListLoading" src="img/loading6.gif" alt="loading..."  style="left:220px; top:60px; position:relative; float:left "/>';
    }
}

function OnGetSearchedRestaurantsCompleted(result) {

    g_rowsPerPage = document.getElementById("hdRowsPerPage").value;
    if (g_rowsPerPage == null || g_rowsPerPage == 'undefined' || parseInt(g_rowsPerPage) == 'NaN') g_rowsPerPage = 25;
    
    hideFeatureListLoadingMask();
    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.text = result + "groupRestaurantsAndShow();";

    headID.appendChild(newScript);
}


function LoadSearchPageIndicators() {
    var CachedTable = document.getElementById('hdcachedTableName').value;
    var RowsPerPage = document.getElementById('hdRowsPerPage').value;
    var Radius = document.getElementById('hdRadius').value;
    if (CachedTable == null || typeof (CachedTable) == "undefined" || CachedTable.length == 0) return;
    Array.clear(arrPageIndicators);
    var FeatureFilters = document.getElementById('hdFeatureFilters').value;
    var CuisineFilters = document.getElementById('hdCuisineFilters').value;
    SearchPage.RestLocationService.get_searchedCount(CachedTable, Radius, RowsPerPage, FeatureFilters, CuisineFilters, OnGetSearchedPageCountCompleted);
}

function LoadSearchPageIndicatorsFromCache()
{
    var _restaurantCnt = document.getElementById('hdRestaurantCount').value;
    var lblTotalRestaurants = document.getElementById('lblTotalRestaurants');
    lblTotalRestaurants.innerHTML = "We have [<label style='font-size:20px; font-weight:bold; color:Red'>&nbsp;" + _restaurantCnt + "&nbsp;</label>] restaurants that fit your criteria";
	var hdStartingPageNbr   = parseInt(document.getElementById('hdStartingPageNbr').value);
	
	if(hdStartingPageNbr <1) hdStartingPageNbr = 1;
    createPageIndicators(hdStartingPageNbr);
    showPageIndicators();
}

function OnGetSearchedPageCountCompleted(result) {
    if(typeof result == 'undefined' || result == null) return;
    document.getElementById('hdStartingPageNbr').value = 1;;
    setPageCounts(result);
    showPageIndicators();
}

function ajaxOnTimeOut(result) {
    document.getElementById('lblSearchError').innerHTML = 'Time Out';
    hidemaskpanel();
}
function ajaxOnError(result) {

    document.getElementById('lblSearchError').innerHTML = 'Error: ' + result._message;
    hidemaskpanel();
}
//---------- Ajax call ends


function filterRestaurantsByDistance(ev) {

    if (document.getElementById('rdDistance5').checked == true) document.getElementById("hdRadius").value = "5.00"
    else if (document.getElementById('rdDistance10').checked == true) document.getElementById("hdRadius").value = "10.00"
    else if (document.getElementById('rdDistance15').checked == true) document.getElementById("hdRadius").value = "15.00"
    else if (document.getElementById('rdDistance30').checked == true) document.getElementById("hdRadius").value = "30.00"
    else document.getElementById("hdRadius").value = "30.00";

    document.getElementById('hdPageNumber').value = "1";
    document.getElementById("hdCuisineFilters").value = "";
    document.getElementById("hdFeatureFilters").value = "";
    
    LoadSearchPageCenter();
    LoadSearchPageLeft();
    LoadSearchPageIndicators();

}

//---------- filter by cuisines Begins

function filterRestaurantsByCuisineTypes() {
    var arrCuisineCheckBoxes = [];
    //var bNoCuisineChecked = true;
    var cuisineFilter        = "";
    arrCuisineCheckBoxes = getElementsByClassName('cuisine');
    for (i in arrCuisineCheckBoxes) {
        if (arrCuisineCheckBoxes[i].checked == true) {
            cuisineFilter += trim(arrCuisineCheckBoxes[i].id.split("|")[1]) +"|";
        }
    }
    //debugger;
    //document.getElementById('hdPageNumber').value = "1";
    document.getElementById("hdCuisineFilters").value = cuisineFilter;

}
//---------- filter by cuisines Ends

//---------- filter by Features Begins
function filterRestaurantsByFeatures() {
    var arrFeatureCheckBoxes = [];
    //var bNoFeatureChecked = true;
    var featureFilter        = "";

    arrFeatureCheckBoxes = getElementsByClassName('feature');
    for (i in arrFeatureCheckBoxes) {
        if (arrFeatureCheckBoxes[i].checked == true) {
            //bNoFeatureChecked = false;
            if( featureFilter.length>0)
                featureFilter += " or " + trim(arrFeatureCheckBoxes[i].id.split("|")[1]) +"=''true''";
            else
                featureFilter += trim(arrFeatureCheckBoxes[i].id.split("|")[1]) +"=''true'' ";
            //break;
        }
    }

    document.getElementById("hdFeatureFilters").value = featureFilter;

}
//---------- filter by Features Ends

//---------- filter restaurants Begins
function filterRestaurantsByCheckBox(event) {

    cursor_wait();
    filterRestaurantsByCuisineTypes();
    filterRestaurantsByFeatures();

    document.getElementById('hdPageNumber').value = "1";
    LoadSearchPageCenter();
    LoadSearchPageIndicators();

    cursor_clear();
}
//---------- filter restaurants ends
//---------- show the page begins
function groupRestaurantsAndShow() {
    
    showRestaurants(0, g_rowsPerPage - 1);
}
//---------- show the page ends
