////////////////////////////////////////////////////////////////////
CMXMLHttpRequest = function(useEncoding) {
	this.status		  	= null;
	this.statusText	  	= null;
	this.responseText 	= null;
	this.responseXML  	= null;
	this.useEncoding	= useEncoding;

	var topWnd = getTopWindow();

	if (typeof(topWnd.varContainer._domImpl_) == "undefined") {
		if (topWnd.g_clientCheck.isIE4up) {
			this._req = new ActiveXObject("Msxml2.XMLHTTP");
		} else if (topWnd.g_clientCheck.isMoz0up) {
			this._req = new XMLHttpRequest();
		} else {
			this._req = new Packages.XMLHttpRequest();
		}
	} else {
		if (topWnd.varContainer._domImpl_.startsWith("MSXML")) {
			var progId = "Msxml2.XMLHTTP";
			if (topWnd.varContainer._domImpl_ == "MSXML4")
				progId += ".4.0";
			else if (topWnd.varContainer._domImpl_ == "MSXML3")
				progId += ".3.0";
			this._req = new ActiveXObject(progId);
		} else if (topWnd.varContainer._domImpl_ == "MOZ") {
			this._req = new XMLHttpRequest();
		} else {
			this._req = new Packages.XMLHttpRequest();
		}
	}
}

CMXMLHttpRequest.prototype.open = function(method, url, skipCacheControl) {
// alert(this._req.open)
	skipCacheControl = skipCacheControl === true;
	this._url = url;
	this._req.open(method, CMDOMUtil.buildURL(url, this.useEncoding, skipCacheControl), false);
	var topWnd = getTopWindow();
	if (!topWnd.g_clientCheck.isIE4up && !topWnd.g_clientCheck.isMoz0up)
		this._req.cookie = document.cookie;
}

CMXMLHttpRequest.prototype.send = function(body) {
	var toSend = body;

	if (typeof(body) != "undefined" && body) {
		if (typeof(body) == "object") {
			if (body.MODULE_NAME == "CMDOMDocumentMS") {
				toSend = body.msDocument;
			} else if (body.MODULE_NAME == "CMDOMDocumentMoz" || body.MODULE_NAME == "CMDOMDocument") {
				toSend = body.toString();
			}
		}
	}

	this._req.send(toSend);

	if (this._req.status == 403 && this._url.indexOf("/servlet/Invalidate") == -1) {
		if(typeof(showSessionInvalidMsg) == "function") {
			showSessionInvalidMsg();
		}
	}

	try {
		this.status 		= this._req.status;
		this.statusText 	= this._req.statusText
		this.responseText 	= this._req.responseText;
		this.responseXML 	= this._req.responseXML;
	} catch(e) {
		this.status 		= 400;
	}
}

CMXMLHttpRequest.prototype.setRequestHeader = function(header, value) {
	this._req.setRequestHeader(header, value);
}

// Sendet einen Request an die URL und liefert das Resultat zurueck,
// falls Status=200, sonst null
CMXMLHttpRequest.sendRequest = function(url) {
	var req = new CMXMLHttpRequest();
	req.open("GET", url);
	req.send(null);
	if (req.status==200)
		return req.responseText;
	return null;
}

// Sendet einen Request an die URL und liefert das Resultat zurueck,
// falls Status=200, sonst null
CMXMLHttpRequest.getXML = function(url) {
	var parser = new CMDOMParser();
	return parser.load(url);
	return null;
}

////////////////////////////////////////////////////////////////////
CMForm = function() {
	this.method	  = "GET";
	this.action   = "";
	this.elements = new Array();
}

CMForm.prototype.setElement = function(name, value) {
	if (typeof(this.elements[name]) == "undefined") {
		this.elements[name] = new Array();
	}

	Array.push(this.elements[name], value);
	//this.elements[name][this.elements[name].length] = value;
}

CMForm.prototype.copyForm = function(theForm, doCorrect) {
	if (!theForm)
		return;

	this.method = theForm.method;

	if (typeof(theForm.action) == "object") {
		this.action = theForm.getAttributeNode("action").nodeValue;
	} else {
		this.action = theForm.action;
	}

	for (var i=0; i < theForm.elements.length; i++) {
		var currentElement = theForm.elements[i];
		//only set enabled fields
		if(!currentElement.disabled) {
			if (doCorrect) {
				if (currentElement.type == "radio" || currentElement.type == "checkbox") {
					if (currentElement.checked) {
						this.setElement(currentElement.name, currentElement.value);
					}
				} else {
					this.setElement(currentElement.name, currentElement.value);
				}
			} else {
				this.setElement(currentElement.name, currentElement.value);
			}
		}
	}
}

CMForm.prototype._getUrl = function() {
	var url = this.action;
	if (this.method.toLowerCase() != "post") {
		var sep='?';
		if (url.indexOf('?') >= 0)
			sep='&';

		var name;
		var value;

		for (name in this.elements) {
			value = Array.shift(this.elements[name]);

			while (value != null) {
				url += sep + name + "=" + jencode(value);

				sep='&';
				value = Array.shift(this.elements[name]);
			}
		}
	}

	return url;
}

CMForm.prototype._getBody = function() {
	var body = "";
	if (this.method.toLowerCase() == "post") {
		var cc = 0;

		var name;
		var value;

		for (name in this.elements) {
			value = Array.shift(this.elements[name]);

			while (value != null) {
				if (cc>0)
					body+="&";

				body += name + "=" + jencode(value);

				cc++;
				value = Array.shift(this.elements[name]);
			}
		}
	}
	return body;
}

CMForm.prototype.submit = function() {
	var req 	= new CMXMLHttpRequest();
	var url 	= this._getUrl();
	var body	= this._getBody();

	req.open(this.method, url);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	req.send(body);

	if (req.status == 200)
		return req.responseText;
	else
		return null;
}

//------------------------------------------------------------------------------
//	Simuliert java.net.URLDecoder.encode()
//function _jencode(s) {
//	s = encodeURL(s);
//	return s.replace(/\+/g, "%2B").replace(/%20/g, "\+");
//}
//------------------------------------------------------------------------------

