﻿// JScript File

function asyncPostUrlInstance()
{
    this.callerContext = null;
    this.postHttp = null;
    
    if(window.XMLHttpRequest)
    {
        this.postHttp = new XMLHttpRequest();
    } 
    else if(window.ActiveXObject)
    {
        var vers = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
        for(var i = 0; i < vers.length; i++)
        {
            try 
            {
                this.postHttp = new ActiveXObject(vers[i]);
                if(this.postHttp)
                    break;
            }
            catch(ex)
            {
            }
        }
    }
    return this;
}

function asyncPostUrlCallBack(inst)
{
    if(inst.postHttp.readyState == 4)
    {
        if(inst.callerContext && inst.callerContext.callBack)
        {
            var success = (inst.postHttp.status == 200 && inst.postHttp.responseText) ? true : false;
            inst.callerContext.callBack(inst.postHttp, success, inst.callerContext);
        }
    }
}

function asyncPostUrl(url, data, callerContext)
{
    var apuInst = new asyncPostUrlInstance();
    apuInst.callerContext = callerContext;
    apuInst.postHttp.onreadystatechange = function(){asyncPostUrlCallBack(apuInst);}
    apuInst.postHttp.open("POST", url, 1);
    apuInst.postHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    apuInst.postHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    apuInst.postHttp.setRequestHeader("Content-length", data.length);
    apuInst.postHttp.send(data);
}

