var LAY = (document.layers && (!window.opera)) ? true : false;
var DOM = (document.getElementById) ? true : false ;
var NS6 = (document.getElementById && !document.all) ? true : false;
var OP = (navigator.userAgent.indexOf("Opera")>-1) ?  true : false;
var IE = (document.all && !OP) ?  true : false;

var ich_scrolle_gerade = false;
var scrY = 0;
var scrXOld = 0;
var scrYOld = 0;
var canScroll = false;
var bannerCounter = 0;

if (LAY)location.href = "ns.html";
if (window.captureEvents){
		window.captureEvents(Event.LOAD || Event.CLICK || Event.MOUSEOVER || Event.MOUSMOVE || Event.SCROLL || Event.RESIZE);
}
window.onload = init;

function init(){
	//alert(screen.availWidth);
    //if (OP) alert(screen.availWidth);
	captureMenue();
	setBanner();
	if(document.getElementById("Zeigepunkt")) captureMap();

	//if (window.location.search.match(/blockhaeuser/)) captureMap();

}
/*function angekommen() {
	 alert ("angekommen");
return
}
*/

/* Navileiste überwachen:  */

function captureMenue(){
	var i=1;
	document.menk = new Array();
	while (document.menk[i] = "menk"+i){
		//if (i==4) continue;
		if (DOM){
			  capObj = document.getElementById(document.menk[i]);
		}
		else if (LAY){
			  capObj = document.layers[document.menk[i]];
		}
		//alert (capObj.id);
		if (document.captureEvents){
			  //alert(menk);
			  window.captureEvents(Event.MOUSEDOWN |Event.MOUSEOVER | Event.MOUSEOUT );
		}
		//typ = typeof(document);
		if (capObj){
			  capObj.onmouseover = openMenu;
			  capObj.onmouseout = checkMenu;
			  //capObj.onmousedown = down;
			  i++;
		}
		else {
			document.menk.pop();
			break;
		}
	}
return
}


function openMenu(evt) {
	if(typeof(window.event) == 'object') {
		 evntTarget = window.event.srcElement.id;
	}
	else {
		evntTarget = evt.target.id;
	}
	var activeMenue = evntTarget.replace(/menk\B/,"men");
	if (DOM){
		aMen = document.getElementById(activeMenue);
		if (aMen.childNodes.length > 0){
	        aMen.style.visibility = "visible";
	        aMen.style.left = document.getElementById(evntTarget).offsetLeft;
		}
		//alert (innerLinkWidth);
	}

return
}

function checkMenu(evt) {
	if(typeof(window.event) == 'object') {
		 evntTarget = window.event.srcElement.id;
	}
	else evntTarget = evt.target.id;
	var activeMenue = evntTarget.replace(/menk\B/,"men");
	//alert(document.menk.length + " - " +activeMenue+ " " + evt.type);
	for (var i = 0; i<document.menk.length; i++){
		var obId = String('men'+i);
		if (obId != activeMenue){
			hide(obId);
		}
	}
return
}
// Ende Navileiste überwachen

//
function setBanner(){
	if (document.getElementById("banner")){
	    document.bc = document.getElementById("linkframe").offsetWidth;
		//Bannerweite soll = Menüweite:
	    var banner_obj = document.getElementById("banner");
		banner_obj.style.width = (!OP) ? document.bc+"px" : document.bc;

		var leftArrow = (document.all) ? leftarrow : document.getElementById("leftarrow");
		//var restPlatz = Fensterweite() - leftArrow.offsetWidth-30;
	    leftArrow.style.left =  (!OP) ? parseFloat(document.bc)+10+"px" : parseFloat(document.bc)+10; //banner_obj.style.width;
	    document.bannerArr = new Array();
	    var bannerId = "";
	    var i = 0;
	    while (bannerId = "bannertext"+i){
	        //if (i==4) continue;
	        //alert (bannerId + " " + document.bannerArr.length);
	        if (DOM){
	              bannerText_obj = document.getElementById(bannerId);
	        }
	        else if (LAY){
	              bannerText_obj = document.layers[document.bannerArr[i]];
	        }
	        //alert (capObj.id);
	        /*if (document.captureEvents){
	              //alert(menk);
	              window.captureEvents(Event.MOUSEDOWN |Event.MOUSEOVER | Event.MOUSEOUT );
	        }*/
	        //typ = typeof(document);
	        if (bannerText_obj){
	            document.bannerArr.push(bannerText_obj);
	            bannerText_obj.onmouseover = setTickerStopTrue;
	            bannerText_obj.onmouseout = setTickerStopFalse;
	            i++;
	        }
	        else {
	            //document.bannerArr.pop();
	            break;
	        }
	    }

		document.foot_obj = (document.all) ? footframe : document.getElementById("footframe");
	    document.getElementsByTagName("body")[0].style.backgroundColor=document.getElementById("contentframe").style.backgroundColor;
	    setMinWidth();
		if (IE){
			//alert(IE);
			//document.foot_obj.style.position = "absolute";

		}
		toBott();
		window.setTimeout("scrollcheck()", 100);
	    //startTicker();

   	}
return
}

function toBott(){
	if (window.pageYOffset) scrY = window.pageYOffset;
	else if (document.body && document.body.scrollTop) scrY = document.body.scrollTop;
	else scrY = 0;
	//alert (scrY);
	if (!ich_scrolle_gerade){
		document.gescrollt = 0;
		footHeight = document.foot_obj.offsetHeight;
		//alert (footHeight);
		if (IE) document.foot_obj.style.top = scrY + document.body.clientHeight - footHeight;
		cont_obj = (document.all) ? contentframe : document.getElementById("contentframe");
		head_obj = (document.all) ? headframe : document.getElementById("headframe");
		var contHeight = 6 + scrY + document.body.clientHeight - footHeight - head_obj.offsetHeight;

		cont_obj.style.height = (!OP) ? contHeight + "px" : contHeight;
		window.cont_obj.onmouseover = checkMenu;
		if(document.getElementById("main")) center();
	}
}

function scrollcheck() {

    window.scrollBy(0, 1);
	var y=0;
	if (window.pageYOffset) {
		 y = window.pageYOffset;
	} else if (document.body && document.body.scrollTop){
		 y=document.body.scrollTop;
	}
    //window.scrollBy(0, -1);
    //alert(y);
	//alert (documentHeight + " " + windowHeight  + " " + document.body.clientHeight  + " " + document.height);
	if ( y > 0 ) {
		window.scrollBy(0, (y*-1));
		canScroll = true;
		window.onmousemove = toBott;
		window.onscroll = toBott;
		window.onresize = toBott;

	}
	var scrup_obj = document.getElementById("scrup");
	var scrwn_obj = document.getElementById("scrwn");

    /*if(canScroll){
        scrup_obj.style.visibility = "visible";
        scrwn_obj.style.visibility = "visible";
        scrup_obj.onclick = scollUp;
        scrwn_obj.onmousedown = scollDown;
    }
    else {
        scrup_obj.style.visibility = "hidden";
        scrwn_obj.style.visibility = "hidden";
    }*/

	//alert ("documentHeight: " + documentHeight + "windowHeight: " + windowHeight);
	return;
}

function scollUp() {
	var y = 0;
	if (window.pageYOffset)  y = window.pageYOffset;
	else if (document.body && document.body.scrollTop) y = document.body.scrollTop;
	var step = -14;
	window.scrollBy(0, step);
	var windowHeight = Fensterhoehe();
	document.gescrollt = document.gescrollt + step;
	if (window.pageYOffset)  scrY = window.pageYOffset;
	else if (document.body && document.body.scrollTop) scrY = document.body.scrollTop;

	//alert(document.gescrollt +" "+ windowHeight);
	if ((y > 0) && (document.gescrollt*-1 < (windowHeight - 200) )){
		ich_scrolle_gerade = true;
		document.foot_obj.style.visibility = "hidden";
		window.setTimeout("scollUp()",20);
	return;
	}
	document.foot_obj.style.visibility = "visible";
	ich_scrolle_gerade = false;
	toBott();
	//window.history.go();
return;

}
function scollDown() {
	var y = 0;
	var documentHeight = (document.height) ? document.height : document.body.scrollHeight;

	if (window.pageYOffset)  y = window.pageYOffset;
	else if (document.body && document.body.scrollTop) y = document.body.scrollTop;
	var step = 14;
	window.scrollBy(0, step);
	var windowHeight = Fensterhoehe();
	document.gescrollt = document.gescrollt + step;
	if (window.pageYOffset)  scrY = window.pageYOffset;
	else if (document.body && document.body.scrollTop) scrY = document.body.scrollTop;

	//alert(document.gescrollt +" "+ windowHeight);
	if ((y < scrY) && (document.gescrollt < (windowHeight - 200) )){
		ich_scrolle_gerade = true;
		document.foot_obj.style.visibility = "hidden";
		window.setTimeout("scollDown()",20);
		return;
	}

	ich_scrolle_gerade = false;
	document.foot_obj.style.visibility = "visible";
	toBott();
return;
}


function center() {
	//window.resizeTo(800,600);
	var wdt = Fensterweite();
	//alert(wdt);
	var pleft =  0;
	//var ptop = (hgt-460)/2;
	if(DOM){
		var mainobj = document.getElementById("main");
		obwdt = mainobj.offsetWidth;
		 pleft = (obwdt>0) ? (wdt-obwdt)/2 : 5;
		mainobj.style.left = pleft+"px";
	}
/*     if (NS6){
		 for (i=0;i<document.getElementsByTagName("p").length;i++){
			 var pStartseite = document.getElementsByTagName("p")[i];
			 if (pStartseite.className == "startseite") pStartseite.style.width = 232+"px";
		 }
	 }
*/	else if (LAY){
		document.main.left = pleft;
	}
return
}



function test(){
	if (document.layers) getMouseLoc;
	else if (document.all){
		getMouseLoc();
		baer(mouseLocation.x,mouseLocation.y);
	}
}
function Point(x,y) {
	this.x = x;
	this.y = y;
}
mouseLocation = new Point(1,1); //erzeugt eine Instanz von Point mit den Werten 1 und 1
function getMouseLoc(evt){
//alert (evt.pageX);
	 if (typeof(window.event) == 'object') {
		mouseLocation.x = event.x + document.body.scrollLeft;
		mouseLocation.y = event.y + document.body.scrollTop;
	 }
	else{
		mouseLocation.x = evt.pageX;
		mouseLocation.y = evt.pageY;
	}
	//alert (mouseLocation.x+ "" +mouseLocation.y);
	return true;
}
function baer(locy, locx) {
	var ob =document.getElementById("baerTxt");
	ob.style.top = eval (locx-200)+"px";
	ob.style.left = eval (locy-200)+"px";
	ob.style.visibility = "visible";
return
}
/* contentframe-width auf Fensterbreite setzen */
function setMinWidth() {
	//setzt die Mindestweite auf 890px!
	if (Fensterweite() < 920){
		fw = (!OP) ? 920+"px" : 920;
		document.getElementById("contentframe").style.width = fw;
		document.getElementById("headframe").style.width = fw;
		document.getElementById("footframe").style.width = fw;
	}
	else {
		document.getElementById("contentframe").style.width = 100+"%";
		document.getElementById("headframe").style.width = 100+"%";
		document.getElementById("footframe").style.width = 100+"%";
	}

return
}


function Fensterweite(){
	if (window.innerWidth){ return window.innerWidth;}
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}

function Fensterhoehe(){
	if (window.innerHeight){ return window.innerHeight;}
	else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
	else return 0;
}

function hide_baer() {
	var ob =document.getElementById("baer");
	ob.style.visibility = "hidden";

return
}

function hide(ID) {
    var ob =document.getElementById(ID);
    ob.style.visibility = "hidden";

return
}


var tickin = true;
var tickerStop = false;
function setTickerStopTrue() {
	tickerStop = true;
return
}

function setTickerStopFalse() {
	tickerStop = false;
return
}

function vtickerIn(){

    var bannerText_obj = document.bannerArr[bannerCounter];
    bannerTextHeight =  bannerText_obj.offsetHeight;
	if (typeof(window['ticStart']) == 'undefined'){
		ticStart =  bannerTextHeight * -1;
	}
	marginL = document.bc;
	bannerText_obj.style.visibility = "visible";
    if (ticStart == 0) {
		tickin = false;
		stopTicker();
		ticStart--;
		window.setTimeout("startTicker()",3000);
		return;
	}
    if ( (ticStart < 0) && tickin ){
		bannerText_obj.style.top = ticStart+"px";
		if (!tickerStop) ticStart++;
		return;
	}
	if (ticStart > (bannerTextHeight * -1)  && !tickin){
        bannerText_obj.style.top = ticStart+"px";
        if (!tickerStop) ticStart--;
	} else {
		tickin = true;
		bannerText_obj.style.visibility = "hidden";
		//ticStart = bannerTextHeight * -1;
		if ( bannerCounter < (document.bannerArr.length - 1) ){
			bannerCounter++;
		} else {
			bannerCounter = 0;
		}
		stopTicker();
		//alert(document.tick);
		startTicker();
	}

return;
}

function stopTicker() {
	window.clearInterval(document.tick);
return
}
function startTicker() {
	//alert (bannerCounter + " " + document.bannerArr.length );
	document.tick = window.setInterval("vtickerIn()", 40);

return
}

function neuAufbau(){
	if (Weite != Fensterweite() || Hoehe != Fensterhoehe())
	//alert();
	window.history.go(0);
}
var pflichtFelder = new Array('Name', 'Vorname', 'Strasse', 'PLZ', 'Ort', 'tel_privat_fest', 'tel_privat_mobil', 'tel_dienst_fest', 'tel_dienst_mobil', 'fax');
var telFlag = false;
function chkForm(){
	var isOk = false;
	for (var i = 0; i < pflichtFelder.length; i++){
		eName = pflichtFelder[i];
		//alert (eName);
		feld_obj = document.form1.elements[eName];
		if (i <= 4 && feld_obj.value != "" && feld_obj.value.length >= 3){
			isOk = true ;
			feld_obj.style.backgroundColor = "#CCFFCC";
		} else if (i <= 4 ) {
			isOk = false ;
			feld_obj.style.backgroundColor = "#FFFF00";
			break;
		}
		if (i > 4){
			var Zahlen = /\d.+\B/;
			var goodStr = /(\d.+)\s(\d.+)/;
			if (Zahlen.test(feld_obj.value) && !goodStr.test(feld_obj.value) ){
				alert ("Bitte [Vorwahl][Leerzeichen][Rufnummer] eintragen");
				break;
			}
			isOk = goodStr.test(feld_obj.value);
			if (isOk == true){
				feld_obj.style.backgroundColor = "#CCFFCC";
				telFlag = true;
			}
			else if (telFlag == false) feld_obj.style.backgroundColor = "#FFFF00";
			if (telFlag) feld_obj.style.backgroundColor = "#CCFFCC";
		}
	}
}
