var WinPopUp;
var EventTriggered = false;

function search_init()
{
	if (document.getElementById)
	{
		var search_init;

		if (search_init = document.getElementById('input_words'))
		{
			search_init.focus();
		}
	}
}

function NeuesFenster(name, url, width, height)
{
	var last_left=10;
	var last_top=10;
	if (WinPopUp && WinPopUp.close) WinPopUp.close();
	WinPopUp=window.open(url,"displayWindow",'width=' + width + 
			',height=' + height + 
			',resizable=0,scrollbars=auto,menubar=no,status=no');
	WinPopUp.resizeTo(width,height);
	WinPopUp.focus();
}

function NeuesFensters(name, url, width, height)
{
	var last_left=10;
	var last_top=10;
	if (WinPopUp && WinPopUp.close) WinPopUp.close();
	WinPopUp=window.open(url,"displayWindow",'width=' + width + 
			',height=' + height + 
			',resizable=0,scrollbars=yes,menubar=no,status=no');
	WinPopUp.resizeTo(width,height);
	WinPopUp.focus();
}

function check_events(node)
{
	/*if (navigator.userAgent.lastIndexOf("MSIE") != -1 && navigator.userAgent.lastIndexOf("Mac") != -1)
	{
		EventTriggered = true;
		return;
	}*/
	
	if (document.getElementById && EventTriggered == false)
	{
		if (node == document.getElementById('header'))
		{
			// Home
			parent.window.location.href ='/';
		}
		else
		{
			// Main Nav
			parent.window.location.href = node.firstChild.getAttribute('href');
		}
	}

	// Prevent second execution on single click:

	EventTriggered = true;
}

var last_class;

function set_menu_events(node)
{
	if (node == null) return;

	var dummy;
	var i;
	
	if(document.getElementById && document.createTextNode)
	{
		if (node.nodeType == 1)
		{
			if (node.nodeName == 'TD')
			{
				dummy = node.className;
				if (dummy != 'active')
				{
					node.onmouseover = function() { this.className = 'hover'; };
					node.onmouseout = function() { this.className = ''; };
				}

				if (node.firstChild.nodeName == 'A')
				{
					//node.onclick = function() { window.location.href = node.firstChild.getAttribute('href'); };
					node.onclick = function () { check_events(node); };
					node.firstChild.onfocus = function () { last_class = node.className; node.className = 'hover'; };
					node.firstChild.onblur = function () { node.className = last_class; };
				}
			}

			if (node.childNodes != null)
			{
				for (i = 0; i < node.childNodes.length; i++)
				{
					set_menu_events(node.childNodes[i]);
				}
			}
		}
	}
}

function preload_images()
{
	if (document.images) {
		plan_a = new Image; plan_a.src = "images/stadtplan_a.gif";
		plan_b = new Image; plan_b.src = "images/stadtplan_b.gif";
		plan_c = new Image; plan_c.src = "images/stadtplan_c.gif";
		plan_d = new Image; plan_d.src = "images/stadtplan_d.gif";
		plan_e = new Image; plan_e.src = "images/stadtplan_e.gif";
		plan_f = new Image; plan_f.src = "images/stadtplan_f.gif";
		plan_g = new Image; plan_g.src = "images/stadtplan_g.gif";
		plan_kt = new Image; plan_kt.src = "images/stadtplan_kt.gif";
		plan_p = new Image; plan_p.src = "images/stadtplan_p.gif";
	}
}


/* Function that swaps images. */

function di20(id, newSrc) {
    var theImage = FWFindImage(document, id, 0);
    if (theImage) {
        theImage.src = newSrc;
    }
}

/* Functions that track and set toggle group button states. */

function FWFindImage(doc, name, j) {
    var theImage = false;
    if (doc.images) {
        theImage = doc.images[name];
    }
    if (theImage) {
        return theImage;
    }
    if (doc.layers) {
        for (j = 0; j < doc.layers.length; j++) {
            theImage = FWFindImage(doc.layers[j].document, name, 0);
            if (theImage) {
                return (theImage);
            }
        }
    }
    return (false);
}



var dropdown_timeout;

function dropdown_toggle(elem, mode)
{
	var i;
	var k;
	var dropdowns;

	if (elem)
	{
		for (i = 0; i < elem.childNodes.length; i++)
		{
			if (elem.childNodes[i].nodeName == 'UL')
			{
				if (typeof mode == 'undefined') mode = (elem.childNodes[i].style['display'] != 'block')? true : false;
				if (mode == true)
				{
					dropdown_stoptimeout();

					// Ggf. andere Dropdowns schließen
					dropdowns = document.getElementsByTagName('div');
					for (k = 0; k < dropdowns.length; k++)
					{
						if (dropdowns[k].className == 'dropdown') dropdown_toggle(dropdowns[k], false);
					}

					elem.childNodes[i].style['display'] = 'block';
					elem.childNodes[i].style['zIndex'] = '100';
				}
				else
				{
					elem.childNodes[i].style['display'] = 'none';
					elem.childNodes[i].style['zIndex'] = '50';
				}
				break;
			}
		}
	}
	return(true);
}

function dropdown_toggle_by_name(name, mode)
{
	var elem = document.getElementById(name);
	if (elem) return(dropdown_toggle(elem, mode));
}

function dropdown_stoptimeout()
{
	if (dropdown_timeout) window.clearTimeout(dropdown_timeout);
}

function dropdown_close_delayed(name)
{
	dropdown_stoptimeout();
	dropdown_timeout = window.setTimeout('dropdown_toggle_by_name(\'' + name + '\', false)', 200);
}

function redirect(uri)
{
	if (uri && uri != '')
	{
		document.location.href = uri;
	}
}

//GIS Kooperation

function gis_popup(gis)
{
	var nw = window.open(gis,"gis_window","width=840,height=840,menubar=no,resizable=yes,scrollbars=yes");	
	nw.focus();
	if (nw) return false;
	else return true;
}
