﻿var _pyd_comments_pageNum=1;var _pyd_comments_type=0;var _pyd_comments_objectID=0;var _pyd_comments_numPerPage=5;function toggleCommentForm(on){if(on){Effect.Appear('_pyd_add_comment_form')}else{Effect.Fade('_pyd_add_comment_form')}};function initComments(type,objectID,numPerPage){if(true==__isSignedIn){$('_comments_add_link').innerHTML='<a href="javascript:toggleCommentForm(true)" class="smallText">Add a comment</a>'}else{$('_comments_add_link').innerHTML='Sign in to comment'}getComments(type,objectID,numPerPage,0)};function pageComments(dir){getComments(null,null,null,dir)};function getComments(type,objectID,numPerPage,dir){try{if(type){_pyd_comments_type=type}if(objectID){_pyd_comments_objectID=objectID}if(numPerPage){_pyd_comments_numPerPage=numPerPage}if(!dir){dir=0}$('_pyd_comments_page_info').innerHTML='Loading...';new Ajax.Request('/AJAX/GetComments.ashx',{parameters:{commentType:_pyd_comments_type,objectID:_pyd_comments_objectID,numPerPage:_pyd_comments_numPerPage,pageNum:_pyd_comments_pageNum+dir},onSuccess:function(transport){var json=transport.responseText.evalJSON();_pyd_comments_pageNum=json.pageNum;var html;if(0==json.comments.length){$('_pyd_add_comment_page_nav').style.display='none';html='No comments have been published yet.'}else{if(1<json.totalPages){$('_pyd_add_comment_page_nav').style.display='';$('_pyd_comments_page_info').innerHTML='Page '+json.pageNum+' of '+json.totalPages}else{$('_pyd_add_comment_page_nav').style.display='none'}html='';for(i=0;i<json.comments.length;i++){var c=json.comments[i];var commentHTML='';if(0<c.subject.length){commentHTML='<b>'+c.subject+'</b><br />'}commentHTML+=c.body.fixLB();html+='<div id="_pyd_comment_'+c.id+'" style="overflow:auto;padding:8px 0;border-top:1px dashed #ccc">'+'<div class="smallText">'+'<div style="float:left">'+c.userHTML+'</div>'+'<div style="float:right;color:#666">'+c.date+'</div>'+'<div style="clear:both"></div>'+'</div>'+'<div style="margin-top:5px" class="smallText">'+commentHTML+'</div>'+'</div>'}}$('_comments_list').innerHTML=html},on400:function(transport){var json=transport.responseText.evalJSON();$('_comments_list').innerHTML=json.message},onFailure:function(transport){ajaxError(transport)}})}catch(e){error(e)}};function publishComment(){var subject,body;try{if('Publish'==$('_comments_publish_button').innerHTML){subject=$('_comments_subject').value.trim();body=$('_comments_body').value.trim();if(0==body.length){throw new Error('Enter a comment to publish.')}$('_comments_publish_button').innerHTML='Please wait...';new Ajax.Request('/AJAX/PublishComment.ashx',{parameters:{commentType:_pyd_comments_type,objectID:_pyd_comments_objectID,subject:subject,body:body},onSuccess:function(transport){pageComments(0);toggleCommentForm(false);$('_comments_subject').value='';$('_comments_body').value=''},on400:function(transport){var json=transport.responseText.evalJSON();error(json.message)},onFailure:function(transport){ajaxError(transport)},onComplete:function(transport){$('_comments_publish_button').innerHTML='Publish'}})}}catch(e){error(e)}};