//AJAX javascript methods for Post Voting
  
 //====================================
  //empty function to have a nice display
  function Vote() {}
//====================================
  function VoteForPost(_postid, _votername, _voteMessageControlId, _voteCountControlId)
  {
      if (_votername=="Anonymous")
      {
        alert ("You must be logged in to vote for a post");
        document.location.href="/login.aspx?returnURL="+escape(location.href) + "&amp;logintovote=1";
      }
      else
      {
        if (typeof(_voteMessageControlId)!="undefined")
        {
         lblvotemessage = _voteMessageControlId;
         lblvotecount = _voteCountControlId;
        }
        
        wineCHATr.WebServices.PostVoting.VoteForPost(_postid,_votername, OnSuccessVote);     
      }
 }
//==================================== 
function OnSuccessVote(result, userContext, methodName)
{  
  var VoteMessageLabel = $get(lblvotemessage);
  var VoteCountLabel = $get(lblvotecount);
   
  switch (result)
    {
      case "success":
        //VoteMessageLabel.innerHTML = '<img src="/images/chatr_icon_vote_active.gif" align="absmiddle" width="16" height="16" title="You&#39;ve Voted!" />&nbsp;<span style="color:green;font-weight:bold">Thanks for voting!</span>';

        VoteMessageLabel.innerHTML = '<img src="/images/btns/chatr_btn_post_vote_on.gif" title="You like this post!" class="imgRating" />';
        
        //to increment vote count by 1 we need to use RegEx to get the digit value from the existing count, then add one to it and write it back to the VoteCount span
        var _voteLabel = VoteCountLabel.innerHTML;
        var _regex = new RegExp(/\d+/);            
        var _newVoteCount = parseInt(_voteLabel.match(_regex)) + 1;
        
        if (_newVoteCount==1)
        {   
          VoteCountLabel.innerHTML = "(1 Member Vote)";
        }
        else
        {
          VoteCountLabel.innerHTML = "(" + _newVoteCount + " Member Votes)";
        }
        break;
      case "dupevote":    //in case a duplicate vote gets through somehow, just post the thanks message, don't update the actual count
        VoteMessageLabel.innerHTML = ' | <img src="/images/chatr_icon_vote_active.gif" align="absmiddle" width="16" height="16" title="You&#39;ve Voted!" />&nbsp;<span style="color:green;font-weight:bold">Thanks for voting!</span>';
        break;
      case "voterisposter":
        VoteMessageLabel.style.visbility = "hidden";
        break;
      case "dbfailure":
        break;      
   } 
    
     // alert ("Thanks for voting! /n/nResult:" + result + "\n\n UserContext: " + userContext + "\n\n MethodName: " + methodName); 
 }
//==================================== 


