﻿$(function () {
    menu(document.URL)
})
var login = function () {
    if ($("#UserName").val() == "" || $("#Password").val() == "") {
        alert("登录信息请填写完整!");
        return false;
    }
}
var menu = function (url) {
    var file = url.split("/");
    if (file[3] == "" || file[3] == "Default.aspx") { $($("#menu li")[0]).find("a").addClass("sel"); }
    else if (file[3].toLowerCase().indexOf("news") != -1) { $($("#menu li")[1]).find("a").addClass("sel"); }
    else if (file[3].toLowerCase().indexOf("pro") != -1) { $($("#menu li")[2]).find("a").addClass("sel"); }
    else if (file[4] && file[4].toLowerCase().indexOf("info-9") != -1) { $($("#menu li")[3]).find("a").addClass("sel"); }
    else if (file[4] && file[4].toLowerCase().indexOf("info-5") != -1) { $($("#menu li")[4]).find("a").addClass("sel"); }
    else if (file[4] && file[4].toLowerCase().indexOf("info-2") != -1) { $($("#menu li")[5]).find("a").addClass("sel"); }
    else if (file[4] && file[4].toLowerCase().indexOf("info-10") != -1) { $($("#menu li")[7]).find("a").addClass("sel"); }
    else { $($("#menu li")[0]).find("a").addClass("sel"); }
}
var buypro = function (id) {
    $.get("/control/Buy.ashx?id=" + id + "&" + Math.random(), function (data) {
        var item = data.split("|");
        alert(item[0]);
        if (item[1] != 0) {
            $(".carcount").html(item[1]);
            $("#spcart").html(item[2]);
        }
    });
}

var buynow = function (id,count) {
    $.get("/control/Buy.ashx?id=" + id + "&count=" + count + "&" + Math.random(), function (data) {
        var item = data.split("|");
        alert(item[0]);
        if (item[1] != 0) {
            $(".carcount").html(item[1]);
            $("#spcart").html(item[2]);
        }
    });
}

var keeppro = function (id) {
    $.get("/control/Keep.ashx?id=" + id + "&" + Math.random(), function (data) {
        alert(data);
    });
}
var updatepro = function (ProductT, CostPrice, SKU) {
    var ptotal = $("#num" + SKU).val();
    if (ptotal == ProductT) {
        alert("无更新操作！"); return;
    }
    $.get("/control/carter.ashx",
    { ProductTotal: ptotal, ProductT: ProductT, CostPrice: CostPrice, SKU: SKU, at: 'update', Math: Math.random() },
    function (data) {
        var item = data.split("|");
        alert(item[0]);
        if (item[1] != 0) {
            //$("#sTotalPrice").html("产品总价：￥" + item[1]);
            //var TotalPrice = parseFloat($("#num" + SKU).val()) * CostPrice;
            //$("#sp" + SKU).html("￥" + TotalPrice.toFixed(2));
            //$("#spcart").html(item[1]);
            window.open("/ShoppingCarts.aspx");
        }
    });
}
var deletepro = function (ProductT, CostPrice, SKU) {
    if (confirm("确定要删除？")) {
        $.get("/control/carter.ashx",
        { ProductTotal: $("#num" + SKU).val(), ProductT: ProductT, CostPrice: CostPrice, SKU: SKU, at: 'delete', Math: Math.random() },
        function (data) {
            var item = data.split("|");
            alert(item[0]);
            if (item[1] != 0) {
                $("#tr" + SKU).hide();
                $("#sTotalPrice").html("产品总价：￥" + item[2]);
                $("#spcart").html(item[2]);
                $(".carcount").html($($(".carcount")[0]).text() - 1);
            }
        });
    }
}
var selall = function () {
    $("#pics1 input[type=checkbox]").attr("checked", 'true');
}
var selfs = function () {
    $("#pics1 input[type=checkbox]").each(function () {
        if ($(this).attr("checked")) { $(this).removeAttr("checked"); }
        else { $(this).attr("checked", 'true'); }
    })
}
var buypros = function () {
    var str = "";
    $("#pics1 input[name='checkbox'][checked]").each(function () { str += $(this).val() + ","; });
    if (str != "") {
        str = str.substring(0, str.length - 1);
        $.get("/control/Buy.ashx?ids=" + str + "&" + Math.random(), function (data) {
            var item = data.split("|");
            alert(item[0]);
            if (item[1] != 0) {
                $(".carcount").html(item[1]);
                $("#spcart").html(item[2]);
            }
        });
    }
    else {
        alert("至少要选择一件产品！");
    }
}
var Domain = {
    Homepage: function () {
        if (document.all) {
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage("http://" + window.location.host);
        }
        else if (window.sidebar) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入about:config,然后将项signed.applets.codebase_principal_support 值该为true");
                    history.go(-1);
                }
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', window.location.href);
        }
    },
    Favorite: function Favorite() {
        var sURL = window.location.url;
        var sTitle = document.title;
        if (sTitle == null) {
            var t_titles = document.getElementByTagName("title")
            if (t_titles && t_titles.length > 0) {
                sTitle = t_titles[0];
            } else {
                sTitle = "";
            }
        }
        try {
            window.external.addFavorite(sURL, sTitle);
        }
        catch (e) {
            try {
                window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch (e) {
                alert("加入收藏失败,请手动添加.");
            }
        }
    }
}
