// $Id: fside.js 30 2008-05-07 11:37:20Z willem $
// Ajax methods: update parts of HTML with results from external scripts

var FSide = function() {
	// init()
	this.init();
}

FSide.prototype.xmlObj = null;

FSide.prototype.init = function() {
	try {
		// Firefox, Opera 8.0+, Safari
		this.xmlObj = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
	    	this.xmlObj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
    		try {
				this.xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	var state = new stateHandler(this);
	
	//state.owner = this;
	this.xmlObj.onreadystatechange = function() {
		// wrap to call object method
		state.handleEvent();
	}
}

var stateHandler = function(owner) {
	this.init(owner);
}
stateHandler.prototype.owner = null;
stateHandler.prototype.debug = false;

stateHandler.prototype.init = function(owner) {
	this.owner = owner;	
}
stateHandler.prototype.handleEvent = function() {
	// called from xmlObj onReadyStateChange
	
	if (this.owner.xmlObj.readyState == 4) {

		if (this.owner.debug)
			alert(this.owner.xmlObj.responseText.substr(0, 255));
		if (this.owner.rewriteTag) {
			var obj = document.getElementById(this.owner.rewriteTag);
			obj.innerHTML = this.owner.xmlObj.responseText;
		}
		if (this.owner.callback)
			eval(this.owner.callback + "()");
	}	
}

