﻿function showTopUpPanel() 
{
    window.parent.document.getElementById("head_topUp").click();
}

/*购买短信*/
 function Disabled(t) {
     if (t > currentUserCoin) {
            $('#_btDialogOK').attr('disabled', 'disabled');
            $('#_btDialogOK').val('余额不足');  
        }
        else {
            $('#_btDialogOK').attr('disabled', '');
            $('#_btDialogOK').val('确定购买');
        }
    }
    $(function() {               
       setbuyButton();
    });
     //购买
    function buy()
    {
        Dialog.Confirm('是否购买?', function () {
            AjaxRequest.Post("_btDialogOK", "ap_buyForm", function (Content) {
                if (Content["Status"] == "Success") {
                    $("[name='rdTypes']").each(function () {
                        if (this.checked) {                           
                            currentUserCoin = currentUserCoin - Number($(this).attr("title"));
                        }
                    });
                    $("#buyMsgDialogCoin").html(currentUserCoin);
                    Dialog.Success(Content["Tip"]);
                }
                else if (Content["Status"] == "Alert") {
                    Dialog.Alert(Content['Tip']);
                }
                else {
                    Dialog.Fail(Content['Tip']);
                }

                setbuyButton();
            });
        });
       
    }
    
    function setbuyButton()
    {      
         $('input[name=rdTypes]').each(function() {
            $(this).click(function() {
                Disabled($(this).attr('title'));
            });
        });
        if($('input[name=rdTypes]').length>=2)
        {
        $('input[name=rdTypes]')[1].click();    
        }
    }

    //更新设置
    function settel(){
        var telnum=$("#edittelnum").val();
        if(telnum=="")
        {
        Dialog.Alert("手机号码不能为空!");
        }
    
        AjaxRequest.Post("btnset","ap_buyForm",function(Content){
    
            if(Content["Status"]=="Success")
            {
                Dialog.Success(Content["Tip"]);                  
            }
            else if(Content["Status"]=="Alert")
            {
            Dialog.Alert(Content['Tip']);
            }
            else{
                 Dialog.Fail(Content['Tip']);
            }

            setbuyButton();
        });      
    }

    secs = 60;
    wait = secs * 1000;
    function sendButton() {
        $("#btnsend").attr("disabled", true);
        for (i = 1; i <= (wait / 1000); i++) {
            window.setTimeout("doUpdate(" + i + ")", i * 1000);
        }
        window.setTimeout("Timer()", wait);
    }
    function doUpdate(num) {
        if (num == (wait / 1000)) {
            $("#btnsend").val("获取验证码 ");
        } else {
            wut = (wait / 1000) - num;
            $("#btnsend").attr("disabled", true);
            $("#btnsend").val("获取验证码(" + wut + ")");
        }
    }

    function Timer() {
        $("#btnsend").attr("disabled", false);
    }




    //验证
    function chkcode()
    {           
        var code=$("#txtcode").val();
        if(code=="")
        {
            Dialog.Alert("验证码不能为空!");
            return;
        }
        AjaxRequest.Post("btncheck", "ap_buyForm", "ap_buyFormBuyTab", function (Content) {
            if (Content["Status"] == "Success") {
                $("#msgDialog_step1").removeClass("on");
                $("#msgDialog_step2").removeClass("on");
                $("#msgDialog_step3").addClass("aon");          
                Dialog.Success(Content["Tip"]);
            }
            else if (Content["Status"] == "Alert") {
                Dialog.Alert(Content['Tip']);
            }
            else {
                Dialog.Fail(Content['Tip']);
            }
            setbuyButton();
        })
    }

    
    //获取验证码
    function getcode()
    {
        var telnum=$("#txtTelNum").val();
        if(telnum=="")
        {
           Dialog.Alert("手机号码不能为空!");
           return;
        }
       $("#hideTelNum").val(telnum);

       AjaxRequest.Post("btnsend", function (Content) {
           if (Content["Status"] == "Success") {
               $("#msgDialog_step1").removeClass("on");
               $("#msgDialog_step2").addClass("on");
               $("#msgDialog_step3").removeClass("aon");
               sendButton();

               Dialog.Success(Content["Tip"]);
               $("#txtcode").focus();
           }
           else if (Content["Status"] == "Alert") {
               Dialog.Alert(Content['Tip']);
           }
           else {
               Dialog.Fail(Content['Tip']);
           }
           setbuyButton();
       })
    }

