
var Iwiw=new Class({Extends:Widget,initialize:function(){this.isLoading=false;this.cfg={hasSettingsBtn:true,title:"IWIW",module:"Iwiw"}
this.tags={};this.content="<div id='cont' style='display:block' class='iwiw'>"+" <div id='error' style='width:210px;margin:5px auto;color:red'></div>"+"   <div id='login' class='login' style='background-color:#d7e4f9;width:225px;margin:0pt auto;'>"+" <div style='padding:10px'>"+"  <span style='float:left;width:80px;'><b>"+loc.text("iwiw_email")+"<b></span>"+"  <input name='username' type='text' style='border:1px solid #000066'>"+" </div>"+" <div style='padding:0px 10px 10px 10px'>"+"  <span style='float:left;width:80px;'><b>"+loc.text("iwiw_pass")+"<b></span>"+"  <input name='password' type='password' style='border:1px solid #000066'>"+" </div>"+" <div style='padding:0px 0px 10px 0px;margin-left:90px'>"+"  <input type='button' name='test' class='module_btn' value='"+loc.text("iwiw_login")+"'>"+" </div>"+" </div>"+"</div>";this.defaultProfile["title"]="IWIW";this.defaultProfile["username"]="";this.defaultProfile["bgcolor"]="orig";this.defaultProfile["stream"]=1;this.defaultProfile["period"]=1200;this.loginError=false;this.deftxt='Üzenj, vagy ossz meg tartalmakat!';this.txtfocus=false;},onBuildInterface:function(){var t=this;t.settings="<form id='f"+t.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'>"+" <span class='settings_label'>"+loc.text("iwiw_need_stream")+"</span>"+" <input type='checkbox' size='15' name='stream'"+(this.profile.stream?' checked':'')+">"+"</div>"+"<div class='settings_section'>"+" <span class='settings_label'>"+loc.text("rss_inp_refresh")+"</span>"+" <select name='period' class='settings_control'>"+"  <option value='120'"+(this.profile.period=='120'?' selected':'')+">"+loc.text("rss_p120")+"</option>"+"  <option value='300'"+(this.profile.period=='300'?' selected':'')+">"+loc.text("rss_p300")+"</option>"+"  <option value='600'"+(this.profile.period=='600'?' selected':'')+">"+loc.text("rss_p600")+"</option>"+"  <option value='1200'"+(this.profile.period=='1200'?' selected':'')+">"+loc.text("rss_p1200")+"</option>"+"  <option value='1800'"+(this.profile.period=='1800'?' selected':'')+">"+loc.text("rss_p1800")+"</option>"+"  <option value='3600'"+(this.profile.period=='3600'?' selected':'')+">"+loc.text("rss_p3600")+"</option>"+"  <option value='10800'"+(this.profile.period=='10800'?' selected':'')+">"+loc.text("rss_p10800")+"</option>"+" </select>"+"</div>"+"</form>";t.setSettings(t.settings+t.changeColors);t.setContent(t.content);t.tags['title']=t.mid.getElement('input[name=title]');t.tags['username']=t.mid.getElement('input[name=username]');t.tags['password']=t.mid.getElement('input[name=password]');t.tags['btn']=t.mid.getElement('input[name=test]');t.tags['stream']=t.mid.getElement('input[name=stream]');t.tags['period']=t.mid.getElement('select[name=period]');t.tags['login']=t.mid.getElement('div[id=login]');t.tags['error']=t.mid.getElement('div[id=error]');t.tags['title'].value=t.profile.title;t.tags['title'].addEvent('keydown',function(e){if(e.key=='enter')
t.settingsSetTitle();});t.tags['btn'].addEvent('click',function(){t.saveProfile();t.isSettingsReduced=true;t.hideSettings(1);});t.tags['password'].addEvent('keydown',function(e){if(e.key=='enter')
t.switchSettings();});t.setTitle(t.profile.title);t.setValue('username',t.profile.username);if(t.tags["username"].value!=""){t.showElId('login','none');}
t.tags['stream'].addEvent('click',function(){t.profile.stream=t.getProp('stream','checked')?1:0;t.save();t.refresh(0);});t.tags['period'].addEvent('change',function(){t.setPeriod();});t.colorsAction();t.setBgColor(t.profile.bgcolor,1);},onOpen:function(){var self=this;if(trim(this.profile.title)==""){this.profile.title=loc.text("iwiw_title");}
this.refresh(0);main.processTimer(this.id,this.profile.period*1000);},saveProfile:function(){if(this.profile.username!=this.tags['username'].value||this.tags['password'].value!=''){this.profile.username=""+trim(this.tags['username'].value);this.save();this.refresh(0);}},refresh:function(nc){if(this.profile["username"]!=""){if(!this.isLoading){this.isLoading=true;this.setTitle(loc.text("msg_loading"));this.tags['error'].innerHTML='';this.hide('login');if(trim(this.tags['password'].value)!=""){request.send({act:"login",cache:nc,username:this.profile.username,password:this.tags['password'].value},this);this.setValue('password',"");}else{request.send({act:"login",nc:nc,username:this.profile.username},this);}}}else{this.show('login');}},setPeriod:function(){this.profile.period=this.getValue('period');main.stopTimer(this.id);main.processTimer(this.id,this.profile.period*1000,true);this.save();},timerHandler:function(){if(!this.isInReader){this.refresh(0);}},activateBox:function(){var txt=this.mid.getElement('textarea[id=share_txt]');if(txt.value==this.deftxt)txt.value='';this.txtfocus=true;},sendComment:function(){var txt=this.mid.getElement('textarea[id=share_txt]');var div=this.mid.getElement('div[id=share_div]');if(txt!=''){var btn=this.mid.getElement('input[id=share_btn]')
request.send({act:"comment",nc:0,username:this.profile.username,comment:txt.value},this);txt.value=this.deftxt;this.txtfocus=false;}},dispatchMsg:function(msg){var pendings,b='',h=h2='',self=this;this.isLoading=false;this.setTitle(this.profile.title);if(msg.act=='comment'){if(msg.status=='ok'){this.refresh(1);}}
else if(msg.act=='login'){if(msg.status=='ok'){this.mid.getElement('div[id=cont]').removeEvents('click');if(this.profile.stream==1){b+="<div style='margin-bottom:5px;'>"+" <div style='border:1px solid #ccc'>"+"  <textarea style='border:none;padding:2px;width:95%;font-family:Tahoma,Verdana;height:44px;font-size:11px' id='share_txt'>"+this.deftxt+"</textarea>"+" </div>"+" <div style='text-align:right'><input id='share_btn' class='share' type='button' style='border:1px solid #0C2253;padding:3px;background-color:#5B74A8;color:white;font-size:11px;margin-top:3px' value='Megosztom'></div>"+"</div>";}
this.setTitle(this.profile.title+" - "+msg.name);if(msg.pendings){pendings=(msg.pendings?toValue(msg.pendings):null);h2='<div class="box_head"><div class="box_head_inner"><div class="box_logo"><h4>'+loc.text("iwiw_marked")+'</h4></div></div><div class="box_content"><a href="http://www.iwiw.hu/pages/user/userdata.jsp?userID='+pendings.userID+'" id="marked_image_link" target="_blank"><img id="marked_image" src="'+pendings.imageurl+'" class="image_border" alt=""></a><div class="box_float_left"><a id="marked_name_link" href="http://iwiw.hu/pages/user/userdata.jsp?userID='+pendings.userID+'" target="_blank">'+pendings.name+'</a> '+loc.text("iwiw_marked")+'</div><div class="clearboth"/></div>';}
h+="<div><ul id='head_misc'>"+msg.box+"</ul></div>"+b+"<div>";if(this.profile.stream==1){h+="<div class='box_head'><div class='box_head_inner'><h4>"+loc.text('iwiw_stream')+"</h4></div></div><ul class='shortmessage'>"+msg.activities+"</div><br>";}
h+="<div class='box_head'><div class='box_head_inner'><h4>"+loc.text('iwiw_birthdays')+"</h4></div></div><div class='box_content'>"+msg.birth+"</div><div>"+h2+"</div>";this.mid.getElement('div[id=cont]').innerHTML=h;this.mid.getElement('textarea[id=share_txt]').addEvent('click',function(e){self.activateBox();});this.mid.getElement('input[id=share_btn]').addEvent('click',function(e){self.sendComment();});this.mid.getElement('div[id=cont]').addEvent('click',function(e){var txt=self.mid.getElement('textarea[id=share_txt]');if(txt.value==''&&self.txtfocus==false){txt.value=self.deftxt;}
self.txtfocus=false;});}else{this.tags['error'].innerHTML=loc.text('iwiw_login_error');this.tags['login'].style.display='block';}}},settingsAll:function(){this.settingsSetTitle();this.saveProfile();}});