function logon(type, sure){ if(type == "logout" && sure != true){ $( "#logout-dialog-confirm" ).dialog( "open" ); return false; } if(sure){ var url = "/logon?actionType=" + type + "&lang=en_US&timeStamp=" + new Date().getTime(); ajaxHandler(url, "loginForm"); } }; function ajaxHandler(url, formName){ createXMLHttpRequest(); xmlHttp.open("POST", url); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = handleLoginStateChange; var postData = getFormValues(document.getElementById(formName)); xmlHttp.send(postData); }; function handleLoginStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { if(trim(xmlHttp.responseText) == "LoginFailed"){ $( "#login-dialog-form" ).dialog( "open" ); document.getElementById("login").innerHTML = "Login"; var tips = $( ".validateTips" ); tips.text( "Login Failed! Invalid UserId or Password" ).addClass( "ui-state-highlight" ); } else if(trim(xmlHttp.responseText) == "LogoutSuccess"){ hide("sayHello"); hide("bookBtn"); show("plsLogin"); show("plsLoginBtn"); window.location = "./"; } else { show("sayHello"); show("bookBtn"); document.getElementById("sayHello").innerHTML = xmlHttp.responseText; hide("plsLogin"); hide("plsLoginBtn"); } } } }; /* logon layer */ $(function() { var userId = $( "#userId" ), passwd = $( "#passwd" ), myUId = $( "#myUserId" ); myMail = $( "#myEmail" ); allFields = $( [] ).add( userId ).add( passwd ), tips = $( ".validateTips" ); function updateHints( t ) { tips.text( t ).addClass( "ui-state-highlight" ); setTimeout(function() { tips.removeClass( "ui-state-highlight", 1500 ); }, 500 ); } function checkInput( o, n ) { if ( o.val().length < 1 ) { o.addClass( "ui-state-error" ); updateHints( n ); o.focus(); return false; } else { return true; } } //login $( "#login-dialog-form" ).dialog({ autoOpen: false, height: 280, width: 360, modal: true, buttons: { "Login": function() { var bValid = true; allFields.removeClass( "ui-state-error" ); bValid = bValid && checkInput( userId, "Please Input UserId" ); bValid = bValid && checkInput( passwd, "Please Input Password" ); if ( bValid ) { logon('login', true); document.getElementById("login").innerHTML = ""; $( this ).dialog( "close" ); } }, "Cancel": function() { $( this ).dialog( "close" ); } }, close: function() { allFields.val( "" ).removeClass( "ui-state-error" ); } }); $( "#login" ).click(function() { $( "#login-dialog-form" ).dialog( "open" ); }); $( "#login2" ).click(function() { $( "#login-dialog-form" ).dialog( "open" ); }); //forgot Password $( "#forgotPasswd-dialog-form" ).dialog({ autoOpen: false, height: 300, width: 360, modal: true, buttons: { "Send New Password": function() { var bValid = true; allFields.removeClass( "ui-state-error" ); bValid = bValid && checkInput( myUId, "Please Input UserId" ); bValid = bValid && checkInput( myMail, "Please input your email" ); if ( bValid ) { sendPasswd(); } }, "Close": function() { $( this ).dialog( "close" ); } }, close: function() { allFields.val( "" ).removeClass( "ui-state-error" ); } }); $( "#forgotPassword" ).click(function() { $( "#login-dialog-form" ).dialog( "close" ); $( "#forgotPasswd-dialog-form" ).dialog( "open" ); }); //press enter to submit $('#login-dialog-form').keyup(function(e) { if (e.keyCode == 13) { logon('login', true); $( this ).dialog( "close" ); } }); //logout $( "#logout-dialog-confirm" ).dialog({ resizable: false, height:168, modal: true, autoOpen: false, buttons: { "Logout": function() { logon('logout', true); $( this ).dialog( "close" ); }, "Cancel": function() { $( this ).dialog( "close" ); } } }); }); /* forgot password layer */ function show(layer){ var layer = document.getElementById(layer); if(layer != null){ layer.style.display = 'block'; } }; function hide(layer){ var layer = document.getElementById(layer); if(layer != null){ layer.style.display = 'none'; } }; function check(type){ if(type=="myBooking"){ window.location = "/my?actionType=" + type; } else if(type=="profile"){ window.location = "/logon?actionType=" + type; } else if(type=="db"){ window.location = "/db"; } }; function sendPasswd(){ var sure = confirm('Your password will be reset. Are you sure to continue?'); if (!sure){ return false; } document.getElementById("fghint").innerHTML = ""; var userId = document.getElementById("myUserId").value; var email = document.getElementById("myEmail").value; var url = "/logon?actionType=sendNewPassword&userId=" + encodeURI(userId) + "&email=" + email + "&lang=en_US"; ajaxNewpassHandler(url); }; function createXMLHttpRequestNewpass(){ if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } }; function ajaxNewpassHandler(url){ createXMLHttpRequestNewpass(); xmlHttp.open("POST", url); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = handleNewpassStateChange; xmlHttp.send(null); }; function handleNewpassStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { if(trim(xmlHttp.responseText) == "OK"){ document.getElementById("fghint").innerHTML = "Your new password has been send to your email. Thank you."; } else { document.getElementById("fghint").innerHTML = "Your password reset failed... Please contact us for further assistance."; } } } };