(function(funcName, baseObj) { // The public function name defaults to window.docReady // but you can pass in your own object and own function name and those will be used // if you want to put them in a different namespace funcName = funcName || "docReady"; baseObj = baseObj || window; var readyList = []; var readyFired = false; var readyEventHandlersInstalled = false; // call this when the document is ready // this function protects itself against being called more than once function ready() { if (!readyFired) { // this must be set to true before we start calling callbacks readyFired = true; for (var i = 0; i < readyList.length; i++) { // if a callback here happens to add new ready handlers, // the docReady() function will see that it already fired // and will schedule the callback to run right after // this event loop finishes so all handlers will still execute // in order and no new ones will be added to the readyList // while we are processing the list readyList[i].fn.call(window, readyList[i].ctx); } // allow any closures held by these functions to free readyList = []; } } function readyStateChange() { if ( document.readyState === "complete" ) { ready(); } } // This is the one public interface // docReady(fn, context); // the context argument is optional - if present, it will be passed // as an argument to the callback baseObj[funcName] = function(callback, context) { // if ready has already fired, then just schedule the callback // to fire asynchronously, but right away if (readyFired) { setTimeout(function() {callback(context);}, 1); return; } else { // add the function and context to the list readyList.push({fn: callback, ctx: context}); } // if document already ready to go, schedule the ready function to run if (document.readyState === "complete") { setTimeout(ready, 1); } else if (!readyEventHandlersInstalled) { // otherwise if we don't have event handlers installed, install them if (document.addEventListener) { // first choice is DOMContentLoaded event document.addEventListener("DOMContentLoaded", ready, false); // backup is window load event window.addEventListener("load", ready, false); } else { // must be IE document.attachEvent("onreadystatechange", readyStateChange); window.attachEvent("onload", ready); } readyEventHandlersInstalled = true; } }; })("docReady", window); docReady(function(){ var elms = document.querySelectorAll('.tab'); [].forEach.call(elms, function(elm) { elm.addEventListener("click", function(){ var id = elm.id.replace("tab", ""); highlightTab(id); }, false); }); if(document.getElementById("profile")){ document.getElementById("dashboard").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/")); }, false); document.getElementById("profile").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Profile/")); //window.location="/Profile/"; }, false); //document.getElementById("configureKitchens").addEventListener("click", function(){ //makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Configure-Kitchens/")); //window.location="/Configure-Kitchens/"; //}, false); var buttons = document.querySelectorAll('.configureVariant'); [].forEach.call(buttons, function(button) { button.addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Configure-Variant/"+button.getAttribute("data-variant")+"/"+button.getAttribute("data-tab")+"/")); }, false); }, false); //document.getElementById("configureVariant").addEventListener("click", function(){ //makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Configure-Variant/")); //window.location="/Configure-Kitchens/"; //}, false); //document.getElementById("configureBathrooms").addEventListener("click", function(){ //makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape(/Configure-Bathrooms/)); //window.location="/Configure-Bathrooms/"; //}, false); document.getElementById("drawings").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Drawings/")); //window.location="/Drawings/"; }, false); document.getElementById("leads").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Leads/")); //window.location="/Leads/"; }, false); document.getElementById("logout").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Logout/")); //window.location="/Logout/"; }, false); } if(document.getElementById("login")){ document.getElementById("home").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/")); //window.location="/"; }, false); document.getElementById("login").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Login/")); //window.location="/Login/"; }, false); } if(document.getElementById("register")){ document.getElementById("register").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/Register/")); //window.location="/Register/"; }, false); } if(document.getElementById("listClients")){ document.getElementById("listClients").addEventListener("click", function(){ makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t=0&u=1&loc="+escape("/ListClientAccounts/")); //window.location="/ListClientAccounts/"; }, false); } if(document.getElementById("langSelect")){ document.getElementById("langSelect").addEventListener("change", function(){ window.location="/core/changeLang.php?lang="+this.value; }, false); document.getElementById("backSelect").addEventListener("change", function(){ window.location="/core/changeBackground.php?background="+this.value; }, false); } }); function validateEmail(email) { var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; return re.test(email); } function highlightTab(t){ var elms = document.querySelectorAll('.tab'); [].forEach.call(elms, function(elm) { if(elm.classList.contains("tab"+t)){ elm.classList.add("activeTab"); makePOSTRequest("/core/activeTab.php", "v="+escape(window.location)+"&t="+t); } else { elm.classList.remove("activeTab"); } }); var elms = document.querySelectorAll('.content'); [].forEach.call(elms, function(elm) { if(elm.classList.contains("tab"+t+"Content")){ elm.classList.add("activeContent"); } else { elm.classList.remove("activeContent"); } }); } function scorePassword(pass) { var score = 0; if (!pass) return score; var letters = new Object(); for (var i=0; i 80) return " "; if (score > 60) return " "; if (score > 30) return " "; if (score > 10) return " "; if(forceAnswer && score < 10) return " "; else return ""; } function percentToRGB(percent) { if (percent === 100) { percent = 99; } var r, g, b; if (percent < 50) { r = Math.floor(255 * (percent / 50)); g = 255; } else { r = 255; g = Math.floor(255 * ((50 - percent % 50) / 50)); } b = 0; return "rgb(" + r + ", " + g + ", " + b + ")"; } var http_request = false; function makePOSTRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.send(parameters); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { eval(http_request.responseText); } } }