﻿// 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));
     
    $.cookie("testtc", "5678", { expires: 1, path: '/', domain: 'www.cnyes.com' });
    
    if ($.cookie("testtc") == null || $.cookie("testtc") == "")
    {
        alert("請開啟瀏覽器 Cookie 功能！");
        return;
    }
    

//    writeCookie("testtc", "5678",  24 ,"/twstock/");
//    if (readCookie("testtc") == null || readCookie("testtc") == "")
//    {
//        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("多空調查投票成功！");
                  }
                  else
                  {
                     alert("不得重複投票，每人一天限投一票！");
                  }
                  
                  window.open('http://www.cnyes.com/twstock/vote.asp');
                }
        );
      }
      else
      {
           alert("不得重複投票，每人一天限投一票！");
           window.open('http://www.cnyes.com/twstock/vote.asp');
      
      }
 
   } 
   
   
   
    function CheckData()
    {
       
       var myForm = document.frmEdit.choice;
       var tmp = false;
       if (myForm){  
           for(var i=0; i<myForm.length; i++)
           {
             if(myForm[i].checked)
             {
             
                tmp = true;
                break;
             
             }
           }                     
           if (tmp == false) 
           {
               alert("您尚未作答!");           
               return false;
           }
           document.frmEdit.submit();   
       }      
    }

   

