﻿function changeCurrency() {
    LoadProductList();
}

function LoadProductList() {
    try {
        var GameID = document.getElementById("ServerNexts1_txt_GameID").value;
        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);
    } catch (e) {
    }
}
function LoadProductList_CallBack(response) {
    try {
        if (response.error != null) {
            //alert(response.error);
            return;
        }
        var ReturnStr = response.value;
        RenderList(ReturnStr);
    } catch (e) {
    }
}
function RenderList(DataTable) {
    try {
        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) {
                document.getElementById("td_vipPrice").style.display = "inline";
            }
            //--end 生成vip价格用---
            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;cursor: pointer;' onmouseover='onMouseOverStyle(this);' onmouseout='onMouseOutStyle(this);' onclick='InsertIntoTempOrder(" + DataTable.Rows[i].serverid + "," + DataTable.Rows[i].amount + "," + DataTable.Rows[i].price + ");'>\n"; }
                else { list_table += "<tr style='background-color:#FFFAED;cursor: pointer;' onmouseover='onMouseOverStyle(this);' onmouseout='onMouseOutStyle(this);' onclick='InsertIntoTempOrder(" + DataTable.Rows[i].serverid + "," + DataTable.Rows[i].amount + "," + DataTable.Rows[i].price + ");'>\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.com/C1/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.com/C1/templates/images/sale.gif' /></td>\n";
                }
//                else if ((parseInt(gameId) == 15 || parseInt(gameId) == 1) && parseInt(DataTable.Rows[i].amount) >= 10000) {
//                    list_table += "<td align='center' width='30%'><img src='http://pics.goldsoon.com/C1/templates/images/ad/num_adFr_07.jpg' style='vertical-align:middle;'/>&nbsp;" + DataTable.Rows[i].num + "&nbsp;<span style=' font-weight:bold; color:#cb0000;'>+" + DataTable.Rows[i].amount * 0.1 + "G</span></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.com/C1/templates/images/newhot.gif' style='vertical-align:middle;'/></td>\n";
                }
                else {
                    list_table += "<td align='center' width='30%'>" + DataTable.Rows[i].num + "</td>\n";
                }
                list_table += "<td  align='center' width='14%'>" + DataTable.Rows[i].unitpriceshow + "</td>\n";
                list_table += "<td align='center' width='14%'>" + DataTable.Rows[i].priceshow + "</td>\n";
                //--begin 生成vip价格---
                if (parseInt(UserID) > 0 && parseFloat(Discount) > 0) {
                    list_table += "<td align='center' width='12%' style='font-weight:bold; color:#ce0000;'>" + CurrencySign + parseFloat(parseFloat(DataTable.Rows[i].price) * parseFloat(Discount)).toFixed(2) + "</td>\n";
                }
                //--end 生成vip价格--
                list_table += "<td align='center' width='30%'><input type='button' class='btn_addtocart' value='' /></td>\n"
                list_table += "</tr>\n";
            }
            list_table += "</table>\n";
            parentObj.innerHTML = list_table;
        }
    } catch (e) {
    }
}

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) {
    try {
        var image = new Array();
        image[0] = "http://pics.goldsoon.com/C1/templates/images/btn_alliance.gif";
        image[1] = "http://pics.goldsoon.com/C1/templates/images/btn1_alliance.gif";
        image[2] = "http://pics.goldsoon.com/C1/templates/images/btn_horde.gif";
        image[3] = "http://pics.goldsoon.com/C1/templates/images/btn1_horde.gif";
        image[4] = "http://pics.goldsoon.com/C1/templates/images/ad/f_back.gif";
        image[5] = "http://pics.goldsoon.com/C1/templates/images/ad/f_back01.gif";
        image[6] = "http://pics.goldsoon.com/C1/templates/images/ad/k_back.gif";
        image[7] = "http://pics.goldsoon.com/C1/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;You are in <a style='font-weight: bold; font-size:18px; color: #C30202'>alliance</a>,Click <a style='font-weight:normal;color:#223D76; text-decoration:underline;cursor:pointer;' onclick='ChangeImagUrl(1)'>Here</a> for <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;You are in <a style='font-weight: bold; font-size:18px; color:#C30202'>Horde</a>,Click <a style='font-weight:normal;color:#223D76; text-decoration:underline;cursor:pointer;' onclick='ChangeImagUrl(0)'>Here</a> to <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;You are in <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;You are in <a style='font-weight: bold; font-size:18px; color:#C30202'>Klingon</a>.";
        }
        LoadProductList();
    } catch (e) {
    }
}

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 = '';
}