﻿var AJAX = {
    makeRequest : function ( url, data, async, method, callback)  
    {
        var http_request = false;

        // Obtain the XMLHttpRequest object
        if (window.XMLHttpRequest) 
        { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
        } 
        else if (window.ActiveXObject) 
        { // IE
            try 
            {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) 
            {
                try 
                {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) 
                { }
            }
        }

        if (!http_request) 
        {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

        // if async is true, register the callback function         
        if(async)
            http_request.onreadystatechange = function( ) { 
                                                callback(http_request); } ;

        // create the request packet
        http_request.open(method, url, async);
		
        // required for POST request
        if(method=='POST')
            http_request.setRequestHeader('Content-Type', 
                                'application/x-www-form-urlencoded');
			
        // Send the packet with the data
        http_request.send(data);

        // if async is false, call the callback function
        if(!async)
            callback(http_request);
    }
} ;

