var reqMenu = null;
var reqContent = null;
var menuHTML = '';
var contentHTML = '';
var contentsChanged = false;
var changingContentsAllowed = true;

//var automaticScrollTimer = null; 
	
function getClientWH() {
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	
	return new Array(x, y);
}

function getWindowWH() {
  var x,y;
  if (self.innerHeight) // all except Explorer  
  {
	  x = self.innerWidth;
	  y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
	  // Explorer 6 Strict Mode
  {
	  x = document.documentElement.clientWidth;
	  y = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
	  x = document.body.clientWidth;
	  y = document.body.clientHeight;
  }
 	return new Array(x, y);
}

function getScrollingWH() {
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{	
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{	
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
 	return new Array(x, y);	
}

function openPopup(url) {
	var win = window.open(url, "popup", "scrollbars=yes,resizable=yes,width=800,height=400,left=100,top=200");
	win.focus();
}

function setWaitCursor() {
	document.body.style.cursor = 'wait';
	var el = document.getElementById('opaqueLayer');
	var arrScroll = getScrollingWH();
	var arrWindow = getWindowWH();
	var arrClient = getClientWH();
	var height = Math.max(arrWindow[1], arrClient[1]);
//	alert(arrSize[0] + ' ' + arrSize[1] + '  ' + arrSize1[0] + ' ' + arrSize1[1] + '   ' + arrSize2[0] + ' ' + arrSize2[1]);
	if (el != null) {
		el.style.height = height + 'px';
		el.style.display = 'block'; 
	}
	el = document.getElementById('opaqueContent');
	if (el != null) {
		var top = (arrWindow[1] - 100) / 2;
		top += arrScroll[1];
		var left = (arrWindow[0] - 400) / 2;
		left += arrScroll[0];		
		if (top < 450) {
			top = 450;
		}
		el.style.top = top + 'px';
		el.style.left = left + 'px';
	}
	return true;
}

function setWaitText() {
	var srcText = '';
	var src = document.getElementById('opaqueContent');
	if (src != null) {
		srcText = src.innerHTML;
	}

	var el = document.getElementById('loadingstatus');
	if (el != null) {
		el.style.display = 'block';
		el.innerHTML = srcText;
	}
}

function setDefaultCursor() {
	document.body.style.cursor = 'default';
	var el = document.getElementById('opaqueLayer');
	if (el != null) {
		el.style.display = 'none';
	}	
}

function processReqChangeMenu() {
	if (reqMenu != null) {
		if (reqMenu.readyState == 4) {
			try {
				if (reqMenu.status == 200) {
					if (reqMenu.responseText != '') {
						menuHTML = reqMenu.responseText;
					}
					else {
						menuHTML = 'error';
					}
				}	
				else {
					menuHTML = 'error';
				}
			}
			catch (e) {
				menuHTML = 'error';
			}
		}
	}
}

function processReqChangeContent() {
	if (reqContent != null) {
		if (reqContent.readyState == 4) {
			try {
				if (reqContent.status == 200) {
					if (reqContent.responseText != '') {
						contentHTML = reqContent.responseText;
					}
					else {
						contentHTML = 'error';
					}
				}	
				else {
					contentHTML = 'error';
				}
			} catch(e) {
				contentHTML = 'error';
			}
		}
	}
}

function setRequestSync(scriptName) {
	closeSurveyLayer();
	
	var url = scriptName;	
	if (window.XMLHttpRequest) {
		var req = new XMLHttpRequest();	
		req.open("GET", url, false);
		try {
			req.send(null);
			return req.responseText;
		}
		catch(e) {
			if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
				alert('Serverskript nicht vorhanden: ' + url);
			}
		}
	} 
	else {
		if (window.ActiveXObject) {
			var req = new ActiveXObject("Microsoft.XMLHTTP");	
			if (req) {
			    req.open("GET", url, false);
				try {
					req.send();
					return req.responseText;	  
				}
				catch(e) {
					if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
						alert('Serverskript nicht vorhanden: ' + url);
					}
				}
			}
		}
	}
}

function setRequestASync(scriptName, callback, reqGen) {
	closeSurveyLayer();

	var url = scriptName;	
	if (window.XMLHttpRequest) {
		reqGen = new XMLHttpRequest();
   		reqGen.onreadystatechange = callback;	
		reqGen.open("GET", url, true);
		try {
			reqGen.send(null);	  
		}
		catch(e) {
			if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
				alert('Serverskript nicht vorhanden: ' + url);
			}
		}
	} 
	else {
		if (window.ActiveXObject) {
			reqGen = new ActiveXObject("Microsoft.XMLHTTP");
    		reqGen.onreadystatechange = callback;	
			if (reqGen) {
			    reqGen.open("GET", url, true);
				try {
					reqGen.send();	  
				}
				catch(e) {
					if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
						alert('Serverskript nicht vorhanden: ' + url);
					}
				}
			}
		}
	}
	return reqGen;
}

function setRequestMenu(scriptName) {
	closeSurveyLayer();
	
	var url = scriptName;	
	if (window.XMLHttpRequest) {
		reqMenu = new XMLHttpRequest();
   		reqMenu.onreadystatechange = processReqChangeMenu;	
		reqMenu.open("GET", url, true);
		try {
			reqMenu.send(null);	  
		}
		catch(e) {
			if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
				alert('Serverskript nicht vorhanden: ' + url);
			}
		}
	} 
	else {
		if (window.ActiveXObject) {
			reqMenu = new ActiveXObject("Microsoft.XMLHTTP");
    		reqMenu.onreadystatechange = processReqChangeMenu;	
			if (reqMenu) {
			    reqMenu.open("GET", url, true);
				try {
					reqMenu.send();	  
				}
				catch(e) {
					if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
						alert('Serverskript nicht vorhanden: ' + url);
					}
				}
			}
		}
	}
}

function setRequestContent(scriptName) {
	closeSurveyLayer();
	
	var url = scriptName;	
	if (window.XMLHttpRequest) {
		reqContent = new XMLHttpRequest();
   		reqContent.onreadystatechange = processReqChangeContent;	
		reqContent.open("GET", url, true);
		try {
			reqContent.send(null);	  
		}
		catch(e) {
			if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
				alert('Serverskript nicht vorhanden: ' + url);
			}
		}
	} 
	else {
		if (window.ActiveXObject) {
			reqContent = new ActiveXObject("Microsoft.XMLHTTP");
    		reqContent.onreadystatechange = processReqChangeContent;	
			if (reqContent) {
			    reqContent.open("GET", url, true);
				try {
					reqContent.send();	  
				}
				catch(e) {
					if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
						alert('Serverskript nicht vorhanden: ' + url);
					}
				}
			}
		}
	}
}

function isIElt7() {
	var browser = navigator.appName; 
	var version=parseFloat(navigator.appVersion);  
	if (browser == 'Microsoft Internet Explorer' && version < 5) {
		if (window.XMLHttpRequest) {
			return false;
		}
		return true;
	}  
	return false;
}

function switchSkin(skinName) {
	
	var e = document.getElementById('skinclass');
	if (e != null) {
		e.className = skinName;
	}
} 

function switchTab(newId) {
	var e;
	e = document.getElementById('tabhead');
	if (e != null) {
		var tabs = e.getElementsByTagName('div');
		for (var i=0; i<tabs.length; i++) {
			if (tabs[i].className == 'tabitemactive') {
				tabs[i].className = 'tabitem';
			}
		}
	}
	e = document.getElementById('tab_' + newId);
	if (e != null) {
		e.className = 'tabitemactive';
	}

	e = document.getElementById('tabcontent');
	if (e != null) {
		var tabs = e.getElementsByTagName('div');
		for (var i=0; i<tabs.length; i++) {
			if (tabs[i].className == 'contentvisible') {
				tabs[i].className = 'contenthidden';
			}
		}
	}

	e = document.getElementById('tabcontent_' + newId);
	if (e != null) {
		e.className = 'contentvisible';
	}
	
	e = document.getElementById('tabimage');
	if (e != null) {
		var tabs = e.getElementsByTagName('div');
		for (var i=0; i<tabs.length; i++) {
			if (tabs[i].className == 'contentvisible') {
				tabs[i].className = 'contenthidden';
			}
		}
	}
	e = document.getElementById('tabimage_' + newId);
	if (e != null) {
		e.className = 'contentvisible';
	}
}

function clearTabImages() {
	arrTabImages = new Array();
}

function addTabImage(tabName, index, src) {
	var obj = {'tabName':tabName, 'index': index, 'src':src};
	arrTabImages.push(obj);
}

function findTabImage(tabName, index) {
	for (var i=0; i<arrTabImages.length; i++) {
		var obj = arrTabImages[i];
		if (obj.tabName == tabName && obj.index == index) {
			return obj.src;
		}
	}
	return false;
}

function getCountImagesByTabName(tabName) {
	var res = 0;
	for (var i=0; i<arrTabImages.length; i++) {
		var obj = arrTabImages[i];
		if (obj.tabName == tabName) {
			res++;;
		}
	}	
	return res;
}

function changeTabImage(tabName, direction, nodeId) {
	var oldHref = '';
	if (direction == 1) {
		var el = document.getElementById('tablink_right_' + nodeId);
		if (el != null) {
			oldHref = el.href; 
		}
	}
	if (direction == -1) {
		var el = document.getElementById('tablink_left_' + nodeId);
		if (el != null) {
			oldHref = el.href;
		}	
	}
	var pos = oldHref.lastIndexOf("/");
	var value = parseInt(oldHref.substr(pos + 1), 10);
	var oldHref = oldHref.substr(0, pos+1);
	var newSrc = findTabImage(tabName, value);
	var imgEl = document.getElementById('image_content_' + nodeId);
	if (imgEl != null) {
		imgEl.src = newSrc;
	}
	
	var tmpValue = value;
	var count = getCountImagesByTabName(tabName);
	
	tmpValue++;
	if (tmpValue > count-1) {
		tmpValue = 0;
	}
	var el = document.getElementById('tablink_right_' + nodeId);
	if (el != null) {	
		el.href = oldHref + tmpValue;
	}

	tmpValue = value;
	tmpValue--;
	if (tmpValue < 0) {
		tmpValue = count-1;
	}
	var el = document.getElementById('tablink_left_' + nodeId);
	if (el != null) {
		el.href = oldHref + tmpValue;
	}			
		
	return false;
}

function preloadSkinImages(skinName) {
	var i = new Image();
	var path = '/extension/phl/design/phldesign/images/skins/' + skinName;
	i.src = path + '/bg-wld-mid.jpg';
	var i = new Image();
	i.src = path + '/bg-wld-top_a.jpg';
	var i = new Image();
	i.src = path + '/bg-wld-top_b.jpg';
	var i = new Image();
	i.src = path + '/bg-wld-mid.jpg';
	var i = new Image();
	i.src = path + '/bg-wld-bot.jpg';
	var i = new Image();
	i.src = path + '/bg-con-mid.png';
	var i = new Image();
	i.src = path + '/bg-con-top.png';
	var i = new Image();
	i.src = path + '/bg-con-bot.png';
	var i = new Image();
	i.src = path + '/bg-box-mid.png';
	var i = new Image();
	i.src = path + '/bg-box-top.png';
	var i = new Image();
	i.src = path + '/bg-box-bot.png';
	var i = new Image();
	i.src = path + '/bg-over-mid.png';
	var i = new Image();
	i.src = path + '/bg-over-top.png';
	var i = new Image();
	i.src = path + '/bg-over-bot.png';
	
/*	var htmlId = new Array('navigation_top' 
						,'navigation_bottom'
						,'page_inner_content'
						,'page_inner_content_bottom'
						);

	var idCnt = htmlId.length;
	var regex = /images\/skins\/.*\//;
	var cssObj = null;
	var bgOld = '';
	var preloadImg = new Array();
	
	if (document.body.currentStyle) {
		for (var i = 0; i < idCnt; i++) {
			if(document.getElementById(htmlId[i])) {
				bgOld = document.getElementById(htmlId[i]).currentStyle.BackgroundImage;
				if(bgOld.length > 1) {
					bgOld = bgOld.substr( bgOld.indexOf('(') + 1, bgOld.indexOf(')') - 4);
					preloadImg[i] = new Image();
					preloadImg[i].src = bgOld.replace(regex, 'images/skins/' + skinName + '/');
				}
			}
		}
	}
	else if (window.getComputedStyle) {
		for (var i = 0; i < idCnt; i++) {
			if(document.getElementById(htmlId[i])) {
				cssObj = window.getComputedStyle(document.getElementById(htmlId[i]), null);
				bgOld = cssObj.backgroundImage;
				if(bgOld.length > 1) {
					bgOld = bgOld.substr( bgOld.indexOf('(') + 1, bgOld.indexOf(')') - 4);
					preloadImg[i] = new Image();
					preloadImg[i].src = bgOld.replace(regex, 'images/skins/' + skinName + '/');
					
				}
			}
		}
	}
	preloadImg = new Array(); */
		
}

// ***********************************************************************************************************************************

var defItemsTop = '';
var maxItemsTop = 0;
var topMiddle = null;
var defItemsBottom = '';
var maxItemsBottom = 0;
var bottomMiddle = null;
var positionDiff = 0;
var scrollTimer = null;
var fontTimer = null;
var fadeTimer = null;
var items = new Array();
var itemToScroll = false;
var toPadding = 0;
var actualPadding = 0;
var toWidth = 0;
var actualWidth = 0;
var toMargin = 0;
var actualMargin = 0;
var ulTopLeft = null;
var ulTopMiddle = null;
var ulTopRight = null;
var ulBottomLeft = null;
var ulBottomMiddle = null;
var ulBottomRight = null;
var opacity = 0;
var paddingFaktor = 0;
var widthFaktor = 0;
var marginFaktor = 0;
var direction = 0;
var scrollType = 0;
var temp = 0;
var IElt7 = false;
var maxItems = 0;
var defItems = 0;
var typePrefix = '';
var itemMiddle = 0;
var fontSmall = 0;
var fontStart = 0;
var fontEnd = 0;
var arrowSuffix = '';
// das sind die standardwerte für normele breite
var longItemWidth = 24;
var leftrightItemWidth = 188;
var marginAdjustment = 0;
var isProcessing = false;
var longItemsIds = new Array();
longItemsIds.push(147);
longItemsIds.push(1795);
var lastLoadedNodeId = new Array();
var ajaxMaxRetries = 1;
var menuRetry = 0;
var contentRetry = 0;

function increaseFontMiddleItem() {
	// wird nur benutzt um die schrift größer zu machen, wird aufgerufen wenn man auf das mittlere item klickt
	if (items[itemMiddle] != null) {
		var fontValue = parseFloat(items[itemMiddle].style.fontSize);
		var fontDiff = fontEnd - fontSmall;		
		fontValue += fontDiff / 3;
		if (fontValue >= fontEnd) {
			window.clearInterval(fontTimer);
			fontTimer = null;
			changeContents();
			fontValue = fontEnd;
		}
		items[itemMiddle].style.fontSize = fontValue + 'em';
	}
}

function increaseFont() {
	if (items[itemMiddle] != null) {
		var fontValue = parseFloat(items[itemMiddle].style.fontSize);
		var fontDiff = fontEnd - fontSmall;		
		fontValue += fontDiff / 3;
		if (fontValue >= fontEnd && opacity >= 100) {
			window.clearInterval(fontTimer);
			fontTimer = null;
			if (changingContentsAllowed) {
				changeContents();
			}
			else {
				isProcessing = false;
			}
			
		}
		if (fontValue > fontEnd) {
			fontValue = fontEnd;
		}
		items[itemMiddle].style.fontSize = fontValue + 'em';
		
		if (opacity < 101) {
			opacity += 40;
			if (opacity > 100) {
				opacity = 100;
			}
			var e;
			e = document.getElementById('arrow_left_' + arrowSuffix);
			if (e != null) {
			    e.style.opacity = opacity/100;
			    e.style.filter = 'alpha(opacity=' + opacity + ')';		              			
			}
			e = document.getElementById('arrow_right_' + arrowSuffix);
			if (e != null) {
			    e.style.opacity = opacity/100;
			    e.style.filter = 'alpha(opacity=' + opacity + ')';
			}
		}
	}	
}

function decreaseFont() {
	if (items[itemMiddle] != null) {
		var fontValue = parseFloat(items[itemMiddle].style.fontSize);
		var fontDiff = fontStart - fontSmall;		
		fontValue -= fontDiff / 3;
		if (fontValue <= fontSmall) {
			fontValue = fontSmall;
			var el = document.getElementById(typePrefix + 'nav' + itemToScroll);
			el.style.paddingLeft = 0;
			el.style.paddingRight = 0;			
		}
		items[itemMiddle].style.fontSize = fontValue + 'em';

		if (opacity > 0) {
			opacity -= 40;
			if (opacity < 0) {
				opacity = 0;
			}
			var e;
			e = document.getElementById('arrow_left_' + arrowSuffix);
			if (e != null) {
			    e.style.opacity = opacity/100;
			    e.style.filter = 'alpha(opacity=' + opacity + ')';		              			
			}
			e = document.getElementById('arrow_right_' + arrowSuffix);
			if (e != null) {
			    e.style.opacity = opacity/100;
			    e.style.filter = 'alpha(opacity=' + opacity + ')';
			}
		}

		if (fontValue <= fontSmall && opacity <= 0) {
			window.clearInterval(fontTimer);
			fontTimer = null;
			
			var w = items[itemToScroll].offsetWidth;
			if (direction == 1) {			
				marginFaktor = 2.5;
			}
			else {
				marginFaktor = 4;
			}
			
			// padding f�r das Element was verschoben wird
			actualPadding = 0;
			toPadding = (((longItemWidth * 10) - w) / 2) / fontSmall; // / fontSmall wegen der font-size und em
			toPadding = toPadding / 10;			
			
			actualWidth = longItemWidth;
			toWidth = parseInt(items[itemMiddle].offsetWidth) + 20;
			toWidth = toWidth / 10;
			
			actualMargin = 0;
			if (direction == 1) {
				toMargin = ((longItemWidth * 10) + items[itemToScroll].offsetLeft - 600) / 10;
				toMargin -= marginAdjustment;
				toMargin -= actualWidth - toWidth;
				toMargin -= 1;
			}
			else {
				toMargin = (360 - items[itemToScroll].offsetLeft + (longItemWidth * 10) - w) / 10;
				toMargin -= marginAdjustment;
			}			
			paddingFaktor = toPadding / (toMargin / marginFaktor);
			widthFaktor = (actualWidth - toWidth) / (toMargin / marginFaktor);			
			
			
			var e;
			e = document.getElementById('arrow_left_' + arrowSuffix);
			if (e != null) {
				e.style.display= 'none';
			}
			e = document.getElementById('arrow_right_' + arrowSuffix);
			if (e != null) {
				e.style.display= 'none';
			}	
			
			e = document.getElementById(typePrefix + 'nav' + itemMiddle);
			if (e != null) {
				e.style.width = longItemWidth + 'em';
			}			
			 
			scrollTimer = window.setInterval('scrollItems()', 60);
		}
	}
}

function changeArrowsHref() {
	var arrow = document.getElementById(typePrefix + 'navarrowleft');
	if (arrow != null) {
		var index = itemMiddle - 1;
		if (index < 0) {
			index = 0;
		}
		arrow.href = defItems[index].href;
	}
	var arrow = document.getElementById(typePrefix + 'navarrowright');
	if (arrow != null) {
		var index = itemMiddle + 1;
		if (index > defItems.length-1) {
			index = defItems.length-1;
		}
		arrow.href = defItems[index].href;
	}
}

function xchangeDOMElements() {
	if (scrollType == 1) {
		ulTopLeft.style.marginLeft = 0;
		ulTopRight.style.width = leftrightItemWidth + 'em';
		ulTopMiddle.style.width = longItemWidth + 'em';
	}
	else {
		if (ulBottomLeft != null) {
			ulBottomLeft.style.marginLeft = 0;
		}
		if (ulBottomRight != null) {
			ulBottomRight.style.width = leftrightItemWidth + 'em';;
		}
		if (ulBottomMiddle != null) {
			ulBottomMiddle.style.width = longItemWidth + 'em';
		}
	}
	
	for (var i=0; i<maxItems; i++) {
		if (items[i] != null) {
			items[i].style.marginLeft = 0;
			items[i].style.marginRight = 0;
			items[i].style.paddingLeft = 0;
			items[i].style.paddingRight = 0;
			items[i].firstChild.nodeValue = '';
		}
	}		
	var el = document.getElementById(typePrefix + 'nav' + itemMiddle);		
	el.style.width = longItemWidth + 'em';
	el = document.getElementById(typePrefix + 'nav' + itemToScroll);			
	el.style.paddingLeft = '1em';
	el.style.paddingRight = '1em';
		
	for (var i=0; i<defItems.length; i++) {
		var obj = defItems[i];
		var newNr = obj.nr - positionDiff;
		if (newNr >= defItems.length) {
			newNr = newNr - defItems.length;
		}
		if (newNr < 0) {
			newNr = defItems.length + newNr;
		}		
		 
		obj.tmpName = defItems[newNr].name;
		obj.tmpNodeid = defItems[newNr].nodeid;
		obj.tmphref = defItems[newNr].href;
		obj.tmpflworld = defItems[newNr].flworld;
		obj.tmpflobject = defItems[newNr].flobject;
		obj.tmpflpath = defItems[newNr].flpath;
		obj.tmpContentid = defItems[newNr].contentid;
	}
	
	for (var i=0; i<defItems.length; i++) {
		var obj = defItems[i];		
		obj.name = obj.tmpName;
		obj.nodeid = obj.tmpNodeid;
		obj.href = obj.tmphref;
		obj.flworld = obj.tmpflworld;
		obj.flobject = obj.tmpflobject;
		obj.flpath = obj.tmpflpath;
		obj.contentid = obj.tmpContentid;
		items[obj.nr].firstChild.nodeValue = obj.name;
		items[obj.nr].href = obj.href;
	}
	
	changeArrowsHref();	
}

function scrollItems() {
	if ((actualMargin > -toMargin && direction == 1) || (actualMargin < toMargin && direction == -1)) {		
		actualMargin += -marginFaktor * direction;
		if (actualMargin < -toMargin && direction == 1) {
			actualMargin = -toMargin;
		}
		
		if (actualMargin > toMargin && direction == -1) {
			actualMargin = toMargin;
		}
		
		if (scrollType == 1) {
			if (IElt7 && actualMargin > 0) {
				ulTopLeft.style.marginLeft = actualMargin/2 + 'em';
			}
			else {
				ulTopLeft.style.marginLeft = actualMargin + 'em';
			}
			ulTopRight.style.width = (leftrightItemWidth - actualMargin) + 'em';
		}
		else {
			if (IElt7 && actualMargin > 0) {
				ulBottomLeft.style.marginLeft = actualMargin/2 + 'em';
			}
			else {
				ulBottomLeft.style.marginLeft = actualMargin + 'em';
			}
			ulBottomRight.style.width = (leftrightItemWidth - actualMargin) + 'em';		
		}
		
		actualPadding += paddingFaktor;
		items[itemToScroll].style.paddingLeft = actualPadding + 'em';
		items[itemToScroll].style.paddingRight = actualPadding + 'em';
		
		actualWidth -= widthFaktor;
		var el = document.getElementById(typePrefix + 'nav' + itemMiddle);
		if (actualWidth < 0) {
			actualWidth = 0;
		}			
		el.style.width = actualWidth + 'em';
		if (scrollType == 1) {			
			ulTopMiddle.style.width = actualWidth + 'em';
		}
		else {
			ulBottomMiddle.style.width = actualWidth + 'em';		
		}		 
	}
	else {
		window.clearInterval(scrollTimer);
		scrollTimer = null;
		
		xchangeDOMElements();
		
		var e;
		e = document.getElementById('arrow_left_' + arrowSuffix);
		if (e != null) {
			e.style.display= 'block';
		}
		e = document.getElementById('arrow_right_' + arrowSuffix);
		if (e != null) {
			e.style.display= 'block';
		}	
		
		e = document.getElementById(typePrefix + 'nav' + itemMiddle);
		if (e != null) {			
			e.style.width = longItemWidth - 4 + 'em';
			if (typePrefix == 'bottom') {
				e.className = 'middle_item_active';
			}
		}
		
		fontTimer = window.setInterval('increaseFont()', 60);			
	}
}

function redirectToNodeId(nodeId) {
	var boolFound = false;
	var dest = '';
	for (var i=0; i<defItemsTop.length; i++) {
		if (defItemsTop[i].nodeid == nodeId) {
			dest = defItemsTop[i].href;
			boolFound = true;
			break;
		}
	}
	if (!boolFound && defItemsBottom != null && defItemsBottom.length > 0) {
		for (var i=0; i<defItemsBottom.length; i++) {
			if (defItemsBottom[i].nodeid == nodeId) {
				dest = defItemsBottom[i].href;
				boolFound = true;
				break;
			}
		}
	}
	
	if (boolFound) {
		top.location.href = dest;
	}
	else {
		// alert('Destination für nodeid not found: ' + nodeId);
	}
}

function moveItems(type) {
	items[itemToScroll].style.fontSize = fontSmall + 'em';
	ulTopLeft.style.marginLeft = 0;
	if (ulBottomLeft != null) {	
		ulBottomLeft.style.marginLeft = 0;
	}
	
	opacity = 100;	
	fontTimer = window.setInterval('decreaseFont()', 60);		
}

function changeMenu() {
	var html = '';
	var isError = false;
	if (menuHTML == '') {
		window.setTimeout("changeMenu()", 100);
	}
	else {
		isError = false;
		if (menuHTML == 'error') {
			//alert('error menu 1');
			isError = true;
		}
		else {
			try {
				obj = eval(menuHTML);
				html = decodeURIComponent(obj.content);
			}
			catch (err) {
				//alert('error menu 2');
				isError = true;
			}
		}

		if (isError) {
			if (menuRetry < ajaxMaxRetries) {
				menuRetry++;
				menuHTML ='';
				//alert('retry - menu ' + menuRetry);
				setRequestMenu('/' + activeSiteAccess + '/getajax/menu/'+ lastLoadedNodeId[0]);
				window.setTimeout("changeMenu()", 10);				
			}
			else {
				//alert('reloading hard link');
				redirectToNodeId(lastLoadedNodeId[0]);
			}
		}
		else {
			var e = document.getElementById('navigation_bottom');
			if (e != null) {
				e.innerHTML = html;			
				var script = "";
				var res = html.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function() {
					if (res !== null)
						script += arguments[1] + '\n';
					return '';
				});
			
				if (window.execScript) {
					window.execScript(script)
				}
				else {
					window.setTimeout(script, 0);
				}
			}
		}
	}
}

function changeContent() {
	var skin = '';
	var html = '';
	var title = '';
	var isError = false;
	if (contentHTML == '') {
		//setWaitText();
		window.setTimeout("changeContent()", 100);
	}
	else {
		isError = false;
		if (contentHTML == 'error') {
			//alert('error content 1');
			isError = true;
		}
		else {
			try {
				obj = eval(contentHTML);
				html = decodeURIComponent(obj.content);
				skin = decodeURIComponent(obj.skin);
				title = decodeURIComponent(obj.title);
			}
			catch (err) {
				//alert('error content 3');
				isError = true;
			}
		}
		
		if (isError) {
			if (contentRetry < ajaxMaxRetries) {
				contentRetry++;
				contentHTML ='';
				//alert('retry - content ' + contentRetry);
				setRequestContent('/' + activeSiteAccess + '/getajax/content/'+ lastLoadedNodeId[1]);
				window.setTimeout("changeContent()", 10);
			}
			else {
				//alert('reloading hard link - content');
				setDefaultCursor();
				redirectToNodeId(lastLoadedNodeId[1]);
				isProcessing = false;	
			}			
		}
		else {
			//setDefaultCursor();
			preloadSkinImages(skin);
			switchSkin(skin);
			
			var e = document.getElementById('page_inner_content');
			if (e != null) {
				e.innerHTML = html;
				
				var script = "";
				var res = html.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function() {
					if (res !== null)
						script += arguments[1] + '\n';
					return '';
				});
			
				script += 'showAllJSControls();\n';
				
				//alert(decodeURIComponent(script));
				if (window.execScript) {
					window.execScript(script)
				}
				else {
					window.setTimeout(script, 0);
				}				
				
				document.title = title;
			}
			isProcessing = false;
		}
	}
}

function loadContents(newNr, nodeId) {
	if (newNr == -1) {	
		var obj = defItems[itemMiddle];
	}
	else {
		var obj = defItems[newNr];
	}
	var menuNodeId = obj.nodeid;
	var contentNodeId = nodeId;
	if (nodeId == -1) {
		contentNodeId = menuNodeId;
	}
	lastLoadedNodeId = new Array(menuNodeId, contentNodeId);
		
	if (scrollType == 1) {
		menuHTML = '';
		menuRetry = 0;
		setRequestMenu('/' + activeSiteAccess + '/getajax/menu/'+ menuNodeId);
	}

	contentHTML = '';
	contentRetry = 0;
	setRequestContent('/' + activeSiteAccess + '/getajax/content/'+ contentNodeId);
}

function changeContents() {
	if (scrollType == 1) {
		changeMenu();
	}

	changeContent();
	
	contentsChanged = true;
}

function initItemsArray() {
	items = new Array();
	for (var i=0; i<maxItems; i++) {
		items[i] = document.getElementById(typePrefix + 'nava' + i);
		if (items[i] != null) {
			items[i].style.marginLeft = 0;
		}
	}
}

function initULElements() {
 	ulTopLeft = document.getElementById('top_items_left');
	ulTopMiddle = document.getElementById('top_item_middle');
	ulTopRight = document.getElementById('top_items_right');
	ulBottomLeft = document.getElementById('bottom_items_left');
	ulBottomMiddle = document.getElementById('bottom_item_middle');
	ulBottomRight = document.getElementById('bottom_items_right');		
}

function checkLongItems() {
	var el = document.getElementById('categorynodeid');
	if (el != null) {
		var elClass = el.className;
		for (var i=0; i<longItemsIds.length; i++) {
			if (elClass == 'catnodeid' + longItemsIds[i]) {
				longItemWidth = 30;
				leftrightItemWidth = 185;
				marginAdjustment = 3;
				break;
			}
		}
	}
}

function doNaviScrollItems(type, newNr, doAutomatic) {

	//doDebug(isProcessing);
	if (isProcessing) {
		return false;
	}
	isProcessing = true;
	
	changingContentsAllowed = !doAutomatic;		
	contentsChanged = false;
	scrollType = type;
	IElt7 = isIElt7();
	longItemWidth = 24;
	leftrightItemWidth = 188;
	marginAdjustment = 0;

	if (scrollType == 1) {
		checkLongItems();
		maxItems = maxItemsTop;
		defItems = defItemsTop;
		typePrefix = 'top';
	}
	else {
		maxItems = maxItemsBottom;
		defItems = defItemsBottom;
		typePrefix = 'bottom';	
	}
		
	initULElements();
	initItemsArray();	
	
	var fakeNodeSelectId = -1;
	if (scrollType == 1) {
		itemMiddle = topMiddle;
		fontSmall = 1.4;
		fontStart = 1.9;
		fontEnd = 1.9;				
		arrowSuffix = 'big';
		// hier gibt es nur den normalfall
		/*if (automaticScrollTimer != null) {
			window.clearInterval(automaticScrollTimer);
			automaticScrollTimer = null;
		}*/
		
		var el = document.getElementById(typePrefix + 'nav' + itemMiddle);
		if (el != null) {
			if (el.className == 'middle_item_inactive') {
				fontStart = 1.4;
			}
		}
		
		/*var url = document.URL;
		var res = url.search(/shop.+/);
		if (res == -1) {	
		//	startAutomaticScroll();
		}*/
		items[itemMiddle].style.fontSize = fontStart + 'em';
		
		// fakeNodeSelectId dient dem automatischen auswählen von child Content
		if (newNr != -1) {
			fakeNodeSelectId = defItems[newNr].contentid;
		}
		else {
			fakeNodeSelectId = defItems[itemMiddle].contentid;
		}
	}
	else {
		itemMiddle = bottomMiddle;
		arrowSuffix = 'small';
		// der normalfall
		fontSmall = 1;
		fontStart = 1.3;
		fontEnd = 1.3;		
		/*if (doAutomatic) {
			// der automatische fall
			fontStart = 1;
			fontEnd = 1;
		}*/
		var el = document.getElementById(typePrefix + 'nav' + itemMiddle);
		if (el != null) {
			if (el.className == 'middle_item_inactive') {
				fontStart = 1;
			}
			else {
				fontStart = 1.3;
			}
			items[itemMiddle].style.fontSize = fontStart + 'em';
		}
				
		/*if (automaticScrollTimer != null && !doAutomatic) {
			window.clearInterval(automaticScrollTimer);
			automaticScrollTimer = null;
		}*/
		
	}
	
	positionDiff = itemMiddle - newNr;
	direction = 1;
	if (positionDiff > 0) {
		direction = -1;
	}

	if (changingContentsAllowed) {
		loadContents(newNr, fakeNodeSelectId);
	}
			
	itemToScroll = newNr;
	if (newNr == -1) {
		// hier nur die schrift größer machen, da das element sich schon an der richtigen position befindet	
		if (scrollType == 1) {
			fontStart = 1.4;
			fontEnd = 1.9;
			items[itemMiddle].style.fontSize = fontStart + 'em';		
			fontTimer = window.setInterval('increaseFontMiddleItem()', 60);		
		}
		else {
			fontStart = 1;
			fontEnd = 1.3;
			items[itemMiddle].style.fontSize = fontStart + 'em';		
			fontTimer = window.setInterval('increaseFontMiddleItem()', 60);
		}
	}
	else {
		notifyFlashworldMovie(defItems[newNr].flworld + ';' + defItems[newNr].flobject + ';' + defItems[newNr].flpath);	
		moveItems(type);
	}
	
	return false;
}

function naviScroll(type, newNr) {
	return doNaviScrollItems(type, newNr, false); 
}


/*function doAutomaticScroll() {
	if (maxItemsBottom > 1) {
		doNaviScrollItems(2, bottomMiddle+1, false);
	}
}*/

/*function startAutomaticScroll() {
	var url = document.URL;
	var res = url.search(/shop.+/);
	if (res == -1) {	
//		automaticScrollTimer = window.setInterval('doAutomaticScroll()', 15000);
	}
}*/

/**
 * Flash communication functions
 */

/*function setMovieName(name) {
	flashMovieName = name;
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1 && window[movieName]) {
		return window[movieName];
	} 
	else {
		return document[movieName];
	}
}


function sendToJavaScript(type, value) {
	
	switch(type.toLowerCase()) {
		case 'animation':
			if(value.toLowerCase() == 'end') {
				//TODO: Animation end event handler (call next world)
			}
			else if(value.toLowerCase() == 'stop') {
				//TODO: User-initiated break handler - stop all automatic handlers
			}
			break;
		case 'location':
			var newUrl = '';
			var newNodeID = 0;
			if(value[0]) {
				newURL = value[0];
			}
			if(value[1]) {
				newNodeID = value[1];
			}
			if(value[1] > 0) {
				//TOTDO: switch to new url/node
			}
			break;
		default:
			return false;
			break;
	}
	return true;
}

function sendToActionScript(value) {
	var movie = thisMovie(flashMovieName);
	if (movie && movie.sendToActionScript != null) {
		movie.sendToActionScript(value);
	}
}

function notifyFlashworldMovie(value) {
	setMovieName('phantasialand');
	sendToActionScript(value);
}

/**
 * END::Flash communication functions
 */

 
/* shop functions */

function formatShopCount(value) {
	if (value < 10) {	
		value = '0' + value;
	}
	return value;
}

function decreaseShopCount(id, day, enableZero) {
	if (day != null) {
		var el = document.getElementById('countinput_' + id + '_' + day);
	}
	else {
		var el = document.getElementById('countinput_' + id);
	}
	if (el != null) {
		var value = el.value;
		var newValue = parseInt(value, 10);
		newValue--;
		if (enableZero) {
			if (newValue < 0) {
				newValue = 0;
			}		
		}
		else {
			if (newValue < 1) {
				newValue = 1;
			}
		}
		newValue = formatShopCount(newValue);
		el.value = newValue;
	}
}


function increaseShopCount(id, day) {
	if (day != null) {
		var el = document.getElementById('countinput_' + id + '_' + day);
	}
	else {
		var el = document.getElementById('countinput_' + id);
	}
	if (el != null) {
		var value = el.value;
		var newValue = parseInt(value, 10);
		newValue++;
		
		if (newValue > 99) {
			newValue = 99;
		}		
		newValue = formatShopCount(newValue);
		el.value = newValue;
	}
}

function refreshSummary(itemId, change) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('shopping-basket-summary');
								if (dest != null) {
									dest.innerHTML = html;
								}
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasketsummary/'+ itemId + '/' + change, this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = '/shop/basket';
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasketsummary/'+ itemId + '/' + change + '/operation', callback, req);
	return false;	
}

function deleteProduct(itemId) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('shopping-basket-summary');
								if (dest != null) {
									dest.innerHTML = html;
								}
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/deleteshopitem/'+ itemId, this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = '/shop/basket';
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/deleteshopitem/'+ itemId + '/operation', callback, req);
	return false;		
}

function addAndRefreshBasket(nodeId, objectId, formname, articlenr) {
	var nodeEl = document.getElementById('lastnode');
	if (nodeEl != null) {
		var parentNodeId = nodeEl.value;
	}
	var el = document.getElementById('countinput_' + nodeId);
	if (el != null) {
		var retries = 0;
		setWaitCursor();
		var req = null;
		
		var callback = function() {
			var isError = false;
			if (req != null) {
				if (req.readyState == 4) {
					try {
						if (req.status == 200) {
							if (req.responseText != '') {
								contentHTML = req.responseText;
								try {
									req = null;
									obj = eval(contentHTML);
									html = decodeURIComponent(obj.content);
									setDefaultCursor();
									var dest = document.getElementById('shopping-basket-container');
									if (dest != null) {
										dest.innerHTML = html;
									}
									if (articlenr != '') {
										osc.evt('BSK', articlenr);
									}									
								}
								catch (err) { isError = true }
							}
							else { isError = true }
						}
						else { isError = true }	
					} catch(e) { isError = true }
				}
			}
			if (isError) {
				if (retries < ajaxMaxRetries) {
					retries++;
					req = null;
					req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasket/'+ objectId + '/' + parseInt(el.value, 10) + '/' + parentNodeId, this, req);
				}
				else {
					setDefaultCursor();
					var elInput = document.getElementById('ActionAddToBasketFallback_' + nodeId);
					if (elInput != null) {
						elInput.value = 1;
					}					
					document[formname].submit();
				}
			}
		}
		
		req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasket/'+ objectId + '/' + parseInt(el.value, 10) + '/' + parentNodeId + '/operation', callback, req);
		return false;	
	}
	return false;
}

function addAndRefreshBasketFantissima(validdate, eventid, formname, day) {
	var oscString = '';
	var nodeEl = document.getElementById('lastnode');
	if (nodeEl != null) {
		var parentNodeId = nodeEl.value;
	}
	var container = document.getElementById('fantissimaticket_' + day);
	if (container == null) {
		return true;
	}
	var els = container.getElementsByTagName('input');
	var counts = new Array();
	var objectIds = new Array();
	var articleNumbers = new Array();
	for (var i=0; i<els.length; i++) {
		if (els[i].className == 'nodeidinput') {
			var nodeId = els[i].value;
			var count = 0;
			var el = document.getElementById('countinput_' + nodeId + '_' + day);
			if (el != null) {
				count = parseInt(el.value, 10);
			}
			counts.push(count);
		}
		else {
			if (els[i].className == 'objectidinput') {
				objectIds.push(els[i].value);
			}
			else {
				if (els[i].className == 'articlenr') {
					articleNumbers.push(els[i].value);					
				}			
			}
		}		
	}

	for (var i=0; i<counts.length; i++) {
		if (counts[i] > 0) {
			oscString += articleNumbers[i] + ',' + validdate + ';';
		}
	}

	var objectIdsString = objectIds.join('-');
	var countsString = counts.join('-');

	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('shopping-basket-container');
								if (dest != null) {
									dest.innerHTML = html;
								}
								if (oscString != '') {
									osc.evt('BSK', oscString);
								}
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasketfantissima/'+ objectIdsString + '/' + countsString + '/' + validdate + '/' + eventid + '/' + parentNodeId, this, req);
			}
			else {
				setDefaultCursor();
				var elInput = document.getElementById('ActionAddToBasketFallback');
				if (elInput != null) {
					elInput.value = 1;
				}
				document[formname].submit();
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/addtobasketfantissima/'+ objectIdsString + '/' + countsString + '/' + validdate + '/' + eventid + '/' + parentNodeId + '/operation', callback, req);
	return false;	
}

function changeAndRefreshBasket(objectId, change, nodeId) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('shopping-basket-container');
								if (dest != null) {
									dest.innerHTML = html;
								}
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < 3) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/incdecbasket/'+ objectId + '/' + change + '/' + nodeId, this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = '/shop/basket?reload=1';
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/incdecbasket/'+ objectId + '/' + change + '/' + nodeId + '/operation', callback, req);
	return false;
}

function getFantissimaTicket(day, nodeId, orgLink) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('fantissima-ticket');
								if (dest != null) {
									dest.innerHTML = html;
									window.location.href = "#ft";
								}								
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/getfantissimaticket/' + day + '/' + nodeId, this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = orgLink;
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/getfantissimaticket/'+ day + '/' + nodeId, callback, req);
	return false;	
}

function getHarmonyOverview(nodeId, validNodeId, orgLink, nodeIdList) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;								
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('harmony_overview_content');
								if (dest != null) {
									dest.innerHTML = html;
								}
								var script = "";
								var res = html.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function() {
									if (res !== null)
										script += arguments[1] + '\n';
									return '';
								});
							
								//alert(decodeURIComponent(script));
								if (window.execScript) {
									window.execScript(script)
								}
								else {
									window.setTimeout(script, 0);
								}								
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/getharmonyoverview/' + nodeId + '/' + validNodeId + '/' + encodeURIComponent(nodeIdList), this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = orgLink;
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/ajaxshop/getharmonyoverview/' + nodeId + '/' + validNodeId + '/' + encodeURIComponent(nodeIdList), callback, req);
	return false;	
}

function doDebug(msg) {
	var el = document.getElementById('debug');
	if (el != null) {
		el.innerHTML += msg +'<br />';
	}
}


function getCalendar(calendarNodeId, nodeId, year, month, day) {
	var retries = 0;
	setWaitCursor();
	var req = null;
	
	var callback = function() {
		var isError = false;
		if (req != null) {
			if (req.readyState == 4) {
				try {
					if (req.status == 200) {
						if (req.responseText != '') {
							contentHTML = req.responseText;
							try {
								req = null;								
								obj = eval(contentHTML);
								html = decodeURIComponent(obj.content);
								setDefaultCursor();
								var dest = document.getElementById('calendar_left');
								if (dest != null) {
									dest.innerHTML = html;
								}
								var script = "";
								var res = html.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function() {
									if (res !== null)
										script += arguments[1] + '\n';
									return '';
								});
							
								//alert(decodeURIComponent(script));
								if (window.execScript) {
									window.execScript(script)
								}
								else {
									window.setTimeout(script, 0);
								}								
							}
							catch (err) { isError = true }
						}
						else { isError = true }
					}
					else { isError = true }	
				} catch(e) { isError = true }
			}
		}
		if (isError) {
			if (retries < ajaxMaxRetries) {
				retries++;
				req = null;
				req = setRequestASync('/' + activeSiteAccess + '/getajax/calendar/' + calendarNodeId + '/' + nodeId + '/' + year + '/' + month + '/' + day, this, req);			
			}
			else {
				setDefaultCursor();
				top.location.href = orgLink;
			}
		}
	}
	
	req = setRequestASync('/' + activeSiteAccess + '/getajax/calendar/' + calendarNodeId + '/' + nodeId + '/' + year + '/' + month + '/' + day, callback, req);
	return false;	
}

/* No JS Fallbacks */

function showAllJSControls() {
	showTicketsControls();
	showFantissimaControls();
	showBasketRightControls();
	showBasketMainControls();
}

function showTicketsControls() {
	if (arrTicketsIdsToShow != null) {
	
		for (var i=0; i<arrTicketsIdsToShow.length; i++) {
			var el = document.getElementById('ticket_left_' + arrTicketsIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}
			var el = document.getElementById('ticket_right_' + arrTicketsIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}			
			var el = document.getElementById('countinput_' + arrTicketsIdsToShow[i]);
			if (el != null) {
				el.className = 'counter';
			}			
		}
	}	
}

function showFantissimaControls() {
	if (arrFantissimaIdsToShow && arrFantissimaIdsToShow != null) {
		for (var i=0; i<arrFantissimaIdsToShow.length; i++) {
			var el = document.getElementById('fantissima_left_' + arrFantissimaIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}
			var el = document.getElementById('fantissima_right_' + arrFantissimaIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}			
			var el = document.getElementById('countinput_' + arrFantissimaIdsToShow[i]);
			if (el != null) {
				el.className = 'counter';
			}			
		}
	}	
}

function showBasketRightControls() {
	if (arrBasketRightIdsToShow != null) {
		for (var i=0; i<arrBasketRightIdsToShow.length; i++) {
			var el = document.getElementById('shopright_left_' + arrBasketRightIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}
			var el = document.getElementById('shopright_right_' + arrBasketRightIdsToShow[i]);
			if (el != null) {
				el.style.visibility = 'visible';
			}
			var el = document.getElementById('shopright_input_' + arrBasketRightIdsToShow[i]);
			if (el != null) {
				el.style.display = 'none';
			}			
			var el = document.getElementById('shopright_div_' + arrBasketRightIdsToShow[i]);
			if (el != null) {
				el.style.display = 'block';
			}			
		}
	}
	var el = document.getElementById('shopright_updatebutton');
	if (el != null) {
		el.style.display = 'none';
	}
}

function showBasketMainControls() {
	if (arrBasketMainIdsToShow != null) {
		for (var i=0; i<arrBasketMainIdsToShow.length; i++) {
			var el = document.getElementById('shopmain_left_' + arrBasketMainIdsToShow[i]);
			if (el != null) {
				el.style.display = 'block';
			}
			var el = document.getElementById('shopmain_right_' + arrBasketMainIdsToShow[i]);
			if (el != null) {
				el.style.display = 'block';
			}
			var el = document.getElementById('shopmain_input_' + arrBasketMainIdsToShow[i]);
			if (el != null) {
				el.style.display = 'none';
			}			
			var el = document.getElementById('shopmain_div_' + arrBasketMainIdsToShow[i]);
			if (el != null) {
				el.style.display = 'block';
			}			
		}
	}
	var el = document.getElementById('shopmain_updatebutton');
	if (el != null) {
		el.style.display = 'none';
	}
}


function sendSurveyValues() {
	if (osc) {
		var paramString = '';
		var e = document.getElementById('3jahre');
		if (e.value > 0) {
			paramString += 'bis 3,' + e.value + ';';
		}
		var e = document.getElementById('4jahre');
		if (e.value > 0) {
			paramString += '4 bis 6,' + e.value + ';';
		}
		var e = document.getElementById('7jahre');
		if (e.value > 0) {
			paramString += '7 bis 9,' + e.value + ';';
		}
		var e = document.getElementById('10jahre');
		if (e.value > 0) {
			paramString += '10 bis 12,' + e.value + ';';
		}
		var e = document.getElementById('13jahre');
		if (e.value > 0) {
			paramString += 'ab 13,' + e.value + ';';
		}
		
		var e = document.getElementById('nicht');
		if (e.checked) {
			paramString += 'ohne Kinder';
		}
		
		if (paramString == '') {
			paramString = 'nicht angegeben';
		}
		
		osc.evt('Kinder', paramString);
		closeSurveyLayer();
	}
}

function openSurveyLayer() {
	var el = document.getElementById('surveyContent');
	if (el != null) {
		el.style.display = 'block';
	}
}

function closeSurveyLayer() {
	var el = document.getElementById('surveyContent');
	if (el != null) {
		el.style.display = 'none';
	}
}

/* No JS Fallbacks */