
var dontLook=new Object();function pC(row,check){if(!diggburylock){diggburylock=1;if(!checkIE()){Effect.Fade('strong-'+row,{duration:1.0,afterFinish:function(){incrCommentDiggs(row);Effect.Appear('strong-'+row,{duration:1.0});}});}else{setTimeout('incrCommentDiggs('+row+')',1000);}
new Ajax.Request('/member/pushcomment',{method:'post',parameters:'commentid='+row+'&up=1&pushcheck='+check,onSuccess:function(xh){diggburylock=0;if(xh.responseText!='NA'){updateCommentDiggs(row,xh.responseText);}}});}}
function tC(row,check){if(!diggburylock){diggburylock=1;incrCommentBuries(row);new Ajax.Request(window.location.pathname,{method:'post',parameters:'commentid='+row+'&up=0&pushcheck='+check,onSuccess:function(xh){diggburylock=0;if(xh.responseText!='NA'){updateCommentDiggs(row,xh.responseText);}}});}}
function incrCommentDiggs(id){target=$('strong-'+id);currentCount=target.innerHTML.replace(/ 推[s]{0,1}/,'');currentCount=currentCount.replace(/\+ /,'');currentCount=currentCount.replace(/\- /,'-');currentCount++;if(currentCount>=0){target.innerHTML='+ '+currentCount+' 推';}else{target.innerHTML=currentCount+' 推';}
greyFlags(id);}
function incrCommentBuries(id){greyFlags(id);collapseComment(id);target=$('strong-'+id);var currentCount=target.innerHTML.replace(/ 推[s]{0,1}/,'');currentCount=currentCount.replace(/\+ /,'');currentCount=currentCount.replace(/\- /,'-');currentCount--;if(currentCount>=0){if(currentCount==1){target.innerHTML='+ '+currentCount+' 推';}else{target.innerHTML='+ '+currentCount+' 推';}}else{if(currentCount==-1){target.innerHTML='- 1 推';}else{number=-currentCount;target.innerHTML='- '+number+' 推';}}}
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;var key=$('commentkey').value;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+'" /><input type="hidden" name="check" value="'+key+'" /></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,xh){eval('returnvalues = ('+xh.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){lastedit=form.edittext.value;new Ajax.Request(window.location.pathname,{method:'post',parameters:'id='+form.id.value+'&edittext='+encodeURIComponent(form.edittext.value)+'&xmlhttp=1&check='+form.check.value,onSuccess:function(xh){handleUpdateComment(targetid,xh);}});return false;}
function setupcreply(parentid,parentusername){ctool=$('ctoolbar');ctool.style.display='none';info=$('cforminfo');baseurl=window.location.href.replace(/(\?.+)?\#.*$/i,'');info.innerHTML='回覆 '+parentusername+'的評論 (<a href="'+baseurl+'?creplyto=0#creplyform" onclick="return(cancelcreply())">取消</a>)';info.style.display='';$('cformreplyto').value=parentid;creturn=$('cformreturn');creturn.value=creturn.value.replace(/\#.*$/i,'')+'#c'+parentid;$('comment').focus();return false;}
function cancelcreply(){ctool=$('ctoolbar');ctool.style.display='';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;}
function pW(row,check){if(!diggburylock){diggburylock=1;if(!checkIE()){Effect.Fade('strong-'+row,{duration:1.0,afterFinish:function(){incrCommentDiggs(row);Effect.Appear('strong-'+row,{duration:1.0});}});}else{setTimeout('incrCommentDiggs('+row+')',1000);}
new Ajax.Request('/member/pushwinevent',{method:'post',parameters:'wineventid='+row+'&up=1&pushcheck='+check,onSuccess:function(xh){diggburylock=0;if(xh.responseText!='NA'){updateCommentDiggs(row,xh.responseText);}}});}}

function hide() {
txt=prompt("請輸入要限回覆後才能觀看的文字","請輸入限回覆才能觀看的文字");
if(txt!=null) {
AddTxt="[hide]"+txt;AddText(AddTxt);AddTxt="[/hide]";AddText(AddTxt);
}
}
function AddText(NewCode) {
target = $('comment');
if (target.createTextRange && target.caretPos) {
var caretPos = target.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
}
else {
target.value+=NewCode
}
target.focus();
}
