
/**
 * AJAX class.
 */
function AJAX() {
    
    var xmlHttp = null;
    
    this.init = function() {
        
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        }
        catch (e) {
            // Internet Explorer
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        
        if (xmlHttp == null)
            return false;
        else
            return true;
        
    }
    
    /**
     * postData() - uses POST method to send data to the script.
     * @param script    The name of the script to call
     * @param params    Any parameters that need POSTing
     * @param callback  Callback function to execute when data is returned by script
     */
    this.postData = function(script, params, callback) {
                    
        // Handle the return from php
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                callback(xmlHttp.responseText);    
            }
        }
        xmlHttp.open("POST", script, true);
        // Send the proper header information along with the request
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(params);
                    
        
    }
    
}
