
//28.07.09


var keycodes={
'033':'PGUP',
'034':'PGDN' ,
'035':'END',
'036':'HOME',
'037':'LEFT',
'038':'UP',
'039':'RIGHT',
'040':'DOWN',
'0145':'SCROLL',
'019':'PAUSE',
'09':'TAB',
'08':'BACKSPACE',
'046':'DEL',
'0144':'NUMLOCK',
'013':'CR',
'045':'INS',
'027':'ESC',
'0112':'F1',
'0113':'F2',
'0114':'F3',
'0115':'F4',
'0116':'F5',
'0117':'F6',
'0118':'F7',
'0119':'F8',
'0120':'F9',
'0121':'F10',
'0122':'F11',
'0123':'F12',
'017':'CTRL',
'018':'ALT',
'016':'SHIFT',
'092':'WIN',
'093':'MENU',
'020':'CAPSLOCK'
}
var y=0
if(typeof(top.popups)=='undefined')  top.popups = {};

function menuclick(action,target,name){//wird aus contextmenue aufgerufen

	if (self[action]) {eval(action+"()")}//action kommt als js-function vor, aufrufen
	else {
		//if (!$(target)) window.open(window.location.pathname+\'?action=\'+action,"xxxx","width=300,height=400,left=100,top=200")
		//if (action.indexOf(window.location.pathname)==-1 && action.indexOf(\'http://\')==-1) action=window.location.pathname+\'?action=\'+action
		//sollte http:links direkt aufrufen, sonst deepbase mit action ... funzt noch nichts
		//if (!$(target)){ f1=window.open(window.location.pathname+\'?action=\'+action,action,"toolbar=1,location=1,scrollbars=1,resizable=1,width=1000,height=800,top=50,left=50");f1.focus();}
		if (target=="popup"){
			if(typeof(name)=='undefined'){
				if(action=='fckedit'){//wir wissen im browser noch nicht, welches script geladen werden soll, also per ajax den server fragen
					new Ajax.Request("?action=ajax&script=¢str(¢lizkey,¢form['formname'])",{
						onComplete: function (response){
							menuclick(action,target,response.responseText);//rekursiv nochmals hier hinein
							return
						}
					});
					return
				}
				else name=action
			}
			popupname=name.replace(/[ %&=]/gi,'')//ie mag keine blanks verleiden
			if(window.e && window.e.ctrlKey)popupname+='_1'
			if (top.popups[popupname] && !top.popups[popupname].closed ) {
				top.popups[popupname].focus()

				return;
			}
			else {

				/*top.popups[name]=window.open('javascript:;',name,"toolbar=1,location=1,scrollbars=1,resizable=1,width=1000,height=800,top=50,left=50");
				if(top.popups[name].document.URL!='about:blank' ){
				top.popups[name].focus()
				}
				else */ {
				top.popups[popupname]=window.open(action.indexOf('ttp://')>-1?action:'deepbase.php?action='+action+'&'+name,popupname,"toolbar=1,location=1,menubar=1,scrollbars=1,statusbar=1,resizable=1,width=1200,height=900,top=50,left=50");
				top.popups[popupname].focus();
				}
				return
			}
		}
		else if(target=='_self'){
			document.location.href='deepbase.php?action='+action
		}
		else 
		//target!=popup{//kein oder anderes target angegeben; im responstext kann jedoch vom server trotzdem ein target verlangt werden, <!-- target=framename.div -->
		new Ajax.Request('deepbase.php?action='+action+'&ajax', {
			onSuccess: function(transport) {
				sendToTarget(transport.responseText)
				if(transport.responseText.match('/<div title=/"Erro'))alert(transport.responseText)
				menuclick.target=typeof(target)=='string'?$$(target)[0]:$(target)
				if(menuclick.target)menuclick.target.update(transport.responseText)
			}
		});
	return

	}
	if (opener && opener.top.frames[target]) {opener.top.frames[target].location='deepbase.php?action='+action;return;}
	if ($(target) && target!='')  {
		$(target).update('deepbase.php?action='+action)
		new Ajax.Updater($(target), window.location.pathname);
	}
	else {

	}
}





/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* @link   http://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
*/

function RGBColor(color_string)
{
	this.ok = false;
	if(color_string.indexOf('rgb')==0) return(color_string)
	// strip any leading #
	if (color_string.charAt(0) == '#') { // remove # if any
		color_string = color_string.substr(1,6);
	}

	color_string = color_string.replace(/ /g,'');
	color_string = color_string.toLowerCase();

	// before getting into regexps, try simple matches
	// and overwrite the input
	var simple_colors = {
		aliceblue: 'f0f8ff',
		antiquewhite: 'faebd7',
		aqua: '00ffff',
		aquamarine: '7fffd4',
		azure: 'f0ffff',
		beige: 'f5f5dc',
		bisque: 'ffe4c4',
		black: '000000',
		blanchedalmond: 'ffebcd',
		blue: '0000ff',
		blueviolet: '8a2be2',
		brown: 'a52a2a',
		burlywood: 'deb887',
		cadetblue: '5f9ea0',
		chartreuse: '7fff00',
		chocolate: 'd2691e',
		coral: 'ff7f50',
		cornflowerblue: '6495ed',
		cornsilk: 'fff8dc',
		crimson: 'dc143c',
		cyan: '00ffff',
		darkblue: '00008b',
		darkcyan: '008b8b',
		darkgoldenrod: 'b8860b',
		darkgray: 'a9a9a9',
		darkgreen: '006400',
		darkkhaki: 'bdb76b',
		darkmagenta: '8b008b',
		darkolivegreen: '556b2f',
		darkorange: 'ff8c00',
		darkorchid: '9932cc',
		darkred: '8b0000',
		darksalmon: 'e9967a',
		darkseagreen: '8fbc8f',
		darkslateblue: '483d8b',
		darkslategray: '2f4f4f',
		darkturquoise: '00ced1',
		darkviolet: '9400d3',
		deeppink: 'ff1493',
		deepskyblue: '00bfff',
		dimgray: '696969',
		dodgerblue: '1e90ff',
		feldspar: 'd19275',
		firebrick: 'b22222',
		floralwhite: 'fffaf0',
		forestgreen: '228b22',
		fuchsia: 'ff00ff',
		gainsboro: 'dcdcdc',
		ghostwhite: 'f8f8ff',
		gold: 'ffd700',
		goldenrod: 'daa520',
		gray: '808080',
		green: '008000',
		greenyellow: 'adff2f',
		honeydew: 'f0fff0',
		hotpink: 'ff69b4',
		indianred : 'cd5c5c',
		indigo : '4b0082',
		ivory: 'fffff0',
		khaki: 'f0e68c',
		lavender: 'e6e6fa',
		lavenderblush: 'fff0f5',
		lawngreen: '7cfc00',
		lemonchiffon: 'fffacd',
		lightblue: 'add8e6',
		lightcoral: 'f08080',
		lightcyan: 'e0ffff',
		lightgoldenrodyellow: 'fafad2',
		lightgrey: 'd3d3d3',
		lightgreen: '90ee90',
		lightpink: 'ffb6c1',
		lightsalmon: 'ffa07a',
		lightseagreen: '20b2aa',
		lightskyblue: '87cefa',
		lightslateblue: '8470ff',
		lightslategray: '778899',
		lightsteelblue: 'b0c4de',
		lightyellow: 'ffffe0',
		lime: '00ff00',
		limegreen: '32cd32',
		linen: 'faf0e6',
		magenta: 'ff00ff',
		maroon: '800000',
		mediumaquamarine: '66cdaa',
		mediumblue: '0000cd',
		mediumorchid: 'ba55d3',
		mediumpurple: '9370d8',
		mediumseagreen: '3cb371',
		mediumslateblue: '7b68ee',
		mediumspringgreen: '00fa9a',
		mediumturquoise: '48d1cc',
		mediumvioletred: 'c71585',
		midnightblue: '191970',
		mintcream: 'f5fffa',
		mistyrose: 'ffe4e1',
		moccasin: 'ffe4b5',
		navajowhite: 'ffdead',
		navy: '000080',
		oldlace: 'fdf5e6',
		olive: '808000',
		olivedrab: '6b8e23',
		orange: 'ffa500',
		orangered: 'ff4500',
		orchid: 'da70d6',
		palegoldenrod: 'eee8aa',
		palegreen: '98fb98',
		paleturquoise: 'afeeee',
		palevioletred: 'd87093',
		papayawhip: 'ffefd5',
		peachpuff: 'ffdab9',
		peru: 'cd853f',
		pink: 'ffc0cb',
		plum: 'dda0dd',
		powderblue: 'b0e0e6',
		purple: '800080',
		red: 'ff0000',
		rosybrown: 'bc8f8f',
		royalblue: '4169e1',
		saddlebrown: '8b4513',
		salmon: 'fa8072',
		sandybrown: 'f4a460',
		seagreen: '2e8b57',
		seashell: 'fff5ee',
		sienna: 'a0522d',
		silver: 'c0c0c0',
		skyblue: '87ceeb',
		slateblue: '6a5acd',
		slategray: '708090',
		snow: 'fffafa',
		springgreen: '00ff7f',
		steelblue: '4682b4',
		tan: 'd2b48c',
		teal: '008080',
		thistle: 'd8bfd8',
		tomato: 'ff6347',
		turquoise: '40e0d0',
		violet: 'ee82ee',
		violetred: 'd02090',
		wheat: 'f5deb3',
		white: 'ffffff',
		whitesmoke: 'f5f5f5',
		yellow: 'ffff00',
		yellowgreen: '9acd32'
	};
	for (var key in simple_colors) {
		if (color_string == key) {
			color_string = simple_colors[key];
			break;
		}
	}
	// emd of simple type-in colors

	// array of color definition objects
	var color_defs = [
	{
		re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
		example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
		process: function (bits){
			return [
			parseInt(bits[1]),
			parseInt(bits[2]),
			parseInt(bits[3])
			];
		}
	},
	{
		re: /^(\w{2})(\w{2})(\w{2})$/,
		example: ['#00ff00', '336699'],
		process: function (bits){
			return [
			parseInt(bits[1], 16),
			parseInt(bits[2], 16),
			parseInt(bits[3], 16)
			];
		}
	},
	{
		re: /^(\w{1})(\w{1})(\w{1})$/,
		example: ['#fb0', 'f0f'],
		process: function (bits){
			return [
			parseInt(bits[1] + bits[1], 16),
			parseInt(bits[2] + bits[2], 16),
			parseInt(bits[3] + bits[3], 16)
			];
		}
	}
	];

	// search through the definitions to find a match
	for (var i = 0; i < color_defs.length; i++) {
		var re = color_defs[i].re;
		var processor = color_defs[i].process;
		var bits = re.exec(color_string);
		if (bits) {
			channels = processor(bits);
			this.r = channels[0];
			this.g = channels[1];
			this.b = channels[2];
			this.ok = true;
		}

	}

	// validate/cleanup values
	this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
	this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
	this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);

	// some getters
	this.toRGB = function () {
		return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
	}

	this.toHex = function () {
		var r = this.r.toString(16);
		var g = this.g.toString(16);
		var b = this.b.toString(16);
		if (r.length == 1) r = '0' + r;
		if (g.length == 1) g = '0' + g;
		if (b.length == 1) b = '0' + b;
		return '#' + r + g + b;
	}

	// help
	this.getHelpXML = function () {

		var examples = new Array();
		// add regexps
		for (var i = 0; i < color_defs.length; i++) {
			var example = color_defs[i].example;
			for (var j = 0; j < example.length; j++) {
				examples[examples.length] = example[j];
			}
		}
		// add type-in colors
		for (var sc in simple_colors) {
			examples[examples.length] = sc;
		}

		var xml = document.createElement('ul');
		xml.setAttribute('id', 'rgbcolor-examples');
		for (var i = 0; i < examples.length; i++) {
			try {
				var list_item = document.createElement('li');
				var list_color = new RGBColor(examples[i]);
				var example_div = document.createElement('div');
				example_div.style.cssText =
				'margin: 3px; '
				+ 'border: 1px solid black; '
				+ 'background:' + list_color.toHex() + '; '
				+ 'color:' + list_color.toHex()
				;
				example_div.appendChild(document.createTextNode('test'));
				var list_item_value = document.createTextNode(
				' ' + examples[i] + ' -> ' + list_color.toRGB() + ' -> ' + list_color.toHex()
				);
				list_item.appendChild(example_div);
				list_item.appendChild(list_item_value);
				xml.appendChild(list_item);

			} catch(e){}
		}
		return xml;

	}
	return(this.toRGB()) //finito hier, rh;

}

function round(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result.toFixed(dec);
}
function sum(targetclass,result){//07.04.09 in tabellen alle elemente die targetclass vorkommen, summieren
	var ret = 0
	$$(targetclass).each(function (item){
		ret+=parseFloat(item.innerHTML.split('\'').join())
	})

	$$('.calc')[0].textContent=round(ret,2)
	return(round(ret,2))

}



Array.prototype.sum = function() {
	return (! this.length) ? 0 : this.slice(1).sum() +
	((typeof this[0] == 'number') ? this[0] : 0);
};

function Sumcol(e){//in arbeit; in Kreuztabelle soll die anzahl selektierten berechnet werden

	//alert(suchajh(e).attributes.ajh)
}
function suchajh(event){
	e=event.target
	if(e.tagName=='SELECT') e=e.options[e.selectedIndex]
	while(e.parentNode && !e.attributes.ajh ){
		e=e.parentNode
	}
	return(e.attributes && e.attributes.ajh?e:event.target.down('[ajh]'))
}
function debug(e){//weil js in htmlscripts manchmal nicht debgierbar, aufruf hierher fuer breakpoint
	alert(e)
	window.status=e
	debugger
}
function melde(text){
	var status=$('status')
	if(!status){
		//Element.insert(document.body,'<span style="position:fixed;top:0;left:0;border:thin solid;background-color:lightgreen" id=status>meldungen</span><script>ADD_DHTML("status")</script>')
		Element.insert(document.body,'<span style="position:fixed;top:0;left:0;border:thin solid;background-color:lightgreen" id=status>meldungen</span>')
		status=$('status')
	}
	status.update(text)
}
function autofit(){//15.01.09
	var dim = $(window.document.body).getDimensions() //ohne $() gibts ärger im IE
	var vp=document.viewport.getDimensions()
	//melde(dim.width+' ,'+dim.height+' ; '+vp.width+','+vp.height)
	window.resizeTo(dim.width+40,dim.height+80)//05.05.09 pendent: getDimension von body bringt bei reload andere dimensionen in chrome und ie
}

getViewport = function() {
	var width = 0;
	var height = 0;
	if( document.documentElement && document.documentElement.clientWidth ) {
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientWidth ) {
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	else if( window.innerWidth ) {
		width = window.innerWidth - 18;
		height = window.innerHeight - 18;
	}
	return {x:width,y:height}
};


getViewportScroll = function() {
	var scrollX = 0;
	var scrollY = 0;
	if( document.documentElement && document.documentElement.scrollLeft ) {
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop;
	}
	else if( document.body && document.body.scrollLeft ) {
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop;
	}
	else if( window.pageXOffset ) {
		scrollX = window.pageXOffset;
		scrollY = window.pageYOffset;
	}
	else if( window.scrollX ) {
		scrollX = window.scrollX;
		scrollY = window.scrollY;
	}
	return ({x:scrollX,y:scrollY})
};


function xautofit(){//15.01.09
	//var d=document.body.getDimensions()
	//alert(window.menubar)
	//var scrollstatus=window.scrollbars.visible

	//while(diff<0)//30.03.09 baustelle: diff wird falsch berechnet, bei 2 bildschirmen stimmt was nicht
	{
		window.scrollbars.visible=true
		diff=window.innerHeight-document.body.scrollHeight
		//alert(window.innerHeight+' '+window.outerHeight+' '+document.body.scrollHeight+' '+diff)
		window.resizeTo(window.outerHeight+diff,window.outerHeight)
	}
	//alert(window.innerHeight+' '+document.body.scrollHeight)
	diff=window.innerWidth-document.body.scrollWidth
	window.resizeTo(window.outerWidth-diff,window.outerHeight)

	//window.scrollbars.visible=scrollstatus
	//window.resizeTo(d.width+24,70+d.height+(window.menubar.visible?35:0)+(window.statusbar.visible?35:0)+(window.locationbar.visible?35:0)+(window.personalbar.visible?35:0))

}

function updateaufrufer(item){
	var feld
	if(Object.keys(top.popups).length==0) top.popups['activewindow']=window
	for (var w in top.popups )if (typeof(top.popups[w].$$)=='function'){
		top.popups[w].$$('#'+item.id).each(function(feld){
		if(feld.down('input')) feld.down('input').value
		else if (feld.value) feld.value=item.value;
		else feld.update(item.value)
		})
	}
}

function checkform(){
	var result=''
	$$('input,textarea').each(
	function(item){
		if(item.value=='*'){alert('Felder mit * müssen ausgefüllt werden');result+=item.name;}
		//if(opener)updateaufrufer(item)
	}
	)
	return(result==''?true:false);
}


function Togglestatus(e){
	if(typeof(e)=='number') {//aufruf beim laden der seite
		$$('.s'+e).invoke('hide')
		return
	}
	if (e.findElement('tr').id=='pivottitel'){//click in spaltenueberschrift
		var stufe =parseInt(e.target.parentNode.className.split(' ')[0].split('s')[1])+1
		var richtung=e.target.innerHTML.substr(e.target.innerHTML.length-1)
		document.body.style.cursor = "wait"
		if (richtung=='-'){//alle stufen rechts schliessen
			var stf
			var classstufen
			$$('#pivottitel th ').each(function (item){//filtern aller th's mit class stufe > als stufe
				if ((stf=(item.className+'s ').split('s')[1].split(' ')[0])>=stufe) {
					Togglestatus(parseInt(stf))
					item.innerHTML=item.innerHTML.split(richtung)[0]+(item.innerHTML.split(richtung)[1]?'+':'')
				}
			})
		}
		else {
			$$('.s'+stufe).invoke('show')
		}
		document.body.style.cursor = ""
	}
	e.target.innerHTML=e.target.innerHTML.split(richtung)[0]+(richtung=='+'?'-':'+')
	return
}

function editrecord(event){
	var id
	if (id=event.findElement('tr').id){
		var url = 'bearbeiten&modus=nachladen&id='+id;
		var pars = '';
		nachladen_post( url,'bearbeiten')
	}
}

function Call(e){//18.02.09
	if (!e) e = window.event;
	if(e.target.attributes.ddfunction){//pivot click auf betrag
		var target =e.target
		var action = Event.findElement(e,'tr').attributes.pid.value
		action +='&ddfunction='+target.attributes.ddfunction.value
		var windowtyp=target.attributes.target? target.attributes.target.value:'popup' //defaults setzen
		var pars=target.attributes.targetpar? target.attributes.targetpar.value:'resizable=1,menubar=1,scrollbars=1,width=800,height=500,left=150,top=50'
		var title=target.attributes.targettitle?target.attributes.targetpar:''
		/*
		status  	The status bar at the bottom of the window.
		toolbar 	The standard browser toolbar, with buttons such as Back and Forward.
		location 	The Location entry field where you enter the URL.
		menubar 	The menu bar of the window
		directories 	The standard browser directory buttons, such as What's New and What's Cool
		resizable 	Allow/Disallow the user to resize the window.
		scrollbars 	Enable the scrollbars if the document is bigger than the window
		height 	Specifies the height of the window in pixels. (example: height='350')
		width 	Specifies the width of the window in pixels.
		*/
	}
	else{//ajaxlink erstellt mit ¢ajax(...)
		var target = e.target.tag!='div'?e.findElement('div'):target=e.target
		if(target.attributes.targetpar) {
			var pars=target.attributes.targetpar.value
			pars=pars.split(':').join('=')
			var action=target.attributes.id.value
			var windowtyp=target.attributes.target.value
		}
	}
	if(windowtyp=='popup'){
		var ziel=window.open(document.location.href.split('?')[0]+'?action='+action,"popup",pars?pars:'resizable=1,menubar=1,width=800,height=500,left=150,top=50')//18.02.09
		ziel.focus()
	}
}

function reload(parameter){
	if (parameter) var location = parameter.indexOf('?')?document.location.split('?')[0]:document.location
	else location=document.location
	document.location=location+parameter

}
function Loadrecord(event){
	var t
	if (t=event.findElement('table').attributes.ajh){
		nachladen_post(t.value+';'+event.findElement('tr').id,false,loadrecord)
		return
	}
	var dt=event.findElement('tr').childNodes
	var f=$$('.feld')
	var fn=$$('#datatable th')
	for (var i=0; i<fn.length;i++){
		var feld
		if (feld=$('feld_'+fn[i].id)){
			if (feld.onchange) feld.onchange()
			feld.innerHTML=dt[i].innerHTML
		}
	}
	event.findElement('table').remove() //ok, solange der dialog in einer tabelle statfindet
}

function openwindow(action,title,targetpar,ev){
	if(!targetpar=='') targetpar='menubar=1,toolbar=1,width=800,menubar=1,scrollbars=1,height=600,left=100,top=200,resizable=yes'
	targetpar=ev.target.attributes.targetpar?e.attributes.targetpar.value.split(":").join("="):targetpar.split(":").join("=")
	top.popups[title]=window.open('',title,targetpar)
	top.popups[title].document.write("<title>"+title+"</title>")
    top.popups[title]=window.open(action+(action.indexOf('about:blank')==-1?ctrlkeys(ev):''),title,targetpar,true);
	top.popups[title].focus();
}

function xxxopenwindow(url){
	if (window.wtemplate===undefined) {
		wtemplate=document.createElement('div')
		nachladen('ds_wtemplate&target=dyn_',wtemplate,function(){openwindow(url)})
		return
	}
	if (!wtemplate.innerHTML)wtemplate.innerHTML=xmlhttp.responseText
	w=wtemplate
	w.style.cssText="border:1;position:relative;width:800;top:0;left:0"
	w.id='editor'
	document.body.appendChild(w)
	//nachladen(url,'benutzerflaeche')
	ADD_DHTML('editor'+RESIZE)
}

function sendToFrame(me){
	//top.frames.dialog.document.body.innerHTML=me.document.body.innerHTML
	
	//log(me + ':'+typeof($))
	if(typeof($)=='undefined') return false
	var target
	if (me=='')return
	var div=$(me)
	//alert(div.attributes)
	if (!div) return
	var targetdoc=top.frames[div.attributes.targetframe.value]//14.04.09 target zu targetframe gewechselt, target in IE vorbelegt
	frameset=top.document.getElementById(target=div.attributes.targetframe.value)
	if (frameset && targetdoc) {frameset=frameset.parentNode} 
	else {//kein dialog-frame gefunden
		if (form=document.forms[me]) {form.target="_self"}
		document.body.children[0].insert({before:div}) //verschiebt das div an erste stelle im body
		div.show()
		return
		div.show()
		if(div.innerHTML=='.'){div.innerHTML=''}//08.04.09 das lästige . mal entfernen,
		return(false)
	}
	targetdoc=targetdoc.document
	if(targetdoc.body){
		var text=div.innerHTML
		if(typeof(targetdoc.body.update)=='function'){targetdoc.body.update(text)} else {return}
		var height=text==''?0:div.getDimensions().height+15
		if(height>0)div.remove()
	}
	else {return}
	var framecnt=0
	for(var i=0;i<frameset.childNodes.length;i++){
		if (frameset.childNodes[i].id) {
			if (frameset.childNodes[i].id==target){
				rowarr=frameset.rows.split(",");
				rowarr[framecnt]=height
				frameset.rows=rowarr.join(",");
				break
			}
			framecnt++;
		}
	}
}

function xsendToFrame(me){
	//top.frames.dialog.document.body.innerHTML=me.document.body.innerHTML
	//debugger
	var target
	if (me=='')return
	div=$(me)
	//alert(div.attributes)
	if (!div) return
	var targetdoc=top.frames[div.attributes.targetframe.value]//14.04.09 target zu targetframe gewechselt, target in IE vorbelegt
	frameset=top.document.getElementById(target=div.attributes.targetframe.value)
	if (frameset && targetdoc) {frameset=frameset.parentNode} else {
		//return(false) //stillgelegt
		if (form=document.forms[me]) {form.target="_self"}
		div.style.position='relative'
		div.style.display="block"
		//ADD_DHTML(me+RESIZABLE);
		if(div.innerHTML=='.'){div.innerHTML=''}//08.04.09 das lästige . mal entfernen,
		return(false)
	}
	targetdoc=targetdoc.document
	neu=targetdoc.createElement("DIV")
	neu.id=div.id
	if(div.innerHTML=='.'){div.innerHTML=''}//ein div ohne sichtbare zeichen wird mit getelement nicht gesehen. daher steht ein . fuer ein leeres div
	neu.ondblclick=div.ondblclick
	neu.innerHTML=div.innerHTML
	//neu = new (div)
	//neu=div
	if(!(navigator.appName=="Microsoft Internet Explorer")){neu=div}
	else{
		//debugger;//ff mozt nicht
	}
	//neu.attributes=div.attributes

	myframes=new Array()
	if (old=targetdoc.getElementsByTagName('div')[div.id]){
		targetdoc.body.replaceChild(neu,old)
	}
	else {
		if(targetdoc.body)targetdoc.body.appendChild(neu)
	}
	neu.style.display="block"
	var framecnt=0
	for(var i=0;i<frameset.childNodes.length;i++){
		if (frameset.childNodes[i].id) {
			if (frameset.childNodes[i].id==target){
				rowarr=frameset.rows.split(",");
				rowarr[framecnt]=neu.offsetHeight;
				frameset.rows=rowarr.join(",");
				break
			}
			framecnt++;
		}
	}
}

var resultnachladen=false;
var xmlhttp=false;

String.prototype.strReplace= function(s,r){
	return(this.split(s).join(r))
}

String.prototype.repeat = function (l){
	return new Array(l+1).join(this);
}
function submitform(action,target){
	//debugger
	document.forms[0].method='post'
	document.forms[0].action.value=action
	if(target) document.forms[0].target=target
	document.forms[0].submit()
	//alert(document.forms[0].action)
}

var formelzeichen=/[-0-9*+/(.)]/


function formatstring(event,mask){
	return Formatstring(event,mask)
}

function Formatstring(event,mask){
	
	if(!mask) mask=event.target.attributes.mask.value
	event = (event) ? event : ((event) ? event : null);
	c=document.all?event.keyCode:event.charCode
	ziel= event.srcElement ? event.srcElement : event.target
	//masktrings: A = alles gross, Aa = Grossklein, 9* = alles Zahlen+Formel, 1=+-[0..9]., 999 999 99 99 99 mit dd.mm.jj  datum 2stellig etc.
	if (!c) return
	if (navigator.appName=="Microsoft Internet Explorer") {	document.selection.createRange().empty}

	mask= (mask.substr(mask.length-1)=='*') ? mask=mask.substr(0,z=mask.length-2)+mask.substr(z,1).repeat(80):mask //20 = eigentlich Feldlaenge, todo!
	var append=ziel.selectionStart==ziel.value.length
	var selectionStart=ziel.selectionStart+1?ziel.selectionStart:ziel.value.length
	var selectionEnd=ziel.selectionEnd?ziel.selectionEnd:ziel.value.length
	var buf = ziel.value.substr(0,selectionStart)+ziel.value.substr(selectionEnd)
	selectionEnd=selectionStart
	{
		buf=buf.substr(0,selectionStart)+String.fromCharCode(c)+buf.substr(selectionStart)
		var value=''

		for (var i=0; i<buf.length;i++){
			var chr = buf.substr(i,1)
			var msk=mask.substr(i,1)
			switch (msk){
				case "A" : value += chr.toUpperCase();break;
				case "a" : value += chr.toLowerCase();break;
				case "9" : if(chr.toUpperCase()=='C') var evalverlangt=true; else value += chr.match(formelzeichen)?chr:'';break;
				case "1" : value += (!isNaN(chr))?chr:'';break;
				case "d" : value += (!isNaN(chr))?chr:'';break;
				case "m" : value += (!isNaN(chr))?chr:'';break;
				case "y" :
				case "j" : value += (!isNaN(chr))?chr:'';break;
				case chr : value += chr; break;
				//etc.
				default:  value+=(i<mask.length)?msk+chr:msk;selectionStart+=append?1:0
			}
		}
		if(evalverlangt && value!='') value=eval(value)
		
		ziel.value=value
		if(parseInt(ziel.attributes.size.value)+2<ziel.value.length)ziel.attributes.size.value=parseInt(ziel.attributes.size.value)+3
	}
	stopEvent(event)
	ziel.selectionStart=selectionStart+1
	ziel.selectionEnd=ziel.selectionStart
	return(false)
}

function stopEvent(e) {
	if(!e) var e = window.event;

	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}


function getElementsById(sId) {//verwendet von schnellliste, doppelte inputs entfernen; umbau auf $$(...) geplant
	var outArray = new Array();
	if(typeof(sId)!='string' || !sId) {
		return outArray;
	};
	if(document.evaluate) {
		var xpathString = "//*[@id='" + sId.toString() + "']"
		var xpathResult = document.evaluate(xpathString, document, null, 0, null);
		while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
		outArray.pop();
	}
	else if((navigator.appName=="Microsoft Internet Explorer")) {
		for(var i=0,j=(navigator.appName=="Microsoft Internet Explorer")[sId].length;i<j;i+=1){
			outArray[i] =  (navigator.appName=="Microsoft Internet Explorer")[sId][i];}

	}
	else if(document.getElementsByTagName) {
		var aEl = document.getElementsByTagName( '*' );
		for(var i=0,j=aEl.length;i<j;i+=1){
			if(aEl[i].id == sId )   {
				outArray.push(aEl[i]);
			};
		};
	};
	return outArray;
}

function radioclear(event) {
	if (!event) event=window.event.srcElement.name
	event.target.checked = false;
}




function linkclick(event){
	Event.stop(event)
	//nachladen(event.target.href,$('main'))
}


function nachladen(link,wo,antwortfunction){
	//debugger
	if (link.indexOf(window.location.pathname)==-1 &&link.indexOf('http://')==-1) link='deepbase.php?action='+link
	var	resfunc= function() {
		if (xmlhttp.readyState==4) {
			resultnachladen=unescape(xmlhttp.responseText)
			//ziel (wo) erstellen oder replacen
			if($(wo)){
				$(wo).update(resultnachladen);
			}
			$$('a').invoke('observe','click',linkclick)
			if(antwortfunction) antwortfunction()
			return
		}
	}
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest()
	}
	if (xmlhttp.readyState!=1 ){
		xmlhttp.open("POST", link,true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//  xmlhttp.open("GET", link,true);
		xmlhttp.onreadystatechange=resfunc;
		xmlhttp.send(null)
	}
}
function resolve(s){
	//die woerter nach $ aufloesen
	var sarr=s.split('$')
	for (var i=1; i<sarr.length;i++){
		var sa=sarr[i]
		var r=sa.split('(').join('').split(')')
		sarr[i]=($f=$(r[0]))?$f.innerHTML+r[1]:''+r[0]+':existiert_nicht_auf_erfassungsmaske'
	}
	return(sarr.join(''))
}


function nachladen_post(link,wohin,antwortfunction,event){//
	if (link.indexOf(window.location.pathname)==-1 && link.indexOf('http://')==-1) link='deepbase.php?action='+link
	if (link.indexOf('$'))link=resolve(link)
	if(!antwortfunction) antwortfunction= function(x) {
		sendToTarget(x)
		var antwort=unescape(x.responseText)
		//ziel (wohin) erstellen oder replacen
		//scripts extrahieren und ausfuehren
		antwort=antwort.split('<deepscript>')//kann js enthalten nach dem tag
		if(!$(wohin)){
			var ziel=document.body.appendChild(document.createElement('div')) //untendran ein div kreieren fuer antwort
			ziel.innerHTML=antwort[0]
		}
		else {
			$(wohin).update(antwort[0])
			if($(wohin).value){$(wohin).value=antwort[0];} //wenn das ziel ein value hat dorthin pfluemlen
			else if($(wohin)){$(wohin).innerHTML=antwort[0];}
		}
		for (var i=1;i<antwort.length;i++){
			antwort[i]=antwort[i].split('</deepscript>')
			eval(antwort[i][0]) //fuehrt z.b das aus-->$$('a').invoke('observe','click',linkclick)
		}
		return(x.responseText)
	}
	if(wohin==false || wohin=='neu'){
		//var ziel=window.open(link+'&modus=nachladen',wohin,",resizable=1,scrollbars=1,menubar=1,width=700,height=500,left=50,top=50")
		var ziel=window.open(link+'&modus=xnachladen',wohin,",resizable=1,scrollbars=1,menubar=1,width=700,height=500,left=50,top=50")//kein modus nachladen wenn in popup
		ziel.focus()
	}
	else {ajax(link+'&modus=nachladen',"POST",antwortfunction )} //modus nachladen, damit der server nicht eine komplette page zurueckgibt
	return(true)
}

function drilldown(e){
	if (!e) e = window.event;
	var f=e.target.attributes.ddfunction.value
	var pid=Event.findElement(e,'tr').attributes.pid.value
	ajax('deepbase.php?action='+pid+'&ddfunction='+f,'POST')
}

function onobserve(e){
	//generelle funktion
	window.status=e.target.className
}
if(typeof(top.fields)=='undefined') top.fields={}

function savesubito(e){
	
	var fieldcopy=top.fields[e.name?e.name:(e.id?e.id:(e.target.id?e.target.id:'undefined'))]
	if (!e) e = window.event;
	if(!e.target)e.target=e //aufruf nicht mit event sondern mit input
	$$('input[name='+e.target.name+'],select[name='+e.target.name+'] option').each(function setvalue(item){
		if(typeof(item.checked)!='undefined') item.writeAttribute({checked:item.checked})
		if(typeof(item.selected)!='undefined') item.writeAttribute({selected:item.selected})
		if(typeof(item.value) !='undefined') item.writeAttribute({value:item.value})
	}
	)

	var target=(e.target.up('subform') || e.target)
	
	//je nach input type value aufbereiten, bis jetzt checkbox und restliche, muss ev. noch radiobutton, select etc. angepasst werden, span=ein subform wird gespeichert (ganzer innerHTML code)
	//window.status='savesubito'
	var value =target.tagName=='SUBFORM'?target.innerHTML:target.type=='checkbox'?target.checked:target.value.split('&').join('<ampersand>')
	//ajax('deepbase.php?action='+target.id+'&value='+value,'POST')
	if(fieldcopy && fieldcopy==value) return  //hat sich nichts geändert
	top.fields[e.target.id]=value 
	if(typeof(top.initphase)!='undefined')if(top.initphase){ return}
	new Ajax.Request('deepbase.php?action='+target.id+'&value='+escape(value)+'&savesubito=true',
	{method:'POST',
	onSuccess: function(transport){
		top.lastsavesubito=e.target.id
		sendToTarget(transport)
		updateaufrufer(e.target)
		var response = transport.responseText || "no response text"
		if(response.indexOf('-1')>0) {
			target.writeAttribute('title','savesubito war nicht erfolgreich: '+response)
			target.setStyle({backgroundColor:'tomato'})
		}
		else{
			target.setStyle({color:'brown'})
			
		}
	},
	onFailure: function(){ window.status='problem bei savesubito' }
	}
	);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
	else return[0,0]
}


function ergaenze(item){
	if (item.tagName.toUpperCase()=='BR') return
	if (item.currentStyle){var style = item.currentStyle;}
	else {var style=window.getComputedStyle(item,'')}
	var offset=findPos(item)
	/*	var eigenschaften='clientheight:'+item.clientHeight+
	'clientwidth:'+item.clientWidth+
	'offsetleft:'+offset[0]+
	'offsettop:'+offset[1]+
	'fontfamily:'+style.fontFamily+
	'fontweight:'+(item.tagName=='STRONG' ?'bold':'')+
	'fontstyle:'+style.fontStyle+(item.tagName=='EM' ?' italic':'')+
	'fontstyle:'+style.fontStyle+(item.tagName=='U' ?' underline':'')+
	'fontsize:'+style.fontSize+
	'fontcolor:'+style.fontColor+
	'textalign:'+style.textAlign+
	'border_trbl_csw:'+style.borderTopColor+':'+style.borderTopStyle+':'+style.borderTopWidth+';'+style.borderRightColor+':'+style.borderRightStyle+':'+style.borderRightWidth+';'+style.borderBottomColor+':'+style.borderBottomStyle+':'+style.borderBottomWidth+';'+style.borderLeftColor+':'+style.borderLeftStyle+':'+style.borderLeftWidth
	item.writeAttribute({eins:'eigenschaften'})*/
	item.writeAttribute({
		clientheight   : (parseInt(item.clientHeight)+(('TD TH '.indexOf(item.tagName.toUpperCase()+' ')>-1?0:0)))/4,
		clientwidth    : (parseInt(item.clientWidth)+(('TD TH '.indexOf(item.tagName.toUpperCase()+' ')>-1?0:0)))/4,
		offsetleft     : parseInt(offset[0])/4,
		offsettop      : parseInt(offset[1])/4,
		fontfamily     : style.fontFamily,
		fontweight	   : (item.tagName.toUpperCase()=='STRONG'?'bold':''),
		fontstyle	   : style.fontStyle,
		fontstyle	   : style.fontStyle,
		fontsize       : style.fontSize,
		fontcolor      : style.fontColor,
		textalign	   : style.textAlign,
		value		   : item.value,
		border_trbl_csw: style.borderTopColor+':'+style.borderTopStyle+':'+style.borderTopWidth+';'+style.borderRightColor+':'+style.borderRightStyle+':'+style.borderRightWidth+';'+style.borderBottomColor+':'+style.borderBottomStyle+':'+style.borderBottomWidth+';'+style.borderLeftColor+':'+style.borderLeftStyle+':'+style.borderLeftWidth
	})
}

function getOuterHTML(object) {
	var element;
	if (!object) return null;
	element = document.createElement("div");
	element.appendChild(object.cloneNode(true));
	return element.innerHTML;
}

function passiv(){
	if($('passiv')){
		$('passiv').show()
		$('aktiv').hide()
	}
}
function aktiv(){
	if($('passiv')){

		$('passiv').hide()
		$('aktiv').show()
	}
}
function sendBackHTML(div,action){//10.01.09
	setTimeout('aktiv()',10)
	$$('[name=druckgutform]').invoke('remove')
	if($$('.selected')[0]) {
		div='.selected'
		if(window.getSelection) {
			var theSelection = window.getSelection(); // firefox
			theSelection.removeAllRanges()
			$$('.selected').each(function(tag){
				theSelection.addRange(document.createRange(tag));
			})
		}
	}
	//$$(div,div+' *').each(function(item){//alle client- dimensionen anpassen ... wysiwig
	//	if(item.tagName=='TABLE') item.addClassName('print')//damit kurzfristig border collapse wirksam wird,
	//	ergaenze(item);
	//})
	var zuDrucken=''
	$$(div).each(function (item){
		zuDrucken+=	escape(getOuterHTML(item))
	})
	Element.insert(document.body,'<form name=druckgutform id=druckgutform method=post action="'+action+'"><input style=display:none name=druckgut id=druckgut value='+zuDrucken+'></form>')
	$$('.print').invoke('removeClassName','print')
	return
}

function getinputs(doc,mainform){//version vom 10.01.2010
	var i=0
	//if(!doc && !doc.$$) return
	if (!doc) {
		var fields=$$('input,select,textarea')
	}
	else  {
		if(typeof(doc.$$)!=='function') doc=top
		var fields=doc.$$('input,select,textarea')
	}
	fields.each(function (f){
		i++
		if(!mainform) {//ein virtuelles formular mit allen felder aller gefundenen forms wird erstellt
			mainform=document.createElement('form')
			mainform.id=mainform.name='virtform'
			mainform.target=f.form.target
			mainform.action=f.form.action
			document.body.appendChild(mainform)
			$(mainform).hide()}
			{
				var feld = f.cloneNode(true)
				feld.value=f.value  //leider nötig, cloneNode ist nicht zuverlässig
				if(f.selectedIndex!='undefined')feld.selectedIndex=f.selectedIndex
				mainform.appendChild(feld)
			}
			if(f.type=='checkbox') {
				mainform.appendChild(document.createElement('input'))
				mainform[mainform.length-1].type='text'
				mainform[mainform.length-1].value=f.checked?'true':'false';
				mainform[mainform.length-1].id=mainform[mainform.length-1].name=feld.name
				feld.remove()
			}//checkbox in textfelder verwandeln damit uncheckte auch gepostet werden

	})
	return(mainform)
}

function ctrlkeys(e){
	var returnstring=''
	if(e.ctrlKey){returnstring+="&ctrlkey=true"}
	if(e.altKey){returnstring+="&altkey=true"}
	if(e.shiftKey) {returnstring+="&shiftkey=true"}
	return returnstring
}

function getallforms(e,target,submit,action,result){//submit, das erste form wird abgeschickt mit allen gefundenen werten im get
	target=window.name=='dialog'?'main':(target!=='main'?target:'_self')
	//if(!target) target=self.name=='dialog'?'main':'_self'
	if($('virtform'))document.body.removeChild($('virtform'))
	if(!e)e=window.event
	if(e){
		if(e.ctrlKey){action+='&ctrlkey=true';target='popup'}
		if(e.altKey){action+='&altkey=true';target='popup'}
		if(e.shiftKey) {action+='&shiftkey=true';target='this'}
		Event.stop(e)
	}
	var mainform
	if(!(mainform=$('druckgutform')))
	{//wenn druckgutform vorhanden dann nicht alle felder zusammensuchen
		if((frms=top.$$('frame'))!=''){//eine hompage mit frms gefunden
			frms.each(function(doc){
				if(doc.contentWindow){
					mainform=getinputs(doc.contentWindow,mainform)
				}
			})
		}
		else{mainform=getinputs(document.defaultView)}
	}
	$$('.selected').each(function (id){

		mainform.appendChild(document.createElement('input'))
		mainform[mainform.length-1].type='text'
		mainform[mainform.length-1].id=mainform[mainform.length-1].name='trid[]'
		mainform[mainform.length-1].value=id.attributes.trid.value


	})

	if(submit=='submit'){
		action = document.location.pathname+'?action='+action
		//action = 'deepbase.php?action='+action
		if(!checkform())return
		if(!mainform){//09.04.09 wenn kein formular vorhanden ist
			document.body.appendChild(mainform=document.createElement('form'))
			mainform.appendChild(document.createElement('input'))
			mainform.action=action
			mainform.method='post'
			mainform.target=target?target:'_self'
			mainform.submit()
			//document.location.href=action//06.04.09 "normaler" link wie z.b. bei scripts bearbeiten
			return
		}
		else {
			if(mainform){
				var savetarget=mainform.target
				var saveaction=mainform.action
			}
			if(!target){
				if(top.frames.main && !opener) {target='main'} 
				else target='_self'
			}
			if (target=='')target='ajax'//target =='' d.h. ausdruck nur in file, antwort landet im "nirwana"
			if(target=='ajax'){
				var myAjax= new Ajax.Request(action.split('?').join('/?')+'&ajax=true',{
					method:'post',
					parameters:Form.serialize(mainform),
					onSuccess:(typeof(result)=='function')?result:function(transport){
						if($(result)) $(result).update(transport.responseText)
						setTimeout("passiv()",0)
					}
				})
				return
			}//ein saveform ohne neuladen des formulars */
			if(true || navigator.appName!="Microsoft Internet Explorer"){//nur in nicht ie popupen, weil ie access denied macht...
				if(target=='popup') {
					popupname=result?result.replace(/[ %&=]/gi,'_'):'popup'//ie mag keine blanks verleiden
					mainform.action+="&title=".popupname
					openwindow('about:blank',popupname,'menubar=yes,width=300,menubar=1,scrollbars=yes,height=400,left=100,top=200,resizable=yes',e);
					mainform.target=popupname
				}
				else if(target!='') mainform.target=target
			}
			if(action) 	mainform.action=action
			mainform.method="post"
			mainform.submit()
			mainform.action=saveaction
			mainform.target=savetarget

			return(false)
		}
	}
	else return(mainform.serialize())
}





function ajax(link,methode,antwort,parameter){
	var post=document.forms[0]?Form.serialize(document.forms[0]):''//08.04.09 post nur wenn form vorhanden ist
	for (var element in post){post[element]=escape(post[element])}
	var myAjax = new Ajax.Request(
	link,
	{
		parameters:post,
		onComplete: antwort }
		);
}

function checkTasten(e) {
	if (!e)
	e = window.event;
	var meldung = "e.keyCode= " + e.keyCode+" e.altKey="+e.altKey+" e.ctrlKey="+e.ctrlKey+" e.shiftKey="+e.shiftKey
	debug(meldung)

}


function tastendown(taste){
	return(false)
}

function mussvorkommenin(event,bedingung){
	if (!event) event=window.event
	var target = event.target ? event.target : event.srcElement

	var antwort=function(){
		if (xmlhttp.readyState==4){
			if (xmlhttp.responseText==target.value+'<br>' && target.value != ''){
				document.getElementById('msg_'+target.id).innerHTML='Willkommen'
				window.location=top.location.pathname+"?action=start_deepbase&login="; //beton, muss noch parametrisiert werden
			}
			else {
				document.getElementById('msg_'+target.id).innerHTML='passwort falsch'
			}
		}
	}
	var link='nachladen&modus=schlagnach&feldpfad='+bedingung+'&v='+target.value+'&okaction=speichern&feld='+target.id;
	nachladen(link+get_posts(document),target,antwort);
}

function bedingung(event,ausdruck,ok,nok){
	if (!event) event=window.event
	var target = event.target ? event.target : event.srcElement
	var action = target.attributes.action?target.attributes.action:target.action
	var antwort=function(){
		if (xmlhttp.readyState==4){
			if (xmlhttp.responseText.indexOf('true')!=-1){window.location=action.nodeValue;return true;}
			return (xmlhttp.responseText=='false'?false:true)
		}
	}
	var link='nachladen&modus=bedingung'
	nachladen(link,target,'bedingung='+ausdruck+'&'+get_posts(document)+'&ok='+ok+'&nok='+nok,antwort);
	return('Anfrage gestartet')
}

function dyn_submit(buttonid){
	button=document.getElementById(buttonid)
	nachladen(top.location.pathname+'?action='+buttonid+get_posts(button))
	//button.parentNode.removeChild(button);
	button.parentNode.parentNode.removeChild(button.parentNode);
}



function get_posts(obj) {
	var getstr = "&";
	if(!obj)obj=document
	var inputs=obj.getElementsByTagName('input')
	for (var input=0;input<inputs.length;input++){
		if (',text,password,hidden'.indexOf(inputs[input].type=="text"))
		getstr += inputs[input].name + "=" + escape(inputs[input].value) + "&";
		else if (inputs[input].type=="checkbox")
		getstr += inputs[input].name + "=" + escape(inputs[input].checked)+ "&" ? escape(inputs[input].value) :'=&';
		else if (inputs[input].type=="radio")
		getstr += inputs[input].checked ? inputs[input].name + '='+escape(inputs[input].value)+"&":'';
	}
	var inputs=obj.getElementsByTagName('SELECT')
	if (inputs.length>0) for (var input in inputs){
		var sel = inputs[input];
		if (sel.selectedIndex>-1){
			for (var o=0;o<sel.options.length;o++){
				//if (sel.options[o].selected)getstr += sel.name + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
				//pendent: wie gibt man per ajax ein input type select zurueck?
			}

		}
	}
	return(getstr)
	/*
	if (tagname) tagname=tagname.toUpperCase;
	if (tagname == "INPUT") {
	if (obj.childNodes[i].type == "text") {
	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
	}
	if (obj.childNodes[i].type == "checkbox") {
	if (obj.childNodes[i].checked) {
	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
	} else {
	getstr += obj.childNodes[i].name + "=&";
	}
	}
	if (obj.childNodes[i].type == "radio") {
	if (obj.childNodes[i].checked) {
	getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
	}
	}
	}
	if (obj.childNodes[i].tagName == "SELECT") {
	var sel = obj.childNodes[i];
	getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	}
	*/


	//makeRequest('get.php', getstr);
}


function getX(obj,relative) {
	var x=0; if(typeof(obj)=="object" && document.getElementById) { x=obj.offsetLeft; if(obj.offsetParent && !relative) { x+=getX(obj.offsetParent); } return x; } else  { return false; }
}
function getY(obj,relative) {
	var y=0; if(typeof(obj)=="object" && document.getElementById) { y=obj.offsetTop; if(obj.offsetParent && !relative) { y+=getY(obj.offsetParent); } return y; } else  { return false; }
}

/**
*
*  Scrollable HTML table
*  http://www.webtoolkit.info/
*
**/

function ScrollableTable (tableEl, tableHeight, tableWidth) { //angepasste version
	if(!tableEl) return(false)
	this.initIEengine = function () {

		this.containerEl.style.overflowY = 'auto';
		if (this.tableEl.parentElement.clientHeight - this.tableEl.offsetHeight < 0) {
			this.tableEl.style.width = this.newWidth - this.scrollWidth +'px';
		} else {
			this.containerEl.style.overflowY = 'hidden';
			this.tableEl.style.width = this.newWidth +'px';
		}

		if (this.thead) {
			var trs = this.thead.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("top",  "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
			}
		}

		if (this.tfoot) {
			var trs = this.tfoot.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("bottom",  "(this.parentElement.parentElement.offsetHeight - this.parentElement.parentElement.parentElement.clientHeight - this.parentElement.parentElement.parentElement.scrollTop) + 'px'");
			}
		}

		eval("window.attachEvent('onresize', function () { document.getElementById('" + this.tableEl.id + "').style.visibility = 'hidden'; document.getElementById('" + this.tableEl.id + "').style.visibility = 'visible'; } )");
	};


	this.initFFengine = function () {
		this.containerEl.style.overflow = 'hidden';
		this.tableEl.style.width = this.newWidth + 'px';

		var headHeight = (this.thead) ? this.thead.clientHeight : 0;
		var footHeight = (this.tfoot) ? this.tfoot.clientHeight : 0;
		var bodyHeight = this.tbody.clientHeight;
		var trs = this.tbody.getElementsByTagName('tr');
		if (bodyHeight >= (this.newHeight - (headHeight + footHeight))) {
			this.tbody.style.overflow = '-moz-scrollbars-vertical';
			for (x=0; x<trs.length; x++) {
				var tds = trs[x].getElementsByTagName('td');
				tds[tds.length-1].style.paddingRight += this.scrollWidth + 'px';
			}
		} else {
			this.tbody.style.overflow = '-moz-scrollbars-none';
		}

		var cellSpacing = (this.tableEl.offsetHeight - (this.tbody.clientHeight + headHeight + footHeight)) / 4;
		this.tbody.style.height = (this.newHeight - (headHeight + cellSpacing * 2) - (footHeight + cellSpacing * 2)) + 'px';

	};
	/*this.tableEl = tableEl;
	this.scrollWidth = 16;

	this.originalHeight = this.tableEl.clientHeight;
	this.originalWidth = this.tableEl.clientWidth;

	this.newHeight = parseInt(tableHeight);
	this.newWidth = tableWidth ? parseInt(tableWidth) : this.originalWidth;

	this.tableEl.style.height = 'auto';
	this.tableEl.removeAttribute('height');

	this.containerEl = this.tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
	this.containerEl.appendChild(this.tableEl);
	this.containerEl.style.height = this.newHeight + 'px';
	this.containerEl.style.width = this.newWidth + 'px';
	*/

	this.tableEl = tableEl;
	this.scrollWidth = 16;

	if(self.frameElement && tableHeight)this.originalHeight = parseInt(self.frameElement.scrollHeight)-getY(tableEl)-80;//rh

	this.originalHeight=parseInt(this.tableEl.parentNode.clientHeight)<this.originalHeight?this.tableEl.clientHeight:this.originalHeight;// rh
	if (tableHeight)this.originalHeight = this.tableEl.clientHeight; //keine dynamik wenn aufrufparametr tableHeight
	this.originalWidth = this.tableEl.clientWidth;

	this.newHeight = parseInt(tableHeight)?parseInt(tableHeight):this.originalHeight
	this.newWidth = tableWidth ? parseInt(tableWidth) : this.originalWidth+this.scrollWidth;

	this.tableEl.style.height = 'auto';
	this.tableEl.removeAttribute('height');

	this.containerEl = this.tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
	this.containerEl.appendChild(this.tableEl);
	this.containerEl.style.height = this.newHeight + 'px';
	this.containerEl.style.width = this.newWidth + 'px';


	var thead = this.tableEl.getElementsByTagName('thead');
	this.thead = (thead[0]) ? thead[0] : null;

	var tfoot = this.tableEl.getElementsByTagName('tfoot');
	this.tfoot = (tfoot[0]) ? tfoot[0] : null;

	var tbody = this.tableEl.getElementsByTagName('tbody');
	var i=0
	while(tbody[i].parentNode.id!=tableEl.id)i++;
	this.tbody = (tbody[i]) ? tbody[i] : null;
	if (!this.tbody) return;

	if ((navigator.appName=="Microsoft Internet Explorer") && document.getElementById && !window.opera) this.initIEengine();
	if (!(navigator.appName=="Microsoft Internet Explorer") && document.getElementById && !window.opera) this.initFFengine();


}
/**
*
*  Scrollable HTML table
*  http://www.webtoolkit.info/
*
**/
//originalxxx
function xxScrollableTable (tableEl, tableHeight, tableWidth) {

	this.initIEengine = function () {

		this.containerEl.style.overflowY = 'auto';
		if (this.tableEl.parentElement.clientHeight - this.tableEl.offsetHeight < 0) {
			this.tableEl.style.width = this.newWidth - this.scrollWidth +'px';
		} else {
			this.containerEl.style.overflowY = 'hidden';
			this.tableEl.style.width = this.newWidth +'px';
		}

		if (this.thead) {
			var trs = this.thead.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("top",  "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
			}
		}

		if (this.tfoot) {
			var trs = this.tfoot.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("bottom",  "(this.parentElement.parentElement.offsetHeight - this.parentElement.parentElement.parentElement.clientHeight - this.parentElement.parentElement.parentElement.scrollTop) + 'px'");
			}
		}

		eval("window.attachEvent('onresize', function () { document.getElementById('" + this.tableEl.id + "').style.visibility = 'hidden'; document.getElementById('" + this.tableEl.id + "').style.visibility = 'visible'; } )");
	};


	this.initFFengine = function () {
		this.containerEl.style.overflow = 'hidden';
		this.tableEl.style.width = this.newWidth + 'px';

		var headHeight = (this.thead) ? this.thead.clientHeight : 0;
		var footHeight = (this.tfoot) ? this.tfoot.clientHeight : 0;
		var bodyHeight = this.tbody.clientHeight;
		var trs = this.tbody.getElementsByTagName('tr');
		if (bodyHeight >= (this.newHeight - (headHeight + footHeight))) {
			this.tbody.style.overflow = '-moz-scrollbars-vertical';
			for (x=0; x<trs.length; x++) {
				var tds = trs[x].getElementsByTagName('td');
				tds[tds.length-1].style.paddingRight += this.scrollWidth + 'px';
			}
		} else {
			this.tbody.style.overflow = '-moz-scrollbars-none';
		}

		var cellSpacing = (this.tableEl.offsetHeight - (this.tbody.clientHeight + headHeight + footHeight)) / 4;
		this.tbody.style.height = (this.newHeight - (headHeight + cellSpacing * 2) - (footHeight + cellSpacing * 2)) + 'px';

	};

	this.tableEl = tableEl;
	this.scrollWidth = 16;

	this.originalHeight = this.tableEl.clientHeight;
	this.originalWidth = this.tableEl.clientWidth;

	this.newHeight = parseInt(tableHeight);
	this.newWidth = tableWidth ? parseInt(tableWidth) : this.originalWidth;

	this.tableEl.style.height = 'auto';
	this.tableEl.removeAttribute('height');

	this.containerEl = this.tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
	this.containerEl.appendChild(this.tableEl);
	this.containerEl.style.height = this.newHeight + 'px';
	this.containerEl.style.width = this.newWidth + 'px';


	var thead = this.tableEl.getElementsByTagName('thead');
	this.thead = (thead[0]) ? thead[0] : null;

	var tfoot = this.tableEl.getElementsByTagName('tfoot');
	this.tfoot = (tfoot[0]) ? tfoot[0] : null;

	var tbody = this.tableEl.getElementsByTagName('tbody');
	var i=0
	while(tbody[i].parentNode.id!=tableEl.id)i++;
	this.tbody = (tbody[i]) ? tbody[i] : null;

	if (!this.tbody) return;

	if ((navigator.appName=="Microsoft Internet Explorer") && document.getElementById && !window.opera) this.initIEengine();
	if (!(navigator.appName=="Microsoft Internet Explorer") && document.getElementById && !window.opera) this.initFFengine();


}

<!--
/* http://www.alistapart.com/articles/zebratables/ */
function removeClassName (elem, className) {
	elem.className = elem.className.replace(className, "").trim();
}

function addCSSClass (elem, className) {
	removeClassName (elem, className);
	elem.className = (elem.className + " " + className).trim();
}

String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}

function stripedTable() {
	if (document.getElementById && document.getElementsByTagName) {
		var allTables = document.getElementsByTagName('table');
		if (!allTables) { return; }

		for (var i = 0; i < allTables.length; i++) {
			if (allTables[i].className.match(/[\w\s ]*scrollTable[\w\s ]*/)) {
				var trs = allTables[i].getElementsByTagName("tr");
				for (var j = 0; j < trs.length; j++) {
					removeClassName(trs[j], 'alternateRow');
					addCSSClass(trs[j], 'normalRow');
				}
				for (var k = 0; k < trs.length; k += 2) {
					removeClassName(trs[k], 'normalRow');
					addCSSClass(trs[k], 'alternateRow');
				}
			}
		}
	}
}

function createTable(row,col){
	var t=document.createElement('table')
	for(r=0;r<row;r++){
		var tr=t.insertRow(t.rows.length)
		for(c=0;c<col;c++){
			var td=tr.insertCell(tr.cells.length)
			td.id=c
			//td.appendChild(document.createTextNode(''))
		}
	}
	return(t)
}
function elasticDiv(){//das gleiche kann mit display:table-cell erreicht werden
	return(createTable(1,1).rows[0].cells[0])
}

//ist vielleicht mal nützlich
Object.extend(Date.prototype, {
	strftime: function(format) {
		var day = this.getUTCDay(), month = this.getUTCMonth();
		var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
		function pad(num) { return num.toPaddedString(2); };

		return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
			switch(part[1]) {
				case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
				case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
				case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
				case 'B': return $w("January February March April May June July August September October November December")[month]; break;
				case 'c': return this.toString(); break;
				case 'd': return this.getUTCDate(); break;
				case 'D': return pad(this.getUTCDate()); break;
				case 'H': return pad(hours); break;
				case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
				case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
				case 'm': return pad(month + 1); break;
				case 'M': return pad(minutes); break;
				case 'p': return hours > 11 ? 'PM' : 'AM'; break;
				case 'S': return pad(this.getUTCSeconds()); break;
				case 'w': return day; break;
				case 'y': return pad(this.getUTCFullYear() % 100); break;
				case 'Y': return this.getUTCFullYear().toString(); break;
			}
		}.bind(this));
	}
});

function clientPosition (element) {
	var p = {x: element.offsetLeft || 0, y:element.offsetTop || 0};
	while (element = element.offsetParent) {
		p.x += element.offsetLeft;
		p.y += element.offsetTop;
	}
	return p;
}

function blurhandler(event){
	if(!event) {
		event=window.event
		var quelle=event.srcElement
	}
	
}

if(typeof(keybuffer)=='undefined') var keybuffer={}

//keyhandler; mit cursortasten focus verschieben
//beispiel für anwendung $$('body').invoke('observe','keyup',keyhandler.bindAsEventListener())

function keyhandler (event){
	if(!event) {
		event=window.event
		var quelle=event.srcElement
	}
	else var quelle=event.target
	if(typeof(quelle.oldvalue)!='undefined') if(quelle.oldvalue!=quelle.value) window.status="raiseEvent('change',quelle)"
	key = event.which || event.keyCode;
	var ziel=''
	//var taste=keycodes[event.charCode.toString()+key.toString()];
	var taste=keycodes['0'+key.toString()];
	if(!taste) taste=(event.ctrlKey?'CTRL':'')+(event.altKey?'ALT':'')+(event.shiftKey?'SHIFT':'')+String.fromCharCode(key)
	var mainwindow=rootwindow()
	if(key>31){
		var x='etwas'
	}
	Object.values(mainwindow.popups).each(function (w) {//in allen frames und popups nach einer function suche für diese taste
		if(taste.match(/\w/) && eval('typeof(w.KEY_'+taste+')')=='function') {
			event.preventDefault();
			eval('w.KEY_'+taste+'(key)');
			return false}}
	)
	//window.status+=taste+' '
	//alert('key='+key+' char='+event.charCode)
	//if(typeof(taste)!='undefined' && eval('typeof(KEY_'+taste+')')=='function') {event.preventDefault();window.status=taste;eval('KEY_'+taste+'(key)');return false}
	var p=clientPosition(quelle)
	
	/*if (quelle.tagName.toUpperCase()=='HTML') {
		new Ajax.Request('?action=define&key='+key	)//tastenschläge ins nirwana werden zum server geschickt, (damit können versteckte logins realisiert werden)
		return;
	}*/
	if(quelle.tagName=='TR'){
		var keyhand
		if(quelle.attributes[taste] && (keyhand=quelle.attributes[taste].value)){
			if(eval('typeof('+keyhand+')')!='function'){//keine js-function definiert, d.h. dynamisch ein deepscript aufrufen
					new Ajax.Request("?action=ajax&ajh="+quelle.attributes.ajh.value+"&script=¢"+keyhand,{
						onComplete: function (response) {
							sendToTarget(response)
						}	
					});
			}
			else eval(keyhand+'(event)')//ein lokales jsscript aufrufen
		}
		if(key==Event.KEY_DOWN || key==Event.KEY_UP){
			var newindex=quelle.rowIndex+(key==Event.KEY_DOWN?1:-1)
			if(newindex>-1){
				ziel=$(quelle).up('table').rows[newindex]
				if(ziel){
					ziel.focus()
					ziel.addClassName('focused')
					quelle.removeClassName('focused')
				}
			}
			event.stop()
			return false
		}
	}
	if(typeof(quelle.value)=='undefined'){return}
	//$('statusbar').update(event.type+key+' '+p.x+' - '+p.y)
	if (typeof(quelle.selectionStart)!='undefined'){
		var selectionStart=quelle.selectionStart+1?quelle.selectionStart:quelle.value.length
		var selectionEnd=quelle.selectionEnd?quelle.selectionEnd:quelle.value.length
	}
	var filter=(navigator.appName=="Microsoft Internet Explorer")?'input,select,textarea':'input,select,textarea:not([type=hidden])'//ie kennt kein not()
	var table=$(quelle).up('table')
	var inputs=table?quelle.up('table').select(filter):$$(filter)//innerhalb der aktuellen tabelle suchen
	var self = clientPosition(quelle)
	var selfright=self.x+quelle.clientWidth
	var altNext=false
	if(key==13) key=9
	switch (key) {
		case Event.KEY_RIGHT:
		if(selectionEnd==quelle.value.length & selectionStart!=0){
			for(var i=0;i<inputs.length;i++){
				var cp=clientPosition(inputs[i])
				if((cp.y*100+cp.x)>(self.y*100+self.x)) {
					break;
				}
			}
		}
		break;
		case Event.KEY_TAB:
		{
			for(var i=0;i<inputs.length;i++){
				var cp=clientPosition(inputs[i])
				if((cp.y*100+cp.x)>(self.y*100+self.x)) {
					break;
				}
			}
		}
		break;
		case Event.KEY_LEFT:
		//if(selectionStart==0 || (selectionStart==quelle.value.length-1)){
		if(selectionStart==0){
			var tr
			if( (tr=quelle.up('tr'))){//pfeil nach links in tabelle soll tabelle nicht verlassend
				tr.id='this'
				var inputs=$$('#this input')
				tr.id=''
				if(quelle==inputs[0]) {i=inputs.length-1;break}
				
				for (var i in  inputs){
					if(inputs[i]==quelle) {i--;break;}
				}
				break;
			}
			for(var i=inputs.length-1;i;i--){
				var cp=clientPosition(inputs[i])
				if((cp.y==self.y) && (cp.x<self.x)) {
					break;
				}
			}
		}
		break;

		case Event.KEY_DOWN:
		{
			for(var i=0;i<inputs.length;i++){
				var cp=clientPosition(inputs[i])
				if((cp.y)>(self.y) && (Math.abs(cp.x+inputs[i].clientWidth-selfright))<10) {
					break;
				}
				else{
					if (!altNext && cp.x>self.x) altNext=i
				}
			}

		}
		
		break;
		case Event.KEY_UP:
		{
			for(var i=inputs.length-1;i>-1;i--){
				var cp=clientPosition(inputs[i])
				if((cp.y)<(self.y) && (Math.abs(cp.x+inputs[i].clientWidth-selfright))<10) {
					break;

				}
				else{
					if (!altNext && cp.x<self.x) altNext=i
				}

			}
		}
		
		break;
		default:return
	}
	if(!inputs[i]){i=altNext}//kein feld in aktueller richtung, altnext stattdessen altnext anspringen
	if(inputs[i]) {//ganzes feld selekt-  und fokussieren
		raiseEvent('click',inputs[i].up('tr'))
		inputs[i].focus()
		inputs[i].select()
		return false
		Event.stop()
	}
}

function getWindowWidth(win) {   //von der-albert.com
	if (win == undefined) win = window;
	if (win.innerWidth) {
		return win.innerWidth;
	}
	else {
		if (win.document.documentElement &&
		win.document.documentElement.clientWidth) {
			return win.document.documentElement.clientWidth;
		}
		return win.document.body.offsetWidth;
	}
}

function getWindowHeight(win) {
	if (win == undefined) win = window;
	if (win.innerHeight) {
		return win.innerHeight;
	}
	else {
		if (win.document.documentElement
		&& win.document.documentElement.clientHeight) {
			return win.document.documentElement.clientHeight;
		}
		return win.document.body.offsetHeight;
	}
}

//V3.01.A - http://www.openjs.com/scripts/jx/   diese library importiert weil Ajax.Request die POSTs nicht mehr richtig sendet
jx = {
	//Create a xmlHttpRequest object - this is the constructor.
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
			//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (window.XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},

	// This function is called from the user's script.
	//Arguments -
	//	url	- The url of the serverside script that is to be called. Append all the arguments to
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json,
	//			the string will be 'eval'ed before returning it. Default:'text'
	//	method - GET or POST. Default 'GET'
	load : function (url,callback,format,method, opt) {
		var http = this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!http||!url) return;
		//XML Format need this for some Mozilla Browsers
		if (http.overrideMimeType) http.overrideMimeType('text/xml');

		if(!method) method = "GET";//Default method is GET
		if(!format) format = "text";//Default return type is 'text'
		if(!opt) opt = {};
		format = format.toLowerCase();
		method = method.toUpperCase();

		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		var parameters = null;

		if(method=="POST") {
			var parts = url.split("\?");
			url = parts[0];
			parameters = parts[1];
		}
		http.open(method, url, true);

		if(method=="POST") {
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", parameters.length);
			http.setRequestHeader("Connection", "close");
		}

		var ths = this;// Closure
		if(opt.handler) { //If a custom handler is defined, use it
			http.onreadystatechange = function() { opt.handler(http); };
		} else {
			http.onreadystatechange = function () {//Call a function when the state changes.
				if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
					if(http.status == 200) {
						var result = "";
						if(http.responseText) result = http.responseText;
						//If the return is in JSON format, eval the result before returning it.
						if(format.charAt(0) == "j") {
							//\n's in JSON string, when evaluated will create errors in IE
							result = result.replace(/[\n\r]/g,"");
							result = eval('('+result+')');

						} else if(format.charAt(0) == "x") { //XML Return
							result = http.responseXML;
						}

						//Give the data to the callback function.
						if(callback) callback(result);
					} else {
						if(opt.loadingIndicator) document.getElementsByTagName("body")[0].removeChild(opt.loadingIndicator); //Remove the loading indicator
						if(opt.loading) document.getElementById(opt.loading).style.display="none"; //Hide the given loading indicator.

						if(error) error(http.status);
					}
				}
			}
		}
		http.send(parameters);
	},
	bind : function(user_options) {
		var opt = {
		'url':'', 			//URL to be loaded
		'onSuccess':false,	//Function that should be called at success
		'onError':false,	//Function that should be called at error
		'format':"text",	//Return type - could be 'xml','json' or 'text'
		'method':"GET",		//GET or POST
		'update':"",		//The id of the element where the resulting data should be shown.
		'loading':"",		//The id of the loading indicator. This will be set to display:block when the url is loading and to display:none when the data has finished loading.
		'loadingIndicator':"" //HTML that would be inserted into the document once the url starts loading and removed when the data has finished loading. This will be inserted into a div with class name 'loading-indicator' and will be placed at 'top:0px;left:0px;'
		}
		for(var key in opt) {
			if(user_options[key]) {//If the user given options contain any valid option, ...
				opt[key] = user_options[key];// ..that option will be put in the opt array.
			}
		}

		if(!opt.url) return; //Return if a url is not provided

		var div = false;
		if(opt.loadingIndicator) { //Show a loading indicator from the given HTML
			div = document.createElement("div");
			div.setAttribute("style","position:absolute;top:0px;left:0px;");
			div.setAttribute("class","loading-indicator");
			div.innerHTML = opt.loadingIndicator;
			document.getElementsByTagName("body")[0].appendChild(div);
			this.opt.loadingIndicator=div;
		}
		if(opt.loading) document.getElementById(opt.loading).style.display="block"; //Show the given loading indicator.

		this.load(opt.url,function(data){
			if(opt.onSuccess) opt.onSuccess(data);
			if(opt.update) document.getElementById(opt.update).innerHTML = data;

			if(div) document.getElementsByTagName("body")[0].removeChild(div); //Remove the loading indicator
			if(opt.loading) document.getElementById(opt.loading).style.display="none"; //Hide the given loading indicator.
		},opt.format,opt.method, opt);
	},
	init : function() {return this.getHTTPObject();}
}

function rootwindow(){
	var mainwindow=window;
	var i
	while(mainwindow.opener && (i<3)){
		mainwindow=mainwindow.opener
		i++
	}
	return mainwindow.top

}
//drag and drop
function drop(e){
	
	var mainwindow=rootwindow();
	if(mainwindow.top.dragSrc.target.tagName=='SELECT'){//select ist speziell..
		var action=mainwindow.top.dragSrc.target.attributes.dropaction.value+'('+mainwindow.top.dragSrc.explicitOriginalTarget.attributes.value.value+')'
	}
	else var action = action=mainwindow.top.dragSrc.target.attributes.dropaction.value+'('+mainwindow.top.dragSrc.explicitOriginalTarget.textContent+')'
	var droptargetid='&droptargetid='+(e.target.attributes.droptargetid?e.target.attributes.droptargetid.value:e.target.up('[droptargetid]').attributes.droptargetid.value)
	menuclick(action+droptargetid,e.currentTarget,'')
	var data = e.dataTransfer.getData("text/plain");
	//e.dataTransfer.dropEffect="copy"
	//e.target.textContent=e.dataTransfer.getData("text/plain")
	e.preventDefault()
	e.target.textContent = data;
	return false
}
function dragenter(e){
	e.preventDefault()
	window.status=e
}
function dragover(e){
	e.preventDefault()
}


function selectcanvas(event) //ein canvas für selectoptionen dragbegleitbild
{  var canvas = document.createElement("canvas");
canvas.width = 200 ;canvas.height = 50
var ctx = canvas.getContext("2d");
ctx.textAlign='center'
ctx.strokeText(event.explicitOriginalTarget.value,25,25,200)
var dt = event.dataTransfer;
return(canvas)
}

if(typeof(dragcache)=='undefined') var dragcache = {};//global to store eventhandler, used to correctly stopObserving later in dragend
var hidetimer =setTimeout(';',0)
function showdraggables(e,todo){
	if(!todo){
		todo='addClassName'
		clearTimeout(hidetimer)
	}
	else todo='removeClassName'
	
	var target=(e.hasClassName?e.currentTarget:e.originalTarget)
	if(typeof(target)=="undefined") return false
	target=target.hasClassName('droptarget')?target:target.up('.droptarget')
	if(!target) return false
	var mainwindow=rootwindow();
	
	for ( var w in mainwindow.top.popups )if (typeof(mainwindow.top.popups[w].$$)=='function'){
		mainwindow.top.popups[w].$$('[droptarget=.'+target.classList[0]+']').invoke(todo,'dropable')
	}
}
function registerFrameset(){
	
	if(!window.top.popups.main) window.top.$$('frame').each(function (win){window.top.popups[win.id]=win.contentWindow})//alle frames im popuparray registrieren, wird von frameset aufgerufen onload
}
function hidedraggables(e){
	hideevent=e  
	hidetimer=setTimeout('showdraggables(hideevent,"hide")',1000)	
	e.stop()
	return false
}

function dragstart(e){
	if(!e.target.attributes) return false
	
	var typ=e.target.attributes.droptarget.value
	var mainwindow=window=rootwindow();
	if(!mainwindow.top.popups.main) mainwindow.top.$$('frame').each(function (win){mainwindow.top.popups[win.id]=win.contentWindow})//alle frames im popuparray registrieren
	for ( var w in mainwindow.top.popups )if (typeof(mainwindow.top.popups[w].$$)=='function'){
		mainwindow.top.popups[w].$$(typ).invoke('toggleClassName','dropable')
		mainwindow.top.popups[w].$$(typ).invoke('observe','dragover',dragcache[dragover]=dragover.bindAsEventListener())
		mainwindow.top.popups[w].$$(typ).invoke('observe','dragenter',dragcache[dragenter]=dragenter.bindAsEventListener())
		mainwindow.top.popups[w].$$(typ).invoke('observe','drop',dragcache[drop]=drop.bindAsEventListener())
	}
	mainwindow.top.dragSrc=e
	if(e.target.tagName=='SELECT'){
		e.dataTransfer.setData('text/plain', e.explicitOriginalTarget.innerHTML)
		e.dataTransfer.setDragImage(selectcanvas(e), 0, 0)
		e.explicitOriginalTarget.style.outline='1px dotted gray'
		e.explicitOriginalTarget.selected=false
		e.target.multiple=false
		e.target.multiple=true
	}
	else e.dataTransfer.setData('text/plain', e.currentTarget.innerHTML)

	return true
}

function dragend(e){
	if(!e.target.attributes) return false
	var typ=e.target.attributes.droptarget.value
	var mainwindow=window=rootwindow();
	for ( var w in mainwindow.top.popups ){
		mainwindow.top.popups[w].$$(typ).invoke('toggleClassName','dropable')
		mainwindow.top.popups[w].$$(typ).invoke('stopObserving','dragover',dragcache[dragover])
		mainwindow.top.popups[w].$$(typ).invoke('stopObserving','dragenter',dragcache[dragenter])
		mainwindow.top.popups[w].$$(typ).invoke('stopObserving','drop',dragcache[dragcache])
	}
	mainwindow.top.dragSrc=''
}

//auf dem client herumhacken
function writefile(fn,data,start)//erstellt file, startet es bei start=true
{//https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO
	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath(fn?fn:"c:\\deebpasestart.bat");
	// file is nsIFile, data is a string
	var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
	createInstance(Components.interfaces.nsIFileOutputStream);
	// use 0x02 | 0x10 to open file for appending.
	foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
	// write, create, truncate
	// In a c file operation, we have no need to set file mode with or operation,
	// directly using "r" or "w" usually.
	// if you are sure there will never ever be any non-ascii text in data you can
	// also call foStream.writeData directly
	var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
	createInstance(Components.interfaces.nsIConverterOutputStream);
	converter.init(foStream, "UTF-8", 0, 0);
	converter.writeString(data);
	converter.close(); // this closes foStream
	if (start){
		var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
		process.init(file);
		process.run(false, ['bla', "bla"], 2);//false=nowait, true=wait
	}
}
function selectionToggle(e){
		if(e.altKey){
			var target=e.sourceElement?e.sourceElement:e.currentTarget
			target.toggleClassName("selected")
			Event.stop(e)
		}
		return(true)		
		}
		
function $$toJSON(obj){
	var json=''
	obj.each(function (element){
		json+=(json!=''?',':"")+"[{'"+element.name+"':'"+element.value+"'}]"})
	return(json)
}
		/**
 * Javascript code to store data as JSON strings in cookies. 
 * It uses prototype.js 1.5.1 (http://www.prototypejs.org)
 * 
 * Author : Lalit Patel
 * Website: http://www.lalit.org/lab/jsoncookies
 * License: Apache Software License 2
 *          http://www.apache.org/licenses/LICENSE-2.0
 * Version: 0.5
 * Updated: Jan 26, 2009 
 * 
 * Chnage Log:
 *   v 0.5
 *   -  Changed License from CC to Apache 2
 *   v 0.4
 *   -  Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason)
 *   -  Removed the parameter name from the initialize function
 *   -  Changed the way expires date was being calculated. (Thanks David)
 *   v 0.3
 *   -  Removed dependancy on json.js (http://www.json.org/json.js)
 *   -  empty() function only deletes the cookies set by CookieJar
 */

var CookieJar = Class.create();

CookieJar.prototype = {

	/**
	 * Append before all cookie names to differntiate them.
	 */
	appendString: "__CJ_",

	/**
	 * Initializes the cookie jar with the options.
	 */
	initialize: function(options) {
		this.options = {
			expires: 3600,		// seconds (1 hr)
			path: '',			// cookie path
			domain: '',			// cookie domain
			secure: ''			// secure ?
		};
		Object.extend(this.options, options || {});

		if (this.options.expires != '') {
			var date = new Date();
			date = new Date(date.getTime() + (this.options.expires * 1000));
			this.options.expires = '; expires=' + date.toGMTString();
		}
		if (this.options.path != '') {
			this.options.path = '; path=' + escape(this.options.path);
		}
		if (this.options.domain != '') {
			this.options.domain = '; domain=' + escape(this.options.domain);
		}
		if (this.options.secure == 'secure') {
			this.options.secure = '; secure';
		} else {
			this.options.secure = '';
		}
	},

	/**
	 * Adds a name values pair.
	 */
	put: function(name, value) {
		name = this.appendString + name;
		cookie = this.options;
		var type = typeof value;
		switch(type) {
		  case 'undefined':
		  case 'function' :
		  case 'unknown'  : return false;
		  case 'boolean'  : 
		  case 'string'   : 
		  case 'number'   : value = String(value.toString());
		}
		var cookie_str = name + "=" + escape(Object.toJSON(value));
		try {
			document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure;
		} catch (e) {
			return false;
		}
		return true;
	},

	/**
	 * Removes a particular cookie (name value pair) form the Cookie Jar.
	 */
	remove: function(name) {
		name = this.appendString + name;
		cookie = this.options;
		try {
			var date = new Date();
			date.setTime(date.getTime() - (3600 * 1000));
			var expires = '; expires=' + date.toGMTString();
			document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure;
		} catch (e) {
			return false;
		}
		return true;
	},

	/**
	 * Return a particular cookie by name;
	 */
	get: function(name) {
		name = this.appendString + name;
		var cookies = document.cookie.match(name + '=(.*?)(;|$)');
		if (cookies) {
			return (unescape(cookies[1])).evalJSON();
		} else {
			return null;
		}
	},

	/**
	 * Empties the Cookie Jar. Deletes all the cookies.
	 */
	empty: function() {
		keys = this.getKeys();
		size = keys.size();
		for(i=0; i<size; i++) {
			this.remove(keys[i]);
		}
	},

	/**
	 * Returns all cookies as a single object
	 */
	getPack: function() {
		pack = {};
		keys = this.getKeys();

		size = keys.size();
		for(i=0; i<size; i++) {
			pack[keys[i]] = this.get(keys[i]);
		}
		return pack;
	},

	/**
	 * Returns all keys.
	 */
	getKeys: function() {
		keys = $A();
		keyRe= /[^=; ]+(?=\=)/g;
		str  = document.cookie;
		CJRe = new RegExp("^" + this.appendString);
		while((match = keyRe.exec(str)) != undefined) {
			if (CJRe.test(match[0].strip())) {
				keys.push(match[0].strip().gsub("^" + this.appendString,""));
			}
		}
		return keys;
	}
};
//von w3schools abgekupfert
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function popup(target,title,url,ev,tp){//target=popup|id eines divs|framename, title=fenstername,url,tp=string mit targetparametern
	
e=suchajh(ev);
if(e.tagName=="OPTION"){
	e.selected=false
	e.addClassName("selected")
}
var targetpar=e.attributes.targetpar?e.attributes.targetpar.value.split(":").join("="):tp.split(":").join("=")
top.popups[title]=window.open("",title,targetpar)
top.popups[title].document.write("<title>"+title+"</title>")
top.popups[title]=window.open(url,title,targetpar,true);
top.popups[title].focus();

}
function kool_call(sender,args,action){
	var _row = args["Row"];
	var _event = args["Event"];	
	var get ='action=<cent>'+action+'&'
		for (var i in args.Row.getDataItem()){
			if(typeof(args.Row.getDataItem()[i])=='string') get+=i+'='+escape(args.Row.getDataItem()[i])+'&'
		}
		window.open('?'+get,'');
}

//der-albert.com
function raiseEvent (eventType, elementID)
{	
	var o = typeof(elementID)=='string'?document.getElementById(elementID):elementID; 
    if (document.createEvent) { 
        var evt = document.createEvent("Events"); 
        evt.initEvent(eventType, true, true); 
        o.dispatchEvent(evt); 
    } 
    else if (document.createEventObject) 
    {
        var evt = document.createEventObject(); 
        o.fireEvent('on' + eventType, evt); 
    } 
    o = null;
} 
 
if(typeof(top.observecalc)=='undefined')  top.observecalc = {};//platz um sich observierungen zu merken



function calc(css,target,operation){//alle elemente werden mit operation(+,-,*) verbunden und berechnet... obsolet
	operation=!operation?'+':operation
	var result=operation=='+'?0:1
	var elements=$$(css).each(function (element){
		var zahl=element.value?element.value:element.down('input')?element.down('input').value:element.textContent
		if(parseFloat(1*zahl)+''=='NaN') zahl=eval(zahl) ;else zahl=parseFloat(1*zahl)
		if(typeof(zahl)=='undefined'||zahl+''=='NaN') zahl=0
		
		eval('result'+operation+'=zahl')
		
	})
	var t=$$(target)[0]
	if(!t) {window.status="function calc findet kein Ziel unter "+target;}
	else {
		if(t.tagName=="INPUT"){
			t.value=round(result,2)
			if(!top.nosave) raiseEvent("change",t)
		}
		else t.update(round(result,2))
	}
	
	if( !top.nosave || !(top.observecalc[target+css])) {//die berechnung soll immer ausgeführt werden, wenn sich ein quellfeld geändert hat, top.nosave gesetzt von tablecalc beim laden
		$$(css).invoke('stopObserving')
		$$(css).invoke('observe','change',function (){calc(css,target,operation)})
		top.observecalc[target+css]=true
	}
	return(result+''=='NaN'?0:result)
}

function sendToTarget(response){//wird von den meisten ajaxhandler responsefuncs aufgerufen, führt js aus (z.b. fehlermeldungen in sep. fenster)
	var div=document.createElement('div').update(response.responseText)
	//raiseEvent("load",window)
}
function gv(selector){//getvalue
	var variables=$$(selector)
	var value=0
	if(variables.length>0){
		variables.each(function(item){
		value+=typeof(item.value)!='undefined'?parseFloat(isNaN(item.value)?0:item.value):parseFloat(isNaN(item.innerHTML)?0:item.innerHTML)
	})
	}
	else {
		if(!top.vars[selector]) top.vars[selector]=0;
		value=top.vars[selector]
	}
	return value
}
if(typeof(top.vars)=='undefined')  top.vars = {};//platz für globale variablen

function $C(formula,destination,event){//formel berechnen: zwtrab1=wb/100*(100-rab1proz), alle variablen sind input.values oder textnodes innerhalb class=varname
	//1. array mit varnamen bilden.
	if(formula.indexOf('gv(')==-1){
		var suchvars = /({.*}|[. ,\w]*(?!\w*(?=[(]))[a-z])/g;
		var myArray;
		var found={}
		while ((myArray = suchvars.exec(formula)) != null)  {found[myArray[0]]=suchvars.lastIndex}
		var result=0
		//2. observieren aller quell-variablen auf change
		for (var css in found)  {
			formula=formula.replace(css,'gv("'+(css=css.replace(/{|}/g,''))+'")') //alle css-selectoren mit gv-aufruf ergänzen (ohne {})
			$$(css).invoke('observe','re:calc',function (event){
				$C(formula,destination,event)
			})
			$$(css).invoke('observe','focus:out',function (event){
				$C(formula,destination,event)
			})
		}
	}
	eval('result='+formula)
	result=round(parseFloat(result),2)
	var dest=$$(destination)
	if (dest.length>0){
		dest.each(function (item){
			item.value=result;
			})
	}
	else {
		top.vars[destination]=result
	}
	if(dest.length>0) {
		dest[0].fire("focus:out") //allfällige change-handler aufrufen (z.b savesubito)
		dest[0].fire("re:calc") //von diesem resultat abhängige formeln nachrechnen
	}
	return true
}

function log(meldung){
		if(!top.w || top.w.closed){
		targetpar='height=900,left=-800,top=50,width=800,toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1'
		top.w=window.open("","log",targetpar)
	}
	top.w.document.write(meldung+'<br>')	

}
function ord (string) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: ord('K');
    // *     returns 1: 75
    // *     example 2: ord('\uD800\uDC00'); // surrogate pair to create a single Unicode character
    // *     returns 2: 65536

    var str = string + '';
    
    var code = str.charCodeAt(0);
    if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
        var hi = code;
        if (str.length === 1) {
            return code; // This is just a high surrogate with no following low surrogate, so we return its value;
                                    // we could also throw an error as it is not a complete character, but someone may want to know
        }
        var low = str.charCodeAt(1);
        if (!low) {
            
        }
        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
    }
    if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
        return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
                                // we could also throw an error as it is not a complete character, but someone may want to know
    }
    return code;
}

function focus_stuff(ev){
var e=suchajh(ev); e=$(e);
	if(!e) return false;
	var table=ev.target.up("table")
	if(table){
		var alt_drinn= table.down(".drinn")
		if (alt_drinn) alt_drinn.removeClassName("drinn")
	}
	var focused=ev.target.up(".focused")
	if(focused) focused.removeClassName("focused")
	e.addClassName("drinn")
	if(e.tagName=="OPTION"){
		if (ev.shiftKey || ev.ctrlKey) return false; //in selectionsboxen multiselect ermöglichen
		e.selected=false
		e.addClassName("selected")
	}
	return e}
	
String.prototype.zu=function(auf,zu){
	var i=0
	while(this[++i]!=zu && i<=this.length){
		if(this[i]=="'") i+=this.substring(i).zu("'","'");
		if(this[i]=='"') i+=this.substring(i).zu('"','"');
		if(this[i]==auf) i+=this.substring(i).zu(auf,zu);
	}
	return (this[i]==zu?i:zu+' not found')
}
function dsdebug(e,s){
	 var zenddebug='&start_debug=1&debug_host=192.168.100.60&debug_port=10000&debug_stop=true&debug_file_bp=/deepbase.beta/deep_pars.php&debug_line_bp=1833&debug_session_id=123456789'
	 var debugline=document.forms[0].appendChild(document.createElement('input'))
	 debugline.type='text'
	 debugline.value=s
	 debugline.id=debugline.name='debugline'
	 var taste=e.keyCode?"&taste="+keycodes['0'+e.keyCode.toString()]:""
	 getallforms(e,"popup","submit","dsdebug"+taste+"&title=Testen von:"+document.forms[0].formname.value+"("+document.forms[0].formsid.value+")"+(e.keyCode==123?zenddebug:''),document.forms[0].formname.value)
	 return true
}
function closewindows(like){
	var o=opener
	while(o.opener) o=o.opener
	for(var w in o.top.popups){
		if(w.indexOf(like)!=-1) o.top.popups[w].close()
	}
	
}
function eventhandler(){
	function focusInHandler(e){
		Event.findElement(e).fire("focus:in");
	}
	function focusOutHandler(e){
		Event.findElement(e).fire("focus:out");
	}
	function clickHandler(e){
		if(!window.event) window.event=e
		if(e.isRightClick()){
			if(!e.ctrlKey){Event.stop(e);Event.findElement(e).fire("right:click",e);}}
	}
	
	if (document.addEventListener){
		document.addEventListener("focus", focusInHandler, true);
		document.addEventListener("blur", focusOutHandler, true);
		document.addEventListener("click", clickHandler, true);
		document.addEventListener("contextmenu", clickHandler, true);
	} else {
		document.observe("focusin", focusInHandler);
		document.observe("focusout", focusOutHandler);
		document.on("mousedown", clickHandler);
		document.on("contextmenu", clickHandler);
	}
	document.on("focus:out",".savesubito",savesubito);
};
function setvar(name,value){
	var ajax=new Ajax.Request('?action=do&func=set&name=value')
}

eventhandler();
