/** JavaScript für DHTML-Browser */

function twedit_switchLogin() {
	var style = document.getElementById("tweditLoginMask").style;
	style.display = (!style.display || style.display=="none") ? "block" : "none";
}

// Funktionen für das Flash-Banner

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined") {
    // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  } else {
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}

function showPhoto(number, title) {
	zoomImage('?target=/Home/Logo/Fotos/Foto '+number+'.jpg',400,400,title,true);
}

glanzEnabled = true;
function hiliteMovie (theMovie) {
	if (movieIsLoaded(theMovie) && glanzEnabled) {
		theMovie.TPlay("_level0/glanz_mc");
		glanzEnabled = false;
		window.setTimeout("glanzEnabled=true;",5000);
	}
}


defaultStatus = document.title.replace(/ </,"");

var documentLoaded = false;

function init() {
	status = defaultStatus;
	//initMenu("menuBar");
	if (is.ie) initFakeLinks();
	checkImages();
	documentLoaded = true;
}

function checkImages() {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].readyState!='complete') {
			document.images[i].src = document.images[i].src;
			//window.setTimeout('document.images['+i+'].src = document.images['+i+'].src;',200);
		}
	}
}

window.onresize = resizeFunc;
//window.onerror = doError;

function doError() {return true;}

function resizeFunc() {}


// Tooltips

addHandler(document, "mouseover", "showTooltip");
addHandler(document, "mouseenter", "showTooltip");

var ttShowTimeout;
var ttHideTimeout;

function showTooltip(event) {
	setupEvent(event);
	var tooltipText = event.target.getAttribute("title");
	if (!tooltipText) tooltipText = event.target.getAttribute("ttitle")
	else {
		event.target.removeAttribute("title");
		event.target.title = "";
		event.target.setAttribute("ttitle", tooltipText);
		addHandler(event.target, "mousemove", "moveTooltip");
		if (document.all) addHandler(event.target, "mouseleave", "hideTooltip");
		else addHandler(event.target, "mouseout", "hideTooltip");
	}
	if (!tooltipText) return;
	var tooltipWidth = event.target.getAttribute("twidth");
	var tooltipDiv = document.getElementById("globalTooltipDiv");
	if (!tooltipDiv) {
		tooltipDiv = document.createElement("div");
		tooltipDiv.id = "globalTooltipDiv";
		document.body.appendChild(tooltipDiv);
	}
	tooltipDiv.innerHTML = unescape(tooltipText);
	if (tooltipWidth && tooltipWidth>0) tooltipDiv.style.width = tooltipWidth + "px";
	else tooltipDiv.style.width = "150px";
	moveTooltip(event);
	//tooltipDiv.style.display = "block";
}

function moveTooltip(event) {
	setupEvent(event);
	var tooltipDiv = document.getElementById("globalTooltipDiv");
	if (!tooltipDiv.offsetWidth) tooltipDiv.offsetWidth = 160;
	tooltipDiv.style.left = Math.min((Fensterweite()-tooltipDiv.offsetWidth-30), (event.mouseX-2)) + "px";
	tooltipDiv.style.top = (event.mouseY + 18) + "px";
	tooltipDiv.style.visibility = "visible";
	//var delay = event.target.getAttribute("tdelay");
	//if (!delay || delay<1) delay = 1;
	//window.clearTimeout(ttHideTimeout);
	//ttShowTimeout = window.setTimeout('document.getElementById("globalTooltipDiv").style.visibility="visible";', delay);
}

function hideTooltip(event) {
	setupEvent(event);
	var tooltipDiv = document.getElementById("globalTooltipDiv");
	tooltipDiv.style.visibility = "hidden";
	//window.clearTimeout(ttShowTimeout);
	//ttHideTimeout = window.setTimeout('document.getElementById("globalTooltipDiv").style.visibility="hidden";', 1);
}


function initFakeLinks() {
	linkCol = document.all.tags("A");
	for (i=0; i<linkCol.length; i++) {
		if (linkCol[i].href=="javascript://") linkCol[i].style.cursor = "default";
	}
}


function Fensterweite() {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 1000;
  }
}



// Funktionen der Reiter

function showReiter(num, boxNum) {
	var c = 0;
	while (document.getElementById("box"+boxNum+"reiter"+c)) {
		document.getElementById("box"+boxNum+"reiter"+c).className = (c==num) ? "activeReiter" : "reiter";
		c++;
	}
	var boxContent = document.getElementById("box"+boxNum+"content");
	for (var i=0; i<boxContent.childNodes.length; i++) {
		boxContent.childNodes[i].style.display = (i==num) ? "block" : "none";
	}
}

// Box-Funktion

function switchBoxContent(num) {
	bCont = eval("box"+num+"ContentDIV");
	rSym = eval("rSym"+num);
	if (bCont.style.display == "block") {
		bCont.style.display = "none";
		rSym.innerHTML = "»";
	}
	else {
		bCont.style.display = "block";
		rSym.innerHTML = "«";
	}
}



// Sonstiges


function showKarte(number) {
	var windowName='Kartenausschnitt'+number;
	window.open('?target=/Info/Stadtplan/!miniKarte&pic='+number,windowName,'status=no,scrollbars=no,locationbar=no,resizable=yes,menubar=no,width=570,height=590');
}


// Funktionen zu Formular-Elementen

function iKeep(event) {
	el = event.srcElement;
	switch(event.type) {
		case "focus" : 
			if (!el.origValue) {
				el.origValue = el.value;
				el.value = "";	
			}
			else if (el.value == el.origValue) el.value = "";
			break;
		case "blur" : if (el.value=="") el.value = el.origValue;
	}
}

selects = new Array();

function grabSelects() {
	if (selects.length==0 || !documentLoaded)
	selects = document.all.tags("SELECT");
}

function hideSelects() {
	if (!is.ie) return true;
	grabSelects();
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility="hidden";
	}	
}

function showSelects() {
	if (!is.ie) return true;
	grabSelects();
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility="visible";
	}
}


// Euro-Rechner

function initRechner() {
	changeInput('dm');
	document.forms.rechner.dm.value = "0,00";
	window.setInterval("checkValues(input)",500);
}

function changeInput(waehrung) {
	rf = document.forms.rechner;
	if (rf.dm.value=="0,00") rf.dm.value = "";
	if (rf.euro.value=="0,00") rf.euro.value = "";
	input = waehrung;
}

function checkValues(waehrung) {

	valid = true;

	validValues = "1234567890.,";
	wert = document.forms.rechner[waehrung].value;

	for (i=0;i<wert.length;i++) {
		if (validValues.indexOf(wert.substr(i,1)) == -1) {
			valid = false;
		}
		else {
			if (wert.indexOf(",") > -1) {
				wert = wert.replace(/,/,".");
			}
		}
	}
	if (valid) refresh(waehrung, wert);
}

function refresh(waehrung, wert) {

	if (waehrung == "dm") {
		target = (wert / 1.95583);
		tWaehr = "euro";
	}
	else {
		target = (wert * 1.95583);
		tWaehr = "dm";
	}
	
	if ((is.ie && is.ver>=5) || is.ns6) {
		target = target.toFixed(2);
	}
	else target = Math.round((target*100))/100;

	tStr = target.toString(10);

	if (tStr.indexOf(".")==-1) tStr += ',00';
	else tStr = str_replace(tStr,".",",");

	document.forms.rechner[tWaehr].value = tStr;
}

function zoomImage(src,width,height,title,inline) {
	
	//neue Variante
	
	if (is.ie5 && inline) {
	
		dialogDIV.style.display = 'none';
		dialogIMG.onload = null;
	
		dMidPosition = 495;
		topOffset = 93;
		dialogContentTD.style.display = 'none';
		dialogDIV.style.width = 170;
		dialogTitleTD.innerHTML = 'Bild wird geladen...';
		dialogTitleTD.style.visibility = 'visible';
		veilDIV.style.width = document.body.clientWidth;
		veilDIV.style.height = document.body.clientHeight;
		if (src.indexOf('Logo')!=-1) {
			dialogDIV.style.left = dMidPosition-(dialogDIV.offsetWidth/2);
			dialogDIV.style.top = topOffset;
		}
		veilDIV.style.display = 'block';
		dialogDIV.style.display = 'block';
		
		dialogIMG.onload = function() {
			//alert('');
			dialogContentTD.style.display = 'block';
			dialogIMG.style.display = 'block';
			dialogIMG.style.margin = '0 -8 0 -8';
			//dialogTitleTD.style.visibility = 'hidden';
			dialogTitleTD.innerHTML = title;
			dialogDIV.style.left = dMidPosition-(dialogDIV.offsetWidth/2);
		}
		dialogIMG.src = src;
		window.setTimeout('if (dialogIMG.complete) dialogIMG.onload();', 200);
		
		return;
	}
	
	
	if (!is.ie) {
		width += 16;
		height += 16;
	}
	else {
		width += 2;
		height += 2;
	}
	zw = window.open(src,"_blank","width="+width+",height="+height+",menubar=no,location=no");
	zw.onerror = 'return false;';
	if (is.ie) {
		command = function() {
			zwBody = zw.document.body;
			if (!zwBody) return;
			zwBody.style.margin = "1 1 1 1";
			window.clearInterval(commandInterval);
		}
		commandInterval = window.setInterval(command,200);
	}
}

function str_replace(str,c1,c2) {
	for (i=0; i<str.length; i++) {
		if (str.charAt(i)==c1) str = str.substring(0,i)+c2+str.substr(i+1);
	}
	return str;
}