
var Webnote=new Class({Extends:Widget,initialize:function(){this.cfg={hasRefreshBtn:false,title:loc.text("webnote_title"),module:"Webnote"}
this.tags={};this.defaultProfile["title"]=this.cfg.title;this.defaultProfile["text"]=loc.text("webnote_text");this.defaultProfile["font"]="Tahoma";this.defaultProfile["size"]="11px";this.defaultProfile["weight"]="normal";this.defaultProfile["style"]="normal";this.defaultProfile["decoration"]="none";this.defaultProfile["bgcolor"]="orig";this.defaultProfile["color"]="orig";this.content="<div class='webnote_text'></div><div style='width:100%;margin:0pt auto'><textarea name='edit' class='webnote_textarea' style='display:none'></textarea></div>";},onBuildInterface:function(){var self=this;this.settings="<form id='f"+this.id+"' onsubmit='return false'>"+"<div class='settings_section' style='padding:4px 8px'>"+" <span class='settings_label'>"+loc.text("inp_title")+"</span>"+" <input type='text' name='title' size='15' class='settings_control'>"+"</div>"+"<div class='settings_section' style='padding:4px 8px'>"+" <span class='settings_label'>"+loc.text("webnote_font")+"</span>"+" <select name='font'>"+'  <option value="Arial Black" style="font-family: Arial Black;">Arial Black</option>'+'  <option value="Century Gothic" style="font-family: Century Gothic;">Century Gothic</option>'+'  <option value="Comic Sans MS" style="font-family: Comic Sans MS;">Comic Sans MS</option>'+'  <option value="Courier New" style="font-family: Courier New;">Courier New</option>'+'  <option value="cursive" style="font-family: cursive;">cursive</option>'+'  <option value="Impact" style="font-family: Impact;">Impact</option>'+'  <option value="monospace" style="font-family: monospace;">monospace</option>'+'  <option value="Tahoma" style="font-family: Tahoma;">Tahoma</option>'+'  <option value="Times New Roman" style="font-family: Times New Roman;">Times New Roman</option>'+'  <option value="Trebuchet MS" style="font-family: Trebuchet MS;">Trebuchet MS</option>'+'  <option value="Verdana" style="font-family: Verdana;">Verdana</option>'+" </select>"+" <img name='weight' src='pix/bold.gif' style='border:1px solid #EAEAEA' title='"+loc.text("webnote_bold")+"'>"+" <img name='style' src='pix/italic.gif' style='border:1px solid #EAEAEA' title='"+loc.text("webnote_italic")+"'>"+" <img name='decoration' src='pix/underline.gif' style='border:1px solid #EAEAEA' title='"+loc.text("webnote_underline")+"'>"+"</div>"+"<div class='settings_section' style='padding:4px 8px'>"+" <span class='settings_label'>"+loc.text("webnote_size")+"</span>"+" <select name='size'>"+'  <option value="11px">'+loc.text("webnote_size_small")+'</option>'+'  <option value="14px">'+loc.text("webnote_size_middle")+'</option>'+'  <option value="20px">'+loc.text("webnote_size_big")+'</option>'+" </select>"+"</div>"+"<div class='settings_section'>"+" <span class='settings_label'>"+loc.text("webnote_color")+"</span>"+" <div name='color-red' class='bg-sel red'></div>"+" <div name='color-orange' class='bg-sel orange'></div>"+" <div name='color-yellow' class='bg-sel yellow'></div>"+" <div name='color-green' class='bg-sel green'></div>"+" <div name='color-blue' class='bg-sel blue'></div>"+" <div name='color-orig' class='bg-sel orig'></div>"+"</div>"+"<div class='settings_section'>"+" <span class='settings_label'>"+loc.text("webnote_bgcolor")+"</span>"+" <div name='bgcolor-red' class='bg-sel wb-red'></div>"+" <div name='bgcolor-orange' class='bg-sel wb-orange'></div>"+" <div name='bgcolor-yellow' class='bg-sel wb-yellow'></div>"+" <div name='bgcolor-green' class='bg-sel wb-green'></div>"+" <div name='bgcolor-blue' class='bg-sel wb-blue'></div>"+" <div name='bgcolor-orig' class='bg-sel orig'></div>"+"</div></form>";this.mid.firstChild.childNodes[1].innerHTML=this.settings;this.tags['title']=this.mid.getElement('input[name=title]');this.tags['font']=this.mid.getElement('select[name=font]');this.tags['size']=this.mid.getElement('select[name=size]');this.tags['weight']=this.mid.getElement('img[name=weight]');this.tags['style']=this.mid.getElement('img[name=style]');this.tags['decoration']=this.mid.getElement('img[name=decoration]');this.setContent(this.content);this.tags['wtext']=this.mid.getElement('.webnote_text');this.tags['wtextarea']=this.mid.getElement('.webnote_textarea');if(!ident.isPublic()||(ident.isPublic()&&ident.isPublicLogged())){this.tags['wtext'].addEvent('click',function(e){self.editText(self,self.tags['wtext'],self.tags['wtextarea']);});}
this.tags['title'].addEvent('keydown',function(e){if(e.key=='enter')
self.settingsSetTitle();});this.tags['font'].addEvent('change',function(e){self.changeFont();});this.tags['size'].addEvent('change',function(e){self.changeSize();});this.tags['weight'].addEvent('click',function(e){self.changeWeight();});this.tags['style'].addEvent('click',function(e){self.changeStyle();});this.tags['decoration'].addEvent('click',function(e){self.changeDecoration();});this.mid.getElement('div[name=color-red]').addEvent('click',function(){self.setColor('redc');});this.mid.getElement('div[name=color-orange]').addEvent('click',function(){self.setColor('orangec');});this.mid.getElement('div[name=color-yellow]').addEvent('click',function(){self.setColor('yellowc');});this.mid.getElement('div[name=color-green]').addEvent('click',function(){self.setColor('greenc');});this.mid.getElement('div[name=color-blue]').addEvent('click',function(){self.setColor('bluec');});this.mid.getElement('div[name=color-orig]').addEvent('click',function(){self.setColor('orig');});this.mid.getElement('div[name=bgcolor-red]').addEvent('click',function(){self.setBgColor('wb-red');});this.mid.getElement('div[name=bgcolor-orange]').addEvent('click',function(){self.setBgColor('wb-orange');});this.mid.getElement('div[name=bgcolor-yellow]').addEvent('click',function(){self.setBgColor('wb-yellow');});this.mid.getElement('div[name=bgcolor-green]').addEvent('click',function(){self.setBgColor('wb-green');});this.mid.getElement('div[name=bgcolor-blue]').addEvent('click',function(){self.setBgColor('wb-blue');});this.mid.getElement('div[name=bgcolor-orig]').addEvent('click',function(){self.setBgColor('orig');});this.tags['title'].value=this.profile.title;if(this.profile.font){this.tags['font'].value=this.profile.font;this.tags['wtext'].setStyle('font-family',this.profile.font);this.tags['wtextarea'].setStyle('font-family',this.profile.font);}
if(this.profile.size){this.tags['size'].value=this.profile.size;this.tags['wtext'].setStyle('font-size',this.profile.size);this.tags['wtextarea'].setStyle('font-size',this.profile.size);}
if(this.profile.weight){this.tags['wtext'].setStyle('font-weight',this.profile.weight);this.tags['wtextarea'].setStyle('font-weight',this.profile.weight);if(this.profile.weight=='bold')
this.tags['weight'].setStyle('border-color','black');}
if(this.profile.style){this.tags['wtext'].setStyle('font-style',this.profile.style);this.tags['wtextarea'].setStyle('font-style',this.profile.style);if(this.profile.style=='italic')
this.tags['style'].setStyle('border-color','black');}
if(this.profile.decoration){this.tags['wtext'].setStyle('text-decoration',this.profile.decoration);this.tags['wtextarea'].setStyle('text-decoration',this.profile.decoration);if(this.profile.decoration=='underline')
this.tags['decoration'].setStyle('border-color','black');}
this.tags['wtext'].addEvent('keyup',function(){self.tags['wtext'].innerHTML=text2html(this.value);self.tags['wtext'].setStyle('display','block');self.style.height=(self.tags['wtext'].offsetHeight+16)+"px";self.tags['wtext'].setStyle('display','none');});this.tags['wtextarea'].addEvent('blur',function(){self.inpblur(self,self.tags['wtext'],self.tags['wtextarea']);});var t=this.profile.text.jsUnescape();this.tags['wtext'].innerHTML=text2html(t).parseUrl();this.setValue('edit',t);this.setBgColor(this.profile.bgcolor,1);this.setTitle(this.profile.title);this.setColor(this.profile.color,1);},editText:function(widget,text_show,text_edit){var h=text_show.offsetHeight;var self=this;text_show.setStyle('display','none');text_edit.setStyle('display','block');text_edit.style.height=(h+16)+"px";text_edit.focus();},inpblur:function(widget,text_show,text_edit){var text=text_edit.value.replace(/\\/g,"");text_edit.setStyle('display','none');htmlText=text2html(text);text_show.innerHTML=htmlText.jsUnescape().parseUrl();text_show.setStyle('display','block');widget.profile.text=text.jsEscape();widget.save();},showText:function(){},applyText:function(){},changeFont:function(){this.profile.font=this.getValue('font');this.tags['wtext'].setStyle('font-family',this.profile.font);this.tags['wtextarea'].setStyle('font-family',this.profile.font);this.save();},changeSize:function(){this.profile.size=this.getValue('size');this.tags['wtext'].setStyle('font-size',this.profile.size);this.tags['wtextarea'].setStyle('font-size',this.profile.size);this.save();},changeWeight:function(){if(this.profile.weight=='normal'){this.profile.weight='bold';this.tags['weight'].setStyle('border-color','black');}else{this.profile.weight='normal';this.tags['weight'].setStyle('border-color','#EAEAEA');}
this.tags['wtext'].setStyle('font-weight',this.profile.weight);this.tags['wtextarea'].setStyle('font-weight',this.profile.weight);this.save();},changeStyle:function(){if(this.profile.style=='normal'){this.profile.style='italic';this.tags['style'].setStyle('border-color','black');}else{this.profile.style='normal';this.tags['style'].setStyle('border-color','#EAEAEA');}
this.tags['wtext'].setStyle('font-style',this.profile.style);this.tags['wtextarea'].setStyle('font-style',this.profile.style);this.save();},changeDecoration:function(){if(this.profile.decoration=='none'){this.profile.decoration='underline';this.tags['decoration'].setStyle('border-color','black');}else{this.profile.decoration='none';this.tags['decoration'].setStyle('border-color','#EAEAEA');}
this.tags['wtext'].setStyle('text-decoration',this.profile.decoration);this.tags['wtextarea'].setStyle('text-decoration',this.profile.decoration);this.save();},setColor:function(color,notsave){this.profile.color=color;this.setTextColor();this.setTextareaColor();if(!notsave)
this.save();},setBgColor:function(bgcolor,notsave){this.profile.bgcolor=bgcolor;if(bgcolor!='orig'){this.mid.getElement('.box-content').set('class','box-content '+bgcolor);}else{this.mid.getElement('.box-content').set('class','box-content');}
this.setTextColor();this.setTextareaColor();if(!notsave)
this.save();},setTextColor:function(){var wnt=this.tags['wtext'];wnt.set('class','webnote_text');if(this.profile.color!='orig'){wnt.addClass(this.profile.color);}},setTextareaColor:function(){var wnt=this.tags['wtextarea'];wnt.set('class','webnote_textarea');if(this.profile.bgcolor!='orig'){wnt.addClass(this.profile.bgcolor);}
if(this.profile.color!='orig'){wnt.addClass(this.profile.color);}},settingsAll:function(){this.settingsSetTitle();}});