﻿// JScript 文件
//创建商品对象
var Product; 
if(!Product) 
    Product={};
    

Product.Info=function()
{
    this.GameId=this.$GID();
    this.CurrentLevel=this.$CL();
    this.DesiredLevel=this.$DL();
    this.ServerID=this.$SID();
    this.GoldNum=this.$GN();
};

//获取游戏ID
Product.Info.prototype.$GID=function()
{
    return $("UC_PLLevel1_HF_GameID").value;
};

//获取CurrentLevel
Product.Info.prototype.$CL=function()
{
    var CL="0";
    var DDL_Cl=$("UC_PLLevel1_DDL_CurrentLevel");
    CL=DDL_Cl.options[DDL_Cl.selectedIndex].value;
    return CL;
};

//获取DesiredLevel
Product.Info.prototype.$DL=function()
{
    var DL="0";
    var DDL_Dl=$("UC_PLLevel1_DDL_DesiredLevel");
    DL=DDL_Dl.options[DDL_Dl.selectedIndex].value;
    return DL;
};

//获取serverID
Product.Info.prototype.$SID=function()
{
    var SID="0";
    var DDL_SID=$("UC_PLLevel1_DDL_ServerList");
    SID=DDL_SID.options[DDL_SID.selectedIndex].value;
    return SID;
};

//获取GoldNum
Product.Info.prototype.$GN=function()
{
    var GN="0";
    var DDL_GN=$("UC_PLLevel1_DDL_Gold");
    GN=DDL_GN.options[DDL_GN.selectedIndex].value;
    return GN;
};

//等级控制
function checkCustomPL()
{
    startLevel = trim($("UC_PLLevel1_DDL_CurrentLevel").value);
    endLevel = trim($("UC_PLLevel1_DDL_DesiredLevel").value);
    if(startLevel == ""){
	    alert("remplissez votre niveau actuel.");
	    return false;
    }

    if(endLevel == ""){        
	    alert("remplissez votre niveau désiré.");
	    return false;
    }

    if(!isnumber(startLevel)){
        $("UC_PLLevel1_price").value="";
        $("UC_PLLevel1_time").value="";
	    return false;
    }

    if(!isnumber(endLevel)){
       $("UC_PLLevel1_DDL_DesiredLevel").selectedIndex=1;
    }

    if(parseInt(startLevel)<1 || parseInt(endLevel)>80 || parseInt(startLevel)>=parseInt(endLevel)){
        if(parseInt(startLevel)==80)
        {
	        $("UC_PLLevel1_DDL_DesiredLevel").selectedIndex=0;
	        $("UC_PLLevel1_DDL_CurrentLevel").selectedIndex=79;
	    }
	    else
	    {
	        $("UC_PLLevel1_DDL_DesiredLevel").selectedIndex=81-parseInt(startLevel)-1;
	    }
    }
    GetAllPrice();
    return true;
}
function checkCustomPL1()
{
    startLevel = $("PLDetail1_DDL_CurrentLevel").value;
    endLevel = $("PLDetail1_DDL_DesiredLevel").value;
    if(startLevel == ""){
	    alert("remplissez votre niveau actuel.");
	    return false;
    }

    if(endLevel == ""){
	    alert("remplissez votre niveau désiré.");
	    return false;
    }    

    if(parseInt(startLevel)<1 || parseInt(endLevel)>80 || parseInt(startLevel)>=parseInt(endLevel)){
        if(parseInt(startLevel)==80)
        {
	        $("PLDetail1_DDL_DesiredLevel").selectedIndex=0;
	        $("PLDetail1_DDL_CurrentLevel").selectedIndex=78;
	    }
	    else
	    {
	        $("PLDetail1_DDL_DesiredLevel").selectedIndex=80-parseInt(startLevel)-1;
	    }
    }
    GetLevelingPrice();
    return true;
}
function checkExtraGold()
{
    var server = trim($("UC_PLLevel1_DDL_ServerList").value);
    var DDL_GN=$("UC_PLLevel1_DDL_Gold");
    var goldnum=0;
    goldnum=DDL_GN.options[DDL_GN.selectedIndex].value;
    if(goldnum != 0 && server == '0')
    {
        alert('choisissez le serveur,S.V.P.');
        DDL_GN.selectedIndex=0;
        return false;
    }
    GetAllPrice();
    return true;
}

function CheckLeveling(obj)
{
    var start=document.getElementById("UC_PLLevel1_DDL_CurrentLevel").value;
    var end=document.getElementById("UC_PLLevel1_DDL_DesiredLevel").value;
    if(CheckServer())
    {
        if(parseInt(start)>=parseInt(end))
        {
            alert("Yvotre niveau actuel doit être moins que votre niveau désiré .");
            return false;
        }
        else
        {
             return CheckPrice(obj);
        }
    }
    else
        return false;
}
//检查是否选择了服务器
function CheckServer()
{
    var selServer=document.getElementById('UC_PLLevel1_DDL_ServerList');
    if( selServer!=null&&selServer.selectedIndex==0)
    {
        alert("choisissez le serveur,S.V.P.!");
        return false;
    }
    else
        return true;
}

//检查价格
function CheckPrice(obj)
{
    var price=document.getElementById(obj).value.replace(/(^\s*)|(\s*$)/g, "");
    if(price=="")
    {
        alert("choisissez votre service");
        return false;
    }
    else
        return true;
}

function GetAllPrice()
{
   var myProduct=new Product.Info();     
    var catagoryID=$("UC_PLLevel1_HF_LevelCategoryID").value+"," + $("UC_PLLevel1_HF_GoldCategoryID").value;    
    var currencyID=$("UC_PLLevel1_HF_CurrencyID").value;
    Rep_AjaxMethod.GetPriceInfo(myProduct.GameId,myProduct.CurrentLevel,myProduct.DesiredLevel,myProduct.ServerID,myProduct.GoldNum,currencyID,catagoryID,GetPrice_CallBack);
}

function GetPrice_CallBack(responseObject)
{
    //转换为JSON对象
    var JsonValue=eval("("+responseObject.value+")");
    if(JsonValue!=null)
    {
        var needTime=Math.floor(JsonValue.NeedTime);
        if(needTime<2)
            needTime=1;    
        $("UC_PLLevel1_price").value=JsonValue.Price;
        $("UC_PLLevel1_time").value=needTime+"-"+ (needTime+1);
    }
    
}
function GetLevelingPrice()
{
    var gameid=$("UC_PLLevel1_HF_GameID").value;
    var start=$("PLDetail1_DDL_CurrentLevel").value;
    var end=$("PLDetail1_DDL_DesiredLevel").value;
    var currencyID=$("UC_PLLevel1_HF_CurrencyID").value;
    Rep_AjaxMethod.GetLevelingPrice(gameid,start,end,currencyID,Leveling_CallBack);
}
function Leveling_CallBack(response)
{
    if(response.error != null) //发生错误
    {
        alert(response.error);
        return;
    }
    else
    {
       var needTime=Math.floor(response.value[1]);
       if(needTime<2)
            needTime=1;
       document.getElementById("PLDetail1_price").value=response.value[0];
       document.getElementById("PLDetail1_time").value=needTime+"-"+(needTime+1);        
    }
}
//通过ID获取对象
function $(id) 
{ 
    return document.getElementById(id); 
}
//通过ID获取值
function $V(id) 
{ 
    var returnValue="";
    var len=id.indexOf("_");
    if(len>0)
    {
        var myArr=id.split("_");
        var num=myArr.length;
        returnValue=myArr[num-1];
    }
    return returnValue;
}
