function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

Ajax={};
Ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
Ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
Ajax.send=function(x,u,f,m,a)
{   // added basic error trapping but no resolution
    x.open(m,u,true);
    x.onreadystatechange=function()
    {
        if(x.readyState==4)
            if (x.status == 200) {
                f(x.responseText)
            } else
                Ajax.error("unknown error");
    };
    if(m=='POST')
        x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    x.send(a)
};
Ajax.get=function(x,url,func){Ajax.send(x,url,func,'GET')};
Ajax.gets=function(x,url){x.open('GET',url,false);x.send(null);return x.responseText};
Ajax.post=function(x,url,func,args){Ajax.send(x,url,func,'POST',args)};
Ajax.update=function(x,url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};Ajax.get(x,url,f)};
Ajax.submit=function(x,url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};Ajax.post(x,url,f,Ajax.serialize(frm))};
Ajax.error=function(str)
{
    window.location = "/error.aspx?error=There was a problem processing your request.  Please try again.&detail=" + str;
}
Ajax.reset=function(x)
{   // resets the current request and returns a new request object
    try { x.abort(); } catch(ex) {}
    return Ajax.x();
}

