﻿function changeCurrency() {
    LoadProductList();
}
function LoadProductList() {
    var GameID = document.getElementById("ServerNexts1_txt_GameID").value;
    //    if (GameID != 1) {
    document.getElementById("divmf").style.display = "none";
    //    }
    var ServerId = document.getElementById("ServerNexts1_txt_ServerId").value;
    var GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName").value;
    var dic_CurrencySign = document.getElementById("ServerNexts1_dic_CurrencySign");
    var CurrencySign = dic_CurrencySign.options[dic_CurrencySign.selectedIndex].value;
    //    if (GameID == 1 || GameID == 15) {
    //        document.getElementById("div_numTenPercent").style.display = "block";
    //    }
    //    else {
    //        document.getElementById("div_numTenPercent").style.display = "none";
    //    }
    AjaxMethod.LoadProductList(GameID, ServerId, GameTypeName, CurrencySign, LoadProductList_CallBack);
}
function LoadProductList_CallBack(response) {
    if (response.error != null) {
        //alert(response.error);
        return;
    }
    var ReturnStr = response.value;
    RenderList(ReturnStr);
}
function RenderList(DataTable) {
    if (DataTable != null && typeof (DataTable) == "object") {
        //--begin 生成vip价格用--
        var UserID = document.getElementById("ServerNexts1_txt_UserID").value;
        var Discount = document.getElementById("ServerNexts1_txt_Discount").value;
        var dic_CurrencySign = document.getElementById("ServerNexts1_dic_CurrencySign");
        var CurrencySign = dic_CurrencySign.options[dic_CurrencySign.selectedIndex].value;
        var gameId = document.getElementById("ServerNexts1_txt_GameID").value;
        //        if (parseInt(UserID) > 0) {
        //            if ((parseInt(Discount) < 1) && (parseInt(gameId) == 1)) {
        //                document.getElementById("td_vipPrice").style.display = "inline";
        //            }
        //            else if ((parseInt(Discount) == 1) && (parseInt(gameId) == 1)) {
        //                document.getElementById("td_currentprice").style.display = "inline";
        //            }
        //            else if (parseInt(Discount) < 1) {
        //                document.getElementById("td_vipPrice").style.display = "inline";
        //            }

        //        }
        //        else {
        //            if (parseInt(gameId) == 1) {
        //                document.getElementById("td_currentprice").style.display = "inline";
        //            }
        //        }
        //--end 生成vip价格用---
        if (parseInt(UserID) > 0 && parseFloat(Discount) > 0 && parseFloat(Discount) < 1) {
            document.getElementById("td_vipPrice").style.display = "inline";
        }
        var parentObj = document.getElementById("ServerNexts1_lab_ProductList");
        var rowcount = 0;
        var td_text;
        var list_table = "<table width='100%'cellspacing='1' cellpadding='5' >\n";
        for (i = 0; i < DataTable.Rows.length; i++) {
            rowcount = rowcount + 1;
            if (rowcount % 2 == 1) { list_table += "<tr style='background: #fff url(../http://pics.goldsoon.fr/F1/templates/images/bgMid1.gif) repeat-x ;' onmouseover='onMouseOverStyle(this);' onmouseout='onMouseOutStyle(this);'>\n"; }
            else { list_table += "<tr style='background-color:#ffffff' onmouseover='onMouseOverStyle(this);' onmouseout='onMouseOutStyle(this);'>\n"; }
            if ((parseInt(gameId) == 45 || parseInt(gameId) == 46) && parseInt(DataTable.Rows[i].amount) == 5000) {
                list_table += "<td align='center' width='30%'>" + DataTable.Rows[i].num + "<img src='http://pics.goldsoon.fr/F1/templates/images/hotFont.gif' /></td>\n";
            }
            else if ((parseInt(gameId) == 45 || parseInt(gameId) == 46) && parseInt(DataTable.Rows[i].amount) == 10000) {
                list_table += "<td align='center' width='30%'>" + DataTable.Rows[i].num + "<img src='http://pics.goldsoon.fr/F1/templates/images/sale.gif' /></td>\n";
            }
            else if ((parseInt(gameId) == 15) && (DataTable.Rows[i].amount == 10000 || DataTable.Rows[i].amount == 5000 || DataTable.Rows[i].amount == 20000)) {
                list_table += "<td align='center' width='30%'>" + DataTable.Rows[i].num + "<img src='http://pics.goldsoon.fr/F1/templates/images/newhot.gif' style='vertical-align:middle;'/></td>\n";
            }
            else if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount > 15000)) {
                //-----------begin OF WOW 购买10000G以上赠送10%~15%活动-----------------------
                //                var clickFun = "GetIshalf(" + DataTable.Rows[i].gameid + "," + DataTable.Rows[i].serverid + "," + DataTable.Rows[i].amount + ",'" + DataTable.Rows[i].price + "'," + DataTable.Rows[i].specialnum + ",'" + parseFloat(DataTable.Rows[i].specialprice / 2) + "','" + CurrencySign + "')";
                //                list_table += "<td align='center' width='35%'>" + DataTable.Rows[i].num + "<img src='http://pics.goldsoon.fr/F1/templates/images/newhot.gif' style='vertical-align:middle;'/><br /><input type='checkbox' style='vertical-align:middle;' onclick=\"" + clickFun + "\" id=\"Checkbox" + DataTable.Rows[i].amount + "\" />&nbsp<span style=' font-weight:400; color:#666; '>" + DataTable.Rows[i].specialnum + DataTable.Rows[i].gameunit + "</span></td>\n";
                //-----------end OF WOW 购买10000G以上赠送10%~15%活动-----------------------
                list_table += "<td align='center' width='35%'>" + DataTable.Rows[i].num + "<img src='http://pics.goldsoon.fr/F1/templates/images/newhot.gif' style='vertical-align:middle;'/></td>\n";
            }
            else {
                list_table += "<td align='center' width='35%'>" + DataTable.Rows[i].num + "</td>\n";
            }

            //begin没有计算折扣的价格
            //            if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount > 15000)) {
            //                list_table += "<td align='center' width='15%'>" + DataTable.Rows[i].priceshow + "<br /><span style='font-weight:400; color:#666;text-decoration: line-through'>" + CurrencySign + parseFloat(DataTable.Rows[i].specialprice).toFixed(2) + "</span></td>\n";
            //            }
            //            else {
            //                if ((parseFloat(Discount) < 1)) {
            //                    if ((parseInt(gameId) == 1)) {
            //                        list_table += "<td align='center' width='15%'> " + DataTable.Rows[i].priceshow + " </td>\n";
            //                    }
            //                    else {
            //                        list_table += "<td align='center' width='15%'><span style='font-weight:400; color:#666;text-decoration: line-through'>" + DataTable.Rows[i].priceshow + "</span></td>\n";
            //                    }
            //                }
            //                else {
            //                    list_table += "<td align='center' width='15%'> " + DataTable.Rows[i].priceshow + "</td>\n";
            //                }

            //            }
            //end没有计算折扣的价格
            if (parseInt(UserID) > 0 && parseFloat(Discount) > 0 && parseFloat(Discount) < 1) {
                list_table += "<td align='center' width='15%'><span style='font-weight:400; color:#666;text-decoration: line-through'>" + DataTable.Rows[i].priceshow + "</span></td>\n";
            }
            else {
                list_table += "<td align='center' width='15%'> " + DataTable.Rows[i].priceshow + "</td>\n";
            }
            //--begin 生成vip价格---
            //            if (parseInt(UserID) > 0 && parseFloat(Discount) > 0) {
            //                if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount > 15000)) {
            //                    list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "<br />" + CurrencySign + parseFloat(DataTable.Rows[i].specialprice * parseFloat(Discount) / 2).toFixed(2) + "</td>\n";
            //                }
            //                else if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount <= 15000)) {
            //                    list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "</td>\n";
            //                }
            //                else if ((parseInt(gameId) == 54) && (parseInt(Discount) == 1)) {

            //                    list_table += "";
            //                }

            //                else if (parseFloat(Discount) < 1) {
            //                    list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "</td>\n";
            //                }
            //            }
            //            else {
            //                if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount > 15000)) {
            //                    list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "<br />" + CurrencySign + parseFloat(DataTable.Rows[i].specialprice * parseFloat(Discount) / 2).toFixed(2) + "</td>\n";
            //                }
            //                else if ((parseInt(gameId) == 1) && (DataTable.Rows[i].amount <= 15000)) {
            //                    list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "</td>\n";
            //                }
            //            }
            //--end 生成vip价格--
            if (parseInt(UserID) > 0 && parseFloat(Discount) > 0 && parseFloat(Discount) < 1) {
                list_table += "<td align='center' width='15%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "</td>\n";
            }
            else {

            }
            list_table += "<td align='center' width='35%'><input type='button'  class='btnbuy' value='Acheter'   onclick='InsertIntoTempOrder(" + DataTable.Rows[i].serverid + "," + DataTable.Rows[i].amount + "," + DataTable.Rows[i].price + ");'/></td>\n"
            list_table += "</tr>\n";
        }
        list_table += "</table>\n";
        parentObj.innerHTML = list_table;
    }
}

function specialNum(num) {
    var extraNum = 0;
    if (num == 10000) extraNum = 2000;
    if (num == 15000) extraNum = 4000;
    if (num == 20000) extraNum = 8000;
    if (num == 25000) extraNum = 10000;
    if (num == 30000) extraNum = 15000;
    if (num == 40000) extraNum = 20000;
    if (num == 50000) extraNum = 25000;
    if (num == 80000) extraNum = 30000;
    if (num == 100000) extraNum = 50000;

    return extraNum;
}

function specialPrice(ServerID, Amount, Currency) {
    var num = specialNum(Amount);
    var extralPrice = AjaxMethod.GetPrice(ServerID, num, Currency).value;
    extralPrice = extralPrice.replace(Currency, "");
    return parseFloat(extralPrice / 2);
}

var Global;
//判断该数量是否要进入半价活动
function GetIshalf(GameID, ServerID, Amount, Price, Halfnumber, Halfprice, CurrencyMark) {
    var Discount = document.getElementById("ServerNexts1_txt_Discount").value;
    if (GameID == 1 && Amount >= 15000) {

        var chks = document.getElementById("Checkbox" + Amount);

        if (chks.checked) {
            graydiv(GameID, ServerID, Amount, CurrencyMark + parseFloat(Price * Discount).toFixed(2), Halfnumber, CurrencyMark + parseFloat(Halfprice * Discount).toFixed(2));
            Global = [ServerID, Amount, Price];
        }
    }

}
function InsertIntoTempOrder(ServerID, Amount, Price) {
    var UserID = document.getElementById("ServerNexts1_txt_UserID").value;
    var IpStr = document.getElementById("ServerNexts1_txt_IpStr").value;
    var Product = document.getElementById("ServerNexts1_lab_ProductName").innerHTML;
    var GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName").value;
    if (GameTypeName.toLowerCase() != 'gold') {
        Product = Product + "-" + GameTypeName;
    }
    var dic_Currency = document.getElementById("ServerNexts1_dic_CurrencySign");
    var PayType = dic_Currency.options[dic_Currency.selectedIndex].value;
    AjaxMethod.TempOrderAdd(UserID, IpStr, ServerID, Product, Price, Amount, PayType, 'goldsoon', InsertIntoTempOrder_CallBack);
}

function InsertIntoTempOrder_CallBack(response) {
    if (response.error != null) {
        //alert(response.error);
        return;
    }
    var ReturnStr = response.value;
    if (ReturnStr == "0") {
        alert("error");
        return;
    }
    else {
        goToNextPage(ReturnStr);
    }
}

function ChangeImagUrl(flag) {
    var image = new Array();
    image[0] = "http://pics.goldsoon.fr/F1/templates/images/btn_alliance.gif";
    image[1] = "http://pics.goldsoon.fr/F1/templates/images/btn1_alliance.gif";
    image[2] = "http://pics.goldsoon.fr/F1/templates/images/btn_horde.gif";
    image[3] = "http://pics.goldsoon.fr/F1/templates/images/btn1_horde.gif";
    image[4] = "http://pics.goldsoon.fr/F1/templates/images/ad/f_back.gif";
    image[5] = "http://pics.goldsoon.fr/F1/templates/images/ad/f_back01.gif";
    image[6] = "http://pics.goldsoon.fr/F1/templates/images/ad/k_back.gif";
    image[7] = "http://pics.goldsoon.fr/F1/templates/images/ad/k_back01.gif";
    var Img_Alliance = document.getElementById("img_Alliance");
    var Img_Horde = document.getElementById("img_Horde");
    var img_Federation = document.getElementById("img_Federation");
    var img_Klingon = document.getElementById("img_Klingon");
    var lab_GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName");
    var lab_flag = document.getElementById("ServerNexts1_lab_flag");
    if (flag == 0) {
        Img_Alliance.src = image[0];
        Img_Horde.src = image[2];
        lab_GameTypeName.value = 'Alliance';
        lab_flag.innerHTML = "&nbsp;&nbsp;Vous êtes dans l' <a style='font-weight: bold; font-size:18px; color: #C30202'>Alliance</a>,Cliquez <a style='font-weight:normal;color:#223D76; text-decoration:underline;cursor:pointer;' onclick='ChangeImagUrl(1)'>Ici</a> pour la <a style='font-weight:bold;'>Horde</a>.";
    }
    else if (flag == 1) {
        Img_Alliance.src = image[1];
        Img_Horde.src = image[3];
        lab_GameTypeName.value = 'Horde';
        lab_flag.innerHTML = "&nbsp;&nbsp;Vous êtes  à la<a style='font-weight: bold; font-size:18px; color:#C30202'>Horde</a>,Cliquez <a style='font-weight:normal;color:#223D76; text-decoration:underline;cursor:pointer;' onclick='ChangeImagUrl(0)'>Ici</a> pour l' <a style='font-weight:bold;'>Alliance</a>."; ;
    }
    else if (flag == 2) {
        img_Federation.src = image[4];
        img_Klingon.src = image[7];
        lab_GameTypeName.value = 'Federation';
        lab_flag.innerHTML = "&nbsp;&nbsp;Vous êtes  à la<a style='font-weight: bold; font-size:18px; color:#C30202'>Federation</a>.";
    }
    else if (flag == 3) {
        img_Federation.src = image[5];
        img_Klingon.src = image[6];
        lab_GameTypeName.value = 'Klingon';
        lab_flag.innerHTML = "&nbsp;&nbsp;Vous êtes  à la<a style='font-weight: bold; font-size:18px; color:#C30202'>Klingon</a>.";
    }
    LoadProductList();
}

function PostData(TempID) {
    PostUrl = "OrderNext.aspx";
    var FormStr;
    FormStr = "<form id=\"form2\" method=\"post\" action=\"" + PostUrl + "\"><input name=\"TempID\" type=\"hidden\" id=\"TempID\" value=\"" + TempID + "\"><\/form><script language=\"javascript\">document.getElementById('form2').submit();<\/script>";
    document.write(FormStr);
}

function goToNextPage(TempID) {
    var Product = document.getElementById("ServerNexts1_lab_ProductName").innerHTML;
    var GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName").value;
    if (GameTypeName.toLowerCase() != 'gold') {
        Product = Product + "-" + GameTypeName;
    }
    Product = Product.replace(/( )/g, "");
    Product = Product.replace(/(-)/g, "_");
    Product = Product.replace(/(')/g, "");
    if (document.getElementById("ServerNexts1_txt_UserID").value > 0) {
        location.href = Product + '_gold_order_' + TempID + ".html";
    }
    else {
        location.href = Product + '_gold_login_' + TempID + ".html";
    }
}

var currentColor;
function onMouseOverStyle(obj) {
    currentColor = obj.style.backgroundColor;
    obj.style.backgroundColor = '#FEEBBC';
    obj.style.fontWeight = '';
}
function onMouseOutStyle(obj) {
    obj.style.backgroundColor = currentColor;
    obj.style.fontWeight = '';
}

function graydiv() {
    document.getElementById("graydiv").style.height = document.body.clientHeight + "px";
    document.getElementById("graydiv").style.width = window.screen.width + "px";
}
function closeHide() {
    var objHide = document.getElementById("closeHide")
    if (objHide.style.display == "block") {
        objHide.style.display = "none";
    }

}

function graydiv() {
    document.getElementById("graydiv").style.height = document.body.clientHeight + "px";
}
function closeHide() {
    var objHide = document.getElementById("closeHide")
    if (objHide.style.display == "block") {
        objHide.style.display = "none";
    }
}


function graydiv(GameID, ServerID, Amount, Price, Halfnumber, Halfprice) {

    document.getElementById("y_amount").innerHTML = Amount;
    document.getElementById("h_amount").innerHTML = Halfnumber;
    document.getElementById("y_price").innerHTML = Price;
    document.getElementById("h_price").innerHTML = Halfprice;
    document.getElementById("closeHide").style.display = "block";
    document.getElementById("graydiv").style.height = document.body.clientHeight + "px";
    var cbs = $("#Checkbox" + Amount);
    var tr = cbs.parent().parent();
    var offset = tr.offset();
    var tops = offset.top - 10;
    $("#showwindow02").css("top", tops);
}
function closeHide() {
    var objHide = document.getElementById("closeHide")
    if (objHide.style.display == "block") {
        objHide.style.display = "none";
    }
    var chks = document.getElementById("Checkbox" + Global[1]);
    chks.checked = false;

}

function GetBuy() {
    var UserID = document.getElementById("ServerNexts1_txt_UserID").value;
    var IpStr = document.getElementById("ServerNexts1_txt_IpStr").value;
    var Product = document.getElementById("ServerNexts1_lab_ProductName").innerHTML;
    var GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName").value;
    if (GameTypeName.toLowerCase() != 'gold') {
        Product = Product + "-" + GameTypeName;
    }
    var dic_Currency = document.getElementById("ServerNexts1_dic_CurrencySign");
    var PayType = dic_Currency.options[dic_Currency.selectedIndex].value;
    AjaxMethod.TempOrderAdd_two(UserID, IpStr, Global[0], Product, Global[2], Global[1], PayType, 'goldsoon', InsertIntoTempOrder_CallBack);
}

function InsertIntoTempOrder2(ServerID, Amount, Price) {
    var UserID = document.getElementById("ServerNexts1_txt_UserID").value;
    var IpStr = document.getElementById("ServerNexts1_txt_IpStr").value;
    var Product = document.getElementById("ServerNexts1_lab_ProductName").innerHTML;
    var GameTypeName = document.getElementById("ServerNexts1_lab_GameTypeName").value;
    if (GameTypeName.toLowerCase() != 'gold') {
        Product = Product + "-" + GameTypeName;
    }
    var dic_Currency = document.getElementById("ServerNexts1_dic_CurrencySign");
    var PayType = dic_Currency.options[dic_Currency.selectedIndex].value;
    AjaxMethod.TempOrderAdd_two(UserID, IpStr, ServerID, Product, Price, Amount, PayType, 'goldsoon', InsertIntoTempOrder_CallBack);
}
