﻿String.prototype.trim=trim;function trim(){return this.replace(/^[\s]+|[\s]+$/g,"")}var wa_LogingImg=undefined;var wa_alpha=80;var wa_background=" #000000";var loginMaskV2=function(){this.loginImage="/images/login/loadingAnimation.gif";this.d=undefined;this.el=undefined;this.id=undefined;this.passwd=undefined;this.logincallback=null;this.callParameter=null;this.inited=false;this.initializeElement=function(){wa_LogingImg=new Image();wa_LogingImg.src=this.loginImage;var c=document.getElementsByTagName("body")[0];var b=document.createElement("Div");b.setAttribute("id","wa_maskDiv");b.setAttribute("class","mask");var a=document.createElement("Div");a.setAttribute("id","wa_loginDiv");a.setAttribute("style","display:none;");a.setAttribute("class","loginDiv");c.appendChild(a);c.appendChild(b);this.d=$("wa_loginDiv");this.el=$("wa_maskDiv");this.el.obj=this;this.el.onclick=function(){this.obj.hidelogin(this.obj)}};this.hidelogin=function(a){if(a==undefined||a==null){a=this}a.d.update("");a.d.hide();a.el.hide()};this.setCallback=function(b,a){if(this.d==undefined){this.initializeElement()}this.logincallback=b;if(a!=undefined){this.callParameter=a}else{this.callParameter=null}Ajax.Request.prototype.logincallback=this.logincallback;Ajax.Request.prototype.callParameter=this.callParameter;Ajax.Request.prototype.showlogin=this.showlogin;Ajax.Request.prototype.obj=this;Ajax.Request.prototype.el=this.el;Ajax.Request.prototype.d=this.d};this.checkLogin=function(b,a){this.setCallback(b,a);new Ajax.Request("/ajaxLogin/checkLogin.jsp",{method:"post",onCreate:function(c){c.request.d.update(wa_LogingImg);c.request.showlogin(c.request.obj)},onSuccess:function(f){var c=f.responseText;if(c.trim()==""){try{if(f.request.logincallback!=""||f.request.logincallback!=undefined){if(f.request.callParameter==null){f.request.logincallback()}else{f.request.logincallback(f.request.callParameter)}}}catch(d){}f.request.obj.hidelogin(f.request.obj)}else{f.request.obj.showloginWH(548,300,f.request.obj);f.request.d.update(c);f.request.obj.setLoginAction()}},onFailure:function(c){alert("有錯誤產生!");c.request.obj.hidelogin(c.request.obj)}})};this.getWindowSize=function(){var c=document.documentElement;var a=window.innerWidth||self.innerWidth||(c&&c.clientWidth)||document.body.clientWidth;var b=window.innerHeight||self.innerHeight||(c&&c.clientHeight)||document.body.clientHeight;arrayPageSize=[a,b];return arrayPageSize};this.showloginWH=function(d,a,e){if(e==undefined||e==null){e=this}var c=e.getWindowSize();var b=Math.max(document.documentElement.scrollHeight,c[1]);e.el.style.height="100%";if(!window.XMLHttpRequest&&window.ActiveXObject){e.el.style.position="absolute"}else{e.el.style.position="fixed"}e.el.style.left="0";e.el.style.top="0";e.el.style.zIndex=90;e.el.style.width="100%";e.el.style.display="block";e.el.style.filter="alpha(opacity="+wa_alpha+")";e.el.style.background=wa_background;if(!window.XMLHttpRequest&&window.ActiveXObject){e.d.style.position="absolute"}else{e.d.style.position="fixed"}e.d.style.zIndex=100;e.d.style.left=(c[0]-d)/2+"px";e.d.style.top=(c[1]-a)/2+"px";e.d.style.display="block"};this.showlogin=function(a){if(a==undefined||a==null){a=this}a.showloginWH(250,130,a)};this.setLoginAction=function(a){if(a==undefined||a==null){a=this}a.id=$("walogin_id");a.id.obj=this;a.passwd=$("walogin_passwd");a.passwd.obj=this;a.id.onkeydown=function(b){if(b==null){keycode=event.keyCode}else{keycode=b.which}if(keycode==13){a.login(a.id.value,a.passwd.value)}};a.passwd.onkeydown=a.id.onkeydown;$("wa_cancel").onclick=function(){a.hidelogin(a)};$("wa_sure").onclick=function(){a.login(a.id.value,a.passwd.value)};Ajax.Request.prototype.passwd=a.passwd},this.login=function(a,c){a.replace("電子郵件","");if(a==""||c==""){alert("帳號或密碼不可為空白!");return}var b="t21_account="+a+"&t21_password="+c;new Ajax.Request("/customer/LoginAction.jsp",{method:"post",postBody:b,asynchronous:false,onSuccess:function(i){var d=i.responseText;var f=new RegExp("alert\\(([^)]+)\\);","mi");d.match(f);var h=RegExp.$1.replace(/'|\"/g,"");if(h.indexOf("歡迎")>-1){i.request.obj.hidelogin(i.request.obj);try{if(i.request.logincallback!=""||i.request.logincallback!=undefined){if(i.request.callParameter==null){i.request.logincallback()}else{i.request.logincallback(i.request.callParameter)}}}catch(g){}return true}else{alert(h);i.request.passwd.value=""}return false},onFailure:function(d){alert("登入失敗!");return false}})}};
