﻿ var L;
 $(document).ready(function() {
     $.ajaxSetup({
         type: "POST",
         cache: false
     });

    L = new PtGift();
    L.checkLogin();
 })
 function PtGift()
 {
  var self=this;
  this.dv_lout=$("#mess");
  this.rezult={};
  this.a_out = $("#a_out");
  this.a_login=$("#a_login");
  this.img_logout = $("#img_logout");
  this.dv_lout = $("#dv_lout");
   this.state = 0;
   this.checkLogin = function() {

       $.getJSON("ajax/PtGifts.ashx", "act=checkLogin", function(d) {
           if (d.user != "") {
               self.dv_lout.css("display", "block"); $("#mess").css("display", "block"); $("#a_login").css("display", "none"); $("#td_out").css("display", "block");
               self.state = d.state;
               $("#str_name").html(d.user);
               if (d.qs != "") {
                   $("#f_qs").html("已开通");
               }
               if (d.email != "") {
                   $("#f_email").html("已开通");
               }
               if (self.state == 1) {
                   $("#td_card").css("display", "none");
               }
               else {
                   $("#td_card").css("display", "");
               }
           }
           else { self.dv_lout.css("display", "none"); $("#td_out").css("display", "none"); }
       })
   }
   this.bnt=$(".bnt");
   $.each(this.bnt, function(i, n) {
       $(n).click(function() {
           $.post("ajax/PtGifts.ashx", "act=gift&rank=" + $(this).attr("vl"), function(d) {
               if (d == "notlogin") { window.showPopWin('', 'Ptlogin.html', 250, 250, null, true, true); }
               else { alert(d); return; }
               //                var ack=d.ack;
               //                if(ack=="notlogin"){ window.showPopWin('', 'Ptlogin.html', 250, 250, null, true, true);}
               //                else if(ack=="notrank"){window.showPopWin('', 'error.html', 250, 130, null, true, true);}
               //                else if(ack=="hadward"){window.showPopWin('', 'msg.html', 250,120, null, true, true);}
               //                else if(ack=="ok"){window.showPopWin('', 'giftbox.html?gift='+self.rezult["msg"], 590,505, null, true, true);}
           })
       })
   })
   self.a_out.click(function(){
      $.post("ajax/luck.ashx","act=out",function(d){
        if(d=="ok"){ self.dv_lout.css("display","none");$("#dv_msg").html("");}
      })
   })
   $("#a_online").click(function(){
        window.open("zhan.html");
   })
   
  $("#a_login").click(function(){
  
     window.showPopWin('', 'Ptlogin.html', 250, 250, null, true, true);
  })
   self.img_logout.click(function(){
      $.post("ajax/luck.ashx","act=out",function(d){
        if(d=="ok"){window.location.href="PtGifts.html"}
      })
  })


  $("#bnt_aolong").click(function() {

      if ($("#txt_aolongCard").val() != "" && $("#txt_aolongCard").val() != "") {
          $.post("ajax/PtGifts.ashx", "act=checcard&cardNo=" + $("#txt_aolongCard").val(), function(d) {

              if (d == "notlogin") { window.showPopWin('', 'Ptlogin.html', 250, 250, null, true, true); }
              else {
                  if (d == -1) {
                      alert("该卡号不存在！");
                      return false;
                  }
                  else if (d == 2) {
                      alert("您已经激活傲龙卡，不能再次激活！");
                      return false;
                  }
                  else if (d == 0) {
                      alert("该卡已经激活，不能再次激活！");
                      return false;
                  }
                  else if (d == 1) {
                      $("#td_card").css("display", "none");
                      self.state = 1;
                      alert("激活成功，可以领取奖励！");
                      return true;
                  }

              }
          })
      }
  })
 }
