﻿function GetXmlHttpObject(handler)
{ 
    var objXmlHttp = null;
    if (!window.XMLHttpRequest)
    {
        // Microsoft
        objXmlHttp = GetMSXmlHttp();
        if (objXmlHttp != null && handler != null)
        {
            objXmlHttp.onreadystatechange = handler;
        }
    } 
    else
    {
        // Mozilla | Netscape | Safari
        objXmlHttp = new XMLHttpRequest();
        if (objXmlHttp != null && handler != null)
        {
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler;
        }
    } 
    return objXmlHttp; 
} 

function GetMSXmlHttp()
{
    var xmlHttp = null;
    var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
                 "Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", 
                 "Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
                 "Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
    for(var i=0; i<clsids.length && xmlHttp == null; i++) {
        xmlHttp = CreateXmlHttp(clsids[i]);
    }
    return xmlHttp;
}

function CreateXmlHttp(clsid) {
    var xmlHttp = null;
    try {
        xmlHttp = new ActiveXObject(clsid);
        lastclsid = clsid;
        return xmlHttp;
    }
    catch(e) { return xmlHttp; }
}
function SendXmlHttpRequest(xmlhttp, url) { 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
}

var xmlHttp; 

function GetXml()
{
    //try 
    //{ 
        xmlHttp = GetXmlHttpObject(null); 
		//var response = xmlHttp.responseText; 
		//if (response.length > 0)
		//{
		//	return xmlHttp.responseText;
		//}
    //}
    //catch(e){} 
}

function GetResponse()
{
	var response = '';
    try 
    { 
		var response = xmlHttp.responseText; 
		if (response.length > 0)
		{
			response = xmlHttp.responseText;
		}
    }
    catch(e){} 
	return response;
}

/*function ExecuteCallOld(url)
{ 
    try 
    { 
        xmlHttp = GetXmlHttpObject(CallbackMethod); 
        SendXmlHttpRequest(xmlHttp, url);
		var response = xmlHttp.responseText; 
		if (response.length > 0)
		{
			return xmlHttp.responseText;
		}
    }
    catch(e){} 
} */
    
//CallbackMethod will fire when the state 
//has changed, i.e. data is received back 
function CallbackMethod() 
{ 
    try
    {
        //readyState of 4 or 'complete' represents 
        //that data has been returned 
        if (xmlHttp.readyState == 4 || 
            xmlHttp.readyState == 'complete')
        {
            //var response = xmlHttp.responseText; 
            //if (response.length > 0)
            //{
                //update page
                //document.getElementById("elementId").innerHTML = response; 
            //} 
        }
    }
    catch(e){}
}