var MemberLogin = MemberLogin || {}; MemberLogin.Ajax = { XMLHttpFactories: [ function () {return new XMLHttpRequest()}, function () {return new ActiveXObject("Msxml2.XMLHTTP")}, function () {return new ActiveXObject("Msxml3.XMLHTTP")}, function () {return new ActiveXObject("Microsoft.XMLHTTP")} ], sendRequest: function (url, callback, postData) { var req = this.createXMLHTTPObject(); var method = (postData) ? "POST" : "GET"; if (!req) { return; } req.open(method, url, true); req.setRequestHeader('User-Agent', 'XMLHTTP/1.0'); req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); if (postData) { req.setRequestHeader('Content-type','application/x-www-form-urlencoded'); } req.onreadystatechange = function () { if (req.readyState != 4) { return; } if (req.status != 200 && req.status != 304) { return; } callback(req); } if (req.readyState == 4) { return; } req.send(postData); }, createXMLHTTPObject: function () { var xmlhttp = false; for (var i = 0; i < this.XMLHttpFactories.length; i++) { try { xmlhttp = this.XMLHttpFactories[i](); } catch (e) { continue; } break; } return xmlhttp; }, get: function (url, container_id) { this.sendRequest(url, function (req) { document.getElementById(container_id).innerHTML = req.responseText; }); }, post: function (url, container_id, postData) { this.sendRequest(url, function (req) { document.getElementById(container_id).innerHTML = req.responseText; }, postData); }, getJSON: function (url, callback) { this.sendRequest(url, function (req) { callback(eval("(" + req.responseText + ")")); }); }, postJSON: function (url, callback, postData) { this.sendRequest(url, function (req) { callback(eval("(" + req.responseText + ")")); }, postData); } }; MemberLogin.Utils = { importCss: function (cssFile) { if (document.createStyleSheet) { document.createStyleSheet(cssFile); } else { var styles = "@import url(" + cssFile + ");"; var newSS = document.createElement('link'); newSS.rel = 'stylesheet'; newSS.href = 'data:text/css,' + escape(styles); document.getElementsByTagName("head")[0].appendChild(newSS); } }, getElementsByClass: function (searchClass, node, tag) { var classElements = new Array(); if (node == null) { node = document; } if (tag == null) { tag = '*'; } var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (var i = 0, j = 0; i < elsLen; i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; j++; } } return classElements; }, addEvent: function (obj, type, fn) { if (obj.addEventListener) { obj.addEventListener( type, fn, false ); MemberLogin.Utils.eventCache.add(obj, type, fn); } else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } obj.attachEvent( "on"+type, obj[type+fn] ); MemberLogin.Utils.eventCache.add(obj, type, fn); } else { obj["on"+type] = obj["e"+type+fn]; } }, eventCache: function () { var listEvents = []; return { listEvents : listEvents, add : function (node, sEventName, fHandler) { listEvents.push(arguments); }, flush : function () { var i, item; for (i = listEvents.length - 1; i >= 0; i = i - 1) { item = listEvents[i]; if(item[0].removeEventListener) { item[0].removeEventListener(item[1], item[2], item[3]); }; if(item[1].substring(0, 2) != "on"){ item[1] = "on" + item[1]; }; if(item[0].detachEvent){ item[0].detachEvent(item[1], item[2]); }; item[0][item[1]] = null; }; } }; }(), serialize: function(form) { if (!form || form.nodeName !== "FORM") { return; } var i, j, q = []; for (i = form.elements.length - 1; i >= 0; i = i - 1) { if (form.elements[i].name === "") { continue; } switch (form.elements[i].nodeName) { case 'INPUT': switch (form.elements[i].type) { case 'text': case 'hidden': case 'password': case 'button': case 'reset': case 'submit': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; case 'checkbox': case 'radio': if (form.elements[i].checked) { q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); } break; case 'file': break; } break; case 'TEXTAREA': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; case 'SELECT': switch (form.elements[i].type) { case 'select-one': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].options[form.elements[i].selectedIndex].value)); break; case 'select-multiple': for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) { if (form.elements[i].options[j].selected) { q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].options[j].value)); } } break; } break; case 'BUTTON': switch (form.elements[i].type) { case 'reset': case 'submit': case 'button': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; } break; } } return q.join("&"); } }; MemberLogin.Login = { logMeIn: function (form) { if (MemberLogin.Login.validateLoginForm(form)) { var postStr = MemberLogin.Utils.serialize(form); MemberLogin.Ajax.getJSON( MemberLogin.LoginSettings.URL + "frontend/include/login.php?f=1&" + postStr, function (json) { switch(json['code']) { case '100': MemberLogin.LoginSettings.messagesWrapper.innerHTML = json['message']; if (json['welcome_page'] != '') { window.location.href = json['welcome_page']; } break; default: MemberLogin.LoginSettings.messagesWrapper.innerHTML = json['message']; break; } } ); MemberLogin.Login.resetLoginForm(form); } }, sendMePassword: function (form) { if (MemberLogin.Login.validateLostPasswordForm(form)) { var postStr = MemberLogin.Utils.serialize(form); MemberLogin.Ajax.getJSON( MemberLogin.LoginSettings.URL + "frontend/include/forgot_password.php?f=1&" + postStr, function (json) { switch(json['code']) { case '100': MemberLogin.LoginSettings.messagesWrapper.innerHTML = json['message']; MemberLogin.Login.loadLogin(false); break; default: MemberLogin.LoginSettings.messagesWrapper.innerHTML = json['message']; break; } } ); MemberLogin.Login.resetLostPasswordForm(form); } }, resetLoginForm: function (form) { form.email.value = ''; form.password.value = ''; }, resetLostPasswordForm: function (form) { form.email.value = ''; }, loadForgotPassword: function (msgFlag) { if (msgFlag) { MemberLogin.LoginSettings.messagesWrapper.innerHTML = ''; } MemberLogin.Ajax.get(MemberLogin.LoginSettings.installFolder + "frontend/include/forgot_password.php?ac=forgot_password", "ml_login_content"); }, loadLogin: function (msgFlag) { if (msgFlag) { MemberLogin.LoginSettings.messagesWrapper.innerHTML = ''; } MemberLogin.Ajax.get(MemberLogin.LoginSettings.installFolder + "frontend/include/login.php?ac=login", "ml_login_content"); }, validateLoginForm: function (form) { re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/; var message = ""; var dataRight = true; var email = form.email.value; var password = form.password.value; if (email.length == 0){ message += "\n - " + MemberLogin.LoginSettings.validationEmail; dataRight = false; } if (email.length!=0 && email.match(re)==null){ dataRight=false; message += "\n - " + MemberLogin.LoginSettings.validationInvalidEmail; } if (password.length == 0){ message += "\n - " + MemberLogin.LoginSettings.validationPassword; dataRight = false; } if (!dataRight){ if (message != "") { message ="\n" + MemberLogin.LoginSettings.validationLoginDataRequired +"\n" + message; } alert(message); } return dataRight; }, validateLostPasswordForm: function (form) { re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/; var message = ""; var dataRight = true; var email = form.email.value; if (email.length == 0){ message += "\n - " + MemberLogin.LoginSettings.validationEmail; dataRight = false; } if (email.length!=0 && email.match(re)==null){ dataRight=false; message += "\n - " + MemberLogin.LoginSettings.validationInvalidEmail; } if (!dataRight){ if (message != "") { message ="\n" + MemberLogin.LoginSettings.validationLoginDataRequired +"\n" + message; } alert(message); } return dataRight; } }; document.writeln('
'); MemberLogin.LoginSettings = { URL: "http://www.oracwa.org/MemberLoginDev/", uploadUrl: "http://www.oracwa.org/MemberLoginDev/uploads/", installFolder: "/MemberLoginDev/", messagesWrapper: document.getElementById("ml_login_messages"), contentWrapper: document.getElementById("ml_login_content"), validationName: "Name", validationEmail: "Email", validationInvalidEmail: "Invalid email address", validationPassword: "Password", validationPhone: "Phone", validationWeb: "Web", validationLoginDataRequired: "Email and password are required." } MemberLogin.Ajax.get("/MemberLoginDev/frontend/include/login.php?f=1&ac=0", "ml_login_content");