﻿function GetXmlHttpObject()
{
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined") {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        throw new Error("XMLHttpRequest not supported");
    }
}
function PostAsynchronousData(url,params,callback_function) {
	var xmlHttp = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest()
	xmlHttp.open("POST", url, true)
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	xmlHttp.setRequestHeader("Content-length", params.length)
	xmlHttp.setRequestHeader("Connection", "close")
	xmlHttp.onreadystatechange = function() {if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {eval(callback_function)}}
	xmlHttp.send(params)
}
function GetAsynchronousData(url,callback_function)
{
    var xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
          alert ("Your browser does not support AJAX!");
          return;
    } 
    
    if (url.indexOf("?")==-1)
    {
        url+="?sid="+Math.random();        
    }
    else
    {
        url+="&sid="+Math.random();        
    }
            
    xmlHttp.onreadystatechange=function () 
    { 
        if (xmlHttp.readyState==4)
        { 
            eval(callback_function)
        }    
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function SendPostAsynchronousData(url,params,callback_function)
{
    var xmlHttp=GetXmlHttpObject();
    
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    
    if (xmlHttp==null)
    {
          alert ("Your browser does not support AJAX!");
          return;
    } 
    
    if (url.indexOf("?")==-1)
    {
        url+="?sid="+Math.random();        
    }
    else
    {
        url+="&sid="+Math.random();        
    }
            
    xmlHttp.onreadystatechange=function () 
    { 
        if (xmlHttp.readyState==4)
        { 
            eval(callback_function)
        }    
    }
    xmlHttp.open('POST', url, true);
    xmlHttp.send(params);    
}
