﻿var name = "#itemDetails";
var menuYloc = null;
function UpdateDetails(s) {
    $("#LoadingImage").show();
    CGB.Bruce.CertDetails(s, onlookupcomplete, onerror);
}
function onerror() {
    //alert("Obtaining certified listings failed");
    $("#LoadingImage").hide();
    return;
}
function onlookupcomplete(result) {
    $("#LoadingImage").hide();
    var res = $get("text");
    res.innerHTML = result;
    $(name).show("normal");
    //cont.style.visibility = "visible";
}
function showhide(cId) {
    var me = $get(cId);
    $(me).hide("normal");
}
function UpdateTable() {
    $(name).hide("normal");
};
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
    UpdateTable();
});
function filterBy(manid) {
    var matches = $('tr.' + manid);
    //hide non-matching trs.
    if (matches.length == 0)
    {
        alert("There are no matching components for this manufacturer.");
    }
    else {
        $('#seriesselect option:selected').removeAttr("selected");
        $("#seriesselect option[value='ALL']").attr("selected", "selected");
        $('#LoadingImage').show();
        $('#componentsdiv table').each(function() {
            if ($(this).find('tr.' + manid).length == 0) {
                $(this).hide();
            }
            else {
                $(this).show();
                $(this).find('tbody tr.' + manid).show();
                $(this).find('tbody tr').not('.' + manid).hide();
            }
        });
    }

    $('#LoadingImage').hide();
}
function binddrop() {
    $('#remmy').remove();
    $('#manus').unbind("change").change(function() {
        var manid = $('#manus option:selected').val();
        if (manid == "ALL") {
            $('#seriesselect option:selected').removeAttr("selected");
            $("#seriesselect option[value='ALL']").attr("selected", "selected");
            $('#componentsdiv table').show();
            $('.compListing tr').show();
        }
        else {
            filterBy(manid);
        }
    });
    $('#seriesselect').unbind("change").change(function() {
        $('#manus option:selected').removeAttr("selected");
        $("#manus option[value='ALL']").attr("selected", "selected");
        var selseries = $('#seriesselect option:selected').val();
        if (selseries == "ALL") {
            $('#componentsdiv table').show().find('tr').show();
        }
        else {
            $('#componentsdiv table').hide();
            $('#' + selseries).show().find('tr').show();
        }
    });
}

$(document).ready(function() {
    binddrop();
    $("#LoadingImage").hide();
    UpdateTable();
    menuYloc = parseInt($(name).css("top").substring(0, $(name).css("top").indexOf("px")))
    $(window).scroll(function() {
        var offset = menuYloc + $(document).scrollTop() + "px";
        $(name).animate({ top: offset }, { duration: 500, queue: false });
    });
});