﻿
    var dllstart = document.getElementById("buy_level_start");
    var dllstop = document.getElementById("buy_level_stop");
 
    
    var _lvstart = new Array();
    var _lvstop = new Array();
    var gid = document.getElementById("txtGameID").value;
    
    var start = 0;
    var stop = 0;
    
    var dvlevel = document.getElementById("dvLevel");
    
    var lvl_btnbuy = document.getElementById("btnBuyLeveling");
    
    var inputstart = document.getElementById("txtStart"); 
    var inputstop = document.getElementById("txtStop"); 
    
    function bindStart()
    {
        dllstart.options.length = 0;
        if(gid>0)
        {
            _lvstart = GamePowerLeveling.Ajax_GetStart(gid).value;
            if(_lvstart != null)
            {
                var len = _lvstart.length;
                if(len>0)
                {
		    var maxstart=0;//2010-01-25
                    for(var i = 0;i<len-1;i+=2)
                    {
                        var opt = document.createElement("option");
                        opt.text = _lvstart[i].toString();
                        opt.value = _lvstart[i+1].toString();
                        dllstart.options.add(opt);
			maxstart=maxstart+1;//2010-01-25
                    }
		    if(maxstart>69)  dllstart.selectedIndex=69;//2010-01-25
                }
                else
                    cannotbuy("Not find the level grade!");
            }
            else
                cannotbuy("Not find the level grade!");
        }
        else
            cannotbuy("Not find the game!");
    }
    
    function bindStop()
    {
        if(dllstart.selectedIndex >= 0)
        {
            start = dllstart.options[dllstart.selectedIndex].text;
            var stopselected = 0;
            if(dllstop.selectedIndex >= 0)
            {
                stop = dllstop.options[dllstop.selectedIndex].text;
                if(start < stop && start.length <= stop.length)
                    stopselected = dllstop.options.selectedIndex
            }
            dllstop.options.length = 0;
            
            if(gid>0)
            {
                if(dllstart.selectedIndex >= 0)
                {
                    //start = dllstart.options[dllstart.selectedIndex].text; //2010-01-25
		    //if(start<10) //2010-01-25
	                start=10;
                    _lvstop = GamePowerLeveling.Ajax_GetStop(gid,start).value;
                    if(_lvstop != null)
                    {
                        var len = _lvstop.length;
                        if(len>0)
                        {
                            for(var i = 0;i<len-1;i+=2)
                            {
                                var opt = document.createElement("option");
                                opt.text = _lvstop[i].toString();
                                opt.value = _lvstop[i+1].toString();
                                dllstop.options.add(opt);
                            }
                            dllstop.selectedIndex = stopselected;
                        }
                        else
                            cannotbuy("Not find the desired level!");
                    }
                    else
                        cannotbuy("Not find the desired level!");
                }
                else
                    cannotbuy("Not find the start level!");
            }
            else
                cannotbuy("Not find the game!");
        }
        else
            cannotbuy("Not find the start level!");
    }
    
    function bindReckon()
    {
        if(dllstart.selectedIndex >=0 && dllstop.selectedIndex >= 0)
        {
            gid = document.getElementById("txtGameID").value;
            start = dllstart.options[dllstart.selectedIndex].text;
            stop = dllstop.options[dllstop.selectedIndex].text;
            
            if(start >= stop && start.length >= stop.length)
                cannotbuy("The start level must be less than the desired level!");
            else
            {
                var val = GamePowerLeveling.Ajax_Reckon(gid,start,stop).value;
                if(val != null)
                    canbuy(val);
                else
                    cannotbuy("unknow error");
            }
        }
        else
            cannotbuy("Not find the level grade!");
    }
    
    
    function chageYourLevel()
    {
        //bindStop();
        bindReckon();
    }
    
    function chageStopLevel()
    {
        bindReckon();
    }
    
    //chageYourLevel();
    
    function buyLevel()
    {
        start = dllstart.options[dllstart.selectedIndex].text;
        stop = dllstop.options[dllstop.selectedIndex].text;        
        inputstart.value = start;
        inputstop.value = stop;
        //UserControl_BuyGold.GoOrder(gid,sid,pid);
    }
        
    bindStart();
    bindStop();
    bindReckon();
        
    function cannotbuy(paras)
    {
        var tips = "<li>" + 
                        "<span class=" + '"' + "spla" + '"' +" style=" + '"' + "width:446px;" + '"' + ">" + 
                            paras + 
                        "</span>" + 
                   "</li>";
        dvlevel.innerHTML = tips;
        lvl_btnbuy.setAttribute('class', 'button_buylevel2no');
        lvl_btnbuy.setAttribute('style','background:url(../common/style/orange/images/btn_buyno.gif);');
        lvl_btnbuy.disabled = 'disabled';
    }
    
    function canbuy(price)
    {
        dvlevel.innerHTML = price;        
        lvl_btnbuy.setAttribute('class', 'button_buylevel2');
        lvl_btnbuy.setAttribute('style','background:url(../common/style/orange/images/btn_buy.gif);');
        lvl_btnbuy.disabled = false;
    }