
var Indamail=new Class({Extends:Widget,initialize:function(){this.isLoading=false;this.cfg={hasSettingsBtn:true,title:"Indamail",module:"Indamail"}
this.data={};this.tags={};this.content=['<div id="error" style="margin:5px auto;color:red;text-align:center"></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("mail_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("mail_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('mail_login'),'">',' </div>',' <div style="text-align:center">',loc.text('indamail_note'),'</div>','</div>','<div id="cont" style="display:block" class="iwiw"><ul id="list" class="ul"></ul></div>'].join('');this.defaultProfile["count"]=10;this.defaultProfile["title"]=this.cfg.title;this.defaultProfile["username"]="";this.defaultProfile["bgcolor"]="orig";this.loginError=false;this.encPass='';},onBuildInterface:function(){var t=this,h='';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("mail_count")+"</span>"+"  <select name='count' class='settings_control'>"+"   <option value='3'"+(this.profile.count=='3'?' selected':'')+">3</option>"+"   <option value='5'"+(this.profile.count=='5'?' selected':'')+">5</option>"+"   <option value='8'"+(this.profile.count=='8'?' selected':'')+">8</option>"+"   <option value='10'"+(this.profile.count=='10'?' selected':'')+">10</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['count']=t.mid.getElement('select[name=count]');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['count'].addEvent('change',function(){t.profile.count=t.getValue('count');t.save();t.refresh();});t.tags['title'].addEvent('keydown',function(e){if(e.key=='enter')
t.settingsSetTitle();});t.tags['btn'].addEvent('click',function(){if(trim(t.tags['password'].value)!=""){t.encPass=encode_base64(t.tags['password'].value);t.isSettingsReduced=true;t.hideSettings();}
else{t.tags['error'].innerHTML=loc.text('mail_error_login');t.show('login');}});t.tags['password'].addEvent('keydown',function(e){if(e.key=='enter'){t.encPass=encode_base64(t.tags['password'].value);t.isSettingsReduced=true;t.hideSettings();}});t.setTitle(t.profile.title);t.setValue('username',t.profile.username);if(t.tags["username"].value!=""){t.showElId('login','none');}
t.colorsAction();t.setBgColor(t.profile.bgcolor,1);},onOpen:function(){if(trim(this.profile.title)==""){this.profile.title=loc.text("indamail_title");}
this.refresh();},onClose:function(){},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();}},refresh:function(){if(!ident.isPublic()||(ident.isPublic()&&ident.isPublicLogged())){if(this.profile["username"]!=""){if(!this.isLoading){this.isLoading=true;this.setTitle(loc.text("msg_loading"));this.tags['error'].style.display='none';this.tags['error'].innerHTML='';this.hide('login');if(trim(this.tags['password'].value)!=""){request.send({act:"list",username:this.profile.username,password:this.encPass,host:this.cfg.module},this,'POST');this.setValue('password','');}else{request.send({act:"list",username:this.profile.username,host:this.cfg.module},this);}}}else{this.show('login');}}else{this.tags['error'].style.display='block';this.setTitle(this.profile.title);this.tags['error'].innerHTML=loc.text("board_nopublic");}},showMail:function(id,i){board.items['mail_pop'].getElement('img[id=ico]').src='widgets/indamail/ico.gif';board.items['mail_pop'].getElement('span.box-title').innerHTML='Indamail';var frm=$('frame_mail'),h;h='<div style="padding-bottom:10px;border-bottom:1px solid #cccccc">'+' <div style="padding:3px;"><div style="float:left;width:50px"><b>'+loc.text("mail_from")+'</b></div><span>'+this.data[i].from+'</span></div>'+' <div style="padding:3px;"><div style="float:left;width:50px"><b>'+loc.text("mail_subject")+'</b></div><span>'+this.data[i].subject+'</span></div>'+' <div style="padding:3px;"><div style="float:left;width:50px"><b>'+loc.text("mail_date")+'</b></div><span>'+this.data[i].date+'</span></div>';if(this.data[i].att){h+='<div style="padding:3px;"><div style="float:left;margin-right:5px"><b>'+loc.text("mail_att")+'</b></div>';for(var j=0;j<this.data[i].att.length;j++){h+='<div style="float:left;margin-right:5px;"><img src="pix/icon_'+this.data[i].att[j].ext+'.gif" style="float:left;margin-right:2px;"><a target="_blank" href="router.php?act=attach&module='+this.cfg.module+'&username='+this.profile.username+'&uid='+id+'&host='+this.cfg.module+'&aid='+this.data[i].att[j].aid+'&ext='+this.data[i].att[j].ext+'&fname='+this.data[i].att[j].name+'" style="float:left;">'+this.data[i].att[j].name+'</a></div>';}
h+='<br clear="all"></div>';}
h+='</div>';$('mail_header').innerHTML=h;url="router.php?act=mail&module="+this.cfg.module+"&username="+this.profile.username+"&uid="+id+"&host="+this.cfg.module;frm.src=url;board.showPopup('mail');},dispatchSearch:function(response){$('popup_mail').getElement('div.box-content').innerHTML=response.responseText;},dispatchMsg:function(msg){var h='',self=this,c=0,ul;var cont=this.mid.getElement('div[id=cont]');cont.innerHTML="";this.isLoading=false;this.setTitle(this.profile.title);if(msg.error){this.tags['error'].innerHTML=loc.text(msg.error);this.tags['error'].style.display='block';if(msg.error='mail_error_login')this.showElId('login','block');}
if(msg.status=='list'){this.setTitle(this.profile.title+" - "+this.profile.username+" - "+msg.total);this.mid.getElement('div[id=cont]').innerHTML='';this.data=msg.mails;if(this.data.length<this.profile.count)
c=this.data.length;else
c=this.profile.count;ul=new Element('ul',{});for(var i=0;i<c;i++){var m=msg.mails[i],x=i;var from=m.from.replace(/&lt;(.*?)&gt;/i,"");m.id=i;row=new Element('li',{'html':'<div style="float:right;position:relative">'+m.date+'</div><div style="float:left;width:16px">'+(m.att?'<img src="pix/mail_attach.gif">':'&nbsp;')+'</div><div style="float:left">'+from+'<p><b>'+m.subject.wordWrap(30)+'</b></p></div>','class':(i!=c-1?'mail-row':'mail-row-last')});row.addEvent('click',function(e,m){self.showMail(m.uid,m.id);}.bindWithEvent(this,m));row.inject(ul);}
ul.inject(this.mid.getElement('div[id=cont]'))}},settingsAll:function(){this.settingsSetTitle();this.saveProfile();}});