// Globale Javascript-Funktionen fuer das AISware CMS3
// Jens Gassmann 04/2003 gassmann@angel.de

/*

Änderungen:

	15. Juli - Jens Gassmann - gassmann@angel.de
	-	dynamischer Pfad für den Link und Medienbrowser hinzugefügt.

*/


over = function() {
	
	if (document.getElementById("header-navigation")) {

		var sfEls = document.getElementById("header-navigation").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" over";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" over\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", over);


// Anzeigen eines Hilfefenster 
function explain(e,TermName,explText,TermId) { 

   var ns = navigator.appName == "Netscape";
   var ns4 = (ns && parseInt(navigator.appVersion) == 4);
   var ns5 = (ns && parseInt(navigator.appVersion) > 4);

    // get mouse position
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }

   // get layer layExplain object
   if (ns4) myLayer = document["layExplain"]; 
   else if (ns5) myLayer = document.getElementById("layExplain");
   else myLayer = document.all ? document.all["layExplain"] : null;

   // get  txtExplain paragraph
   if (ns4) txtPara = document["txtExplain"]; 
   else if (ns5) txtPara = document.getElementById("txtExplain");
   else txtPara = document.all ? document.all["txtExplain"] : null;

   // get lexLink linkage
   if (ns4) lexText = document["lexLink"];
   else if (ns5) lexText = document.getElementById("lexLink");
   else lexText = document.all ? document.all["lexLink"] : null;
   TermId = '/lexikon/?termID=' + TermId;

   // write text and move into visible area
   if (myLayer) {

       txtPara.innerHTML = explText;
       lexText.href = TermId;
       myLayer.style.left=xMousePos - 20;
       myLayer.style.top=yMousePos - 30;
   }
}

// Ausblenden des Hilfefensters
function unexplain()
{  
   var ns = navigator.appName == "Netscape";
   var ns4 = (ns && parseInt(navigator.appVersion) == 4);
   var ns5 = (ns && parseInt(navigator.appVersion) > 4);

   // get layer layExplain object
   if (ns4) myLayer = document["layExplain"]; 
   else if (ns5) myLayer = document.getElementById("layExplain");
   else myLayer = document.all ? document.all["layExplain"] : null;

   // get  txtExplain paragraph
   if (ns4) txtPara = document["txtExplain"]; 
   else if (ns5) txtPara = document.getElementById("txtExplain");
   else txtPara = document.all ? document.all["txtExplain"] : null;

   // move out of visible area
   if (myLayer) {
	   txtPara.innerHTML = "";
	   myLayer.style.left=0;
	   myLayer.style.top=-100;
   }
}

// Funktion zum dynamischen Wechsel der CSS-Class eines Feldes/Zelle/bEreiches
function pviiClassNew(obj, new_style) {
  obj.className=new_style;
}

// Structur editieren
function structur_edit(id,parent_id,sort,table,edit,text) { //v1.0 by JGA

	document.structur_edit.structur_id.value		= id;
	document.structur_edit.structur_parent_id.value = parent_id;
	document.structur_edit.structur_sort.value		= sort;
	document.structur_edit.structur_table.value 	= table; 
	document.structur_edit.structur_edit.value		= edit;
	document.structur_edit.action = "";	

	var admin_path = document.structur_edit.wizard_path.value;
	var input_path = document.structur_edit.input_path.value;
	var session	   = document.structur_edit.session.value;	
	var table      = document.structur_edit.admin_tree.value;

	if (edit == 'del') {
	    
	    var ok = confirm(text);		
    
	    if (ok) {
	        document.structur_edit.submit();
	    }
		
	} else if (edit == 'add'){
	
		if (table == 'content_ext') {
			 
			 document.structur_edit.action = '/admin'+ admin_path + session + '/' + input_path + 'site_add_'+ id +'.htm';
		} 
				
		document.structur_edit.submit()
			

	} else if (edit == 'under') {
	
	   	if (table == 'content_ext') {

			document.structur_edit.action = '/admin'+ admin_path + session + '/' + input_path +  'site_under_'+ id +'.htm';
		}

		document.structur_edit.submit();
		
	} 
	
	if (edit == 'up') {
	
	    document.structur_edit.submit();
	}
	
	if (edit == 'down') {
	
	    document.structur_edit.submit();
	}


}

// Funktion fuer die Haendlerdatenbank V1.0 by JGA
function dealeraction(action,id) {

    document.content.action.value = action;
    document.content.id.value	  = id;
    document.content.submit();
}

// Medien Browser V1.3 by JGA
function open_media_browser(typei,fieldi,sorti) {

    media_browser_path  = document.content.media_browser_path.value;
	if (media_browser_path) {
	
	    media_id          	= eval("document.content."+fieldi+".value");
    	media_path        	= eval("document.content.media_path_"+fieldi+".value");
	    media_win 	        = window.open(media_browser_path+'/byid-'+media_path+'/id-'+media_id+'-name-'+fieldi+'-type-'+typei+'-sort-'+sorti+'.htm','mediabrowser',"width=750,height=500,scrollbars=yes,status=yes,resizable=yes,left=0,top=0");
	
	} else {
	
		alert('Es sind keine Zugriffsrechte auf den Mediabrowser für den angemeldeten Benutzer eingerichtet!');
	}
}


function openit(path,height,width) {

	window.open(path,'mediabrowser',"width="+width+",height="+height+",scrollbars=yes,status=yes,resizable=yes,left=0,top=0");
}


// Link Browser V1.3 by JGA
function open_link_browser(fieldi) { 
  
    link_browser_path 	= document.content.link_browser_path.value;
    
	if (link_browser_path) {
	
	    link_id   	       	= eval("document.content."+fieldi+".value");
	    link_name        	= eval("document.content.link_name_"+fieldi+".value");
   	    media_win        	= window.open(link_browser_path+'/byid-'+link_name+'/id-'+link_id+'-name-'+fieldi+'-type-0-sort-0.htm','mediabrowser',"width=275,height=500,scrollbars=yes,status=no,resizable=yes,left=15,top=15");

	} else {
	
		alert('Es sind keine Zugriffsrechte auf den Linkbrowser für den angemeldeten Benutzer eingerichtet!');
	}
}

// Link Browser Extended V1.1 by JGA
function open_link_browser_extended(fieldi) { 
  
    var link_browser_path 	= document.content.link_browser_path.value;

	if (link_browser_path) {
    
		var link_field   	= eval("document.content."+fieldi+".value") || 0;
	    var link_data		= link_field.split("o");
    	var id_structur		= link_data[0];
	    var id_item			= link_data[1];
    	var link_name       = eval("document.content.link_name_"+fieldi+".value");
	    var media_win       = window.open(link_browser_path+'/link-browser-row-'+fieldi+'-id_structur-'+id_structur+'-id_item-'+id_item+'.htm','mediabrowser',"width=700,height=500,scrollbars=yes,status=yes,resizable=yes,left=15,top=15");

	} else {
		alert('Es sind keine Zugriffsrechte auf den erweitertem Linkbrowser für den angemeldeten Benutzer eingerichtet!');
	}
}


// Linkbrowser, Rückgabe V1.2 by JGA
function setlink(id_media,name) { 

    row = document.content.row.value;    
    eval("window.opener.document.content."+row+".value = id_media");
    eval("window.opener.document.getElementById('"+row+"').innerHTML = name");
    self.close();
}


// MediaBrowser, Rückgabe V1.3 by JGA
function setmedia(id_media,name,file,media_path,short_name) { 

    row = document.content.row.value;	
    window.opener.document.getElementById(row).innerHTML = short_name;
    eval("window.opener.document.content."+row+".value = id_media");
    eval("window.opener.document.content.media_name_"+row+".value = name");
    eval("window.opener.document.content.media_path_"+row+".value = media_path");
    eval("window.opener.document.media_src_"+row+".src= file");
    self.close();
}

// MediaBrowser WYSIWYG-Mode, Rückgabe V1. by JGA
function setmedia_wysiwyg(url,id) { 

    window.opener.setImage(url,id);
    window.close();
}


// Media löschen V 1.0 by JGA
function media_delete(id) { 

	ok = confirm("Media wirklich löschen?");

	if (ok) {

	    document.medialist.action_id.value = id;
	    document.medialist.action.value    = 'delete';
	    document.medialist.submit();	
	}
}
// Medien sortieren ändern V1.0 by JGA
function media_sort(id,way) { 

    document.medialist.action_id.value = id;
    document.medialist.action.value    = way;
    document.medialist.submit();
}

// Medienvorschau V1.1 by JGA
function view(murl,mtype) {

    showie = window.open("","Fenster2","width=440,height=440,left=25,top=25,scrollbars=yes,resizable=yes");
    showie.location.href=murl;
    showie.focus();
}

// Blockverwaltung V1.1 by JGA
function blockaction(action,sort,loop) { 

    document.content.block_sort.value   = sort;
    document.content.block_action.value = action;
    document.content.block_loop.value	= loop;
    document.content.target        		="_self";
    document.content.action	       		="";
    if (action == 'delete') {
	
	var dele = confirm("Absatz wirklich löschen?");
    
        if (dele) {
	
	    document.content.submit();
		}
		
    } else {
	
	document.content.submit();
    }
}


// Toggle für die Auswahl der Medien V1.1 by JGA
function select_toggle(id,obj) { 

    class_name = obj.className;
    field = 'media_tools_id_'+id;
    
    if (class_name == 'box') {

	obj.className = 'boxselected';
	eval('document.medialist.'+field+'.value=\'checked\'');

    } else {
    	obj.className = 'box';
    	eval('document.medialist.'+field+'.value=\'\'');
    }
}

// Formular Funktionen
function form_upblock(id) {
	// Block nach oben verschieben
	document.content.upblock.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_downblock(id) {
	// Block nach unten verschieben
	document.content.downblock.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_upgroup(id) {
	// Gruppe nach oben verschieben
	document.content.upgroup.value = id;
	document.content.save.value = 1;	
	document.content.submit();
}
function form_downgroup(id) {
	// Gruppe nach unten verschieben
	document.content.downgroup.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_upquest(id) {
	// Frage nach oben verschieben
	document.content.upquest.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_downquest(id) {
	// Frage nach unten verschieben
	document.content.downquest.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_delblock(id) {
	// Block löschen
	document.content.delblock.value = id;
	document.content.save.value = 1;	
	document.content.submit();
}
function form_delgroup(id) {
	// Gruppe löschen
	document.content.delgroup.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_delquest(id) {
	// Frage löschen
	document.content.delquest.value = id;
	document.content.save.value = 1;
	document.content.submit();
}

function form_addblock(id) {
	// Block hinzufügen
	document.content.addblock.value = id;
	document.content.save.value = 1;
	document.content.submit();
}
function form_addgroup(id,block) {
	// Gruppe hinzufügen
	document.content.addgroup.value = id;
	document.content.addgroup_block.value = block;
	document.content.save.value = 1;
	document.content.submit();
}
function form_addquest(id,group) {
	// Frage hinzufügen
	document.content.addquest.value = id;
	document.content.addquest_group.value = group;
	document.content.save.value = 1;
	document.content.submit();
}

function access_action(what) {

    document.content.access_action.value = what;
    document.content.submit();
				
}

// Template Code sichern V1.0 by JGA
function save_wysiwyg_template(goback) {

			if (goback == 0) {

				document.template.submit();
		}
		
		if (goback == 1) {
		
				document.template.action = 'savecode-0.htm';
				document.template.submit();		
		}
}
// Vorlagen Elemente sichern V1.1 by JGA
function save_template_parts(goback) {

		if (goback == 0) {

			document.template.submit();
		}
		
		if (goback == 1) {
		
			document.template.action = 'saveparts-0.htm';
			document.template.submit();		
		}

		if (goback == 2) {

			document.location.href = 'index-0.htm';		
		}
}
// Vorlagen Elemente modifzieren V 1.1 by JGA
function mod_template_parts(action,id) {

	if (action == 'add') {
			
				document.template.field_name_new.value = prompt('Bitte Namen für neues Element eingeben!');
	 		document.template.field_row_new.value  = prompt('Bitte Spaltenbezeichnung für neues Element eingeben! \n Nur a-z und _');
				document.template.action.value = action;
				document.template.id.value = id;
				if (document.template.field_name_new.value && document.template.field_row_new.value) document.template.submit() ;
	
	} else if (action == 'addloop') {
			
				document.template.field_name_new.value = prompt('Bitte Namen für neuen Absatz eingeben!');
				document.template.field_row_new.value  = prompt('Bitte Bezeichnung für neuen Absatz! \n Nur a-z und _');
	 		document.template.action.value = action;
				document.template.id.value = id;
				if (document.template.field_name_new.value && document.template.field_row_new.value) document.template.submit() ; 
	

	} else {

				document.template.action.value = action;
				document.template.id.value = id;
				document.template.submit();
	}
}

	// neue Vorlage hinzufügen V 1.0 by JGA
function add_template() { 
 
	document.template.template_name_new.value         = prompt('Bitte Namen für neuen Vorlage eingeben!');
	document.template.template_description_new.value  = prompt('Bitte kurze Beschreibung für die Vorlage eingeben');
 document.template.submit();
}
// Vorlagen Vorschau V 1.0  by JGA
function preview_template(preview_path) {
 
	preview2 = window.open('','preview2','status=yes,scrollbars=yes,resizable=yes,width=800,height=600,top=50,left=50');
	document.content.preview.value = 1;
    document.content.update.value  = 0;
	document.content.target        = "preview2";
	document.content.action        = preview_path;
	document.content.submit();
	preview2.focus();
	
}

// Vorlage speichern V 1.0 by JGA
function save_template() {
  
    document.content.preview.value =  0;
    document.content.update.value  =  1;
    document.content.action        = '';
    document.content.target        ="_self";
    document.content.submit();
}

// Vorlage speichern und zurück zur seite V 1.0 by JGA
function save_and_back_template(preview_path) {
  
    document.content.preview.value = 0;
    document.content.update.value  = 1;
	document.content.save.value	   = 1;
    document.content.action        = preview_path;
    document.content.target        ="_self";
    document.content.submit();
}

// Vorlagen Sample V 1.0 by JGA
function sample_template(sid) {
	sample1 = window.open('','sample1','status=yes,scrollbars=yes,resizable=yes,width=800,height=600,top=50,left=50');
  	document.content.sample_id.value  = sid;
	document.content.target    = "sample1";
	document.content.action    = "/site/";
	document.content.submit();
	sample1.focus();
}

// Newsletter speichern/senden und testen
function newsletter_save(action_url) {

	document.newsletter.action = action_url;
	document.newsletter.submit();
}

// Termin speichern/zur übersicht V1.0 by JGA
function eventmanager_save(action_url) {

	document.content.action = action_url;
	document.content.submit();
}

// Admin Structur Elemente modifzieren V 1.1 by JGA
function mod_admin_structur_parts(action,id) {

	if (action == 'add') {
			
				document.admin_structur.field_name_new.value = prompt('Bitte Namen für neues Element eingeben!');
	 		document.admin_structur.action.value = action;
				document.admin_structur.id.value = id;
				if (document.admin_structur.field_name_new.value) document.admin_structur.submit() ;
	
	} else if (action == 'under') {
			
				document.admin_structur.field_name_new.value = prompt('Bitte Namen für neuen Absatz eingeben!');
	 		document.admin_structur.action.value = action;
				document.admin_structur.id.value = id;
				if (document.admin_structur.field_name_new.value) document.admin_structur.submit() ; 
	
	} else {

				document.admin_structur.action.value = action;
				document.admin_structur.id.value = id;
				document.admin_structur.submit();
	}
}

// Funktion zur dynamischen anzeige des Administrationsuntermenüs V1.0 JGA 13.Oktober 2oo3
function change_view(count) {

	for (var i = 0; i < document.getElementsByTagName("div").length; i++) {

		if (document.getElementsByTagName('div')[i].id.indexOf('subadmin') == 0) {
		 
		 	document.getElementsByTagName('div')[i].style.visibility = "hidden";
		}
	}

	for (var i = 0; i < document.getElementsByTagName("a").length; i++) {
		if (document.getElementsByTagName('a')[i].id.indexOf('navadmin') == 0) {
	 
	 	 	document.getElementsByTagName('a')[i].className = 'topbutton';
		}
	}
	
	document.getElementById("navadmin_"+count).className = 'topbuttonover';
	document.getElementById("subadmin_"+count).style.visibility = "visible";
} 

// Medienbrowser Bild löschen Funktion

// Medienbrowser Bild löschen Funktion
function media_browser_delete(id) {

	var ok = confirm('Datei wirklich löschen?');
	
	if (ok) {
		
		document.content.deletemedia.value = id ;
		document.content.submit();
	}
}

// Subsite - Löschen einer kompletten Unterseite inkl allen Inhalten usw
function del_subsite(id_users) {

	var ok = confirm('Komplette Unterseite wirklich löschen?');
		
	if (ok) {
		
		document.location.href = "delete-" + id_users + ".htm";

	}
}

// Löschen eines Benutzers
function del_user(link_del) {

	var ok = confirm('Benutzer wirklich löschen?');
		
	if (ok) {
		
		document.location.href = link_del;

	}
}

// Löschen eines Produktes
function del_orderform(link_del) {

	var ok = confirm('Produkt wirklich löschen?');
		
	if (ok) {
		
		document.location.href = link_del;

	}
}


// Alle Checkboxen toggeln 
function changeall(ele) {

	for(var x=0;x<document.content.elements.length;x++) {
	
		var y=document.content.elements[x];
		if(y.name=="report"+ele) {
		 eval("y.checked=document.content.change"+ele+".checked;");
		}
	}
}

// Alle Checkboxen toggeln name der Checkboxen, Referenzfeld
function toggleall(ele,ref,myformname) {

	if ( myformname == undefined )  myformname = 'content' ;
	
	var pos = 0 ;
	for ( pos=0;pos<document.forms.length;pos++) {			
		if (document.forms[pos].name == myformname ) {
			var myform = document.forms[pos] ;
 		}
	}

	for(var x=0;x< myform.elements.length;x++) {
		var y=myform.elements[x];
		if(y.name == ele) {
			y.checked= ref.checked;
 		}
	}

}

// Erlaube beim Kalender nur Montage auszufwählen
function only_monday(date) {

	var day = date.getDay();
		if (day == 1 ) {
		 return false;
	} else {
		 return true;
	}
}

// Erlaube beim Kalender nur Sonntage auszufwählen
function only_sunday(date) {

	var day = date.getDay();
		if (day == 0 ) {
		 return false;
	} else {
		 return true;
	}
}

// Helpbox tooglen
function togglehelp(toggle) {

	
	
	if (toggle) {
		 document.getElementById("helpbox").style.display = "block";
	} else {
	   document.getElementById("helpbox").style.display = "none";
	}	
}


// Abfrage ob wirklich löschen!
function confirm_delete(message,link_del) {

	var ok = confirm(message);
		
	if (ok) {
		document.location.href = link_del;
	}
}


// Abfrage ob wirklich löschen - Javascript-Code ausführen
function confirm_js(message,code) {

	var ok = confirm(message);
		
	if (ok) {
		eval(code);
	}
}

// Maximale Anzahl von Zeichen in einer textarea
function maxchar(tfield,trest,max) {

		var text = tfield.value;
		ist = text.length
		rest = max - ist
		if (rest < 0) {
			tfield.value = text.substr(0,max);
			rest = 0;
		}
		trest.value = rest
}

// Display-toogle für ein Element 
function toggleElement(ElementID){
 document.getElementById(ElementID).style.display = ( document.getElementById(ElementID).style.display.indexOf('block') == -1) ? 'block' : 'none';	
}

// Formular an ein bestimmte URL absenden
function submitform(formname,url) {

	eval("document."+formname+".action='"+url+"';");
	eval("document."+formname+".submit();");
}


// Funktion zum Aufruf einer Website
function website_call(website) {

	if ( website != '' ) {
	   url = "http://" + website;
  	   F1 = window.open(url,"Fenster","");
	   F1.focus(); 
	} else {
	  alert("Keine Website eingeben!");
	}
    return false;
}