// XMLHTTPRequest base object and methods // by Lost Boys - www.lostboys.nl var XMLHttp = { load:function(url, func){ return this.sendAndLoad(null, url, func, 'get'); }, sendAndLoad:function(doc, url, func, type){ var xmlhttp = this.getXMLHttp(); var async = func? true:false; var method = type || 'post'; xmlhttp.open(method, url, async); if(async) { xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4) { func(xmlhttp.responseXML, xmlhttp.status); } } } if(method == 'post' && typeof doc == 'string') { xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.setRequestHeader('Content-length', doc.length ); xmlhttp.setRequestHeader('Connection', 'close'); } xmlhttp.send(doc); if(!async) return xmlhttp.responseXML; }, getXMLHttp:function() { if(window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { var xmlhttp, http = ['Microsoft.XMLHTTP', 'Msxml2.XMLHTTP'], l = http.length; while(l--) { try { xmlhttp = new ActiveXObject(http[l]); return xmlhttp; } catch (e) {} } } else return false; } }