﻿function SetSliderValue(slider, value) {
    jQuery(slider).slider('value', [value]);
}
function ScrapeChecked(field)
{
    return jQuery('#' + field).is(':checked');
}
function ScrapeRadio(field, value)
{
    return (jQuery('#' + field).is(':checked') ? value : '');
}
function ScrapeCheckbox(field, value)
{
    return (jQuery('#' + field).is(':checked') ? value : '');
}

function GenerateReport(targetElement, pageNo) {
    if (typeof Validate == "function") {
        Validate();
    }

    jQuery('#PageNo').val(pageNo);

    jQuery('#' + targetElement).prepend("<div class='loading'>Loading</div>");
    var params = jQuery('form').serialize(true);

    jQuery.ajax({
        type: "POST",
        url: "/Handler/ProductSelectorReportHandler.ashx",  
        data: params,      
        success: function(html) {
            jQuery('#' + targetElement).html(html);
        },
        error: function() {
            AjaxError;
        }   
    });    
}

function ShowAll() {
    var maxResultCount = jQuery('#MaxResultCount').val();
    //Show All
    if (maxResultCount == "50") {
        jQuery('#MaxResultCount').val("-1");
        jQuery('#topResultText').val("All results shown");
        jQuery('#topResult').attr('src', "/IMG/Template/btn-show-top50-results.gif");
    }
    else //Show 50
    {
        jQuery('#MaxResultCount').val("50");
        jQuery('#topResultText').val("Top 50 results shown");
        jQuery('#topResult').attr('src', '/IMG/Template/btn-show-all-results.gif');
    }

    AjaxClick(false);
}
function SetCurrentTab(tabId) {    
    if (jQuery("#ProductSelectorReport").val() != null) {
        setTabList(tabId, "ProductSelectorReport", "on");
    }
}
function ClickAndRunReport(isTabChange, repName, tabId) {
    
    if (jQuery('#ReportName').val() == repName) {
        if (isTabChange) {
            SetCurrentTab(tabId);
        }

        GenerateReport("productSelectorReportResults", 1);
    }
}

function SetSort(reportName, sortReportName, sortField) {
    jQuery('#ReportName').val(reportName);
    jQuery('#SortReportName').val(sortReportName);
    jQuery('#SortField').val(sortField);
}


            
