/*
 * Project: Login
 * Author: Pierpaolo Rebecchi - 3BI Consulting. SA
 * Version: 1.0
 * 
 * Copyright © 2007-2008 3BI Consulting. SA. All rights reserved.
 * 
 * Contact: info@3-bi.ch http:\\www.3-bi.ch
 * 
 * 
 */


ThreeBI.Login.Comm=function(){};(function(){ThreeBI.Login.Comm.ErrorReport=function(error){var winError;if(error=='EXPIRED'){var yesButton=new Ext.Button({text:'Yes',minWidth:80});winError=new Ext.Window({title:'Session expired',autoCreate:true,resizable:false,layout:'fit',width:255,height:140,closable:false,draggable:false,plain:false,modal:true,iconCls:'refreshNAV'});var href=window.document.location.href.toString();href=href.substring(0,href.lastIndexOf('/'))+'/../Default.aspx';winError.add(new Ext.Panel({frame:false,border:false,autoScroll:false,html:'<span style="padding-left:1px;color:red"><b>You\'ve been away too long, your session has expired.<br/>Please login again '+'<a href="'+href+'" target="_top">here</a></b></span>',bodyStyle:'padding:5px;'}));yesButton.on("click",function(){alert('not implemented');});winError.show(this.id);}else if(error=='INMAINTENANCE'){winError=new Ext.Window({title:'System in maintenance',autoCreate:true,resizable:false,layout:'fit',width:255,height:110,closable:false,plain:false,modal:true,draggable:false});var msg=ThreeBI.Login.Comm.getMaintenanceMsg();winError.add(new Ext.Panel({frame:false,border:false,autoScroll:false,html:'<span style="padding-left:1px;color:red"><b>'+msg+'</b></span>',bodyStyle:'padding:5px;'}));winError.show(this.id);}
else{winError=new Ext.Window({title:'Error caught',autoCreate:true,resizable:true,layout:'fit',width:255,height:110,closable:false,plain:false,modal:true,draggable:true,maximizable:true});winError.add(new Ext.Panel({frame:false,border:false,autoScroll:false,layout:'fit',html:'<span style="padding-left:1px;color:red"><b>The following error has been caught:<br/></b></span><pre>'+error+'</pre>',bodyStyle:'padding:5px;'}))
winError.show(this.id);}}
var loginHandler=new LoginHandler();ThreeBI.Login.Comm.checkLogin=function(par1,par2){var x=ThreeBI.Login.Utils.Crypt(par1);var y=ThreeBI.Login.Utils.Crypt(par2);var data=loginHandler.checkLogin(x,y);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};ThreeBI.Login.Comm.changePWD=function(par1,par2,par3){var x=ThreeBI.Login.Utils.Crypt(par1);var y=ThreeBI.Login.Utils.Crypt(par2);var z=ThreeBI.Login.Utils.Crypt(par3);var data=loginHandler.changePWD(x,y,z);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};ThreeBI.Login.Comm.asknewPWD=function(par1){var x=ThreeBI.Login.Utils.Crypt(par1);var data=loginHandler.asknewPWD(x);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};ThreeBI.Login.Comm.register=function(par1,par2,par3,par4,par5,par6,par7,par8,par9,par10,par11){var data=loginHandler.register(par1,par2,par3,par4,par5,par6,par7,par8,par9,par10,par11);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};ThreeBI.Login.Comm.getConnection=function(par1,par2){var x=ThreeBI.Login.Utils.Crypt(par1);var y=ThreeBI.Login.Utils.Crypt(par2);var data=loginHandler.getConnection(x,y);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};ThreeBI.Login.Comm.closeConnection=function(){var data=loginHandler.closeConnection();};ThreeBI.Login.Comm.sendMailBeforeLogin=function(pid,name,subject,msg){var data=loginHandler.sendMailBeforeLogin(pid,name,subject,msg);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else return data};ThreeBI.Login.Comm.checkStatus=function(){var status=loginHandler.getStatus();if(status!='OK')ThreeBI.Login.Comm.ErrorReport(status);};ThreeBI.Login.Comm.getMaintenanceMsg=function(){return loginHandler.getMaintenanceMsg();};ThreeBI.Login.Comm.getUserLevel=function(){var data=loginHandler.getUserLevel();if(data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{return parseInt(data);}};ThreeBI.Login.Comm.getUserPID=function(){var data=loginHandler.getUserPID();if(data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{return data;}};ThreeBI.Login.Comm.getUserID=function(){var data=loginHandler.getUserID();if(data=='EXPIRED'||data=='INMAINTENANCE'||data.indexOf("ERROR")>=0){ThreeBI.Login.Comm.ErrorReport(data);}
else{return data;}};ThreeBI.Login.Comm.getListCombo=function(par1){var data=loginHandler.getListCombo(par1);if(data.indexOf('ERROR')>=0||data=='EXPIRED'||data=='INMAINTENANCE'){ThreeBI.Login.Comm.ErrorReport(data);return new String('ERROR');}
else{var xmldoc;if(window.ActiveXObject){xmldoc=new ActiveXObject("Microsoft.XMLDOM");xmldoc.async="false";xmldoc.loadXML(data);}else{xmldoc=new DOMParser().parseFromString(data,"text/xml");}
return xmldoc;}};})();

ThreeBI.Login.SendMailBeforeLogin=function(){};(function(){ThreeBI.Login.SendMailBeforeLogin.show=function(button){var winSendMail;if(!winSendMail){var sendButton=new Ext.Button({text:'Send',minWidth:80});var cancelButton=new Ext.Button({text:'Cancel',minWidth:80});winSendMail=new Ext.Window({title:'Send an email to the Administrator',autoCreate:true,resizable:true,maximizable:true,layout:'anchor',width:475,height:240,closeAction:'close',plain:true,modal:true,iconCls:'x-Login-contactButton',buttons:[cancelButton,sendButton]});this.pidField=new Ext.form.TextField({fieldLabel:'Your Login Name',name:'Your PID',width:200,msgTarget:'side',allowBlank:false});this.nameField=new Ext.form.TextField({fieldLabel:'Your Name',name:'Your Name',width:200,msgTarget:'side',allowBlank:false});this.subjectField=new Ext.form.TextField({fieldLabel:'Subject',name:'Subject',width:200,msgTarget:'side',allowBlank:false});this.textArea=new Ext.form.TextArea({fieldLabel:'text',name:'text',width:320,msgTarget:'side',allowBlank:false});this.formPanel=new Ext.FormPanel({labelAlign:'left',monitorValid:false,frame:false,border:true,bodyStyle:'padding-left:5px;padding-top:20px;position:relative',items:[this.pidField,this.nameField,this.subjectField,this.textArea]});winSendMail.add(this.formPanel);cancelButton.on("click",function(){winSendMail.close();});sendButton.on("click",function(){if(this.pidField.getValue().toString()==''||this.nameField.getValue().toString()==''||this.subjectField.getValue().toString()==''||this.textArea.getValue().toString()==''){Ext.MessageBox.alert('ERROR !','All fields are mandatory');}else{var result=ThreeBI.Login.Comm.sendMailBeforeLogin(this.pidField.getValue().toString(),this.nameField.getValue().toString(),this.subjectField.getValue().toString(),this.textArea.getRawValue());winSendMail.close();if(result=='OK'){Ext.MessageBox.alert('Success','Mail has been sent successfully.');}else{Ext.MessageBox.alert('ERROR !','An error occured.<p>The mail has not been sent.</p>');}}},this);}
winSendMail.show(button.id);return true;};})();

ThreeBI.Login.Utils=function(){};(function(){ThreeBI.Login.Utils.objectDump=function(obj){var output='';for(var el in obj){if(typeof obj[el]!='function')
output+=el+'='+obj[el]+'\n';}
alert(output);};ThreeBI.Login.Utils.Crypt=function(obj){var key='1234567890qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM';if(obj==null)return null;var keyLenght=key.length;var sout='';if(obj=='')return sout;for(var ic=0;ic<obj.length;ic++)
{var c=obj.charAt(ic);var idx=key.indexOf(c);var chout='';if(idx>=0)chout=key.substring(keyLenght-idx-1,keyLenght-idx);else chout=c;sout=sout+chout;}
return sout;};})();

ThreeBI.Login.LoginPanel=function(config){config.border=false;config.width=400;config.height=375+50;config.frame=false;config.layout='anchor';config.bodyStyle='background:'+config.backgroundColor+';';config.deferredRender=false;ThreeBI.Login.LoginPanel.superclass.constructor.call(this,config);this.buildPanel();this.mainPanel();if(config.renderTo){this.doLayout();this.initHandlers();this.initStatus();}}
Ext.extend(ThreeBI.Login.LoginPanel,Ext.Panel,{loginType:'mainlogin',backgroundColor:'white',externalLoginHandler:null,onMouseOverButton:function(e){this.addClass("x-Login-btn-over");},onMouseOutButton:function(e){this.removeClass("x-Login-btn-over");},onMouseDownButton:function(e){this.addClass("x-Login-btn-clicked");},onMouseUpButton:function(e){this.removeClass("x-Login-btn-clicked");},onMouseOverLink:function(e){this.addClass("x-Login-link-over");},onMouseOutLink:function(e){this.removeClass("x-Login-link-over");},onMouseDownLink:function(e){this.addClass("x-Login-link-clicked");},onMouseUpLink:function(e){this.removeClass("x-Login-link-clicked");},initHandlers:function(){var AskPWD=Ext.get('AskPWDID');AskPWD.on('click',this.asknewpasswordStatus,this);AskPWD.on({'mouseover':this.onMouseOverLink,'mouseout':this.onMouseOutLink,'mousedown':this.onMouseDownLink,'mouseup':this.onMouseUpLink,scope:AskPWD});var registerLink=Ext.get('registerLinkID');registerLink.on('click',this.registerStatus,this);registerLink.on({'mouseover':this.onMouseOverLink,'mouseout':this.onMouseOutLink,'mousedown':this.onMouseDownLink,'mouseup':this.onMouseUpLink,scope:registerLink});var ChangepasswordLink=Ext.get('ChangepasswordID');ChangepasswordLink.on('click',this.changepasswordStatus,this);ChangepasswordLink.on({'mouseover':this.onMouseOverLink,'mouseout':this.onMouseOutLink,'mousedown':this.onMouseDownLink,'mouseup':this.onMouseUpLink,scope:ChangepasswordLink});var Button=Ext.get('loginButtonID');Button.on('click',this.loginHandler,this);Button.on({'mouseover':this.onMouseOverButton,'mouseout':this.onMouseOutButton,'mousedown':this.onMouseDownButton,'mouseup':this.onMouseUpButton,scope:Button});var Button1=Ext.get('loginButtonID1');Button1.on('click',this.loginHandler,this);Button1.on({'mouseover':this.onMouseOverLink,'mouseout':this.onMouseOutLink,'mousedown':this.onMouseDownLink,'mouseup':this.onMouseUpLink,scope:Button1});var AdministratorLink3=Ext.get('AdministratorLinkID3');AdministratorLink3.on('click',function(){ThreeBI.Login.SendMailBeforeLogin.show('AdministratorLinkID3');});AdministratorLink3.on({'mouseover':this.onMouseOverButton,'mouseout':this.onMouseOutButton,'mousedown':this.onMouseDownButton,'mouseup':this.onMouseUpButton,scope:AdministratorLink3});var backButtonID=Ext.get('backButtonID');backButtonID.on('click',this.backButtonHandler,this);backButtonID.on({'mouseover':this.onMouseOverButton,'mouseout':this.onMouseOutButton,'mousedown':this.onMouseDownButton,'mouseup':this.onMouseUpButton,scope:backButtonID});},initStatus:function(){Ext.get('headerPanelID').update('Please enter your:');Ext.get('loginButtonID1').update('Login');Ext.get('loginButtonID').removeClass('x-Login-sendButton');Ext.get('loginButtonID').addClass('x-Login-loginButton');Ext.get('loginButtonID1').removeClass('x-Login-loginLinkChange');Ext.get('loginButtonID1').addClass('x-Login-loginLink');Ext.get('loginButtonID1').removeClass('x-Login-link-clicked');Ext.get('loginButtonFillerID').setHeight(0);Ext.get('loginButtonID').setHeight(45);Ext.get('backButtonID').dom.style.display="none";this.formPanel_1.getEl().dom.style.paddingTop='12px';this.pidField.getEl().parent().parent().dom.style.display="block";this.pwdField.getEl().parent().parent().dom.style.display="block";this.oldpwdField.getEl().parent().parent().dom.style.display="none";this.newpwdField.getEl().parent().parent().dom.style.display="none";this.confField.getEl().parent().parent().dom.style.display="none";this.newconfField.getEl().parent().parent().dom.style.display="none";this.firstnameField.getEl().parent().parent().dom.style.display="none";this.familynameField.getEl().parent().parent().dom.style.display="none";this.mailField.getEl().parent().parent().dom.style.display="none";this.pwdField.reset();this.oldpwdField.reset();this.newpwdField.reset();this.confField.reset();this.newconfField.reset();this.firstnameField.reset();this.familynameField.reset();this.mailField.reset();if(this.loginMode=='usrreg')this.registerStatus();if(this.loginMode=='smllgn'){Ext.get('backButtonID').dom.style.display="none";Ext.get('AdministratorLinkID3').dom.style.display="none";this.changepasswordButtonPanel.setVisible(false);this.zonePanelRegister.setVisible(false);}},registerStatus:function(){Ext.get('loginButtonID').setHeight(50);Ext.get('backButtonID').dom.style.display="block";this.oldpwdField.getEl().parent().parent().dom.style.display="none";this.newpwdField.getEl().parent().parent().dom.style.display="none";this.confField.getEl().parent().parent().dom.style.display="block";this.newconfField.getEl().parent().parent().dom.style.display="none";this.firstnameField.getEl().parent().parent().dom.style.display="block";this.familynameField.getEl().parent().parent().dom.style.display="block";this.mailField.getEl().parent().parent().dom.style.display="block";this.loginType='register';if(this.loginMode=='usrreg'){Ext.get('backButtonID').dom.style.display="none";Ext.get('AdministratorLinkID3').dom.style.display="none";}
this.mainPanel();this.pwdField.reset();},changepasswordStatus:function(){Ext.get('backButtonID').dom.style.display="block";this.pwdField.getEl().parent().parent().dom.style.display="none";this.oldpwdField.getEl().parent().parent().dom.style.display="block";this.newpwdField.getEl().parent().parent().dom.style.display="block";this.confField.getEl().parent().parent().dom.style.display="none";this.newconfField.getEl().parent().parent().dom.style.display="block";this.firstnameField.getEl().parent().parent().dom.style.display="none";this.familynameField.getEl().parent().parent().dom.style.display="none";this.mailField.getEl().parent().parent().dom.style.display="none";this.loginType='changePassword';this.mainPanel();this.pwdField.reset();},asknewpasswordStatus:function(){Ext.get('loginButtonID').setHeight(50);Ext.get('backButtonID').dom.style.display="block";this.pwdField.getEl().parent().parent().dom.style.display="none";this.oldpwdField.getEl().parent().parent().dom.style.display="none";this.newpwdField.getEl().parent().parent().dom.style.display="none";this.confField.getEl().parent().parent().dom.style.display="none";this.newconfField.getEl().parent().parent().dom.style.display="none";this.firstnameField.getEl().parent().parent().dom.style.display="none";this.familynameField.getEl().parent().parent().dom.style.display="none";this.mailField.getEl().parent().parent().dom.style.display="none";this.loginType='asknewpassword';this.mainPanel();},mainPanel:function(){if(this.loginType=='mainlogin'){this.loginButtonPanel.setVisible(true);this.changepasswordButtonPanel.setVisible(true);this.changePWDRegisterPanel.setVisible(false);this.zonePanelRegister.setVisible(true);this.zonePanelMessage.setVisible(false);this.loginButtonPanel.setHeight(80);}
if(this.loginType=='register'){this.formPanel_1.getEl().dom.style.paddingTop='0px';Ext.get('loginButtonFillerID').setHeight((this.formPanel_1.getInnerHeight())/3.0);Ext.get('headerPanelID').update('Register:');Ext.get('loginButtonID1').update('Send');Ext.get('loginButtonID').removeClass('x-Login-loginButton');Ext.get('loginButtonID').addClass('x-Login-sendButton');this.loginButtonPanel.setVisible(true);this.changepasswordButtonPanel.setVisible(false);this.changePWDRegisterPanel.setVisible(true);this.zonePanelRegister.setVisible(false);this.zonePanelMessage.setVisible(false);this.loginButtonPanel.setHeight(this.formPanel_1.getInnerHeight());}
if(this.loginType=='changePassword'){this.formPanel_1.getEl().dom.style.paddingTop='0px';Ext.get('loginButtonID').setHeight((this.formPanel_1.getInnerHeight())/1.8);Ext.get('headerPanelID').update('Change password:');Ext.get('loginButtonID1').update('Change');Ext.get('loginButtonID').removeClass('x-Login-loginButton');Ext.get('loginButtonID').addClass('x-Login-sendButton');Ext.get('loginButtonID1').removeClass('x-Login-loginLink');Ext.get('loginButtonID1').addClass('x-Login-loginLinkChange');this.loginButtonPanel.setVisible(true);this.changepasswordButtonPanel.setVisible(false);this.changePWDRegisterPanel.setVisible(true);this.zonePanelRegister.setVisible(false);this.zonePanelMessage.setVisible(false);this.loginButtonPanel.setHeight(this.formPanel_1.getInnerHeight());Ext.get('loginButtonID').adjustHeight(this.formPanel_1.getInnerHeight()/2)}
if(this.loginType=='asknewpassword'){this.formPanel_1.getEl().dom.style.paddingTop='20px';Ext.get('headerPanelID').update('Ask new password:');Ext.get('loginButtonID1').update('Send');Ext.get('loginButtonID').removeClass('x-Login-loginButton');Ext.get('loginButtonID').addClass('x-Login-sendButton');this.loginButtonPanel.setVisible(true);this.changepasswordButtonPanel.setVisible(false);this.changePWDRegisterPanel.setVisible(true);this.zonePanelRegister.setVisible(false);this.zonePanelMessage.setVisible(false);this.loginButtonPanel.setHeight(80);}},backButtonHandler:function(){this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;},loginHandler:function(){if(this.loginType=='mainlogin'){if(this.pidField.getValue().toString()==''||this.pwdField.getValue().toString()==''){var mess1='All fields are mandatory';this.updateMessage(mess1);}
else{var xmlData=ThreeBI.Login.Comm.checkLogin(this.pidField.getValue().toString(),this.pwdField.getValue().toString());if(!(xmlData instanceof String&&xmlData=='ERROR')){var data=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});data.loadData(xmlData);var messageText=data.getAt(0).get('MessageText');var error_Code=data.getAt(0).get('Error_Code');var severityLevel=data.getAt(0).get('SeverityLevel');if(severityLevel==0){if(error_Code=='CHPWD'){this.changepasswordStatus();this.updateMessage(messageText);}
else if(error_Code=='VALID'){this.openWindow();}
function showResult(btn){if(btn=='yes')
this.changepasswordStatus();else if(btn=='no'){this.openWindow();}};if(error_Code=='DATE'){Ext.MessageBox.confirm('Confirm',messageText,showResult,this);}}else{if(error_Code=='EXPIRED'){var xmlDataCHP=ThreeBI.Login.Comm.asknewPWD(this.pidField.getValue().toString());if(!(xmlDataCHP instanceof String&&xmlDataCHP=='ERROR')){var dataCHP=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});dataCHP.loadData(xmlDataCHP);var messageTextCHP=dataCHP.getAt(0).get('MessageText');var error_CodeCHP=dataCHP.getAt(0).get('Error_Code');if(error_CodeCHP!='VALID'){this.updateMessage(messageTextCHP);}
else{Ext.MessageBox.alert('Information',messageText);this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;}}}else{this.updateMessage(messageText);}}}}}
else
if(this.loginType=='register'){this.verificationRegister();}
else if(this.loginType=='changePassword'){this.verificationchangePWD();}
else if(this.loginType=='asknewpassword'){this.verificationasknewPWD();}},verificationchangePWD:function(){if(this.pidField.getValue().toString()!=''&&this.oldpwdField.getValue().toString()!=''&&this.newpwdField.getValue().toString()!=''&&this.newconfField.getValue().toString()==''){var x=false;var y=this.newconfField.getValue().toString()==this.newpwdField.getValue().toString();}
else{var x=true;var y=this.newconfField.getValue().toString()==this.newpwdField.getValue().toString();}
if(this.pidField.getValue().toString()==''||this.oldpwdField.getValue().toString()==''||this.newpwdField.getValue().toString()==''||this.newconfField.getValue().toString()==''){this.updateMessage('All fields are mandatory');}
if(this.oldpwdField.getValue().toString()==this.newpwdField.getValue().toString()){this.updateMessage('The new password must be different than the old password');}
else{if(x&&y){var xmlData=ThreeBI.Login.Comm.changePWD(this.pidField.getValue().toString(),this.oldpwdField.getValue().toString(),this.newpwdField.getValue().toString());if(!(xmlData instanceof String&&xmlData=='ERROR')){var data=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});data.loadData(xmlData);var messageText=data.getAt(0).get('MessageText');var error_Code=data.getAt(0).get('Error_Code');if(error_Code=='EXPIRED'){var xmlDataCHP=ThreeBI.Login.Comm.asknewPWD(this.pidField.getValue().toString());if(!(xmlDataCHP instanceof String&&xmlDataCHP=='ERROR')){var dataCHP=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});dataCHP.loadData(xmlDataCHP);var messageTextCHP=dataCHP.getAt(0).get('MessageText');var error_CodeCHP=dataCHP.getAt(0).get('Error_Code');if(error_CodeCHP!='VALID'){this.updateMessage(messageTextCHP);}
else{Ext.MessageBox.alert('Information',messageText);this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;}}}else if(error_Code!='OK'){this.updateMessage(messageText);}
else{Ext.MessageBox.alert('Information','Your password has been successfully changed');this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;}}}
else{if(!x){var messageText='Please enter confirmation password';}
else{var messageText='The passwords do not match';}
this.updateMessage(messageText);}}},verificationasknewPWD:function(){if(this.pidField.getValue().toString()==''){var mess1='This field is mandatory';this.updateMessage(mess1);}else{var xmlData=ThreeBI.Login.Comm.asknewPWD(this.pidField.getValue().toString());if(!(xmlData instanceof String&&xmlData=='ERROR')){var data=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});data.loadData(xmlData);var messageText=data.getAt(0).get('MessageText');var error_Code=data.getAt(0).get('Error_Code');if(error_Code!='VALID'){this.updateMessage(messageText);}
else{Ext.MessageBox.alert('Information','Your new password has been sent to you by email');this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;}}}},verificationRegister:function(){if(this.pidField.getValue().toString()==''||this.pwdField.getValue().toString()==''||this.confField.getValue().toString()==''||this.firstnameField.getValue().toString()==''||this.familynameField.getValue().toString()==''||this.mailField.getValue().toString()==''){this.updateMessage('All fields are mandatory');}else if(this.pwdField.getValue().toString()!=this.confField.getValue().toString()){this.updateMessage('The passwords do not match');}else if(!this.mailField.isValid()){this.updateMessage('Your email must be a valid email');}else if(!this.pidField.isValid()){this.updateMessage('Your Login Name must be valid');}else{var xmlData=ThreeBI.Login.Comm.register(this.pidField.getValue().toString(),this.pwdField.getValue().toString(),this.confField.getValue().toString(),this.firstnameField.getValue().toString(),this.familynameField.getValue().toString(),1,'',1,this.mailField.getValue().toString(),0,'0');if(!(xmlData instanceof String&&xmlData=='ERROR')){var data=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'Error_Code',mapping:'Error_Code'},{name:'ID_Login_Messages',mapping:'ID_Login_Messages'},{name:'MessageText',mapping:'MessageText'},{name:'SeverityLevel',mapping:'SeverityLevel'}])});data.loadData(xmlData);var messageText=data.getAt(0).get('MessageText');var error_Code=data.getAt(0).get('Error_Code');if(error_Code!='OK'){this.updateMessage(messageText);}
else{Ext.MessageBox.alert('Information','Dear user,<br>we have received your access request to '+this.portalName+'<br>and will get back to you very briefly.<br>');this.loginType='mainlogin';this.initStatus();this.mainPanel();return true;}}}},buildPanel:function(){this.zonePanelMessage=new Ext.Panel({deferredRender:false,header:false,border:false,frame:false,html:'<div id=messageContent class="x-Login-messageCLS" style="display:block;"></div>',visible:true});this.pidField=new Ext.form.TextField({fieldLabel:'Login Name',name:'PID',width:150,msgTarget:'side',allowBlank:false,maxLength:10,maxLengthText:'Login Name must be less than 11 characters'});this.pidField.on('specialkey',this.keyPressed,this)
this.pwdField=new Ext.form.TextField({fieldLabel:'Password',name:'pwd',inputType:'password',id:'pwd',width:150,msgTarget:'side',allowBlank:false});this.pwdField.on('specialkey',this.keyPressed,this)
this.oldpwdField=new Ext.form.TextField({fieldLabel:'Old password',name:'old pass',inputType:'password',width:150,msgTarget:'side',allowBlank:false});this.oldpwdField.on('specialkey',this.keyPressed,this)
this.newpwdField=new Ext.form.TextField({fieldLabel:'New password',name:'newpwd',inputType:'password',id:'newpwd',width:150,msgTarget:'side',allowBlank:false});this.newpwdField.on('specialkey',this.keyPressed,this)
this.confField=new Ext.form.TextField({fieldLabel:'Confirmation',name:'Confirmation',inputType:'password',vtype:'pwd',initialPassField:'pwd',width:150,msgTarget:'side',allowBlank:false,pwdField:this.pwdField});this.confField.on('specialkey',this.keyPressed,this)
this.newconfField=new Ext.form.TextField({fieldLabel:'Confirmation',name:'Confirmation1',inputType:'password',vtype:'newpwd',initialPassField:'newpwd',width:150,msgTarget:'side',allowBlank:false,newpwdField:this.newpwdField});this.newconfField.on('specialkey',this.keyPressed,this)
this.firstnameField=new Ext.form.TextField({fieldLabel:'First Name',name:'First Name',width:150,msgTarget:'side',allowBlank:false});this.firstnameField.on('specialkey',this.keyPressed,this)
this.familynameField=new Ext.form.TextField({fieldLabel:'Family Name',name:'Family Name',width:150,msgTarget:'side',allowBlank:false});this.familynameField.on('specialkey',this.keyPressed,this)
var storeZone=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'ID',mapping:'ID'},{name:'Text',mapping:'Text'}])});storeZone.loadData(ThreeBI.Login.Comm.getListCombo('Zone'));this.zoneField=new Ext.form.ComboBox({fieldLabel:'Zone where you are based',width:150,maxHeight:100,store:storeZone,editable:false,valueField:'ID',displayField:'Text',mode:'local',typeAhead:true,triggerAction:'all',allowBlank:false});this.mailField=new Ext.form.TextField({fieldLabel:'Your e-mail',name:'Your professional e-mail',width:150,msgTarget:'side',vtype:'email',allowBlank:false});this.mailField.on('specialkey',this.keyPressed,this)
this.telephone=new Ext.form.TextField({fieldLabel:'Telephone',name:'Telephone',width:150,msgTarget:'side',allowBlank:false});this.telephone.on('specialkey',this.keyPressed,this)
var storeLocation=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'ID',mapping:'ID'},{name:'Text',mapping:'Text'}])});storeLocation.loadData(ThreeBI.Login.Comm.getListCombo('Location'));this.location=new Ext.form.ComboBox({fieldLabel:'Location',width:150,maxHeight:100,store:storeLocation,editable:false,valueField:'ID',displayField:'Text',mode:'local',typeAhead:true,triggerAction:'all',allowBlank:false});var storeDivision=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'ID',mapping:'ID'},{name:'Text',mapping:'Text'}])});storeDivision.loadData(ThreeBI.Login.Comm.getListCombo('Division'));this.divisionField=new Ext.form.ComboBox({fieldLabel:'Division',width:150,containerHeight:124,store:storeDivision,valueField:'ID',displayField:'Text',mode:'local',allowBlank:false,editable:false});var storeActivity=new Ext.data.Store({reader:new Ext.data.XmlReader({record:'row'},[{name:'ID',mapping:'ID'},{name:'Text',mapping:'Text'}])});storeActivity.loadData(ThreeBI.Login.Comm.getListCombo('Activity'));this.activityField=new Ext.ux.form.LovCombo({fieldLabel:'Activity',width:150,containerHeight:124,store:storeActivity,valueField:'ID',displayField:'Text',mode:'local',allowBlank:false,editable:false});this.pidField.on('focus',this.resetMessage,this);this.pwdField.on('focus',this.resetMessage,this);this.oldpwdField.on('focus',this.resetMessage,this);this.newpwdField.on('focus',this.resetMessage,this);this.confField.on('focus',this.resetMessage,this);this.newconfField.on('focus',this.resetMessage,this);this.firstnameField.on('focus',this.resetMessage,this);this.familynameField.on('focus',this.resetMessage,this);this.zoneField.on('focus',this.resetMessage,this);this.mailField.on('focus',this.resetMessage,this);this.telephone.on('focus',this.resetMessage,this);this.location.on('focus',this.resetMessage,this);this.headerPanel=new Ext.Panel({deferredRender:false,height:40,bodyStyle:'padding-top:2px;padding-left:5px;'+'background:'+this.backgroundColor+';',border:false,html:'<table width="100%">'+'<tr align="left">'+'<td  style="align:left;" class="x-Login-helpButton" id="AdministratorLinkID3"></td>'+'<td  style="align:left;" class="x-Login-backButton" id="backButtonID"></td>'+'<td id="headerPanelID" style="padding-left:10px;padding-bottom:15px;text-align:left;font-size:13pt;vertical-align: middle;">Please enter your:</td>'+'</tr>'+'</table>'});this.add(this.headerPanel);this.tab=new Ext.Panel({deferredRender:false,bodyStyle:'background:'+this.backgroundColor+';',border:false,layout:'column',layoutConfig:{columns:2}});this.formPanel_1=new Ext.FormPanel({border:false,align:'left',deferredRender:false,cellCls:'x-Login-formPanel',bodyStyle:'text-align:left;padding-top:2px;padding-left:12px;'+'background:'+this.backgroundColor+';',labelAlign:'left',monitorValid:false,frame:false,labelWidth:155,width:346,items:[this.pidField,this.pwdField,this.oldpwdField,this.newpwdField,this.confField,this.newconfField,this.firstnameField,this.familynameField,this.mailField]});this.loginButtonPanel=new Ext.Panel({border:false,deferredRender:false,cellCls:'x-Login-loginButtonPanel',bodyStyle:' text-align:center;'+'background:'+this.backgroundColor+';',width:55,html:'<table>'+'<tr>'+'<td id="loginButtonFillerID" '+'></td>'+'</tr>'+'<tr>'+'<td class="x-Login-loginButton" id="loginButtonID" '+'></td>'+'</tr>'+'<tr>'+'<td><a class="x-Login-loginLink" id="loginButtonID1"  >Login</a></td>'+'</tr>'+'</table>'})
this.tab.add(this.formPanel_1);this.tab.add(this.loginButtonPanel);this.add(this.tab);this.tab.doLayout();this.changepasswordButtonPanel=new Ext.Panel({deferredRender:false,bodyStyle:'background:'+this.backgroundColor+';',border:false,align:'left',html:'<table width="100%">'+'<tr align="left">'+'<td style="padding-left:10px;text-align:left;font-size:12px;">Click <div class="x-Login-changepassword" id="ChangepasswordID"> Change password </div>'+'to modify your password</td>'+'<tr align="left">'+'<tr >'+'<td style="padding-left:10px;text-align:left;font-size:12px;">Click <div class="x-Login-askPWDID" id="AskPWDID"> Ask new password </div>'+'to request a new password</td>'+'</tr>'+'</table>'})
this.add(this.changepasswordButtonPanel);this.changePWDRegisterPanel=new Ext.Panel({deferredRender:false,border:false,disabled:false,html:'<table width="100%">'+'<td align="center" style="font-weight: normal; background-color: White; color: White;font-size: 9px; padding: 0px 5px 0px 5px; height:35px;"></td>'+'</table>'});this.add(this.changePWDRegisterPanel);this.zonePanelRegister=new Ext.Panel({deferredRender:false,border:false,disabled:false,html:'<table width="100%">'+'<tr>'+'<td align="left" colspan="2" style="padding-left:10px;font-size:12px;">If you are a <span class="highlight">new user</span>, '+'please register <div class="x-Login-registerLink" id="registerLinkID">here<br></div>'+'</td>'+'</tr>'+'</table>'});this.add(this.zonePanelRegister);this.add(this.zonePanelMessage);},updateMessage:function(mess){var el=Ext.fly('messageContent');el.update(mess);if(mess=='')
this.zonePanelMessage.setVisible(false);else{this.zonePanelMessage.setVisible(true);}},resetMessage:function(){this.updateMessage('');},keyPressed:function(field,evenement){var touche=evenement.getKey();if(touche==13){var Button=Ext.get('loginButtonID');Button.addClass("x-Login-btn-clicked");Button.removeClass.defer(300,Button,["x-Login-btn-clicked"]);return this.loginHandler();}else{return true;}},openWindow:function(){var xmlData=ThreeBI.Login.Comm.getConnection(this.pidField.getValue().toString(),this.pwdField.getValue().toString());if(!(xmlData instanceof String&&xmlData=='ERROR')){if(this.externalLoginHandler){this.externalLoginHandler.call(this);}
else{this.updateMessage('');var mask=Ext.DomHelper.append(document.body,{tag:"div",cls:"x-dlg-mask"},true);mask.enableDisplayMode("block");mask.hide();Ext.getBody().addClass("x-body-masked");mask.setSize(Ext.lib.Dom.getViewWidth(true),Ext.lib.Dom.getViewHeight(true));mask.show();window.open("MainMenu.aspx","External");}}}});Ext.apply(Ext.form.VTypes,{pwd:function(val,field){if(field.pwdField){if(val==field.pwdField.getValue()){return true}else{field.invalidText='The passwords do not match';return false;}}
return true;},passwordText:'The passwords do not match',newpwd:function(val,field){if(field.newpwdField){if(val==field.newpwdField.getValue()){return true}else{field.invalidText='The passwords do not match';return false;}}
return true;},emailfir:function(val,field){return true}});

if('function'!==typeof RegExp.escape){RegExp.escape=function(s){if('string'!==typeof s){return s;}
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g,'\\$1');};}
Ext.ns('Ext.ux.form');Ext.ux.form.LovCombo=Ext.extend(Ext.form.ComboBox,{checkField:'checked',separator:' | ',valueSeparator:';',initComponent:function(){if(!this.tpl){this.tpl='<tpl for=".">'
+'<div class="x-combo-list-item">'
+'<table>'
+'<tr>'
+'<td>'
+'<img src="'+Ext.BLANK_IMAGE_URL+'" '
+'class="ux-lovcombo-icon ux-lovcombo-icon-'
+'{[values.'+this.checkField+'?"checked":"unchecked"'+']}">'
+'</td>'
+'<td>'
+'<span class="ux-lovcombo-item-text">{'+(this.displayField||'text')+'}</span>'
+'</td>'
+'</tr>'
+'</table>'
+'</div>'
+'</tpl>';}
Ext.ux.form.LovCombo.superclass.initComponent.apply(this,arguments);this.on({scope:this,beforequery:this.onBeforeQuery,blur:this.onRealBlur});this.onLoad=this.onLoad.createSequence(function(){if(this.el){var v=this.el.dom.value;this.el.dom.value='';this.el.dom.value=v;}});},initEvents:function(){Ext.ux.form.LovCombo.superclass.initEvents.apply(this,arguments);this.keyNav.tab=false;},clearValue:function(){this.value='';this.setRawValue(this.value);this.store.clearFilter();this.store.each(function(r){r.set(this.checkField,false);},this);if(this.hiddenField){this.hiddenField.value='';}
this.applyEmptyText();},getCheckedDisplay:function(){var re=new RegExp(this.valueSeparator,"g");return this.getCheckedValue(this.displayField).replace(re,this.separator);},getCheckedValue:function(field){field=field||this.valueField;var c=[];var snapshot=this.store.snapshot||this.store.data;snapshot.each(function(r){if(r.get(this.checkField)){c.push(r.get(field));}},this);return c.join(this.valueSeparator);},onBeforeQuery:function(qe){qe.query=qe.query.replace(new RegExp(this.getCheckedDisplay()+'[ '+this.separator+']*'),'');},onRealBlur:function(){this.list.hide();var rv=this.getRawValue();var rva=rv.split(new RegExp(RegExp.escape(this.separator)+' *'));var va=[];var snapshot=this.store.snapshot||this.store.data;Ext.each(rva,function(v){snapshot.each(function(r){if(v===r.get(this.displayField)){va.push(r.get(this.valueField));}},this);},this);this.setValue(va.join(this.valueSeparator));this.store.clearFilter();},onSelect:function(record,index){if(this.fireEvent('beforeselect',this,record,index)!==false){record.set(this.checkField,!record.get(this.checkField));if(this.store.isFiltered()){this.doQuery(this.allQuery);}
this.setValue(this.getCheckedValue());this.fireEvent('select',this,record,index);}},setValue:function(v){Ext.QuickTips.getQuickTip().unregister(this);if(v){v=''+v;if(this.valueField){this.store.clearFilter();this.store.each(function(r){var checked=!(!v.match('(^|'+this.valueSeparator+')'+RegExp.escape(r.get(this.valueField))
+'('+this.valueSeparator+'|$)'));r.set(this.checkField,checked);},this);this.value=this.getCheckedValue();this.setRawValue(this.getCheckedDisplay());if(this.hiddenField){this.hiddenField.value=this.value;}}
else{this.value=v;this.setRawValue(v);if(this.hiddenField){this.hiddenField.value=v;}}
if(this.el){this.el.removeClass(this.emptyClass);}
Ext.QuickTips.getQuickTip().register({target:this,text:this.getCheckedDisplay()});}
else{this.clearValue();}},selectAll:function(){this.store.each(function(record){record.set(this.checkField,true);},this);this.doQuery(this.allQuery);this.setValue(this.getCheckedValue());},deselectAll:function(){this.clearValue();}});Ext.reg('lovcombo',Ext.ux.form.LovCombo);

