// filename: _gen.js
// functions for the main navigation and other pages
// version 1.01 - 2003--
// Distributed under the terms of the GNU Library General Public License
// author: kontakt@manderbachmedia.de

window.onerror = null
var thetest = 1;
var flash6plugin = false;

function pageInit(von) {
	
	is = new BrowserCheck();
	
	if (is.ie || is.ns6up) {
		showTools();
		initToolvalues();
		
		initFontchange();
		// checks if there is a fontcookie and sets individual fontsize
		checkFontCookie();
	}
	
	// show disclaimer for Netscape 4.x users
	if (is.ns4) {
		if (von == "home") {windowOpener("/nn4disclaimer.de.html",500,250,"netscape4",200,100);}
		else if (von == "home_en") windowOpener("/nn4disclaimer.en.html",500,250,"netscape4",200,100);
	}	
	
	// hide ghost-scrollbar in IE and show bookmarlink
	if (is.ie && is.dom) {
		document.getElementsByTagName("body")[0].style.overflow = "auto";
		if (!is.mac) document.getElementById("bookmarkDiv").style.display = "inline";
	}

	
	
}

function popupInit() {
	
	is = new BrowserCheck();
	
	// hide ghost-scrollbar in IE
	if (is.ie && is.dom) document.getElementsByTagName("body")[0].style.overflow = "auto";

	// resize height of popup-window to image-height in dom-browsers
	if (is.dom) {
		var popupcontentheight = 400;
		if (is.all) popupcontentheight = (is.ie4)? document.all["popupContentDiv"].pixelHeight : document.all["popupContentDiv"].offsetHeight;
		else popupcontentheight = parseInt(getComputedStyle(document.getElementById('popupContentDiv'), null).getPropertyValue('height'));

		window.resizeTo(550,popupcontentheight+100);
		
	}
}
	
function flashPosition() {
	if (flash6plugin = true) { 
		if (document.getElementById) {
			document.getElementById("flashDiv").style.top = "0px";
			document.getElementById("flashDiv").style.left = "24px";
			}
		if (document.layers) {
			document.flashDiv.left = 24;
			document.flashDiv.top = 0;
			}
	}
}

function flashInit() {
	flash6plugin = true;
}

// show tools Box

function showTools() {
	if (document.getElementById("toolsDiv")) document.getElementById("toolsDiv").style.display = "inline";
}

// get cookies an set colnumber and fontsize
function initToolvalues() {
	var thecolnumber = GetCookie("mmediacolnumber");
	if ((thecolnumber == 1) || (thecolnumber == 2)) changeColnumber(thecolnumber);
}


// bookmark with title in IE

function bookmarkThis() {
	var thetitle = document.title;
	var theurl = document.URL;
	window.external.AddFavorite(theurl,thetitle);
}

// move marker of main navigation	

function mainover(where){
	if (is.dom) {
		var newpos = 3 + where * 21;/*  was 24 rma 20060414 */
		document.getElementById("navMainDynbgDiv").style.top = newpos + "px";
	}
}

function mainout () {
	if (is.dom) {
		document.getElementById("navMainDynbgDiv").style.visibility = "hidden";
		document.getElementById("navMainDynbgDiv").style.top = "-200px";
		document.getElementById("navMainDynbgDiv").style.visibility = "visible";
	}
}
	
	
// change Colnumber 1 <-> 2

function changeColnumber(number) {
	if (is.dom && document.getElementById("haelfte1Div")) {
		if (number == 2) {
			document.getElementById("haelfte1Div").className = 'zweispaltig';
			document.getElementById("haelfte2Div").className = 'zweispaltig';
			/* document.getElementById("haelfte1Div").style.width = '295';
			document.getElementById("haelfte2Div").style.width = '295'; */
			
		}
		else {
			document.getElementById("haelfte1Div").className = 'einspaltig';
			document.getElementById("haelfte2Div").className = 'einspaltig';
		}
	}
	SetCookie("mmediacolnumber",number,"/");
}

/////////////////////////////////////////////
////////// functions for font-change ////////
/////////////////////////////////////////////

// global vars for changing of fontsize
var globalFontchange = 0; // difference to default
var contentObj; // contentlayer obj
var fontTag = new Array();
	fontTag[0]="p";
	fontTag[1]="h1";
	fontTag[2]="h2";
	fontTag[3]="h3";
	fontTag[4]="a";
	fontTag[5]="div";
	fontTag[6]="li";
	fontTag[7]="address";
	
function initFontchange(){
contentObj = document.getElementById("mainContentDiv");

}
	
function changeFontsize(num){
	globalFontchange+=num;
	
	if (globalFontchange < 0) {globalFontchange = 0; num = 0;}
	else if (globalFontchange >10) {globalFontchange = 10; num = 0;}
	
	var newfontsize=0;
	var helpobj;
	for (var i=0; i<fontTag.length; i++){
		for (var j=0; j<contentObj.getElementsByTagName(fontTag[i]).length; j++){
			if (is.ie) newfontsize = parseInt(contentObj.getElementsByTagName(fontTag[i])[j].currentStyle.fontSize);
			else newfontsize = parseInt(document.defaultView.getComputedStyle(contentObj.getElementsByTagName(fontTag[i])[j],"").getPropertyValue("font-size"));
			newfontsize+=num;
			contentObj.getElementsByTagName(fontTag[i])[j].style.fontSize = newfontsize+"px";// set new fontsize
			contentObj.getElementsByTagName(fontTag[i])[j].style.lineHeight = Math.round(newfontsize*(15/11))+"px";// set new line-height
		}
	}
	SetCookie("mmediafont",globalFontchange,"/");
}

function checkFontCookie(){
	if (document.cookie) {
		var userfontsize = GetCookie("mmediafont");
		if ((isNaN(userfontsize) != true) && (userfontsize != null)) {
			userfontsize = Math.round(userfontsize);
			changeFontsize(userfontsize);
		}
	}	
}

	
	
// ############# cookie-handling ############

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function DeleteCookie (name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-80 00:00:01 GMT";
	}
}

function SetCookie (name,value,path,expires,domain,secure) {
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure=" + secure : "");
}

// ##########################################
	
	
	
	
	
// makeArray() - make new arrays with image objects
function makeArray(n) {
	this.length = n + 1
	for (var i = 1; i<=n; i++) {
		this[i] = new Image()
		}
	return this
	}
	
// open pop-up window
function windowOpener(winUrl,winWidth,winHeight,winName,winX,winY,winScrollbars,winLocation,winStatus,winPersonalbar,winResizable,winToolbar,winMenubar,winDependent,winDirectories) {
	var windowName = ""
	// set defaults
	if (!winWidth) winWidth = 300
	if (!winHeight) winHeight = 300
	if (!winName) winName = 'popupWindow'
	if (!winX) winX = 10
	if (!winY) winY = 10
	if (!winScrollbars) winScrollbars = "yes"
	if (!winLocation) winLocation = "no"
	if (!winStatus) winStatus = "no"
	if (!winPersonalbar) winPersonalbar = "no"
	if (!winResizable) winResizable = "yes"
	if (!winToolbar) winToolbar = "no"
	if (!winMenubar) winMenubar = "no"
	if (!winDependent) winDependent = "no"
	if (!winDirectories) winDirectories = "no"
	// open pop-up window
	eval(winName +  '= window.open(winUrl,winName,"width=' + winWidth + ",height=" + winHeight + ",left=" + winX + ",top=" + winY + ",screenX=" + winX + ",screenY=" + winY + ",scrollbars=" + winScrollbars + ",location=" + winLocation + ",status=" + winStatus + ",personalbar=" + winPersonalbar + ",resizable=" + winResizable + ",toolbar=" + winToolbar + ",menubar=" + winMenubar + ",dependent=" + winDependent + ",directories=" + winDirectories + '")')
	eval(winName).focus()
	}
