﻿function SetOptions(Options, lang) {
    pageLoading();
    if (lang === undefined) lang = _LanguageCode;
    $.ajax({
        type: "POST",
        url: "/system/services/productfilterRight.asmx/SetOptions",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({ "Options": Options, LanguageCode: lang }),
        success: function (res) {
            var obj = JSON.parse(res.d);
            displayResults(obj);
            pageLoaded();
            window.location.hash = '#search/' + Options;
            $('#hidAjaxHash').val(window.location.hash);
        },
        error: function (res) { displayException(res); }
    });
}

function displayResults(obj) {
    if (obj.Redirect) {
        top.location.href = obj.Redirect;
    } else {
        $('#content').html(obj.Content);
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        $('#divTopHeader').html(obj.Header);
        $('#breadcrumbCell').html(obj.Breadcrumb);
        document.title = obj.PageTitle;
        readyAlsoAfterAjax();
    }
}

function displayResults2(obj) {
    if (obj.Redirect) {
        top.location.href = obj.Redirect;
    } else {
        $('#productGrid').html(obj.ProductGrid);
    }
}

function ChangePage(PageIndex, FullPage) {
    ajaxPost('/system/services/productfilterRight.asmx/GetResults',
                { PageIndex: PageIndex, PerPage: -1, FullPage: FullPage },
                function (res) {
                    var obj = JSON.parse(res.d);
                    if (FullPage == true) {
                        displayResults(obj);
                    } else {
                        displayResults2(obj);
                    }
                    $('#imgAjax').hide();
                });
}

function displayException(res) {
    var obj = eval("(" + res.responseText + ")");
    alert(obj.Message);
    $('#imgAjax').hide();
}