﻿var showShadow = true;

$(document).ready(
	function()
	{
		// Top Dropdown Menue
		$("#dropdownListTop").click(
			function()
			{
				if ($("#dropdownListTop > div:first").is(":hidden"))
				{
					$("#dropdownListTop > div:first").slideDown("normal");
					showShadow = false;
					if (document.all)
					{
						$("#headerImageBorderLeft").hide();
						$(".headerImg").hide();
					}
				}
				else
				{
					if (document.all)
					{
						$("#headerImageBorderLeft").show();
						$(".headerImg").show();
					}
					$("#dropdownListTop > div:first").hide();
				}
			}
		)

		$("#dropdownListTeaser").click(
			function()
			{
				if ($("#dropdownListTeaser > div:first").is(":hidden"))
				{
					$("#dropdownListTeaser > div:first").slideDown("normal");
				}
				else
				{
					$("#dropdownListTeaser > div:first").hide();
				}
			}
		)

		$(document).click(
			function()
			{
				if (!$("#dropdownListTop > div:first").is(":hidden"))
				{
					$("#dropdownListTop > div:first").hide();
					if (showShadow)
					{
						if (document.all)
						{
							$("#headerImageBorderLeft").show();
							$(".headerImg").show();
						}
					}
					else
						showShadow = true;
				}

				if (!$("#dropdownListTeaser > div:first").is(":hidden"))
					$("#dropdownListTeaser > div:first").hide();

				// reset home menues
				$("div.menue:visible").slideUp("normal");
				var unmoeglicheId = 'haberkuck123';
				for (i = 0; i < ($("img.homeButton[id!=" + unmoeglicheId + "]").length); i++)
				{
					var img = ($("img.homeButton[id!=" + unmoeglicheId + "]")[i]);
					img.src = imgDir + "HomeNavigation/" + img.id + ".png"
				}
				$("div.home_background").hide();
			}
		)

		// home menues
		$("img.homeButton").hover(
			function()
			{
				var elementId = $(this).attr("id");
				var menueId = "menue_" + elementId;
				var backgroundId = "background_" + elementId;
				$("div.menue[id!=" + menueId + "]:visible").slideUp("normal");
				$("div.menue[id=" + menueId + "]:hidden").slideDown("normal");
				$("div.home_background[id!=" + backgroundId + "]:visible").hide();
				$("div.home_background[id=" + backgroundId + "]:hidden").show();
				$(this).attr("src", imgDir + "HomeNavigation/" + elementId + "_on.png");
				for (i = 0; i < ($("img.homeButton[id!=" + elementId + "]").length); i++)
				{
					var img = ($("img.homeButton[id!=" + elementId + "]")[i]);
					img.src = imgDir + "HomeNavigation/" + img.id + ".png"
				}
			},
			function() { }
		);

		// kill last borders
		$("#dropdownListTop > div:first > ul > li > a:last").css("border-bottom", "0px");

		// collapse containers
		$("div.collapseContainer > div.header").toggle(
			function()
			{
				var containerId = $(this).parent().attr("id");
				$("div.collapseContainer[id=" + containerId + "] > div.content").slideDown("fast");
				$(this).addClass("open");
			},
			function()
			{
				var containerId = $(this).parent().attr("id");
				$("div.collapseContainer[id=" + containerId + "] > div.content").slideUp("fast");
				$(this).removeClass("open");
			}
		);
	}
);

var searchFieldText = "Suchbegriff";

function setSearchFieldText(searchfield)
{
	if (searchfield.value == searchFieldText)
		searchfield.value = "";
}

function setSearchFieldTextOnBlur(searchfield)
{
	if (searchfield.value == "")
		searchfield.value = searchFieldText;
}

function setImgOn(folder, imgId, fileType)
{
	if (document.getElementById(imgId))
		document.getElementById(imgId).src = imgDir + folder + "/" + imgId + "_on." + fileType;
}

function setImgOff(folder, imgId, fileType)
{
	if (document.getElementById(imgId))
		document.getElementById(imgId).src = imgDir + folder + "/" + imgId + "." + fileType;
}

function validateEmail(textFieldId)
{
	if (document.getElementById(textFieldId).value != "")
	{
		reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		address = document.getElementById(textFieldId).value;
		isValid = reg.test(address);

		if (!isValid)
		{
			alert("Bitte geben Sie eine gültige E-Mail-Adresse ein!");
			document.getElementById(textFieldId).value = "";
		}

		return isValid;
	}
	else
		return false;
}

var currentInfoPopup = "";
var infoPopupTop = (document.all) ? 9 : 10;
var infoPopupLeft = (document.all) ? 275 : 285;

function placeInfoPopup(divId)
{
	obj = document.getElementById(divId);
	objPopup = document.getElementById("infoPopup");

	if (obj)
	{
		var icon = $("#" + divId);
		var iconPosition = icon.position();
		objPopup.style.top = iconPosition.top - 10 + "px";
		objPopup.style.left = iconPosition.left + 25 + "px";
	}
}

function hideInfoPopup(iconId)
{
	objPopup = document.getElementById("infoPopup");
	if (currentInfoPopup == iconId && objPopup.style.display == "block")
	{
		objPopup.style.display = "none";
	}
}

function showInfoPopup(iconId, text)
{
	objPopup = document.getElementById("infoPopup");
	objText = document.getElementById("infoPopupText");

	if (currentInfoPopup == iconId && objPopup.style.display == "block")
	{
		objPopup.style.display = "none";
	}
	else
	{
		currentInfoPopup = iconId;
		
		if (objPopup)
			objPopup.style.display = "block";

		if (objText && text != "")
			objText.innerHTML = text;

		placeInfoPopup(iconId);
	}
}

function textboxLengthCheck(tbId, length)
{
	tb = document.getElementById(tbId);
	
	if (tb)
	{
		if (tb.value.length > 0 && tb.value.length < length)
		{
			alert("Die Eingabe muss mindestens " + length + " Zeichen lang sein");
			tb.value = "";
		}
	}
}
