// Java Bibliotek -- Pinzgau.com
function zusatzeinstellungen()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.sprachen_id.value='1';
		document.formular.id.value='49';
		document.cookie="zusatzeinstellung=1";
		document.formular.aktion.value='sprache';
		document.formular.submit();
	}
}

function textlinkeinstellungen()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.sprachen_id.value='1';
		document.formular.id.value='39950';
		document.cookie="zusatzeinstellung=5";
		document.formular.aktion.value='sprache';
		document.formular.submit();
	}
}

function sprachen()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.sprachen_id.value='1';
		document.formular.id.value='97';
		document.cookie="zusatzeinstellung=2";
		document.formular.aktion.value='sprache';
		document.formular.submit();
	}
}
function verknuepfungen()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.sprachen_id.value='1';
		document.formular.id.value='4328';
		document.cookie="zusatzeinstellung=3";
		document.formular.aktion.value='';
		document.formular.submit();
	}
}
function standardeinstellungen()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.id.value='42';
		document.cookie="zusatzeinstellung=4";
		document.formular.aktion.value='';
		document.formular.submit();
	}
}

function workflow()
{
	if(document.formular.detail_id.value == 0)
	{
		alert("Bitte speichern Sie zuerst diesen Inhalt");
	}
	else
	{	
		document.formular.id.value='42';
		document.cookie="zusatzeinstellung=6";
		document.formular.aktion.value='';
		document.formular.submit();
	}
}

function checkall(formname,thestate) {
	var el_collection=eval("document.forms."+formname)	
	for (c=0;c<el_collection.elements.length;c++) {
		if(el_collection.elements[c].type == "checkbox")
			el_collection.elements[c].checked=thestate
	}
}
// Überprüft ob das aktuelle Feld eine Zahl ist
function checkZahl(feld) {
 if(isNaN(feld.value) == true) {
  alert(feld.value + " ist keine Zahl!");
  feld.focus();
  return false;
 }
 else return true;
}
// Überprüft ob ein Wert steht oder nicht
function notEmpty(feld) {
 if((feld.value == null) || (feld.value == "")) {
  alert("Wert darf nicht null sein" )
  feld.focus();
  return false;
 }
 else
  return true;
}
// Überprüft ob die maximale Zeichenlänge schonerreicht wurde oder nicht
function zeichenzaehler(feld,maxstring) {
 eingabetext = feld.value;
 ist = feld.length;
 rest = maxstring - ist;
 if (rest < 0) {  // keine weiteren Eingaben zulassen
 feld.value = eingabetext.substr(0,maxstring);
 rest = 0;
 }
 alert(ist);
 //feld.value = rest;
}
// Funktion zum setzen eines Optionsfeldes
function set_option(feld,wert)
{
	if (navigator.appName.indexOf("Microsoft")== -1) 
	{
		feld.options[wert].selected = true;
	}
	else
	{
		feld.value = wert;
	}
}
function get_option_text(obj) 
{
	for (var i=0; i<obj.options.length; i++) 
	{
		if(	obj.options[i].selected == true)
			return obj.options[i].text;
	}
}
function get_option_value(obj) 
{
	for (var i=0; i<obj.options.length; i++) 
	{
		if(	obj.options[i].selected == true)
			return obj.options[i].value;
	}
}
function get_option_text_nr(obj,value) 
{
	for (var i=0; i<obj.options.length; i++) 
	{
		if(	obj.options[i].value == value)
			return obj.options[i].text;
	}
}
function get_option_nr(obj) 
{
	for (var i=0; i<obj.options.length; i++) 
	{
		if(	obj.options[i].selected == true)
			return i;
	}
}
// Ladet eine URL mit den entsprechenden parametern
function laden(url,parameter) {
	fenster = open(url,'fenster',parameter);
}
function laden_mitte(url,breite,hoehe,parameter)
{
	position_links = (screen.width - breite-20)/2;
	position_oben = (screen.height - hoehe)/2.5;
	var par = 'width='+breite+',height='+hoehe+',left='+position_links+',top='+position_oben +"," + parameter;
	fenster = open(url,'fenster',par);
	fenster.focus();
}
// Datum überprüfen
function pruefe_datum(feld) {
	var arr_datum = feld.value.split('.');
	var gueltig = true;
	var tag = "";
	var monat = "";
	var jahr = "";
	var zeit = "";
	if (feld.value.length) {
		for(i=0;i<feld.value.length;++i)
		switch(feld.value.charAt(i)) {
			case "0":
			case "1":
			case "2":
			case "3":
			case "4":
			case "5":
			case "6":
			case "7":
			case "8":
			case "9":
			case ".":
			case ":":
			case " ":
				break;
			default:
				gueltig = false;
				break;
		}
		if(gueltig) {
			for(o=0;o<3;o++) {
				switch(o) {
					case 0:
						if((arr_datum[o]<1)||(arr_datum[o]>31)) {
							alert('Tag ungültig: ' + arr_datum[o]);
							gueltig = false;
							feld.focus();
						}
						tag = arr_datum[o];
						break;
					case 1:
						if((arr_datum[o]<1)||(arr_datum[o]>12)) {
							alert('Monat ungültig: ' + arr_datum[o]);
							gueltig = false;
							feld.focus();
						}
						monat = arr_datum[o];					
						break;
					case 2:
						arr_jahr = arr_datum[o].split(' ');
						if(arr_jahr[0].length > 2) {
							jahr = arr_jahr[0].substring(2,4);
						}
						else {
							jahr = arr_jahr[0].substring(0,2);
						}
						if(arr_jahr[1]) {
							zeit = arr_jahr[1];
						}
						break;
					case 3:
						break;
					case 4:
						break;
				}
			}
			feld.value = (tag+'.'+monat+'.'+jahr+' ' + zeit);
		}
		else {
			alert("Das Datumsformat ist ungültig!")
			feld.focus();
		}
	}
}
function hinzufuegen(id) {
	document.formular.id.value=id;
	document.formular.detail_id.value=0;
	document.formular.aktion.value='hinzufuegen';
	document.formular.submit();
}
function objekt_hinzufuegen(id) {
	document.formular.id.value=id;
	document.formular.aktion.value='hinzufuegen';
	document.formular.seitenlimit.value='nein';
	document.formular.submit();
}

function objekt_export(konto_id) {
	//XML Export
	//AD am 14.12.06
	var id = document.formular.detail_id.value;
	//var sid = document.xml_session_id.xml_session_id.value;
	
	var jetzt = new Date();
	var Tag = jetzt.getDate();
	var Mon = jetzt.getMonth();
	var Jah = jetzt.getFullYear(); //nein, ich glaube nicht an Jah ;)
	
	ext = ".xml";
	
	var dateiname = konto_id + "_" + id + "_" + Tag + "-" + Mon + "-" + Jah + ext;
	//open_window("../xml/cms_export.php?session_id="+sid+"&konto_id="+konto_id+"&output="+dateiname+"&eltern_id="+id, 640, 480, 1, 1, 1, 1);
	url = "../xml/cms_export_menu.php?konto_id="+konto_id+"&file="+dateiname+"&id="+id;
	var alert_str = "Export aus dem Konto "+konto_id+", alle Kinder der ID "+id+" werden exportiert.";
	//alert_str = alert_str + "\nBitte haben Sie Geduld, der Export kann möglicherweise etwas dauern!";
	//alert(alert_str);
	//window.location.href = url;
	laden_mitte(url,"500","640","scrollbars=yes");
}

function objekt_import(konto_id) {
	var id = document.formular.detail_id.value;
	var sid = document.xml_session_id.xml_session_id.value;
	//laden_mitte("../tools/importcms.php?konto_id="+konto_id+"&eltern_id="+id,"380","450","scrollbar=yes");
	//open_window("../xml/cms_import.php?session_id="+sid+"&konto_id="+konto_id+"&popup&eltern_id="+id, 370, 430, 0, 0, 0, 0, 0);
	laden_mitte("../xml/cms_import.php?session_id="+sid+"&konto_id="+konto_id+"&popup&eltern_id="+id,"450","500","scrollbars=yes");
}
// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
function selectUnselectMatchingValueOptions(obj,value,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		for (var i=0; i<obj.options.length; i++) {
			if (obj.options[i].value == value) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
// -------------------------------------------------------------------
// Für die Anzeigensteuerung von Layers

function MM_findObj(n, d) { //v4.0
  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() { //v3.0
  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; }
    obj.visibility=v; }
}		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
function selectMatchingValueOptions(obj,value) {
	selectUnselectMatchingValueOptions(obj,value,"select",false);
	}	
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (obj.options==null) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// Spezialfunktion für Benutzerauswahl Übernahme

function moveSelectedOptions2(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
	
		// Alle die nicht eingetragen sind 
		// unselectieren
		
		var from2 = arguments[3];
		
		for (var i=0; i<from2.options.length; i++) 
		{
			selectMatchingValueOptions(from,from2.options[i].value);
		}
	}
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}
// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].value] = to.options[i].text;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}
// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions2(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].value] = to.options[i].text;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
			to.options[to.options.length] = new Option( o.text, o.value, false, o.selected);
			}
		}
	// if ((arguments.length<3) || (arguments[2]==true)) {
	//	sortSelect(to);
	// 	}
	// from.selectedIndex = -1;
	// to.selectedIndex = -1;
	}
// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		var o=from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
			} 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 
// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}
function popup_editor(id)
{
	// Inhalt in neues Hiddenfeld kopieren

	editor_element = window.document.getElementById(id);

	window.parent.cms_sitemap.document.editor.langtext.value = editor_element.value;
	
	// Beim ersten Oeffnen ein lokales ewebeditpro Objekt verwenden

	if(window.parent.cms_sitemap.eWebEditPro.popups.length)
	{
		if(window.parent.cms_sitemap.eWebEditPro.popups[0].isOpen())
		{
			// Nur Inhalt austauschen

			
			window.parent.cms_sitemap.eWebEditPro.popups[0].objWindow.eWebEditPro.instances.popup.editor.setDocument(editor_element.value);
			window.parent.cms_sitemap.eWebEditPro.popups[0].objWindow.focus();
			window.parent.cms_sitemap.eWebEditPro.popups[0].objWindow.eWebEditPro.instances.popup.editor.focus();
		}
		else
		{
			// Neu oeffnen

			window.parent.cms_sitemap.eWebEditPro.edit("langtext");
		}
	}
	else
	{
		// Neu oeffnen

		window.parent.cms_sitemap.eWebEditPro.edit("langtext");
	}
}
function select_option(id,value)
{
	el = window.document.getElementById(id);
	
	if (value != '')
	{
		if (navigator.appName.indexOf("Microsoft")== -1)
		{
			el.options[value].selected = true;
		}
		else
		{
			el.value = value;
		}
	}
}


/**
 * Funktion zum Erstellen zufälliger Zahlen
 * wird für open_window benötigt
 */
function randNoDups(maxNum) {
	tmpRand = 0;
	randNum = 0;
	while (tmpRand == randNum) {
		tmpRand = Math.round(Math.random()*maxNum);
	}
	randNum = tmpRand;
	return tmpRand;
}

/**
 * Funktion zum oeffnen eines Popups
 * open_window("http://google.at", 640, 480, 1, 1, 0, 1);
 */

function open_window(url, breite, hoehe, res, scrollbar, menu, tool, loc) {
	position_links = (screen.width - breite-20)/2;
	position_oben = (screen.height - hoehe)/2.5;
	var parameter = 'width='+breite+',height='+hoehe+',left='+position_links+',top='+position_oben+',resizable='+res+',scrollbars='+scrollbar+',menubar='+menu+',toolbar='+tool+',location='+loc;
	var num = randNoDups(100);
	fenster = open(url, 'fenster'+num, parameter);
	fenster.focus();
}
function kontakt_loeschen(url,count)
{
	if(count<=1)
	{
		if(window.confirm("Wenn Sie diese Verknüpfung löschen wird der Kontakt ebenfalls gelöscht. Sind Sie sicher?"))
			window.location.href = url;
	}
	else
	{
		if(window.confirm("Sind Sie sicher, dass Sie diese Verknüpfung entfernen möchten?"))
			window.location.href = url;
	}
}
