﻿var Count=0;
function DeletecComment(strCommentID)
{
      if (!confirm("Confirm deletion"))
        return false;
    
        objRequest=null;

        if (window.XMLHttpRequest)  // FF,Safari, etc...
        { 
           objRequest = new XMLHttpRequest();
        } 
        else if (window.ActiveXObject)  // IE
        { 
            try 
            {
                objRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (jsError) 
            {
                try 
                {
                    objRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (jsError) 
                {
                }
            }
        }

        if (!objRequest) 
        {
            alert("Cannot create an XMLHTTP Instance");
            return false;
        }
        
        Count++;
        
        var strURL="DeleteComment.aspx?CommentID="+strCommentID;
        objRequest.open("GET", strURL, false);
        objRequest.send(null);
        window.location.reload(true);
}





function jsCommentsUp(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
    
    var strBrowser = navigator.userAgent.toLowerCase();
        if (strBrowser.indexOf('safari')>-1 || strBrowser.indexOf('chrome')>-1)
        {
          jsForSafariOrChromeCommentsUp(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID);
        }
        else //(strBrowser.indexOf('msie')>-1 || strBrowser.indexOf('firefox')>-1)
        {
           jsForFirefoxOrIECommentsUp(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID);
        }
    
    return false;
}

function jsCommentsDown(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
    var strBrowser = navigator.userAgent.toLowerCase();
    
        if (strBrowser.indexOf('safari')>-1 || strBrowser.indexOf('chrome')>-1)
        {
           jsForSafariOrChromeCommentsDown(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID);
        }
        else // (strBrowser.indexOf('msie')>-1 || strBrowser.indexOf('firefox')>-1)
        {
            jsForFirefoxOrIECommentsDown(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID);
        }
       
    return false;
}


function jsForFirefoxOrIECommentsUp(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
    
       var strURL="CommentsUpDown.aspx?CommentID="+strCommentID+"&User="+strUserID+"&Up=1&Down=0";
       xmlDoc=loadXMLDoc(strURL);
    
        objThumbsUpNode = xmlDoc.getElementsByTagName("ThumbsUp");
        objThumbsDownNode = xmlDoc.getElementsByTagName("ThumbsDown");

        var responseNode= xmlDoc.getElementsByTagName("Status");
        var Status=responseNode[0].childNodes[0].nodeValue;
        
        if (Status=="Success")
        {
            document.getElementById(strUpScoreID).innerHTML=objThumbsUpNode[0].childNodes[0].nodeValue;
            document.getElementById(strDownScoreID).innerHTML=objThumbsDownNode[0].childNodes[0].nodeValue;
            document.getElementById(strUpImgID).src="Images/Buttons/thumbs_up.jpg";
            document.getElementById(strUpImgID).disabled=true;
            document.getElementById(strDownImgID).src='Images/Buttons/thumbs_down_grey.jpg';
            document.getElementById(strDownImgID).disabled=false;
     
        }
        else
        {
            alert(Status);
        }
}

function jsForFirefoxOrIECommentsDown(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
     
       var strURL="CommentsUpDown.aspx?CommentID="+strCommentID+"&User="+strUserID+"&Up=0&Down=1";
        xmlDoc=loadXMLDoc(strURL);
        objThumbsUpNode = xmlDoc.getElementsByTagName("ThumbsUp");
        objThumbsDownNode = xmlDoc.getElementsByTagName("ThumbsDown");

        var responseNode= xmlDoc.getElementsByTagName("Status");
        var Status=responseNode[0].childNodes[0].nodeValue;

        if (Status=="Success")
        {
            document.getElementById(strUpScoreID).innerHTML=objThumbsUpNode[0].childNodes[0].nodeValue;
            document.getElementById(strDownScoreID).innerHTML=objThumbsDownNode[0].childNodes[0].nodeValue;
            document.getElementById(strUpImgID).src="Images/Buttons/thumbs_up_grey.jpg";
            document.getElementById(strUpImgID).disabled=false;
            document.getElementById(strDownImgID).src='Images/Buttons/thumbs_down.jpg';
            document.getElementById(strDownImgID).disabled=true;
    
        }
        else
        {
            alert(Status);
        }
}


function jsForSafariOrChromeCommentsUp(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
       var xmlhttp = new window.XMLHttpRequest();
        var strURL="CommentsUpDown.aspx?CommentID="+strCommentID+"&User="+strUserID+"&Up=1&Down=0";
       
       xmlhttp.open("GET",strURL,false);
       xmlhttp.send(null);
       xmlDoc = xmlhttp.responseXML.documentElement;
       
       objThumbsUpNode = xmlDoc.getElementsByTagName("ThumbsUp");
       objThumbsDownNode = xmlDoc.getElementsByTagName("ThumbsDown");

        var responseNode= xmlDoc.getElementsByTagName("Status");
        var Status=responseNode[0].childNodes[0].nodeValue;
        
        if (Status=="Success")
        {
          document.getElementById(strUpScoreID).innerHTML=objThumbsUpNode[0].childNodes[0].nodeValue;
          document.getElementById(strDownScoreID).innerHTML=objThumbsDownNode[0].childNodes[0].nodeValue;
          document.getElementById(strUpImgID).src="Images/Buttons/thumbs_up.jpg";
          document.getElementById(strUpImgID).disabled=true;
          document.getElementById(strDownImgID).src='Images/Buttons/thumbs_down_grey.jpg';
          document.getElementById(strDownImgID).disabled=false;
        }
        else
        {
            alert(Status);
        }
}



function jsForSafariOrChromeCommentsDown(strUpImgID,strDownImgID,strCommentID,strUpScoreID,strDownScoreID,strUserID)
{
       var xmlhttp = new window.XMLHttpRequest();
       var strURL="";    
       
       var strURL="CommentsUpDown.aspx?CommentID="+strCommentID+"&User="+strUserID+"&Up=0&Down=1";
       
       
       xmlhttp.open("GET",strURL,false);
       xmlhttp.send(null);
       xmlDoc = xmlhttp.responseXML.documentElement;
       
        objThumbsUpNode = xmlDoc.getElementsByTagName("ThumbsUp");
        objThumbsDownNode = xmlDoc.getElementsByTagName("ThumbsDown");

        var responseNode= xmlDoc.getElementsByTagName("Status");
        var Status=responseNode[0].childNodes[0].nodeValue;
        
        if (Status=="Success")
        {
        document.getElementById(strUpScoreID).innerHTML=objThumbsUpNode[0].childNodes[0].nodeValue;
        document.getElementById(strDownScoreID).innerHTML=objThumbsDownNode[0].childNodes[0].nodeValue;
        document.getElementById(strDownImgID).src="Images/Buttons/thumbs_down.jpg";
        document.getElementById(strDownImgID).disabled=true;
        
        document.getElementById(strUpImgID).src='Images/Buttons/thumbs_up_grey.jpg';
        document.getElementById(strUpImgID).disabled=false;
        
        }
        else
        {
            alert(Status);
        }
}

function ConfirmDelete()
{
    if (!confirm("Confirm deletion"))
        return false;
}