
var dontLook=new Object();function strongAppear(row){Effect.Appear('strong-'+row,{duration:1.0});}
function diggComment(row){if(!diggburylock){diggburylock=1;if(!checkIE()){Effect.Fade('strong-'+row,{duration:1.0});setTimeout("strongAppear("+row+")",1100);}
setTimeout('incrCommentDiggs('+row+')',1000);myxmlhttp[row]=new myXMLHttpRequest();url='/diggcomment';content='&commentid='+row+'&up=1';myxmlhttp[row].open("POST",url,true);myxmlhttp[row].setRequestHeader('Content-Type','application/x-www-form-urlencoded');myxmlhttp[row].onreadystatechange=function(){if(myxmlhttp[row].readyState==4){diggburylock=0;if(myxmlhttp[row].responseText!='NA'){updateCommentDiggs(row,myxmlhttp[row].responseText);}}}
myxmlhttp[row].send(content);}
return(false);}
function buryComment(row){if(!diggburylock){diggburylock=1;incrCommentBuries(row);myxmlhttp[row]=new myXMLHttpRequest();url='/diggcomment';content='&commentid='+row+'&up=0';myxmlhttp[row].open("POST",url,true);myxmlhttp[row].setRequestHeader('Content-Type','application/x-www-form-urlencoded');myxmlhttp[row].onreadystatechange=function(){if(myxmlhttp[row].readyState==4){diggburylock=0;if(myxmlhttp[row].responseText!='NA'){updateCommentDiggs(row,myxmlhttp[row].responseText);}}}
myxmlhttp[row].send(content);}
return(false);}
function incrCommentDiggs(id){target=$('strong-'+id);currentCount=target.innerHTML.replace(/ digg[s]{0,1}/,'');currentCount=currentCount.replace(/\+ /,'');currentCount=currentCount.replace(/\- /,'-');currentCount++;if(currentCount>=0){if(currentCount==1){target.innerHTML='+ '+currentCount+' digg';}else{target.innerHTML='+ '+currentCount+' diggs';}}else{target.innerHTML=currentCount+' diggs';}
greyFlags(id);}
function incrCommentBuries(id){greyFlags(id);collapseComment(id);target=$('strong-'+id);var currentCount=target.innerHTML.replace(/ digg[s]{0,1}/,'');currentCount=currentCount.replace(/\+ /,'');currentCount=currentCount.replace(/\- /,'-');currentCount--;if(currentCount>=0){if(currentCount==1){target.innerHTML='+ '+currentCount+' digg';}else{target.innerHTML='+ '+currentCount+' diggs';}}else{if(currentCount==-1){target.innerHTML='- 1 digg';}else{number=-currentCount;target.innerHTML='- '+number+' diggs';}}}
function greyFlags(commentId){$('colorthumbs'+commentId).style.display='none';$('graythumbs'+commentId).style.display='inline';}
function collapseComment(commentId){$('cshowlink'+commentId).style.display='inline';$('cshowa'+commentId).style.display='inline';$('chidea'+commentId).style.display='none';greyFlags(commentId);$('c'+commentId).className='c-bury';Effect.SlideUp('cbody'+commentId);return(false);}
function updateCommentDiggs(row,response){dontLook[row]=true;Effect.Appear('strong-'+row);}
var lastedit='';var removeEditTimeouts=new Object();function clickEdit(target,id,text){var realtarget=target.parentNode.parentNode;text=text.replace(/<[^>]*>/gi,'');realtarget.style.display='none';secondsremaining=parseInt($('countdown'+id).innerHTML);clearInterval(countdownTimer['countdown'+id]);countdownTimer['countdown'+id]=null;realtarget.innerHTML='<div id="editdiv"><form><textarea name="edittext" id="edittext'+id+'" style="width:100%">'+text+'</textarea><input type="hidden" name="savedtext" id="savedtext'+id+'" value="'+text+'"><input type="submit" onclick="return(updateComment(this.form, \''+realtarget.id+'\'))" value="Update"><input type="hidden" name="id" value="'+id+'"></form></div>';window.setTimeout("$('edittext"+id+"').focus()",1200);removeEditTimeouts[id]=window.setTimeout("removeEdit("+id+")",(secondsremaining+29)*1000);Effect.Appear(realtarget);return(false);}
function removeEdit(id){target=$('cbody'+id);target.display='none';$('c'+id).className='';newhtml='<div class="c-body-inside" style="">'+($('savedtext'+id).value.replace(/\n/g,'<br />'))+'</div>';target.innerHTML=newhtml;Effect.Appear(target)}
function handleUpdateComment(targetid){if(myxmlhttp.readyState==4){eval('returnvalues = ('+myxmlhttp.responseText+')');if(returnvalues['error']==false){alert('There was an error updating your comment.');}else{var numericId=targetid.replace(/cbody/,'');clearTimeout(removeEditTimeouts[numericId]);var target=$('cbody'+numericId);target.display='none';if(returnvalues['secondsleft']>0){var text=returnvalues['comment'].replace(/\n/g,'\\n').replace(/'/g,"\\'");var newhtml='<div class="c-body-inside" style=""><a onclick="return(clickEdit(this, \''+numericId+'\',\''+text+'\'))" href="?cedit='+numericId+'#'+numericId+'" class="c-editable"><strong>Click to Edit</strong> (Available for <span id="countdown'+numericId+'">'+returnvalues['secondsleft']+'</span> Seconds)</a>'+returnvalues['comment'].replace(/\n/g,'<br />');}else{newhtml='<div class="c-body-inside" style="">'+(returnvalues['comment'].replace(/\n/g,'<br />'));$('c'+numericId).className='';}
if(returnvalues['showreplylink']){newhtml+='<a href="?creplyto='+numericId+'#creplyform" onclick="return(setupcreply(\''+numericId+'\', \''+returnvalues['username']+'\'))" class="c-reply">[reply]</a>';}
newhtml+='</div>';target.innerHTML=newhtml;if(returnvalues['secondsleft']>0){startCountdown('countdown'+numericId,returnvalues['secondsleft'],returnvalues['showreplylink']);}
Effect.Appear(target);}}}
function updateComment(form,targetid){myxmlhttp=new myXMLHttpRequest();url='/commentedit';content='id='+form.id.value+'&edittext='+encodeURIComponent(form.edittext.value)+'&xmlhttp=1';lastedit=form.edittext.value;myxmlhttp.open("POST",url,true);myxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');myxmlhttp.onreadystatechange=new Function('handleUpdateComment(\''+targetid+'\')');myxmlhttp.send(content);return(false);}
function setupcreply(parentid,parentusername){info=$('cforminfo');baseurl=window.location.href.replace(/(\?.+)?\#.*$/i,'');info.innerHTML='Replying to comment by '+parentusername+' (<a href="'+baseurl+'?creplyto=0#creplyform" onclick="return(cancelcreply())">cancel</a>)';info.style.display='';creplyto=$('cformreplyto');creplyto.value=parentid;creturn=$('cformreturn');creturn.value=creturn.value.replace(/\#.*$/i,'')+'#c'+parentid;$('comment').focus();return false;}
function cancelcreply(){info=$('cforminfo');info.style.display='none';info.innerHTML='';creplyto=$('cformreplyto');parentid=creplyto.value;creplyto.value='';creturn=$('cformreturn');creturn.value=creturn.value.replace(/\#.*$/i,'');$('comment').focus();return false;}
var clock=0;
function cshow(commentId,thumbsActive){if(!clock){clock=1;Effect.SlideDown('cbody'+commentId,{afterFinish:finishShow});if(!dontLook[commentId]&&thumbsActive){$('colorthumbs'+commentId).style.display='inline';$('graythumbs'+commentId).style.display='none';}else{$('colorthumbs'+commentId).style.display='none';$('graythumbs'+commentId).style.display='inline';}}
return false;}
function finishShow(obj){var commentid=obj.element.id.replace(/cbody/,'');if($('cshowa'+commentid).style.display=='none'){$('cshowa'+commentid).style.display='inline';$('chidea'+commentid).style.display='none';}else{$('cshowa'+commentid).style.display='none';$('chidea'+commentid).style.display='inline';}
clock=0;return(false);}
function chide(commentId){
	if(!clock){clock=1;Effect.SlideUp('cbody'+commentId,{afterFinish:finishHide});}
	return(false);
}

function finishHide(obj){var commentid=obj.element.id.replace(/cbody/,'');if($('cshowa'+commentid).style.display=='none'||$('cshowa'+commentid).style.display==''){$('cshowa'+commentid).style.display='inline';$('chidea'+commentid).style.display='none';$('colorthumbs'+commentid).style.display='none';$('graythumbs'+commentid).style.display='inline';}else{$('cshowa'+commentid).style.display='none';$('chidea'+commentid).style.display='inline';if(!dontLook[commentid]){$('colorthumbs'+commentid).style.display='inline';}
$('graythumbs'+commentid).style.display='none';}
clock=0;return(false);}

var first_focus=true;

function txtarea_first_focus(){
	if(first_focus){
		first_focus=false;
		document.getElementById('comment').value='';
	}
}

function js_submit_comment(account_id,account_un,comment_id){
	comment_text='';
	comment_text=document.getElementById('comment').value;
	if(first_focus||comment_text==''){
		alert('You must enter a comment.');
	}else{
		document.getElementById('comment_master_holder').style.display='block';
		parent_id=document.getElementById('i_parent_id').value;
		xajax_submit_comment(account_id,account_un,comment_id,comment_text,parent_id);
		document.getElementById('comment').value='';
		document.getElementById('i_parent_id').value='0';
	}
}

function comment_spell_checker(){
	alert('spell checker code');
}

function js_post_reply(parent_id){
	document.getElementById('i_parent_id').value=parent_id;
	document.getElementById('comment_master_holder').style.display='none';
}
