// SUMMARY: init(), showmenu(mnu), menuOff(mnu), checkemail(frm, mesg),

// ** GENERAL VALUES ** ----------------------------------------------------
var ns4 = (document.layers) ? true:false;
var ie4 = (document.all) ? true:false;
var DOM = (document.getElementById) ? true:false;	
var CSS2 = (document.documentElement && document.documentElement.style && document.documentElement.style.getPropertyValue) ? true: false;
var macIE5 = navigator.appVersion.indexOf('MSIE 5.0'); macIE5 = (macIE5 != -1) ? true:false;

var varCurrent = "";
var fixedmenu = -1;
var fixedlink = 0; 
var loaded = false;
var counter=1000;
var POSY=20;

function setKoordinaten(left,top){
  this.leftPosition = left;
  this.topPosition = top;
}

var arrMnuNamen = new Array('mnuv', 'mnut', 'mnup' , 'mnub', 'mnua'); 
var arrMnuPos = new Array();

// Koordinaten der Menus - bei Browsern ohne Javascript gilt die Einstellung aus der vb24.css datei
arrMnuPos ["mnuv"] = new setKoordinaten(134,POSY);
arrMnuPos ["mnut"] = new setKoordinaten(255,POSY);
arrMnuPos ["mnup"] = new setKoordinaten(375,POSY);
arrMnuPos ["mnub"] = new setKoordinaten(495,POSY);
arrMnuPos ["mnua"] = new setKoordinaten(575,POSY);

var initWidth  = window.innerWidth;
var initHeight = window.innerHeight;


// ** FUNCTIONS ------------------------------------------------------------
function netscapeResize(){
  if (navigator.appName == 'Netscape'){
	if ((window.innerWidth != initWidth) || (window.innerHeight != initHeight)){
	  location.reload();
	}
  }
}

function testmouseout(name) {			
	
	if(!loaded) return true;
										
	over = false;
	setTimeout('menuOff("'+name+'" )', 1500);
}

function menuOff(name) {
	
	if (!loaded || !name || over == true ) return;
	if(fixedmenu > 0 ) {
			
		if(arrMnuNamen[fixedmenu-1] == name || 
					   (arrMnuNamen[1] == name )){
			return;
		}
	}

	popMenu(name,'off');
}

function showmenu(name) {			
	
		if (!loaded)  return;
			
		over = true;

		if (varCurrent != "" && varCurrent != name){
			hideOthers(name);
		}
		
		posMenu(name, arrMnuPos[name].leftPosition, arrMnuPos[name].topPosition);
		popMenu(name, 'on');
		varCurrent= name;
		//alert('showmenu done' + varCurrent + " " + varCurrent.substr(0,3) );
}

function hideOthers(name) {
	
	for (var i = 0; i < arrMnuNamen.length; i++) {
		if (arrMnuNamen[i] != name && i != fixedmenu -1 && 
						(arrMnuNamen[i] != "mnu2" || (fixedmenu !=6 && fixedmenu != 7 ))) {
				popMenu(arrMnuNamen[i],'off');
				posMenu(name, arrMnuPos[name].leftPosition, arrMnuPos[name].topPosition);
		}
	}
}

function keepopen(name) {
	over=true;
}

function dompopmenu(obj, vstate,dstate,zindex)
{
	if(!obj || !obj.style) return;
	
	obj.style.visibility = vstate;
	obj.style.display = dstate;
	obj.style.zIndex = zindex;
	
}

function popMenu(name,status) {			// show/hide a given layer

	var vstate = "hidden";
	var dstate = "none";
	var zindex = "999";
	
	if(!loaded) return;
	
	if(status == 'on') {
			vstate = "visible";
			dstate = "block";
			zindex = counter++;
	}
							
	if (DOM) {
		dompopmenu(document.getElementById(name), vstate, dstate, zindex);
	} else if (ie4){
		document.all.item(name).style.visibility = dstate;
	} else if (ns4) {
		document.layers[name].visibility = vstate;
	}
}

function posMenu(name,left,top){

	if(!loaded) return; 
	
	if(DOM && ! macIE5 ) {
		if(CSS2){
			document.getElementById(name).style.setProperty(
										'left',left+"px",null);
			document.getElementById(name).style.setProperty(
										'top',top+"px",null);
		} else {	
			document.getElementById(name).style.left = left+"px";
			document.getElementById(name).style.top = top+"px";
		}
		
	} else if (ie4 && ! macIE5){
		document.all[name].style.left = left;
		document.all[name].style.top = top;
	} else if (ns4) {
		document.layers[name].left = left;
		document.layers[name].top = top;
	}
}

/* works only in ie6 */
function returnMenu(name){

	if(!loaded) return;
	
	posMenu(name,-500,-500);
	
}
	
function fixWinIE(){

	// EVERY DIV WITH FLOAT SET NEEDS TO BE PROSERVERD FROM THE IE6 BUG
	
}


// markitem ist mnu 0 oder -1, wird nichts markiert, ist dest = 0 wird nur ein menu aiugeschaltet
function markitem(mnu,dest) {
	
	var node, i, j;
	
	if(mnu < 1 || mnu >5) return;
		
	showmenu(arrMnuNamen[mnu-1]);

	if(!DOM||dest <1 ) return null;

	node = document.getElementById(arrMnuNamen[mnu-1]);
	if(!node ) return null;

	for(i=0,j=-1; i< node.childNodes.length && j != dest -1; i++){
		// alert("debug " + node.childNodes[i].nodeName + "; looking for " + dest + " =? " + j + "/" + node.childNodes.length);
		if (node.childNodes[i].nodeName == "LI" ) j++;
	}
	
	//DEBUG
	if ( j == -1  ) {
			alert("void menu structure 2 i="+i + " j= " + j + "dest = " + dest);
			return null;
	}
	node=node.childNodes[i-1];
			
	for(i=0; i< node.childNodes.length; i++){
		if (node.childNodes[i].nodeName == "A" ) {
				node.childNodes[i].style.background = "#ffffff"; // no ";" color: hardcoded! 
				break;
		}
	}
}
function preload_ifmozilla(){
	if (document.addEventListener) {
			    document.addEventListener("DOMContentLoaded", preinit, null);
	}
}
// wird aufgerufen bevor das ganze Dokument geladen ist
function printhtml(){

	var a;
	var b;
	
	if(document.getElementById && (a=document.getElementById('printimg'))){
		b=a.src;
		a.src=printimgname;
		if(macIE5 == 0){
			window.print();
			a.src=b;
		}
		else {
			
			if(fadeobj)	{
						fadeobj=0;
						a.style.display="none";
			}
			a.src=printimgname;
			confirm("Drucken sie die Seite jetzt mit ihrem Browser aus.");
			
		}
	}
}

// --- INIT FUNCTIONS ---------------------------------

function init(){

	if(loaded == true ) // CHECK IF init 
		return;
		
	loaded = true;
	
	if (ns4) {
		window.captureEvents(Event.RESIZE);
		window.onresize = netscapeResize;
		document.alinkColor="#27365c";
		document.vlinkColor="#27365c";
	}
	if (!ie4 && DOM) {
		document.getElementById(arrMnuNamen[0]).style.display = "";
		document.getElementById(arrMnuNamen[1]).style.display = "";
		document.getElementById(arrMnuNamen[2]).style.display = "";
		document.getElementById(arrMnuNamen[3]).style.display = "";
	}
	
	for(a=0; a<arrMnuNamen.length && a <10;a++){
		returnMenu(arrMnuNamen[a]);
	}
	
	if(fixedmenu > 0 && fixedmenu < 6)
		markitem(fixedmenu,fixedlink);
	
	if(document.all && window.attachEvent) 
		window.attachEvent("onload",fixWinIE);
	
}

// sonstige javascript funktionen

// wird bei Mozilla und IE_WIN32 Browsern gestartet, bevor die Bilder komplett geladen sind.
function preinit(){
	if(document.getElementById && document.getElementById('mnu5')){
	// nur falls, der letzte tag (das mnu5) gelesen ist, wird init gestartet. (IE Absturzmoegl.)
		//DEBUG
		//alert("PRELOAD of JAVASCRIPT MENU: is fine");
		setTimeout('init(2)',50);
	}
}


//-- fuer Email Adressen checks

// arg: Das Formular, darin muss sich ein Feld namens email befinden
var alertlocked=0;

function checkemail(formular, alertmsg){

	if(formular && formular.email){
		
		if(alertmsg == "")
			alertmsg = "Ungueltige Eingabe: E-Mailadresse nicht erkannt.";
		
		with(formular){
		
			var p = email.value;
			
			if (p=p.replace (/^\s+/,'')) email.value = p; // Remove Leading  and Trailing Spaces
			if (p=p.replace (/\s+$/,'')) email.value = p; // Remove Leading  and Trailing Spaces
				
			if( p.search(/^[^ ]+@[^.][^.]+\.[^ ][^ ]+$/) == -1) {
				if(alertlocked == 0){ // wurde zweimal aktiviert
					
					alertlocked=1; //Verhindert eine Formular-Validierung solange Alertmsg auf Bildschirm
					alert(alertmsg); 
					alertlocked=0;
				}
				email.value="";
				
				return false;
			}
			return true;
		}
	}
	
}
function swapimg(name){
	
	var img = document.getElementById("ilogo");
	img.src="img/"+name;
	alert(img.src);
}
function checkfrm(formular){
	var errstr = "";
	
	with(formular) {
		
		// LANGUAGE SPEZIFIC
		if(name1.value == "" ) errstr += "Nachname, ";
		if(inhalt.value == "" ) errstr +=  "einen Feedback-Text, ";
		if(email.value == "" || tel.value ) errstr +=  "Email oder Telefon, ";
			
		if(errstr == "") {
			submit();
			return true;
		}
	}
	
	alert("Bitte geben sie in folgende Felder einen Text ein: \012" + errstr +" !");
	return false;
}

// von Thaus Java Script Tutorial
function X_readCookie(name) {

	if (document.cookie == '') { 
    
   // there's no cookie, so go no further
    
	return false;

	} else {
    
   // there is a cookie

	var firstChar, lastChar;

	var theBigCookie = document.cookie;

	firstChar = theBigCookie.indexOf(name);
	
   // find the start of 'name'

	if(firstChar != -1)  {
	
   // if you found the cookie

	firstChar += name.length + 1;
	    
   // skip 'name' and '='
	   
	lastChar = theBigCookie.indexOf(';', firstChar);
	    
   // Find the end of the value string (i.e. the next ';').
	    
	if(lastChar == -1) lastChar = theBigCookie.length;
	    
	return unescape(theBigCookie.substring(firstChar, lastChar));

	} else {
	
   // If there was no cookie of that name, return false.
	
	return false;
	
	}

    }
}
// wird bei Mozilla und IE_WIN32 Browsern gestartet, bevor die Bilder komplett geladen sind.
function preinit(){
	if(document.getElementById && document.getElementById('mnu5')){
	// nur falls, der letzte tag (das mnu5) gelesen ist, wird init gestartet. (IE Absturzmoegl.)
		//DEBUG
		//alert("PRELOAD of JAVASCRIPT MENU: is fine");
		setTimeout('init(2)',50);
	}
}
function preload_ifmoz(){
	if (document.addEventListener) {
			    document.addEventListener("DOMContentLoaded", preinit, null);
	}
}