﻿// JScript 文件
function SelWholesale() {
    var TypeCount = document.getElementsByName("TxtWholesale");

    for (var i = 1; i < TypeCount.length; i++) {
        if (TypeCount[i].checked) {
            if (TypeCount[i].value == "1") {
                DivWholesale.style.display = "";
            }
            else {
                DivWholesale.style.display = "none";
            }
        }
    }
}


function SelRetailPrice() {
    if (document.getElementsByName("RetailPriceSet")[2].checked) {
        DivRetailPrice.style.display = "";
    }
    else {
        DivRetailPrice.style.display = "none";
    }
}


function SelColor(input_val, img_val) {
    //WinOpen("../../common/SelColor.aspx?input_val="+input_val+"&img_val="+img_val+"","","380","300");
    WinOpenDialog("../../common/SelColor.aspx?input_val=" + input_val + "&img_val=" + img_val + "", "360", "330");
}

function SetShopParam() {
    var data = XmlHttpPostMethodText("../info/GetColumn.aspx", "ColId=" + $('ddlColId').value);
    if (data == "") {
        return;
    }
    else {
        var param = data.split('$');
        if (param.length == 7) {
            $('txtPageType_' + (param[0] - 1)).checked = true;
            $('txtTemplatePath').value = param[1];
            if (param[6] == "True") {
                $('chkBoxIsAllowComment').checked = true;
            }
        }
    }
}

//标题类型
function SetTitleType(obj) {
    var temp = obj;
    if (temp == 1) {
        $('rbComm').checked = true;
        if ($('ShowImgUrl') != null) {
            ShowImgUrl.style.display = "none";
        }
    }
    else if (temp == 2) {
        $('rbImg').checked = true;
        if ($('ShowImgUrl') != null) {
            ShowImgUrl.style.display = "";
        }
    }
}

//检测标题
function CheckTitle(TableName) {
    var title = $("txtTitle").value.trim();
    if (title.length == 0) {
        alert('检测的标题必须填写');
        $("txtTitle").focus();
        return;
    }
    var flag = CheckHas("../common/CheckHas.aspx", title, "Title", TableName)
    if (!flag) {
        alert("该标题不存在！");
        $("txtTitle").focus();
    }
    else {
        alert("该标题已经存在！");
        $("txtTitle").focus();
    }
}

//检测标题
function CheckProductNum(TableName) {
    var ProductNum = $("txtProductNum").value.trim();
    if (ProductNum.length == 0) {
        alert('检测的商品编号必须填写');
        $("txtProductNum").focus();
        return;
    }
    var flag = CheckHas("../common/CheckHas.aspx", ProductNum, "ProductNum", TableName)
    if (!flag) {
        alert("该商品编号不存在");
        $("txtProductNum").focus();
    }
    else {
        alert("该商品编号已经存在");
        $("txtProductNum").focus();
    }
}

function GetShopModelHtml(ChId, Id) {
    system_shop_SetShop.GetModelHtmlValue(ChId, Id, CallBack)
}

function GetShopModelHtmlUser(ChId, Id) {
    user_info_SetShop.GetModelHtmlValue(ChId, Id, CallBack)
}

function BuyCart(RootPath, ChId, Id) {
    var CharacterName = "";
    //    CharacterName=$("CharacterName").value        
    //    if(CharacterName=="")
    //    {
    //       alert("Please fill Character Name!");
    //       $("CharacterName").focus();
    //       return;
    //    }
    //    
    //    CharacterName="<li>Character Name: "+CharacterName+"</li>";

    if ($("Account") != null) {
        if ($("Account").value == "") {
            alert("Please fill account");
            $("Account").focus();
            return;
        }
        CharacterName += "<li>Account: " + $("Account").value + "</li>";
    }

    if ($("Password") != null) {
        if ($("Password").value == "") {
            alert("Please fill passwrod");
            $("Password").focus();
            return;
        }
        CharacterName += "<li>Password: " + $("Password").value + "</li>";
    }


    if ($("Country") != null) {
        CharacterName += "<li>Country: " + $("Country").value + "</li>";
    }

    if ($("Country") != null) {
        CharacterName += "<li>Game server: " + $("CharClass").value + "</li>";
    }

    if ($("NOTE") != null) {
        CharacterName += "<li>Note: " + $("NOTE").value + "</li>";
    }

    if ($("GameServer") != null) {
        if ($("GameServer").value == "") {
            alert("Please fill Game Server")
            $("GameServer").focus();
            return;
        }
        CharacterName += "<li>Game Server: " + $("GameServer").value + "</li>";
    }
    var num = 1;
    if ($("num_" + ChId + "_" + Id) != null) {
        num = $("num_" + ChId + "_" + Id).value;
    }

    var data = XmlHttpPostMethodText("" + RootPath + "/user/shop/BuyCart.aspx", "CharacterName=" + escape(CharacterName) + "&ChId=" + ChId + "&Id=" + Id+"&num="+num);
    //	if (data == "0") {
    //	    alert("购物车中不能既存在金币也存在代练");
    //	    return;
    //	}
    var redirctRul = document.location.href.toLowerCase();
//    if (redirctRul.indexOf("default.aspx") == -1 && redirctRul.indexOf("items.html") == -1 && redirctRul.indexOf("buy-account") == -1 && redirctRul.indexOf("special.html") == -1 && redirctRul.indexOf("power-leveling.html") == -1) {
//        document.location.href = redirctRul;
//    }
//    else {
        document.location.href = "/user/shop/ShoppingCart.aspx";
    //}
    return;
    if (data == "") {
        return;
    }
    else {
        switch (data) {
            case "1":
                document.location.href = "" + RootPath + "/user/shop/ShoppingCart.aspx";
                return;
                break;
            case "NoSale":
                alert("该商品目前还不支持销售操作");
                return;
                break;
            case "2":
                alert("成功加入购物车");
                return;
                break;
            case "NotLogin":
                alert("请登陆后使用");
                return;
                break;
            case "NoStorageNum":
                alert("该商品库存数量不足，不能够购买");
                return;
                break;
            //            case "NoUserShop":  
            //                alert("你购物车中已经有另一人商品\n\n请下订单/取消购物车中商品后才能购买该商品")  
            //                return;  
            //                break;  
            default:
                document.location.href = data;
                return;
                break;
        }
    }
}

function PaymentUserLogin() {
    if ($("UserLogin1").checked) {
        $("Div_UserLogin2").style.display = "none";
        $("Div_UserLogin1").style.display = "";
    }
    else {
        $("Div_UserLogin2").style.display = "";
        $("Div_UserLogin1").style.display = "none";
    }
}

function GetGamePart(id) {
    document.form1.GameServer.length = 0;
    if (id == "0") {
        document.form1.GameServer.length++;
        document.form1.GameServer.options[0].text = "选择服务器";
        document.form1.GameServer.options[0].value = "0";
    }
    else {
        system_shop_SetShop.GetGamePart(id, GamePart_Call_Back);
    }
}


function GamePart_Call_Back(res) {
    document.form1.GameServer.length = 0;
    document.form1.GameServer.length++;
    document.form1.GameServer.options[0].text = "选择服务器";
    document.form1.GameServer.options[0].value = "0";

    if (res.value.Rows.length > 0) {
        for (var i = 0; i < res.value.Rows.length; i++) {
            document.form1.GameServer.length++;
            document.form1.GameServer.options[i + 1].text = res.value.Rows[i]["ColName"]; ;
            document.form1.GameServer.options[i + 1].value = res.value.Rows[i]["ColId"]; ;
        }
    }
}

function DisplayImag(name) {
    document.getElementById(name).style.display = "inline";
}
function GoToUrl(value) {
    window.location.href = value;
}
function Checkname(txtName, imgName) {
    var value = $(txtName).value;
    if (value == "") {
        $(imgName).style.display = "inline";
        $(imgName).src = "/image/no.gif";
        return false;
    }
    if (txtName == "txtAddress") {
        var patt = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        if (!patt.test(value.trim())) {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/no.gif";
            return false;
        }
        else {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/yes.gif";
            return true;
        }
    }
    else if (txtName == "txtUsNum") {
        var patt = /^\d{3}-\d{3}-\d{4}$/;
        if (!patt.test(value.trim())) {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/no.gif";
            return false;
        }
        else {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/yes.gif";
            return true;
        }
    }
    else if (txtName == "txtNoUsNum") {
        var patt = /^\d+$/;
        if (!patt.test(value.trim())) {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/no.gif";
            return false;
        }
        else {
            $(imgName).style.display = "inline";
            $(imgName).src = "/image/yes.gif";
            return true;
        }
    }
    else {
        $(imgName).style.display = "inline";
        $(imgName).src = "/image/yes.gif";
        return true;

    }
}
function ChkTel() {
    if ($("txtUsNum1").value != "" && $("txtUsNum2").value != "" && $("txtUsNum3") != "") {
        var value = $("txtUsNum1").value + "-" + $("txtUsNum2").value + "-" + $("txtUsNum3").value;
        var patt = /^\d{3}-\d{3}-\d{4}$/;
        if (!patt.test(value.trim())) {
            $("imgNsNum").style.display = "inline";
            $("imgNsNum").src = "/image/no.gif";
            return false;
        }
        else {
            $("imgNsNum").style.display = "inline";
            $("imgNsNum").src = "/image/yes.gif";
            return true;
        }
    }
    $("imgNsNum").style.display = "inline";
    $("imgNsNum").src = "/image/no.gif";
    return false;
}


function ShowPrice(oThis) {
    if (oThis[oThis.selectedIndex].value == "NULL") {
        $("PriceValue").innerHTML = $("PriceValue").innerHTML.substring(0, 1) + " 0.00";
        return;
    }

    var price = oThis[oThis.selectedIndex].value.split(",")[1];
    var type;
    try {
        type = $("PriceValue").innerHTML.substring(0, 1);
    }
    catch (ex) {
        alert($("PriceValue").innerHTML);
    }
    price = GetChangePrice(type, price);
    $("PriceValue").innerHTML = type + " " + price;
}
function ChangePrice(newtype) {
    var slt = $("sltProduct");
    if (!slt) {
        $("PriceValue").innerHTML = newtype + " 0.00";
        return;
    }
    if (slt[slt.selectedIndex].value == "NULL") {
        $("PriceValue").innerHTML = newtype + " 0.00";
    }
    else {
        var price = slt[slt.selectedIndex].value.split(",")[1];
        price = GetChangePrice(newtype, price);
        $("PriceValue").innerHTML = newtype + " " + price;
    }

    var num = parseInt(document.getElementById("ratenum").value) + 1;
    for (var v = 1; v <= num; v++) {
        document.getElementById("PriceList" + v).style.display = "none";
    }

    document.getElementById("PriceList" + document.getElementById(newtype + "index").value).style.display = "block";
}
function GetChangePrice(newType, price) {
    //var newTypeIndex = GetTypeIndex(newType);
    price = price * document.getElementById(newType).value;

    var vals = price.toString().split(".");
    if (vals[1] == null) {
        return vals[0];
    }
    return vals[0] + "." + vals[1].substring(0, 2);
}
function GetRate() {
    var value = XmlHttpPostMethodText("/other/GetRates.aspx", "");
    $("languagechoose").innerHTML = value;
}

function CheckBuyGoldsInfo() {
    var slt = $("sltProduct");
    var product = slt[slt.selectedIndex].value.split(",")[0];
    if (product == "NULL") {
        alert("Plesea select your product");
        return false;
    }
    var fname = $("txtFirstName").value;
    if (fname == "") {
        alert("Please fill Firs Name!");
        $("txtFirstName").focus();
        return false;
    }

    var fname = $("txtLastName").value;
    if (fname == "") {
        alert("Please fill Last Name!");
        $("txtLastName").focus();
        return false;
    }


    var cname = $("txtChaName").value;
    if (cname == "") {
        alert("Please fill Address!");
        $("txtChaName").focus();
        return false;
    }
    var address = $("txtAddress").value;
    var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!reg.test(address)) {
        alert("Please fill right Address!");
        $("txtAddress").focus();
        return false;
    }

    var usNum = $("txtUsNum1").value + "-" + $("txtUsNum2").value + "-" + $("txtUsNum3").value;
    var nonUsNum = $("txtNoUsNum").value;
    reg = /^\d{3}-\d{3}-\d{4}$/;
    var reg2 = /^\d*$/;
    if (usNum == "--" && nonUsNum == "") {
        alert("Please fill Phone!");
        $("txtUsNum1").focus();
        return false;
    }
    else if (usNum != "--" && !reg.test(usNum)) {
        alert("Your US Phone is error!");
        $("txtUsNum1").focus();
        return false;
    }
    else if (nonUsNum != "" && !reg2.test(nonUsNum)) {
        alert("Your Non-US Phone is error!");
        $("txtNoUsNum").focus();
        return false;
    }
}

function ShowUserInfo() {
    var result = XmlHttpGetMethodText("/other/GetLoginUerInfo.aspx");
    if (result != "NULL") {
        var vals = result.split("|");
        $("txtFirstName").value = vals[0];
        $("txtLastName").value = vals[1];
        $("txtNoUsNum").value = vals[3];
        $("txtAddress").value = vals[4];
        var patten = /^\d{3}-\d{3}-\d{4}$/;
        if (patten.exec(vals[2])) {
            var tels = vals[2].split("-");
            $("txtUsNum1").value = tels[0];
            $("txtUsNum2").value = tels[1];
            $("txtUsNum3").value = tels[2];
        }
    }
}

function selectpricelist(title, price) {
    //判断是否存在
    var isExit = false;
    for (var i = 0; i < $("sltProduct").options.length; i++) {
        if ($("sltProduct").options[i].text == title) {
            $("sltProduct").options[i].selected = true;
            isExit = true;
            break;
        }
    }
    ShowPrice(document.getElementById("sltProduct"));
} 

