﻿// JScript 檔

 function ChannelVote(channel,kind,cls,id)
  {
     writeCookie("futuresTestCookie", "1234");
     if (readCookie("futuresTestCookie") == null || readCookie("futuresTestCookie") == "")
     {
        alert("請開啟 cookie 功能！");
        return;
     }
  
     if(readCookie(kind) == null || readCookie(kind) !="YES")
     {
        var pd = "channel="+channel+"&kind="+kind+"&cls="+cls+"&id="+id+"&rnd="+Rnd();

        $.post("/futures/Ajax/FuturesVote.aspx", 
                pd, 
                function(result)
                {
                  //alert(result);
                  
                  if(result.split("|")[0] == 1)
                  {
                      
                     var bullPercent = parseInt(result.split('|')[1]);
                     var bearPercent = parseInt(result.split('|')[2]);
                     var consolidationPercent = parseInt(result.split('|')[3]);
                   
                     $("span[class='bar_r']").css({width: bullPercent + "%"});
                     $("span[class='bar_g']").css({width: bearPercent + "%"});
                     $("span[class='bar_y']").css({width: consolidationPercent + "%"});
                     
                     $("#percent_r").text(bullPercent + "%");
                     $("#percent_g").text(bearPercent + "%");
                     $("#percent_y").text(consolidationPercent + "%");
                     
                     //投票成功寫入Cookie
                     writeCookie(kind,  "YES",  24);
                  
                     alert("多空調查投票成功！");
                     window.open('http://www.cnyes.com/futures/vote.aspx');
                  
                  }
                  else
                  {
                     alert("不得重複投票，每人一天限投一票！");
                     window.open('http://www.cnyes.com/futures/vote.aspx');
                  
                  }
                }
        );
      }
      else
      {
           alert("不得重複投票，每人一天限投一票！");
           window.open('http://www.cnyes.com/futures/vote.aspx');
      
      }
 
   } 