if(typeof (PHP2Controls)=="undefined"){PHP2Controls=new Object()}PHP2Controls.LoginManager=function(H,F,D,A,I){this.wsUrl=(H!=null)?H:"/wsdl/main.ajax.php";this.sRootUrl="/";var B=((F!=null)?F:"txtLogin");var E=((D!=null)?D:"txtPassword");var C=((A!=null)?A:"btnLogin");var I=((I!=null)?I:"cbAutoLogin");var G=this;this.txtLoginControl=document.getElementById(B);this.txtPasswordControl=document.getElementById(E);this.btnLoginControl=document.getElementById(C);this.cbAutoLoginControl=document.getElementById(I);this.setOnEnterHandler(this.txtLoginControl);this.setOnEnterHandler(this.txtPasswordControl);if(this.cbAutoLoginControl!=null){this.setOnEnterHandler(this.cbAutoLoginControl)}this.setOnEnterHandler(this.btnLoginControl);this.btnLoginControl.onclick=function(){G.doLogin()}};PHP2Controls.LoginManager.prototype.setSRootUrl=function(A){this.sRootUrl=A};PHP2Controls.LoginManager.prototype.doLogin=function(){this.serverResponse=new PHP2Ajax.JSONRequest(this.wsUrl);this.serverResponse.call("doLogin");this.serverResponse.add("txtLogin",this.txtLoginControl.value);this.serverResponse.add("txtPassword",this.txtPasswordControl.value);this.serverResponse.add("cbAutoLogin",(this.cbAutoLoginControl!=null)?this.cbAutoLoginControl.checked:false);this.serverResponse.setHandler(this.onLoginChecked);this.serverResponse.onResponseError=this.onResponseError;this.serverResponse.currentObject=this;this.serverResponse.execute();this.showLoading()};PHP2Controls.LoginManager.prototype.onLoginChecked=function(){this.currentObject.hideLoading();if(this.response.Response.LoginError.Code>0){this.currentObject.alert(this.response.Response.LoginError.Message)}else{document.location.href=this.response.Response.EnterPoint}return true};PHP2Controls.LoginManager.prototype.onResponseError=function(){this.currentObject.alert=new PHP2Controls.Alert("Error: "+this.response.Error.Code+". "+this.response.Error.Message);this.currentObject.hideLoading()};PHP2Controls.LoginManager.prototype.showLoading=function(){if(!document.getElementById("loginManagerLoading")){document.body.insertAdjacentHTML("beforeend",'<p id="loginManagerLoading" style="padding-left: 10px; position: absolute; display: none;"><img src="'+this.sRootUrl+'images/ajax/loading.circle.gif" height="20" width="20" /> <b>Logging in...</b></p>')}this.loginManagerLoadingPanel=document.getElementById("loginManagerLoading");this.loginManagerLoadingPanel.style.left=HTMLElement.findPosX(this.btnLoginControl)+this.btnLoginControl.offsetWidth+10+"px";this.loginManagerLoadingPanel.style.top=HTMLElement.findPosY(this.btnLoginControl)+"px";this.loginManagerLoadingPanel.style.display="inline"};PHP2Controls.LoginManager.prototype.hideLoading=function(){if(this.loginManagerLoadingPanel!=null){this.loginManagerLoadingPanel.style.display="none"}};PHP2Controls.LoginManager.prototype.alert=function(A,B){if(document.getElementById("pageMessages")!=null){document.getElementById("pageMessages").innerText=document.getElementById("pageMessages").textContent=A;document.getElementById("pageMessages").className="errorBlock"}else{this.txtLoginControl.style.borderColor="#FF0000";this.txtLoginControl.style.backgroundColor="#FFEFEF";this.txtPasswordControl.style.borderColor="#FF0000";this.txtPasswordControl.style.backgroundColor="#FFEFEF"}if(document.getElementById("loginErrorContainer")!=null){document.getElementById("loginErrorContainer").style.display="block"}};PHP2Controls.LoginManager.prototype.setOnEnterHandler=function(D){var B=this;var A=D;A.defaultOnKeyDownEventHandler=D.onkeydown;var C=function(E){mbEvent=((E)?E:event);if(mbEvent.keyCode==13){if(B.txtPasswordControl.value&&B.txtLoginControl.value){B.doLogin()}}else{if(typeof (A.defaultOnKeyDownEventHandler)=="function"){A.defaultOnKeyDownEventHandler(event)}}};D.onkeydown=C};
