/* Popups */

/* CDweb07
function popup(format) {
	switch(format) {
		case 'hoch':
		hoch = window.open("popupHoch.php","hoch","height=700, width=550, noresize, adressbar=0, toolbar=0, status=1, resizable=1");
		break;
		default:
		quer = window.open("popupQuer.php","quer","height=550, width=700, noresize, adressbar=0, toolbar=0, status=1, resizable=1");
		break;
	}
}
*/

/* Menufunktionen */

startList = function() {
	if (document.all && document.getElementById) {
	
		/* Hauptnavigation */
		
		navRoot = document.getElementById("topNavigation");
		
		// For example on login page
		if (!navRoot)
			return;
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			
			checkNode = false;
			if(node.childNodes[1]) {
				checkNode = true;			/* Wenn es ein Ausklappmenu gibt */
			}
			
			if(checkNode) {
				for (u=0; u<node.childNodes[1].childNodes.length; u++) {
					subnode = node.childNodes[1].childNodes[u];
					if (subnode.nodeName == "LI") {
						subnode.onmouseover=function() {
							this.style.backgroundColor = "#990";
							if (this.childNodes[1].style) {
								this.childNodes[1].style.display = "block";
								this.childNodes[1].childNodes[0].style.display = "block";
							}
						}
						subnode.onmouseout=function() {
							this.style.backgroundColor = "#69C";
							if (this.childNodes[1].style) {
								this.childNodes[1].style.display = "";
								this.childNodes[1].childNodes[0].style.display = "";
							}	
						}
					}
				}
			}
			if (node.nodeName == "LI") {
				if(checkNode) {
					node.onmouseover=function() {
						this.style.backgroundColor = "#990";
						this.childNodes[1].style.display = "block";
					}
					node.onmouseout=function() {
						this.style.backgroundColor = "#69C";
						this.childNodes[1].style.display = "";
					}
				} else {
					node.onmouseover=function() {
						this.style.backgroundColor = "#990";
					}
					node.onmouseout=function() {
						this.style.backgroundColor = "#69C";
					}					
				}
			} 
		} 
		
	}	
}


window.onload = function() {
	startList();
}

/* Druckfunktion */

/* OBSOLETE -- U1.5.1
function drucken() {
	window.print();
}
*/

/* Neue Sachen von JBR */

function openerWin(url) {
	var win = window.opener;
	if (win && !win.closed) {
		win.document.location = DocSubRoot + url;
		win.focus();
	} else {
		document.location = DocSubRoot + url;
	}
}

function contactWin() {
	var url = "/contact.php?popup=1";
	_showWin(url, "contact", 500, 500);
}

function faqWin(appl) {
	var url = "/misc/sendFaq.php";
	if (appl.length > 0)
		url += "?appl=" + appl;
	_showWin(url, "faq", 500, 500);
}

function galleryWin(appl) {
	var url = "/misc/sendGallery.php";
	if (appl.length > 0)
		url += "?appl=" + appl;
	_showWin(url, "gallery", 500, 500);
}

function helpWin(url) {
	_showWin(url, "help", 400, 300);
}

function subsWin(appl) {
	var url;
	if ((appl.length == 0) || (appl == "other") || (appl == "all"))
		url = "/subs/";
	else
		url = "/subs/subscribe.php?appl=" + appl;
	_showWin(url, "subs", 500, 500);
}

function profileWin() {
	_showWin("/account/profile.php", "profile", 500, 500);
}

// U1.5.1
function printWin(pageAlias, printTree) {
	var pt = (printTree) ? 1 : 0;
	// pac: print and close window; pt: print tree
	var url = "/printable.php?pac=1&pt=" + pt + "&name=" + pageAlias;
	var win = window.open(url);
}

function printChoice(pageAlias) {
	_showDialog("/misc/printChoice.php?alias=" + pageAlias, "printChoice", 450, 130);
}

/* CDweb07
function plsLogin(msg, resume) {
	if ( confirm(msg + ' Would you like to login now?') ) {
		var url = DocSubRoot + "/account/login.php?resume=" + escape(resume);
		document.location = url;
	}
}
*/

// Unlike _showWin(), this attempts to center the win on the parent

function _showDialog(url, name, width, height) {
	url = DocSubRoot + url;

	var args = 'toolbar=no,menubar=no,location=no,directories=no,' +
		'status=no,scrollbars=no,resizable=no,copyhistory=no,' +
		'width=' + width + ',height=' + height;

	// attempt to determine X/Y to center new win on parent
	var winX, winY;
	if (document.all) {  // MSIE
		winX = window.screenLeft;
		winY = window.screenTop;
	} else {  // non-MSIE
		winX = window.screenX;
		winY = window.screenY;
	}
	winX += (document.body.clientWidth / 2) - (width / 2);
	winY += (document.body.clientHeight / 2) - (height / 2);
	args += ',top=' + winY + ',left=' + winX;

	var win = window.open(url, name, args);
	win.focus();
	
	return win;
}

function _showWin(url, name) {
	url = DocSubRoot + url;

	var args = 'toolbar=no,menubar=no,location=no,directories=no,' +
		'status=no,scrollbars=yes,resizable=yes,copyhistory=no';

	// add (optional) width/height
	if (arguments.length > 2)
		args += ',width=' + arguments[2];
	if (arguments.length > 3)
		args += ',height=' + arguments[3];

	// attempt to offset the new window from the parent
	args += ',screenX=' + (window.screenX + 30);
	args += ',screenY=' + (window.screenY + 30);

	// the following doesn't seem to do anything...
	args += ',dependent=yes';

	var win = window.open(url, name, args);
	win.focus();
}

function noop() {
}


function del(id, type, fn) {
	var msg = "Do you really want to delete this " + type + "?";
	if ( confirm(msg) )
		location = fn + ".php?id=" + id;
}

/* --- all-purpose functions --------------------------------------*/

function getElement(elemId) {
	if (document.getElementById && document.getElementById(elemId))
		return document.getElementById(elemId);
	else if (document.all && document.all(elemId))
		return document.all(elemId);
	else
		return false;
}

function getStyleObject(elemId) {
	var elem = getElement(elemId);

	return (elem) ? elem.style : false;
}

function setDisplay(elemId, value) {
	var styleObj = getStyleObject(elemId);
	if (styleObj)
		styleObj.display = value;
}

// Undo the cloaking (*not* encrypting) that was done by cloak()

function decloak(origStr) {
	var newStr = "";
	for (i=0; i<origStr.length; i++)
		newStr += String.fromCharCode(origStr.charCodeAt(i) + (i % 5));

	return newStr;
}

// Make a link out of a cloaked e-mail address. If a 2nd arg is passed,
// us it as the text for the link.

function decloakLink(email) {
	email = decloak(email);
	var link = '<a href="mailto:' + email + '">';
	if (arguments.length > 1)
		link += arguments[1] + '</a>';
	else
		link += email + '</a>';

	return link;
}

/* CDweb07

// To hide the searchbox menus from overlapping TopNavi in Win Explorer.
// Any <li class="doSbPopup"> directly below #topNavigation will be managed.

var re = /msie.*win/i;
var IsMsieWin = re.test(navigator.userAgent);
var SbPopupVisibility = 'visible';

function sbPopupVis(vis) {
	if ( !IsMsieWin )
		return;
	if (SbPopupVisibility == vis)
		return;
		
	var elem = window.event.srcElement;
	if (elem.id == "topNavigation")
		return;
		
	while (elem.parentNode.id != "topNavigation")
		elem = elem.parentNode;
	if (elem.className == "doSbPopup") {
		elem = document.getElementById("domainId");
		elem.style.visibility = vis;
		elem = document.getElementById("applId");
		elem.style.visibility = vis;
		SbPopupVisibility = vis;
	}
}
*/

/* --- in support of filters --------------------------------------*/

var Zoom;

function wopen(theURL) {
	if (!Zoom || Zoom.closed) {
		Zoom = window.open("", "",
			"location=no,toolbar=no,status=no,resizable=yes," +
			"scrollbars=yes,height=440,width=600");
	}
	Zoom.document.open();
	var con = "<html><head><title>Zoom</title></head><body><img src=\"";
	con += theURL;
	con += "\"></body></html>";
	Zoom.document.write(con);
	Zoom.document.close();
	Zoom.focus();
}

function dopen(theURL) {
	var DocWin;
	if (!DocWin || DocWin.open) {
		DocWin = window.open("", "",
			"location=no,toolbar=no,status=no,resizable=yes," +
			"scrollbars=yes,height=400,width=600");
	}
  
	DocWin.location.href = theURL;
	DocWin.focus();
}
