
function Establishment() {
    this.initialize = function(callback) {
        this.callback = callback;
    }

    this.getDailyDeals = function(v_city_id, v_day_of_week, v_limit) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getDailyDeals(v_city_id, v_day_of_week, v_limit);
    }

    this.getDealsByBounds = function(v_top, v_left, v_bottom, v_right, v_day_of_week, v_page) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getDealsByBounds(v_top, v_left, v_bottom, v_right, v_day_of_week, v_page);
    }

    this.getLatLong = function(v_post_code) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getLatLong(v_post_code);
    }

    this.getRecentUpdates = function(v_city_id, v_limit) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getRecentUpdates(v_city_id, v_limit);
    }

    this.getTopRanked = function(v_city_id, v_limit) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getTopRanked(v_city_id, v_limit);
    }

    this.getCityAreas = function(v_city_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getCityAreas(v_city_id);
    }

    this.getEstablishmentCities = function(v_prov_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getEstablishmentCities(v_prov_id);
    }

    this.getAllEstablishmentsFor = function(v_city_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getAllEstablishmentsFor(v_city_id);
    }

    this.getEstablishmentSuggestions = function(v_query, v_city_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getEstablishmentSuggestions(v_query, v_city_id);
    }

    this.postComment = function(v_estab_id, v_rate_quality, v_rate_plump, v_rate_sauce, v_rate_service, v_username, v_email, v_comment, v_captcha, v_isLoggedIn, v_module) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.postComment(v_estab_id, v_rate_quality, v_rate_plump, v_rate_sauce, v_rate_service, v_username, v_email, v_comment, v_captcha, v_isLoggedIn, v_module);
    }

    this.commentVote = function(v_comment_id, b_isup) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.commentVote(v_comment_id, b_isup);
    }

    this.getCommentsPage = function(v_estab_id, v_page_id, v_module) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.getCommentsPage(v_estab_id, v_page_id, v_module);
    }

    this.reportAbuse = function(v_comments_id, v_name, v_email, v_reason, v_captcha, v_isLoggedIn) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.reportAbuse(v_comments_id, v_name, v_email, v_reason, v_captcha, v_isLoggedIn);
    }

    this.postReply = function(v_parent_id, v_comment) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.postReply(v_parent_id, v_comment);
    }

    this.addToFavourites = function(v_estab_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.addToFavourites(v_estab_id);
    }

    this.removeFromFavourites = function(v_estab_id) {
        var HW = new EstablishmentAjaxProvider(this.callback);
        return HW.removeFromFavourites(v_estab_id);
    }
}

function listingFilterChanged(obForm) {
    var obSortBy = obForm.sortBy;
    var obCityId = obForm.frmCityID;
    var obDay    = null;

    if (obForm.dow)
        obDay = obForm.dow;

    var strSortBy = obSortBy.options[obSortBy.selectedIndex].value;
    var strCityId = obCityId.options[obCityId.selectedIndex].value;
    var strDow    = (obDay) ? obDay.options[obDay.selectedIndex].value : "0";

    var strOrderPart = "";
    var strCityPart  = "";
    var strDowPart   = "";

    if (strSortBy != "0") {
        strOrderPart = "orderBy/" + strSortBy + "/";
        bRedirect = true;
    }
    if (strCityId != "0") {
        strCityPart = "frmCityID/" + strCityId + "/";
        bRedirect = true;
    }
    if (strDow != "0") {
        strDowPart = "dow/" + strDow + "/";
        bRedirect = true;
    }

    if (bRedirect)
        location.href = SGL_JS_WEBROOT + "/wing-vendors/" + strOrderPart + strCityPart + strDowPart + strUrlQuery;
}

function reviewFilterChanged(obForm) {
    var obSortBy = obForm.sortBy;
    var obCityId = obForm.frmCityID;

    var strSortBy = obSortBy.options[obSortBy.selectedIndex].value;
    var strCityId = obCityId.options[obCityId.selectedIndex].value;

    var strOrderPart = "";
    var strCityPart  = "";

    if (strSortBy != "0") {
        strOrderPart = "orderBy/" + strSortBy + "/";
        bRedirect = true;
    }
    if (strCityId != "0") {
        strCityPart = "frmCityID/" + strCityId + "/";
        bRedirect = true;
    }

    if (bRedirect)
        location.href = SGL_JS_WEBROOT + "/wing-reviews/" + strOrderPart + strCityPart;
}
