﻿function createRequestObject()
{
    var tmpXmlHttpObject;
    
    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest)
    { // Mozilla, Safari, ...
        tmpXmlHttpObject = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject)
    { // IE
        try
        {
            tmpXmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e)
        {
            try
            {
                tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
    }
    
    return tmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
function makeGetRequest(url, values, dest)
{
    var http = createRequestObject();
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    if (http)
    {
        var req;
        if(values == '')
            req = url
        else
            req = url + '?' + values;
        http.open('GET', req, true);
    	
        //assign a handler for the response
        http.onreadystatechange = function() {processResponse(http, dest)};
    	
        //actually send the request to the server
        http.send(null);
    }
}

function processResponse(http, dest)
{
    try
    {
        //check if the response has been received from the server
        if(http.readyState == 4){
    	
	        if (http.status == 200)
	        {
                //read and assign the response from the server
                var response = http.responseText;
        		
                //in this case simply assign the response to the contents of the <div> on the page. 
                if (response != '')
                    document.getElementById(dest).innerHTML = response;
            }		
        }
    }
    catch(e) {}
}
