//
//
// Blue Engine Web Development - Async ajax core
//
// developed by Blue Engine Web Development, Bratton, Wiltshire UK Call 07802 911498 - http://www.blueengine.co.uk


/* AJAXConnection class
This code should be generic to all similar AJAX applications
*/
function AJAXConnection(name) {    
    this.className = 'AJAXConnection';
    //alert(this.className + ' ' + name);
    
    /* Default construtor */
    {    
        this.name = name;
    }

    this.xmlhttpPost = function (strURL, functionObj, params) {
        var xmlHttpReq = false;
        var self = this;

        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            self.xmlHttpReq = new XMLHttpRequest();
            if (self.xmlHttpReq.overrideMimeType) {
                self.xmlHttpReq.overrideMimeType('text/xml');
                // See note below about this line
            }
        // IE
        } else if (window.ActiveXObject) { // IE
            try {
                self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
            }
        }
        if (!self.xmlHttpReq) {
            alert('ERROR AJAX:( Cannot create an XMLHTTP instance');
            return false;
        }

        //alert(strURL);
        self.xmlHttpReq.open('POST', strURL, true);
        self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {_callBackFunction(self.xmlHttpReq, functionObj);};
        self.xmlHttpReq.send(params);

    }
    
    _callBackFunction = function (http_request, functionObj)
    {
        if (http_request.readyState == 4)
        {
            if (http_request.status == 200)
            {
                //alert(http_request.responseText);
                functionObj.callBackFunction(http_request.responseText);
            } 
            else
            {
                // at some point do something else here...
                //alert('ERROR: AJAX request status = ' + http_request.status);
            }
        }
     }

}

