﻿
var DrawIntegral_url="ashx/DrawIntegral.ashx";
//设置选择的抽奖分类状态
function SetCurDraw(pid,vid,type)
{
   for(var i=0;i<vid;i++)
   {
      if(document.getElementById("draw_a"+String(i)) != null && document.getElementById("draw_ul"+String(i)) != null)
      {
         if(pid == i)
         {            
            document.getElementById("draw_a"+String(i)).className = "curr";
            document.getElementById("draw_ul"+String(i)).style.display = "block";            
            if(document.getElementById("draw_a_more") != null&&type != undefined)
            {                
                document.getElementById("draw_a_more").href = "Integral_spend_draw.aspx?Type="+type;
            }            
         }
         else
         {
            document.getElementById("draw_a"+String(i)).className = "";
            document.getElementById("draw_ul"+String(i)).style.display = "none";
         }
      }
      else
      {
         break;
      }
   }   
}
//设置选择的积分分类状态
function SetCurIntegral(pid,vid)
{
    for(var i=0;i<vid;i++)
   {
      if(document.getElementById("integral_a"+String(i)) != null && document.getElementById("integral_ul"+String(i)) != null)
      {
         if(pid == i)
         {
            document.getElementById("integral_a"+String(i)).className = "curr";
            document.getElementById("integral_ul"+String(i)).style.display = "block";
         }
         else
         {
            document.getElementById("integral_a"+String(i)).className = "";
            document.getElementById("integral_ul"+String(i)).style.display = "none";
         }
      }
      else
      {
         break;
      }
   }   
}

//获取积分和抽奖活动
function LoadDraw()
{
     document.getElementById("draw_div").innerHTML = "正在获取抽奖信息……";
     var param="FUN=Load&Type=2";
     var ajax=new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:LoadDrawComplete});
}
function LoadDrawComplete(ajaxResponse)
{
    document.getElementById("draw_div").innerHTML = ajaxResponse.responseText;
    SetCurDraw(0,100);
}

function LoadDraw_More()
{
     document.getElementById("draw_div").innerHTML = "正在获取抽奖信息……";
     var param="FUN=Load_More&Type=2";
     var ajax=new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:LoadDrawComplete});
}

function LoadIntegral()
{
    document.getElementById("integral_div").innerHTML = "正在获取抽奖信息……";
    var param="FUN=Load&Type=1";
    var ajax=new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:LoadIntegralComplete});
}
function LoadIntegralComplete(ajaxResponse)
{
    document.getElementById("integral_div").innerHTML = ajaxResponse.responseText;
    SetCurIntegral(0,100);
}

/*获取积分兑换的物品*/
function LoadDuiHuan()
{
    document.getElementById("quanke_duihuan").innerHTML = "正在获取兑换信息……";
    var param="FUN=DuiHuan";
    var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:LoadDuiHuanComplete});
}
function LoadDuiHuanComplete(ajaxResponse)
{
   document.getElementById("quanke_duihuan").innerHTML = ajaxResponse.responseText;
}

//获取最新兑换
function GetLastestDuiHuan(count)
{
   document.getElementById("lastest_duihuan").innerHTML="正在获取最新兑换信息……";
   var param="FUN=L_DuiHuan&Count="+count;
   var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:GetLastestDuiHuanComplete});
}
function GetLastestDuiHuanComplete(ajaxResponse)
{
    document.getElementById("lastest_duihuan").innerHTML = ajaxResponse.responseText;
}


function DuiHuan()
{
    if(confirm("确认兑换此物品吗？"))
    {
        var DuiHuan = document.getElementById("hidNm").value;
        if(isNull(DuiHuan))
        {
            alert("对不起，还不能兑换！");
            return false;
        }
        var param = "FUN=DuiHuanBaoWu&DuiHuanNM="+DuiHuan;
        var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:DuiHuanComplete});
    }
}
function DuiHuanComplete(ajaxResponse)
{
    alert(ajaxResponse.responseText);
    window.location.reload();
    return false;
}


/*获取热门兑换*/
function GetHotDuiHuan()
{
    document.getElementById("hot_duihuan").innerHTML = "正在获取热门兑换……";
    var param = "FUN=HotDuiHuan";
    var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:GetHotComplete});
}
function GetHotComplete(ajaxResponse)
{
    document.getElementById("hot_duihuan").innerHTML = ajaxResponse.responseText;
}

/*抽奖*/
function LuckyDraw()
{
    var drawId = document.getElementById("hidNm").value;
    if(isNull(drawId))
    {
        alert("对不起，还不能抽奖！");
        return false;
    }
    var param = "FUN=Draw&DrawId="+drawId;
    var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:LuckyDrawComplete});
}

function LuckyDrawComplete(ajaxResponse)
{
    if(ajaxResponse.responseText == "1")
    {
        alert("恭喜你，中奖了！");
        window.location.reload();
        return false;
    }
    if(ajaxResponse.responseText == "0")
    {
        alert("下一个幸运儿就是你哦！");
        window.location.reload();
        return false;
    }
    alert(ajaxResponse.responseText);
    return false;
}


/*
    获取中奖者名单
*/
function GetDrawLucker()
{
    document.getElementById("draw_lucker").innerHTML = "正在获取已中奖名单……";
    var param = "FUN=GetLucker";
    var ajax = new Ajax.Request(DrawIntegral_url,{method:"post",parameters:param,onComplete:GetDrawLuckerComplete});
}
function GetDrawLuckerComplete(ajaxResponse)
{
    document.getElementById("draw_lucker").innerHTML = ajaxResponse.responseText;
}
