﻿function FlagThis(guid) {
    AjaxCalls.Flag(guid,null,null);
    $('aFlag' + guid).innerHTML = 'Flagged. Thank you.';
    $('aFlag' + guid).href = 'javascript:;';
};

/* AjaxVote Functions */
/*var contentGuid;var checkedImg="";var uncheckedImg="";
var voteButtons = new Array();
function VoteButton(id,value)
{
    this.img = $(id);
    this.img.voteButton = this;
    this.img.onclick = onclickFunc;
    this.value = value;
    
    function onclickFunc()
    {
        resetUserVote(this.voteButton.value);        
        AjaxCalls.SubmitVote(contentGuid,this.voteButton.value,voteCallback,voteCallback);
    }
    
};
VoteButton.prototype.check = function(){
    this.img.src = checkedImg;
};
VoteButton.prototype.uncheck = function(){
    this.img.src = uncheckedImg;
};
    
function resetAvgVote(val)
{
    for (i=0;i<avgArr.length;i++){
        avgArr[i].src = uncheckedImg;
    };
    for (i=0;i<val;i++){
        avgArr[i].src = checkedImg;
    };
};
function resetUserVote(val)
{
    for (i=0;i<val;i++){
        voteButtons[i].check();
    };
    for (i=val;i<voteButtons.length;i++){
        voteButtons[i].uncheck();
    };
};



function voteCallback(obj)
{
    if (obj)
        resetAvgVote(obj);
}
*/

// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
    if (element == null)
        return false;
    bubbling = bubbling || false;
    if(window.addEventListener) { // Standard
        element.addEventListener(type, expression, bubbling);
        return true;
    } else if(window.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
        return true;
    } else return false;
}


/* AjaxComment Functions */
var commentPage=1;
var sortDir='desc';
var commentDiv;
function commentCallback(val)
{
    commentDiv = $('commentDiv');
    var spn = $('spnLanguage');
    if (val[1] == "-1"){
          spn.innerHTML='You have used inappropriate language. Please edit your comment and re-submit.';
          spn.style.display='inline';
          $('btnComment').enabled='true';
          return;
    };
    if (val[1] == "-2"){
        spn.innerHTML='HTML Tags are not allowed. Please remove all HTML tags before posting your comment. Detected web addresses will automatically be converted to hyperlinks for you.';
        spn.style.display='inline';
        $('btnComment').enabled='true';
        return;
    };
    pnlAddComment.style.display='none';
    $('aCommentOrder').innerHTML='View comments in ascending order';
    sortDir='desc';
    commentPage=1;
    commentDiv.innerHTML=val[1];
    window.location='#' + val[0];
};
function getCommentsCallback(val)
{
    commentDiv = $('commentDiv');
    commentDiv.innerHTML=val;
};
function switchCommentOrder()
{
    var a = $('aCommentOrder');
    if (sortDir=='desc'){
        sortDir='asc';
        commentPage=1;
        a.innerHTML='View comments in descending order';
    } else {
        sortDir='desc';
        commentPage=1;
        a.innerHTML='View comments in ascending order';
    };
    AjaxCalls.GetComments(contentGuid,commentPage,sortDir,getCommentsCallback,null);
};
function CommentPage(p) {
    commentPage = p;
    AjaxCalls.GetComments(contentGuid,commentPage,sortDir,getCommentsCallback,null);
};
function resetComments()
{
    var spn = $('spnLanguage');
    commentPage=1;
    sortDir='desc';
    var a = $('aCommentOrder');
    a.innerHTML='View comments in ascending order';
    commentTitle.value='';
    commentBody.value='';
    spn.style.display='none';
    pnlAddComment.style.display='inline';
    $('btnComment').removeAttribute('DISABLED');
    $('aCommentOrder').innerHTML='View comments in ascending order';
    sortDir='desc';
    commentPage=1;
    AjaxCalls.GetComments(contentGuid,commentPage,sortDir,getCommentsCallback,null);
};
function resetSendToFriend() {
    document.getElementById('dvSend').style.display='inline';
    document.getElementById('dvSendComplete').style.display='none';
};