﻿// JScript 檔

  function ChannelVote(channel,kind,cls,id)
  {
     
     //alert(document.cookie);
     //writeCookie("twstockTestCookie", "1234",  24 ,"/twstock/");

     //alert(document.cookie);
     //alert(readCookie("twstockTestCookie"));
     
     //if (readCookie("twstockTestCookie") == null || readCookie("twstockTestCookie") == "")
     //{
       // alert("請開啟 cookie 功能！");
        //return;
     //}
     
     //alert(readCookie(kind));
     

    //if ($.cookie("twstockTestCookie") == null || $.cookie("twstockTestCookie") == "")
    //{
    //    alert("請開啟瀏覽器 Cookie 功能！");
    //    return;
    //}
    
     //var today = new Date();
     //var yyyyMMdd = today.getYear() + "" + today.getMonth() + "" + today.getDay();
    
     if(readCookie(kind) == null || readCookie(kind) !="YES")
     //if($.cookie(kind) == null || $.cookie(kind) !="YES")
     //if ($("#EmuCookie").val() == "1" || yyyyMMdd != $("#EmuCookie").val())
     {
        var pd = "channel="+channel+"&kind="+kind+"&cls="+cls+"&id="+id+"&rnd="+Rnd();

        $.post("/twstock/Ajax/TwstockVote2.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_y']").css({width: bearPercent + "%"});
                     $("span[class='bar_g']").css({width: consolidationPercent + "%"});
                     
                     $("#percent_r").text(bullPercent + "%");
                     $("#percent_y").text(bearPercent + "%");
                     $("#percent_g").text(consolidationPercent + "%");
                     
                     //投票成功寫入Cookie
                     writeCookie(kind,  "YES",  24 ,"/twstock/");
                     //$.cookie(kind, "YES", { expires: 1, path: '/', domain: _RootURL  });
                    //$("#EmuCookie").val(yyyyMMdd);
                    
                     alert("多空調查投票成功！");
                     window.open('http://www.cnyes.com/twstock/vote.asp');
                  
                  }
                  else
                  {
                     alert("不得重複投票，每人一天限投一票！");
                     window.open('http://www.cnyes.com/twstock/vote.asp');
                  
                  }
                }
        );
      }
      else
      {
           alert("不得重複投票，每人一天限投一票！");
           window.open('http://www.cnyes.com/twstock/vote.asp');
      
      }
 
   } 
   
