function doMenuLink(ContentId) {
	window.location.href = "?ContentId=" + ContentId;
}

var id = new String();
var cookies = document.cookie;
var arrCookies = new Array();
arrCookies = cookies.split(";");
for (var i = 0; i < arrCookies.length; i++) {
	var arrCookie = new Array();
	arrCookie = arrCookies[i].toString().split("=");
	if (arrCookie[0] && arrCookie[0].toString().indexOf("ASPSESSION") > -1) {
		id = arrCookie[1].toString();
		break;
	}
}

var stickyNameOrg = new String("Dein Name");
var stickyTextOrg = new String("Deine Nachricht");

function clearField(oThis) {
	if (oThis.id == "stickyName") {
		if (oThis.value == stickyNameOrg) { oThis.value = ""; }
	}
	if (oThis.id == "stickyText") {
		if (oThis.value == stickyTextOrg) { oThis.value = ""; }
	}	
}

function writeSticky() {
	var stickyName = new String(document.getElementById("stickyName").value);
	if (stickyName.length == 0 || stickyName.indexOf(stickyNameOrg) > -1 ) {
		showMessage("Sticky", "Bitte gib Deinen Namen ein.");
		document.getElementById("stickyName").value = stickyNameOrg;
		return false;	
	}
	var stickyText = new String(document.getElementById("stickyText").value);
	if (stickyText.length == 0 || stickyText.indexOf(stickyTextOrg) > -1) {
		showMessage("Sticky", "Bitte gib Deinen Text ein.");
		document.getElementById("stickyText").value = stickyTextOrg;
		return false;
	}

	with (new ajaxSticky()) {
		name = stickyName;
		text = stickyText;
		sId = id;
		onSuccess = _refreshStickyView;
		onError = function(response) { showMessage("Fehler", response); }
		SaveSticky();
	}
}

function _refreshStickyView(response) {
	var counter = new Number(parseInt(response));
	document.getElementById("divSticky").innerHTML = "Sticky... (" + counter + ")";
	if (counter && counter > 0) {
		with (new ajaxSticky()) {
			sId = id;
			onSuccess = function(response) {
				document.getElementById("divStickies").style.display = "block";
				document.getElementById("divStickies").innerHTML = "" + response;
				document.getElementById("stickyName").value = stickyNameOrg;
				document.getElementById("stickyText").value = stickyTextOrg;
			}
			onError = function(response) { showMessage("Fehler", response); }
			getStickies();
		}
	} else {
		document.getElementById("divStickies").style.display = "none";
	}
}

function ajaxSticky() {
	this.url = new String("/vw-fm/includes/ajaxSticky.aspx");
	this.sId = new String();
	this.params = new String();
	this.cmd = new String();
	this.method = new String("GET");
	this.onError = function(msg) { alert("Error!\n\n" + msg); }
	this.ShowMessage = function(msg) { alert("Message:\n\n" + msg); }
	this.onSuccess = successHandler;
	
	this.name = new String();
	this.text = new String();

	function successHandler(txt, xml) {
		// dummy, falls kein eigenes onSuccess angegeben wurde.
		this.ShowMessage(txt);
	}
}
ajaxSticky.prototype.SaveSticky = function() {
	this.cmd = "savesticky";
	if (this.sId.length == 0) {
		this.onError("missing id");
		return false;
	}
	if (this.name.length == 0) {
		this.onError("missing name");
		return false;
	}
	if (this.text.length == 0) {
		this.onError("missing text");
		return false;
	}
	this.params = "cmd=" + this.cmd
		+ "&sId=" + this.sId
		+ "&Name=" + this.name
		+ "&Text=" + this.text;
	var _this = this;
	var xmlHttpRequestSticky = _getXMLHttpRequestForSticky();
	if (!xmlHttpRequestSticky) {
		_this.onError("Es konnte kein xmlHttpRequestForMail-Objekt erstellt werden.");
		return false;
	}
	xmlHttpRequestSticky.open(this.method, this.url + "?" + this.params, true);
	xmlHttpRequestSticky.onreadystatechange = readyStateHandler;
	xmlHttpRequestSticky.setRequestHeader("Pragma", "no-cache");
	xmlHttpRequestSticky.setRequestHeader("Cache-Control", "must-revalidate");
	xmlHttpRequestSticky.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequestSticky.setRequestHeader("If-Modified-Since", document.lastModified);
	xmlHttpRequestSticky.setRequestHeader("Expires", 0);
	xmlHttpRequestSticky.send(null);

	function readyStateHandler() {
		if (xmlHttpRequestSticky.readyState < 4) {
			return false;
		}
		if (xmlHttpRequestSticky.status == 200 || xmlHttpRequestSticky.status == 304) {
			if (_this.onSuccess) {
				var ResponseText = new String();
				var ResponseXml = new String();
				ResponseText = xmlHttpRequestSticky.responseText;
				ResponseXml = xmlHttpRequestSticky.responseXML;

				ResponseText = ResponseText.replace(/\n/g, "");
				ResponseText = ResponseText.replace(/\r/g, "");
				_this.onSuccess(ResponseText, ResponseXml);
			}
		} else {
			if (xmlHttpRequestSticky.status == 404) {
				if (_this.onError) {
					_this.onError("Fehler " + xmlHttpRequestSticky.status + " aufgetreten, Dienst nicht gefunden.")
				}
			}
		}
	}
}
ajaxSticky.prototype.getStickies = function() {
	this.cmd = "getstickies";
	if (this.sId.length == 0) {
		this.onError("missing id");
		return false;
	}
	this.params = "cmd=" + this.cmd + "&sId=" + this.sId;
	var _this = this;
	var xmlHttpRequestSticky = _getXMLHttpRequestForSticky();
	if (!xmlHttpRequestSticky) {
		_this.onError("Es konnte kein xmlHttpRequestForMail-Objekt erstellt werden.");
		return false;
	}
	xmlHttpRequestSticky.open(this.method, this.url + "?" + this.params, true);
	xmlHttpRequestSticky.onreadystatechange = readyStateHandler;
	xmlHttpRequestSticky.setRequestHeader("Pragma", "no-cache");
	xmlHttpRequestSticky.setRequestHeader("Cache-Control", "must-revalidate");
	xmlHttpRequestSticky.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpRequestSticky.setRequestHeader("If-Modified-Since", document.lastModified);
	xmlHttpRequestSticky.setRequestHeader("Expires", 0);
	xmlHttpRequestSticky.send(null);

	function readyStateHandler() {
		if (xmlHttpRequestSticky.readyState < 4) {
			return false;
		}
		if (xmlHttpRequestSticky.status == 200 || xmlHttpRequestSticky.status == 304) {
			if (_this.onSuccess) {
				var ResponseText = new String();
				var ResponseXml = new String();
				ResponseText = xmlHttpRequestSticky.responseText;
				ResponseXml = xmlHttpRequestSticky.responseXML;

				ResponseText = ResponseText.replace(/\n/g, "");
				ResponseText = ResponseText.replace(/\r/g, "");
				_this.onSuccess(ResponseText, ResponseXml);
			}
		} else {
			if (xmlHttpRequestSticky.status == 404) {
				if (_this.onError) {
					_this.onError("Fehler " + xmlHttpRequestSticky.status + " aufgetreten, Dienst nicht gefunden.")
				}
			}
		}
	}
}

function _getXMLHttpRequestForSticky() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var idx = 0; idx < versions.length; idx++) {
			try {
				return new ActiveXObject(versions[idx]);
			} catch (objException) {
				;
			}
		}
	}
}
