// CMS Content Java
// Version 2.0

// Kein Doppelclick
var clickstop = 0;
// Bereich markiert
var divclickstop = 0;
// Keine mousehover
var mousestop = 0;
// Link zur Modulwahl
var divobjname = '';
// Schutz wenn Div aktiv war
var textclickstop = 0;
// Content bei Textclick
var contentnr = '';
// aktuelle Seite
var CmsPage = 0;

// Cms-Variablen für Singleklick
var CmsCont = '';
var CmsContent = '';
var CmsTyp = '';
var CmsStart = '';
var CmsStop = '';
var CmsEditor = '';

// DIVs
bg_old = new Array();
borderbottom_old = new Array();
bordertop_old = new Array();
var farbwechsel = false;


// Get Variable hinzufügen
function getAdd(getVar,getValue,getString) 
{
 	var getNewString = '';
 	
 	if (getString == '')
 		getString = window.location.search;
		 	
 	if (getString != '') 
 	{
		v=getString.substring(1, getString.length).split('&');
		getVars = new Array();

 		// Alle Get durchlaufen
		for(var x in v)
		{
 			var temp = v[x].split('=');
 			if (temp[0] && temp[0] != '' && temp[1] && temp[1] != '') 
 			{ 
 				// Variable gefunden
 				if (temp[0] == getVar) 
 				{
 					temp[1] = getValue;
 					getVar = ''; 
 				}
 				 				
 				// Eintragen
 				if (getNewString == '')
 					getNewString = '?'+temp[0]+'='+temp[1];
 				else
  				getNewString += '&'+temp[0]+'='+temp[1];
  		}			
		}
	}

	// neue Variable eintragen
	if (getVar != '') {
		if (getNewString == '')
	 		getNewString = '?'+getVar+'='+getValue;
		else
	 	getNewString += '&'+getVar+'='+getValue;
	}
	return getNewString;
}

// Get Variablen zur Adresse hinzufügen
function getWrite(newGet) {

	adresse = window.location.href;
	var varstart = adresse.indexOf('?');
	if (varstart != -1)
	{
		adresse = adresse.substr(0,varstart);	
	}
	adresse += newGet;
	return adresse;
}

// Editor falsch geschlossen
function editclose() 
{
	alert("Die letzten Eingaben wurden nicht gespeichert.\n\nVerwenden Sie zum Schliessen des Editor-Fensters besser die Schaltflächen im Editor!");
	
	newget = getAdd('reload','true','');
	adresse = getWrite(newget);

	window.location.href=adresse;
	window.focus();
}

// Datnebank cms ende
function cmsdbende() 
{
	adresse = window.location.href;
	window.location.href=adresse;
	window.focus();	
}


function cmsmenu(meldung) 
{
	if (meldung)
	{
		adresse = "/cms/login.php?button=editwindow";
	}
	else
	{
		adresse = "/cms/login.php";
	}
	top.location.href=adresse;
	window.focus();	
}

function cmsstyles()
{
	stylewindow=window.open('/cms/styles/styles.php', 'Formate', 'width=800, height=900, top=0, left=0, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
	window.stylewindow.focus();	
}

// Links abschalten
function cmslinksoff() 
{		
	newget = getAdd('linksoff','true','');
	adresse = getWrite(newget);
		
	window.location.href=adresse;
	window.focus();
}

function cmssicherung(befehl) 
{				
	content = contentnr;
		
	newget = getAdd('history',content,'');
	newget = getAdd('historychg', befehl, newget);
	adresse = getWrite(newget);

	window.location.href=adresse;
	window.focus();
}

function cmsbackup() 
{	
	newget = getAdd('cmsbackup','backup','');
	adresse = getWrite(newget);

	window.location.href=adresse;
	window.focus();
}

function cmsclass(befehl) 
{
	if (divclickstop && divobjname) 
	{		
		// weitere Befehle
		if (befehl == 'delete') 
		{
			if (window.confirm('Möchten Sie das ausgewählte Element löschen?') == true)
			{ 				
				newget = getAdd('cmscontent',CmsContent,'');
				newget = getAdd('cmstyp', CmsTyp, newget);
				newget = getAdd('cmsstart', CmsStart, newget);
				newget = getAdd('cmsstop', CmsStop, newget);
				newget = getAdd('befehl', 'delete', newget);
				adresse = getWrite(newget);
				window.location.href=adresse;
			} 
		}
		else if (befehl == 'down' || befehl == 'up' || befehl == 'shiftup' || befehl == 'shiftdown' ) 
		{		
				newget = getAdd('cmscontent',CmsContent,'');
				newget = getAdd('cmsstart', CmsStart, newget);
				newget = getAdd('cmsstop', CmsStop, newget);
				newget = getAdd('befehl', befehl, newget);
				adresse = getWrite(newget);				
				window.location.href=adresse;
		}			
		else if (befehl == 'change') 
		{		
			//buttonsoff();	
		cmswindow=window.open('/cms/scripts/cms_modulclassedit.php?cont='+CmsCont+'&cmscontent='+CmsContent+'&cmstyp='+CmsTyp+'&cmsstart='+CmsStart+'&cmsstop='+CmsStop+'&befehl=change', 'Class', 'width=600, height=700, top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');	
		}			
	}
}

function ElementMove(befehl) 
{	
	if (befehl == 'down' || befehl == 'up' || befehl == 'shiftup' || befehl == 'shiftdown') 
	{		
		newget = getAdd('cmscontent',CmsContent,'');
		newget = getAdd('cmsstart', CmsStart, newget);
		newget = getAdd('cmsstop', CmsStop, newget);
		newget = getAdd('befehl', befehl, newget);
		adresse = getWrite(newget);
		window.location.href=adresse;
	}			
}

function NewContent(befehl) 
{	
	if (befehl == 'newcontent') 
	{		
		if (window.confirm('Soll einer neuer Content eingefügt werden?') == true) 
		{
			newget = getAdd('cmspage',CmsPage,'');
			newget = getAdd('befehl', befehl, newget);
			adresse = getWrite(newget);
			window.location.href=adresse;
		}
	}			
}

function DelContent(befehl) 
{	
	if (contentnr && befehl == 'delcontent' ) 
	{		
		if (window.confirm('Soll dieser Content gelöscht werden?') == true) 
		{
			newget = getAdd('cmscontent',contentnr,'');
			newget = getAdd('befehl', befehl, newget);
			adresse = getWrite(newget);
			window.location.href=adresse;
		}
	}			
}

function ViewContent(befehl) 
{	
	if (contentnr && befehl == 'viewcontent' ) 
	{		
		newget = getAdd('cmscontent',contentnr,'');
		newget = getAdd('befehl', befehl, newget);
		adresse = '/cms/scripts/viewcontent.php'+newget;
		contentwindow=window.open(adresse, 'Contentwindow', 'width=750, height=700, top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
		contentwindow.focus();
	}			
}

function ElementMoveOn(cmscontent, cmsstart, cmsstop) 
{	
	CmsContent = cmscontent;
	CmsStart = cmsstart;
	CmsStop = cmsstop;
				
	// Elementbearbeitung ein
	parent.leftframe.document.getElementById("but-element").style.display= 'none';
	parent.leftframe.document.getElementById("but-elementmove").style.display= 'block';
	parent.leftframe.document.getElementById("but-elementdelmove").style.display= 'none';
}

function ElementMoveOff() 
{	
		parent.leftframe.document.getElementById("but-element").style.display= 'none';
		parent.leftframe.document.getElementById("but-elementmove").style.display= 'none';
		parent.leftframe.document.getElementById("but-elementdelmove").style.display= 'none';
}



// Auswertung CMS-Befehle
function cmsbefehl(befehl) 
{
	if (divclickstop && divobjname) 
	{		
		if (!clickstop && CmsEditor) 
		{
			if (CmsEditor != 'cms_editor_window.php')
			{
				// anderer Editor
				querystring = '/cms/scripts/'+CmsEditor+'?cont='+CmsCont+'&cmscontent='+CmsContent+'&cmstyp='+CmsTyp+'&cmsstart='+CmsStart+'&cmsstop='+CmsStop+'&befehl=direkt';											
				cmswindow=window.open(querystring, 'CMS', 'width=750, height=700, top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
				cmswindow.focus();
				clickstop =1;
				buttonsoff();					
			}			
			else if (befehl == 'open') 
			{
				// Editor im gleichen Fenster
				querystring = '?cont='+CmsCont+'&cmscontent='+CmsContent+'&cmstyp='+CmsTyp+'&cmsstart='+CmsStart+'&cmsstop='+CmsStop;									
				adresse = getWrite(querystring);	
				clickstop =1;
				buttonsoff();	
				window.location.href=adresse;
			}	
			else if (befehl == 'winopen')
			{
				// Editor im eigenen Fenster
				querystring = '/cms/scripts/cms_editor_window.php'+'?cont='+CmsCont+'&cmscontent='+CmsContent+'&cmstyp='+CmsTyp+'&cmsstart='+CmsStart+'&cmsstop='+CmsStop;											cmswindow=window.open(querystring, 'CMS', 'width=750, height=700, top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
				cmswindow.focus();
				clickstop =1;
				buttonsoff();	
			}
		} 
	}
}

function cmsreset() 
{
	if (window.confirm('Wenn Sie OK drücken verlieren Sie die Änderungen im aktuellen Editorfenster!') == true) 
	{
		newget = getAdd('reload','true','');
		adresse = getWrite(newget);

		window.location.href=adresse;
		window.focus();	
	}
}

// History-Buttons
//
function cmshistory(content, befehl) 
{		
	if (befehl == 'cancel') 
	{
		if (window.confirm('Möchten Sie alle Änderungen verwerfen?') == false)
			return
	}
	
	newget = getAdd('history',content,'');
	if (befehl)
		newget = getAdd('historychg',befehl,newget);
			
	adresse = getWrite(newget);
	window.location.href=adresse;
	window.focus();	
}


// Original zeigen
function cmshistorytop(befehl) 
{		
	if (!contentnr && befehl == 'orig')
		return;
		
	content = contentnr;
		
	newget = getAdd('history',content,'');
	if (befehl)
		newget = getAdd('historychg',befehl,newget);
	
	adresse = getWrite(newget);

	window.location.href=adresse;
	window.focus();	
}

// Content-Klick
//
// Doppelklick CMS-Editor
function cmsdblklick(objname, hoehe, breite) 
{
	if (!clickstop) 
	{
		
		// Divrahmen aus
		if (divclickstop) 
		{
			// backupcolors(objname); 
		}		
		
		// Elementbearbeitung aus
		parent.leftframe.document.getElementById("but-element").style.display= 'none';
		parent.leftframe.document.getElementById("but-elementmove").style.display= 'none';
		parent.leftframe.document.getElementById("but-elementdelmove").style.display= 'none';
		
		cmswindow=window.open(objname, 'CMS', 'width='+breite+', height='+hoehe+', top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
		cmswindow.focus();
		clickstop =1;
		buttonsoff();	
	}
}

// Doppelklick Editor ohne Window
function cmsdblnowin(content,vars)
{
	if (!clickstop) 
	{		
		// Elementbearbeitung aus
		ElementMoveOff();

		newget = getAdd('cont',content,'');
		newget = newget+vars;
		adresse = getWrite(newget);
		
		clickstop =1;
		buttonsoff();	
		window.location.href=adresse;
		window.focus();
	}	
}

// Doppelklick Direkt-Editor
function cmsdirekt(objname) 
{
	if (!clickstop) 
	{
		
		// Divrahmen aus
		if (divclickstop) 
		{
			backupcolors(objname); 
		}		
		cmswindow=window.open(objname+'&befehl=direkt', 'Direkteditor', 'width=600, height=500, top=30, left=60, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
		cmswindow.focus();
		clickstop =1;
		buttonsoff();	
	}
}

// Singleclick
function cmssingleklick(cid, cont, content, cmstyp, cmsstart, cmsstop, cmseditor) 
{

	if (!clickstop && !divclickstop) 
	{		
		backupcolors(cid); 
		savecolors(cid);
		document.getElementById(cid).style.backgroundColor='#DDEFDE'; 
		document.getElementById(cid).style.borderTop ="solid red 3px";
		document.getElementById(cid).style.borderBottom ="solid red 3px";
				
		divclickstop = cid;

		if (cmseditor)
		{
			// Elementbearbeitung ein
			parent.leftframe.document.getElementById("but-element").style.display= 'block';
			parent.leftframe.document.getElementById("but-elementmove").style.display= 'none';
			parent.leftframe.document.getElementById("but-elementdelmove").style.display= 'none';
		}
		else
		{
			// Container
			parent.leftframe.document.getElementById("but-element").style.display= 'none';
			parent.leftframe.document.getElementById("but-elementmove").style.display= 'none';
			parent.leftframe.document.getElementById("but-elementdelmove").style.display= 'block';
		}


		divobjname = true;
		CmsCont = cont;
		CmsContent = content;
		CmsTyp = cmstyp;
		CmsStart = cmsstart;
		CmsStop = cmsstop;
		CmsEditor = cmseditor;
	} 
	else if (divclickstop == cid)
	{		
		backupcolors(cid); 
		divclickstop =0;

		// Elementbearbeitung aus
		ElementMoveOff();
		
		divobjname = '';
		CmsCont = '';
		CmsContent = '';
		CmsTyp = '';
		CmsStart = '';
		CmsStop = '';
		CmsEditor = '';
		textclickstop =1;	
	}
}

// Textcontentclick
function cmscontklick(cid, content) 
{
	if (textclickstop) 
	{
		textclickstop = 0;
		return;
	}
	
	if (!clickstop && !divclickstop) 
	{
		savecolors(cid);
		document.getElementById(cid).style.borderTop ="solid red 3px";
		document.getElementById(cid).style.borderBottom ="solid red 3px";
				
		contentnr = content;
		if (contentnr.substring(0, 3) == 'new') 
		{
			parent.navigation.document.getElementById("but-orig").disabled = false;
		} 
		else 
		{
			parent.navigation.document.getElementById("but-sicherung").disabled = false;
		}
		divobjname = '';
		divclickstop = cid;	
		
		parent.leftframe.document.getElementById("but-content").style.display= 'block';		
	} 
	else if (divclickstop == cid) 
	{		
		backupcolors(cid); 
		divclickstop =0;
		contentnr = '';
		parent.navigation.document.getElementById("but-sicherung").disabled = true;
		parent.navigation.document.getElementById("but-orig").disabled = true;	
		parent.leftframe.document.getElementById("but-content").style.display= 'none';		
	}
}

// Datenbank Doppelklick
function dbedit(objname) 
{
		cmswindow=window.open(objname, 'CMS', 'width=750, height=700, top=30, left=30, menubar=0, resizable=1, toolbar=0,location=0,directories=0,scrollbars=yes');
		cmswindow.focus();
		clickstop =1;
}

// Mouse-Funktionen
//
function cmstextover(objname, farbe) 
{
	if (!mousestop) 
	{
		 document.getElementById(objname).style.backgroundColor=farbe; 
	}
}

function cmstextout(objname) {
 document.getElementById(objname).style.backgroundColor="transparent"; 
}

// Mouseover DIV
function cmsdivover(objname, farbe, farbe2) 
{
	mousestop	= 1;


	if (!divclickstop) 
	{
		if (farbwechsel)
			farbwechsel = false;
		else
			farbwechsel = true;
		if (farbwechsel)
			farbe = farbe2;
		
		setdivover(objname, farbe);
	}
}

// Mouseout DIV
function cmsdivout(objname) 
{
	mousestop = 0;

	if (!divclickstop) 
	{
		backupcolors(objname);	
	}				
}


// Farbwechsel
//
function getStyle(el)
{
	var Farbe;
	if(window.getComputedStyle)
 	  Farbe=window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("background-color");
	else if(document.getElementById(el).currentStyle)
   	Farbe=document.getElementById(el).currentStyle.backgroundColor; 
	else if(document.ids)
  	 Farbe= document.layers[el].bgColor;
	else if(document.all)
  	  Farbe=document.all.el.style.backgroundColor;
 	return Farbe;
}

function getTopBorder(el)
{
	var Farbe;
	if(window.getComputedStyle)
 	  Farbe=window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Top-Style")+' '+window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Top-Color")+' '+window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Top-Width");
	else if(document.getElementById(el).currentStyle)
   	Farbe=document.getElementById(el).currentStyle.borderTopStyle+' '+document.getElementById(el).currentStyle.borderTopWidth+' '+document.getElementById(el).currentStyle.borderTopColor+' '; 
// else if(document.ids)
//   Farbe= document.layers[el].bgColor;
// else if(document.all)
//    Farbe=document.all.el.style.border;
 	return Farbe;
}

function getBottomBorder(el)
{
	var Farbe;
	if(window.getComputedStyle)
 	  Farbe=window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Bottom-Style")+' '+window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Bottom-Color")+' '+window.getComputedStyle(document.getElementById(el),"" ).getPropertyValue("border-Bottom-Width");
	else if(document.getElementById(el).currentStyle)
 	  Farbe=document.getElementById(el).currentStyle.borderBottomStyle+' '+document.getElementById(el).currentStyle.borderBottomWidth+' '+document.getElementById(el).currentStyle.borderBottomColor+' '; 
// else if(document.ids)
//   Farbe= document.layers[el].bgColor;
// else if(document.all)
//    Farbe=document.all.el.style.border;
 	return Farbe;
}

function setStyle(el,Farbe)
{
	if(document.getElementById)
  	document.getElementById(el).style.backgroundColor=Farbe;
	else if(document.ids)
  	document.layers[el].bgColor=Farbe;
	else if(document.all)
  	document.all[el].style.backgroundColor=Farbe;
}

// Farbwechsel DIVs
function setdivover(objname, farbe) 
{
	savecolors(objname); 
	document.getElementById(objname).style.backgroundColor=farbe; 
	document.getElementById(objname).style.borderTop ="dotted red 1px";
	document.getElementById(objname).style.borderBottom ="dotted red 1px";
}

// Farben speichern
function savecolors(objname) 
{
	// alte Werte speichern		
	bg_old[objname] = getStyle(objname);
	bordertop_old[objname] = getTopBorder(objname);
	borderbottom_old[objname] = getBottomBorder(objname);
}

// alte Werte zurück
function backupcolors(objname) 
{
	if (bg_old[objname])
		setStyle(objname,bg_old[objname]);
	else
		document.getElementById(objname).style.backgroundColor="transparent"; 
			
	if (bordertop_old[objname])
		document.getElementById(objname).style.borderTop = bordertop_old[objname];
	else
		document.getElementById(objname).style.borderTop ="none";
		
	if (borderbottom_old[objname])
		document.getElementById(objname).style.borderBottom = borderbottom_old[objname];
	else
		document.getElementById(objname).style.borderBottom ="none";	
}


// alle Buttons aus
function buttonsoff() 
{
	parent.navigation.document.getElementById("but-orig").disabled = true;
	parent.navigation.document.getElementById("but-chg").disabled = true;
	parent.navigation.document.getElementById("but-sicherung").disabled = true;
	parent.navigation.document.getElementById("but-lsicherung").disabled = true;
	parent.navigation.document.getElementById("but-menu").disabled = true;
	parent.navigation.document.getElementById("but-linksoff").disabled = true;
	parent.leftframe.document.getElementById("but-direkt").style.display= 'none';
	parent.leftframe.document.getElementById("but-content").style.display= 'none';
	parent.navigation.document.getElementById("NaviButtonsLeft").style.display= 'none';
	parent.navigation.document.getElementById("NaviButtonsRight").style.display= 'none';
	parent.navigation.document.getElementById("NaviButtonsExtra").style.display= 'none';
}

// Standard Buttons an
function buttonson() 
{
	parent.navigation.document.getElementById("but-menu").disabled = false;
	parent.navigation.document.getElementById("but-linksoff").disabled = false;
	top.leftframe.document.getElementById("but-direkt").style.display= 'block';
	top.leftframe.document.getElementById("but-content").style.display= 'none';		
	parent.navigation.document.getElementById("NaviButtonsLeft").style.display= 'block';
	parent.navigation.document.getElementById("NaviButtonsRight").style.display= 'block';
	parent.navigation.document.getElementById("NaviButtonsExtra").style.display= 'block';
}

