if('function'!=typeof addLoadEvent)addLoadEvent=function(func){var oldonload=window.onload;if(typeof window.onload!='function')window.onload=func;else window.onload=function(){oldonload();func();}};var commentPreview;var commentLast;var acpFormElement;var inputElement;var outputElement;var doitElement;var authorElement;var urlElement;function commentPreviewInit(){doitElement=document.getElementById('acp-preview');if(!doitElement)return false;acpFormElement=doitElement.parentNode;while('form'!=acpFormElement.tagName.toLowerCase())acpFormElement=acpFormElement.parentNode;disableSubmit();outputElement=document.getElementById('ajax-comment-preview');textAreaElement=acpGetFormInput('comment');textAreaElement.onkeyup=function(){if(!submitDisabled()&&textAreaElement.value!=commentLast){disableSubmit();outputElement.innerHTML='<div style="margin-top:8px">'+AjaxCommentPreviewVars.emptyString+'</div>';};};textAreaElement.onchange=function(){if(!submitDisabled()&&textAreaElement.value!=commentLast){disableSubmit();outputElement.innerHTML='<div style="margin-top:8px">'+AjaxCommentPreviewVars.emptyString+'</div>';};};inputElement=acpGetFormInput('comment');authorElement=acpGetFormInput('author');urlElement=acpGetFormInput('url');if(inputElement==null||outputElement==null||doitElement==null)return;doitElement.onclick=commentPreviewAJAX;if(''==AjaxCommentPreviewVars.emptyString)outputElement.style.display='none';else outputElement.innerHTML='<div style="margin-top:8px">'+AjaxCommentPreviewVars.emptyString+'</div>';};addLoadEvent(commentPreviewInit);function enableSubmit(){submitElement=acpGetFormInput('submit');submitElement.style.visibility='visible';submitElement.style.display='inline';doitElement.style.visibility='hidden';doitElement.style.display='none';};function disableSubmit(){submitElement=acpGetFormInput('submit');submitElement.style.visibility='hidden';submitElement.style.display='none';doitElement.style.visibility='visible';doitElement.style.display='inline';};function submitDisabled(){submitElement=acpGetFormInput('submit');if(submitElement.style.display=='none'){return true;}return false;};function acpGetFormInput(el){for(i=0;i<acpFormElement.elements.length;i++)if(el==acpFormElement.elements[i].name)return acpFormElement.elements[i];};function commentPreviewAJAX(){var req='';var newSack=false;commentPreview=new sack(AjaxCommentPreviewVars.url);var sep=commentPreview.argumentSeparator?commentPreview.argumentSeparator:'&';commentPreview.method='POST';commentPreview.encodeURIString=false;commentPreview.onLoading=function(){outputElement.innerHTML='<img style="margin:2px;" src="'+AjaxCommentPreviewVars.image_loading+'" alt="" />';};commentPreview.onLoaded=function(){outputElement.innerHTML+='';};commentPreview.onInteractive=function(){outputElement.innerHTML+='';};commentPreview.onCompletion=function(){outputElement.innerHTML=commentPreview.response;enableSubmit();};req=commentPreview.encVar('text',inputElement.value);doitElement=document.getElementById('acp-preview');if(req){req+=authorElement?sep+commentPreview.encVar('author',authorElement.value):'';req+=urlElement?sep+commentPreview.encVar('url',urlElement.value):'';}else{if(authorElement)commentPreview.encVar('author',authorElement.value);if(urlElement)commentPreview.encVar('url',urlElement.value);req=new Array();for(key in commentPreview.vars)req[req.length]=key+"="+commentPreview.vars[key][0];req=req.join(sep);newSack=true;}if(''!=inputElement.value){commentPreview.runAJAX(newSack?'':req);}else if(''==inputElement.value){if(''==AjaxCommentPreviewVars.emptyString){outputElement.innerHTML='';outputElement.style.display="none";}else outputElement.innerHTML='<div style="margin-top:8px">'+AjaxCommentPreviewVars.emptyString+'</div>';disableSubmit();}commentLast=inputElement.value;}