/**  AJAXConnection class  */
function AJAXConnection(name) {    
    this.className = 'AJAXConnection';

    //alert(this.className + ' ' + name);
    /** Default construtor
     *
     * name - div name
     */
    {    
        this.name = name;
    }

	// Create instance of XMLHTTPRequest depending on browser //
    this.xmlhttpPost = function (strURL, functionObj, form) {
        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;
        } 
		
		
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() { _callBackFunction(self.xmlHttpReq, functionObj, form); };
        self.xmlHttpReq.send("");
    }
    
    _callBackFunction = function (http_request, functionObj, form) {

		var div_id = 'wait_' + form;
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {

                // alert(http_request.responseText);

				// indicate http response complete (stop waiting...)
				document.getElementById(div_id).innerHTML = "";
				document.getElementById(div_id).style.display = "none";

				var update = http_request.responseText;
                functionObj.callBackFunction(update,form);

            } else {
                alert('ERROR: AJAX request status = ' + http_request.status);
            }
        }else{
		// indicate http response incomplete (start waiting...)
		document.getElementById(div_id).innerHTML = "<div align='right'><img src='http://www.queensland.info/includes/forms/loader.gif' width='32' height='32' hspace='15' vspace='15'/></div>";
		}
	}
}