function Http(method, action, d, caller) {
    this.method = method;
    this.action = action;
    this.pars = d;
    this.caller = caller;
    this.async;
    this.xmlhttp;
    this.response;
    this.recipient;
    this.Server = new Array();
    var me = this;
    this.pairs = new Array();
    this.pair = new Array();
    this.send = function () {
        if (this.caller != "") {
            this.recipient = this.caller;
            this.async = true;   //default async
        }
        else {
            this.async = false;
        }
        this.xmlhttp = null;
        // code for Mozilla, etc.
        if (window.XMLHttpRequest) {
            this.xmlhttp = new XMLHttpRequest();
        }
        // code for IE
        else if (window.ActiveXObject) {
            this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (this.xmlhttp != null) {
            if (this.async) {
                this.xmlhttp.onreadystatechange = this.state_Change;
            }
            this.xmlhttp.open(this.method, this.action, this.async);
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            //alert("d="+d);  
            this.xmlhttp.send(d);
        }
        else {
            alert("Your browser does not support XMLHTTP.");
        }
        if (!this.async) {
            this.response = this.xmlhttp.responseText;
            this.parse();
        }
    }
    this.parse = function () {
        if (this.response.charCodeAt(0) == 0xFEFF) { this.response = this.response.substr(1); }
        this.pairs = this.response.split("&");
        for (i = 0; i < this.pairs.length; i++) {
            this.pair = this.pairs[i].split("=", 2);
            this.Server[this.pair[0]] = this.pair[1];
        }
    }

    this.state_Change = function () {
        if (me.xmlhttp.readyState == 4) {
            me.response = me.xmlhttp.responseText;
            //alert(me.xmlhttp.readyState);
            me.parse();
            me.recipient();
        }

    }
}
//replaces any non alpha numeric with %<hex> for transport over http
//this makes the '&' and '=' unique for parameter definitions
function encode(s) {
es = "";
    if(s != "")
    {
        for(var i=0;i<s.length;i++)
        {
            cc = s.charCodeAt(i);
            if(cc >= 48 && cc <= 57 || cc >= 64 && cc <= 90 || cc >= 97 && cc <= 122)
            {
            es += s.charAt(i);
            }
            else
            {
            es += "%"
            if (s.charCodeAt(i)<16){es += "0";}
            es += d2h(s.charCodeAt(i));
            }
        }
    }        
    return es;        
}

//replaces %<hex> with the character represented by <hex>
function decode(s)
{
es = "";
    try
    {
        if(s != "")
        {
    //alert(s);    
            for (i=0;i<s.length;i++)
            {
            cc = s.charAt(i);
                if(cc == "%")
                {
                es += unescape(s.substr(i,3));
                i = i +2;
                }
                else{es += cc;}
            }
        }
    }
    catch(err)
    {
    es = "";
    }
return es; 
}
//hex <-> dec conversion
function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);}
function posting(p) {
    var q = "";
    var sep = ""
    for (var k in p) {
        q += sep + k + "=" + p[k];
        sep = "&";
    }
    return q;
}


