﻿$(document).ready(fncReady);
function fncReady() {
    var isOutside = true;
    var previewId;

    window.onresize = fitQuickView;
    //fitCatItem();
    //$(".cat-checkbox").dgStyle();
    //            $(".cat-checkbox input:checkbox").click(function() {
    //                alert("1" + $(this).attr("checked"));
    //            });
    
    $(".lnkProduct").mouseover(function() {
        isOutside = true;
        var pos = $(this).parent().offset();
        previewId = $(this).attr('rel');
        $("#dvPreview").css({ "left": (pos.left + 15) + "px", "top": (pos.top + 47) + "px", "display": "block" });
    }).mouseout(function() {
        setTimeout(function() {
            if (isOutside) {
                $("#dvPreview").hide();
            }
        }, 50);
    });

    $("#dvPreview").mouseover(function() {
        isOutside = false;
    }).mouseout(function() {
        isOutside = true;
    }).click(function() {        
        load(previewId);
    });
}
function load(id) {
    
    return $.ajax({
        type: "POST",
        url: "/item-detail.aspx",
        data: { itemid: id },
        success: function(data) {

            $("#ItemDetail").empty().html(data)
                        .dialog({
                            width: 600,
                            closeText: "",
                            resizable: false,
                            draggable: false,
                            modal: true
                        });
                        $(".ui-dialog-titlebar").hide();
                        
        }
    });

}
var disType = '';
function displaystyle(displaystyle) {
    if (displaystyle == 'list' || disType == 'list') {
        $(".cat-item").removeClass("cat-item-grid");
        $(".cat-item").addClass("cat-item-list");
        disType = "list";
    }
    if (displaystyle == 'grid' || disType == 'grid') {
        $(".cat-item").removeClass("cat-item-list");
        $(".cat-item").addClass("cat-item-grid");
        disType = 'grid';
        fitCatItem();
    }
}

function CheckBoxListClearAll() {
    $("#refineMenu input:checkbox").attr('checked', false);
    document.forms['aspnetForm'].submit();
}

function CheckBoxListSelect(cbControl, state) {
    var chkBoxList = document.getElementById(cbControl);
    if (chkBoxList != null) {

        var chkBoxCount = chkBoxList.getElementsByTagName("input");
        for (var i = 0; i < chkBoxCount.length; i++) {
            chkBoxCount[i].checked = state;
        }
        document.forms['aspnetForm'].submit();
    }
}

function onReviewClick() {
    var tabs = $(".synTabbed").find(".synTabs").children().filter("*").addClass("synTab");
    if (tabs.length > 0)
        tabs[2].click();
}

function fitQuickView() {
    var winH = $(window).height();

    if (winH > 574) winH = 574;
    if (winH < 300) winH = 300;

    $("div[id$=pnlProductQuickView]").css("height", winH + "px");
}

function checkBrands() {    
    var text = $("#txtSearchTerm").val().toLowerCase();
    $("Table[id$=chkBrands] label").each(function() {        
        if ($(this).text().toLowerCase().indexOf(text) != -1) {
            $(this).parent().parent().css("display", "block");
            
        }
        else {
            $(this).parent().parent().css("display", "none");
            
        }
    });
}

function FilterBrand() {
    var text = $("#txtSearchTerm-brand").val().toLowerCase();
    $("#cat-fil-brand label").each(function() {
        if ($(this).text().toLowerCase().indexOf(text) != -1) {
            $(this).parent().parent().css("display", "block");

        }
        else {
            $(this).parent().parent().css("display", "none");

        }
    });
}

function FilterIndex() {
    var text = $("#txtFilter").val().toLowerCase();
    $("#alpha-result-box label").each(function() {
        if ($(this).text().toLowerCase().indexOf(text) != -1) {
            $(this).parent().parent().css("display", "block");

        }
        else {
            $(this).parent().parent().css("display", "none");

        }
    });
}

function fitCatItem() {    
    $(".cat-item-grid").each(function() {   
        $(this).css("height", $(this).parent().height());
    });
     
}

//function onItemSelected(sender, args) {
//    //the label1's value cannot be saved because it is not saved in the viewstate
//    $get("lblClientValue").innerHTML = args._value;
//    //save it in the hiddenfiled   
//    $get("HiddenField1").value = args._value;
//    //you can comment it to show the value in label1 or uncomment it to show the value in label2   
//    //javascript: WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button1", "", false, "", "TestCreatAutoItemValueAndGetItWhenPostBack.aspx", false, true));   
//}   
