﻿function UsePropCard(useurl,propid,usecount,successfn)
{
    var obj = this;
    this.BuyPropCard = function(buycount,buymethod){
        Http.get('/widget/buy.aspx?propid='+propid+'&buycount='+buycount+'&buymethod='+buymethod+'&date='+escape(Date().toString()) ,
        function(retext){
            var buystate = JSON.parse(retext);
            if(buystate.IsSuccess){
                kg.Confirm('购买成功，已保存于你的道具箱，需要马上使用吗？','道具使用',obj.Use,null,500,'是','否','why',true);
            }else{
                kg.Alert(buystate.Error,'',null,0,'确定','error',true);
            }
        },
        function(){
            kg.Alert('抱歉，购买道具失败，请重新购买。','',null,0,'确定','error',true);
        }
        );
    }
    
    this.CheckPropCard = function()
    {
        Http.get('/widget/checkuse.aspx?propid='+propid+'&usecount='+usecount+'&date='+escape(Date().toString()) ,
        function(retext){
            eval(retext);
        },
        function(){
            kg.Alert('抱歉，道具使用失败，请重新使用。','',null,0,'确定','error',true);
        }
        );
    }
    
    this.Use = function ()
    {
        if(useurl.indexOf('?')!=-1)
        {
            useurl += "&";
        }
        else
        {
            useurl += "?";
        }
        Http.get(useurl+'date='+escape(Date().toString()) ,
        function(retext){
            var usestate = JSON.parse(retext);
            if(usestate.IsSuccess){
                kg.Alert('哇，好厉害，道具使用成功了！','',null,0,'确定','ok',true);
                if(successfn)successfn();
            }else{
                kg.Alert(usestate.Error,'',null,0,'确定','error',true);
            }
        },
        function(){
            kg.Alert('抱歉，道具使用失败，请重新使用。','',null,0,'确定','error',true);
        }
        );
    }
}