//	Deakivieren / Aktivieren von Formularfeldern

function SetDisableFieldByName(name, status)
{
	obj	=	gebn(name);
	if(obj != null && !status)
	{	obj.disable().setStyle({backgroundColor:""});	}
	else if(obj != null)
	{	obj.enable().setStyle({backgroundColor:"silver"});	}
}


function changeChecked(id)
{	$(id).checked	=	($(id).checked == true) ? true : false;
	return $(id).checked;
}

function showById(id)
{	$(id).show();	}
function showByIdOhne(id)
{	$(id).show();	}

function hideById(id)
{	$(id).hide();	}

function ddrivetip()
{	tip_it();	}
function hideddrivetip()
{	tip_it();	}
function hideByIdOhne(id)
{	$(id).hide();	}

var userBox	=	
{
	top: 0,
	left:0,
	show: function (title,text,width,jsyes,jsno)
	{
		yesno	=	true;
		img		=	'<img src="images/icons/help.png">';
		if(title == '')
		{
			title	=	'Hinweis';
			yesno	=	false;
			img		=	'<img src="images/icons/exclamation.png">';
		}
		body	=	$$('body')[0];
		html	=	'<div id="uBDtitle">'+img+title+'</div>'+
					'<div id="uBDtext">'+text+'</div>'+
					((yesno) ? '<div id="uBDyes"><a onclick="'+jsyes+';$(\'uBD\').remove();">Ja</a></div><div id="uBDno"><a onclick="'+jsno+';$(\'uBD\').remove();">Nein</a></div>' : '<div id="uBDok"><a id="button" onclick="'+jsyes+';$(\'uBD\').remove();">OK</a></div>');
		if($('uBD') == null)
		{	
			body.insert({bottom: new Element('div', { 'id': 'uBD'}).setStyle({margin:'auto auto', 'width': (width)+'px'})});
		}
		this.top		=	(document.viewport.getHeight()/2)-($('uBD').getHeight()/2);
		this.left	=	(document.viewport.getWidth()/2)-($('uBD').getWidth()/2);
		$('uBD').setStyle({'left':this.left+'px','top':this.top+'px'});
		$('uBD').update(html);
		new Draggable('uBD',{handle:'uBDtitle',starteffect: userBox.nothing,endeffect:userBox.nothing});


	},
	hide: function ()
	{
		if($('uBD') != null)
		{	$('uBD').remove();	}
	},
	nothing: function ()
	{
		
	}
}
/**
 * Funktion zum anzeigen eines Tooltips
 *
 */

function tip_it()
{
	if($('ToolTip') == null)
	{	$$('body')[0].insert({bottom: new Element('div', { 'id': 'ToolTip'}).setStyle({position:'absolute'})});	}
	
	if(tip_it.arguments.length > 0 && $('ToolTip') != null)
	{	ContentInfo = ''+
			'<table border="0" cellspacing="0" cellpadding="1" class="tooltiptable" '+((tip_it.arguments.length>2) ? ' width="'+tip_it.arguments[2]+'" ' : '')+'>'+
				((tip_it.arguments.length > 1 && tip_it.arguments[1] != "") ? '<tr><td width="100%" class="tooltiptitle">'+tip_it.arguments[1]+'</td></tr>' : '')+
				'<tr><td width="100%" class="tooltipcontent">'+tip_it.arguments[0]+'</td></tr>'+
			'</table>';
		$('ToolTip').update(ContentInfo).show();
	}
	else if($('ToolTip') != null)
	{	$('ToolTip').update().hide();	}
}

function ddrivetip(text,width)
{
	tip_it(text,'',width);
}


function hideByIdTime(id)
{	setTimeout("$('"+id+"').hide();",500);	}

function hideByIdTimeOhne(id)
{	setTimeout("$('"+id+"').hide();",500);	}

function switchById(id)
{	return ($(id).toggle().getStyle('display') == 'none') ? false: true;	}

	function rePosInfo(oldname,versetzung)
		{
		if(!versetzung) versetzung =0;
		neuesObj	=	gebi('tabedinfo');
		altesObj	=	gebn(oldname);

		//	alert(oldname+": "+getLeft(altesObj) +" / "+getTop(altesObj));
		altesX		=	getLeft(altesObj);
		altesY		=	getTop(altesObj);
		neuesX		=	altesX;
		neuesY		=	altesY+24+versetzung;
		neuesObj.style.position	=	"absolute";
		neuesObj.style.left		=	neuesX+"px";
		neuesObj.style.top		=	neuesY+"px";
		neuesObj.style.zIndex	=	100;	
		//	alert(oldname+": "+getLeft(neuesObj) +" / "+getTop(neuesObj));
		}

function removeErrorBubbles()
{	alleBubbles	=	$$('div.errorbubble').each(Element.remove);	}
	
function rmSingleBubbles(name)
{	alleBubbles	=	$$('div.errorbubble[info='+name+']').each(Element.remove);	}

function rePosAnyName(qo,zo)
{	rePosAny(gebn(qo),zo);	}
		function gLeftAbs(qo)
		{	var cl = 0;
			if (qo.offsetParent) {	while (qo = qo.offsetParent) {	if(qo.style.position == 'absolute') {	cl += qo.offsetLeft;	}	}	}
			else if (qo.x) {	return qo.x;	}
			return cl;
		}

		function gLeft(qo) 
		{	var cl = 0;
			if (qo.offsetParent) {	cl = qo.offsetLeft;	while (qo = qo.offsetParent)	{	cl += qo.offsetLeft;	}	}
			else if (qo.x) {	return qo.x;	}
			return cl;
		}

		function gTopAbs(qo)
		{	var ct = 0;
			if (qo.offsetParent) {	while (qo = qo.offsetParent) {	if(qo.style.position == 'absolute') {	ct += qo.offsetTop;	}	}	}
			else if (qo.x) {	return qo.x;	}
			return ct;
		}

		function gTop(qo) 
		{	var ct = 0;
			if (qo.offsetParent) {	ct = qo.offsetTop;	while (qo = qo.offsetParent) {	ct += qo.offsetTop;	}	}
			else if (qo.y) {	return qo.y;	}
			return ct;
		}
		function rePosAny2(qo,zo)
		{	
			Element.clonePosition($(zo),$(qo));
			if($(qo) != null && $(zo) != null)
			{
				var cleft	=	gLeft($(qo))-gLeftAbs($(zo));
				var ctop	=	gTop($(qo))-gTopAbs($(zo));
			//	$(zo).setStyle({left:cleft+"px",top:ctop+'px',position:'absolute'});
			}
		}
			
function generateErrorbubble(name,inhalt,richtung)
{
	$$('body')[0].insert({bottom: new Element('div', { 'id':'errorbubble'+$$('div.errorbubble').length,'class':'errorbubble','info':name}).setStyle({position:'absolute',width:'131px',zIndex:'50'}).update(Base64.decode(inhalt))});	
	rePosAnyName(name,'errorbubble'+($$('div.errorbubble').length-1));
	switch(richtung)
	{
		case "left":
			rePosLeft(moveid);
			break;
		case "right":
			rePosRight(moveid,name);
			break;
		case "bottom":
			rePosBottom(moveid,name);
			break;
	}
}

function rePosLeft(id)
{
	selobj		=	gebi(id);
	selwidth	=	selobj.clientWidth;
	neuesX		=	getLeft(selobj)-getAbsDiffLeft(selobj)-selwidth;
	selobj.style.left		=	neuesX+"px";
}
function rePosRight(id,name)
{
	selobj		=	gebi(id);
	quellobj	=	gebn(name);
	quellwidth	=	quellobj.clientWidth;
	neuesX		=	getLeft(selobj)-getAbsDiffLeft(selobj)+quellwidth;
	selobj.style.left		=	neuesX+"px";
}
function rePosBottom(id,name)
{
	selobj		=	gebi(id);
	quellobj	=	gebn(name);
	quellheight	=	quellobj.clientHeight;
	neuesY		=	getTop(selobj)-getAbsDiffTop(selobj)+quellheight;
	selobj.style.top		=	neuesY+"px";
}

function IdBottomName(id,name)
{
	quellobj	=	$$('[name='+name+']')[0];
	selobj		=	$(id);
	Element.absolutize(selobj);
	quellheight	=	quellobj.getHeight()+1;
	Element.clonePosition(selobj, quellobj,{ offsetTop: quellheight,height: false, width: false});
}


function formFeedbackSetAW1(newvalue)
	{
	gebn('antwort1').value=newvalue;
	}



function addButton(mykey)
	{
	if(myobj)
		{
		aktvalue		=	myobj.value;
		newvalue		=	aktvalue+mykey;
		if(myobj.maxLength && myobj.maxLength > 0)
			{
			maxlength		=	myobj.maxLength;
			myobj.value		=	newvalue.substring(0,maxlength);
			}
		else
			{
			myobj.value		=	newvalue;
			}
		myobj.focus();
		}
	}
function remButton()
	{
	if(myobj)
		{
		var aktvalue	=	"";
		aktvalue		=	myobj.value;
		aktlength		=	aktvalue.length;
		if(aktlength > 0)
			myobj.value		=	aktvalue.substring(0,aktlength-1);
		myobj.focus();
		}
	}


function lowButton()
	{
	gebi('lower').show();
	gebi('upper').hide();
	}

function uppButton()
	{
	gebi('upper').show();
	gebi('lower').hide();
	}

function destroyObj(givenobj)
{
	if(givenobj.id)
	{
		givenobjselobj	=	gebi(givenobj.id);
		givenobjselobjparent	=	givenobjselobj.parentNode;
		if(givenobjselobjparent)
		{
			givenobjselobjparent.removeChild(givenobjselobj);
		}
	}
}

function keyboardshowhide(richtung)
{
	if(richtung == 'down')
	{
		versetzungX	=	0-50;
		versetzungY	=	50;
	}
	else
	{
		versetzungX	=	0-200;
		versetzungY	=	0-200;
	}
	
	if(gebi('keyboard'))
	{
		if(gebi('keyboard').style.visibility =='visible')
		{
			gebi('keyboard').style.visibility='hidden';
			gebi('keyboard').style.display='none';
			document.onmousemove = null;
			document.onmouseup = null;
		}
		else
		{
			gebi('keyboard').style.visibility='visible';
			gebi('keyboard').style.display='inline';
			tempadd		=	(Math.round((Math.random()*15)) *5);
			orginaltop	=	getAttributeByName(gebi('keyboard'), "orginaltop");
			orginalleft	=	getAttributeByName(gebi('keyboard'), "orginalleft");
			temptop		=	gebi('keyboard').offsetTop;
			templeft	=	gebi('keyboard').offsetLeft;
			if(orginaltop == "0" || orginaltop == 0)
			{
				gebi('keyboard').orginaltop		=	temptop+versetzungY;
				gebi('keyboard').orginalleft	=	templeft+versetzungX;
				gebi('keyboard').setAttribute("orginaltop",temptop);
				gebi('keyboard').setAttribute("orginalleft",templeft);
			}
			else
			{
				temptop		=	parseInt(orginaltop);
				templeft	=	parseInt(orginalleft);
			}
			templeft	=	templeft+tempadd;
			temptop		=	temptop+tempadd;
		
			gebi('keyboard').style.left	=	templeft+'px'
			gebi('keyboard').style.top	=	temptop+'px';
	//		document.onmousemove = drag;
	//		document.onmouseup = dragstop;
		}
	}
}



function activatefield(keyname)
{
	aktiv	=	'#DDFFDD';
	myborder	=	'1px solid silver';
	var a = new Array('kennung','kundenid','oldpw','newfirst','newsecond','login','password','tan1','tan2','tanliste','ssloldpw','ssltanliste','outsidebkennung','outsidelogin');
	for (var i = 0; i < a.length; ++i)
	{
		name	=	a[i];
		if(gebn(name))
		{
			if(keyname == name)
				gebn(name).style.backgroundColor=aktiv;
			else
				gebn(name).style.backgroundColor='white';
			gebn(name).style.border=myborder;
		}
	}
}

var myobj = gebi("kennung");
if(myobj)
	{
	}
else
	{
	var myobj = gebi("login");
	}
function rePosAnyBottom(selid,quellid)
{	Element.clonePosition($(selid),$(quellid),{offsetTop: $(quellid).getHeight(), setWidth:false, setHeight:false});	}

function treeSelect(liste,selectionen)
{
	selection	=	selectionen[0];
	newselections	=	selectionen.without(selection);
	neueliste	=	new Array();
	y=0;
	for(x=0;x<liste.length;x++)
	{
		if(liste[x].hasClassName(selection))
		{
			neueliste[y]	=	liste[x];
			y++;
		}
	}
	if(newselections.length >0)
		return treeSelect(neueliste,newselections);
	else
		return neueliste;
}
var publiccat = '';
var publicumkreis = '';
var publicplz = '';
function vTree(cat,umkreis,plz)
{
	selectionen		=	new Array();
	menusel			=	new Array();
	publiccat		=	((cat == '')	 ? publiccat	 : ((cat == 'cat_false')	 ? '' : cat));
	publicumkreis	=	((umkreis == '') ? publicumkreis : ((umkreis == 'umkreis_false') ? '' : umkreis));
	publicplz		=	((plz == '')	 ? publicplz	 : ((plz == 'plz_false')	 ? '' : plz));
	x=0;
	y=0;
	if(publiccat != '')
	{	selectionen[x]	=	publiccat;	x++;	}
	else
	{	menusel[y]		=	'cat_false';	y++;	}
	if(publicumkreis != '')
	{	selectionen[x]	=	publicumkreis;	x++;	}
	else
	{	menusel[y]		=	'umkreis_false';	y++;	}
	if(publicplz != '')
	{	selectionen[x]	=	publicplz;	x++;	}
	else
	{	menusel[y]		=	'plz_false';	y++;	}
	$$('div.ergebnisse').each(Element.hide);
	menulinks	=	$('treemenumain').select('li').toArray();
	for(myx=0;myx<menulinks.length;myx++)
	{
		if(selectionen.indexOf(menulinks[myx].id) == -1 && menusel.indexOf(menulinks[myx].id) == -1)
		menulinks[myx].removeClassName('active');
		else
		menulinks[myx].addClassName('active');
	}
	neueliste	=	treeSelect($$('div.ergebnisse').toArray(),selectionen);
	if(neueliste.length>0)
	{
		for(myx=0;myx<neueliste.length;myx++)
		{
			neueliste[myx].show();
		}
	}
}
