var popwin;

// PopUps aufrufen
function PopUp(src,w,h)
{
	oversize = 0;
	if(popwin) popwin.close();

	if(w > screen.width-100)
	{
		oversize = 1;
		// h = Math.round((screen.width-100)/w*h); // Verhältnis
		h = parseInt(h)+20; // Scrollbars
		w = (screen.width-100);
	}
	if(h > screen.height-150)
	{
		oversize = 1;
	    	// w = Math.round((screen.height-150)/h*w); // Verhältnis
	    	w = parseInt(w)+20; // Scrollbars
		h = (screen.height-150);
	}

	breite = Math.round((screen.width - w) / 2);
	hoehe = Math.round((screen.height - h) / 2);

	if(oversize == 1)
		popwin = window.open(src,"popwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top="+hoehe+",left="+breite);
	else
		popwin = window.open(src,"popwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h+",top="+hoehe+",left="+breite);
}

// Druckansicht
function PrintView(src,w,h)
{
	var breite = (screen.width - w) / 2;
	var hoehe = (screen.height - h) / 2;
	window.open(src,"printview","toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top="+hoehe+",left="+breite);
}

// Formulare leeren
function ClearForm(Formular)
{
	document.forms[Formular].reset(); // Zuerst reset!
	var x = 0;
	while(document.forms[Formular].elements[x])
	{
		if(document.forms[Formular].elements[x].type == "checkbox" || document.forms[Formular].elements[x].type == "radio")
		{
			// Checkboxen + Radiobuttons werden nicht angehakt
			document.forms[Formular].elements[x].checked = false;
		}
		else if(document.forms[Formular].elements[x].type != "hidden" && document.forms[Formular].elements[x].type != "submit" && document.forms[Formular].elements[x].type != "reset" && document.forms[Formular].elements[x].type != "button")
		{
			// Alle, ausser versteckte Felder, dürfen geleert werden
			document.forms[Formular].elements[x].value = "";
		}
		x++;
	}
}

// Zum Anfang der Seite scrollen
function ScrollToTop()
{
	var y = 0;

	if(window.pageYOffset) y = window.pageYOffset;
	else
	if(document.body && document.body.scrollTop) y=document.body.scrollTop;

	while(y > 0)
	{
		setTimeout("window.scrollBy(0,-20)",10);
		y = y-5;
	}
}

// Seite zu den Favoriten
function MakeFavorite(title,url)
{
	if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(url,title)
	}
	else if(navigator.appName == "Netscape")
	{
		alert("Unsere Homepage können Sie manuell oder\nmit den Tasten STRG+D zu den Favoriten hinzufügen.");
	}
}

// Bilder vorladen, mit PreloadImages('bild1.jpg','bild2.gif'); aufrufen
function PreloadImages()
{
	document.Vorladen = new Array();
	if(document.images)
	{
		for(var i=0; i<PreloadImages.arguments.length; i++)
		{
			document.Vorladen[i] = new Image();
			document.Vorladen[i].src = PreloadImages.arguments[i];
		}
	}
}

// Für Navigation - Drop-Down

var TimeAktiv;

// Wenn Maus ausserhalb vom Menü, alle Layer nach 0,5 Sekunde ausblenden
function CheckMouseOut()
{
	if(TimeAktiv) window.clearTimeout(TimeAktiv);
	TimeAktiv = window.setTimeout('HideSubmenus()',500);
}

// Navigation 1.Ebene - Horizontale Navigation
function DisplayMenu(id)
{
	HideSubmenus();
	if(document.getElementById('submenu' + id))
	{
		document.getElementById('submenu' + id).style.display = 'block';
	}
}

function defineMenuWidth()
{
	//alert(menuId.length);
	for(var i=0; i < menuId.length; i++){
		var mId = menuId[i];
		var elementDiv = document.getElementById('submenu' + mId);
		var elementCell = document.getElementById('menuitem' + mId);
		var elementHeightCell = document.getElementById('menucell' + mId);
		var divWidth = elementDiv.offsetWidth;
		elementCell.style.width = divWidth + 'px';
		var cellWidth = elementCell.offsetWidth - 2;
		var divHeight = elementDiv.offsetHeight;
		var cellHeight = elementHeightCell.offsetHeight;
		if(divHeight < cellHeight)
		{
			var divTopPadding = (cellHeight / 2 - 9);
			elementDiv.style.paddingTop = (cellHeight / 2 - 10) + 'px';
			elementDiv.style.height = (cellHeight-divTopPadding) + 'px';
		}
		
		/*if(divWidth > cellWidth + 2)
		{
		    //alert('A ' + cellWidth + ' --- ' + divWidth);
			elementCell.style.width = divWidth + 'px';
		}
		else if(cellWidth > divWidth)
		{
		    //alert('B ' + cellWidth + ' --- ' + divWidth);
			elementDiv.style.width = cellWidth + 'px';
		}*/
		
		elementDiv.style.display = 'none';
	}
}

// Transparenz-Filter bei PNG-Bilder für IE 5.5 und IE 6 anwenden
// Aufruf bei $(document).ready() oder mit JS-Code vor </body>:
// <script type="text/javascript">
// fixPng();
// </script>
function fixPng()
{
    if($.browser.msie == true && $.browser.version > 5.5 && $.browser.version < 7.0 && document.body.filters)
    {
        $('img').each(function(){
			if(this.src.match(/\.png$/) != null){
				$(this)
					.css({
						filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+$(this).attr('src')+'\', sizingMethod=\'image\')',
						width: $(this).width()+'px',
						height: $(this).height()+'px'
					})
					.attr('src','images/t3_blank.gif');
			}
        });
	}
}

$(document).ready(function(){
	$('.zoombox').zoombox();
});


