var menu_punkt = null;
var menu = null;
var hideExecute = null;
var submenu_hide_timeout = 0.5;

function menu_start(){
	buildAll();
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_menu")) & ("A" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.onmouseover = link_in;
	    }
	 }
	});
}

function link_in(){
	hideAll();
	menu_punkt = Element.extend(this);
	aparent = menu_punkt.up();
	aparent.descendants().each(function(top) {
	 if((top.hasClassName("popup_hover_js")) & ("UL" == top.tagName)){
		menu = top;
		menu.show();
    	menu.onmouseover = menu_in;
		menu.onmouseout = null;
		menu_punkt.onmouseout = link_out;
	 }
	});
	return false;
}

function link_out() {
	menu_punkt.onmouseout = null;
	if (menu.onmouseout == null) submenu_tryhide();
}

function menu_out() {
	menu.onmouseout = null;
	if (menu_punkt.onmouseout == null) submenu_tryhide();
}

function menu_in() {
	menu.onmouseout = menu_out;
}

function submenu_tryhide() {
	if (hideExecute) hideExecute.stop();
	hideExecute = new PeriodicalExecuter(submenu_hide, submenu_hide_timeout);
}

function submenu_hide() {
	if (hideExecute) hideExecute.stop();
	if (!menu.onmouseout && !menu_punkt.onmouseout) {
		menu.onmouseover = null;
		hideAll();
	}
}

function hideAll() {
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_hover_js")) & ("UL" == top.tagName)){
	    if(Element.visible(top)) {
	    	top.hide();
	    }
	 }
	});
}

function buildAll() {
	$('menu').descendants().each(function(top) {
	 if((top.hasClassName("popup_hover")) & ("UL" == top.tagName)){
    	top.hide();
		top.addClassName("popup_hover_js");
		top.removeClassName("popup_hover");
	 }
	});
}

/**
 *
 * @access public
 * @return void
 * void klick( rubrik_k, rubrik, mall, firma_id, aktion, table)
 **/
function gu(link_obj, link_mode, para)
{
//	alert(link_mode+"_");
	var destinationUrl = web_stammverzeichnis + "click.phtml?url=" + escape(link_obj.href) + "&mode=" + escape(link_mode) + "&p=" + escape(para);
//	alert(destinationUrl);
	if(link_obj != null && link_obj.target != null && link_obj.target.toLowerCase() == '_blank')
	{
		window.open(destinationUrl);
	}
	else
	{
    	document.location.href = destinationUrl;
    }
    
    return false;
}

function openPopupSendArticle()
{
	var currentUrl = document.location.href+"";
	var location = "popup=true&action=sendArticle";

	if (currentUrl.indexOf("#")>-1)
	 currentUrl = currentUrl.substr(0,currentUrl.indexOf("#"));

	if(currentUrl.indexOf("?") == -1)
		location = currentUrl+"?" + location;
	else
		location = currentUrl+"&" + location;
	
	window.open(location, 'sendArticle', 'width=500,height=520,screenX=0,screenY=0,scrollbars=yes,resizable=no');
}
function openPopupSendInvitation(url)
{
	
	var currentUrl = "";
	if (url==null)
	  currentUrl = document.location.href+"";
	 else 
	  currentUrl = url; 
	var location = "popup=true&action=sendInvitation";

	if (currentUrl.indexOf("#")>-1)
	 currentUrl = currentUrl.substr(0,currentUrl.indexOf("#"));

	if(currentUrl.indexOf("?") == -1)
		location = currentUrl+"?" + location;
	else
		location = currentUrl+"&" + location;
	
	window.open(location, 'sendArticle', 'width=480,height=520,screenX=0,screenY=0,scrollbars=yes,resizable=no');
}

/**
 *
 * @access public
 * @return void
 * void validRubrik( rubrik_k )
 **/
function validRubrik(rubrik_k){
    document.getElementById('handel').disabled = 'disabled';
    document.getElementById('dienstleistung').disabled = 'disabled';
    document.getElementById('bau_handwerk').disabled = 'disabled';
    document.getElementById('gastronomie').disabled = 'disabled';
    document.getElementById('gesundheit').disabled = 'disabled';
    document.getElementById('b2b').disabled = 'disabled';
    document.getElementById('bildung').disabled = 'disabled';
    document.getElementById('neue_branche').disabled = 'disabled';
    document.getElementById(rubrik_k).disabled = false;
}

	/*
	 * @author dominic
	 * fix firefox layout anker bug 
	 * */
	var isMSIE = document.all?true:false;
	var checkScrollTimeout=null;
	 function checkScroll(step)
	 {
		if (step==null) step=0;
//		if ( isMSIE ) return;
		if (checkScrollTimeout!=null) clearTimeout(checkScrollTimeout); 
		var withAnker = false;
		if (location.href.indexOf('#')>0)
		withAnker = true;
		if ( withAnker )
		{
			var unten = document.getElementById('unten');
			if (unten != null)
			 {
				var untenScrollTop = unten.scrollTop; 
				if (untenScrollTop>0)
				 {
					unten.scrollTop = 0;
					var layoutTopSpace = 160;
					document.documentElement.scrollTop = /*document.documentElement.scrollTop + */layoutTopSpace+untenScrollTop;
					}
			}
		} // Falls nachtr�gilch ein Anker zukommt muss es auch klappen...
			if (step < 5 ) 
				checkScrollTimeout = setTimeout("checkScroll("+(step+1)+");",250);
			else 
				checkScrollTimeout = setTimeout("checkScroll("+(step+1)+");",1000);
	}
	setTimeout("checkScroll(0)",50);
	 
script_loaded = true;

function loginForm()
{
	var formF = document.getElementById("frmLogin");
	var newUrl = document.location+"";
	var username =formF.txtLoginUsername.value+""; 
	if (
		( username == "www.oberlahn.de" && newUrl.indexOf("www.oberlahn.de")>-1 ) 
		|| ( username=="www.lahn-dill-live.de" && newUrl.indexOf("www.lahn-dill-live.de")>-1) 
		) {
		newUrl = newUrl.replace(/http\:/, "https:");
//		alert(newUrl);	
		if (!(newUrl.indexOf("https") >= 0) && username=="www.lahn-dill-live.de") 
			newUrl = "https://www.lahn-dill-live.de";
		if (!(newUrl.indexOf("https") >= 0) && username=="www.oberlahn.de") 
			newUrl = "https://www.oberlahn.de";
		formF.action=newUrl;
	}
}
function hideLoginOSDBox()
{
	clearTimeout(updateDarkHeightTimer);
	document.getElementById('darkfader').style.display="none";
	document.getElementById('login_osd').style.display="none";
}
function showLoginOSDBox(msg)
{
	if (typeof oldLoginAlert != "undefined" && oldLoginAlert)
	{
		alert( msg );
		return; 
	}
	if (msg!=null)
	{
		document.getElementById('loginBoxMsgDiv').innerHTML=msg;
	}
	document.getElementById('darkfader').style.display="block";
	document.getElementById('login_osd').style.display="block";
	//  alert(document.documentElement.scrollTop);
	updateDarkHeight();
}


var updateDarkHeightTimer = 0;
function updateDarkHeight()
{
	clearTimeout(updateDarkHeightTimer);
	document.getElementById('darkfader').style.height=(document.body.scrollHeight+document.documentElement.scrollTop)+"px";
	var newTop = (140+document.documentElement.scrollTop);
	if (newTop<240) newTop=240;
	newTop+="px";
	document.getElementById('login_osd').style.top=newTop;
	updateDarkHeightTimer = setTimeout("updateDarkHeight();",50);
}


function showPopupLoginOSD( msg )
{
	if (typeof oldLoginAlert != "undefined" && oldLoginAlert)
	{
		alert( msg );
		return; 
	}
	if (typeof opener != "undefined" && opener != null && opener.showLoginOSDBox) // Opener existiert und hat loginbox funktion
	{
		if (opener.showLoginOSDBox && !opener.is_registered) // Gibt es die Funktion? (Falls nicht schon eingeloggt!)
		{
			opener.showLoginOSDBox(msg);
			opener.focus();
			popupPollForRegistered();
		}
		else {
			document.location.reload();
		}
	}
	else // Kein geeigneter Opener da 
	{
//		alert("dann nich");
		opener = window.open("/?showLoginOSDBox","_blank");
		popupPollForRegistered();
	}
	
} 
// Wird aktiviert sobald sich eingeloggt werden soll, pollt ob eingeloggt ist
var popupPollForRegisteredTimer = 0;
function popupPollForRegistered()
{
	clearTimeout(popupPollForRegisteredTimer);
	var done = false;
	try {
	if (typeof opener != "undefined") 
		if (opener) 
			if (typeof opener.is_registered != "undefined") 
				if (opener.is_registered) {
					//focus();
					//opener.chld=this;
					//opener.setTimeout('chld.focus();',1);
					// Fokus holen, scheinbar nur durch Alert zu erreichen...
					alert("Du bist nun eingeloggt und kannst die Funktion jetzt verwenden. ");
					document.location.reload();
					// document.location.href = document.location.href + ""; // Reload without post
					done = true; 
				}
	} catch (e){alert(e);}
	if ( ! done)
	popupPollForRegisteredTimer = setTimeout("popupPollForRegistered();",500)
}
/*
var chldToFocus = null;
function giveMeFocus(chld)
{
	chldToFocus = chld;
}
function focusPoller()
{
	if (chldToFocus!=null)
	{
		alert("ok!");
		chldToFocus.focus();
		//chldToFocus = null;
	}else
	setTimeout("focusPoller();",100);
}
setTimeout("focusPoller();",100);
*/
function putMaail(tld, dom, main)
{
	var full = main+"@"+dom+"."+tld;
	document.write("<a href='mailto:"+full+"'>"+full+"</a>");
}
function dge(e)
{
	return document.getElementById(e);	
}
