function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent (bodyHeight);
//addLoadEvent (initToolbar);
//addLoadEvent (setStyle);



/*
function setStyle () {
	
	
		if 	(readCookie("style")!=null) {
						
			var currentCssPath = document.getElementById("styleSheet").href.valueOf();
			var position = currentCssPath.lastIndexOf("/");
			var newCssPath = currentCssPath.substring(0,position)+"/"+(readCookie("style"));
		
			document.getElementById("styleSheet").href=newCssPath;
		}
	
		
	
	
}

function initStyle () {
		
		var styles = new Array ("style1","style2","style3","style4")
			for (i=0; i<styles.length;i++) {
				if (document.getElementById(styles[i])) {
					styleLink = document.getElementById(styles[i]);	
					if  (window.addEventListener){ // Mozilla, Netscape, Firefox
						styleLink.addEventListener('click', changeStyleTo, false);
					} 
					else { // IE
						styleLink.attachEvent('onclick', changeStyleTo);
					}
				}
			}
	
}
*/


function bodyHeight () {
	var bodyHeight = document.body.offsetHeight;
	var wHeight = new getWindowHeight();
		if (bodyHeight<wHeight.windowHeight) {
		
			document.body.style.height="100%";
					}

}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		this.windowHeight=window.innerHeight-2;
	}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			this.windowHeight=document.documentElement.clientHeight-2;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				this.windowHeight=document.body.clientHeight-2;
			}
		}
	}

}

/**
 * @constructor
 * Determin which element has caused the event. 
 * @param {event} e 
 * @return {object} caller
 * @return {string} callerId
 * @return {string} callerName
 * 
 * 
 */
function callingElement (e) {
	var targ;
		if (!e) var e = window.event;
		if (e.target) {targ = e.target;}
		if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) {// defeat Safari bug
		targ = targ.parentNode;
	}	
	// var callerId= targ.id;
	this.caller = targ;	
	this.callerId= targ.id;
	this.callerName = targ.name;
}


/** 
*Determing the pressed Key
*This function determins which key was pressed when the event occured. It takes the event as an paramter and returns 
*keypressed which is a numeric value (e.g '13' equals the enter key
*@constructor
*@param e (event)
*@returns keyPressed
*@author Uwe Duesing
**/
function whichKeyWasPressed (e) {

	if (!e) var e = window.event;
	if (e.which) { 
		var keyPressed = e.which;
	}
	if (e.keyCode) { 
		var keyPressed =e.keyCode; 
	}
	return keyPressed;
}

/**
*Counting how many <li> elements are in a list
*This function counts the li elements of a 'ul' or 'ol' list. It takes the list as an object as a paramter and returns a numeic value
*@constructor
*@param list (the ul or ol list as an object)
*@returns nodeCount (numeric Value)
*@author Uwe Duesing
**/
function countNodes (list) {
	var li = list.firstChild;
	var i=0;
	while (li != null) {
	  var i=i+1;
	   li = li.nextSibling;
	  
}
	if (browser =="mz") {
		i=i-3;
	}
	this.nodeCount = i;

}

/**
*Determin the coords of an event
*This function takes the event object as a paramter and returns two numeric values representing the x/y coordinates of the event
*@constructor
*@param e (event object)
*@returns x,y
*
**/

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}



function initToolbar () {

	var tools = new Array ("list_Active",
						   "list_Available",
						   "label_Active",
						   "label_Available",
						   "lightbox_Active",
						   "lightbox_Available",
						   "detail_Available",
						   "detail_Active",
						   "begin_Available",
						   "previous_Available",
						   "next_Available",
						   "end_Available",
						   "help_available")
						   
						   
	for (i=0; i<tools.length;i++) {
	
		if (document.getElementById(tools[i])) {
		
			var tool = document.getElementById(tools[i]);	
			if  (window.addEventListener){ // Mozilla, Netscape, Firefox
				tool.addEventListener('mouseover', showTool, false);
				tool.addEventListener('mouseout', hideTool, false);
			} 
			else { // IE
				tool.attachEvent('onmouseover', showTool);
				tool.attachEvent('onmouseout', hideTool);
			}	
		
		}						   
	};
};

var helpText = new Array()
		helpText[0] = new Object();
		helpText[0]["list"] = new Image; 		helpText[0]["list"].src="./img/helpText_List.gif";
		helpText[0]["label"] = new Image; 		helpText[0]["label"].src="./img/helpText_label.gif";	
		helpText[0]["lightbox"] = new Image; 	helpText[0]["lightbox"].src="./img/helpText_lightbox.gif";	
		helpText[0]["detail"] = new Image; 		helpText[0]["detail"].src="./img/helpText_detail.gif";	
		helpText[0]["begin"] = new Image; 		helpText[0]["begin"].src="./img/helpText_beginning.gif";
		helpText[0]["previous"] = new Image; 	helpText[0]["previous"].src="./img/helpText_previous.gif";	
		helpText[0]["next"] = new Image; 		helpText[0]["next"].src="./img/helpText_next.gif";	
		helpText[0]["end"] = new Image; 		helpText[0]["end"].src="./img/helpText_end.gif";	
		helpText[0]["help"] = new Image; 		helpText[0]["help"].src="./img/helpText_help.gif";

function showTool (e) {

	var availableTool = new callingElement(e);
	
	var helpTextIdIndex= availableTool.callerId.indexOf("_");

	var helptextId=availableTool.callerId.substr(0,helpTextIdIndex);
	

	var newHelptext = document.createElement("img");
	newHelptext = helpText[0][helptextId];

	var ankerpoint = document.getElementById("helpTextDisplay");
	if (ankerpoint.hasChildNodes()) {
		nodeToRemove = ankerpoint.childNodes[0];
		ankerpoint.removeChild(nodeToRemove);		
	}
	ankerpoint.appendChild(newHelptext);
}
function hideTool () {	
	var ankerpoint = document.getElementById("helpTextDisplay");	
		if (ankerpoint.hasChildNodes()) {
			nodeToRemove = ankerpoint.childNodes[0];
			ankerpoint.removeChild(nodeToRemove);		
		}
}


function changeStyleTo (e) {
	
	var styleLinkObject = new callingElement(e);
	var styleLink = styleLinkObject.callerId;
	
	if (styleLink=="style1") { var newStyle="browser_style1.css"; }
	if (styleLink=="style2") { var newStyle="browser_style2.css"; }
	if (styleLink=="style3") { var newStyle="browser_style3.css"; }
	if (styleLink=="style4") { var newStyle="wallace.css"; }
	
	var currentCssPath = document.getElementById("styleSheet").href.valueOf();
	var position = currentCssPath.lastIndexOf("/");
	var newCssPath = currentCssPath.substring(0,position)+"/"+newStyle;
	
    document.getElementById("styleSheet").href=newCssPath;
    var cookie = new createCookie("style",newStyle,0);

	//css/browser_style2.css
	
}




function createCookie(name,value,days) {
	if (days) {
		
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}