/*分类选择层开始*/
var openCategorySelectLayerBut = null;
var categorySelectList = "<div class='selectBoxProgressBar'><p><img src='/Administration/Content/Images/progressbar.gif'/></p></div>";

function CategoryTree(obj) {
    var state = $(obj).attr("class");
    if (state == "open") {
        $("#categorTree tr[tree_pid='" + $(obj).parent().parent().attr("tree_id") + "']").css("display", "table-row");
        $(obj).removeClass("open").addClass("close");
    }
    else if (state == "close") {
        $("#categorTree tr[tree_pid='" + $(obj).parent().parent().attr("tree_id") + "']").css("display", "none");
        $(obj).removeClass("close").addClass("open");
    }
}

function SetSelectedCategory(obj) {
    var cateObj = $(openCategorySelectLayerBut).parent().find(".CateId");
    cateObj.val($(obj).parent().parent().attr("tree_id"));
    var getedcateName = $(obj).parent().parent().find("th").text();
    $(openCategorySelectLayerBut).val(getedcateName);
    $(openCategorySelectLayerBut).parent().find(".CategoryName").val(getedcateName);
    $.jBox.close('CategorySelectLayer');
}

function AjaxCategorySelectList() {
    $.jBox.setContent(categorySelectList);
    $.get("/Administration/Cache/Category/selectlist.txt?t=" + new Date(), function (data) {
        $.jBox.setContent(data);
    })
}

function openCategorySelectLayer(openLayerBut) {
    $.jBox('html:categorySelectList', {
        id: 'CategorySelectLayer',
        width: 750,
        buttons: { '关闭': true },
        title: "选择类别"
    });
    openCategorySelectLayerBut = openLayerBut;
    AjaxCategorySelectList();
}
/*分类选择层开始*/

/*品牌选择层开始*/
var oldSelectListSearchBrand = "";
var openBrandSelectLayerBut = null;
var brandSelectList = "<div class='selectBoxProgressBar'><p><img src='/Administration/Content/Images/progressbar.gif'/></p></div>";

function SetSelectedBrand(item) {
    var brandObj = $(openBrandSelectLayerBut).parent().find(".BrandId");
    brandObj.val($(item).attr("brandid"));
    var getbrandName = $(item).text();
    $(openBrandSelectLayerBut).val(getbrandName);
    $(openBrandSelectLayerBut).parent().find(".BrandName").val(getbrandName);
    $.jBox.close('BrandSelectLayer');
}

function AjaxBrandSelectList(brandName, pageNumber) {
    $.jBox.setContent(brandSelectList);
    $.get("/admin/Brand/SelectList?t=" + new Date(), {
        'brandName': brandName,
        'pageNumber': pageNumber
    }, function (data) {
        var listObj = eval(data);
        var list = "<div id='selectBrandBox'><table width='100%' ><tr><td>品牌名称:<input type='text' id='selectListSearchBrand'  name='selectListSearchBrand' style='width:120px;height:18px;'> <input type='image' onclick='SearchBrandSelectList()' src='/Administration/Content/Images/s.jpg' class='searchBut'></td></tr><tr><td><div id='selectBrandBoxCon'><ul>";
        for (var i = 0; i < listObj.items.length; i++) {
            list += "<li><a onclick='SetSelectedBrand(this)' brandid='" + listObj.items[i].id + "'>" + listObj.items[i].name + "</a></li>";
        }
        list += "<div class='clear'></div></ul><div class='clear'></div></div></td></tr><tr><td><div class='page' style='position:static;'>";
        for (var j = 1; j <= listObj.count; j++) {
            if (j != listObj.page) {
                list += "<a href='javascript:;' class='bt' onclick='GoBrandSelectListPage(this)' pageNumber='" + j + "'>" + j + "</a>";
            }
            else {
                list += "<a href='javascript:;' onclick='GoBrandSelectListPage(this)' pageNumber='" + j + "'>" + j + "</a>";
            }
        }
        $.jBox.setContent(list + "</div></td></tr></table></div>");
        $("#selectListSearchBrand").val(oldSelectListSearchBrand);
    })
}

function SearchBrandSelectList() {
    oldSelectListSearchBrand = $("#selectListSearchBrand").val();
    AjaxBrandSelectList(oldSelectListSearchBrand);
}

function GoBrandSelectListPage(pageObj) {
    oldSelectListSearchBrand = $("#selectListSearchBrand").val();
    AjaxBrandSelectList(oldSelectListSearchBrand, $(pageObj).attr("pageNumber"));
}

function openBrandSelectLayer(openLayerBut) {
    $.jBox('html:brandSelectList', {
        id: 'BrandSelectLayer',
        width: 750,
        buttons: { '关闭': true },
        title: "选择品牌"
    });
    openBrandSelectLayerBut = openLayerBut;
    AjaxBrandSelectList();

}
/*品牌选择层结束*/

/*商品选择层开始*/
var oldSelectListSearchProduct = "";
var openProductSelectLayerBut = null;
var productSelectList = "<div class='selectBoxProgressBar'><p><img src='/Administration/Content/Images/progressbar.gif'/></p></div>";

function SetSelectedProduct(item) {
    var productObj = $(openProductSelectLayerBut).parent().find(".Pid");
    productObj.val($(item).attr("pid"));
    var getproductName = $(item).text();
    $(openProductSelectLayerBut).val(getproductName);
    $(openProductSelectLayerBut).parent().find(".ProductName").val(getproductName);
    $.jBox.close('ProductSelectLayer');
}

function AjaxProductSelectList(productName, pageNumber) {
    $.jBox.setContent(productSelectList);
    $.get("/admin/Product/ProductSelectList?t=" + new Date(), {
        'ProductName': productName,
        'pageNumber': pageNumber
    }, function (data) {
        var listObj = eval(data);
        var list = "<div id='selectProductBox'><table width='100%' ><tr><td>商品名称:<input type='text' id='selectListSearchProduct'  name='selectListSearchProduct' style='width:120px;height:18px;'> <input type='image' onclick='SearchProductSelectList()' src='/Administration/Content/Images/s.jpg' class='searchBut'></td></tr><tr><td><div id='selectProductBoxCon'><ul>";
        for (var i = 0; i < listObj.items.length; i++) {
            list += "<li><a onclick='SetSelectedProduct(this)' pid='" + listObj.items[i].id + "'>" + listObj.items[i].name + "</a></li>";
        }
        list += "<div class='clear'></div></ul><div class='clear'></div></div></td></tr><tr><td><div class='page' style='position:static;'>";
        for (var j = 1; j <= listObj.count; j++) {
            if (j != listObj.page) {
                list += "<a href='javascript:;' class='bt' onclick='GoProductSelectListPage(this)' pageNumber='" + j + "'>" + j + "</a>";
            }
            else {
                list += "<a href='javascript:;' onclick='GoProductSelectListPage(this)' pageNumber='" + j + "'>" + j + "</a>";
            }
        }
        $.jBox.setContent(list + "</div></td></tr></table></div>");
        $("#selectListSearchProduct").val(oldSelectListSearchProduct);
    })
}

function SearchProductSelectList() {
    oldSelectListSearchProduct = $("#selectListSearchProduct").val();
    AjaxProductSelectList(oldSelectListSearchProduct);
}

function GoProductSelectListPage(pageObj) {
    oldSelectListSearchProduct = $("#selectListSearchProduct").val();
    AjaxProductSelectList(oldSelectListSearchProduct, $(pageObj).attr("pageNumber"));
}

function openProductSelectLayer(openLayerBut) {
    $.jBox('html:productSelectList', {
        id: 'ProductSelectLayer',
        width: 750,
        buttons: { '关闭': true },
        title: "选择商品"
    });
    openProductSelectLayerBut = openLayerBut;
    AjaxProductSelectList();

}
/*商品选择层结束*/