function JCommentsEvents(){} function JCommentsInput(){} function JCommentsIndicator(){this.init();} function JCommentsForm(id,editor){this.init(id,editor);} function JCommentsEditor(textarea,resizable){this.init(textarea,resizable);} function JComments(oi,og,r){this.init(oi,og,r);} JCommentsEvents.prototype = { add: function(o,e,f){if(o.addEventListener){o.addEventListener(e,f,false);return true;}else if(o.attachEvent){return o.attachEvent("on"+e,f);}else{return false;}}, remove: function(o,e,f){if(o.removeEventListener){o.removeEventListener(e,f,false);}else if(o.detachEvent){o.detachEvent( "on"+e,o[e+f] );o[e+f]=null;o["e"+e+f]=null;}}, cancel: function(e){if(e.stopPropagation){e.cancelBubble=true;e.preventDefault();e.stopPropagation();}e.returnValue=false;return false;}, target: function(e){var t;if(!e)e=window.event;if(e.target)t=e.target;else if(e.srcElement)t=e.srcElement;if(t.nodeType==3)t=t.parentNode;return t;} }; JCommentsInput.prototype = { register: function(el){if(el){var th=this,events=new JCommentsEvents();events.add(el,'focus',function(e){return th.onFocus(e);});events.add(el,'blur',function(e){return th.onBlur(e);});}}, unregister: function(el){if(el){var th=this,events=new JCommentsEvents();events.remove(el,'focus',function(e){return th.onFocus(e);});events.remove(el,'blur',function(e){return th.onBlur(e);});}}, onFocus: function(e){var t=JCommentsEvents.prototype.target(e);if(t!=null){t.className=t.className.replace('error','')+' selected';}}, onBlur: function(e){var t=JCommentsEvents.prototype.target(e);if(t!=null){var c=t.className.replace('error','');c=c.replace('error','');c=c.replace('selected','');t.className=c.replace(/^\s+/g,"");}} }; JCommentsEditor.prototype = { ta: null, l10n: {}, tags: {}, smiles: {}, events: null, counter: null, focused: false, resizable: true, init: function(textareaID, r) { this.ta=JComments.prototype.$(textareaID); this.l10n={counterPre:'',counterPost:' symbols left'}; this.resizable=r; this.events=new JCommentsEvents(); this.defaultHeight=this.ta.clientHeight; this.defaultRows=this.ta.rows; //if(this.resizable){this.addGrippie();} this.isWebkit=/webkit/.test(navigator.userAgent.toLowerCase()); var th = this; this.events.add(document,!window.opera&&document.all?'keydown':'keypress',function(e){return th.onKeyPress(e);}); this.events.add(this.ta,'click',function(e){th.closeSmiles();return th.storeCaret(this.ta);}); this.events.add(this.ta,'select',function(e){return th.storeCaret(this.ta);}); this.events.add(this.ta,'change',function(e){th.onChange(); return th.storeCaret(this.ta);}); this.events.add(this.ta,'keyup',function(e){return th.onChange();}); this.events.add(this.ta,'focus',function(e){th.closeSmiles(); return th.focused=true;}); this.events.add(this.ta,'blur',function(e){return th.focused=false;}); }, onKeyPress: function(e) { if (!this.focused){return;} var k=String.fromCharCode(e.keyCode?e.keyCode:e.charCode),t; for(var id in this.tags){ t=this.tags[id]; if(!t.key||k.toUpperCase()!=t.key.toUpperCase())continue; if(t.ctrl&&!e[t.ctrl+"Key"])continue; this.insertTag(id); return this.events.cancel(e); } return e.returnValue; }, defined: function(v){return (typeof(v)!="undefined");}, clear: function(){this.ta.value='';if(this.defaultHeight){this.ta.style.height=this.defaultHeight+'px';}this.updateCounter();}, focus: function(){this.ta.focus();}, storeCaret: function(){var ta=this.ta;if(ta.createTextRange)ta.caretPos=document.selection.createRange().duplicate();}, getElementPos: function(e){var p={left:0,top:0,right:0,bottom:0};while(e!=null){p.left+=e.offsetLeft;p.top+=e.offsetTop;e=e.offsetParent;}p.right+=p.left;p.bottom+=p.top;return p;}, getSelection: function(){var ta=this.ta,s='';if(document.selection&&document.selection.createRange){s=document.selection.createRange().text;}else{s=ta.value.substr(ta.selectionStart,ta.selectionEnd-ta.selectionStart);}return s;}, insertText: function(text) { var ta=this.ta; if(this.defined(ta.caretPos)&&ta.createTextRange){ta.focus();var sel=document.selection.createRange();sel.text=sel.text+text;ta.focus();} else if(this.defined(ta.selectionStart)){ var ss=ta.value.substr(0, ta.selectionStart); var se=ta.value.substr(ta.selectionEnd),sp=ta.scrollTop; ta.value=ss+text+se; if(ta.setSelectionRange){ta.focus();ta.setSelectionRange(ss.length+text.length,ss.length+text.length);} ta.scrollTop=sp; } else {ta.value+=text;ta.focus(ta.value.length-1);} }, surroundText: function(t1,t2) { var ta=this.ta; if (this.defined(ta.caretPos) && ta.createTextRange){ var cp=ta.caretPos,tl=cp.text.length; cp.text=cp.text.charAt(cp.text.length-1)==' '?t1+cp.text+t2+' ':t1+cp.text+t2; if(tl==0){cp.moveStart("character",-t2.length);cp.moveEnd("character",-t2.length);cp.select();} else{ta.focus(cp);} }else if(this.defined(ta.selectionStart)){ var ss=ta.value.substr(0,ta.selectionStart),se=ta.value.substr(ta.selectionEnd); var sl=ta.value.substr(ta.selectionStart,ta.selectionEnd-ta.selectionStart); var nc=ta.selectionStart,sp=ta.scrollTop; ta.value=ss+t1+sl+t2+se; if(ta.setSelectionRange){ if(sl.length==0){ta.setSelectionRange(nc+t1.length,nc+t1.length);} else{ta.setSelectionRange(nc,nc+t1.length+sl.length+t2.length);} ta.focus(); } ta.scrollTop=sp; }else{ta.value+=t1+t2;ta.focus(ta.value.length-1);} }, insertTag: function(id) {var tag=this.tags[id];if(!tag)return;var s=this.getSelection();if(s.length>0){this.surroundText(tag.open,tag.close);}}, initTags: function(){ if (this.bbc==null||this.bbc.length==0){ this.bbc={}; this.bbc['b']={id:'bbcode-b',open:'[b]',close:'[/b]',key:'B',ctrl:'ctrl',hint:'Bold'}; this.bbc['i']={id:'bbcode-i',open:'[i]',close:'[/i]',key:'I',ctrl:'ctrl',hint:'Italic'}; this.bbc['u']={id:'bbcode-u',open:'[u]',close:'[/u]',key:'U',ctrl:'ctrl',hint:'Underline'}; this.bbc['s']={id:'bbcode-s',open:'[s]',close:'[/s]',key:null,ctrl:null,hint:'Strikeout'}; this.bbc['img']={id:'bbcode-img',open:'[img]',close:'[/img]',key:null,ctrl:null,hint:'Image'}; this.bbc['url']={id:'bbcode-url',open:'[url]',close:'[/url]',key:null,ctrl:null,hint:'Link'}; this.bbc['hide']={id:'bbcode-hide',open:'[hide]',close:'[/hide]',key:null,ctrl:null,hint:'Hidden'}; this.bbc['quote']={id:'bbcode-quote',open:'[quote]',close:'[/quote]',key:null,ctrl:null,hint:'Quote'}; this.bbc['list']={id:'bbcode-list',open:'[list][*]',close:'[/list]',key:null,ctrl:null,hint:'List'}; } }, createButton: function(i,t,c,f,img){ var e;if(img==null||img==""){e=document.createElement('a');e.style.display='block';e.setAttribute('href','#');} else{e=document.createElement('img');if(t){e.setAttribute('alt',t);}e.setAttribute('src',img);if(!c){c='custombbcode';}} if(i){e.setAttribute('id',i);}if(t){e.setAttribute('title',t);}if(c){e.className=c;} var ee=e;e.onclick=(f!=null?function(){f(ee); return false;}:function(){return false;}); return e; }, addButton: function(id,h,p,ot,ct,css,img) { if(this.ta){ this.initTags(); var tag=this.bbc[id],th=this; if(!tag){ if(ot&&ct) { this.bbc[id]={id:id,open:ot,close:ct,key:null,ctrl:null,hint:h}; tag=this.bbc[id]; } else { return; } } if(this.bbcPanel==null){ this.bbcPanel=document.createElement('span'); this.bbcPanel.className='bbcode'; this.bbcPanel.style.display='block'; this.ta.parentNode.insertBefore(this.bbcPanel,this.ta); } var f=function(){var s=th.getSelection();if(s.length>0){th.surroundText(tag.open,tag.close);}else{var v=prompt(p,'');if(null!=v && ''!=v){th.insertText(tag.open+v+tag.close);}}return false;}; tag.e=this.createButton(tag.id,(h!=null?h:tag.hint),(css?css:tag.id),f,img); this.bbcPanel.appendChild(tag.e); this.tags[tag.id]=tag; } }, initSmiles: function(p){this.smilesPath=p; if(this.ta){ this.smilesPanel=document.createElement('div'); if(this.bbcPanel){ document.body.appendChild(this.smilesPanel); this.smilesPanel.id='comments-form-smilespanel'; this.smilesPanel.setAttribute('style','display:none;top:0;left:0;position:absolute;'); this.smilesPanel.onclick=function(){this.style.display='none';}; var jc=this,f=function(e){ var sp=jc.smilesPanel,p=jc.getElementPos(e); if(sp){var sps=sp.style;sps.display=(sps.display=='none'||sps.display==''?'block':'none');sps.left=p.left+"px";sps.top=p.bottom+e.offsetHeight+"px";sps.zIndex=99;} return false; }; this.bbcPanel.appendChild(this.createButton(null,null,'bbcode-smile',f)); } else { this.smilesPanel.className='smiles';this.ta.parentNode.insertBefore(this.smilesPanel, this.ta); } } }, closeSmiles: function(){if(this.smilesPanel&&this.bbcPanel){this.smilesPanel.style.display='none';}}, addSmile: function(code,image){ if(this.ta){ if(!this.smilesPath||!this.smilesPanel){return;} var th=this,e=document.createElement('img'); e.setAttribute('src',this.smilesPath+'/'+image); e.setAttribute('alt',code); e.className='smile'; e.onclick=function(){th.insertText(' '+code+' ');}; this.smilesPanel.appendChild(e); } }, addCounter: function(m,pre,post,className){ if(this.ta){ if(pre!=null){this.l10n.counterPre=pre;}if(post!=null){this.l10n.counterPost=post;} var ch=document.createElement('span');ch.className=className!=null?className:''; var t1=document.createTextNode(this.l10n.counterPre+' '),t2=document.createTextNode(' '+this.l10n.counterPost); var c=document.createElement('span');ch.appendChild(t1);ch.appendChild(c);ch.appendChild(t2); if(this.resizable){if(this.grippie!=null){this.grippie.appendChild(ch);}} else{var d=document.createElement('div');d.className='counterpanel';this.ta.parentNode.insertBefore(d,this.ta.nextSibling);d.appendChild(ch);} this.counter={e:c,max:m}; this.updateCounter(); } }, updateCounter: function(){if(this.counter!=null){var ta=this.ta,e=this.counter.e;try{var n=document.createElement(e.tagName),v=this.counter.max;if(ta.value.length>0){v=v-ta.value.length;var ln=ta.value.match(/[^\r]\n/g);if(ln){v=v-ln.length;}}n.innerHTML=(v>=0)?v:0;e.parentNode.replaceChild(n,e);this.counter.e=n;}catch(ex){}}}, mousePosition: function(e){var px=0,py=0;if(!e){e=window.event;}if(e.pageX||e.pageY){px=e.pageX;py=e.pageY;}else if(e.clientX||e.clientY){px=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;py=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}return {x:px,y:py};}, onChange: function(){this.updateCounter();if(this.ta&&!this.isWebkit){var l=this.ta.value.split('\n');this.ta.rows=(l.lengthb[0]&&a[1]b[1])){window.scrollTo(a[0],a[1]);}} }; JCommentsForm.prototype = { id:null, form: null, events: null, editor: null, elements: {}, store: new Array('name','email','homepage'), fadeTimer: null, init: function(id,editor){this.id=id;this.form=this.$(id);this.editor=editor;this.events=new JCommentsEvents();this.setElements(new Array('name','email','homepage','title','comment'));this.restoreValues();this.clear('captcha');this.setCaptcha();}, setCaptcha: function(){this.captchaImage=this.$(this.id+'-captcha-image');this.register('captcha');}, setEditor: function(e){this.editor=e;}, setElements: function(e){for(var i=0;ie){for(var i=s;i>=e;i--){setTimeout("JComments.prototype.setOpacity('"+id+"',"+i+")",(timer*speed));timer++;}var o=JComments.prototype.$(id);if(o){setTimeout(function(){o.style.display='none';},((s-e)*speed));}}else if(s