/************************  http  *******************************/
/**
 @constructor
 @author:
 @version: 27-01-05
*/
httpClass = function () {
	this.requests = new Object ();
	this.counter = -1; // I wanna start at 0, so I put this at -1 and start with a ++this.counter

	this.xmlObjects = new Object ();
	this.counter = -1; // I wanna start at 0, so I put this at -1 and start with a ++this.counter

//	this.debug = debug.newWin;
	this.debug = false;
	
	this.async = true;

	if (document.location.protocol == 'file:')
		this.filemode = true;
	else
		this.filemode = false;

//	this.usejsurl = false;
}

httpClass.prototype.abort = function () {
	if (typeof http == 'undefined')
		return true;

	var counter = false;
	if (typeof arguments [0] == 'number') {
		if (this.debug)
			this.debug ('delResp: ' + arguments [0]);

		counter = arguments [0];
	}

        if (typeof arguments [0] == 'object' || typeof arguments [0] == 'function') {
		if (typeof arguments [0].counter != 'undefined') {
                	if (this.debug)
				this.debug ('abort: ' + arguments [0].counter);

	 		counter = arguments [0].counter;
		}
        }

	if (counter === false)
		return true;

	try {
		this.xmlObjects [counter].onreadystatechange = function () {};
	} catch (e) {
		if (http.debug)
			http.debug ('failed to set to empty function');
	}
	try {
		this.xmlObjects [counter].abort ();
	} catch (e) {
		if (http.debug)
			http.debug ('failed to set abort request');
	}

	return http.delResp (counter);
}

httpClass.prototype.newReqWithoutSession = function (url, async) {
	var counter = ++http.counter; // counter, like the httpObjects, needs to unique
	
	this.requests [counter] = new this.request (counter, url, async);
	this.requests [counter].debug = http.debug;

	return (this.requests [counter]);
}

httpClass.prototype.newReq = function (url, async) {
	url = createUrlWithSession(url);

	return this.newReqWithoutSession (url, async);
}

httpClass.prototype.nonCacheReq = function (url, async) {
	return http.newReq (url + (/\?/.test (url)?'&':'?') +'ts'+new Date ().getTime ()+'=0', async);
}

httpClass.prototype.delResp = function (arg1) {
	if (typeof arg1 == 'number') {
		if (this.debug)
			this.debug ('delResp: ' + arg1);

		if (typeof this.requests [arg1] != 'undefined') {
//			this.requests [arguments [0]] = false;
			if (http.xmlObjects [this.requests [arg1].counter] !== false) {
				http.xmlObjects [this.requests [arg1].counter] = false;
				delete http.xmlObjects [this.requests [arg1].counter];
			}
			delete this.requests [arg1];
		}
	}

	if (typeof arg1 == 'object' || typeof arg1 == 'function') {
		if (this.debug)
			this.debug ('delResp: ' + arg1.counter);

		if (typeof this.requests [arg1.counter] != 'undefined') {
			this.requests [arg1.counter] = false;
			if (http.xmlObjects [arg1.counter] !== false) {
				http.xmlObjects [arg1.counter] = false;
				delete http.xmlObjects [arg1.counter];
			}
			delete this.requests [arg1.counter];
		}
	}
}

/*
httpClass.prototype.make_fullurl = function (url) {
	if (url.indexOf ('://') >= 0) { // found
		// problably already is a full url
	} else {
		if (url.substr (0, 1) == '/') { // starts with /
			url = location.protocol + '//' + location.host + url;
		} else {
			url = location.protocol + '//' + location.host + location.pathname.substring(0,location.pathname.lastIndexOf('/')) + '/'+url;
		}
	}

	return (url);
}
*/

/************************  http.request  *******************************/

httpClass.prototype.request = function (counter, url, async) {
	this.url = url; // http.make_fullurl (url);
	this.counter = counter;
	this.responseObject = new Object();
	this.data = null;
	this.async = http.async;
	this.method = 'GET';
	this.callback = false;
	this.timeout = false; //no timeout handling...
	this.headers = new Array ();
	this.auth = false;

	if (typeof async != 'undefined')
		this.async = async;

	var myObj = this;

/// old create-requestObject-code-location

	this.myreadystatechange = function () {
		// [LB]
		// in Mozilla:	'this' is the function (which was usefull)
		// in IE:	'this' is document (which is useless)
		// but I am inside the scope of the request object somehow and myObj is unique
		// it's strange, but I'm starting to understand, little, by little

		if (typeof myObj != 'undefined' && http.xmlObjects [myObj.counter]) {
//			leeninspect (myObj.url + ': ' + myObj.xmlhttp.readyState);
//			debug.out (myObj.url + ' ; ' + http.xmlObjects [myObj.counter].status);
//			debug.out (myObj.url + ' ; ' + http.xmlObjects [myObj.counter].readyState);
			if (http.xmlObjects [myObj.counter].readyState == 4) {
				http.xmlObjects [myObj.counter].onreadystatechange = function () {};

//				if (myObj.typecomobject != 'Opera')
//				if (http.compat.hasFeature ('httpheaders'))

				if (typeof http.xmlObjects [myObj.counter].getResponseHeader != 'undefined')
					myObj.responseObject.contenttype 	= http.xmlObjects [myObj.counter].getResponseHeader('Content-Type');

				myObj.responseObject.url 				= myObj.url;
				myObj.responseObject.status				= http.xmlObjects [myObj.counter].status;
				myObj.responseObject.statustext 		= http.xmlObjects [myObj.counter].statusText;

				try {
					var type = typeof http.xmlObjects [myObj.counter].responseText;
				} catch (e) {
					var type = false;
				}

				if (type == 'string') {
					myObj.responseObject.responsetext		= http.xmlObjects [myObj.counter].responseText;// unescape(loader.xmlhttp.responseText);

					if (typeof http.xmlObjects [myObj.counter].responseXML == 'undefined')
						myObj.responseObject.responsexml	= false;
					else
						myObj.responseObject.responsexml	= http.xmlObjects [myObj.counter].responseXML;
				} else {
					myObj.responseObject.responsexml = false;
					myObj.responseObject.responsetext = http.xmlObjects [myObj.counter].responseBody;
				}

				if (myObj.debug)
					myObj.debug ('response ('+myObj.counter+') '+myObj.responseObject.status+' '+myObj.responseObject.statustext+''); //+': '+myObj.responseObject.responsetext);
//					myObj.debug ('response ('+myObj.counter+') '+myObj.responseObject.status+' '+myObj.responseObject.statustext+"\n" + myObj.responseObject.responsetext);

				if (typeof myObj.callback == 'function') {
					myObj.callback (myObj);
				} else {
					if (typeof myObj.callback == 'object') {
						if (typeof myObj.callback.addArg == 'function') {
							myObj.callback.addArg (myObj);
							done (myObj.callback);
						}
					}
				}
			}
		}
	}
}

httpClass.prototype.request.prototype.addHeader = function (var1, var2) {
	this.headers [this.headers.length] = {'name':var1,'data':var2};
}

httpClass.prototype.request.prototype.abort = function () {
	http.abort (this.counter);
}

httpClass.prototype.request.prototype.doRequest = function () {
	var myObj = this;
	// needs to goto compat-section ?:

	if (window.opera) { // Opera
		this.typecomobject = 'Opera';
		http.typecomobject = 'Opera';
		http.xmlObjects [this.counter] = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // probably IE
		
		var xmlarr = new Array ('MSXML2.XMLHTTP.4.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP');
		var bool = true;

		var i = 0;

		while (bool) {
			this.typecomobject = xmlarr [i];
			http.typecomobject = xmlarr [i];
			try {
				http.xmlObjects [this.counter] = new ActiveXObject (this.typecomobject);
				bool = false;
			} catch (e) {
//				if (!http.xmlObjects [this.counter])
					bool = true;
			}
			i++;
			if (xmlarr.length <= i)
				bool = false;
		}
	} else{
		this.typecomobject = 'Gecko-engine';
		http.typecomobject = 'Gecko-engine';
		http.xmlObjects [this.counter] = new XMLHttpRequest();
	}

	http.xmlObjects [this.counter] = http.compat.request ();

//	debug.docWrite ('XMLHTTP-system: '+this.typecomobject);

	if (this.timeout != false && this.timeout > 0) {
		this._timeout = function () {
			if (http.xmlObjects [myObj.counter].readyState != 4) {
				if (myObj.debug)
					myObj.debug ('timeout: '+myObj.url);

				http.xmlObjects [myObj.counter].onreadystatechange = function () {};
				http.xmlObjects [myObj.counter] = null;
				myObj.responseObject = false;
				if (typeof myObj.callback == 'function')
					myObj.callback (myObj);
				else
					if (typeof myObj.callback == 'object') {
						if (typeof myObj.callback.addArg == 'function') {
							myObj.callback.addArg (myObj);
							done (myObj.callback);
						}
					}
			}
		}
	}

	if (this.async == true) {
		if (window.navigator.userAgent.indexOf ('Firefox/3.5') !== -1) { // temporary workaround for Firebug/Firefox XHR-timing-bug
		    http.xmlObjects [myObj.counter].onload = http.xmlObjects [myObj.counter].onerror = http.xmlObjects [myObj.counter].onabort = this.myreadystatechange;
		} else
			http.xmlObjects [myObj.counter].onreadystatechange = this.myreadystatechange;
	}

	try {
		if (this.debug) {
			if (this.data)
				this.debug ('request ('+this.counter+': '+this.method+' '+this.url+'): '+this.data.toString ());
			else
				this.debug ('request ('+this.counter+': '+this.method+' '+this.url+')');
		}

//		leeninspect ('xmlhttp.open (this.method, this.url): ' + this.method + ', ' + this.url + ', ' + this.async);

//		debug.out (myObj.url + ' ; open');
		if (this.auth !== false && typeof this.auth.user != 'undefined' && typeof this.auth.pass != 'undefined')
			http.xmlObjects [myObj.counter].open(this.method, this.url, this.async, this.auth.user, this.auth.pass);
		else
			http.xmlObjects [myObj.counter].open(this.method, this.url, this.async);

		if (this.async == true && this.timeout > 0) {
			if (this.debug)
				this.debug ('setting timeout ('+this.timeout+'): '+this.url);

			window.setTimeout (this._timeout, this.timeout);
		}

		for (var i = 0; i < this.headers.length; i++)
			http.xmlObjects [myObj.counter].setRequestHeader (this.headers [i]['name'], this.headers [i]['data']);

//		debug.out (myObj.url + ' ; send');
		http.xmlObjects [myObj.counter].send(this.data);

//		leeninspect ('after-send');
	} catch (e) {
/*	    debug.docWrite ("typeof e is: " + typeof e)
	    debug.docWrite ("e is: " + e)
	    debug.docWrite ("e.number is: " + (e.number & 0xFFFF));
	    debug.docWrite ("e.description is: " + e.description);
	    debug.docWrite ("e.name is: " + e.name);
	    debug.docWrite ("e.message is: " + e.message);
*/
		this.error = 'http-error, loading URL: '+this.url;
		this.httperror = e;
	}
	if (this.async == false)
		this.myreadystatechange ();

	return true;
}

httpClass.prototype.request.prototype.get = function () {
	this.method = 'GET';
	this.data = null;
	return this.doRequest ();
}

httpClass.prototype.request.prototype.post = function (data) {
	this.method = 'POST';
	if (data != '' && data != undefined) {
		this.data = data;
		this.method = 'POST';
	} else
		return (false);

	return this.doRequest ();
}

httpClass.prototype.compat = {
	request:function () {
		var obj = http.compat.gues_xmlhttp_activex_object ();
		if (obj !== false)
			return obj;

		try {
			return new XMLHttpRequest ();
		} catch (e) {
			return false;
		}
	},
	xmldoc:function () {
		if (typeof document.implementation == 'undefined' || typeof document.implementation.createDocument == 'undefined') {
			var retval = http.compat.gues_xmlhttp_activex_object (false);
			if (retval === false)
				return false;

			try {
				return new ActiveXObject (http.compat.xmldocactivex [0]);
			} catch (e) {
				return false;
			}

			return obj;
		} else
			return document.implementation.createDocument ("", "", null);
	},
	hashttpheaders:function () {
		return !(typeof XMLHttpRequest !== 'undefined' && window.opera)
	},
	hasFeature:function (feature, version) {
		if (typeof feature != 'string')
			return false;

		feature = feature.toLowerCase ();

		if (typeof http.compat ['has'+feature] == 'boolean')
			return http.compat ['has'+feature];

		if (typeof http.compat ['has'+feature] == 'function')
			return http.compat ['has'+feature] = http.compat ['has'+feature] (version);

		return false;
	},
	gues_xmlhttp_activex_object:function (needObj) {
		var obj = false;

		if (typeof ActiveXObject == 'undefined')
			return false;

		if (needObj === false && http.compat.httpactivex.length == 1)
			return true;

		for (var i = 0; i < http.compat.httpactivex.length; i++) {
			var typename = http.compat.httpactivex [i];
			try {
				obj = new ActiveXObject (typename);

				if (http.compat.httpactivex.length != 1) {
					http.compat.httpactivex = [typename];
					http.compat.xmldocactivex = [http.compat.xmldocactivex [i]];
				}

				return obj;

			} catch (e) { obj = false }
		}

		return false;
	},
	httpactivex:['MSXML2.XMLHTTP.4.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'],
// "Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0"
	xmldocactivex:['MSXML2.DOMDocument.4.0','MSXML2.DOMDocument','Microsoft.XMLDOM']
};

var http = new httpClass ();

/************************ httpSet ***********************/

httpClass.prototype.setCounter = -1;

httpClass.prototype.Set = function () {
	var listItem = ++this.setCounterlistItem;
	return (this.list [listItem]);
}

/**
 @constructor
 @author:
 @version: 27-01-05
*/
httpSetClass = function () {
	this.counter = -1;
	this.list = new Object ();
	this.setlist = new Object ();
	this.progress = false;
}

httpSetClass.prototype = new httpClass ();

httpSetClass.prototype.tryLoaded = function (name) {
	var listItem = escape (name);

	if (typeof this.list [listItem] != 'undefined' && this.list [listItem].tryloaded == true)
		return true
	else
		return false;
}

// Leen: not sure, but I think following function is old and obsolute, possible buggy:

httpSetClass.prototype.hasLoaded = function (name) {
	var listItem = escape (name);

	if (typeof this.list [listItem] != 'undefined' && this.list [listItem].loaded == true)
		return true
	else
		return false;
}

httpSetClass.prototype.makeUrl = function (name) {
	return name;
}

httpSetClass.prototype.load = function (name) {
	var url = this.makeUrl (name);

	return this._load (escape (name));
}

httpSetClass.prototype._load = function (name) {
	this.registerLoaded (this.list [name].url, false);

	this.list [name].obj = http.newReqWithoutSession (this.list [name].url);
	var myObj = this;
	this.list [name].obj.callback = this.loaded;

//	debug.out ('_load: ' + this.list [name].url);

	this.list [name].obj.get ();
	return true;
}

httpSetClass.prototype.loadSet = function (names, callback, alwaysCallCallBack) {
	if (alwaysCallCallBack !== true)
		alwaysCallCallBack = false;

	var listItems = new Object ();
	var tempArr = new Array ();
	var count = 0;
	var setExists = false;

//	if (typeof names != 'object')
//		names = {};

	// create the loadSet
	for (var el in names)
		if (typeof names [el] == 'string') {
			listItems [el] = this.createItem (names [el]);
			var tempCounter = this.list [listItems [el]].counter;
			tempArr [tempArr.length] = tempCounter;
			count++;
		}

	// create setName
	var setName = this.makeSetName (tempArr);

	if (typeof this.setlist [setName] == 'undefined') {
		this.setlist [setName] = new Object ();
		this.setlist [setName].callback = new Array ();

		if (this.progress) {
			var progress = this.progress;
			this.setlist [setName].progress = this.progress;
			this.setlist [setName].callback [this.setlist [setName].callback.length] = function () { progress.remove.apply (progress) };
		}

		this.setlist [setName].list = new Array ();
		this.setlist [setName].loadCount = 0;
		this.setlist [setName].setDone = new Array ();
	} else
		setExists = true;

	this.setlist [setName].length = count;

	if (count != 0) {
		// removed this, not needed, maybe we should initialize the progress-object of the set though...?
/*		if (this.progress) {
			debug.newWinAlways ('in httpSet.loadSet : this.progress : ' + this.progress.id);
			this.progress.init.apply (this.progress);
		}
*/
		if (setExists === false) 
			for (var el in listItems)
				if (typeof listItems [el] != 'function') {
					this.setlist [setName].list [this.setlist [setName].list.length] = listItems [el];

					if (!this.list [listItems [el]].sets)
						this.list [listItems [el]].sets = new Array ();

					this.list [listItems [el]].sets [this.list [listItems [el]].sets.length] = setName;
				}

		var whereNotDone = new Array ();
		for (var el in listItems)
			if (typeof listItems [el] != 'function') {
				if (!this.hasLoaded (this.list [listItems [el]].url)) {
					whereNotDone [whereNotDone.length] = el;
				}
			}

		if (typeof this.setlist [setName].setDone == 'undefined') {
			this.setlist [setName].setDone = new Array ();
		}

		this.setlist [setName].setDone [this.setlist [setName].setDone.length] = callback;

		if (this.setlist [setName].progress)
			this.setlist [setName].progress.set.apply (this.setlist [setName].progress, new Array (this.setlist [setName].list.length*2, this.setlist [setName].list.length ));

		if (whereNotDone.length > 0) { /// we used to forget a lot of callbacks here...
			for (var i = 0; i < whereNotDone.length; i ++) {
				if (!this.tryLoaded (this.list [listItems [ whereNotDone [i] ]].url))
					this.load (this.list [listItems [ whereNotDone [i] ]].url);
			}
		} else {
			var calls = this.setlist [setName].callback;
			this.setlist [setName].callback = false;

			for (var j = 0; j < calls.length; j++){
				switch(typeof calls [j]){
					case "function":
						calls [j] ();
						break;
					case "object":
						done(calls [j]);
						break;
				}
			}

			if (alwaysCallCallBack === true) {
				for (var k=0; k < this.setlist [setName].setDone.length; k++) {
					if (typeof this.setlist [setName].setDone [k] == 'function') {
						this.setlist [setName].setDone [k] (true);
					} else {
						if (typeof this.setlist [setName].setDone [k] == 'object') {
							done (this.setlist [setName].setDone [k]);
						}
					}
				}
			}
			delete this.setlist [setName].setDone;
		}
	} else {
		if (alwaysCallCallBack === true && typeof callback == 'function')
			callback ();
			
	}
	return true;
}

httpSetClass.prototype.makeSetName = function (numberArray) {
	/*
		sort by number and then add _'s to it, then you have a proper name,
			you can check up on, that's always the same.
	*/

	numberArray.sort(this._helper_sortNumeric);
	var str = '';

	for (var i = 0; i < numberArray.length; i++) {
		if (str.length == 0)
			str = numberArray [i];
		else
			str = str + '_' + numberArray [i];
	}
	return str;
}

httpSetClass.prototype._helper_sortNumeric = function (a, b) {
	return a - b;
}

httpSetClass.prototype.createItem = function (name) {
	var url = this.makeUrl (name);
	var listItem = escape (url);

	if (typeof httpSet.list [listItem] == 'undefined') {
		httpSet.list [listItem] = new Object;
		httpSet.list [listItem].counter = ++this.counter;
		httpSet.list [listItem].url = name;
	}

	return listItem;
}

httpSetClass.prototype.registerLoaded = function (url, val) {
	listItem = httpSet.createItem (url);

	if (val == false) // try
		httpSet.list [listItem].tryloaded = true;
	else// loaded
		httpSet.list [listItem].loaded = true;
}

httpSetClass.prototype.loaded = function (obj) {
	var responseObj = obj.responseObject;

	httpSet.registerLoaded (responseObj.url, true);

	var url = escape (responseObj.url);
	for (var i = 0; i < httpSet.list [url].sets.length; i++) {
		var setName = httpSet.list [url].sets [i];
		if (typeof httpSet.setlist [setName] != 'undefined') {
			httpSet.setlist [setName].loadCount++;
			if (httpSet.setlist [setName].progress)
				httpSet.setlist [setName].progress.set.apply (httpSet.setlist [setName].progress, new Array (httpSet.setlist [setName].list.length*2, httpSet.setlist [setName].loadCount*2 ));
		}
	}

	if (httpSet.list [url].sets) {
		var retval = httpSet.get_completed (httpSet.list [url].sets);

		if (retval.length > 0) {
			for (var i = 0; i < retval.length; i++) {
				if (typeof httpSet.setlist [retval [i]] == 'object') {
					for (var j = 0; j < httpSet.setlist [retval [i]].list.length; j++) {
						if (typeof httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj != 'undefined') { // needs check: all ready preloaded
							var status = httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject.status;
//							if (status == 200) { // || responseObj.status == 304) { // maybe we want 304 also ?

							if ((!http.filemode && status == 200) || (http.filemode && status == 0)) { // || responseObj.status == 304) { // maybe we want 304 also ?
								if (this.debug)
									this.debug ('new preLoadClass ('+httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject.contenttype+')'); //+': '+httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject.responsetext+')');

								var tmpPreLoad = new preLoadClass (httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject);
								tmpPreLoad = false;
							} else {
								alert ('Failed to load (1?): '+httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject.url);
							}
						}
					}

					var calls = httpSet.setlist [retval [i]].callback;
					httpSet.setlist [retval [i]].callback = false;

					for (var j = 0; j < calls.length; j++) {
						calls [j] ();
					}

					if (typeof debug != 'undefined' && typeof debug.out != 'undefined')
						debug.out ('loaded: ' + url);

					if (typeof httpSet.setlist [retval [i]].setDone !== "undefined"){
						if (httpSet.setlist [retval [i]].setDone.length > 0) {
							for (var k=0; k < httpSet.setlist [retval [i]].setDone.length; k++) {
								if (typeof httpSet.setlist [retval [i]].setDone [k] == 'function')
									httpSet.setlist [retval [i]].setDone [k] (true);
								else
									if (typeof httpSet.setlist [retval [i]].setDone [k] == 'object')
										done (httpSet.setlist [retval [i]].setDone [k]);

							}
						}
						delete httpSet.setlist [retval [i]].setDone;
					} else {
						if (typeof debug != 'undefined' && typeof debug.out != 'undefined')
							debug.out ('loaded: !! error !!');
						//alert("error!: " + url);
					}
					// remove the set
					for (var j = 0; j < httpSet.setlist [retval [i]].list.length; j++) {
						// don't delete the response if it's already been deleted !:
						if (typeof httpSet.list [ httpSet.setlist [retval [i]].list [j] ] != 'undefined') {

							if (typeof httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj != 'undefined') {
								if (typeof httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject != 'undefined')
									delete httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.responseObject;

								http.delResp (httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj.counter);

								delete httpSet.list [ httpSet.setlist [retval [i]].list [j] ].obj;
							}
							delete httpSet.list [ httpSet.setlist [retval [i]].list [j] ].sets;
//							delete httpSet.list [ httpSet.setlist [retval [i]].list [j] ]; // not needed: because there is information kept there...
						}
						delete httpSet.setlist [retval [i]].list [j].calls;
//						delete httpSet.setlist [retval [i]].list [j]; // not needed: because there is information kept there...
					}
				}
			}
		}
	}
}

httpSetClass.prototype.get_completed = function (sets) {
	var retval = new Array ();

	for (var i = 0; i < sets.length; i++) {
		var setName = sets [i];
		if (typeof httpSet.setlist [setName] != 'undefined') {
			var allBool = true;
			for (var j = 0; j < httpSet.setlist [setName].list.length; j++)
				if (typeof httpSet.list [httpSet.setlist [setName].list[j]] != 'undefined')
					if (httpSet.list [httpSet.setlist [setName].list[j]].loaded != true)
						allBool = false;

			if (allBool)
				retval [retval.length] = setName;
		}
	}

	return retval;
}

var httpSet = new httpSetClass ();

/**************************** preLoader ************************************/

/*
	example:
		var tmpPreLoad = new preLoadClass (httpResponseObject);
//old		tmpPreLoad = false; // I prefered undefined, but it doesn't work always, so I stopped using it.
		delete tmpPreLoad; // I prefered undefined, but it doesn't work always, so I stopped using it.
*/

preLoadClass = function (responseObj) {
	if (typeof responseObj == 'object') {
		this.responseObj = responseObj;
		var type = this.typeSwitch ();

		if (type === false) {
			alert ('preLoadClass: unknown type for: ' + responseObj.url);
			return false;
		}

		var str = type+'Handler';

		if (typeof this [str] == 'function') {
			this [str] ();
		} else {
			alert ('unknown preLoad-handler: '+type);
			return false;
		}
	} else {
		alert ("not a proper httpResponseObject passed to the preLoadClass");
		return false;
	}
}

// The switch for determining what type a preloaded file is...
preLoadClass.prototype.typeSwitch = function () {
	if (http.filemode) {
		var url = this.responseObj.url;
		var ext = this.url2ext (url);
		return this.ext2type (ext);
	} else {
		var contenttype = this.responseObj.contenttype || '';

		contenttype = contenttype.toLowerCase()
			
		switch (contenttype) {
		case 'application/x-javascript':
			return 'javaScript';

		case 'text/css':
			return 'styleSheet';

		default:
			if (contenttype.slice(0,5) == 'image')
				return 'image';
			else { // an other switch checking on extension in the URL ??
				var url = this.responseObj.url;
				var ext = this.url2ext (url);
				// if we get here we still don't know
				return this.ext2type (ext);
			}
		}
	}
}

preLoadClass.prototype.url2ext = function (url) {
	var idx = url.indexOf ('?');
	if (idx != -1) {
		if (idx == 0)
			return (false);
		url = url.slice (0, idx);
	}

	var idx = url.lastIndexOf ('.');
	if (idx == -1)
		return false;
	if (idx == 0 || url.length == idx)
		return false;

	return url.slice (idx+1, url.length);
}

preLoadClass.prototype.ext2type = function (ext) {
	if (typeof ext != 'string')
		return false;

	switch (ext.toLowerCase ()) {
	case 'js':
		return 'javaScript';
	case 'css':
		return 'styleSheet';
	case 'bmp':
	case 'png':
	case 'gif':
	case 'jpg':
	case 'jpeg':
		return 'image';
	default:
		return false;
	}
}

preLoadClass.prototype.javaScriptHandler = function (scriptText) {

	if (arguments.length == 0) {
		var scriptText = this.responseObj.responsetext;
		var url = this.responseObj.url;
	}

	try {
		if(scriptText !== "") {
//			if (http.usejsurl)
//				window.execScriptURL (url);
//			else
				window.execScript (scriptText);
		}
	} catch (e) {
		alert ("javaScriptHandler caught an exception: " + e.message);
	}
}

preLoadClass.prototype.imageHandler = function () {
	// euh... it's cached now ?
	var img = new Image('');
	img.src = this.responseObj.url;
}

preLoadClass.prototype.styleSheetHandler = function (cssRules, id) {
//	debug.out ('styleSheetHandler');

	if (arguments.length == 0)
		cssRules = this.responseObj.responsetext;
/*
	if (document.styleSheets.length == 0) { // IE needs atleast one STYLE-element in the document
		var el = document.createElement ('STYLE');
		document.documentElement.appendChild (el);
	}

	if (typeof document.styleSheets [document.styleSheets.length-1].cssText != 'undefined')
		document.styleSheets [document.styleSheets.length-1].cssText = cssRules;
	else {
		if (!el) { // for Mozilla we just add a STYLE-tag for each set style rules
			var el = document.createElement ('STYLE');
			document.documentElement.appendChild (el);
		}
		el.innerHTML = cssRules;
	}
*/


//	it's better to connect it to the HEAD-tag

/*
	var head = document.getElementById ('headtag');

	if (head === null)
*/		
/*	else
		head.appendChild (el);
*/
	var el = document.createElement ('STYLE');
	
	if (typeof document.styleSheets [document.styleSheets.length-1].cssText != 'undefined'){
		document.documentElement.appendChild (el);
		document.styleSheets [document.styleSheets.length-1].cssText = cssRules;
	}else{
		var pa= document.getElementsByTagName('head')[0];
		el.type= 'text/css';
		el.media= 'screen';
		el.appendChild(document.createTextNode(cssRules));
		pa.appendChild(el);
		//el.innerHTML = cssRules;
		//document.styleSheets [document.styleSheets.length-1].cssText = cssRules;
	}
}

function createUrlWithSession(url){

	//Set the url ofthe page we wanna get
	var str = document.location.search.slice (1, document.location.search.length);

	var sessionid = _getSessionFromUrl(str);

	if (sessionid === false) {
		var anchors = document.getElementsByTagName("A");
		if (typeof anchors !== "undefined" && anchors.length > 0) {
			sessionid = _getSessionFromUrl(anchors[0].href);
		}
	}

	if (sessionid === false) {
		sessionid = getSessionIdFromForms ();
	}
	
	if (sessionid !== false){
		if (url.indexOf("?") === -1){
			url = url + '?sessionid='+sessionid;
		} else {
			url = url + '&sessionid='+sessionid;
		}
	}
	return url;
}

function _getSessionFromUrl(str) {
	if (typeof sessionpageid != 'undefined' && sessionpageid != '')
		return sessionpageid;

	var urlarr = str.split ('&');

	for (var urlarri = 0; urlarri < urlarr.length; urlarri++) {
		var tmp = urlarr[urlarri].split ('=');
		if (tmp [0].toLowerCase () == 'sessionid') {
			return tmp[1];
		}
	}
	return false;
}

function getSessionIdFromForms () {
	for (var i=0; i < document.forms.length; i++) {
		if (typeof document.forms [i].sessionid != 'undefined') {
			if (document.forms [i].sessionid.value != '')
				return document.forms [i].sessionid.value;
		}
	}
	return false;
}


function CDATAencoder(str) {
	if (typeof str == 'string') {
		str = str.replace (/&rsquo;/g, '');
		str = str.replace (/&/g, '&amp;');

		var arr = new Array ();

		var changed = false;

		for (var i = 0; i < str.length; i++) {
			var code = str.charCodeAt (i);

			if (code > 159) {
				changed = true;
				arr [arr.length] = '&#' + code + ';';
			} else
				arr [arr.length] = str.charAt (i);
		}

		str = arr.join ('');
		return str.replace (/</g, '&lt;').replace (/>/g, '&gt;');
	} else
		return str;
}

function CDATAdecoder (str) {
	if (typeof str == 'string') {
		var arr = new Array ();

		var re = /&[0-9][0-9][0-9];/g;

		var tmpStr = str;
		var result = '';

		var pos = tmpStr.search (re);
		while (pos != -1) {
			result = result + tmpStr.slice (0, pos);

			var code = tmpStr.slice (pos, pos+5);

			tmpStr = tmpStr.slice (pos+5, tmpStr.length);
			result = result + String.fromCharCode ( code.charAt (1) + code.charAt (2) + code.charAt (3) );
			pos = tmpStr.search (re);
		}
		result = result + tmpStr;

		return result.replace (/&lt;/, '<').replace (/&gt;/, '>').replace (/&amp;/, '&');
	} else
		return str;
}

