//alert("common");
//---------------------------------------------------------------------------------------------- 
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);
	}
}
//---------------------------------------------------------------------------------------------- 
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.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;
}
//-----------------------------------------------------------------------------------
