browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
var msie = (browserName == "Microsoft Internet Explorer");
var newtext = 0;


function OpenNewWindow(Picture,Breit,Hoch,ll_close) {
	xsize = Breit+50;// Zusatz fuer Rand rechts und links
	ysize = Hoch+130; //Zusatz fuer Rand oben und unten - damit Button angezeit werden kann 
	    
	ScreenWidth = screen.width;
	ScreenHeight = screen.height;
	
	xpos = (ScreenWidth/2)-(xsize/2);
	ypos = (ScreenHeight/2)-(ysize/2);
	
	NewCodeWindow=window.open("","Picture","height="+ysize+",width="+xsize+",scrollbars=yes,resizable=no,top="+ypos+",left="+xpos+"");
	NewCodeWindow.document.write ("<html><head><title>Kunstwerk");
	NewCodeWindow.document.write ("</title><style type=\"text/css\">body {background-color:#B9B9B9;background-image:url(images/mad/bg.gif);}</style></head>");
    NewCodeWindow.document.write ("<body onload='focus()'>");
	//NewWindow.document.write ("<body bgcolor='#cccccc'>");
	NewCodeWindow.document.write ("<table align='center'><tr>");
	NewCodeWindow.document.write ("<td align='center' valign='top'>");
	NewCodeWindow.document.write ("<table border='1' bgcolor='#000000' cellpadding='0' cellspacing='1'><tr><td align='center'>");
	NewCodeWindow.document.write ("<img src=\"");
	NewCodeWindow.document.write (Picture);
	NewCodeWindow.document.write ("\"  onClick='self.close()'>");
	NewCodeWindow.document.write ("</tr></table>");
	NewCodeWindow.document.write ("</td></tr><tr>");
	NewCodeWindow.document.write ("<td align='center' valign='bottom'>");
	NewCodeWindow.document.write ("<br><center><form><input type='button' value='"+ll_close+"' style='font-family: Verdana; font-size: 10px' onClick='self.close()'>");
	NewCodeWindow.document.write ("</td></tr></table>");
	NewCodeWindow.document.write ("</form></body></html>");
	NewCodeWindow.document.close();
    NewCodeWindow.resizeTo(xsize,ysize); 
}

// enlarges thumbnail to image area size and adds button to maximize
function largeImg(url,w,h,wm,hm,license) {
	$('imgview').style.position = 'absolute';
	$('imgview').style.backgroundColor = '#fff';
	$('imgview').style.border = 'none';
	$('imgview').style.padding = '0px';
	$('imgview').show();
	Position.clone($('tharea'),$('imgview'));
	$('imgview').innerHTML = '<img id="imgview_item" src="'+url+'" width="'+w+'" height="'+h+'" alt="'+btn_close+'" title="'+btn_close+'" onclick="$(\'imgview\').hide()">   \
		<br><span id="enlargelink"><a href="javascript://" onclick="imgMax(\''+url+'\','+wm+','+hm+')">   \
		<img src="images/search.png" align="top" border="0"> '+btn_enlarge+'</a><br>'+license+'</span>';
}

// helper function for largeImg - maximizes image
function imgMax(url, wm, hm) {
	if(wm > document.body.offsetWidth) wm = document.body.offsetWidth - 10;
	if(hm > document.body.offsetHeight) hm = document.body.offsetHeight - 10;
	$('imgview').style.left = (document.body.offsetWidth/2 - (wm/2)) + 'px';
	$('imgview').style.top = (document.body.offsetHeight/2 - (hm/2)) + 'px';
	$('imgview').style.border = '1px solid #999';
	$('imgview').style.width = wm+'px';
	$('imgview').style.height = hm+'px';
	$('imgview_item').style.width = wm+'px';
	$('imgview_item').style.height = hm+'px';
	$('enlargelink').remove();
	$('imgview').style.padding = '30px';
}

function shImg(url,w,h,wm,hm) {
	$('lview').style.display = 'block';
	//var l = $('lview').style.left;
	//var t = $('lview').style.top;
	var p = Position.page($('lview'));
	var l = p.shift();
	var t = p.shift();
	var i = new Image();
	i.src = url;
	i.height = h;
	i.width = w;
	var n = Math.floor(Math.random()*100);
	i.setAttribute('id','im'+n);
	//i.setAttribute('onclick','$(\'lview\').hide();');
	$('lview').setAttribute('onclick','imMax(\'im'+n+'\','+t+','+l+',1);');
	$('lview').innerHTML = '';
	$('lview').appendChild(i);
	//$('lview').innerHTML += '<br><a href="javascript://" id="max" class="btnmax" onclick="imMax(\'im'+n+'\',\''+wm+'\',\''+hm+'\',0);">max</a>';
	var max = $('max');
	$('max').style.top = ($('max').style.top - 17) +'px';
}

function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function el(id) {
	return document.getElementById(id);
}


var items = ['neu','menu'];
var menu = new Array();
menu['neu'] = false;
menu['menu'] = false;
//menu['media'] = false;

// simple div switcher for dropdown menus
function nshow(id,tag,off) {
	if(!menu[id]) {
		//alert(tag.offsetParent.offsetLeft+" / "+tag.offsetLeft+" - "+msie4+msie);
		if(off != undefined) var offset = off;
		else var offset = 0;
		if(tag.offsetParent.offsetLeft == 0) var left = tag.offsetLeft;
		else var left = tag.offsetLeft;
		if(msie4) left += 752;
		$(id).style.top = (tag.offsetTop+tag.offsetHeight)+'px';
		if(msie4) $(id).style.top = '35px';
		//left -= $(id).offsetWidth;
		$(id).style.left = left+'px';
		$(id).style.display = 'block';
		for(var i=0;i<items.length;i++) { 
			if(items[i] != id) {
				menu[items[i]] = false;
				$(items[i]).style.display = 'none';
			}
		}
		menu[id] = true;
	} else {
		$(id).style.display = 'none';
		menu[id] = false;
	}
}

// resize textarea while typing
function resize(fld, type) {
	var fheight = 0;
	var fwidth = 0;
	var size = fld.value.length;
	var lines = fld.value.split("\n").length;
	if(size <= 30) { NOfwidth = 235; fheight = 16; }
	if(size > 30 && type == 1) { fwidth = 450; fheight = 16; }
	if(size > 70/type && lines < 3) fheight = 38;
	if(size > 125/type && lines < 4) fheight = 70;
	if(size > 250/type) fheight = 100;
	if(size > 350/type) fheight = 150;
	if(size > 850/type) fheight = 230;
	if(size > 1200) fheight = 300;
	if(size > 1600) fheight = 350;
	//if(lines > 1) fheight = fheight+((lines-2+type)*16);
	if(lines > 1) {
		cpl = Math.round(size/lines);
		if(cpl < 70/type) fheight = lines*16;
		else fheight = fheight+((lines-2+type)*16);
	}
	if(fheight > 0) fld.style.height = fheight+'px'; 
	if(fwidth > 0) fld.style.width = fwidth+'px'; 
	fld.style.backgroundColor = '#eee';
	//$('info').innerHTML = 'L:'+lines+' - C:'+size+' (H:'+fheight+') cpl:'+Math.round(cpl);
}

function doblur(fld,id) {
	if(fld.value.length == 0) {
		fld.style.backgroundColor = '#fff';
		//if(el('b'+id) != undefined) el('b'+id).style.display = 'none';
	}
}

function blockshow(id) {
	el(id).style.display = 'block';
}

var active;  // globally defined, so subsequent calls of ajaxSearch can use it


/////////////////////////////////////////////////////////// 
// Main search and filter functions
//

// Definition of filter to show for each asset
var stdfilter = ['inst','perf','video','audio','net','asc','artlife','cddvd','commun','ani','dfoto','game','holo','inter','laser','map','archit','public','robo','soft','wear'];
var filter = new Hash({
	all: stdfilter,
	artist: stdfilter.concat(['tbirth','pbirth','place','tproj','pproj','relau']),
	author: stdfilter.concat(['tbirth','pbirth','place','tproj','pproj','relar']),
	project: stdfilter.concat(['tconc','tproj','pproj','prod','distrib','tbirthar','pbirthar']),
	source: stdfilter.concat(['tpub','pub','tbirthar','pbirthar']),
	keywords: ['kwsrc','kwproj','kwart','kwauth','kwcat']
});

// general search on index page
// wrapper for doAjaxSearch; prevents incomplete search while typing
function ajaxSearch(search, filteract, timer) {
	if(timer == undefined) timer = 700;
	if(active) window.clearTimeout(active);
	active = window.setTimeout("doAjaxSearch('"+search+"','"+filteract+"')", timer);
}

// set filter and do ajaxSearch
function setFlt() {
	fltactive = getActiveFlt();
	ajaxSearch($('search').value, fltactive, 1200);
}

// return comma separated list of chosen filters
function getActiveFlt() {
	var farr = [];
	var parent = $('filterarea');
	var div = document.getElementsByClassName('flt', $('filterarea'));
	for(var i=0; i< div.length; i++) {
		if(div[i].firstChild.checked == true) farr.push(div[i].firstChild.getAttribute('id'));
		key = div[i].firstChild.getAttribute('id');
		//$('n_'+key).innerHTML = '';
	}
	return farr.join(',');
}

// deselect all filters
function fltRemove() {
	var parent = $('filterarea');
	var div = document.getElementsByClassName('flt', $('filterarea'));
	for(var i=0; i< div.length; i++) {
		div[i].firstChild.checked = false;
		div[i].childNodes[1].style.color = '#555';
	}
	if($('search').value != '') doAjaxSearch($('search').value, '');
}

// hide selected filters
function fltDisplay(asset) {
	var parent = $('filterarea');
	var div = document.getElementsByClassName('flt', $('filterarea'));
	for(var i=0; i< div.length; i++) {
		div[i].style.display = 'none';
	}
	filter[asset].each(function(item) {
		if($('f_'+item)) $('f_'+item).style.display = 'block';
	});
}

//
// working horse - 
//
function doAjaxSearch(search, fltactive) {
	if(fltactive == undefined) fltactive = '0';
	var minchars = 1;
	// detect choosen asset
	var asset = 'all';
	for(var i=0; i< $('asset').childNodes.length; i++) {
		box = $('asset').childNodes[i];
		if(box.checked == true) asset = box.getAttribute('id');
	}
	//alert(search+" / "+parm);
	if(search.length < minchars) return; // one-letter search does not make sense

	$('loading').style.display = 'block';
	$('count').innerHTML = '';
	$('result').innerHTML = '';
	var lang = $('lang').value;

	new Ajax.Request('ajaxSearch.php', {
	  method: 'get',
	  parameters: 'tk=091965&ll='+lang+'&asset='+asset+'&filter='+filter[asset]+'&fltact='+fltactive+'&search='+encodeURI(search),
	  onSuccess: function(transport) {
		filter[asset].each(function(key) {
			//$('n_'+key).innerHTML = '';
		});
		$('loading').style.display = 'none';
		$('resultarea').style.display = 'block';
		$('filterarea').style.display = 'block';
		$('countarea').style.display = 'block';
		var result = transport.responseText.split('|');
		result.each(function(pair) { 
			assignDivs(pair);
		});
	  }
	});
}

// assigns values to fields ; numbers are added
// helper for doAjaxSearch
// @param	string	field_id#value
function assignDivs(pair) {
	var item = [];
	item = pair.split('#');
	if(item[1] == '') return;
	var field = item.shift();
	if(field != 'result') {
		var cnt = $(field).innerHTML;
		var addcnt = item.last();
		$(field).innerHTML = (addcnt*1) + (cnt*1);
	} else {
		if(item.length > 1) item = item.join('');
		else item = item.last();
		$(field).innerHTML += item;
	}
}

// filter checkbox changer for labels
function change(id) {
	var label;
	if($(id).checked == true) {
		$(id).checked = false;
		$(id).nextSibling.style.color = '#555';
	} else {
		$(id).checked = true;
		$(id).nextSibling.style.color = '#a50400';
	}
}

// label changer when clicking the checkbox
function chlabel(id) {
	if(id.checked == false) {
		id.nextSibling.style.color = '#555';
	} else {
		id.nextSibling.style.color = '#a50400';
	} 
}

// set sorting selector depending on chosen asset
function setSort(el) {
	//alert(el.getAttribute('id'));
	var asset = el.getAttribute('id');
	fltDisplay(asset);
	//$('sort').style.display = 'block';
	if($('search').value == '') $('search').value = '*';
	doAjaxSearch($('search').value, getActiveFlt());
}


// main function for ajax lookups (used for countries, languages, artists, art works etc.)
// root function of the ajaxField set
// @param	string	Searchterm
// @param	string	additional parameters
// @param	string	id of element to display the result in
// @param	string	language to use (two letter code)
function ajaxData(search, parm, result, lang) {
	var minchars = 2;
	//alert(search+" / "+parm);
	if(parm.match('country|keyword|lang')) minchars = 2;
	// for reverse-lookup ids < 10 (charlength = 1!) must be allowed!
	if(parm.match('(country|asource)=2')) minchars = 1;
	if(search.length < minchars) return; // one-letter search does not make sense
	new Ajax.Request('ajaxGet.php', {
	  method: 'get',
	  parameters: 'tk=091965&ll='+lang+'&search='+encodeURI(search)+'&'+parm,
	  onSuccess: function(transport) {
		$(result).style.display = 'block';
		if($(result).inspect().indexOf("input") > 0) {
			$(result).value = transport.responseText;
		} else {
			$(result).update(transport.responseText);
		}
	  }
	});
}

// puts data into the database
// depending on the given code, arguments are interpreted differently
function ajaxSave(code, data_id, params) {
	var parm;
	var lang;
	if(code == 'excerpt') {
		// data_id: art_id
		// params: newtext|ntext|npages|cncode
		var data = params.split('|');
		parm = '&code='+code;
		parm += '&text='+$(data[1]).value;
		parm += '&pages='+$(data[2]).value;
		parm += '&source_id='+$(data[3]).value;
		parm += '&art_id='+data_id;
		lang = data[4];
	}
	new Ajax.Request('ajaxSave.php', {
	  method: 'get',
	  parameters: 'tk=091965&ll='+lang + parm,
	  onSuccess: function(transport) {
		if(transport.responseText == '1') {
			document.location.reload();
		} else {
			$(data[0]).innerHTML += '<br><br>Error on saving: '+transport.responseText;
		}
	  }
	});
}


// adds selected entry from ajax result to visible list of names and invisible list of ids
// part of the ajaxField set
function addToList(id, idlist, namelist, value, str_del) {
	var list = new Array();
	//$(namelist).innerHTML += '<tr><td>'+value+'</td><td> &nbsp;&nbsp; </td><td><a onclick="removeId('+id+',\''+idlist+'\',\''+namelist+'\',\''+value+'\')" href="javascript://" alt="'+str_del+'" title="'+str_del+'">X</a></td></tr>';
	$(namelist).style.display = 'block';
	$(namelist).innerHTML += '<div class="namelist"><div class="name">'+value+'</div><div class="func"><a onclick="removeId('+id+',\''+idlist+'\',\''+namelist+'\',\''+value+'\')" href="javascript://" alt="'+str_del+'" title="'+str_del+'">X</a></div></div><br clear="all">';
	$(idlist+'_gen').value += '#'+value+'|'+id+'|'+idlist+'|'+namelist+'|'+str_del;
	list = $(idlist).value.split(',');
	list.each(function(item, i) { 
		if(item == '') list.splice(i, 1);
	});
	list.push(id);
	$(idlist).value = list.join(',');
	$(idlist+'_search').focus();
}

// sets selected entry from ajax result to visible field and invisible value of ids
// part of the ajaxField set
function setValue(valueid, value, displayid, display) {
	var list = new Array();
	$(displayid).value = display;
	$(displayid).style.backgroundColor = '#eee';
	$(valueid).value = value;
}

// part of the ajaxField set
function removeId(id, idlist, namelist, value) {
	var list = new Array();
	//alert(idlist);
	list = $(idlist).value.split(',');
	var orig = list;
	list = list.without(id);
	$(idlist).value = list.join(',');
	parseGenList(idlist, namelist);
}

// 
// part of the ajaxField set
function parseGenList(idlist, displaylist) {
	var todel = -1;
    if($(idlist+'_gen').value != '') {
        var list = new Array();
        glist = $(idlist+'_gen').value.split('#');
        ids = $(idlist).value.split(',');
        ids.each(function(item, i) { 
			if(item == '') ids.splice(i, 1);
		});
        $(displaylist).innerHTML = '';
        for(var i=0;i<glist.length;i++) {
			if(glist[i] == '') continue;
            list = glist[i].split('|');
            value = list[0];
            id = list[1];
            id_list = list[2];
            namelist = list[3];
            str_del = list[4];
			// omit entry from displaylist, whose id is not in array "ids"
            if(ids.indexOf(id) < 0) {
				if(todel < 0) { 
					todel = i;
					continue;
				}
			}
            $(displaylist).innerHTML += '<div class="namelist"><div class="name">'+value+'</div><div class="func"><a onclick="removeId('+id+',\''+id_list+'\',\''+namelist+'\',\''+value+'\')" href="javascript://" alt="'+str_del+'" title="'+str_del+'">X</a></div></div><br clear="all">';
        }
		if(todel >= 0) glist.splice(todel, 1);
		$(idlist+'_gen').value = glist.join('#');
		$(displaylist).style.display = 'block';
    }
}

// empties idlist, if visible field is emptied
function mkempty(namelist, id) {
	if(namelist.value == '') $(id).value = '';
}

// copy complete DOM-Object and set new form element names
// @param	object	'this' 
// @param	string	'src' is a source instead of a regular field
// type: 'src': source texts; else: standard rendering;
function domcopy(el,type) {
	var itm;
	var name = 0;
	cp = el.parentNode.cloneNode(true);
	cp.style.borderColor = '#fff';
	// remove form values and get sample name-attribute
	var fnode = new Object();
	fnode.value = cp;
	name = emptyForm(fnode);
	if(type == 'src') {
		var oldkey = getKey(name,0);
		var newkey = getKey(name,1);
		cp.innerHTML = cp.innerHTML.gsub(oldkey, newkey);
	}
	el.parentNode.parentNode.appendChild(cp);
	el.style.display='none';
}

function copyElement(e, type) {
	// get corrent node
	var el = e.parentNode;
	// remove highlighting
	el.style.borderColor = '#FFF';
	
	// copy it
	var cp = el.cloneNode(true);
	
	// find ajax fields in it
	ajaxfld = new Array();
	for(var y=0, a=0;y<cp.getElementsByTagName('div').length;y++){
		var field = cp.getElementsByTagName('div')[y];
		if(field.attributes['name'] && field.attributes['name'].value == "ajaxfld") {
			ajaxfld[a] = field;
			a++;
		}
	}
	
	// should check for input fields?
	if(type == 'inputs') {
		//remove content and set new names
		if(cp.getElementsByTagName('textarea').length > 0){
			var textarea = cp.getElementsByTagName('textarea');
			for(var i=0;i<textarea.length;i++) {
				// remove content
				textarea[i].innerHTML='';
				// Is this a copy of a copy?
				if(textarea[i].name.match(/new/)){ // yes
					var oldname = textarea[i].name;
					var	newname = oldname.substr(0,oldname.length-2); // remove the last two chars -> x]
					var key = oldname.substr(oldname.length-2,1); // get the key
					key++; // and increment it
					newname += key + "]"; // reassemble it
					textarea[i].name = newname; // set the new name
				} else { // no
					var newname = textarea[i].name; 
					newname = newname.substr(0,newname.length-1); // remove the last char -> ]
					textarea[i].name = newname + "_new_1]"; // and add key
				}
			}
		}
		if(cp.getElementsByTagName('select').length > 0){
			var select = cp.getElementsByTagName('select');
			for(var i=0;i<select.length;i++) {
				// Is this a copy of a copy?
				if(select[i].name.match(/new/)){ // yes
					var oldname = select[i].name;
					var	newname = oldname.substr(0,oldname.length-2); // remove the last two chars -> x]
					var key = oldname.substr(oldname.length-2,1); // get the key
					key++; // and increment it
					newname += key + "]"; // reassemble it
					select[i].name = newname; // set the new name
				} else { // no
					var newname = select[i].name; 
					newname = newname.substr(0,newname.length-1); // remove the last char -> ]
					select[i].name = newname + "_new_1]"; // and add key
				}
			}
		}
		if(cp.getElementsByTagName('input').length > 0){
			var input = cp.getElementsByTagName('input');
			for(var i=0;i<input.length;i++) {
				// remove content
				input[i].value='';
				// Is this a copy of a copy?
				if(input[i].name.match(/new/)){ // yes
					var oldname = input[i].name;
					var	newname = oldname.substr(0,oldname.length-2); // remove the last two chars -> x]
					var key = oldname.substr(oldname.length-2,1); // get the key
					key++; // and increment it
					newname += key + "]"; // reassemble it
					input[i].name = newname; // set the new name
				} else { // no
					var newname = input[i].name; 
					newname = newname.substr(0,newname.length-1); // remove the last char -> ]
					input[i].name = newname + "_new_1]"; // and add key
				}
			}
			
			// prepare ajax fields
			for(var i=0;i<ajaxfld.length;i++){
				// create new key and replace the old one
				input = ajaxfld[i].getElementsByTagName('input');
				var	uid = input[0].id.substr(input[0].id.length-2,input[0].id.length);
				newuid = "N"+uid;
				input[0].id = input[0].id.replace(uid, newuid);
				input[1].id = input[1].id.replace(uid, newuid);
				input[1].attributes['onkeyup'].value = input[1].attributes['onkeyup'].value.replace(new RegExp(uid,"g"), newuid);
				
				// replace in div id
				ajaxfld[i].getElementsByTagName('div')[1].id = ajaxfld[i].getElementsByTagName('div')[1].id.replace(uid, newuid);
				
				// make brs invisible
				var br = ajaxfld[i].getElementsByTagName('br')[0];
				br.style.display='none';
			}
		}
	
	}
	
	// Da removeChild teilweise Probleme gemacht hat
	// display = none
	
	// remove field descriptions
	label = cp.getElementsByTagName('label');
	for(var i=0;i<label.length;i++)
		label[i].style.display='none';
	
	// make the plus invisible
	e.style.display='none';
	
	// insert the copy
	el.parentNode.appendChild(cp);
	
	// done ;)
}

// new blockid for copy operations for use in recursive function emptyForm
var blockid = 99;

// set new keys for the form elements
// @param	string	form element name
// @param	integer	type of output
// helper for domcopy
function getKey(thename,step) {
	var oldkey; var newkey; // form names - old and new
	if(thename.indexOf('][') > 0) {
		parts = thename.split('][');
		oldkey = parts[1].substr(0, parts[1].length-1);
		if(oldkey.match(/new/)) {
			newkey = oldkey.replace(/new_/, '');
		} else {
			newkey = oldkey;
		}
		newkey++;
		newkey = 'new_'+newkey;
	} else {
		if(thename.indexOf('[]') > 0) {
			oldkey = thename;
			parts = thename.split('[');
			newkey = parts[0]+'[]['+parts[1];
		} else {
			newkey = oldkey = thename;
		}
	}
	//alert(oldkey+" "+newkey);
	if(step == 0) return oldkey;
	else if(step == 1) return newkey;
	else return thename.replace(oldkey, newkey);
}

// recursivly search for form fields, make them empty and return a sample name-attribute
// helper for domcopy
function emptyForm(fnode) {
	var name = 0;
	var atval;
	if(!fnode.value.hasChildNodes()) return;
	for(var i=0; i<fnode.value.childNodes.length;  i++) {
		atval = '';
		itm = fnode.value.childNodes[i];
		if(itm.nodeName.match(/INPUT|TEXTAREA/)) {
			for(i=0; i<itm.attributes.length; i++) atval += itm.attributes[i].nodeValue;
			if(atval.match(/blockshow/)) {
				var bs = itm.getAttribute('onfocus');
				itm.setAttribute('onfocus', bs.replace(/b\d+/,'b'+blockid));
			}
		}
		if(itm.nodeName == 'INPUT') {
			itm.setAttribute('value','');
			if(name == 0 && itm.getAttribute('name') != null) name = itm.getAttribute('name');
		}
		if(itm.nodeName == 'TEXTAREA') {
			if(itm.innerHTML != '') itm.innerHTML = '';
			if(name == 0 &&  itm.getAttribute('name') != null) name = itm.getAttribute('name');
		}
		if(itm.nodeName == 'SCRIPT') {
			if(itm.hasChildNodes()) itm.removeChild(itm.firstChild);
		}	
		// recurse into div elements
		if(itm.nodeName == 'DIV') {
			if(itm.getAttribute('id') && itm.getAttribute('id').match(/b\d+/)) {
				var bs = itm.getAttribute('id');
				itm.setAttribute('id', bs.replace(/b\d+/,'b'+blockid));
				blockid++;
			}
			var subnode = new Object();
			subnode.value = itm;
			name = emptyForm(subnode);
		}
	}
	return name;
}


// switcher for sidebar window (id: sidebar)
function barSwitch(linkid) {
	var tmp = linkid.innerHTML;
	linkid.innerHTML = $('barhead').innerHTML;
	$('barhead').innerHTML = tmp;
	if($('sidebar_2').style.display == 'none') {
		$('sidebar').style.display = 'none';
		$('sidebar_2').style.display = 'block';
	} else {
		$('sidebar').style.display = 'block';
		$('sidebar_2').style.display = 'none';
	}
}

// puts layer 1 onto layer 2 and makes it visible
function divOverlay(id1, id2) {
	if(newtext == 0) {
		$(id1).style.position = 'absolute';
		Position.clone($(id2),$(id1));
		$(id1).style.display = 'block';
		$(id1).addClassName('newtext');
		$(id1).style.width = '315px';
		newtext = 1;
	} else {
		$(id1).style.display = 'none';
		newtext = 0;
	}
}

// put source texts into display div
function showText(id) {
	$('tdisplay').innerHTML = $(id).innerHTML;
	$('tdisplay').style.display = 'block';
}

var timer = 0;
function restoreScreen(vidid) {
	timer = window.setTimeout(function() {
		$('scr'+vidid).style.display = 'block';
		$('vid'+vidid).style.display = 'none';
	}, 1400);
}

function showVidLinks(vidid, extern) {
	window.clearTimeout(timer);
	if(extern == '') {
		$('vid'+vidid).style.display='block';
		$('scr'+vidid).style.display='none';
	}
}


/**
 * email encoding to block spammers
 */
function eml(code) {
	location.href='mailto:'+acl.decode(code);
}

/**
*
*  encode / decode
*  http://www.webtoolkit.info/
*
**/
var acl = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = acl._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = acl._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}
}

