/* http://code.google.com/p/ifaddons/ */SKIFS.quickEdit={config:{button:'<img src="http://ifaddons.googlecode.com/svn/quickedit/release/support/button.png" alt="Quick Edit" /> ',postCellCount:3,editHistoryEnabled:true,addQuickEditButton:true,hideEditButtons:false,enableDoubleClick:false},originalPostHtml:{},postIcons:{},authKey:'',construct:function(useCustomStyles){if(!SKIFS.util.getAjax()||!document.getElementById||!document.body.innerHTML)return;if(!useCustomStyles){document.write('<style type="text/css">'+'.quick-edit { border: 3px solid #000000; padding: 4px; line-height: 100% }'+'.quick-edit textarea { width: 100%; border: 1px solid #999999; padding: 5px; color: #000000; background: #FFFFFF; font-family: Verdana, sans-serif }'+'.quick-edit .editor { margin-bottom: 3px; }'+'.quick-edit .right-buttons input { width: 30px; background: #EFEFEF; border: 1px solid #999999; border-top: 0; margin: -4px 0 0 3px; cursor: pointer }'+'.quick-edit .right-buttons input:hover { background: #CCCCCC; }'+'.quick-edit .break { height: 1px; margin: -1px 0 0 0; clear: both }'+'.quick-edit .save { font-weight: bold }'+'.quick-edit .full { margin-left: 20px }'+'</style>')}var links=document.links;for(var i=0;i<links.length;i++){if(!links[i].href)continue;var href=links[i].href;if(href.match(/act=Post&CODE=08/)){var fid=href.match(/f=([0-9]+)/)[1];var tid=href.match(/t=([0-9]+)/)[1];var pid=href.match(/p=([0-9]+)/)[1];if(this.config.addQuickEditButton){var editButton=document.createElement('span');editButton.innerHTML='<a style="cursor:pointer" onclick="SKIFS.quickEdit.edit('+fid+','+tid+','+pid+')">'+this.config.button+'</a>';links[i].parentNode.insertBefore(editButton,links[i].nextSibling)}if(this.config.hideEditButtons)links[i].style.display='none';if(this.config.enableDoubleClick){var postE=this.getPostElement(pid);postE.fid=fid;postE.tid=tid;postE.pid=pid;postE.ondblclick=function(){SKIFS.quickEdit.edit(this.fid,this.tid,this.pid)}}}}},getPostElement:function(pid){var postAreaE=null;var anchors=document.anchors;for(var i=0;i<anchors.length;i++){if(anchors[i].getAttribute&&anchors[i].getAttribute('name')=='entry'+pid){postAreaE=anchors[i];break}}var postE=postAreaE.nextSibling;if(postE.nodeType!=1)postE=postE.nextSibling;postE=postE.getElementsByTagName('td')[this.config.postCellCount];return postE},edit:function(fid,tid,pid){if(this.originalPostHtml[pid])return;var postE=this.getPostElement(pid);postE.id="post-area-"+pid;this.originalPostHtml[pid]=postE.innerHTML;postE.innerHTML='<form method="post" action="#" id="qe-form-'+pid+'">'+'<div class="quick-edit"><div id="qe-editor-'+pid+'" class="editor"><textarea rows="10" cols="60" disabled="disabled" name="Post" style="height: 200px">Please wait as the post loads...</textarea></div>'+'<div style="float:left" class="buttons"><input name="save" class="save" type="button" value="Save Changes" disabled="disabled" onclick="SKIFS.quickEdit.save('+fid+','+tid+','+pid+')" /> '+'<input name="cancel" class="cancel" type="button" disabled="disabled" value="Cancel" onclick="if(confirm(\'Are you sure you wish to discard your changes?\'))SKIFS.quickEdit.discard('+pid+')" /> '+'<input name="full" class="full" type="button" onclick="this.form.submit()" disabled="disabled" value="Full Edit &gt;&gt;" /></div>'+'<div style="text-align:right" class="right-buttons"><input type="button" value="+" onclick="if(this.form.Post)this.form.Post.style.height=parseInt(this.form.Post.style.height)+100+\'px\'" /><input type="button" value="-" onclick="if(this.form.Post)this.form.Post.style.height=parseInt(this.form.Post.style.height)-100+\'px\'" /></div>'+'<div class="break"></div></div></form>';var req=SKIFS.util.getAjax();req.open('GET',SKIFS.util.getBaseUrl()+'index.php?act=Post&CODE=08&f='+fid+'&t='+tid+'&p='+pid+'&s='+SKIFS.util.getSessionId(),true);req.onreadystatechange=function(){if(req.readyState==4)SKIFS.quickEdit.update(fid,tid,pid,req.responseText)};req.send(null)},update:function(fid,tid,pid,response){var editorE=document.getElementById('qe-editor-'+pid);var formE=document.getElementById('qe-form-'+pid);this.authKey=response.match(/auth_key' value='(.{32})'/)[1];var content=response.match(/<textarea cols='80' rows='20' name='Post' tabindex='3' class='textinput'>((.|\n)*)<\/textarea>/)[1];if(!content)content=response.match(/<textarea cols='80' rows='20' name='Post' tabindex='3' class='textinput'>(.*)<\/textarea>/)[1];editorE.innerHTML='<textarea rows="10" cols="60" name="Post" style="height: 200px">'+content+'</textarea>';this.postIcons[pid]=response.match(/name=('|")iconid('|") value=('|")([0-9]+)('|") checked/)[4];with(formE){Post.focus();save.disabled=false;cancel.disabled=false;full.disabled=false;action=window.location.href.replace(/index\..*$/,'')+'index.php?act=Post&CODE=08&f='+fid+'&t='+tid+'&p='+pid+'&editupload=keep&add_edit='+(this.config.editHistoryEnabled?'1':'0')+'&iconid='+this.postIcons[pid]+'&enableemo=yes&enablesig=yes&preview=1'}},discard:function(pid){var postE=document.getElementById('post-area-'+pid);postE.innerHTML=this.originalPostHtml[pid];this.originalPostHtml[pid]=null;this.postIcons[pid]=null},save:function(fid,tid,pid){var formE=document.getElementById('qe-form-'+pid);if(formE.Post.value==''){alert('You must enter a message to post!');return}formE.Post.disabled=true;formE.cancel.disabled=true;formE.save.value="Saving... please wait";var st=window.location.href.match(/st=([0-9]+)/);st=st?st[1]:0;var req=SKIFS.util.getAjax();req.open('POST',SKIFS.util.getBaseUrl()+'index.php?act=Post&CODE=09&f='+fid+'&t='+tid+'&p='+pid+'&st='+st+'&auth_key='+this.authKey+'&s='+SKIFS.util.getSessionId(),true);req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');req.onreadystatechange=function(){if(req.readyState==4)SKIFS.quickEdit.finish(pid,req.responseText)};req.send('editupload=keep&add_edit='+(this.config.editHistoryEnabled?'1':'0')+'&iconid='+this.postIcons[pid]+'&enableemo=yes&enablesig=yes&Post='+SKIFS.util.utf8Decode(formE.Post.value))},finish:function(pid,response){var formE=document.getElementById('qe-form-'+pid);var newPost=new RegExp('<!\-\- THE POST '+pid+' \-\->((.|\n)*?)<!\-\- THE POST \-\->');newPost=newPost.exec(response);if(!newPost){alert("An error has occurred while saving your post.");formE.save.value="Save";return}newPost=newPost[1];var postE=document.getElementById('post-area-'+pid);postE.innerHTML=newPost;this.originalPostHtml[pid]=null;this.postIcons[pid]=null}}