/* $Id: generic_lib.js,v 1.20 2004/09/06 13:57:07 chris Exp $ */

//***************************************************************************************************
// JavaScript Version 1.2 
// © Yellowspace smart solutions
// includes generell independent functions 
//***************************************************************************************************

/*******************************************************
 *******************************************************
 
	STARTUP
 
 *******************************************************
 */ function ____StartUp________() {} /*
 *******************************************************/	

//alert('generic_lib is loading');

var page_loaded = 'no';
OnLoadFunctions = new Array();
function OnLoadExec() {
	//alert("starting onload functions");
	for (cux=0;cux< OnLoadFunctions.length;cux++) {
		my_eval = OnLoadFunctions[cux];
		//alert(OnLoadFunctions[cux]);
		eval(my_eval);
	}
	page_loaded = "yes";
	//DebugDump('page_loaded');
}

/*******************************************************
 *******************************************************
 
	LAYER
 
 *******************************************************
 */ function ____Layer________() {} /*
 *******************************************************/	

function showElementsIndexOf(el_tag,el_matchindex,event) {
	var elList = new Array();
	elList = document.getElementsByTagName(el_tag);
	for (var i = 0; i < elList.length; i++) {
		if(elList[i].id && elList[i].id != 'undefined' && elList[i].className == "eventcalendar" && elList[i].id.indexOf(el_matchindex) == -1) {
			elList[i].style.display = 'none';
		} else if(elList[i].id && elList[i].id != 'undefined' && elList[i].className == "eventcalendar" && elList[i].id.indexOf(el_matchindex) > 0) 
					elList[i].style.display = 'block';
	}

	el_target = getEventTarget(event);
	a_el =  updateClassName(el_target,'click');
}

function ToogleVisibility(LayerName) {
	switch (SmartAgent){
	case "Netscape4":
		if(!document.layers[LayerName]) return;
		if(document.layers[LayerName].display == 'none') {
			document.layers[LayerName].display = 'block';
		} else {
			document.layers[LayerName].display = 'none';
		}
	break;
	case "MSIE5":
		if(!document.all[LayerName]) return;
		if(document.all[LayerName].style.display == 'none') {
			document.all[LayerName].style.display = 'block';
		} else {
			document.all[LayerName].style.display = 'none';
		}
	break;
	default:
		if(!document.getElementById(LayerName)) return;
		if(document.getElementById(LayerName).style.display == 'none') {
			document.getElementById(LayerName).style.display = 'block';
		} else {
			document.getElementById(LayerName).style.display = 'none';
		}
	break;
	
	}
}

function folderTree(LayerName) {
	ToogleVisibilitySwapImage(LayerName);
}

function ToogleVisibilitySwapImage(LayerName) {
	
	
	switch (SmartAgent){
	case "Netscape4":
		if(!document.layers[LayerName]) return;
		if(document.layers[LayerName].display == 'none') {
			document.layers[LayerName].display = 'block';
			SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_down.gif");
		} else {
			document.layers[LayerName].display = 'none';
			SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_right.gif");
		}
	break;
	case "MSIE5":
	if(!document.all[LayerName]) return;
	if(document.all[LayerName].style.display == 'none') {
		document.all[LayerName].style.display = 'block';
		SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_down.gif");
	} else {
		document.all[LayerName].style.display = 'none';
		SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_right.gif");
	}
	break;
	default:
		if(!document.getElementById(LayerName)) return;
		if(document.getElementById(LayerName).style.display == 'none') {
			document.getElementById(LayerName).style.display = 'block';
			SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_down.gif");
		} else {
			document.getElementById(LayerName).style.display = 'none';
			SwapImage("arrow_"+LayerName,"/images_admin/editor/arrow_right.gif");
		}
	break;
	}
}

function ToggleVisibilitySwapImagePath(LayerName,img_base_path) {
	switch (SmartAgent){
	case "Netscape4":
		if(document.layers[LayerName].display == 'none') {
			document.layers[LayerName].display = 'block';
			SwapImage("arrow_"+LayerName,img_base_path+"arrow_down.gif");
		} else {
			document.layers[LayerName].display = 'none';
			SwapImage("arrow_"+LayerName,img_base_path+"arrow_right.gif");
		}
	break;
	case "MSIE5":
	if(document.all[LayerName].style.display == 'none') {
		document.all[LayerName].style.display = 'block';
		SwapImage("arrow_"+LayerName,img_base_path+"arrow_down.gif");
	} else {
		document.all[LayerName].style.display = 'none';
		SwapImage("arrow_"+LayerName,img_base_path+"arrow_right.gif");
	}
	break;
	case "Netscape6":
	case "MSIE5.5":
	case "Opera5":
	default:
		if(document.getElementById(LayerName).style.display == 'none') {
			document.getElementById(LayerName).style.display = 'block';
			SwapImage("arrow_"+LayerName,img_base_path+"arrow_down.gif");
		} else {
			document.getElementById(LayerName).style.display = 'none';
			SwapImage("arrow_"+LayerName,img_base_path+"arrow_right.gif");
		}
	break;
	}
}

var ms_run = false; ms_open = false;
function smartMessage(message,title,autoclose) {
	if(ms_run === true) window.clearTimeout(mt);
	if(typeof autoclose == 'undefined') var autoclose = true;
	if(!document.getElementById('js_message')) initSmartMessage();
	messageLayer = document.getElementById('js_message');
	messageLayer.style.display = '';
	var now = new Date();
  	var hrs = now.getHours();
   	var mins = now.getMinutes();
   	var secs = now.getSeconds();
	var elapsed = hrs+'.'+mins+'.'+secs+' h';
	if(typeof title != 'undefined') innerLayer = elapsed+'<br /><b>' + title + '</b> ';
	else innerLayer = innerLayer = elapsed;
	innerLayer += '<p>' +  message + '</p>';
	innerLayer += '<a href="#" style="position:absolute;top:3px; right:5px" class="triggerbutton" onclick="closeMessage(); return false;">&nbsp;ok&nbsp;</a>';
	messageLayer.innerHTML = innerLayer;

	if(autoclose == true) {
		mt = window.setTimeout("closeMessage()",5000);
		ms_run = true;
	} else if(autoclose == 'clickoutside') {
		messageLayer.closeM = function(event) {
			var target=getEventTarget(event);
			is_container_of = getContainerWith(target, 'DIV', 'message')
			if(is_container_of != null) return true;
			if(target == messageLayer) return;
			messageLayer.style.display = 'none';
			removeSmartEvent(document,"mousedown", messageLayer.closeM);
		};
		addSmartEvent(document,"mousedown", messageLayer.closeM);		
	}
}

function initSmartMessage() {
	message_layer = document.getElementsByTagName('body')[0];
	var new_message_layer = document.createElement("div");
	message_layer.appendChild(new_message_layer);
	new_message_layer.className = 'message';
	new_message_layer.id = 'js_message';
	var width =  250;
	var height =  100;

	var wheight = GetWindowHeight();
	var wwidth = GetWindowWidth();
	var top = (getScrollY()+(wheight/2))-(height/2);
	var left = (getScrollX()+(wwidth/2))-(width/2);
	new_message_layer.style.top = top +'px';
	new_message_layer.style.left = left +'px';
}

function closeMessage() {
	document.getElementById('js_message').style.display = 'none';
	if(ms_run === true) { 
		window.clearTimeout(mt);
		ms_run = false;
	}
}


/*******************************************************
 *******************************************************
 
	IMAGE
 
 *******************************************************
 */ function ____Image________() {} /*
 *******************************************************/	

function ImageSwapById(el_id,img_src) {
var my_img = document.getElementById(el_id);
my_img.src = img_src;
}

function openbigpicture(width,height,picture,label) {
if (height > 600) {
		filename = "/site-functions/large_image_view.php?pic="+picture+"&height="+height+"&width="+width+"&name="+label;
		window.open(filename,"Screenshot","scrollbars=1,width="+width+",height=600,status=0,toolbar=0,location=0,menubar=0,resizable=0");
	} else {
		filename = "/site-functions/large_image_view.php?pic="+picture+"&height="+height+"&width="+width+"&name="+label;
		window.open(filename,"Screenshot","scrollbars=0,width="+width+",height="+height+",status=0,toolbar=0,location=0,menubar=0,resizable=0");
	}
}

OnLoadFunctions[OnLoadFunctions.length] = "preloadImages();";
function preloadImages() {
	PreLoad('/images/interface/spinning_wheel.gif');
	//PreLoad('/images/interface/warten.gif');
	/*	PreloadedImage = new Image();
	PreloadedImage.src = imgUrl;
	*/
}


/*******************************************************
 *******************************************************
 
	IFRAME
 
 *******************************************************
 */ function ____IFrame________() {} /*
 *******************************************************/	


IFrameDoc = false;
function ManageIFrame(myIFrame,plusDoc) {

	switch (SmartAgent){
	case "Netscape4":
		// not supported
	break;
	case "MSIE5":
		IFrameObj = document.frames[myIFrame];
	break;
	case "MSIE5.5":
	case "MSIE6":
	case "Opera5":
		IFrameObj = document.frames[myIFrame];
	break;
	case "Netscape6":
		IFrameObj = document.getElementById(myIFrame).contentWindow;		
		// IFrameDoc = IFrameObj.contentWindow.document; 
	break;
	case "Khtml":
		IFrameObj = document.getElementById(myIFrame);
	break;
	default:
		IFrameObj = document.getElementById(myIFrame);
	}

/* not implemented yet
if (plusDoc) {
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }

}
*/

if (plusDoc) return IFrameDoc 
else return IFrameObj;

}

function JumpToIFrameAnchor(my_anchor) {
	IFrameDoc = ManageIFrame(myIFrame,false);
	IFrameDoc.location.hash = my_anchor;
}

function MakeIFrameSinging (myIFrame) {
	IFrameDoc = ManageIFrame(myIFrame,false);
	IFrameDoc.sing();
}

function returnIFrameObj(myIFrame) {

	switch (SmartAgent){
	case "Netscape4":
	case "MSIE5":
		IFrameObj = document.frames[myIFrame];
	break;
	case "MSIE5.5":
	case "MSIE6":
	case "Opera5":
		IFrameObj = document.frames[myIFrame];
	break;
	case "Netscape6":
	case "Khtml":
	default:
		IFrameObj = document.getElementById(myIFrame);		
	break;
	}

	return IFrameObj;

}
 var timesloaded = 0;
function loadIntoIframe(path,iframe_id) {
	e = urlGetExtension(path);
	frames[iframe_id].location.href =  path+e+'timesloaded='+timesloaded;
	timesloaded++;
}

var rIframeId = false; var timeout = 3000;
var timeout_running = false;
function smartIframeFunction(iframe_id,path,timeout) {

	if(timeout_running === true) return;
	iframe_el = document.getElementById(iframe_id);
	
	timeout = timeout;
	px = GetWindowWidth();
	py = GetWindowHeight();
	diff = 7;

	iframe_el.style.left = (px - diff - iframe_el.offsetWidth) +'px';
	iframe_el.style.top = (py - diff - iframe_el.offsetHeight)+'px';
	
	if(path.length > 0) loadIntoIframe(path,iframe_id);

	if(timeout) { 
		rIframeId = iframe_id;	
		window.setTimeout("smartEnableIFrame()",1000);
		timeout_running = true;
	}	
}

function smartTimeoutIframe() {
	iframe_obj = document.getElementById(rIframeId);
	iframe_obj.style.visibility = 'hidden';
	rIframeId = false; timeout_running = false;
}

function smartEnableIFrame() {
	iframe_obj = document.getElementById(rIframeId);
	iframe_obj.style.visibility = 'visible';
	window.setTimeout("smartTimeoutIframe()",timeout);
}

/*******************************************************
 *******************************************************
 
	FORM
 
 *******************************************************
 */ function ____Form________() {} /*
 *******************************************************/	


function countLength(layerId,fieldId,max_field_length) {
//	if(Platform == 'Mac') return true;
	if(!max_field_length) max_field_length = 10000;
	if(!layerId) layerId = 'beitra_laenge';
	if(!fieldId) fieldId = 'message';
	ff = document.getElementById(fieldId);
	content_length = 10000-ff.value.length;
	if(content_length < 1) { 
		WriteToLayer(layerId,'<font color="red">'+content_length+'</font>');
	}
	else WriteToLayer(layerId,content_length);
}



function setBundesland(val) {
	if (!document.getElementById('Bundesland')) return; 
	if (!document.getElementById('Land')) return; 
	
	var el_bundesland = document.getElementById('Bundesland');
	aktuelles_bundesland = el_bundesland.value;
	var el_land = document.getElementById('Land');
	aktuelles_land = el_land.value;

	var match = 0;
	if (bundesland[aktuelles_land]) {
		el_bundesland.options.length = null;
		for (var i=0;i<bundesland[aktuelles_land].length;i++) {
			if(i == 0) {
				NeuerEintrag = new Option(bundesland[aktuelles_land][i],'',false,false);
			} else if (bundesland[aktuelles_land][i] == aktuelles_bundesland)  {
				NeuerEintrag = new Option(bundesland[aktuelles_land][i],bundesland[aktuelles_land][i],true,true);
				match++;
			} else {
				NeuerEintrag = new Option(bundesland[aktuelles_land][i],bundesland[aktuelles_land][i],false,false);
			}
			el_bundesland.options[i] = NeuerEintrag;
		}

		if (match == 0 && val == false) {
			if(aktuelles_bundesland.length == 0) {
				el_bundesland.options[0].selected=true;
			} else { 
				NeuerEintrag = new Option(aktuelles_bundesland,aktuelles_bundesland,true,true);
				el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;	
			}
		}

	} else {
		if (val == true) {
			el_bundesland.options.length = null;
			NeuerEintrag = new Option('keine Auswahl vorhanden','',false,false);
			el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;
			NeuerEintrag = new Option('anderes','',false,false);
			el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;
		} else {
			el_bundesland.options.length = null;
			if (aktuelles_bundesland.length > 0) { 
				NeuerEintrag = new Option(aktuelles_bundesland,aktuelles_bundesland,false,false);
				el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;	
			} else {	
				NeuerEintrag = new Option('Bitte Land auswählen','',false,false);		
				el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;
			}
			NeuerEintrag = new Option('anderes','',false,false);
			el_bundesland.options[el_bundesland.options.length] = NeuerEintrag;		
		}	
	}
}



function ExtendFormfield(fieldId,checkfieldvalue,confirmmessage) {
	var field = document.getElementById(fieldId);
	if (field.value != checkfieldvalue) return;
	
	var fieldtype = document.getElementById(fieldId).type;
	var n = prompt(confirmmessage,"")
	if (n == null) return;
	if (n.length >0) {	
		switch(fieldtype) {
			case"select-one":
				NeuerEintrag = new Option(n,n,false,true);
 				// document.form.Selectname.options[document.forms.Auswahl.length] = NeuerEintrag;
				field.options[field.options.length] = NeuerEintrag;
			break;
		}	
	}
}

function setDefaultValue() {
	 for(i=0; i<document.forms[0].elements.length; i++) {
  		switch(document.forms[0].elements[i].type) {
			case"select-one":
				for(s=0; s<document.forms[0].elements[i].options.length; s++) {
					if(document.forms[0].elements[i].options[s].defaultSelected == true) document.forms[0].elements[i].options[s].selected=true;
				}
				break;
			case"radio":
			case"checkbox":
				if(document.forms[0].elements[i].defaultChecked == false) document.forms[0].elements[i].checked = false;
				break;
			case"text":
			case"password":
			case"textarea":
			default:
				document.forms[0].elements[i].value = document.forms[0].elements[i].defaultValue;
				break;
  		}
  		
	}
}

function hideFormfields() {
	 for(i=0; i<document.forms[0].elements.length; i++) {
  		switch(document.forms[0].elements[i].type) {
			case"select-one":
			case"radio":
			case"checkbox":
			case"text":
			case"password":
			case"textarea":
			default:
				document.forms[0].elements[i].style.visibility = 'hidden';
				//document.forms[0].elements[i].style.display = 'none';
				break;
  		}
	}
}

function hideLayers(layerid) {
	
	if(!document.getElementsByTagName) return;
	var layers = document.getElementsByTagName('div');
	for(i=0; i<layers.length; i++) {
		if(layerid) {
			if(layers[i].id != layerid) layers[i].style.display = 'none';
		} else layers[i].style.display = 'none';
	}
}

function GetFocus() {
	form_length = document.login.elements.length;
	for (i=0; i < form_length; i++) {
			name = document.login.elements[i].name;
			if (document.login.elements[i].type == "text") {
				document.login.elements[i].focus();
				return;
			}	
	}
}


function IFrameParseFunction (myIFrame,formname,operation,q) {
	IFrame = ManageIFrame(myIFrame,false);
	IFrame.EditFunctions(formname,operation,q);
}


function EditFunctions(formname,operation,q) {
	question = q;
	theForm = document.forms[formname];
	selected_item = theForm.selected_item.value;
	current_statement:
	if (question) {
	if (selected_item.length == 0) {
		alert("Es ist  nichts selektiert... ");
		return;
	}

		if (confirm(question)) {
			theForm.operation.value = operation;
			theForm.onsubmit(); // workaround browser bugs.
			theForm.submit();
		}
	} else {
		theForm.operation.value = operation;
		theForm.onsubmit(); // workaround browser bugs.
		theForm.submit();
	}
}


function WriteAddEndOfFormField (fieldid,texttoadd) {
	insertedtext = document.getElementById(fieldid).value;
	if (insertedtext.length > 0) insertedtext = insertedtext + " ";
	document.getElementById(fieldid).value = insertedtext + texttoadd;
}

/* tested on MacIE5.14, MacMozialla5.0,WinIE5.01 */
function GetFocusFormNull() {
	form_length = document.forms[0].elements.length;
	for (i=0; i < form_length; i++) {
			name = document.forms[0].elements[i].name;
			if (document.forms[0].elements[i].type == "text") {
				document.forms[0].elements[i].focus();
			return;
			}
	}
}


running_action = false;
function donotInterruptSubmits() {
	if(!document.getElementById('freelayer')) return;
	running_action = true;
	window.scrollTo(0,0);
	
	switch (SmartAgent){
	case "Netscape4":
		break;
	case "Netscape6":
	case "MSIE5":
	case "Khtml":
		hideLayers('freelayer');
	break;
	case "Opera5":
		break;
	case "MSIE5.5":
	case "MSIE6":
		hideFormfields();
	break;
	}
	
	/*getZeroPos();
	var img_left = WLeft +45;
	var img_top = WTop +35;*/
	var img_left = 45;
	var img_top = 35;	
	loading_text = '<img style="width:28px;height:28px;margin:'+img_top+'px 0px 0px '+img_left+'px" src="/images/interface/spinning_wheel.gif">';
	//loading_text = '<img style="width:30px;height:30px;margin:'+img_top+'px 0px 0px '+img_left+'px" src="/images/interface/warten.gif">';
	WriteToLayer('freelayer',loading_text);
	
	el_l = document.getElementById('freelayer');
	el_l.style.backgroundColor = '#FAFAFA';
	//el_l.style.backgroundColor = '#ffffff';
	el_l.style.width = '5000px';
	el_l.style.height = '5000px';
	el_l.style.zIndex = 300;
//	ManageLayer(el_l.id,true,-20,-20,false,false,300);	
	ManageLayer(el_l.id,true,0,0,false,false,300);	
}


function setActionAndSubmit(my_action,my_target) {
	if(running_action == true) return;
	document.forms[0].target = my_target;
	document.forms[0].action = my_action;
	document.forms[0].onsubmit(); // workaround browser bugs.
	document.forms[0].submit();
}

function setHidden(hidden_value,hidden_id) {
	document.getElementById(hidden_id).value = hidden_value;
}

function setBrowse(hidden_value,hidden_id,eidb) {

	// mod by lopez 16.04.2004: added eidb (prefix for layouts)
	var addition = '';
	var page_offset = '';
	var list_operation = '';
	var order = '';
		
	if(!eidb) eidb = '';
	
	if(document.getElementById(hidden_id)) document.getElementById(hidden_id).value = hidden_value;
	else addition = '/' + hidden_id + '=' + hidden_value;
	
	mlocation = document.forms[0].action;
	seek_id = '' + eidb + 'page_offset';
	if(document.getElementById(seek_id)) page_offset =  document.getElementById(seek_id).value;
	
	seek_id = '' + eidb + 'list_operation';
	if(document.getElementById(seek_id)) {
		list_operation = document.getElementById(eidb+'list_operation').value;
	} else {
		seek_id = '' + eidb + 'hidden_offset';
		list_operation = document.getElementById(seek_id).value; // old name
	}
	seek_id = '' + eidb + 'order';
	if(document.getElementById(seek_id)) order = document.getElementById(seek_id).value;
	
	var path= myPlainPagePath + '/' + page_offset + '/' + list_operation + '/' + order + addition;
	donotInterruptSubmits();
	location.href = checkUrl(path);
}


function setHiddenAndSubmit(hidden_value,hidden_id) {
	
	if(running_action == true) return;
	document.getElementById(hidden_id).value = hidden_value;
	document.forms[0].onsubmit(); // workaround browser bugs.
	document.forms[0].submit();
}

function justSubmit() {
	if(running_action == true) return;
	document.forms[0].onsubmit(); // workaround browser bugs.
	document.forms[0].submit();
}

function confirmHidden(hidden_value,hidden_id,question) {
	if (confirm(question)) {
		document.getElementById(hidden_id).value = hidden_value;
	} else { 
		if(document.getElementById('triggers')) document.getElementById('triggers').value = ''; // unset triggers
		return false;
	}
}

function confirmOperation(operation,question) {
	if (confirm(question)) {
		eval(operation);
	} else return false;
}

function confirmHiddenAndSubmit(hidden_value,hidden_id,question) {
	if(running_action == true) return;
	if (confirm(question)) {
		document.getElementById(hidden_id).value = hidden_value;
		document.forms[0].onsubmit(); // workaround browser bugs.
		document.forms[0].submit();	
	} else { 
		if(document.getElementById('triggers')) document.getElementById('triggers').value = ''; // unset triggers
		return false;
	}
}

function quoteMessage(trigger,message) {

	// check if something selected
	// check if it is in the same range as message_sid? by id?
	// fill up message_spec and message_quote_spec
	// say all for complete message
	pattern = getSelection(parent.window.content);
	question = 'M\u00F6chtest du wirklich den ganzen Beitrag zitieren? Du kannst auch nur einen Teil daraus selektieren und dann wieder auf den Button "Antworten mit Zitat" klicken.';
	if(pattern.length==0) {
		if (confirm(question)) {
			pattern = 'all';
		} else return;
	}
	document.getElementById('message_quote_spec').value = pattern;
	document.getElementById('message_spec').value = message;
	document.getElementById('triggers').value = trigger;
	document.forms[0].onsubmit(); // workaround browser bugs.
	document.forms[0].submit();	
//	alert(pattern);
}

function confirmLayer(layername,triggername,message,fieldid) {
	//addEventMousePos();

	switch(triggername) {
		case"mlayer":
		default:
			var el_width = 300; // aktuelle Breite des Menupunktes 
			var el_height = 100; // aktuelle Hšhe des Menupunktes				
			break;	
	}


	 
	if(document.getElementById(layername)) {
		this.element = document.getElementById(layername);
		
		WriteToLayer('description_'+fieldid,message);
		
		var el_left = MLeft -20;
		var el_top = MTop +10;

		ManageLayer(this.element.id,true,el_left,el_top,false,false,2);
		this.element.style.display = 'block';
		this.isOpen = true;
		document.getElementById('triggers').value = triggername;
		
		//removeEventMousePos();
	} else return false;
	return false;
}


function setSelctedItem(selectthis,formname) {
	theForm = document.forms[formname];
	theForm.selected_item.value = selectthis;
}

function swapFieldValues(fieldId_1,fieldId_2) {
	my_value = document.getElementById(fieldId_1).value;
	document.getElementById(fieldId_2).value = my_value;
}


OnLoadFunctions[OnLoadFunctions.length] = "checkAdminMode();";
function checkAdminMode() {
	if(document.getElementById('editorchen_layer')) return;
	else if(typeof GetMousePos == 'function') return;
	else addEventMousePos();
}

function showLayerOnMousePos(layername,show_hide) {
	if(document.getElementById(layername)) {
		this.element = document.getElementById(layername);
		
		var el_left = MLeft -100;
		var el_top = MTop +15;

		ManageLayer(this.element.id,true,el_left,el_top,false,false,2);
		this.element.style.display = show_hide;
		this.isOpen = true;
	} else alert('layer wurde nicht gefunden...');
}

function hideDefaultValue(el_id,default_value) {
	
	if(document.getElementById(el_id).value == default_value) {
		document.getElementById(el_id).value = '';
		
	} /*else if(document.getElementById(el_id).value.length == 0) {
		alert(document.getElementById(el_id).value.length);
		document.getElementById(el_id).value = default_value;
	}*/
}

/*******************************************************
 *******************************************************
 
	EVENTS
 
 *******************************************************
 */ function ____Events________() {} /*
 *******************************************************/	


function addSmartEvent(el,evname,func) {

	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}

/*
  	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			el.addEventListener(evname, func, true);
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			el.attachEvent("on" + evname, func);
	}*/
}

function removeSmartEvent(el,evname,func) {

	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
/*
  	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			el.removeEventListener(evname, func, true);
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			el.detachEvent("on" + evname, func);
	}*/
}

function stopSmartEvent(ev)  {

  	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			ev.preventDefault();
			ev.stopPropagation();
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			ev.cancelBubble = true;
			ev.returnValue = false;
	}
}

MLeft = 0;  MTop = 0; 
function addEventMousePos() {
  	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			document.addEventListener("mousemove", mousePos,true);
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			document.onmousemove = mousePos;
			
	}
}

function mousePos(e) {
	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			MLeft = e.pageX;
			MTop = e.pageY;
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			 //MLeft = window.event.clientX;
			 //MTop = window.event.clientY;
			MLeft = event.clientX + document.body.scrollLeft;
			MTop = event.clientY + document.body.scrollTop;
		}
}
function removeEventMousePos() {

	switch (SmartAgent){
		case "Netscape4":
		case "Opera5":
			break;
		case "Netscape6":
		case "Khtml":
			//document.body.style.overflow = "hidden";
			document.removeEventListener("mousemove", addEventMousePos,true);
			break;
		case "MSIE5":
		case "MSIE5.5":
		default:
			document.onmousemove = null;
			
	}
}

function getEventTarget(event) {
	var target;

	switch (SmartAgent){
		case "MSIE5":
		case "MSIE5.5":
			target = window.event.srcElement;
			break;
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
		case "Opera5":
		default:
			target = (event.target.tagName ? event.target : event.target.parentNode);
		}
	
	return target;
}

/*******************************************************
 *******************************************************
 
	WINDOW
 
 *******************************************************
 */ function ____Window________() {} /*
 *******************************************************/	

//-----------------------------------------------------------------------------
// Get x scroll position.
// The number of pixels the document has scrolled horizontally.

function getScrollX() {

	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
		case "Opera5":
 			offset = window.pageXOffset;
		break;
		case "MSIE5":
		case "MSIE5.5":
		default:
 			offset = document.body.scrollLeft;
		}
  return offset;
}

//-----------------------------------------------------------------------------
// Get y scroll position.
// The number of pixels the document has scrolled vertically.

function getScrollY() {
  var offset;
	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
		case "Opera5":
 			offset = window.pageYOffset;
		break;
		case "MSIE5":
		case "MSIE5.5":
		default:
 			offset = document.body.scrollTop;
		}
  return offset;
}

function getZeroPos() {
	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			WLeft = window.pageXOffset;
			WTop = window.pageYOffset;
		break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
		default:
			 //MLeft = window.event.clientX;
			 //MTop = window.event.clientY;
			WLeft = document.body.scrollLeft;
			WTop = document.body.scrollTop;
		}
	//	alert('Left: '+WLeft+', Top: '+WTop);
}


function urlGetExtension(path) {
	var reg = '[\?]'; 
	//var found = path.match(/([\?]+)/); // <-- maybe better...
	var found = path.match(reg);
	if(found) return "&";
	else return "?";
}

function checkUrl(SessionUrl) {

	var urlString;
	var reg = '[&\?]PHPSESSID=[a-z0-9]{32}';
	var found = SessionUrl.match(reg);
	if(found) return SessionUrl; 
	
	var reg = '[\?]';
	var found = SessionUrl.match(reg);
	if(found) wildcard = "&";
	else wildcard = "?";
	//SessionUrl.indexOf("?") > -1 ? wildcard = "&" : wildcard = "?"; 
	if(parent.navigation && parent.navigation.useSession) var urlString = wildcard + "PHPSESSID="+parent.navigation.useSessionId;
	else if(document.forms[0] && document.forms[0].PHPSESSID) var urlString = wildcard + document.forms[0].PHPSESSID.value;
	else return SessionUrl;
	
	var urlString = SessionUrl+urlString;
	return urlString;
}


function checkFormElement(formname,element_name) {
	for(els=0;els<formname.elements.length;els++) {
		if(formname.elements[els].name == element_name) return true;
	}
	return false;
}


function addColorset(colorurl) {
	if(!object_implementation) object_implementation = false;
	switch(object_implementation) {
		case 1:
			if(parent.content && parent.content.active_color_set) colorset_suffix = active_color_set;
			else colorset_suffix = active_color_set;
			break;
		case 2:
		default:
			colorset_suffix = active_color_set;
			break;
	}

	var reg = '[\?]';
	var found = colorurl.match(reg);
	if(found) wildcard = "&";
	else wildcard = "?";
	return colorurl+wildcard+"color_suffix="+colorset_suffix;
}

function contextual_info(infotext_id) {
	Ipath = '/info_texte?infotext_id='+infotext_id+"&color_suffix="+active_color_set;
	width = 390;
	height = 300;
	Iname = 'Info';
	myscreen = GetScreenInfo();
	wtop = (myscreen["height"] / 2) - (height / 2);
	wleft = (myscreen["width"] / 2) - (width / 2);
	var Ipath = checkUrl(Ipath);
	mywin = window.open(Ipath,Iname,"top="+wtop+",left="+wleft+",width="+width+",height="+height+",dependent=yes,scrollbars=2,titlebar=no,status=no,toolbar=no,location=no,directories=no,menubar=no,resizable=yes");
	mywin.focus();
}

function FensterOeffnen(path,name,width,height,scroll) {
	path = checkUrl(path);
	path = addColorset(path);
	//alert(path+' / '+name+' / '+width+' / '+height+' / '+scroll);
	mywin = window.open(path,name,"top=20,left=30,width="+width+",height="+height+",dependent=yes,scrollbars="+scroll+",status=no,toolbar=no,location=no,menubar=no,resizable=yes");
	mywin.focus();
}

function jumpSimple(myUrl) {
	jumpToExtLink(myUrl,'kh');
}

function jumpToExtLink(myUrl,myName,hitId,hitName) {
	var jumpPage = "/link/external";
	var path = myUrl; // myUrl;
	jumpPage = jumpPage+"?path="+path;
//	alert(path);
	if (hitId.length >0 && hitName.length >0) jumpPage = jumpPage+"&object_id="+hitId+"&object_name="+hitName;
	mywin = window.open(jumpPage,myName);
	mywin.focus();
}

jumpindex = 0;
function jumpToAnchor(anchor_index) {
	if(jumpindex>0) return;
	else if(anchor_index.length == 0) return;
	else window.location.href  = '#index_'+anchor_index;
	jumpindex++;
}

function printVersion() {
	if (printversion_available == 'n') {
		alert('Es ist keine Druckansicht f\u00FCr diese Seite verf\u00FCgbar...');
	} else {
		var Ppath = checkUrl(myPlainPagePath+"?print=true");
		FensterOeffnen(Ppath,"PrintVersion",540,GetWindowHeight()-10,'yes')
	}
}


/*******************************************************
 *******************************************************
 
	DOM-ELEMENT-FUNCTIONS
 
 *******************************************************
 */ function ____DOMElementFunctions________() {} /*
	http://developer.apple.com/internet/webcontent/dom2i.html
 *******************************************************/	
/*
Methods are : 
newText = document.createTextNode("This is a new sentence.");
elRef.appendChild(newText)

function removeBElm(){
    var para = document.getElementById("example2");
    var boldElm = document.getElementById("example2B");
    var removed = para.removeChild(boldElm);
}
function replaceSpan(){

    var newSpan = document.createElement("span");
    var newText =Â 
	document.createTextNode("on top of the astounded zebra");
    newSpan.appendChild(newText);

    var para = document.getElementById("example3");
    var spanElm = document.getElementById("ex3Span");
    var replaced = para.replaceChild(newSpan,spanElm);
}
function insertTD(){

	var newTD = document.createElement("td");
	var newText = document.createTextNode("New Cell " + (TDCount++));
	newTD.appendChild(newText);

	var trElm = document.getElementById("example4");
	var refTD = trElm.getElementsByTagName("td").item(2);
	trElm.insertBefore(newTD,refTD);
	
}
*/

function createNewElement(elRef,eltagName) {
	return elRef.createElement(eltagName);
}

function setElementAttribute(el,attrName,attrValue,force) {
	if(force !== false) el.setAttribute(attrName,attrValue);
	else {
		
		// if force = false, replace attirbute only if it does not exist
		
		if (el.hasAttribute(attrName) === false) {
			el.setAttribute(attrName,attrValue);
		}
	}
}

var el_updated = false;
function updateClassName(el,par) {

	if(el == el_updated) return false;
	if(el.className.length>0) { 
		if(el_updated)  el_updated.className = updatedClassName;
		updatedClassName = el.className;
		el.className = el.className+par;
		el_updated = el;
	} else {
		updateClassName(el.parentNode,par)
	}
}

function FindElementsByClassName(el, className) {

  var i, tmp;

  if (el.className == className)
    return el;

  // Search for a descendant element assigned the given class.

  for (i = 0; i < el.childNodes.length; i++) {
    tmp = FindElementsByClassName(el.childNodes[i], className);
    if (tmp != null)
      return tmp;
  }
  return null;
}

function FindElementsByTagName(el, tagName) {

  var i, tmp;

  if (el.tagName == tagName)
    return el;

  // Search for a descendant element assigned the given tagname.

  for (i = 0; i < el.childNodes.length; i++) {
    tmp = FindElementsByTagName(el.childNodes[i], tagName);
    if (tmp != null)
      return tmp;
  }
  return null;
}

function getContainerWith(node, tagName, className) {

  	// Starting with the given node, find the nearest containing element
	// with the specified tag name and style class.

	while (node != null) {
		if (node.tagName != null && node.tagName == tagName && hasClassName(node, className))
		return node;
		node = node.parentNode;
	}
	
	return node;
}

function getContainerWithTag(node, tagName) {

  	// Starting with the given node, find the nearest containing element
	// with the specified tag name and style class.

	while (node != null) {
		if (node.tagName != null && node.tagName == tagName)
		return node;
		node = node.parentNode;
	}
	
	return node;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}


function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}





function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function winFindByClassName(el, className) {

  var i, tmp;

  if (el.className == className)
    return el;

  // Search for a descendant element assigned the given class.

  for (i = 0; i < el.childNodes.length; i++) {
    tmp = winFindByClassName(el.childNodes[i], className);
    if (tmp != null)
      return tmp;
  }

  return null;
}


/*******************************************************
 *******************************************************
 
	ALERT
 
 *******************************************************
 */ function ____Alert________() {} /*
 *******************************************************/	


function ShowAlert(MyAlert,AlertKind) {
AlertKind ? AlertKind = AlertKind + " " : AlertKind = "";
alert(AlertKind+MyAlert);
}

function ConfirmForm(question,urltoload) {
	if (confirm(question)) {
	} else {
		document.login.mysavecookie.checked = false;
	}
}

/*******************************************************
 *******************************************************
 
	LOGIN
 
 *******************************************************
 */ function ____Login________() {} /*
 *******************************************************/	


function LoginOperation(operation) {
	document.forms[0].operation.value = operation;
	document.forms[0].onsubmit(); // workaround browser bugs.
	document.forms[0].submit();
}

function ShowLogin() {

	ManageLayer("mylogin",true,StartPoint,topposition,layerwidth,layerheight);
	StartPoint = StartPoint + 15;
	if (StartPoint >= EndPoint) { 
		clearInterval(rollitbaby);
		myloginstatus = "open";
		GetFocus();
	}
}

myloginstatus = "closed";
rollitbaby = false;
function StartLogin() {
if (myloginstatus == "open") {
ManageLayer("mylogin",false);
myloginstatus = "closed";
} else {
	if (rollitbaby) clearInterval(rollitbaby);
	fensterbreite = GetWindowWidth();
	fensterhoehe = GetWindowHeight();
	layerheight = 200;
	layerwidth = 202;
	StartPoint = 0 - layerwidth;
	EndPoint = 10;
	topposition = fensterhoehe - layerheight;
	rollitbaby = setInterval("ShowLogin()", 50);
}
}


function warning() {
	if (document.login.mysavecookie.checked) {
	tips = " ";
	tips += "Warnung!";
	tips += " ";
	tips += "Ein Cookie mit den Zugangsdaten wird jetzt gespeichert.\n";
	tips += "Damit hat jeder mit diesem Internet Browser Zugriff auf den Adminstrationsmodus dieser Website.\n";
	tips += "Fortfahren?";
	ConfirmForm(tips);
	}
}

/*******************************************************
 *******************************************************
 
	ADDITIONS
 
 *******************************************************
 */ function ____Additions________() {} /*
 *******************************************************/	


var bdl = new Array('Deutschland','Österreich','Schweiz');
var bundesland = new Array(bdl);
bundesland['Deutschland'] = new Array('Bitte auswählen','Baden-Württemberg', 'Bayern', 'Berlin', 'Brandenburg', 'Bremen', 'Hamburg', 'Hessen', 'Mecklenburg-Vorpommern', 'Niedersachsen', 'Nordrhein-Westfalen', 'Rheinland-Pfalz', 'Saarland', 'Sachsen', 'Sachsen-Anhalt', 'Schleswig-Holstein', 'Thüringen');
bundesland['Österreich'] = new Array('Bitte auswählen','Burgenland', 'Kärnten', 'Niederösterreich', 'Oberösterreich', 'Osttirol', 'Salzburg', 'Steiermark', 'Tirol', 'Vorarlberg', 'Wien');
bundesland['Schweiz'] = new Array('Bitte auswählen','Aargau', 'Appenzell Ausserrhoden', 'Appenzell Innerrhoden', 'Basel-Land', 'Basel-Stadt', 'Bern', 'Freiburg', 'Genf', 'Glarus', 'Graubünden', 'Jura', 'Luzern', 'Neuenburg', 'Nidwalden', 'Obwalden', 'Schaffhausen', 'Schwyz', 'Solothurn', 'St. Gallen', 'Tessin', 'Thurgau', 'Uri', 'Waadt', 'Wallis', 'Zug', 'Zürich');


