function getPinkieBoxRequestObject() {
	var req = null;
	try {
		req = new XMLHttpRequest();
	}
	catch (ms) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (nonms) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				req = null;
			}
		}
	}
	if (req == null)
		alert("Error creating request object!");
	return req;
}
function initPinkieBox(dest, objId, value) {
	var http = getPinkieBoxRequestObject();
	http.open("GET", window.location.href.substring(0, window.location.href.lastIndexOf("/")) + dest + "?IMAGE=" + encodeURIComponent(value), true);
 	http.onreadystatechange = function() {
 		if (http.readyState == 4)
 			if (http.responseText != "") {
				var response = http.responseText;
 				imageWidth = http.responseText.substr(0, response.indexOf("x"));
 				imageHeight = http.responseText.substr(response.indexOf("x")+1, (response.length - response.indexOf("x") - 1));
				imageHeight = parseInt(imageHeight) + parseInt(40);
				screenWidth = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
				screenHeight = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
				xPos = (screenWidth - imageWidth) * 0.5;
				yPos = (screenHeight - imageHeight) * 0.5;
				document.getElementById(objId).style.width=imageWidth+"px";
				document.getElementById(objId).style.height=imageHeight+"px";
				document.getElementById(objId).style.left=xPos+"px";
				document.getElementById(objId).style.top=yPos+"px";
				document.getElementById(objId+"_close").style.left=(imageWidth-19)+"px";
				document.getElementById(objId+"_close").style.top=(imageHeight-24)+"px";
			}
 	}
	http.send(null);
}
function openPinkieBox(objId, imgSrc) {
	document.getElementById(objId + "_img").src = imgSrc;
	initPinkieBox("/ajax/getPinkieBoxDimension.php", objId, imgSrc);
	document.getElementById('pinkiecurtain').style.visibility = 'visible';
	document.getElementById(objId).style.visibility = 'visible';
}
function closePinkieBox(objId) {
	document.getElementById('pinkiecurtain').style.visibility='hidden';
	document.getElementById(objId).style.visibility='hidden';
}
function MenuOver(obj, mainmenu) {
	obj.style.cursor = "pointer";
	if (mainmenu) {
		obj.style.backgroundImage = "url('images/menuselection.gif')";
		obj.style.backgroundRepeat = "repeat-x";
	}
	else {
		obj.style.backgroundImage = "url('images/menubg.jpg')";
		//obj.style.backgroundRepeat = "repeat-y";
	}
}
function MenuOver(obj) {
	obj.style.cursor = "pointer";
	obj.style.backgroundImage = "url('images/menuselection.gif')";
	obj.style.backgroundRepeat = "repeat-x";
}
function MenuOut(obj) {
	obj.style.backgroundImage = "";
	obj.style.backgroundRepeat = "";
}
function MouseOver(obj) {
	obj.style.cursor = "pointer";
}
function getRequestObject() {
	var req = null;
	try {
		req = new XMLHttpRequest();
	}
	catch (ms) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (nonms) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				req = null;
			}
		}
	}
	if (req == null)
		alert("Error creating request object!");
	return req;
}
function ajaxSetContent(dest, key, value, id) {
	var http = getRequestObject();
	var urlext = "";
	if (id > 0)
		urlext = "&ID=" + id;
	http.open("GET", window.location.href.substring(0, window.location.href.lastIndexOf("/")) + dest + "?" + key + "=" + value + urlext, true);
 	http.onreadystatechange = function() {
 		if (http.readyState == 4)
 			if (http.responseText != "") {
			 	document.getElementById("StoryContainer").innerHTML = http.responseText;
			}
 	}
	http.send(null);
}
function changeTeamImage(objId, maxId, active) {
	var col = objId % 2 == 0 ? 2 : 1;
	var row = col == 1 ? Math.floor(objId / 2) + 1 : objId / 2;
	var active = active ? "_active" : "";
	var active2 = active ? "_active2" : "";
	var lastrow = maxId % 2 == 1 ? Math.floor(maxId / 2) + 1 : maxId / 2;
	if (row < lastrow)
		document.getElementById("Team"+(objId+2)).style.backgroundImage = "url(images/team_r"+(row+1)+"c"+col+active2+".jpg)";		
	document.getElementById("Team"+objId).style.backgroundImage = "url(images/team_r"+row+"c"+col+active+".jpg)";
	document.getElementById("Team"+objId).style.color = active ? "white" : "rgb(23, 32, 60)";
	//alert(document.getElementById("Team"+objId).id + "  url:(images/team_r"+row+"c"+col+active+".jpg)" + lastrow);
}
function select(menuKey, obj) {
	divList = document.getElementsByTagName("div");
	for (var idx = 0; idx < divList.length; idx++) {
		if (divList[idx].className == "MenuEntry")
			divList[idx].style.color = "rgb(189, 203, 216)";
	}
	obj.style.color = "white";
	ajaxSetContent("/contents.php", "KEY", menuKey, 0);
}
function selectTeam(id) {
	select("TEAM", document.getElementById("MenuTEAM"));
	selectItem("TEAM", id);
}
function selectItem(menuKey, id) {
	ajaxSetContent("/contents.php", "KEY", menuKey, id);
}
function openPrintView(address) {
	windowPrintView = window.open(address, "Druckansicht", "width=700,height=600,scrollbars=1,resizable=0");
	windowPrintView.focus();
}

