﻿/// <reference path="jquery-1.2.6.js" />
document.write('<div id="ShadeBg" style="position:absolute;background:#000;display:none;width:100%;left:0;top:0;filter:alpha(opacity=60);-moz-opacity:0.6;z-index:10;"></div>');
document.write('<div id="ShadeMsg" style="position:absolute;display:none;left:0;top:0;z-index:11;"></div>');
var shadeTimer;
function ShadeShow(key, w, h) {
    MoveTo(w, h);
    $('#ShadeMsg').css("display","block");
    $('#ShadeBg').css("display", "block");
    $('#ShadeMsg').html(key);
}
function ShadeHide() {
    $('#ShadeMsg').css("display", "none");
    $('#ShadeBg').css("display", "none");
    $('#ShadeMsg').html("");
    clearTimeout(shadeTimer);
}
function MoveTo(w, h) {
  $('#ShadeMsg')[0].style.left = (document.documentElement.clientWidth - w) / 2 + document.documentElement.scrollLeft + "px";
    $('#ShadeMsg')[0].style.top = document.documentElement.clientHeight / 2 + document.documentElement.scrollTop - h / 2 + "px";
    $('#ShadeBg')[0].style.width =  document.documentElement.scrollWidth + "px";
    $('#ShadeBg')[0].style.height =  document.documentElement.scrollHeight + "px";
    shadeTimer = setTimeout('MoveTo(' + w + ',' + h + ')', 50);
}
function showBrandbox() {
    ShadeShow($('#floatBox').html(), 400, 228);
}
function addBrand() {
    var obj = $("input[@name=BrandName]");
    if (obj.val() == "") {
        alert("品牌名称不能为空!");
        return;
    }
    $.post("handler/ajaxpage.aspx?action=addbrand",
    "BrandName=" + escape(obj.val()) + "&BrandIntro=" + escape($("textarea[@name=BrandIntro]").val()) + "&BrandBigClass=" + $("#BrandBigClass").val(),
    function(txt) {
        if (txt == "error") { alert("添加错误!"); return; }
        else if (txt == "second") { alert("该品牌已经存在!"); return; }
        else { $("#Brand")[0].options.add(new Option(obj.val(), txt)); $("#Brand").val(txt); }
    });    
    ShadeHide();
}
function getBrandSeries() {
    if ($("#Brand").val() == "") {
        $("#ProductSeries").empty();
        $("#ProductSeries")[0].options.add(new Option("请选择", ""));
        return;
    }

    $.getJSON("handler/ajaxpage.aspx?action=getbrandseries&brandid=" + $("#Brand").val(),
    function(data) {
        $("#ProductSeries").empty();
        $("#ProductSeries")[0].options.add(new Option("请选择", ""));
        $.each(data, function(i, item) { 
            $("#ProductSeries")[0].options.add(new Option(item.ProductSeriesName, item.ProductSeriesID));
        });
    });
}
function showSeriesbox() {
    if ($("#Brand").val() == "") {
        alert("请先选择所属品牌!");
        return;
    }
    ShadeShow($('#floatBox2').html(), 400, 95);
}
function addSeries() {
    var obj = $("input[@name=SeriesName]");
    if (obj.val() == "") {
        alert("系列名称不能为空!");
        return;
    }
    $.post("handler/ajaxpage.aspx?action=addseries&brandid=" + $("#Brand").val(),
    "SeriesName=" + escape(obj.val()),
    function(txt) {
        if (txt == "error") { alert("添加错误!"); return; }
        else if (txt == "second") { alert("该系列已经存在!"); return; }
        else { $("#ProductSeries")[0].options.add(new Option(obj.val(), txt)); $("#ProductSeries").val(txt); }
    });
    ShadeHide();
}
function AddProduct() {
    if ($("#ProductName").val() == "") {
        alert("商品名称不能为空!");
        return;
    }
    else if ($("#Brand").val() == "") {
        alert("请选择所属品牌!");
        return;
    }
    $("#table1").css("display", "none");
    $("#table2").css("display", "block");
    $("#cargo2").attr("src", "../images/button_add-cargo2.gif");
    $("#cargo3").attr("src", "../images/button_add-cargo33.gif");
}
function ReturnAddProduct() {
    $("#table1").css("display", "block");
    $("#table2").css("display", "none");
    $("#cargo2").attr("src", "../images/button_add-cargo22.gif");
    $("#cargo3").attr("src", "../images/button_add-cargo3.gif");
}
function CheckForm(form) {
    var files = form.Files;
    var patn = /\.rar$|\.zip$/i;
    if (!patn.test(files.value)) {
        alert("仅支持 RAR, ZIP 文件上传");
        return false;
    }
    return true;
}
function AddProgram() {
    if ($("#ProgramName").val() == "") {
        alert("请输入项目名称!");
        return;
    }
    var obj = $("#ProductTo option");
    if (obj.length == 0) {
        alert("请选择包含的产品!");
        return;
    }
    var items = "";
    obj.each(function() {
        items += "," + $(this).val();
    });
    $("#ProgramItems").val(items.substring(1));
    $("#table1").css("display", "none");
    $("#table2").css("display", "block");
    $("#cargo2").attr("src", "../images/button_add-cargo2.gif");
    $("#cargo3").attr("src", "../images/button_add-cargo33.gif");
}
function AddItem() {
    $("#ProductFrom option:selected").appendTo($("#ProductTo"));
}
function DelItem() {
    $("#ProductTo option:selected").appendTo($("#ProductFrom"));
}
