var win = null;

// ===============================================================================================================================

function NewWindow(mypage, myname, w, h, scroll)
{	
	
	if (win && !win.closed) win.close();
	
	

	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, settings);
	if (win.window.focus) { win.window.focus(); }
}

// ===============================================================================================================================

function getViewport(returnmode)
{
	// Gibt Höhe oder Breite des Viewports zurück
	var viewportwidth;
	var viewportheight;
	 
	// standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof(window.innerWidth) != 'undefined')
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	 
	// IE6 in standards compliant mode
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	 
	// older versions of IE 
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	
	if (returnmode == "width") return viewportwidth;
	else return viewportheight;
	
}

// ===============================================================================================================================

function setHeightSpacer(myValue, showSky, minSkySpacerHeight)
{
	// Setzt Höhe für pt.gif
	var spacerHeight;
	var fullHeight = getViewport(); // get current viewport height
	
	var headerHeight = document.getElementById("header-wrapper").offsetHeight;
	var footerHeight = document.getElementById("footer").offsetHeight;
	
	var remainingHeight = fullHeight - (headerHeight + footerHeight) - 20;
	
	if (document.all) remainingHeight = remainingHeight - 0; // Wenn IE

	
	if (remainingHeight > 0)
		{
		document.getElementById("content-table").style.height = remainingHeight + "px";
		}
}

// ===============================================================================================================================

function hideDiv(idDiv) 
{
	document.getElementById(idDiv).style.display = 'none';
}

// ===============================================================================================================================

function showDiv(idDiv) 
{
	document.getElementById(idDiv).style.display = '';
}

// ===============================================================================================================================

function email_valid(email) 
{
 	var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  	var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,6}";
  	var regex  = "^" + usr + "\@" + domain + "$";
  	var rgx    = new RegExp(regex);
  	return rgx.exec(email) ? true : false;
}

// ===============================================================================================================================

function maildecode (input)
	{
	var output=input;
	output=output.replace(/\|/, '@');
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	output=output.replace("#xxcom#", ".");
	return (output);
	}

// ===============================================================================================================================

function writemaillink ($input,$hid)
	{
	$showmail=maildecode($input);
	$showmail=$showmail.replace('@','&#64;');
	$showmail=$showmail.replace(/\./,'&#46;');
	$showmail=$showmail.replace(/\?.*/,'');
	document.write('Email:&nbsp;');
	document.write ("<a href=\"javascript:makemail('"+$input+"','"+$hid+"')\">");
	document.write($showmail);
	document.write ('</a><br>');
	}
	
// ===============================================================================================================================

function makemail($link,$hid)
	{
	if ($hid>0) mailtocount($hid);
	$link=maildecode($link);
	this.location.href="mailto:"+$link;
	}

// ===============================================================================================================================

function getStyle(elementId,stylePropJs,stylePropCss)
{
	// RETURNS CSS STYLE VALUE, REQUIRES JS AND CSS NOTATION, IF POSSIBLE USE JQUERY TO DETERMINE COMPUTED STYLE
	var obj = document.getElementById(elementId);
	if (obj.currentStyle) // IE
		var styleValue = obj.currentStyle[stylePropJs];
	else if (window.getComputedStyle) // Mozilla
		var styleValue = document.defaultView.getComputedStyle(obj,null).getPropertyValue(stylePropCss);
	return styleValue;
}

// ===============================================================================================================================

function format_fieldcolor(idDiv, showError)
{
	showError = showError | false;
	var errorClass = "fc-error";
	var normalClass = "fc-normal";
	var labelColor = (showError) ? "#CC0000" : "";
	var d = document.getElementById(idDiv);
	var currentClass = d.className;
	var myLabel = "labelfor_" + idDiv;
	
	if (showError)
	{
		var showClass = errorClass;
		var oppClass = normalClass;
	}
	else
	{
		var showClass = normalClass;
		var oppClass = errorClass;
	}
	
	if (currentClass == "" || currentClass == oppClass)
	{
		d.className = showClass;
	}
	else
	{
		var indexOfSpace = currentClass.indexOf(" ");
		if(indexOfSpace == -1)
		{
			d.className = currentClass + " " + showClass;
		}
		else
		{
			var mainClass = currentClass.substring(0, indexOfSpace + 1);
			d.className = mainClass + " " + showClass;
		}
	}
	
	if (document.getElementById(myLabel)) document.getElementById(myLabel).style.color = labelColor;
}

// ===============================================================================================================================

function fieldcolor_normal(idDiv)
{
	format_fieldcolor(idDiv);
}

// ===============================================================================================================================

function fieldcolor_error(idDiv)
{
	format_fieldcolor(idDiv, true);
}

// ===============================================================================================================================

