// filename: aas_gen.js
// functions for the main navigation and other pages
// version 1.01 - 2003-10-05
// Distributed under the terms of the GNU Library General Public License
// author: kontakt at manderbachmedia dot de

window.onerror = null

// 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]="h4";
	fontTag[5]="a";
	fontTag[6]="div";
	fontTag[7]="address";

function pageInit(thepage) {	
	is = new BrowserCheck();
	
	// correct display for Netscape 4.7 users
	if (is.ns4) correctForNN4(thepage);
	// display printbutton and font-change-buttons on new browser
	if (is.ie || is.ns6up) showLayer("fontButtonsDiv");
	// display searchfunction in ie on arachnologists-page
	if (is.ie && document.getElementById("searchDiv")) showLayer("searchDiv");
	
	// init fontChange - select fontchange from cookie
	initFontchange(thepage);
	
}

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(530,popupcontentheight+60);		
	}
}

function showLayer(derlayer){
	document.getElementById(derlayer).style.visibility = "visible";
}

function correctForNN4(thepage){
	// alert(document.centerDiv.document.mainContentboxHomeDiv.width);
	document.centerDiv.left = 0;
	if (thepage == "home") document.centerDiv.document.homeTopVisualDiv.top = 7;
	if (thepage == "home") document.centerDiv.document.mainContentboxHomeDiv.top = 28;
	//if (thepage == "home") alert("Dear user of Netscape4.x. Your browser does not support modern w3c-standards of CSS.\nThis may result in incorrect display of elements. Sorry for that.");
	// document.centerDiv.document.mainContentboxHomeDiv.background = none;
}


////////////////////////////////////
////////// search function ////////
/////////////////////////////////////


var n   = 0;

function findInPage(str) {
  var txt, i, found;
  if (str == "") return false;
  
  if (is.ie) {
    txt = window.document.body.createTextRange();

    // Find the nth match from the top of the page.
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
      txt.moveStart("character", 1);
      txt.moveEnd("textedit");
    }

    
    if (found) {// Mark it and scroll it into view.
      txt.moveStart("character", -1);
      txt.findText(str);
      txt.select(); 	
	  newsearchypos = document.body.scrollTop+txt.offsetTop-10;
	  if (newsearchypos < 250) newsearchypos = 250;
	  document.getElementById("searchDiv").style.left = "73px";
	  document.getElementById("searchDiv").style.top = (newsearchypos+"px");
      txt.scrollIntoView();	 
      n++;
    }

    
    else { // Start over at the top of the page and find first match.
      if (n > 0) {
        n = 0;
        findInPage(str);
      }

      else
        alert("'"+str+"' not found");
    }
  }

  return false;
}





/////////////////////////////////////////////
////////// functions for font-change ////////
/////////////////////////////////////////////

function initFontchange(fromwhere){
	if (fromwhere == 'home') contentObj = document.getElementById("contentRightHomeDiv");
	else contentObj = document.getElementById("contentRightDiv");
	var thecookie =  GetCookie("mmediafont");
	if (thecookie != null && thecookie != 0) {
		thecookie = parseInt(thecookie);
		changeFontsize(thecookie);
	}
}
	
function changeFontsize(num){
	globalFontchange+=num;
	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/12))+"px";// set new line-height
		}
	}
	// set cookie
	SetCookie("mmediafont",globalFontchange,"/");
}
	
////////////////////////////////////
//////// functions cookiehandling///
///////////////////////////////////

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() : "") +
		((expires) ? "; expires=Thu, 01-Jan-07 00:00:01 GMT" : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure=" + secure : "");
}

//////////////////////////////////////////////
/////////// other helpful functions /////////
/////////////////////////////////////////////

function printScreen() {
	if (window.print) window.print();
}


// 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 = 345
	if (!winHeight) winHeight = 323
	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 = "no"
	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()
	}
