var loaderImage = 'theme/images/ajax-loader.gif'; // Location of loader image, leave blank to disable preloader; function getElement(psID) { if(document.all) { return document.all[psID]; } else { return document.getElementById(psID); } } var ajaxPool = (function() { var stack = new Array(); var poolSize = 10; var nullFunction = function() {}; function getHTTPObject() { if(window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } } for (var i = 0; i < poolSize; i++) { stack.push(getHTTPObject()); } return ({ release:function(xhr) { xhr.onreadystatechange = nullFunction; stack.push(xhr); }, getInstance:function() { if (stack.length < 1) { return getHTTPObject(); } else { return stack.pop(); } }, toString:function() { return "stack size = " + stack.length; } }); })(); var ajaxPreLoader = (function() { return ({ show:function(called){ if (called && loaderImage) { var object = getElement('content'); if (object.offsetWidth) { var newdiv = document.createElement('div'); newdiv.setAttribute('id','loader'); newdiv.style.position='absolute'; newdiv.style.top='0px'; newdiv.style.left='0px'; newdiv.style.width=(object.offsetWidth+10)+'px'; newdiv.style.height=(object.offsetHeight+10)+'px'; imgposX = Math.round(((object.offsetWidth+10)/2)-16); imgposY = Math.round(((object.offsetHeight+10)/2)-16); if (imgposY<0) { imgposY = 50; } newdiv.innerHTML = ''; object.appendChild(newdiv); } } }, hide:function(called){ if (called && loaderImage) { var object = getElement('content'); if (getElement('loader')&&getElement('content')) { object.removeChild(getElement('loader')); } window.scroll(0,0); } } }); })(); var ajaxResponse = (function() { function processForm(form) { var params ='' for (var i = 0; i-1) { url += '&'+unique; } else { url += '?'+unique; } return url; } function handleResponse(method,handler,response) { switch(method) { case 'GET_CONTENT': switch (handler.tagName) { case 'DIV': handler.innerHTML = response; break; } break; case 'HANDLE_RESPONSE': handler(response); break; } } return ({ get:function(query,method,handler,showloader) { if (ajaxPreLoader) { ajaxPreLoader.show(showloader); } query = uniqueUrl(query); var httpStream = ajaxPool.getInstance(); httpStream.open('GET', query, true); httpStream.onreadystatechange = function() { if (httpStream.readyState == 4) { if (ajaxPreLoader) { ajaxPreLoader.hide(showloader); } if(httpStream.status == 408) { // Do Something } else if (httpStream.status == 200) { handleResponse(method,handler,httpStream.responseText); } ajaxPool.release(httpStream); } } httpStream.send(null); }, post:function(form,url,method,handler,showloader) { if (ajaxPreLoader) { ajaxPreLoader.show(showloader); } if (form.submit && form.submit.disabled) { form.submit.disabled=true; } var httpStream = ajaxPool.getInstance(); var params = processForm(form); url=uniqueUrl(url); httpStream.open("POST", url, true); httpStream.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpStream.setRequestHeader("Content-length", params.length); httpStream.setRequestHeader("Connection", "close"); httpStream.onreadystatechange = function() { if(httpStream.readyState == 4) { if(httpStream.status == 408) { // Do Something } else if (httpStream.status == 200) { handleResponse(method,handler,httpStream.responseText); if (ajaxPreLoader) { ajaxPreLoader.hide(showloader); } if (form.submit&&form.submit.disabled) { form.submit.disabled=false; } } ajaxPool.release(httpStream); } } httpStream.send(params); } }); })(); var attachToHead = (function() { return ({ css:function(location){ var headID = document.getElementsByTagName("head")[0]; var loaded = false; for ( i=1; i< headID.childNodes.length; i++ ) { node = headID.childNodes[i]; if (node.nodeName=="LINK") { if (node.href.match(location)) { var loaded=true; } } } if (!loaded) { var cssNode = document.createElement('link'); cssNode.type = 'text/css'; cssNode.rel = 'stylesheet'; cssNode.href = location; headID.appendChild(cssNode); } }, js:function(location,reload){ var headID = document.getElementsByTagName("head")[0]; var loaded = false; for ( i=1; i< headID.childNodes.length; i++ ) { node = headID.childNodes[i]; if (node.nodeName=="SCRIPT") { if (node.src.match(location)) { if (!reload) { var loaded = true; } else { headID.removeChild(node); } } } } if (!loaded) { var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = location; headID.appendChild(newScript); } } }); })(); function urlencode(url) { data = url; var utftext = ""; len = data.length; for (var i=0;i 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return escape(utftext); }