﻿function voting()
{
   var v1=document.getElementById("survey1_RadioButton1").checked;
   var v2=document.getElementById("survey1_RadioButton2").checked;
   var v3=document.getElementById("survey1_RadioButton3").checked;
   var v4=document.getElementById("survey1_RadioButton4").checked;
   var v5=document.getElementById("survey1_RadioButton5").checked;   
   if(v1||v2||v3||v4||v5)
   {
     var Tag=voteTag(); //获取所选择项
     var isV=readcookie('isVote');//获取Cookies值
         if(!isV)//判断是否已投过
         {
           VoteInto(Tag);//正式投票
         } 
         else
         {
           alert('您已投过票了!感谢您的支持!');
         }    
   }
   else
   {
     alert('请选择后再点击投票!');
   }
   

}

function VoteInto(obj)
{
     switch(obj)
     {
     case 1:newDLL.Vote(1,0,0,0,0,getvoteback);
     break;
     case 2:newDLL.Vote(0,1,0,0,0,getvoteback);
     break;
     case 3:newDLL.Vote(0,0,1,0,0,getvoteback);
     break;
     case 4:newDLL.Vote(0,0,0,1,0,getvoteback);
     break;
     case 5:newDLL.Vote(0,0,0,0,1,getvoteback);
     break;
     }
}

function getvoteback(response)
{
    if(response!=null)
    {       
       if(response.value==true)
       {
         alert('投票成功,非常感谢您的支持!');
         writecookie("isVote",true)
       }
       else
       {
          alert('投票失败,请刷新页面再试!');
       }
    }
    else
    {
        alert('网络超时,请重新再试!');
    }
}



function voteTag()
{
  var i;
  for(i=1;i<6;i++)
  {
     if(document.getElementById("survey1_RadioButton"+i).checked)
     {return i; }
  }  
}


function writecookie(name, value)
{
  document.cookie=name + "=" + value + ";";
}

function readcookie(name) 
{
    var mycookie = document.cookie;
    var start1 = mycookie.indexOf(name + "=");
    if (start1== -1)
        return false;
    else
    {
        start=mycookie.indexOf("=",start1) + 1;
        var end = mycookie.indexOf(";",start);
        if (end==-1)
        {
            end=mycookie.length;
            //return unescape(mycookie.substring(start,end));
        }
        return unescape(mycookie.substring(start,end));
    }
}


function openwindows()
{
  window.open('voteResult.aspx','亮湾湾在线调查','width=530,height=240,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no'); 

}
