﻿ 
function VoteUp(sStationID, sControlID)
{
    DebugOut("  Voting for Station " + sStationID );
    StationPortal_Voting.ThumbsUp(
        sStationID,        
        VoteUp_Succeeded, VoteUp_FailedCallback,
        sStationID);

}

 
function TipStationUp(sStationID, sTipAmount)
{
    DebugOut("  Voting for Story " + sStationID );
    StationPortal_Voting.TipStory(
        sStationID, sTipAmount,        
        TipStory_Succeeded, TipStory_FailedCallback,
        sStationID);
}

  
function TipUserUp(UserId, sTipAmount)
{
    
    StationPortal_Voting.TipUser(
        UserId, sTipAmount,        
        TipUser_Succeeded, TipUser_FailedCallback,
        UserId);

}
 
function VoteComment(sCommentID, nValue)
{

    DebugOut("  Voting for Comment " + sCommentID );
    StationPortal_Voting.CommentUp(
        sCommentID, nValue,       
        CommentUp_Succeeded, CommentUp_FailedCallback,
        sCommentID);

}
 
function CommentOnStory(sStationID, nReplyCommentID, sComment, sControlID)
{
    DebugOut("  Commenting on Story " + sStationID );        
    StationPortal_Voting.CommentOnStation(
        sStationID, nReplyCommentID, sComment,       
        Comment_Succeeded, Comment_FailedCallback,
        sControlID);        
        
}

function CommentOnGroup(sGroupID, nReplyCommentID, sComment, sControlID)
{
    DebugOut("  Commenting on Story " + sGroupID );        
    StationPortal_Voting.CommentOnGroup(
        sGroupID, nReplyCommentID, sComment,       
        GroupComment_Succeeded, GroupComment_FailedCallback,
        sControlID);        
        
}

function AddGroupToStation(sStationID, sGroupID)
{
    
    StationPortal_Voting.AddStationToGroup(
        sStationID, sGroupID,        
        AddGroup_Succeeded, AddGroup_FailedCallback,
        sStationID);
}


function VoteUp_Succeeded(result, userContext, methodName)
{

    var sErrCode = "";

        if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sErrCode = result.selectSingleNode("//vote/@errcode").textContent;        
         }
         else
         {
            sErrCode = result.selectSingleNode("//vote/@errcode").text;
         }
    
    DebugOut("  VoteUp_Succeeded.  ErrCode was  " + sErrCode);

    if(sErrCode == "0")
    {    
        var sNewCount = ""
        
          if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sNewCount = result.selectSingleNode("//vote/@newcount").textContent;        
         }
         else
         {
            sNewCount = result.selectSingleNode("//vote/@newcount").text;
         }
                
        DebugOut("  NewCount = " + sNewCount);  
        var nCur = 0;        
        //var sDivName = userContext + "_" + nCur;                
        
        var sDivName = "thumbsup-" + userContext 
        
        
        var elOutput = document.getElementById(sDivName);
        
        var sDivVote = "vote-" + userContext;
        var elVote = document.getElementById(sDivVote);
        
        elOutput.innerHTML = sNewCount + " <br />Votes";
        elVote.innerHTML = "<a href='javascript://'>Thanks!</a>";
        //elVote.innerHTML = "<a href=\"javascript://\" onclick='TipStory(" +userContext + ");'>Tip</a>";                
    }           
    else
    {
    
     if(sErrCode == "2")
        alert("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + sErrCode);
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function VoteUp_FailedCallback(error)
{
    if(error == 2)
        MessageBox("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + error);
}


function TipStory_Succeeded(result, userContext, methodName)
{
 
    var sErrCode = "";

    if(result.selectSingleNode("//vote/@errcode").text == null)
    {
        sErrCode = result.selectSingleNode("//vote/@errcode").textContent;        
     }
     else
     {
        sErrCode = result.selectSingleNode("//vote/@errcode").text;
     }
    
    DebugOut("  VoteUp_Succeeded.  ErrCode was  " + sErrCode);

    if(sErrCode == "0")
    {    
        var sNewCount = ""
        
          if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sNewCount = result.selectSingleNode("//vote/@newcount").textContent;        
         }
         else
         {
            sNewCount = result.selectSingleNode("//vote/@newcount").text;
         }
                
        DebugOut("  NewCount = " + sNewCount);  
        var nCur = 0;        
        
        var sDivName = "thumbsup-" + userContext 
        
        
        var elOutput = document.getElementById(sDivName);
        
        var sDivVote = "vote-" + userContext;
        var elVote = document.getElementById(sDivVote);
        
        elOutput.innerHTML = sNewCount + " <br />Votes";
        elVote.innerHTML = "<a href='javascript://'>Tip'd!</a>";
    }           
    else
    {
    
     if(sErrCode == "2")
        alert("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + sErrCode);
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function TipStory_FailedCallback(error)
{
    if(error == 2)
        MessageBox("You must be logged in to tip");
     else
        DebugOut("  ERROR HIT: " + error);
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function VoteUp_FailedCallback(error)
{
    if(error == 2)
        MessageBox("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + error);
}


// ===================


function TipUser_Succeeded(result, userContext, methodName)
{
 
    var sErrCode = "";

    if(result.selectSingleNode("//vote/@errcode").text == null)
    {
        sErrCode = result.selectSingleNode("//vote/@errcode").textContent;        
     }
     else
     {
        sErrCode = result.selectSingleNode("//vote/@errcode").text;
     }
    
    DebugOut("  UserUp_Succeeded.  ErrCode was  " + sErrCode);

    if(sErrCode == "0")
    {    
        var sNewCount = ""
        
          if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sNewCount = result.selectSingleNode("//vote/@newcount").textContent;        
         }
         else
         {
            sNewCount = result.selectSingleNode("//vote/@newcount").text;
         }
                
        DebugOut("  NewCount = " + sNewCount);  
        var nCur = 0;        
        
        var sDivName = "ctl00_ContentPlaceHolder1_txtNozzlCash" 
        
        
        var elOutput = document.getElementById(sDivName);
        
        
        elOutput.innerHTML = "$" + sNewCount ;
        
    }           
    else
    {
    
     if(sErrCode == "2")
        alert("You must be logged in to vote");        
     else
     {
         if(sErrCode == "3")
         {
         alert("Unable to tip that");
         }
         else     
            DebugOut("  ERROR HIT: " + sErrCode);      
     }   
    }
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function TipUser_FailedCallback(error)
{
    if(error == 2)
        MessageBox("You must be logged in to tip");
     else
        DebugOut("  ERROR HIT: " + error);
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function VoteUp_FailedCallback(error)
{
    if(error == 2)
        MessageBox("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + error);
}


// ===================

function CommentUp_Succeeded(result, userContext, methodName)
{

    var sErrCode = "";

        if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sErrCode = result.selectSingleNode("//vote/@errcode").textContent;        
         }
         else
         {
            sErrCode = result.selectSingleNode("//vote/@errcode").text;
         }
    
    DebugOut("  VoteUp_Succeeded.  ErrCode was  " + sErrCode);

    if(sErrCode == "0")
    {    
        var sNewCount = ""
        
          if(result.selectSingleNode("//vote/@errcode").text == null)
        {
            sNewCount = result.selectSingleNode("//vote/@newcount").textContent;        
         }
         else
         {
            sNewCount = result.selectSingleNode("//vote/@newcount").text;
         }
                
        DebugOut("  NewCount = " + sNewCount);  
        var nCur = 0;        
        //var sDivName = userContext + "_" + nCur;                
        
        var sDivName = "thumbsup-" + userContext 
        
        
        var elOutput = document.getElementById(sDivName);
        
        var sDivVote = "vote-" + userContext;
        var elVote = document.getElementById(sDivVote);
        
        elOutput.innerHTML = sNewCount + " Votes";
        elVote.innerHTML = "&nbsp;&nbsp;<a href='javascript://' title=''>Thanks!</a>&nbsp;&nbsp;";
    }           
    else
    {
    
     if(sErrCode == "2")
        alert("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + sErrCode);
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function CommentUp_FailedCallback(error)
{
    alert(error);
    if(error == 2)
        MessageBox("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + error);
}

function Comment_Succeeded(result, userContext, methodName)
{
    
    var sErrCode = "";

    if(result.selectSingleNode("//comment/@errcode").text == null)
    {
    
        sErrCode = result.selectSingleNode("//comment/@errcode").textContent;        
     }
     else
     {
     
        sErrCode = result.selectSingleNode("//comment/@errcode").text;
     }


    DebugOut(" Comment_Succeeded.  ErrCode was  " + sErrCode);
    
    
     //var elFin = document.getElementById(userContext);
     
//    if(elFin == null)
        elFin = userContext;
 
    if(elFin != null)
        elFin.style.display = "block";

    if(sErrCode == "0")
    {    
        var sComment = ""
        
        if(result.selectSingleNode("//comment/@commenttext").text == null)
        {
            sComment = result.selectSingleNode("//comment/@commenttext").textContent;        
         }
         else
         {
            sComment = result.selectSingleNode("//comment/@commenttext").text;
         }
         
         var sStationID = ""
        
        if(result.selectSingleNode("//comment/@StationID").text == null)
        {
            sStationID = result.selectSingleNode("//comment/@StationID").textContent;        
         }
         else
         {
            sStationID = result.selectSingleNode("//comment/@StationID").text;
         }
         elFin.innerHTML = "<div class='comment_new_done'><b>Comment Added</b>:<hr/>" +  sComment + ".</div>";//  View <a target='_top' href='story.aspx?id=" + sStationID + "'>other comments</a>";        

    }           
    else
    {
        
         if(sErrCode == "2")
            alert("You must be logged in to vote");
         else
         {
            elFin.innerText = "Error saving comment: " + sErrCode;
            DebugOut("  ERROR HIT: " + sErrCode);
         }
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function  Comment_FailedCallback(error)
{
    alert(error.get_message());    
    if(error == 2)
        MessageBox("You must be logged in to vote");
     else
        DebugOut("  ERROR HIT: " + error);
}














function GroupComment_Succeeded(result, userContext, methodName)
{
    
    var sErrCode = "";

    if(result.selectSingleNode("//comment/@errcode").text == null)
    {
    
        sErrCode = result.selectSingleNode("//comment/@errcode").textContent;        
     }
     else
     {
     
        sErrCode = result.selectSingleNode("//comment/@errcode").text;
     }


    DebugOut(" Comment_Succeeded.  ErrCode was  " + sErrCode);
    
    
     //var elFin = document.getElementById(userContext);
     
//    if(elFin == null)
        elFin = userContext;
 
    if(elFin != null)
        elFin.style.display = "block";

    if(sErrCode == "0")
    {    
        var sComment = ""
        
        if(result.selectSingleNode("//comment/@commenttext").text == null)
        {
            sComment = result.selectSingleNode("//comment/@commenttext").textContent;        
         }
         else
         {
            sComment = result.selectSingleNode("//comment/@commenttext").text;
         }
         
         var sGroupID = ""
        
        if(result.selectSingleNode("//comment/@GroupID").text == null)
        {
            sGroupID = result.selectSingleNode("//comment/@GroupID").textContent;        
         }
         else
         {
            sGroupID = result.selectSingleNode("//comment/@GroupID").text;
         }
         elFin.innerHTML = "<div class='comment_new_done'><b>Comment Added</b>:<hr/>" +  sComment + ".</div>";//  View <a target='_top' href='story.aspx?id=" + sStationID + "'>other comments</a>";        

    }           
    else
    {
        
         if(sErrCode == "2")
            alert("You must be logged in to vote");
         else
         {
            elFin.innerText = "Error saving comment: " + sErrCode;
            DebugOut("  ERROR HIT: " + sErrCode);
         }
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function  GroupComment_FailedCallback(error)
{
    alert(error.get_message());    
    if(error == 2)
        MessageBox("You must be logged in to comment on a group");
     else
        DebugOut("  ERROR HIT: " + error);
}



function AddGroup_Succeeded(result, userContext, methodName)
{
 
    var sErrCode = "";

    if(result.selectSingleNode("//vote/@errcode").text == null)
    {
        sErrCode = result.selectSingleNode("//vote/@errcode").textContent;        
     }
     else
     {
        sErrCode = result.selectSingleNode("//vote/@errcode").text;
     }
    
    DebugOut("  AddGroup_Succeeded.  ErrCode was  " + sErrCode);

    if(sErrCode == "0")
    {    
        var sNewCount = ""
               
    }           
    else
    {    
       if(sErrCode == "2")
            ("You must be logged in to add a station to a group");
       else
       {
          if(sErrCode == "3")
          {
               alert("You must belong to that group to add a station to it"); 
          }
          else
          {
            if(sErrCode = "4")
            {
                alert("Error adding that station to a group");
            }
            else
            {
             DebugOut("  ERROR HIT: " + error);
             }
          }
       }
    }   
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameterd.
function AddGroup_FailedCallback(error)
{
    if(error == 2)
        alert("You must be logged in to add a station to a group");
     else
     {
         if(error == 3)
         {
           alert("You must belong to that group to add a station to it"); 
         }
         else
         {
           DebugOut("  ERROR HIT: " + error);
         }
     }
}








if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
