﻿// JScript 文件
function GetLocalIPAddress()
{
    var obj = null;
    var rslt = "";
    try
    {
        obj = new ActiveXObject("rcbdyctl.Setting");
        rslt = obj.GetIPAddress;
        obj = null;
    }
    catch(e)
    {
        //异常发生
        rslt = "";
    }
    
    return rslt;
}

function mouseOver(obj)
{
    obj.className="cssButtonHover button_buy_now button_buy_nowHover";
}

function mouseOut(obj)
{
    obj.className = "cssButton button_buy_now";
}

function InsertIntoTempOrder(serverId,amount,price)
{
    var userId = 0;
    if(document.getElementById("ServerNext_UC1_txt_UserId").value != "")
    {
        userId = document.getElementById("ServerNext_UC1_txt_UserId").value;
    }
    var ipStr = document.getElementById("ServerNext_UC1_txt_IpStr").value;
    var product = document.getElementById("ServerNext_UC1_lab_product").innerHTML;
    var controCurrency = document.getElementById("dic_currency");
    var payType = controCurrency.options[controCurrency.selectedIndex].value;
    AjaxMethod.TempOrderAdd(userId,ipStr,serverId,product,price,amount,payType,'raidgold',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 goToNextPage(tempId)
{   
    var Product = document.getElementById("ServerNext_UC1_lab_product").innerHTML;
    Product = Product.replace(/( )/g,"");
    Product = Product.replace(/(')/g,"");
    var userId = document.getElementById("ServerNext_UC1_txt_UserId").value;
    if(userId != "" && parseInt(userId) > 0)
    {
        location.href = Product + '-gold-order-' + tempId + ".html";
    }
    else
    {
        location.href= Product + "-gold-login-" + tempId + ".html";
    }
}

function loadProductList()
{
    var url = window.location.href;
    var urlArray;
    var paraStr;
    var gameId = 0;
    var serverId = 0;
    if(url.indexOf(".html") > 0)
    {
        url = url.replace(".html","").replace("http://www.raidgold.fr/","");
        urlArray = url.split("-");
        paraStr = urlArray[urlArray.length - 1].split("_");
        gameId = paraStr[0];
        serverId = paraStr[1];
    }
    if(url.indexOf(".aspx") > 0)
    {
        url = url.replace(".aspx","").replace("http://www.raidgold.fr/","");
        urlArray = url.substring(url.indexOf("?")+1,url.length).split("&");
        //paraStr = urlArray[urlArray.length - 1].split("_");
        gameId = urlArray[0].split("=")[1];
        serverId = urlArray[1].split("=")[1];
    }
    var control_Currency = document.getElementById("dic_currency");
    var currency = control_Currency.options[control_Currency.selectedIndex].value;
    AjaxMethod.LoadProductList(gameId,serverId,currency,loadProductList_CallBack);
}

function loadProductList_CallBack(response) {
    if (response.error != null) {
        return;
    }
    var dataTable = response.value;
    var str = "<table width='100%' border='0' cellspacing='0' cellpadding='0' id='cat7_94Table' class='tabTable'>";
    str += "<tr class='productListing-rowheading'>";
    str += "<th class='productListing-heading' align='left' scope='col' id='listCell0-0'>Item Name</th>";
    str += "<th class='productListing-heading' align='left' width='125' scope='col' id='listCell0-1'>Price</th>";
    str += "<th class='productListing-heading' align='right' scope='col' id='listCell0-2'>&nbsp;Buy Now&nbsp;</th>";
    str += "</tr>";
    var amount;
    var gameId = parseInt(document.getElementById("ServerNext_UC1_txt_GameId").value);
    for (i = 0; i < dataTable.Rows.length; i++) {
        if (i % 2 == 0) {
            str += "<tr class='productListing-odd'>";
        }
        else {
            str += "<tr class='productListing-even'>";
        }
        var urlstring = dataTable.Rows[i].product.replace(/( )/g, "").replace(/(')/g, "") + "-p-" + dataTable.Rows[i].serverid;
        //数量赠送金币百分比活动20100623
        amount = dataTable.Rows[i].amount;
//        if (gameId == 1) {
//            if (amount >= 10000) {
//                if (amount == 10000 || amount == 30000) {
//                    str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a  href='#' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + amount + "," + dataTable.Rows[i].price + ");'><font  color=\"#FF0000\">" + dataTable.Rows[i].product + "+ [" + MarketingOperate(gameId, amount) + "G for free]" + "</font></a></h3><div class='listingDescription'></div></td>";
//                }
//                else {
//                    str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a href='#' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + amount + "," + dataTable.Rows[i].price + ");'>" + dataTable.Rows[i].product + "+ [" + MarketingOperate(gameId, amount) + "G for free]" + "</a></h3><div class='listingDescription'></div></td>";
//                }

//            }
//            else {
//                if (amount == 5000) {
//                    str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a href='#' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + amount + "," + dataTable.Rows[i].price + ");'><font  color=\"#FF0000\">" + dataTable.Rows[i].product + "</font></a></h3><div class='listingDescription'></div></td>";
//                }
//                else {
//                    str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a href='#' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + amount + "," + dataTable.Rows[i].price + ");'>" + dataTable.Rows[i].product + "</a></h3><div class='listingDescription'></div></td>";
//                }
//            }
//        }
//        else {
            str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a href='#' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + amount + "," + dataTable.Rows[i].price + ");'>" + dataTable.Rows[i].product + "</a></h3><div class='listingDescription'></div></td>";
//        }
        //str += "<td class='productListing-data' align='left'><h3 class='itemTitle'><a href='" + urlstring + ".html'>" + dataTable.Rows[i].product + "</a></h3><div class='listingDescription'></div></td>";
        str += "<td class='productListing-data' align='left'>" + dataTable.Rows[i].priceshow + "<br /></td>";
        str += "<td class='productListing-data' align='right'><span id='btn_buy' class='cssButton button_buy_now' onmouseover='mouseOver(this);' onmouseout='mouseOut(this);' onclick='InsertIntoTempOrder(" + dataTable.Rows[i].serverid + "," + dataTable.Rows[i].amount + "," + dataTable.Rows[i].price + ");' style='width: 84px;cursor: pointer;' >&nbsp;Buy Now&nbsp;</span><br /></td>";
        str += "<tr>";
    }
    str += "</table>";
    var parentObj = document.getElementById("ServerNext_UC1_lab_ProductList");
    parentObj.innerHTML = str;
}
function MarketingOperate(gameID, amount) {
    /// <summary>
    /// 数量赠送金币百分比活动20100623
    /// </summary>
    if (gameID == 1) {
        var marketDiscount = Marketing(gameID, amount);
        return amount * marketDiscount;
    }
    return 0;
}
function Marketing(gameID, amount) {
    var marketDiscount = 0;
    if (gameID == 1) {
        if (10000 <= amount && amount <= 25000) {
            marketDiscount = 0.1;
        }
        else if (30000 <= amount && amount <= 100000) {
            marketDiscount = 0.15;
        }
        else {
            marketDiscount = 0;
        }
    }
    return marketDiscount;
}
