window.AJAX={object2url:function(e){if(!e){e={}}var d="";var a=function(g){for(var c in g){if(d.length){d+="&"}d+=encodeURIComponent(c)+"="+encodeURIComponent(g[c])}};if(e instanceof Array){for(var b=0,f=e.length;b<f;b++){a(e[b])}}else{a(e)}return d},catched:function(b,a){throw new Error("AJAX ERROR: "+b.toString()+": Server response: "+a)},update:function(id,url,params,method){if(!method){method="GET"}var request=new AJAX.request(function(transport,aborted){if(!aborted){var html=transport.responseText;(typeof id=="string"?document.getElementById(id):id).innerHTML=html;var scriptsRegExp="<script.*?>s*(?:<!--)?s*((\n|\r|.)*?)<\/script>";var allScripts=html.match(new RegExp(scriptsRegExp,"img"));if(allScripts){var scriptsCount=allScripts.length;for(var i=0;i<scriptsCount;i++){try{eval(allScripts[i].match(new RegExp(scriptsRegExp,"im"))[1])}catch(e){AJAX.catched(e,html)}}}}request=null},method,url,params);return request},run:function(url,params,method){if(!method){method="GET"}var request=new AJAX.request(function(transport,aborted){if(!aborted){var script_body=transport.responseText.replace(/^\s*<\!\-\-\s*/,"");try{eval(script_body)}catch(e){AJAX.catched(e,script_body)}}request=null},method,url,params,{Accept:"text/javascript"});return request},fire:function(callback,url,params,method){var events={onBefore:null,onComplete:null};if(typeof callback=="function"){events.onComplete=callback}else{if(callback.onBefore&&typeof callback.onBefore=="function"){events.onBefore=callback.onBefore}if(callback.onComplete&&typeof callback.onComplete=="function"){events.onComplete=callback.onComplete}}if(!method){method="GET"}var request=new AJAX.request({onBefore:events.onBefore,onComplete:function(transport,aborted){if(aborted){if(events.onComplete){events.onComplete(null,aborted)}}else{var data=transport.responseText;var content_type=transport.getResponseHeader("Content-Type");request=null;try{if(content_type.match(new RegExp("application/json"))){eval("data = "+data)}if(events.onComplete){events.onComplete(data,aborted)}}catch(e){AJAX.catched(e,data)}}}},method,url,params);return request},form:function(k,j,f){var h=new Array();var d=location.pathname;var a="GET";if(k&&k.elements){if(k.action.length){d=k.action}if(k.method.toUpperCase()=="POST"){a="POST"}for(var l=0,m=k.elements.length;l<m;l++){var g=k.elements[l];if(g.name&&!g.disabled){switch(g.type){case"radio":case"checkbox":if(g.checked){var e={};e[g.name]=g.value;h.push(e)}break;case"select-one":for(var n=0,b=g.options.length;n<b;n++){if(g.options[n].selected){var e={};e[g.name]=g.options[n].value;h.push(e);break}}break;case"select-multiple":for(var n=0,b=g.options.length;n<b;n++){if(g.options[n].selected){var e={};e[g.name]=g.options[n].value;h.push(e)}}break;default:var e={};e[g.name]=g.value;h.push(e)}}}}if(j=="run"){return this.run(d,h,a)}else{if(j=="update"){return this.update(f,d,h,a)}else{if(j=="fire"){return this.fire(f,d,h,a)}else{return false}}}}};AJAX.counter=0;AJAX.request=function(h,g,a,f,d){this.id=AJAX.counter++;this.events={onBefore:null,onComplete:null};this.params=f||{};this.headers=d||{};this.method=g?g.toUpperCase():"POST";this.url=a||location.href;this.data=null;this.transport=null;this.requesting=false;this.aborted=false;if(typeof h=="function"){this.events.onComplete=h}else{if(h.onBefore&&typeof h.onBefore=="function"){this.events.onBefore=h.onBefore}if(h.onComplete&&typeof h.onComplete=="function"){this.events.onComplete=h.onComplete}}if(!this.transport){try{this.transport=new XMLHttpRequest()}catch(c){}}if(!this.transport){try{this.transport=new ActiveXObject("Msxml2.XMLHTTP")}catch(c){}}if(!this.transport){try{this.transport=new ActiveXObject("Microsoft.XMLHTTP")}catch(c){}}this.data=AJAX.object2url(this.params);if(this.data.length){this.data+="&"}this.data+="ajaxrndcmpnt="+Math.random();if(this.method!="POST"){this.url+=(this.url.indexOf("?")==-1?"?":"&")+this.data}this.transport.open(this.method,this.url,true,false);if(this.method=="POST"){this.transport.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}this.transport.setRequestHeader("X-Requested-With","XMLHttpRequest");for(header_name in this.headers){this.transport.setRequestHeader(header_name,this.headers[header_name])}var b=this;this.transport.onreadystatechange=function(){if(b.transport.readyState==4){b.requesting=false;if(!b.aborted){b.events.onComplete(b.transport,b.aborted)}b.transport=null}};this.send=AJAX.request.send;this.abort=AJAX.request.abort;this.send()};AJAX.request.send=function(){this.requesting=true;if(this.events.onBefore){this.events.onBefore()}if(this.method=="POST"){this.transport.send(this.data)}else{this.transport.send("")}};AJAX.request.abort=function(){if(this.requesting){this.requesting=false;this.aborted=true;this.transport.abort();if(this.events.onComplete){this.events.onComplete(this.transport,this.aborted)}this.transport=null}};
