var mx = 0;
var my = 0;
var isNetscape = false;
var browserVersion;
var activeDiv;
var activeElement;

function setActiveElement( elem ) {
	if( document.getElementById ) {
		activeElement = document.getElementById( elem );
	}
}

function setActiveElementValue( form, value ) {
	var value;

	if( !form || !activeElement ) {
		return;
	}

	activeElement.value = value;
}

function idbaseGUIHideContained( container, contained ) {
	var ns6 = document.getElementById && !document.all;
	var ie4 = document.all && navigator.userAgent.indexOf("Opera") == -1;

	var iscontained = 0;
	var i = 0;
	var e = document.getElementById( container );

	if( e.id == container ) {
		iscontained = 1;
	} else {
		while( ( ns6 && e.parentNode ) || ( ie4 && e.parentElement ) ) {
			if( e.id == container || e.id == contained ) {
				iscontained = ( e.id == container ) ? 1 : 0;
				break;
			}

			e = ns6 ? e.parentNode : e.parentElement;
		}
	}

	if( iscontained ) {
		var foldercontent = ns6 ? e.getElementsByTagName("DIV")[0] : e.all.tags("DIV")[0];
		foldercontent.style.display = "none";
	}
}

function idbaseGUIShowContained( container, contained ) {
	var ns6 = document.getElementById && !document.all;
	var ie4 = document.all && navigator.userAgent.indexOf("Opera") == -1;

	var iscontained = 0;
	var i = 0;
	var e = document.getElementById( container );

	if( e.id == container ) {
		iscontained = 1;
	} else {
		while( ( ns6 && e.parentNode ) || ( ie4 && e.parentElement ) ) {
			if( e.id == container || e.id == contained ) {
				iscontained = ( e.id == container ) ? 1 : 0;
				break;
			}

			e = ns6 ? e.parentNode : e.parentElement;
		}
	}

	if( iscontained ) {
		var foldercontent = ns6 ? e.getElementsByTagName("DIV")[0] : e.all.tags("DIV")[0];
		foldercontent.style.display = "show";
	}
}
/*
function onmousemove( Event )
{
	if (isNetscape) {
		mx = Event.pageX;
		my = Event.pageY;
	} else {
		mx = window.event.x;
		my = window.event.y;
	}
}
*/
function onclick( Event )
{
	if( activeDiv ) {
		MM_showHideLayers( activeDiv.id, '', 'hide' );
	}
}

function ShowBubble( elem, x, y )
{
	if( activeDiv ) {
		if( !document.getElementById ) {
			activeDiv.visibility='hidden';
		} else {
			MM_showHideLayers( activeDiv.id, '', 'hide' )
		}
	}

	if( x != 0 ) {
		document.getElementById( elem ).style.left	= mx + x;
	}

	if( y != 0 ) {
		document.getElementById( elem ).style.top	= my + y;
	}
	
	if( !document.getElementById ) {
		document.layers[elem].visibility='visible';
		activeDiv = document.layers[elem];
	} else {
		MM_showHideLayers( document.getElementById( elem ).id, '', 'show' );
		activeDiv = document.getElementById( elem );
	}
}

function HideBubble()
{
	if( activeDiv ) {
		MM_showHideLayers( activeDiv.id, '', 'hide' );
	}
}

function init()
{
	if( navigator.appName == "Netscape" ) {
		isNetscape = true;
	}

	browserVersion = parseFloat( navigator.appVersion );
	
	if( browserVersion < 4 ) {
		return;
	}

	document.onmousemove = onmousemove;
	document.onclick = onclick;	
}

function formHandler(){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}

/* globale Variables {{{ */
var currRange;
/* }}} */


/* CMS Formularbehandlung {{{ */
function initFormElements()
{
	for( var i = 0; i < document.forms.length; i++ )
	{
		for( var j = 0; j < document.forms[i].elements.length; j++ )
		{
			switch( document.forms[i].elements[j].type )
			{
				case 'text':
				case 'textarea':
					document.forms[i].elements[j].onselect	= storeSelection;
					document.forms[i].elements[j].onclick	= storeSelection;
					document.forms[i].elements[j].onkeyup	= storeSelection;
					document.forms[i].elements[j].onkeydown	= storeSelection;
					document.forms[i].elements[j].onfocus	= storeSelection;
					break;
			}
		}		
	}
}

function setCheckboxes( object, boxes, value )
{
    var elements = document.forms[object].elements[boxes];
    var size	 = elements.length;

    for( var i = 0; i < size; i++ ) {
        elements[i].checked = value;
    }

    return true;
}

function insertText( text )
{
	if( !currRange ) {
		return;
	}

	currRange.text = text;
	currRange.select();
}

function insertTag( tag, option )
{
	tag = '<' + tag;
		
	if( option != null ) {
		tag = tag + ' ' + option;
	}
		
	tag = tag + '>';
	insertText( tag );
}

function insertTags( tag, option )
{
	var tag_text;

	if( !currRange ) {
		return;
	}	
	
	tag_text = '<' + tag;
		
	if( option != null ) {
		tag_text = tag_text + ' ' + option;
	}
		
	tag_text = tag_text + '>';	

	currRange.text = tag_text + currRange.text + '</' + tag + '>';
	currRange.select();
}

function insertLink( askWindow, askUrl, askText )
{
	var text;
	var url;

	if( !currRange ) {
		return;
	}	
	
	if( !( url = prompt( askUrl, "http://" ) ) ) {
		return;
	}
		
	if( url == "http://" ) {
		return;
	}
		
	if( !( text = prompt( askText, currRange.text ) ) ) {
		return;
	}
		
	currRange.text = '<a href="' + url + '"';

	if( confirm( askWindow ) ) {
		currRange.text += ' target="_blank"'
	}
	
	currRange.text += '>' + text + '</a>';
	currRange.select();
}

function insertMail( askMail, askDescription )
{
	var text;
	var mail;

	if( !( mail = prompt( askMail, "" ) ) ) {
		return;
	}
		
	if( !( text = prompt( askDescription, currRange.text ) ) ) {
		return;
	}

	insertText( '<a href="mailto:' + mail + '">' + text + '</a>' );
}

function storeSelection()
{
	if( document.selection.createRange ) {
		currRange = document.selection.createRange().duplicate();
	}
}

function deleteOptions( form, object )
{
	var length = form.elements[object].length;

	if( !form.elements[object] ) {
		return;
	}

	form.elements[object].options.length = 0;
}


function addOptions()
{
	var args = addOptions.arguments;

	if( args < 3 ) {
		return;
	}

	var value = args[0].options[args[0].selectedIndex].value;

	if( !value ) {
		return;
	}

	var options = args[2][value];
	deleteOptions( args[0].form, args[1] );

	for( var i = 0; i < options.length; i++ ) {
		args[0].form.elements[args[1]].options[i] = new Option( options[i], false, true );
	}
}

function autoSubmit( object )
{
	switch( object.type )
	{
		case 'select-one':
		case 'select-multiple':
			object.value = object.options[object.selectedIndex].value;
			object.form.submit();
			break;
	}
}

function submitForm()
{
	var args = submitForm.arguments;

	if( args.length < 3 ) {
		return;
	}

	var thisForm = document.forms[args[0]];

	for( var i = 1; i < args.length; i++ ) {
		var element = document.getElementById( args[i] );
		var input = document.createElement('INPUT');

		if( !element ) {
			continue;
		}

        input.name = args[i];
       	input.type = 'hidden';
   	    input.value = element.innerHTML;
		thisForm.appendChild( input );
	}

	thisForm.submit();
}
/* }}} */


/* CMS GUI {{{ */
function toggleLayer( layer )
{
	if( (obj = MM_findObj(layer)) != null) {
		if( obj.style ) {
			obj=obj.style;
		}

		MM_showHideLayers( layer, '', ( obj.visibility == 'hidden' ? 'show' : 'hide' ) );
	}
}

function expandContained( container, contained ) {
	var ns6 = document.getElementById && !document.all;
	var ie4 = document.all && navigator.userAgent.indexOf("Opera") == -1;

	var iscontained = 0;
	var i = 0;
	var e = document.getElementById( container );

	if( e.id == container ) {
		iscontained = 1;
	} else {
		while( ns6 && e.parentNode || ( ie4 && e.parentElement ) ) {
			if( e.id == container || e.id == contained ) {
				iscontained = ( e.id == container ) ? 1 : 0;
				break
			}

			e = ns6 ? e.parentNode : e.parentElement;
		}
	}

	if( iscontained ) {
		var foldercontent = ns6 ? e.nextSibling.nextSibling : e.all.tags("div")[0];

		if( foldercontent.style.display == "none" ) {
			foldercontent.style.display = "";
		} else {
			foldercontent.style.display = "none";
		}
	}
}

function setFocus( e )
{
	var focusedElement = document.getElementById( e );

	if( !focusedElement ) {
		return;
	}

	focusedElement.focus();
}

function setStyle( e, attribute, style )
{
	var e = document.getElementById( e );

	if( !e ) {
		return;
	}

	e.style[attribute] = style;
}

function setStyles()
{
	var args = setStyles.arguments;

	if( args.length < 3 ) {
		return;
	}

	for( var i = 2; i <= args.length; i++ ) {
		setStyle( args[i], args[0], args[1] );
	}
}

function refreshContainer( e )
{
	var html;
	e = document.getElementById( e );

	if( !e ) {
		return;
	}

	html = e.innerHTML;
	e.innerHTML = '';
	e.innerHTML = html;
}

function clearContainer( e )
{
	e = document.getElementById( e );

	if( !e ) {
		return;
	}

	e.innerHTML = '';
}

function clearContainers( e )
{
	var args = clearContainers.arguments;

	if( args.length < 1 ) {
		return;
	}

	for( var i = 0; i <= args.length; i++ ) {
		clearContainer( args[i] );
	}
}

function doUndo()
{
	document.execCommand('Undo');
}

function doRedo()
{
	document.execCommand('Redo');
}

function doCopy()
{
	document.execCommand('Copy');
}

function doPaste()
{
	document.execCommand('Paste');
}

function doSelect()
{
	document.execCommand('SelectAll');
}

function showTooltip( e, x, y, hide )
{
	if( !document.activeTooltips ) {
		document.activeTooltips = new Array();
	}

	document.activeTooltips[e] = document.getElementById( e );

	if( !document.activeTooltips[e] ) {
		return;
	}

	if( hide ) {
		hideTooltips();
	}

	MM_showHideLayers( document.activeTooltips[e].id, '', 'show' );

	if( x != null ) {
		document.activeTooltips[e].style.left = window.event.x + x;
	}

	if( y != null ) {
		document.activeTooltips[e].style.top	= window.event.y + y;
	}
}

function hideTooltip( e )
{
	if( document.activeTooltips[e] ) {
		MM_showHideLayers( document.activeTooltips[e].id, '', 'hide' );
	}
}

function hideTooltips()
{
	if( !document.activeTooltips ) {
		return;
	}

	for( tooltip in document.activeTooltips ) {
		MM_showHideLayers( document.activeTooltips[tooltip].id, '', 'hide' );
	}
}
/* }}} */


/* Dreamweaver stuff {{{ */
function MM_openBrWindow( theURL, winName, features )
{
	window.open( theURL, winName, features );
}

function MM_findObj( n, d )
{
	var p,i,x;

	if(!d) {
		d=document;
	}
	
	if( (p = n.indexOf("?") ) > 0 && parent.frames.length ) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}

	if( !(x=d[n])&& d.all ) {
		x = d.all[n];
	}

	for( i=0; !x && i < d.forms.length;i++ ) {
		x=d.forms[i][n];
	}

	for( i=0; !x && d.layers && i < d.layers.length;i++) {
		x = MM_findObj(n,d.layers[i].document);
	}

	if( !x && document.getElementById) {
		x=document.getElementById(n);
	}
	return x;
}

function MM_showHideLayers()
{
	var i,p,v,obj,args = MM_showHideLayers.arguments;

	for( i=0; i < (args.length-2); i+=3) {
		if( (obj = MM_findObj(args[i])) != null) {
			v=args[i+2];

			if( obj.style ) {
				obj=obj.style;
				v=(v=='show')?'visible':(v='hide')?'hidden':v;
				d=(v=='visible')?'block':(v='hidden')?'none':obj.display;
				
			}
			
			obj.display=d;
			obj.visibility=v;
		}
	}
}

function MM_displayStatusMsg( msgStr ) {
	status = msgStr;
	document.MM_returnValue = true;
}

function idbaseFormAddOptions()
{

	var args = idbaseFormAddOptions.arguments;

	if( args < 3 ) {
		return;
	}

	var value = args[0].options[args[0].selectedIndex].value;

	if( !value ) {
		return;
	}

	var options = args[2][value];
	idbaseFormDeleteOptions( args[0].form, args[1] );
	var x = 0;
	for( var i = 0; i < options.length; i++ ) {
		if ( options[i] )
		{
			
			args[0].form.elements[args[1]].options[x] = new Option( options[i], i, true );
			x++;
		}
	}
	
}

function idbaseFormSubmit( form, action )
{
	var thisForm;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return;
		}

		if( thisForm.name != form ) {
			return;
		}
	}

	thisForm.action = action;
	thisForm.submit();
}


function idbaseFormAutoSubmit( object )
{
	switch( object.type )
	{
		case 'select-one':
		case 'select-multiple':
			object.value = object.options[object.selectedIndex].value;
			object.form.submit();
			break;

		case 'checkbox':
			object.form.submit();
			break;
	}
}

function idbaseFormAddOptionsValue()
{
	
	var args = idbaseFormAddOptionsValue.arguments;

	if( args < 3 ) {
		return;
	}

	var value = args[0].options[args[0].selectedIndex].value;

	if( !value ) {
		return;
	}

	var options = args[2][value];
	idbaseFormDeleteOptions( args[0].form, args[1] );

	for( var i = 0; i < options.length; i++ ) {
		args[0].form.elements[args[1]].options[i] = new Option( options[i]['description'], options[i]['value'], true );
	}
}

function idbaseFormDeleteOptions( form, object )
{
	var length = form.elements[object].length;

	if( !form.elements[object] ) {
		return;
	}

	form.elements[object].options.length = 0;
}

function idbaseFormGetValue( form, element, value )
{
	var thisForm;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return;
		}

		if( thisForm.name != form ) {
			return;
		}
	}

	if( !thisForm.elements[element] ) {
		return;
	}

	return thisForm.elements[element].value;
}

function idbaseFormSetValue( form, element, value )
{
	var thisForm;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return;
		}

		if( thisForm.name != form ) {
			return;
		}
	}

	if( !thisForm.elements[element] ) {
		return;
	}

	thisForm.elements[element].value = value;
}

function idbaseFormSetChecked( form, element, value )
{
	var thisForm;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return;
		}

		if( thisForm.name != form ) {
			return;
		}
	}

	if( !thisForm.elements[element] ) {
		return;
	}

	thisForm.elements[element].checked = value;
}


function idbaseFormGetChecked( form, element )
{
	var thisForm;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return;
		}

		if( thisForm.name != form ) {
			return;
		}
	}

	if( !thisForm.elements[element] ) {
		return;
	}

	return thisForm.elements[element].checked;
}

function idbaseFormCreateField( form, name, type, defaultValue )
{
	var thisForm;
	var input;

	if( !( thisForm = document.forms[form] ) ) {
		if( !( thisForm = document.getElementById( form ) ) ) {
			return NULL;
		}

		if( thisForm.name != form ) {
			return NULL;
		}
	}

	input = document.createElement( 'INPUT' );
	input.setAttribute( 'type', type );
	input.setAttribute( 'name', name );
	input.setAttribute( 'value', defaultValue );
	return input;
}

function idbaseGUIAddChildId( id, child, returnParent )
{
	var parent = document.getElementById( id );

	if( !parent ) {
		return NULL;
	}

	parent.appendChild( child );

	if( returnParent ) {
		return parent;
	}

	return child;
}

function idbaseGUIAddChild( parent, child, returnParent )
{
	if( !parent ) {
		return NULL;
	}

	parent.appendChild( child );

	if( returnParent ) {
		return parent;
	}

	return child;
}

function extra(linka){
site = linka;
NewWindow=window.open(	site,
						'NewWindow',
						'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}


function limit_input_extranet(max_char) {
e = document.erwProfil.persSeite;
anz = document.erwProfil.anzeige;

	if( !e ) {
		return;
	}

	if ( e.value.length > max_char ) {
	 e.value = e.value.substring(0,max_char-1);

	}
	
	anz.value = e.value.length;
	anz.value = anz.value+" / "+max_char
	
}

function limit_input(max_char) {
e = document.stellengesuch.persSeite;
anz = document.stellengesuch.anzeige;

	if( !e ) {
		return;
	}

	if ( e.value.length > max_char ) {
	 e.value = e.value.substring(0,max_char-1);

	}
	
	anz.value = e.value.length;
	anz.value = anz.value+" / "+max_char
	
}
	
	
	
		function deleteAlert(url){

			answer = confirm("Wollen Sie diesen Eintrag wirklich löschen?")
			if ( answer != 0 ){
				document.location.href = url;
			}

			
		}
		
function openNewWindowImage(media,alt,width,height){
NewWindow=window.open(	'',
						'NewWindow',
						'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=' + width + ',height=' + height);
NewWindow.document.write('<html><head><title>'+alt+'</title><style type="Text/CSS">* {margin: 0px;padding: 0px;}</style></head><body><img src="'+media+'" alt="'+alt+'"></body></html>');
NewWindow.focus();
}