// JavaScript Document
/** A AJAXConnection class  */
function AJAXConnection(name) {    
    this.className = 'AJAXConnection';
    //alert(this.className + ' ' + name);
    
    /** Default construtor
     *
     * name - div name
     */
    {    
        this.name = name;
    }

    this.xmlhttpPost = function (strURL, functionObj) {
        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); 
        };
        self.xmlHttpReq.send("");
    }
    
    _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 {
                alert('ERROR: AJAX request status = ' + http_request.status);
            }
        }
	}
}
/** A AlertTemplate class */
function AlertTemplate() {	
    this.className = 'AlertTemplate';
    
    /** Call Back Function - called by AJAXAdaptor
     *
     * str - string from XMLHttpRequest
     */    
    this.callBackFunction = function(str) {
        alert(str)
    }    
}

/** A WindowTemplate class */
function WindowTemplate() {	
    this.className = 'WindowTemplate';
    
    /** Call Back Function - called by AJAXAdaptor
     *
     * str - string from XMLHttpRequest
     */    
    this.callBackFunction = function(str) {
        myWindow = window.open("", "tinyWindow", 'toolbar,width=150,height=100')
        myWindow.document.write(str)
        myWindow.document.close() 
    }    
}
/** A DivTemplate class */
function DivTemplate(sid) {
	this.className = 'DivTemplate';
	
	/** Call Back Function - called by AJAXAdaptor
	 *
	 * str - string from XMLHttpRequest
	 */
	 this.elementID = sid;
	 this.callBackFunction = function(str){
		 document.getElementById(this.elementID).innerHTML = str;
	 }
}