/********************************************************************/
/*START: Fix IE 6 Text Selection Bug & Flickering Background Images */
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat") {
	document.onreadystatechange = function fixIE6AbsPos()
	{
		if( !document.body ) {
			return;
		}
		if( document.readyState == "complete" ) {
			document.body.style.height = document.documentElement.scrollHeight + 'px';
		}
	}

	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}
/*END: Fix IE 6 Text Selection Bug & Flickering Background Images */
/********************************************************************/
function handleVouchterCodeEntry(oInput)
{
	if (oInput.id=="payment-voucher") {
		showdiv('voucher-code-entry');
		document.getElementById('voucher-code').focus();
		hidediv('additional-registration');
	} else {
		hidediv('voucher-code-entry');
		showdiv('additional-registration');
	}
}

function handleDeliveryAddress()
{	
	isOneChecked = false;
	var arrCheck = {
		1: document.getElementById('free-copy-cz').checked,
		2: document.getElementById('free-copy-ll').checked,
		3: document.getElementById('free-copy-wip').checked,
		4: document.getElementById('free-copy-ea').checked,
		5: document.getElementById('free-copy-ia').checked
	}
	
	for (arrElem in arrCheck)
	{
		if (arrCheck[arrElem])
		{
			isOneChecked = true;
			break;
		}
	}
	
	if (isOneChecked)
	{
		showdiv('delivery-address');
	}
	else
	{
		hidediv('delivery-address');
	}
}

function isOneFreePrintChecked()
{	
	isOneChecked = false;
	if (document.getElementById('free-copy-cz').checked ||
		document.getElementById('free-copy-ll').checked ||
		document.getElementById('free-copy-wip').checked ||
		document.getElementById('free-copy-ea').checked ||
		document.getElementById('free-copy-ia').checked)
	{
		isOneChecked = true;
	}
		
	return isOneChecked;
}
/**************************************************/
/*START: Functions for displaying and hiding DIVs */
function showhidediv(div) {
	if (document.getElementById(div).style.display == 'none')
	{
		showdiv(div);
	}
	else
	{
		hidediv(div);
	}
}

function showdiv (div) 
{
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById(div).style.display = 'block';
	}
}

function hidediv(div)
{
	//alert('hidediv');
	if (document.getElementById)
	{ // DOM3 = IE5, NS6
		document.getElementById(div).style.display = 'none';
	}
}
/*END: Functions for displaying and hiding DIVs */
/**************************************************/
/********************************************************************/
/*START: Functions to open popups */
function openPopup(url, popupName, width, height, posX, posY)
{
	var pos = getWindowPos(width, height, posX, posY);
	if (pos != undefined)
	{
		posX = pos[0];
		posY = pos[1];
	}
	popupwindow = window.open(url, popupName, 'width='+width+', height='+height+', toolbar=no, menubar=no, scrollbars=yes, resizable=no, top='+posY+', left='+posX);
	popupwindow.focus();
}

function openEventImage(url, popupName, posX, posY)
{
	width = 690;
	height = 565;
	var pos = getWindowPos(width, height, posX, posY);
	if (pos != undefined)
	{
		posX = pos[0];
		posY = pos[1];
	}
	popupwindow = window.open(url, popupName, 'width='+width+', height='+height+', toolbar=no, menubar=no, scrollbars=yes, resizable=yes, top='+posY+', left='+posX);
	popupwindow.focus();
}

function openVita(url, popupName, width, height, posX, posY)
{
	width = 500;
	height = 568;
	var pos = getWindowPos(width, height, posX, posY);
	if (pos != undefined)
	{
		posX = pos[0];
		posY = pos[1];
	}
	popupwindow = window.open(url, popupName, 'width='+width+', height='+height+', toolbar=no, menubar=no, resizable=no, top='+posY+', left='+posX);
	popupwindow.focus();
}

function getWindowPos(width, height, posX, posY)
{
	var standardX = 255;
	var standardY = 70;
	
	if(posX == undefined)
	{
		if(window.screenLeft != undefined){
			//for microsoft ie
			if(window.screenLeft + standardX + width < screen.width - 100)
			{
				posX = window.screenLeft + standardX;
			} 
			else 
			{
				posX = screenLeft - 50;
			}
			
			if(window.screenTop + standardY + height < screen.height - 30)
			{
				posY = window.screenTop + standardY;
			}
			else
			{
				posY = standardY;
			}
		}
		else 
		{
			if(window.screenX + standardX + width < screen.width - 100)
			{
				posX = window.screenX + standardX;
			} 
			else 
			{
				posX = screenX - 50;
			}
			
			if(window.screenY + standardY + height < screen.height - 30)
			{
				posY = window.screenY + standardY + 111;
			}
			else
			{
				posY = standardY + 111;
			}
		}
	return [posX,posY]
	}
}
/*END: Functions to open popups */
/********************************************************************/
/********************************************************************/
/*START: Functions to close popups */
function doClose()
{
	if (window.opener)
	{
		window.opener.location.reload();
	}
	window.close();
}


function doCloseReload(path)
{
	if (window.opener && path)
	{
		window.opener.location.href=path;
	}
	window.close();
}
/*END: Functions to close popups */
/********************************************************************/

/********************************************************************/
/*START: Function to track printing */
function doPrint(servletSrc)
{
	window.print();
	var trackingImage = new Image();
	trackingImage.src = servletSrc; 
}
/*END: Function to track printing */
/********************************************************************/

/********************************************************************/
/*START: Function to rewrite pwd-field */
function handlePassword()
{
	var inputPwd = document.getElementById('login-password');
	if (inputPwd) {
		var inputDummy = document.createElement("input");
		inputDummy.value = "Passwort";
		inputDummy.name = "dummy";
		inputDummy.id = "dummy";
		inputDummy.className = "styled-input M";
		inputPwd.style.display = "none";
		inputPwd.parentNode.insertBefore(inputDummy,inputPwd.nextSibling);

		inputDummy.inputPwd = inputPwd;
		inputDummy.onfocus = function () {
			this.style.display = "none";
			this.inputPwd.style.display = "inline";
			this.inputPwd.value = "";
			this.inputPwd.focus();
		}

		inputPwd.inputDummy = inputDummy;
		inputPwd.onblur = function () {
			if (this.value.length==0) {
				this.style.display = "none";
				this.inputDummy.style.display = "inline";
			}
		}
	}
}
/*END: Function to rewrite pwd-field */
/********************************************************************/
window.onload = function ()
{
	handlePassword();
}