popupActive = false;

function togglePopup(headerText, contentText, buttonText){
	var box = document.getElementById("popupWindow");
	if(!box || box == null || typeof(box) == 'undefined')
		return;
	
	// init disable box
	var disableBox = document.getElementById('disableWindowAccess');
	
	if(!popupActive){
		if(typeof(headerText) != 'undefined')
			document.getElementById('popupTitle').innerHTML = headerText;
		else
			document.getElementById('popupTitle').innerHTML = 'Fehler';
		
		if(typeof(contentText) != 'undefined')
			document.getElementById('popupContent').innerHTML = contentText.replace(/(\+\+\+===)/g, '<br />');
		
		if(typeof(buttonText) != 'undefined')
			document.getElementById('popupSubmit').value = buttonText;
		else
			document.getElementById('popupSubmit').value = 'OK';
		
		// getting measures of box
		if(box.offsetWidth)
			box_w = parseInt(box.offsetWidth);
		else if(box.scrollWidth)
			box_w = parseInt(box.scrollWidth);
		else
			return;
		
		if(box.offsetHeight)
			box_h = parseInt(box.offsetHeight);
		else
			return;
			
		var dimensions = getAvailableDimensions();	
		var offset_w = 0;
		
		popupActive = true;
		box.style.left = ((dimensions.width / 2) - (box_w / 2) - offset_w + (dimensions.scrollLeft / 2))+"px";
		box.style.top = ((dimensions.height / 2) - (box_h / 2) + dimensions.scrollTop)+"px";
		box.style.visibility = 'visible';
		disableBox.style.display = 'block';
		disableBox.style.height = document.body.offsetHeight+"px";
		
		if(isIE6()){
			disableBox.style.height = dimensions.height+dimensions.scrollTop+"px";
		}
	}else{
		box.style.visibility = 'hidden';
		disableBox.style.display = 'none';
		popupActive = false;
	}
}

function getAvailableDimensions(){
	if (window.innerWidth)
    	var w = window.innerWidth;
  	else if (!w && document.body.offsetWidth)
		var w = document.body.offsetWidth;

  	if (window.innerHeight)
   		var h = window.innerHeight;
	else if(document.documentElement.clientHeight)
		var h = document.documentElement.clientHeight;
  	else if (document.body.offsetHeight)
		var h = document.body.offsetHeight;
	else h = 700;
		
	
	sLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
	sTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
	
	return {scrollLeft: parseInt(sLeft), scrollTop: parseInt(sTop), width: parseInt(w), height:parseInt(h) };
}

function isIE6(){
	return /msie|MSIE 6/.test(navigator.userAgent);	
}

function isIE7(){
	return /msie|MSIE 7/.test(navigator.userAgent);	
}

function isIE(){
	return /msie|MSIE/.test(navigator.userAgent);	
}

function isFF(){
	return /Firefox/.test(navigator.userAgent);	
}

tickerPosition = new Array();
tickerTimeouts = new Array();

function startTicker(sliceID, speed, init){
	ticker = document.getElementById("tickerAnchor_"+sliceID);
	//alert(ticker);
	
	if(init){
		tickerPosition['ticker_'+sliceID] = 0;
		
		ticker.onmouseover = function(){ pauseTicker(sliceID); };
		ticker.onmouseout = function(){ startTicker(sliceID, speed); };
	}

	var leftPos = parseInt(ticker.style.left.replace(/px/, ''));
	
	//length of container
	var boxObj = document.getElementById("tickerBox_"+sliceID);
	var boxLength = parseInt(boxObj.offsetWidth.toString().replace(/px/, ''));
	
	//length of content
	var contentObj = document.getElementById("tickerContent_"+sliceID);
	var contentLength = parseInt(contentObj.offsetWidth.toString().replace(/px/, ''));
	
	if((leftPos * -1) > contentLength)
		leftPos = boxLength + 5;
	
	tickerPosition['ticker_'+sliceID] = (leftPos-5);
	ticker.style.left = (leftPos-5)+"px";
	
	
	tickerTimeouts['ticker_'+sliceID] = setTimeout(function(){ startTicker(sliceID, speed); }, (200 - (40 * (speed - 1))));
}

function pauseTicker(sliceID){
	clearTimeout(tickerTimeouts['ticker_'+sliceID]);
	tickerTimeouts['ticker_'+sliceID] = null;
}

