// Ajax js osztaly
// (C) BODI ADAM, 2006
function ajaxclass() {

    this.xmlhttp = null;
    
    this.reset = function() {
	 this.onLoading = function() { };
         this.onLoaded = function() { };
         this.onInteractive = function() { };
         this.onCompletion = function() { };
         this.onError = function() { };
         this.onFail = function() { };
         
         this.method = "GET";
         this.status = "";
         this.statusText = "";
         this.element = null;
         this.elementObj = null;
    }
    
    this.createAJAX = function() {
/*@cc_on @*/
/*@if (@_jscript_version >= 5)

    // Explorer
    try {
	this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
	try {
    	    this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
    	    this.xmlhttp = false;
	}
    }
@end @*/

    // Mozilla, Safari
    if (! this.xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
    	    this.xmlhttp = new XMLHttpRequest();
	} catch (e) {
    	    this.xmlhttp = false;
	}
    }

    // Egyeb
    if (! this.xmlhttp && window.createRequest) {
	try {
    	    this.xmlhttp = window.createRequest();
	} catch (e) {
    	    this.xmlhttp = false;
	}
    }
};
    this.run = function(urlstring) {
	this.URLString = urlstring;
	if (! this.xmlhttp) {
	    this.onFail();
	} else {
	    if (this.element)
		this.elementObj = document.getElementById(this.element);
	    if (this.xmlhttp) {
	    
		this.xmlhttp.onreadystatechange = function() {};
		this.xmlhttp.abort();
    
		var self = this;
		this.xmlhttp.open(this.method, this.URLString, true);
		if (this.method == "POST") {
		    try {
			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    } catch (e) { }
		}
		
		this.xmlhttp.onreadystatechange = function() {
		    switch (self.xmlhttp.readyState) {
			case 1: self.onLoading();
			break;
			case 2: self.onLoaded();
			break;
			case 3: self.onInteractive();
			break;
			case 4: self.response = self.xmlhttp.responseText;
				self.status = self.xmlhttp.status;
				self.statusText = self.xmlhttp.statusText;
				if (self.elementObj)
				    self.elementObj.innerHTML = self.response;
				if (self.status == "200") {
				    self.onCompletion();
				} else self.onError();
				self.URLString = "";
			break;
		    }	
		};
		this.xmlhttp.send(this.URLString);
	    }
	    
	}
    
    }
    
    this.reset();
    this.createAJAX();
};
