hiddenParagraph = new Array('pI',  'pII', 'pIII', 'pIV', 'pV', 'pVI', 'pVII', 'pVIII', 'pIX', 'pX', 'pXI', 'pXII');

function box_standalone(url, openId, jump) {

	if (!openId) openId='';

/*function popIdInline(openId) {
  MeinFenster.document.getElementById(openId).style.display = 'inline';
}
MeinFenster = window.open(url+'?layout=standalone'+'#'+jump, "", "width=700,height=650,left=250,top=10, scrollbars=yes");
MeinFenster.onload= popIdInline(openId);
MeinFenster.focus();
*/

MeinFenster = window.open(url+'?layout=standalone'+'#'+jump, "", "width=700,height=650,left=270,top=10, scrollbars=yes");
//  alert(MeinFenster);
	doc = MeinFenster.document; 
	
	if (MeinFenster){
MeinFenster.onload=function(){
//alert('nano')
  MeinFenster.focus();	
//alert(MeinFenster.document.getElementById(openId));
MeinFenster.document.getElementById(openId).style.display = 'inline';
//MeinFenster.document.getElementById('I').style.color = 'green';
MeinFenster.location.href = '#'+jump;

}

}
}


function toggle(id) {

	el = document.getElementById(id);
//alert(el.innerHTML)	
	if (el.style.display == 'none') el.style.display = 'inline'; else el.style.display = 'none';
}

function expand_all(count) {

	for (i=0; i<count; i++) {
		
		el = document.getElementById(hiddenParagraph[i]);
		el.style.display = 'inline';
	}
}

function collapse_all(count) {

	for (i=0; i<count; i++) {
		
		el = document.getElementById(hiddenParagraph[i]);
		el.style.display = 'none';
	}
}

popupArray = new Array();

// Style for the listings of all vocabulary
vocListStyle =  '.voc_table td {font-weight:bold;padding:0.5em;vertical-align:top;border: 1px solid grey;}\n';
vocListStyle += '.voc_table .even {background-color:#FFFFFF;}';
vocListStyle += '.voc_table .odd {background-color:#E0E0E0;}';
vocListStyle += '.voc_table .voc {color:#660000;}';
vocListStyle += '.voc_table .exp {color:#000000;text-align:justify;}';
vocListStyle += '.voc_h {color:#AA0000;text-align:center;}';

vocListWinW = 550;
vocListWinH = 550;

/**************************************** POPUP STUFF *********************************************/


/*
 * Settings
 */

/*** Default values - may be overwritten by the caller's arguments ***/


defaultWidth = 400;
defaultHeight = 300;
defaultCloseText = 'Close';
defaultStyleAll = 'padding: 10px; font-family:"Arial", "Helvetica", sans-serif;';
defaultStyleCaption = 'font-size: 20px; font-weight: bold; padding-bottom: 20px; text-align: center;';
defaultStyleText = 'font-size: 14px; font-weight: bold;';
defaultStyleFooter = 'padding-top: 15px; text-align: center;';
defaultTitle = 'EVTI - English Via The Internet';
defaultCloseHTML = '<div class="footer"><input type=\'button\' value="##CLOSETEXT##" onclick="javascript:window.close();"></div>';

// Style for Vocwin (vocabulary window) layout
vocwinStyleAll = '';
vocwinStyleCaption = 'font-size: 20px; font-weight: bold; color: #cc0000;';
vocwinStyleText = 'font-size: 14px; font-weight: bold; text-align: center;';

/*** General settings - not overwritable by the caller! - i.e. valid for the whole evti ***/
posOverTreeMarginTop = 120;
posOverTreeMarginLeft = 10;
posOverTreeWidth = 240;
posOverTreeHeight = 600;

autoResizeDivId = 'resizeToMe';

// HTML to be used if no URL is specified (but strings for caption and/ or text)
// every ##NAME## element will be replaced by either the default value or the caller's arguments
defHtml =  "<html>\n<head>\n<title>##TITLE##</title>";
// Including an external stylesheet unfortunately causes Mozilla to fail with resizing! So we use <style>
defHtml += "\n<style>";
defHtml += "\nbody, html { padding: 0; margin: 0; }";
defHtml += "\n.caption { " + defaultStyleCaption + " ##CSSCAP## }";
defHtml += "\n.text { " + defaultStyleText + " ##CSSTEXT## }";
defHtml += "\n.footer { " + defaultStyleFooter + " }";
defHtml += "\n#" + autoResizeDivId + " { position: absolute; top: 0; left: 0; width: 100%; }";
defHtml += "\n#resizedContent { " + defaultStyleAll + " ##CSSALL## }";
defHtml += "\n##CSSMORE##";
defHtml += "\n</style>";
defHtml += "\n</head>\n<body>";
defHtml += "\n<div id=\"" + autoResizeDivId + "\">";
defHtml += "\n<div id='resizedContent'>";
defHtml += "\n<div class=\"caption\">##CAPTION##</div>";
defHtml += "\n<div class=\"text\">##TEXT##</div>";
defHtml += "\n<div class=\"footer\">##CLOSEHTML##</div>";
defHtml += "\n</div></div></body>\n</html>";

html2 =  "<html>\n<head>\n<title>TITLE</title>\n";


html2 += "<link rel=stylesheet href=\"test.css\" type=\"text/css\">\n";
html2 += "</head>\n<body>\n";
html2 += "<div id=\"" + autoResizeDivId + "\">\n";

html2 += "</div></body>\n</html>\n";

// The script uses these filetypes to distinguish between URL and text, so add all possible filetypes to avoid problems
possibleFileExtensions = new Array('htm', 'php', 'stm');


/*
 *	Preparation
 */


// Constants ("Macros"), for ease of use of the popup function. Don't Change!

SETX = -1.0001;
SETY = -1.0002;
POSITION = -1.0003;
POSOVERTREE	= -1.0004;
CLOSETEXT = -1.0005;
CLOSEHTML = -1.0006;
DEFSIZE = -1.0007;
CSSCAPTION = -1.0008;	
CSSTEXT = -1.0009;
CSSALL = -1.0010;
NORESIZE  = -1.0011;
TITLE = -1.0012;
PARASTRING = -1.0013;
VOCWIN = -1.0014;
CSSMORE = -1.0015;
REUSE = -1.0016;
TARGET = -1.0017;
WIDTH = -1.0018;
HEIGHT = -1.0019;
/*** Add feature here ***/

STRINGCASE = 1;
URLCASE = 2;

function popup() {

	// Initialisation.
	userXactive = 0; userXvalue = 0;
	userYactive = 0; userYvalue = 0;
	userXactive = 0; userYactive = 0; userXvalue = 0; userYvalue = 0;
	userPOTactive = 0;
	userCloseTextActive = 0; userCloseTextValue = '';
	userCloseHTMLActive = 0; userCloseHTMLValue = '';
	userSizeActive = 0; userDefW = 0; userDefH = 0;
	userStyleCapActive = 0; userStyleCapValue = ''; 	
	userStyleTextActive = 0; userStyleTextValue = '';
	userStyleAllActive = 0; userStyleAllValue = '';
	userStyleMoreActive = 0; userStyleMoreValue = '';
	resizeActive = 1;
	userTitleActive = 0; userTitleValue = defaultTitle;
	userParastringActive = 0; userParastringValue = '';
	reuseActive = 0;
	targetActive = 0; target = '';
	userWactive = 0; 
	userHactive = 0; 
	/*** Add feature here ***/

	vocWin = 0;
	html = defHtml;
	
	
	var arg = arguments;

	var text = ''; oW = 0; oH = 0;

	// Process flag arguments (and determine the number of plain arguments)
	var plainArgs = 0;	
	for (i = 0; i < arg.length; i++) {

			if (arg[i] == SETX) { userXactive = 1; userXvalue = arg[++i]; continue; }
			if (arg[i] == SETY) { userYactive = 1; userYvalue = arg[++i]; continue; }
			if (arg[i] == POSITION) { userXactive = 1; userYactive = 1; userXvalue = arg[++i]; userYvalue = arg[++i]; continue; }
			if (arg[i] == DEFSIZE) { userSizeActive = 1; userDefW = arg[++i]; userDefH = arg[++i]; continue; }
			if (arg[i] == POSOVERTREE) { userPOTactive = 1; continue; }
			if (arg[i] == TITLE) { userTitleActive = 1; userTitleValue = arg[++i]; continue; }
			if (arg[i] == CLOSETEXT) { userCloseTextActive = 1; userCloseTextValue = arg[++i]; continue; }
			if (arg[i] == CLOSEHTML) { userCloseHTMLActive = 1; userCloseHTMLValue = arg[++i]; continue; }
			
			// Style addings	
			if (arg[i] == VOCWIN) { 
				vocWin = 1;
				reuseActive = 1;
				userStyleCapActive = 1; userStyleCapValue += vocwinStyleCaption; 
				userStyleTextActive = 1; userStyleTextValue += vocwinStyleText; 
				userStyleAllActive = 1; userStyleAllValue += vocwinStyleAll; 
				continue; 
			}

			if (arg[i] == CSSCAPTION) { userStyleCapActive = 1; userStyleCapValue += arg[++i]; continue; }
			if (arg[i] == CSSTEXT) { userStyleTextActive = 1; userStyleTextValue += arg[++i]; continue; }
			if (arg[i] == CSSALL) { userStyleAllActive = 1; userStyleAllValue += arg[++i]; continue; }

			if (arg[i] == CSSMORE) { userStyleMoreActive = 1; userStyleMoreValue += arg[++i]; continue; }

			if (arg[i] == PARASTRING) { userParastringActive = 1; userParastringValue = ', ' + arg[++i]; continue; }
			if (arg[i] == NORESIZE) { resizeActive = 0; continue; }
			if (arg[i] == REUSE) { reuseActive = 1; continue; }
			if (arg[i] == TARGET) { targetActive = 1; target = arg[++i]; continue; }
			
			if (arg[i] == WIDTH) { userWactive = 1; userWidth = arg[++i]; continue; }
			if (arg[i] == HEIGHT) { userHactive = 1; userHeight = arg[++i]; continue; }
			/*** Add feature here ***/

			plainArgs++;

	}
	
	width = userWactive ? userWidth : defaultWidth;
	width = userSizeActive ? userDefW : width;
	height = userHactive ? userHeight : defaultHeight;
	height = userSizeActive ? userDefH : height;
		
//alert(width);
	// Process plain arguments (i.e. those that are allowed to be presented in the usual way, not by macros)
	if (plainArgs) {
	
		URL = 0; sourceURL = '';
		caption = ''; text = '';
		
		if (plainArgs > 2) { resizeActive = 0; width = arg[plainArgs - 2]; height = arg[plainArgs - 1]; plainArgs -= 2; }
		if (plainArgs == 1) { 
		
			// URL or text?

			text = arg[0];
			URL = 0;			
			if ( arg[0].indexOf(' ') < 0 ) {
				for (k = 0; k < possibleFileExtensions.length; k++) {
					if ( arg[0].indexOf('.' + possibleFileExtensions[k]) > 0 ) { URL = 1; sourceURL = arg[0]; text = ''; break; }
				}
			}
		}
		if (plainArgs == 2) { caption = arg[0]; text = arg[1]; }
	}
	
	// Does the browser actually support the resizing code?
//alert(userParastringValue);	
	popupName = (reuseActive ? 'evtiPopup' : target);
//	alert(popupName);
	paraString = 'width=' + width +', height=' + height + ', resizable=1, scrollbars=yes' + userParastringValue;
	//if (URL) paraString += ', scrollbars=yes';
// Nichtexistent = erster Seitenaufruf, closed = wurde geschlossen
if ((!popupArray[popupName]) || ((popupArray[popupName]) && (popupArray[popupName].closed))) {
//alert(sourceURL);
	popupArray[popupName] = window.open( sourceURL, popupName, paraString);
//alert(popupArray[popupName]);
}
//	popupWindow.blur();
	//window.focus();	
	if (!URL) {
	
		// Prepare HTML according to caller's specs, and write it to popup
		
		var title = (userTitleActive ? userTitleValue : defaultTitle); 
//alert (caption);
		var closeText = (userCloseTextActive ? userCloseTextValue : defaultCloseText); 
		var closeHTML = (userCloseHTMLActive ? userCloseHTMLValue : defaultCloseHTML.replace(/##CLOSETEXT##/, closeText) ); 

		var styleCapAdd = (userStyleCapActive ? userStyleCapValue : ''); 
		var styleTextAdd = (userStyleTextActive ? userStyleTextValue : ''); 
		var styleAllAdd = (userStyleAllActive ? userStyleAllValue : ''); 
		var styleMoreAdd = (userStyleMoreActive ? userStyleMoreValue : ''); 
		
		html = html.replace(/##CSSCAP##/, styleCapAdd);
		html = html.replace(/##CSSTEXT##/, styleTextAdd);
		html = html.replace(/##CSSALL##/, styleAllAdd);
		html = html.replace(/##CSSMORE##/, styleMoreAdd);
		
		html = html.replace(/##TITLE##/, title);
		html = html.replace(/##CAPTION##/, caption);
		html = html.replace(/##TEXT##/, text);
		html = html.replace(/##CLOSEHTML##/, closeHTML);
	//html2 = html2.replace(/##STYLESHEET##/, defaultStylesheet);
//html = html.replace(/##/, '');
		
        popupArray[popupName].document.open();
        popupArray[popupName].document.write(html);
		
        popupArray[popupName].document.close();	
	}
	else {
		popupArray[popupName].location.href=sourceURL;
	}
	// Resizing fails when a file, not strings, has been loaded (don't ask me why, prob'ly a runtime problem)
	// Workaround: Calling resizeAndMove() directly from the loaded file
	resizeAndMove(popupArray[popupName], STRINGCASE); 
	
} 
 

// Funcs for auto-Resizing
function resizeAndMove(win, caseFlag) {


	// If the function has been called from a the popup window (i. e. in the URL case), not from the popup() function, the needed vars must be loaded
	if (caseFlag == URLCASE) {
		userPOTactive = opener.userPOTactive; 
		posOverTreeWidth = opener.posOverTreeWidth; 
		posOverTreeMarginLeft = opener.posOverTreeMarginLeft; 
		posOverTreeMarginTop = opener.posOverTreeMarginTop; 
		userXactive = opener.userXactive; 
		userXvalue = opener.userXvalue; 
		userYactive = opener.userYactive; 
		userYvalue = opener.userYvalue; 
		resizeActive = opener.resizeActive; 
	}
	
	// Resizing
	if (userPOTactive) win.resizeTo( posOverTreeWidth, posOverTreeHeight );	
	//oW = userPOTactive ? posOverTreeWidth : width;
	oW = userPOTactive ? posOverTreeWidth : 400;
	allDiv = getRefToDivMod( autoResizeDivId, win.document ); 
	
	if (allDiv) { oH = allDiv.clip ? allDiv.clip.height : allDiv.offsetHeight; }
	if (oH && browserSupportsResizing() && resizeActive) resizeToContent(win);
	
	// Moving
	move(win);
	
	win.focus();	
}
	
function getRefToDivMod( divID, oDoc ) {

	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
	if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
	for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
	y = getRefToDivNest(divID,oDoc.layers[x].document); }
	return y; } }
	if( document.getElementById ) { 
//alert(oDoc.getElementById(divID));
	
		return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }

	return document[divID];
}

function resizeToContent(win) {


//alert (oH+'u'+oW);
	win.resizeTo( oW + 200, oH + 200 );

	var myW = 0, myH = 0, d = win.document.documentElement, b = win.document.body;
	if( win.innerWidth ) { myW = win.innerWidth; myH = win.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
	//oW = userPOTactive ? posOverTreeWidth : (oW + ( ( oW + 200 ) - myW ));
	win.resizeTo( oW , oH = oH + ( (oH + 200 ) - myH ) );
	//if (userPOTactive) win.resizeTo( oW = posOverTreeWidth, oH = oH + ( (oH + 200 ) - myH ) );
	return false;
}

function move(win) {
//alert ('move')
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	var xCoord = (userXactive ? userXvalue : Math.round((scW-oW)/2));
	var yCoord = (userYactive ? userYvalue : Math.round((scH-oH)/2));
	if (userPOTactive) { xCoord = posOverTreeMarginLeft;  yCoord = posOverTreeMarginTop; }
	win.moveTo(xCoord, yCoord);
}

function browserSupportsResizing() {

	return 1;
}

// Positions a window as desired.
// Horizontically, the pixels from the left side is required. (XfromLeft)
// To center the window horizontically, use XfromLeft = -1 !
// Vertically, an offset from the midst must be defined. (Yoffset)
// Note: you may the evti default values vocWinDefaultXfromLeft and vocWinDefaultYoffset.

function moveWin(window, winWidth, winHeight,  XfromLeft, Yoffset) {

        var X = XfromLeft;
        if (XfromLeft == -1) X = (screen.width - winWidth)/2;
        var Y = (screen.height - winHeight)/2 + Yoffset;
        window.moveTo(X,Y);
}

function show_tooltip(text) {

        return overlib(text, FGCOLOR, '#ffffff', BGCOLOR, '#000000');

}

function viewVocList(vocField) {

	// vocListStyle is defined in the Configs on top of the file
	var rowClass = 'odd'
	var htmlBegin = '<div class="box_content">\n'
		htmlBegin += '<table border="0" rules="all" cellspacing="0" class="voc_table">\n'
	var htmlEnd = '</table>\n</div>\n';
	
	
	var html = htmlBegin.replace(/##vocListStyle##/, vocListStyle);
	
	var i=0
   	for (var Voc in vocField)	
   	{
   		i++;
   		if ((i%2) == 1)	{rowClass = 'odd'}
   		else {rowClass = 'even'}
		html += '<tr class="' + rowClass + '">\n\t';
		html += '<td class="voc">' + Voc + '</td>\n\t';
		html += '<td class="exp">' + vocField[Voc] + '</td>\n';
		html += '</tr>\n';
	}
	
	html += htmlEnd;
	
	popup('Vocabulary List',html, vocListWinW, vocListWinH, CSSCAPTION, 'color:#AA0000;', CSSMORE, vocListStyle, TITLE, 'Vocabulary List', PARASTRING, 'scrollbars=yes', SETY, 30);
}

/*
 * Crossbrowser API to access elements
 * taken from SELFHTML 8.0 - selfhtml.teamone.de
 */

var DHTML = 0, DOM = 0, MS = 0, NS = 0, OP = 0;

function DHTML_init() {

 if (window.opera) {
     OP = 1;
 }
 if(document.getElementById) {
   DHTML = 1;
   DOM = 1;
 }
 if(document.all && !OP) {
   DHTML = 1;
   MS = 1;
 }
if(document.layers && !OP) {
   DHTML = 1;
   NS = 1;
 }
}


function getElem(p1,p2,p3) {
 var Elem;
 if(DOM) {
   if(p1.toLowerCase()=="id") {
     if (typeof document.getElementById(p2) == "object")
     Elem = document.getElementById(p2);
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
     if (typeof document.getElementsByName(p2) == "object")
     Elem = document.getElementsByName(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
     if (typeof document.getElementsByTagName(p2) == "object" || (OP && typeof document.getElementsByTagName(p2) == "function"))
     Elem = document.getElementsByTagName(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
 else if(MS) {
   if(p1.toLowerCase()=="id") {
     if (typeof document.all[p2] == "object")
     Elem = document.all[p2];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
     if (typeof document.all.tags(p2) == "object")
     Elem = document.all.tags(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
     if (typeof document[p2] == "object")
     Elem = document[p2];
     else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
 else if(NS) {
   if(p1.toLowerCase()=="id" || p1.toLowerCase()=="name") {
   if (typeof document[p2] == "object")
     Elem = document[p2];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="index") {
    if (typeof document.layers[p2] == "object")
     Elem = document.layers[p2];
    else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
}

function getCont(p1,p2,p3) {
   var Cont;
   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild) {
     if(getElem(p1,p2,p3).firstChild.nodeType == 3)
       Cont = getElem(p1,p2,p3).firstChild.nodeValue;
     else
       Cont = "";
     return(Cont);
   }
   else if(MS && getElem(p1,p2,p3)) {
     Cont = getElem(p1,p2,p3).innerText;
     return(Cont);
   }
   else return void(0);
}

function getAttr(p1,p2,p3,p4) {
   var Attr;
   if((DOM || MS) && getElem(p1,p2,p3)) {
     Attr = getElem(p1,p2,p3).getAttribute(p4);
     return(Attr);
   }
   else if (NS && getElem(p1,p2)) {
       if (typeof getElem(p1,p2)[p3] == "object")
        Attr=getElem(p1,p2)[p3][p4]
       else
        Attr=getElem(p1,p2)[p4]
         return Attr;
       }
   else return void(0);
}

// p1: "id", "name", "tagname", "index"
// p2: Wert zu p1
// p3: fortlaufende Nr. (nur bei "name" oder "tagname", sonst null)
// p4: zu setzender Wert

function setCont(p1,p2,p3,p4) {


   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild)
     getElem(p1,p2,p3).firstChild.nodeValue = p4;
   else if(MS && getElem(p1,p2,p3))
     getElem(p1,p2,p3).innerText = p4;
   else if(NS && getElem(p1,p2,p3)) {
     getElem(p1,p2,p3).document.open();
     getElem(p1,p2,p3).document.write(p4);
     getElem(p1,p2,p3).document.close();
   }
}

DHTML_init();

/*
 * Browser-Detection
 * written by Thomas Brattli - www.dhtmlcentral.com
 */

function cm_bwcheck() {

        //In theory we should use object detection, but this script needs work-arounds for almost every browser...
        this.ver=navigator.appVersion
        this.agent=navigator.userAgent.toLowerCase()
        this.dom=document.getElementById?1:0
        this.ns4=(!this.dom && document.layers)?1:0;
        this.op=window.opera
        this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
        this.ie=this.agent.indexOf("msie")>-1 && !this.op
        if(this.op){
                this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
                this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
                this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
        }else if(this.moz) this.ns6 = 1
        else if(this.ie){
                this.ie4 = !this.dom && document.all
          this.ie5 = (this.agent.indexOf("msie 5")>-1)
          this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
          this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
        }
        this.mac=(this.agent.indexOf("mac")>-1)
        this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
        return this
}

var bw=new cm_bwcheck();
//alert (bw.ns6);
//if (!parent.left.exclist) parent.left.exclist = new Array(); 
//parent.left.exclist[0] = document.location;
//alert (parent.left.exclist[0]);



// Old funcs

/*** Vocabulary popup related variables ***/

// Voc. window width and heigth
vocWinDefaultWidth = 350;
vocWinDefaultHeight = 300;

// Specifies how many pixels a vocabulary explanation window is shown above screen midst by default
// Note: negative value for above, positive for below midst
vocWinDefaultYoffset = 100;

// Specifies how many pixels a vocabulary explanation window is shown from the left side
// Note: To center the window horizontally, use -1 !
vocWinDefaultXfromLeft = 100;

/*///////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------
// <void> = newWindow(file, n, w, h, x, y, extra)
// -----------------------------------------------------------------
// description: 
//		opens a new browser window as popup window, displaying the
//		html/php,etc. page 'file'. 
//
//		The name, width, height and offset of the popup window are 
//		passed to this function.
//
//		By default, the window is resizable and has scrollbars enabled.
//
//		Other additional properties can be switched on, by using the 
//		'extra' string-parameter. Refer to the description of the 
//		JS-standard 'open()'-function to learn how to assemble the
//		'extra' string.
//	
// input:
//		file (string): URI of the file to be displayed.
//		n (string): name of the window.
//		w (string): width (in px) of the window (excl. window frame)
//		h (string): height (in px) of the window (excl. window frame)
//		x (string): window-offset (in px) from the left screen border
//		y (string): window-offset (in px) from the upper screen border
//		extra (string): additional properties (adress-bar, etc.) 
//										passed to the JS open()-function
//
// output: --
///////////////////////////////////////////////////////////////////*/
function newWindow(file, n, w, h, x, y, extra) {

var width=w?w:700;
var height=h?h:500;
var name=n?n:'popup';
var strLeft=x?',left='+x:',left=0';
var strTop=y?',top='+y:',top=0';
var strExtra=extra?','+extra:'';

 infoWin=window.open(file, name,"width="+width+",height="+height+",scrollbars=yes,resizable=yes"+strExtra+strLeft+strTop)
 infoWin.resizeTo(width,height);
 infoWin.moveTo(x,y);
 infoWin.focus();

}

function newWin(file, n, w, h, tb, x ,y) {

var width=w?w:400;
var height=h?h:300;
var name=n?n:'pop_up';
var tbar=tb?tb:0;
tbarStr=tbar?'yes':'no';
var strLeft=x?',left='+x:'';
var strTop=y?',top='+y:'';


 infoWin=window.open(file, name,"toolbar="+tbarStr+",scrollbars=yes,width="+width+",height="+height+",resizable=yes"+strLeft+strTop)
 infoWin.focus();

}

// Vocabulary window
// Should be used by all vocabulary boxes

// XfromLeft specifies distance of  a vocabulary explanation window from the left side.
// Yoffset specifies how many pixels a vocabulary explanation window is shown above screen midst.
// If not specified, default values are used (Configurable on top of this document).


function vocWin(word, explanation, width, height, XfromLeft, Yoffset, bBackButton) {

        if (!arguments[2])        var width = vocWinDefaultWidth;
        if (!arguments[3])        var height = vocWinDefaultHeight;
        if (!arguments[4]) var XfromLeft = vocWinDefaultXfromLeft;
        if (!arguments[5]) var Yoffset = vocWinDefaultYoffset;
        if (!arguments[6]) var bBackButton = false;
        
        var X = XfromLeft;
        if (XfromLeft == -1) X = (screen.width - width)/2;
        var Y = (screen.height - height)/2 + Yoffset;

        text =  "<html>\n<head>\n<title>Vocabulary Box</title>\n";
        text += "<link rel=stylesheet type=\"text/css\" href=\"/common/css/popup.css\">\n";
        text += "<script type=\"text/javascript\" src=\"/common/js/evti.js\"></script>\n";
        text += "<script type=\"text/javascript\" src=\"vocabulary.js\"></script>\n";
        text += "</head>\n<body>\n";
        text += "<div class=\"popup_voc\">\n";
        text += ("<h1 class=\"voc_h\">" +word+ "</h1>\n");
        text += ("<p>" +explanation+ "</p>\n");
        if (bBackButton) {
        	text += "<a href=\"javascript:history.back();\">back</a>&nbsp;&nbsp;";
        }
        text += "<a href=\"javascript:window.close();\">Close</a>";
        text += "</div>\n</body>\n</html>\n";
        
        vocWindow = window.open('','newWin','width='+width+',height='+height+',scrollbars=yes,resizable=yes,left='+X+',top='+Y);
        vocWindow.document.open();
        vocWindow.document.write(text);
        vocWindow.document.close();

        vocWindow.focus();
}

function vocWin_alt(word, explanation, width, height, XfromLeft, Yoffset) {

        if (!arguments[2])        var width = vocWinDefaultWidth;
        if (!arguments[3])        var height = vocWinDefaultHeight;
        if (!arguments[4]) var XfromLeft = vocWinDefaultXfromLeft;
        if (!arguments[5]) var Yoffset = vocWinDefaultYoffset;
        
        var X = XfromLeft;
        if (XfromLeft == -1) X = (screen.width - width)/2;
        var Y = (screen.height - height)/2 + Yoffset;

        text =  "<html>\n<head>\n<title>Vocabulary Box</title>\n";
        text += "<link rel=stylesheet type=\"text/css\" href=\"/common/css/popup.css\">\n";
        text += "</head>\n<body>\n";
        text += "<div class=\"popup_voc\">\n";
        text += ("<h1 class=\"voc_h\">" +word+ "</h1>\n");
        text += ("<p>" +explanation+ "</p>\n");
        text += "<a href=\"javascript:window.close();\">close</a>";
        text += "</div>\n</body>\n</html>\n";
        
        vocWindow = window.open('','newWin','width='+width+',height='+height+',scrollbars=yes,resizable=yes,left='+X+',top='+Y);
        vocWindow.document.open();
        vocWindow.document.write(text);
        vocWindow.document.close();

        vocWindow.focus();
}

function getRefToDivModALT( divID, oDoc ) {
if( !oDoc ) { oDoc = document; }
if( document.layers ) {
if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
y = getRefToDivNest(divID,oDoc.layers[x].document); }
return y; } }
if( document.getElementById ) { return oDoc.getElementById(divID); }
if( document.all ) { return oDoc.all[divID]; }
return document[divID];
}

function openPerfectPopup(oW,oTitle,oContent) {
var x = window.open('','windowName','width=100,height=400');
if( !x ) { return true; }
x.document.open();
x.document.write('<html><head><title>'+oTitle+'<\/title><\/head><body background="/common/graphics/cnt_bg.jpg">'+
  (document.layers?('<layer left="0" top="0" width="'+oW+'" id="myID">')
    :('<div style="position:absolute;left:0px;top:0px;padding:10px;width:'+oW+'px;" id="myID">'))+
  oContent+(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
x.document.close();
var oH = getRefToDivMod( 'myID', x.document ); if( !oH ) { return false; }
var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
x.resizeTo( oW + 200, oH + 200 );
var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
if( window.opera && !document.childNodes ) { myW += 16; }


x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );
var scW = screen.availWidth ? screen.availWidth : screen.width;
var scH = screen.availHeight ? screen.availHeight : screen.height;
x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));
if( x.focus ) { x.focus(); }
return false;
}

function colloTooltip() {


}


/*
 *	On Enter key press, performs the JS given in commandString (e.g. a function call)
 */

function on_enter(commandString) {

	if (document.layers) document.captureEvents(Event.KEYDOWN);
	document.onkeydown = function (evt) {
		var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
		if (keyCode == 13) {
			eval(commandString);
			return false;
		}
		else return true;
	};
}

function reset_gaps() {

//if (!MS) {
formIndex = 0;
while (document.forms[formIndex]) {
	for(i=0;i<document.forms[formIndex].length;++i)
	 {
	  e = document.forms[formIndex].elements[i];
	 
	if (e.type == 'text') e.value = ''; 
	 }
	 formIndex++;

}

//}
}

function expand (id) {

	e = document.getElementById(id);
	e.style.visibility = 'visible';
	e.style.height = 'auto';
	
	id = id.replace(/expand/, "expander");
	sC(id, strip_tags(gC(id)));	
}

function strip_tags (s) {

	while (s.indexOf('<') > -1) {
		l = s.indexOf('<'); r = s.indexOf('>');
		s = s.substring(0, l) + s.substring(r+1, s.length);
	}
	
	return s;

}

// von: Collo Trainer

function gE (id) { return document.getElementById(id); }

/*
 *	(get Height) liefert Hoehe eines Elements
 */

function gH(e) {

	if (DOM) {

		MS ? h = e.offsetHeight : h = document.defaultView.getComputedStyle(e, "").getPropertyValue("height");
		return h;
	}

}

/*
 *	(get Width) liefert Breite eines Elements
 */

function gW(e) {

	if (DOM) { 
//alert(e);

		MS ? w = e.offsetWidth : w = document.defaultView.getComputedStyle(e, "").getPropertyValue("width");
		return w;
	}

}


/*
 *	(set Height) setzt Hoehe eines Elements
 */

function sH(e, val) {

	if (DOM) {

		e.style.height = val;
	}

}/*
 *	(set Width) setzt Weite eines Elements
 */

function sW(e, val) {

	if (DOM) {

		e.style.width = val;
	}

}

/*
 *	(show Element)
 */

function sE(id) {

		if (DOM) { e = getElem(id); e.style.visibility = 'visible'; }
}
/*
 *	(hide Element)
 */

function hE(id) {

		if (DOM) { e = getElem(id); e.style.visibility = 'hidden'; }
}


// Get Content		
function gC(id) {

		if (DOM) { return document.getElementById(id).innerHTML; }
}		

// Set Content
function sC(id, c) {

		if (DOM) { document.getElementById(id).innerHTML = c; return true; }
}		
/*Swaps the values of two indicies
------------------------------------------- */
Array.prototype.swap = function( index1, index2 )
{
var temp = this[index1];
this[index1] = this[index2];
this[index2] = temp;
}

/* Trims leading and trailing whitespace from string
------------------------------------------- */
String.prototype.trim = function()
{
return this.replace( /^\s+|\s+$/g, "" );
}
 
/*Randomly shuffles array (mutates)
------------------------------------------- */
Array.prototype.shuffle = function()
{
for ( var i = 0; i < this.length; i++ )
{
ind1 = Math.floor( Math.random() * this.length );
ind2 = Math.floor( Math.random() * this.length );
this.swap( ind1, ind2 );
}
}
