/*
	created by Michael Welt <michael.welt@cusox.com>
	&cpy; 2007 cusox <www.cusox.com>
	its crossbrowser implemented and should work for 
	IE5.5 and greater and 
	Firefox1.5 and greater
*/

/*
	init the hover menus if existent max menuitems 9
*/
function initMenus()
{	

	
	/*initial ofset of the menus*/
	
	var off_set=30;
	
	
	/* Set up hover ids */
	/*for(i = 1; i < 6; i++) {
		var strBlankHover = 'hover';
		
		if(!document.getElementById('hover')) continue;
		
		document.getElementById('hover').setAttribute("id", strBlankHover+i);
		if(document.getElementById(strBlankHover+i) ) {
			alert('set a hover with id '+strBlankHover+i);
		}
	}*/
	
	
	
	
	for(i = 1; i < 6 ; i++)
	{
		/*build current menu id and hover id*/
		var menu_id = 'menu'+i;
		var hover_id = 'hover'+i;
		/*if no such menu break end return*/
		if(!document.getElementById(menu_id))
			break;
			
		/*move hover*/
		
		var style = document.getElementById(hover_id).style;
		style.position = "absolute";
		style.left = off_set + "px";
		
		
		
		/*and now some sweet heart fix for the IE*/
		if(document.all)
		{
			style.display = ''; /*switching the hover for a short moment on to get height*/
			
			/*if the div is rendered because he has content so build the workaround!*/
			if(document.getElementById(hover_id).clientHeight)
			{
				var iframe = document.createElement('iframe');
				var height = document.getElementById(hover_id).clientHeight - 10;
				iframe.style.position = "absolute"
				iframe.style.display = "none";
				iframe.style.width = "300px"
				iframe.style.height = height + "px";
				iframe.style.left = off_set + "px";
				iframe.id = "iebug" + i;
				iframe.style.top = 42;
				document.getElementById('mainnavi').appendChild(iframe);
			}
			style.display = 'none'; /*switching the hover off again*/
		} 
		
		/*register mousehandler*/
		document.getElementById(menu_id).onmouseover = mouseOver;
		document.getElementById(menu_id).onmouseout = mouseOut;
		document.getElementById(hover_id).onmouseout = mouseOut;
		
		/*calculate the offset for the next hovermenu*/
		off_set = off_set + document.getElementById(menu_id).clientWidth + 1;
		
	}
}

/*
	this saves the current visible hovermenu, for closing it later on
*/
var curr_hover_id = 0;

/*
	it shows the corresponding hover menu to the tab on which the mouse
	is over. 
*/
function mouseOver(e)
{
	/*firefox uses param e IE uses window.event :(*/
	if (!e) var e = window.event;
	/*firefox uses e.srcElement IE uses e.target :(*/
	var tg = (window.event) ? e.srcElement : e.target;
	/*firefox gives back the span tag IE gives directly the A tag back*/
	if(tg.nodeName != 'A')
		tg = tg.parentNode;	
	/*mark the current hover div as shown*/	
	curr_hover_id = tg.id.substr(4,2);
	/*show it*/
	showHover(curr_hover_id);	
}

/**
	the hover div can't be close if one of the following
	things happens:
	
	1.we are at the link and proceed foreward to the div
	2.we are at the div and proceed foreward to an childNode
	inside of the div
	3.we are at the div and proceed foreward to the mannavi link
	belonging to the hovermenu div
*/
function mouseOut(e)
{
	/*firefox uses param e IE uses window.event :(*/
	if (!e) var e = window.event;
	/*firefox uses e.srcElement IE uses e.target :(*/
	var tg = (window.event) ? e.srcElement : e.target;
	/*same procedure for the to Element*/
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	
	if(!tg || !reltg)
	{
		hideHover(curr_hover_id);
		return;
	}
	
	/*went over to the div do nothin*/
	/*we could also walk straight into the mannavi span thus we also do nothing the only possibly child
	element of the mainnavi <a>*/

	/*the IE throws Exceptions if we try to get parent Nodes of html or body
	thus we ask for it and quit and done*/
	var hover_id = 'hover'+curr_hover_id;
	var menu_id = 'menu'+curr_hover_id;
	while(reltg.nodeName != 'HTML')
	{
		if(reltg.id == hover_id || reltg.id == menu_id)
		{
			return;
		} 
		
		if(!reltg.parentNode)
		{
			hideHover(curr_hover_id);
		}
		
		reltg = reltg.parentNode;
	}
	
	hideHover(curr_hover_id);
}


/*
	show the hovermenu with id id
*/
function showHover(id)
{
	//alert('show hover: '+'hover'+id);
	var h_style = document.getElementById("hover"+id).style;
	h_style.display = '';

	if(document.all && document.getElementById("iebug"+id))
	{
		var iframe_style = document.getElementById("iebug"+id).style;
		iframe_style.display = '';
	}
}


/*
	hide the hovermenu with id id
*/
function hideHover(id)
{
	//alert('hide hover: '+'hover'+id);
	var hover_menu_style = document.getElementById("hover"+id).style;
	hover_menu_style.display = 'none';
	
	if(document.all && document.getElementById("iebug"+id))
	{
		var iframe_style = document.getElementById("iebug"+id).style;
		iframe_style.display = 'none';
	}
}

/*
additional pagespecific scripts
*/

function popup(url,title,width,height)
{
	var title_ = title;
	var url_ = url;
	var args = "width=" + width + ",height=" + height + ", scrollbars=yes, resizeable=yes";
	window.open(url_,title_,args);
}

function sendpage()
{
	var url = "send_page.php?url=" + this.document.location.href;
	popup(url,"",550,630);
}

function kontakt_submit()
{
	var form = document.getElementById('kontakt_form');
	
	if(form.email.value == "")
  	{
   		alert("Bitte geben Sie Ihre E-Mail-Adresse ein!");
   		form.email.focus();
		return false;
  	}
    if(form.email.value.indexOf('@') == -1 || form.email.value.indexOf('.') == -1)
  	{
   		alert("Keine gueltige E-Mail-Adresse!");
   		form.email.focus();
   		return false;
  	}
	if(form.anliegen.value.length < 1)
	{
		alert("Bitte formulieren sie ihr Anliegen!");
   		form.anliegen.focus();
   		return false;
  	}
	
	return true;
}

function kontakt_reset()
{
	pruef=window.confirm("Sind Sie sicher, dass Sie die Eingaben verwerfen wollen?");
	if(pruef)
		return true;
	return false;
}

function sendpage_submit()
{
	var form = document.getElementById('sendpage_form');
	
	if(form.freundemail.value == "")
  	{
   		alert("Bitte geben Sie die E-Mail-Adresse ihres Freundes ein!");
   		form.freundemail.focus();
		return false;
  	}
    if(form.freundemail.value.indexOf('@') == -1 || form.email.value.indexOf('.') == -1)
  	{
   		alert("Keine gueltige E-Mail-Adresse ihres Freundes!");
   		form.freundemail.focus();
   		return false;
  	}
	if(form.email.value == "")
  	{
   		alert("Bitte geben Sie Ihre E-Mail-Adresse ein!");
   		form.email.focus();
		return false;
  	}
    if(form.email.value.indexOf('@') == -1 || form.email.value.indexOf('.') == -1)
  	{
   		alert("Keine gueltige E-Mail-Adresse!");
   		form.email.focus();
   		return false;
  	}
  	
		
	return true;
}

function sendpage_reset()
{
	pruef=window.confirm("Sind Sie sicher, dass Sie die Eingaben verwerfen wollen?");
	if(pruef)
		return true;
	return false;
}

