//alert("common");
//------------------------------------------------------------------------------------------------
function add_is_read(object_name,item_id)
{
	cache_is_read = parent.Select.document.getElementById('cache_is_read');
	{
		if(cache_is_read.value.length == 0)
		cache_is_read.value = object_name;
		cache_is_read.value+= ',' + item_id;
		//alert(cache_is_read.value);
		document.getElementById('cache_is_read').value = cache_is_read.value;
	}
}
//------------------------------------------------------------------------------------------------
function get_is_read()
{
	var is_read = '';
	if(input = document.getElementById('cache_is_read'))
	{
		if(input.value.length > 0)
		is_read = input.value;
		//alert(input.value);
	}
	parent.Select.document.getElementById('cache_is_read').value = is_read;
}
//------------------------------------------------------------------------------------------------
function openURL(URL,WIN)
{
	win = window.open(URL, WIN);
	win.focus();
}
//------------------------------------------------------------------------------------------------
function openPopUp(URL,LANG,WIN,WIDTH,HEIGHT,SB,ACTION)
{
	if (!SB) SB="yes";
	if (!HEIGHT) HEIGHT=400;
	if (!WIDTH) WIDTH=600;
	OPT="height="+HEIGHT+", width="+WIDTH+", scrollbars=no";
	if(HEIGHT > screen.availHeight)
	{
		HEIGHT = screen.availHeight;
		SB="yes";
	}
	win_popup = window.open("about:blank", WIN, OPT);
	win_popup.document.open("text/html");
	win_popup.document.write("<html><head><title>" + gl_title + "</title></head>"
	+ '<frameset rows="*,1,30" frameborder="0" framespacing="0" border="0" onload="' + ACTION + '">'
	+ '<frame name="Content" src="' + URL + '" marginwidth="1" marginheight="1" scrolling="' + SB + '" frameborder="0">'
	+ '<frame src="'+ base +'htmdocs/emptyborder.html" marginwidth="0" marginheight="1" scrolling="no" frameborder="0" noresize>'
	+ '<frame src="'+ base +'htmdocs/'+ LANG +'/popup_close.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize>'
	+ '</frameset><body></body></html>');
	win_popup.document.close;
	win_popup.focus();
}
//---------------------------------------------------------------------------------------------- 
vis = new Array("hidden","visible");
function show(which,mod)
{
	itm = document.getElementById(which);
	itm.style.visibility = vis[mod];
	return;
}
//---------------------------------------------------------------------------------------------- 
function show_hide(id)
{
	itm = document.getElementById(id);
	if (itm.style.visibility == "hidden")
	{
		itm.style.visibility = "visible";
	}
	else
	{
		itm.style.visibility = "hidden";
	}
}
//---------------------------------------------------------------------------------------------- 
function show_hide_id(id)
{
	i = id.lastIndexOf("_");
	id_hide = id.substr(0,i) + "_hide";
	id_show = id.substr(0,i) + "_show";
	itm_hide = document.getElementById(id_hide);
	itm_show = document.getElementById(id_show);
	if (id == id_hide)
	{
		itm_hide.style.visibility = "hidden";
		if(itm_show) itm_show.style.visibility = "visible";
	}
	else
	{
		if(itm_hide) itm_hide.style.visibility = "visible";
		itm_show.style.visibility = "hidden";
	}
}
//---------------------------------------------------------------------------------------------- 
var showh_items_array = new Array();
var child_items_array = new Array();
var cache_items_array = new Array();
//---------------------------------------------------------------------------------------------- 
function switch_items(item_id)
{
	i = item_id.lastIndexOf("_");
	id_0 = item_id.substr(0,i) + "_0";
	id_1 = item_id.substr(0,i) + "_1";
	show_hide_item(id_0);
	show_hide_item(id_1);
}
//---------------------------------------------------------------------------------------------- 
function show_hide_item(item_id)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
//		handle_nodes(item_id);
		show_hide(item_id);
	}
	else
	{
		show_hide(item_id);
	}
}
//---------------------------------------------------------------------------------------------- 
var noFolder = true;
// top_margin im doc
// row_height im doc
// group_topspace im doc
var group_ids = new Array();
var group_items = new Array();
var group_images = new Array();
var group_contents = new Array();
var group_links = new Array();
var select_plus = new Image();
var select_minus = new Image();
var start_closefolder = false; //zum Überschreiben in init.js
function init_folder()
{
	select_plus.scr = button_dir + "/select_plus.gif";
	select_minus.scr = button_dir + "/select_minus.gif";
	div_items = document.getElementsByTagName("div");
	j = 0;
	for(i=0; i<div_items.length; i++)
	{
		if(div_items[i].id.substr(0,11) == "groupfolder")
		{
			group_id = parseInt(div_items[i].id.substr(11,2));
			group_ids[group_id] = j;
			group_items[j] = div_items[i];
			group_images[j] = document.getElementById("img" + group_id);
			group_contents[j] = document.getElementById("groupcontent" + group_id);
			//alert("Gruppe " + group_id + " " + j);
			collect_grouplinks(group_id, group_contents[j]);
			j++;
		}
	}
//	group_contents[1].style.visibility = "visible";
	if(auto_closefolder || start_closefolder)
		for(i=0; i<group_items.length; i++)
		{
			group_contents[i].style.visibility = "hidden";
			group_images[i].src = select_plus.scr;
		//click_folder(1);
		}
	if(j > 0)
	{
		noFolder = false;
		setFolderPositions();
	}
}
//-----------------------------------------------------------------
function collect_grouplinks(group_id, group_content)
{
	var i;
	//alert("group_content " + group_id + " " + group_content.childNodes.length);
	for(i=0; i<group_content.childNodes.length; i++) // ids der Links in der Gruppe
	{
		chld = group_content.childNodes[i];
		if(chld.tagName == "A")
		{
			group_links[chld.id] = group_id;
			//alert(chld.id + " " + group_id + " " + i);
			//alert(group_id + chld.tagName);
		}
		else
		{
		if(chld.childNodes.length > 0 )
		{
			//alert(group_id + chld.tagName + chld.children.length);
//	if(chld.childNodes.length > 1 || chld.tagName == "TD") alert("collect " + group_id + " " + chld.tagName);
			collect_grouplinks(group_id, chld);
		}
		}
	}
}
//-----------------------------------------------------------------
function open_folder(group_id)
{
	if(noFolder) return;
	group_no = group_ids[group_id];
//alert(group_id + " " + group_no);
	//group_no = group_id;
	if(group_contents[group_no].style.visibility == "hidden")
	{
		click_folder(group_id);
	}
}
//-----------------------------------------------------------------
function click_folder(group_id)
{
	if(noFolder) return;
	group_no = group_ids[group_id];
//alert(group_id + " " + group_no);
	group_content = group_contents[group_no];
	if(group_content.style.visibility == "hidden")
	{
		if(auto_closefolder)
		for(i=0; i<group_items.length; i++)
		{
			if(group_contents[i].style.visibility == "visible")
			{
				group_contents[i].style.visibility = "hidden";
				group_images[i].src = select_plus.scr;
			}
		//	alert(pos_y + " group" + i);
		}
		group_content.style.visibility = "visible";
		group_images[group_no].src = select_minus.scr;
	}
	else
	{
		group_content.style.visibility = "hidden";
		group_images[group_no].src = select_plus.scr;
	}
	setFolderPositions();
}
//-----------------------------------------------------------------
function setFolderPositions()
{
	pos_y = top_margin;
	for(i=0; i<group_items.length; i++)
	{
		//i = group_ids[j];
		group_item = group_items[i];
		pos_y = pos_y + group_topspace;
		//alert(group_item.style.top + ' -> ' + pos_y);
		group_item.style.top = pos_y+"px";
		pos_y = pos_y + row_height;
		group_content = group_contents[i];
		if(group_content.style.visibility == "visible")
		{
			pos_y = pos_y + parseInt(group_content.style.height);// +"px";
		}
		group_content.style.top = pos_y+"px";
	//	alert(pos_y + " group" + i);
	}
}
//-----------------------------------------------------------------
function handle_nodes(id)
{
	id = 'a'+id;
	for(i=0;i<showh_items_array.length;i++)
	{
		f_item = showh_items_array[i];
		if(f_item.id == id)
		{
			c_item = child_items_array[i];
			if(c_item.style.visibility == "hidden")
			{
				for(k=0;k < cache_items_array[i][0];k++)
				{
					t_item = cache_items_array[i][k+1];
					//alert(k + "  " + c_item.nodeName);
					c_item.appendChild(t_item);
				}
				f_item.appendChild(c_item);
				c_item.style.visibility = "visible";
			}else{
				c_item.style.visibility = "hidden";
				while(f_item.childNodes.length > 0)
					f_item.removeChild(f_item.firstChild);
			}
		return;
		}
	}
}
//---------------------------------------------------------------------------------------------- 
function show_hide(id)
{
	f_item = document.getElementById(id);
	if(f_item.style.visibility == "hidden")
	{
		f_item.style.visibility = "visible";
		f_item.style.position = "relative";
		f_item.style.top = 0;
	}else{
		f_item.style.visibility = "hidden";
		f_item.style.position = "absolute";
	}
	return;
	for(i=0;i<showh_items_array.length;i++)
	{
		f_item = showh_items_array[i];
		fid = f_item.getAttribute("id");
		if(fid == id)
		{
			if(f_item.style.visibility == "hidden")
			{
				f_item.style.visibility = "visible";
				f_item.style.position = "relative";
				f_item.style.top = 0;
			}else{
				f_item.style.visibility = "hidden";
				f_item.style.position = "absolute";
				f_item.style.top = i * 20;
			}
		return;
		}
	}
}
//---------------------------------------------------------------------------------------------- 
function init_show_hide_items(classname)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
//		init_handle_nodes(classname);
		init_show_hide(classname);
	}
	else
	{
		init_show_hide(classname);
	}
}
//---------------------------------------------------------------------------------------------- 
function init_handle_nodes(classname)
{
	var div_items = new Array();
	div_items = document.getElementsByName(classname);
	j = 0;
	for(i=0;i<div_items.length;i++)
	{
		f_item = div_items[i];
		if(f_item.id)
		{
		alert(f_item.id);
			cache_items_array[j] = new Array();
			showh_items_array[j] = f_item;
			c_item = f_item.firstChild;
			child_items_array[j] = c_item;
			c_item.style.visibility = "hidden";
			cache_items_array[j][0] = c_item.childNodes.length;
			for(k=c_item.childNodes.length;k>0;k--)
			{
				t_item = c_item.childNodes[k-1];
				//alert(k + "  " + t_item.nodeName);
				cache_items_array[j][k] = t_item;
				c_item.removeChild(t_item);
			}
			f_item.removeChild(c_item);
			j++;
		}
	}
}
//---------------------------------------------------------------------------------------------- 
function init_show_hide(classname)
{
	div_items = document.getElementsByTagName("div");
	j = 0;
	for(i=0;i<div_items.length;i++)
	{
		f_item = div_items[i];
//		if(f_item.attributes.length > 1) alert(f_item.attributes.length +" "+ f_item.attributes[1].name +"="+ f_item.attributes[1].value);
		if(f_item.getAttribute("name") == classname)
		{
			showh_items_array[j] = f_item;
			j++;
			if(f_item.style.visibility == "hidden")
			{
				f_item.style.visibility = "visible";
			}
			else
			{
				f_item.style.visibility = "hidden";
				f_item.style.position = "absolute";
				f_item.style.top = i * 20;
			}
		}
	}
}
//---------------------------------------------------------------------------------------------- 
function searchWiki(str)
{
	if(str == '')
	{
		URL = "http://de.wikipedia.org/";
	}
	else
	{
		URL = "http://de.wikipedia.org/wiki/Spezial:Search?ns0=1&search=" + str + "&fulltext=Suche";
	}
	//alert(URL); return;
	wiki = window.open(URL, "_blank", "width=1098,height=720");
	wiki.focus();
}
//-----------------------------------------------------------------------------------
function nameCapitals(str)
{
	var chk = '';
	i = str.indexOf(' ');
	/*a = str.indexOf(' ');
	b = str.indexOf('-');
	if(a)
	i = Math.min(a, b);
	alert(a + ' - ' + b);
	*/
	if(i > 1)
	{
		chk = str.substr(0, i);
		str = str.substr(i+1);
		//alert(chk + ' vor ' + str);
		if(chk == 'am' || chk == 'an' || chk == 'aus' || chk == 'de' || chk == 'dem' || chk == 'den' || chk == 'der' || chk == 'im' || chk == 'in' || chk == 'la' || chk == 'le' || chk == 'van' || chk == 'vom' || chk == 'von' || chk == 'vorm')
		{
			//alert(str + ' vor ' + chk);
		}
		else
		{
			chk = nameCapitals(chk);
		}
		str = chk + ' ' + nameCapitals(str);
	}
	else
	{
		str = textCapitals(str);
	}
	return str;
}
//-----------------------------------------------------------------------------------
function textCapitals(str)
{
	var chk = '';
	i = str.indexOf('-');
	if(i > 0)
	{
		chk = str.substr(0, i);
		str = str.substr(i+1);
		str = firstCapital(chk) + '-' + textCapitals(str);
	}
	else
	{
		str = firstCapital(str);
	}
	return str;
}
//-----------------------------------------------------------------------------------
function firstCapital(str)
{
	if(str.length > 0)
	{
		chk = str;
		if(chk == 'am' || chk == 'an' || chk == 'aus' || chk == 'de' || chk == 'dem' || chk == 'den' || chk == 'der' || chk == 'im' || chk == 'in' || chk == 'la' || chk == 'le' || chk == 'van' || chk == 'vom' || chk == 'von' || chk == 'vorm')
		{
			//alert(str + ' vor ' + chk);
		}
		else if(str.substr(str.length-1) != '.' || str.substr(str.length-4) == 'str.')
		{
			// alert('Abkürzung ' + chk);
			str = str.substr(0,1).toUpperCase() + str.substr(1);
		}
	}
	return str;
}
//-----------------------------------------------------------------------------------
function set_field(fld, val)
{
	if(fld.value=='')
	{
		fld.value=val;
	}
}
//-----------------------------------------------------------------------------------
function supBlancs(str)
{
  for(i=0;i<str.length;++i)
    if(str.charAt(i)==" ")
	{
	  str=str.substr(0,i)+str.substr(i+1);
	  --i;
	}
  return str;
}
//-----------------------------------------------------------------------------------
function checkDecimal(dec)
{
	if(dec=='') return '0,00';
	if(!isNaN(dec))
	{
		dec=String(dec);
		dec = dec.replace(/\./,',');
	}
	for(i=dec.length-1; i>=0; i--)
	{
		test=dec.substr(i,1);
		if(isNaN(test))
		{
			if(test != ',' && test != '-')
			{
				dec = dec.replace(test,'');
			}
		}		
	}
	if(dec.indexOf(",")<0) dec+=',';
	dec+='00#';
	dec=dec.substring(0,dec.indexOf(",")+3);
	dec = dec.replace(/\./,'');
	return dec;
}
//-----------------------------------------------------------------------------------
function checkDate(date)
{
	if(date=='') return date;
	for(i=0; i<date.length; i++)
	{
		test=date.substr(i,1);
		if(isNaN(test) == true)
		{
			if(test != '.')
			{
				alert("Kein gültiges Datum!\n(Format ##.##.####)");
				return '';
			}
		}
	}
	if(date.indexOf(".")==0)
	{
		date=date+'.';
	}
 	dnow=new Date();
 	y=dnow.getYear();
 	if(y < 1000) y+=1900;
 	y=y+'';
 	m=dnow.getMonth()+1;
 	m="00"+m;
 	m=m.substr(m.length-2);
 	d=dnow.getDate();
 	d="00"+d;
 	d=d.substr(d.length-2);
 	datenow=y+m+d;
 	
 	datestr=date.split(".");
 	if(datestr.length == 0)
 	{
 		return '';
 	}
 	if(datestr[0])
 	{
 		d='00'+datestr[0];
 		d=d.substr(d.length-2);
 	}
 	datestr[0]=d;
 	if(datestr[1])
 	{
 		m='00'+datestr[1];
 		m=m.substr(m.length-2);
 	}
 	datestr[1]=m;
 	if(datestr[2])
 	{
 		i = 4 - datestr[2].length;
 		y=y.substr(0,i) + datestr[2];
 	}
 	datestr[2]=y;
 	date=datestr.join(".");
 	date=date.substr(0,10);
	return date;
}
//-----------------------------------------------------------------------------------
function checkDateOB(date)
{
	if(date=='') return date;
	for(i=0; i<date.length; i++)
	{
		test=date.substr(i,1);
		if(isNaN(test) == true)
		{
			if(test != '.')
			{
				alert("Kein gültiges Datum!\n(Format ##.##.####)");
				return '';
			}
		}
	}
	if(date.indexOf(".")==0)
	{
		date=date+'.';
	}
 	dnow=new Date();
 	y=1900;
 	y=y+'';
 	m=dnow.getMonth()+1;
 	m="00"+m;
 	m=m.substr(m.length-2);
 	d=dnow.getDate();
 	d="00"+d;
 	d=d.substr(d.length-2);
 	datenow=y+m+d;
 	
 	datestr=date.split(".");
 	if(datestr.length == 0)
 	{
 		return '';
 	}
 	if(datestr[0])
 	{
 		d='00'+datestr[0];
 		d=d.substr(d.length-2);
 	}
 	datestr[0]=d;
 	if(datestr[1])
 	{
 		m='00'+datestr[1];
 		m=m.substr(m.length-2);
 	}
 	datestr[1]=m;
 	if(datestr[2])
 	{
 		i = 4 - datestr[2].length;
 		y=y.substr(0,i) + datestr[2];
 	}
 	datestr[2]=y;
 	date=datestr.join(".");
 	date=date.substr(0,10);
	return date;
}
//-----------------------------------------------------------------------------------
function longDate(val)
{
	monate=new Array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	datestr=val.split('.');
	datestr[0]=parseInt(datestr[0]) + '.';
	datestr[1]=parseInt(datestr[1] * 1) - 1;
	datestr[1]=monate[datestr[1]];
	return datestr.join(' ');
}
//-----------------------------------------------------------------------------------
function checkInteger(val){
  for(i=0;i<val.length;++i)
    if(val.charAt(i) < "0" || val.charAt(i) > "9")
    { alert("Bitte nur Ziffern eingeben!");
	  val="";
    }
	return val;
}
//-----------------------------------------------------------------------------------
function checkDouble(val){
	  for(i=0;i<val.length;++i)
	    if(val.charAt(i) < "0" || val.charAt(i) > "9")
	      if(val.charAt(i) != ",")
		     { alert("Bitte nur Zahlen eingeben!");
	           val="";
	         }
	return val;
}
//-----------------------------------------------------------------------------------
function checkBLZ(val){
	if(val.length == 0)
		return val;
	val = supBlancs(val);
	for(i=0;i<val.length;++i)
		if(val.charAt(i) < "0" || val.charAt(i) > "9")
		{
			alert("Bitte nur Ziffern eingeben!");
			return '';
		}
	if(val.length < 8)
	{
		alert("Die Bankleitzahl muss 8 Ziffern haben!");
	}
	val = val.substring(0, 3) + ' ' + val.substring(3, 6) + ' ' + val.substring(6, 9);
	return val;
}
//-----------------------------------------------------------------------------------
function toASCII(val)
{
	searchArray = new Array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "á", "Á", "à", "À", "â", "Â", "é", "É", "è", "È", "ê", "Ê", "í", "Í", "ì", "Ì", "î", "Î", "ó", "Ó", "ò", "Ò", "ô", "Ô", "ú", "Ú", "ù", "Ù", "û", "Û");
	replaceArray = new Array ("ae", "AE", "oe", "OE", "ue", "UE", "ss", "a", "A", "a", "A", "a", "A", "e", "E", "e", "E", "e", "E", "i", "I", "i", "I", "i", "I", "o", "O", "o", "O", "o", "O", "u", "U", "u", "U", "u", "U");
	
	if(val.length == 0)
		return val;
	val = supBlancs(val);
	for(var i=0;i<searchArray.length;i++)
	{
		val=val.replace(searchArray[i],replaceArray[i]);
	}
	return val;
}
//-----------------------------------------------------------------------------------
function check_fileDate()
{
	f = location.href;
	f = f.substr(f.lastIndexOf("."));
	i = f.indexOf("htm");
	if(i < 0)
	{
		return;
	}
	today = new Date();
	y = today.getFullYear();
	m = '0' + (today.getMonth() + 1);
	m = m.substr(m.length-2);
	d = '0' + today.getDate();
	d = d.substr(d.length-2);
//	d = '06';
	heute = y + '-' + m + '-' + d;
	gueltig_bis = document.getElementById("file_valid_till").getAttribute("value");
	if(gueltig_bis < heute)
	{
		// *.php im gleichen Verzeichnis aufrufen, ggf. area als Parameter
		//i = location.href.lastIndexOf("/");
		f = location.href; //.substr(i + 1);
		f = f.substr(0,f.lastIndexOf("."));
		i = f.lastIndexOf("_");
		if(i > 0)
		{
			f = f.substr(0,i) + ".php?area=" + f.substr(i + 1);
		}
		else
		{
			f = f + ".php";
		}
		//alert(gueltig_bis);alert(f);return;
		location.href = f;
	}
}
//-----------------------------------------------------------------------------------
function reset_msgDisplay()
{
	if(msg = document.getElementById("msg"))
	{
		msg.style.visibility = 'hidden';
	}
	//alert(msg.style.visibility);
}
//-----------------------------------------------------------------------------------
function dispLength(elem)
{
	max_len = document.getElementById(elem.name + "_maxLength").firstChild.nodeValue;
	if(elem.value.length >= max_len)
	{
		elem.value = elem.value.substr(0, max_len);
	}
	disp = document.getElementById(elem.name + "_dispLength");
	disp.firstChild.nodeValue = elem.value.length;
}
//-----------------------------------------------------------------------------------

