//////////////////////////////////////////////////////////////////////
// Initialisieren der globalen Objekte...
var oCurrentRange;
var oCurrentRangeType	= "None";
var oTable						= null;
var oTr								= null;
var oTd								= null;
var oTable2						= null;
var oTr2							= null;
var oTd2							= null;
var oImg							= null;
var oImg2							= null;
var oAhref						= null;
var reqEditorFormat;

// Initialisieren der globalen Integer...
var vUndoPos					= 0; //Position des undo
var vLayoutID					= 0;
var vBrowser					= 0;
var sLayoutStyle			= "";

// Inistialisieren der gloablen Booleans...
var bBackupFlag				= false;

// Initialisieren der gloablen Strings...
var sStartSelection		= "";
var sEndSelection			= "";
var sCurrentSelection	= "";
var sComboPath				= "";

// Initialisieren der globalen Arrays...
var aBackup						= new Array(); // Hier werden die undos gespeichert
var aParentNodes			= new Array();
var aToggledButtons		= new Array();
var aButtonNames			= new Array("bold", "italic", "underline", "strikethrough", "superscript", "subscript");
var aTagNames					= new Array("B", "I", "U", "STRIKE", "SUP", "SUB");
var aAlterTagNames		= new Array("STRONG", "EM", "U", "STRIKE", "SUP", "SUB");

//////////////////////////////////////////////////////////////////////
// Systemfunktionen...
function HPW_EditorGetSize(sEditorID, vLoadingDone)
{
	// Editorgröße berechnen...
	var oSize = new Object();
	if (document.getElementById(sEditorID) && (vLoadingDone == 1))
	{
		oSize.y = parseInt(document.getElementById(sEditorID).style.height);
		oSize.x = parseInt(document.getElementById(sEditorID).style.width);
	}
	else
	{
		oSize.y = parseInt(document.getElementById(sEditorID+"_container").style.height);
		oSize.x = parseInt(document.getElementById(sEditorID+"_container").style.width);
	}
	return oSize;
}

// Formatieren des Inhaltes...
function HPW_EditorFormating(sEditorID, bFocus)
{
	var sTemp = "";
	var myframe = null;

	// Auslesen und wechseln der Hidden-Infos...
	var vLoadingDone = parseInt(document.getElementById(sEditorID+"_LoadingIsDone").value);
	var vShowHTML = parseInt(document.getElementById(sEditorID+"_ShowHTML").value);
	if (vShowHTML == 1) {vShowHTML = 0;	document.getElementById(sEditorID+"_ShowHTML").value = 0;}
	else {vShowHTML = 1; document.getElementById(sEditorID+"_ShowHTML").value = 1;}

	// Editorgröße berechnen...
	var vHeight = 0;
	var vWidth = 0;
	var oSize = HPW_EditorGetSize(sEditorID, vLoadingDone);
	vHeight = oSize.y;
	vWidth = oSize.x;

	var sGetText = "";
	if (vLoadingDone == 1)
	{
		if (vShowHTML == 1)
		{
			if (myframe == null) {myframe = HPW_GetIFrameDocument(sEditorID);}
			sGetText = myframe.getElementById(sEditorID+"_content").innerHTML;
		}
		else {sGetText = document.getElementById(sEditorID).value;}
	}
	else {sGetText = document.getElementById(sEditorID+"_TextMode").value;}

	// Waitscreen anzeigen...
	/*document.getElementById(sEditorID+"_LoadingIsDone").value = 0;
	var sWaitscreen = "";
	sWaitscreen += "<table style=\"width:"+vWidth+"px; height:"+vHeight+"px; background-color:#EEEEEE; border:solid 1px #000000;\">";
	sWaitscreen += "<tr>";
		sWaitscreen += "<td align=\"center\" valign=\"center\"><img src=\""+sComboPath+"img/loading.gif\" border=\"0\"> Loading...</td>";
	sWaitscreen += "</tr>";
	sWaitscreen += "</table>";
	document.getElementById(sEditorID+"_container").innerHTML = sWaitscreen;
	document.getElementById(sEditorID+"_HTMLToolbar").style.display = "none";
	if (document.getElementById(sEditorID+"_WYSIWYGToolbar")) {document.getElementById(sEditorID+"_WYSIWYGToolbar").style.display = "none";}
	document.getElementById(sEditorID+"_Loading_Toolbar").style.display = "inline";*/

	HPW_CreateEditor(vWidth, vHeight, sEditorID, vShowHTML, sGetText, sLayoutStyle, bFocus);

	document.getElementById(sEditorID+"_LoadingIsDone").value = 1;
	document.getElementById(sEditorID+"_Loading_Toolbar").style.display = "none";
}

// Rückgabe des contentDocument vom IFrame...
function HPW_GetIFrameDocument(sEditorID)
{
	if (document.getElementById(sEditorID))
	{
		// Existiert das IFrame contentDocument, dann gebe es für W3C compatible Browser zurück (z.B. Mozilla)...
		if (document.getElementById(sEditorID).contentDocument) {return document.getElementById(sEditorID).contentDocument;}
		else
		{
			if (document.frames[sEditorID].contentWindow) {return document.frames[sEditorID].contentWindow.document;}
			else {return document.frames[sEditorID].document;}
		} // Gebe IFrame contentDocument-Alternative für IE zurück
	}
}

// Erstellen des Editors...
function HPW_CreateEditor(vWidth, vHeight, sEditorID, vHTMLMode, sHTML, sStyle, bFocus)
{
	if (vHTMLMode == 1)
	{
		var myContainer = document.getElementById(sEditorID+"_container");
		var sContainerText = "<textarea name=\""+sEditorID+"\" id=\""+sEditorID+"\" ";
		sContainerText += "style=\"width:"+vWidth+"px; height:"+(vHeight-5)+"px; border:solid 1px #000000;\">"+sHTML+"</textarea>";
		myContainer.innerHTML = sContainerText;
		document.getElementById(sEditorID+"_HTMLToolbar").style.display = "inline";
		document.getElementById(sEditorID+"_TagBar").style.display = "none";
		document.getElementById(sEditorID+"_Smilies").style.display = "none";
		// if (bFocus == true) {setTimeout("document.getElementById('"+sEditorID+"').focus();", 100);}
		if (bFocus == true) {document.getElementById(sEditorID).focus();}
	}
	else
	{
		// Editor erstellen...
		var myContainer = document.getElementById(sEditorID+"_container");
		var sContainerText = "<iframe name=\""+sEditorID+"\" id=\""+sEditorID+"\" ";
		sContainerText += "style=\"width:"+vWidth+"px; height:"+(vHeight+5)+"px; border:solid 1px #000000;\"></iframe>";
		myContainer.innerHTML = sContainerText;
		
		// Editor editierbar schalten...
		var myframe = HPW_GetIFrameDocument(sEditorID);
		if (myframe.contentEditable) {myframe.contentEditable = true;} else {myframe.designMode = "on";}
		
		// Editor füllen...
		myframe.open();
		myframe.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		myframe.write("<html>");
		myframe.write("<head>");
		myframe.write("<title>Editor</title>");
		myframe.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
		myframe.write("<style type=\"text/css\">");
		myframe.write("td {border:dashed 1px #cccccc;}");
		myframe.write("td.combodatensatz {border:solid 1px #ff0000;}");
		myframe.write("</style>");
		myframe.write("<link rel=\"stylesheet\" type=\"text/css\" href=\""+sComboPath+"css/Style"+vLayoutID+"Main.css\">");
		myframe.write("</head>");
		myframe.write("<body style=\"width:100%; height:100%; margin:0px;\" ");
		myframe.write("id=\""+sEditorID+"_content\" name=\""+sEditorID+"_content\" class=\"cells\" style=\""+sStyle+"\">");
		myframe.write(sHTML);
		myframe.write("</body>");
		myframe.write("</html>");
		myframe.close();
		
		HPW_OnEvents(sEditorID);

		// document.getElementById(sEditorID+"_WYSIWYGToolbar").style.display = "inline";
		document.getElementById(sEditorID+"_TagBar").style.display = "inline";
		document.getElementById(sEditorID+"_Smilies").style.display = "inline";
		if (bFocus == true) {myframe.getElementById(sEditorID+"_content").focus();}
	}
}

// Wechseln zwischen HTML- und WYSIWYG-Modus...
function HPW_ChangeToHTMLMode(sEditorID)
{
	if (document.getElementById(sEditorID+"_LoadingIsDone"))
	{
		if (document.getElementById(sEditorID+"_LoadingIsDone").value == 1)
		{
			HPW_EditorFormating(sEditorID, false);
			HPW_EditorToolbarRequest(sEditorID, sComboPath+"lib/editor/change_mode.php", "");
		} // is loading done?
	}
}

// Globale Variablen festlegen...
function HPW_InitEditorGlobals(vBrowser2, sComboPath2, vLayoutID2)
{
	// if (vBrowser2 == 3) {vBrowser2 = 5;} // Lass Opera wie den IE benutzen
	// alert(vBrowser2);
	vBrowser = vBrowser2;
	sComboPath = sComboPath2;
	vLayoutID = vLayoutID2;
}

function HPW_InitEditorAddStyle(sStyle) {sLayoutStyle = sStyle;}

function HPW_OnEvents(sEditorID)
{
	var myframe = HPW_GetIFrameDocument(sEditorID);
	if (window.captureEvents)
	{
		window.captureEvents(Event.KEYDOWN);
		window.captureEvents(Event.KEYPRESS);
		// window.onkeydown			= HPW_DispatchKeycode;
		window.onkeypress			= new Function("HPW_HandleKeys('"+sEditorID+"');");
		// window.onmouseup			= new Function("HPW_SetRange('"+sEditorID+"');");
		// window.onkeyup				= new Function("HPW_SetRange('"+sEditorID+"');");
		// window.oncontextmenu	= new Function("HPW_ToggleContext('"+sEditorID+"'); return false;");
	}
	else
	{
		// myframe.onkeydown			= HPW_DispatchKeycode;
		myframe.onkeypress		= new Function("HPW_HandleKeys('"+sEditorID+"');");
	}
	
	myframe.onmouseup			= new Function("HPW_SetRange('"+sEditorID+"');");
	myframe.onkeyup				= new Function("HPW_SetRange('"+sEditorID+"');");
	myframe.oncontextmenu	= new Function("HPW_ToggleContext('"+sEditorID+"'); return false;");
//	myframe.images.onFocus = new Function("HPW_OnElementSelect(this);");
	// myframe.onkeyup = new Function("HPW_HandleKeys('"+sEditorID+"',"+vBrowser+",'"+sComboPath+"');");
	// myframe.onkeydown			= new Function("HPW_DispatchKeyControl('"+sEditorID+"');");
	// document.onkeydown		= new Function("HPW_DispatchKeyControl2();");
	// myframe.ondoubleclick = new Function("HPW_SetRange('"+sEditorID+"',"+vBrowser+",'"+sComboPath+"');");
	// myframe.onclick = new Function("HPW_SetRange('"+sEditorID+"',"+vBrowser+",'"+sComboPath+"');");
}

function HPW_DispatchKeycode(e)
{
	var keyCode = (e)? e.which : event.keyCode;
	if (keyCode == 13) {alert("ENTER gedrückt!");}
/*
	var e = e || window.event;
	if (window.captureEvents) {var taste = e.which;}
	else {var taste = e.keyCode;}
	
	if (taste == 38 OR taste == 40)
	{         //HIER HAB ICH WAS ANGEPASST
		if(e.preventDefault) {e.preventDefault();}
		else {e.returnValue = false;}
	}
	*/
}

// Initialisiert den Editor...
function HPW_InitEditor(vWidth, vHeight, sEditorID, bFocus) {HPW_EditorFormating(sEditorID, bFocus);}

// Vorgegebene Editiercommandos vom Browser...
function HPW_DoRichEditCommand(sEditorID, sCommand, sExpression)
{
	var myframe = HPW_GetIFrameDocument(sEditorID);
	document.getElementById(sEditorID).contentWindow.focus();
	myframe.execCommand(sCommand, false, sExpression);
}

function HPW_ToggleActiveButtons(sEditorID, sNewName)
{
	for (var i=0; i<aTagNames.length; i++)
	{
		if ((sNewName == aTagNames[i]) || (sNewName == aAlterTagNames[i]))
		{
			document.getElementById(sEditorID+"_"+aButtonNames[i]+"Selected").value = 1;
			document.getElementById(sEditorID+"_"+aButtonNames[i]+"image").src = sComboPath+"img/editor/"+aButtonNames[i]+"3.gif";
		}
	}
}

function HPW_HighlightToolButtons(sEditorID, sKey)
{
	var sNewPic = sComboPath+"img/editor/"+sKey;
	if (parseInt(document.getElementById(sEditorID+"_"+sKey+"Selected").value) == 1) {sNewPic += "3.gif";} else {sNewPic += ".gif";}
	document.getElementById(sEditorID+"_"+sKey+"image").src = sNewPic;
}

// Setze die Range der Markierung...
function HPW_SetRange(sEditorID)
{
	// ContextMenü ausblenden...
	document.getElementById(sEditorID+"_ContextMenu").style.visibility = "hidden";

	// Sind wir im HTML Modus?...
	if (!document.getElementById(sEditorID+"_ShowHTML")) {var vIsHtml = 1;}
	else {var vIsHtml = document.getElementById(sEditorID+"_ShowHTML").value;}

	// Wenn im HTML Modus, dann wähle WYSIWYG Editor Document...
	if (vIsHtml == 1)
	{
		if (vBrowser == 5)
		{
			var mydocument = document;
			mydocument.getElementById(sEditorID).focus();
		}
		else
		{
			var mydocument = document.getElementById(sEditorID);
			mydocument.focus();
		}
	}
	else
	{
		if (vBrowser == 5) {mydocument = HPW_GetIFrameDocument(sEditorID); mydocument.getElementById(sEditorID+"_content").focus();}
		else {mydocument = HPW_GetIFrameDocument(sEditorID);}
	}
	
	// Internet Explorer...
	if (vBrowser == 5)
	{
		if (vIsHtml == 1)
		{
			oCurrentRange = mydocument.selection.createTextRange();
			oCurrentRangeType = mydocument.selection.type;
		}
		else
		{
			oCurrentRange = mydocument.selection.createRange();
			oCurrentRangeType = mydocument.selection.type;
		}
	}
	else //if (vBrowser != 5) // Gecko, Mozilla und co...
	{
		if (vIsHtml == 1)
		{
			sStartSelection = mydocument.selectionStart;
			sEndSelection = mydocument.selectionEnd;
			sCurrentSelection = mydocument.value.substring(start, end);
		}
		else
		{
			oCurrentRange = mydocument.getSelection();
		}
	}
	HPW_FindTags(sEditorID);
}

function HPW_FindTags(sEditorID)
{
	// TODO: Prüfe beim markieren, welche Eigenschaften aktiv sind...
/*	if (oCurrentRangeType != 'Control')
	{
		var tmpRange = mydocument.selection.createRange();
		var parentElement = tmpRange.parentElement().tagName;
		tmpRange.moveStart("character", -1);
		var parentElement2 = tmpRange.parentElement().tagName;
		if ((parentElement != "STRONG") && (parentElement2 != "STRONG")
		&& (parentElement != "EM")		&& (parentElement2 != "EM")
		&& (parentElement != "I")		&& (parentElement2 != "I")
		&& (parentElement != "U")		&& (parentElement2 != "U")
		&& (parentElement != "SUP")	&& (parentElement2 != "SUP")
		&& (parentElement != "SUB")	&& (parentElement2 != "SUB"))
		{
			for (var i=0; i<aTagNames.length; i++)
			{
				document.getElementById(sEditorID+"_"+aButtonNames[i]+"Selected").value = 0;
				document.getElementById(sEditorID+"_"+aButtonNames[i]+"image").src = sComboPath+"img/editor/"+aButtonNames[i]+".gif";
			}
		} // for aTagNames.length
	}*/

	// Hole die Nodes (Tags), die Editiert werden dürfen...
	HPW_GetParentNodes(sEditorID);
	
	// Zeige Tags am unteren Editorrand...
	var sNewLink = "";
	for (var i=0; i<aTagNames.length; i++)
	{
		document.getElementById(sEditorID+"_"+aButtonNames[i]+"Selected").value = 0;
		document.getElementById(sEditorID+"_"+aButtonNames[i]+"image").src = sComboPath+"img/editor/"+aButtonNames[i]+".gif";
	}
	for (var i=aParentNodes.length-1; i>=0; i--)
	{
		sNewName = aParentNodes[i].tagName.toUpperCase();
		sNewColor = aParentNodes[i].color;
		sNewSize = aParentNodes[i].size;
		sNewLink += "<a href='javascript:;' target='_self'>&lt;"+sNewName;
		if (sNewColor) {sNewLink += " color='"+sNewColor+"'";}
		if (sNewSize) {sNewLink += " size='"+sNewSize+"'";}
		sNewLink += "&gt;</a> ";
		HPW_ToggleActiveButtons(sEditorID, sNewName);		
	}
	if (sNewLink != "") {document.getElementById(sEditorID+"_TagBar").innerHTML = sNewLink;}
}

// Setzt einen Tag um die Markierung...
function HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag)
{
	// Sind wir im HTML Modus?...
	if (!document.getElementById(sEditorID+"_ShowHTML")) {var vIsHtml = 1;}
	else {var vIsHtml = parseInt(document.getElementById(sEditorID+"_ShowHTML").value);}
	
	// Internet Explorer...
	if (vBrowser == 5)
	{
		// Tags einfügen...
		if (vIsHtml == 1) {oCurrentRange.text = sStartTag + oCurrentRange.text + sEndTag;}
		else
		{
			oCurrentRange.pasteHTML(sStartTag + oCurrentRange.htmlText + sEndTag);
		}
	}
	else // if (vBrowser != 5) // Gecko, Mozilla und co...
	{
		// Tags einfügen...
		if (vIsHtml == 1)
		{
			var mydocument = document.getElementById(sEditorID);
			var newText = mydocument.value.substr(0, sStartSelection) + sStartTag + sCurrentSelection + sEndTag + mydocument.value.substr(sEndSelection);
			mydocument.value = newText;
		}
		else
		{
			var mydocument = HPW_GetIFrameDocument(sEditorID);
			var newText = sStartTag + oCurrentRange + sEndTag;
			var myHTML = mydocument.getElementById(sEditorID+"_content");
			myHTML.innerHTML = myHTML.innerHTML.replace(oCurrentRange, newText);
		}
	}
}

/*
function HPW_GetCurrentNodes()
{
	// TODO!!!!!
	if (!oCurrentRange) {return;}
	var oTempElement = null;
	var aChildNodes = new Array();
	if (window.getSelection)				{oSelRange = window.getSelection();}
	else if (document.getSelection)	{oSelRange = document.getSelection();}
	else if (document.selection)		{oSelRange = document.selection.createRange();}
	var sSelType = document.selection.type; // Den Typ der Markierung herausfinden (TODO: Momentan nur IE!)
	// var oSelRange = document.selection.createRange();	// Die Range für die Markierung festlegen (TODO: Momentan nur IE!)
	// var oNode = (sSelType == "Control")?oSelRange(0):oSelRange.parentElement();
	
	// alert(sSelType);
	// alert(oSelRange.item(0)+" -> "+oSelRange.item(0).outerHTML);
	// oTempElement = oSelRange.selectNode("IMG");
	// alert(oTempElement);

	if (oNode)
	{
		oTempElement = oNode.getElementsByTagName("IMG");
		if (oTempElement[0])
		{
			for (var i=0; i<oTempElement.length; i++)
			{
				if (oTempElement[i] == true) {aChildNodes.push(oTempElement[i]);}
			}
		}
		// oTempElement = oNode.getElementsByTagName("A");			if (oTempElement[0]) {aChildNodes.push(oTempElement[0]);}
		return aChildNodes;
	}
	return;
}
*/
/*
function HPW_OnElementSelect(oCurrentElement)
{
	alert(oCurrentElement);
	if (oCurrentElement)
	{
		var sTagName = oCurrentElement.tagName.toUpperCase();
		if (sTagName == "IMG") {oImg = oCurrentElement;}
		if (sTagName == "A") {oAhref = oCurrentElement;}
	}
}
*/
// Hole nächte(n) Tag...
function HPW_GetParentNodes(sEditorID)
{
	if (!oCurrentRange) {return;}
	if (window.getSelection)				{oSelRange = window.getSelection();}
	else if (document.getSelection)	{oSelRange = document.getSelection();}
	else if (document.selection)		{oSelRange = document.selection.createRange();}
	var sSelType = document.selection.type; // Den Typ der Markierung herausfinden (TODO: Momentan nur IE!)
	// var oSelRange = document.selection.createRange();	// Die Range für die Markierung festlegen (TODO: Momentan nur IE!)
	var oNode = (sSelType == "Control")?oSelRange(0):oSelRange.parentElement();
	//var oNode = (sSelType == "Control")?oCurrentRange(0):oCurrentRange.parentElement();
	aParentNodes.length = 0;
	if ((!oNode) || (oNode.id == sEditorID+"_content")) {return;}
	while ((oNode) && (oNode.id != sEditorID+"_content"))
	{
		aParentNodes.push(oNode);
		oNode = oNode.parentElement;
	}
}

// Ist Markierung in einem bestimmten Tag?...
function HPW_InNode(sEditorID, sNodeType)
{
	sNodeType = sNodeType.toUpperCase(); // String in Großbuchstaben umwandeln
	var sSelType = document.selection.type; // Den Typ der Markierung herausfinden (TODO: Momentan nur IE!)
	var oSelRange = document.selection.createRange();		// Die Range für die Markierung festlegen (TODO: Momentan nur IE!)
	var oNode = (sSelType == "Control")?oSelRange(0):oSelRange.parentElement();
	//var oNode = (sSelType == "Control")?oCurrentRange(0):oCurrentRange.parentElement();
	parentNodes.length = 0;
	if ((!oNode) || (oNode.id == sEditorID+"_content")) {return;}
	while ((oNode) && (oNode.id != sEditorID+"_content"))
	{
		if (oNode.tagName.toUpperCase() == sNodeType) {return true;}
		oNode = oNode.parentElement;
	}
	return false;
}

// Überschreiben der Tastaturfunktionen für den WYSIWYG...
// TODO: Funktioniert noch nicht.
/*function HPW_DispatchKeyControl(sEditorID)
{
//	if (!oCurrentRange) {return;} // Abbrechen, wenn noch keine Markierung erfolgte
	if (document.getElementById(sEditorID+"_ShowHTML") != 1) // nicht im HTML Modus?
	{
		var mydocument = HPW_GetIFrameDocument(sEditorID);

		if (window.event.keyCode == 13 || window.event.keyCode == 32)
		{
			// elm.onchange = elm.oldonchange;
			// elm.onchange();
			// elm.oldonchange = null;
	
			mydocument.cancelEvent(window.event);
		}

		if ((oCurrentRange) && (window.event.keyCode == 13) && (!window.event.shiftKey)) // Wird Eingabetaste ohne Shift gedrückt?
		{
			if (!HPW_InNode(sEditorID, "LI")) // Markierung nicht in einer Liste?
			{
				oCurrentRange.pasteHTML("<br>"); // Füge einen normalen Zeilenumbruch in HTML ein
				window.event.returnValue = false; // ??? Verhindern der eigentlichen rückgabe durch druck auf die Taste
			}
		}
		
	}
	return false;
}
*/

function HPW_ChangeEditorHeight(sEditorID, vPixel, vMinHeight)
{
	vMinHeight = parseInt(vMinHeight);
	/*if (parseInt(document.getElementById(sEditorID+"_ShowHTML").value) == 1)
	{
		var vTemp = parseInt(document.getElementById(sEditorID+"_TextMode").style.height);
		vTemp += vPixel;
		if (vTemp >= vMinHeight) {document.getElementById(sEditorID+"_TextMode").style.height = vTemp+"px";}
	}
	else
	{*/
		var vTemp = 0;
		var vTemp2 = 0;
		//var vIsHtml = parseInt(document.getElementById(sEditorID+"_ShowHTML").value);
		//if (vIsHtml == 1) {vTemp2 = 5;}
		if (document.getElementById(sEditorID)) {vTemp = parseInt(document.getElementById(sEditorID).style.height);}
		else if (document.getElementById(sEditorID+"_container")) {vTemp = parseInt(document.getElementById(sEditorID+"_container").style.height);}
		else if (document.getElementById(sEditorID+"_TD")) {vTemp = parseInt(document.getElementById(sEditorID+"_TD").style.height);}
		vTemp += vPixel;
		if (vTemp >= vMinHeight)
		{
			if (document.getElementById(sEditorID)) {document.getElementById(sEditorID).style.height = vTemp+"px";}
			if (document.getElementById(sEditorID)+"_container") {document.getElementById(sEditorID+"_container").style.height = (vTemp+vTemp2)+"px";}
			if (document.getElementById(sEditorID)+"_TD") {document.getElementById(sEditorID+"_TD").style.height = vTemp+"px";}
		}
	//}
}

//////////////////////////////////////////////////////////////////////
// Backup...
// Events die einen Backup erzeugen...
function HPW_HandleKeys(sEditorID, evt)
{
	mydocument = document.frames[sEditorID];

	if (mydocument.event)
	{
		switch (mydocument.event.keyCode)
		{
			// Backspace...
			case 8: HPW_BackUp(sEditorID); break;

			// Eingabe- und Entertaste...
			case 13: HPW_BackUp(sEditorID); break;

			// Space-Taste...
			case 32: HPW_BackUp(sEditorID); break;

			// Ausrufezeichen-Taste...
			case 33: HPW_BackUp(sEditorID); break;

			// Pfeiltaste links...
			case 37: HPW_SetRange(sEditorID); break;

			// Pfeiltaste hoch...
			case 38: HPW_SetRange(sEditorID); break;

			// Pfeiltaste rechts...
			case 39: HPW_SetRange(sEditorID); break;

			// Pfeiltaste runter...
			case 40: HPW_SetRange(sEditorID); break;

			// delete bzw. entfernen...
			case 46: HPW_BackUp(sEditorID); break;
			
			// Punkt-Taste...
			case 190: HPW_BackUp(sEditorID); break;
			
			// Komma...
			case 188: HPW_BackUp(sEditorID); break;

			// Semikolon...
			case 186: HPW_BackUp(sEditorID); break;

			// Fragezeichen-Taste...
			case 63: HPW_BackUp(sEditorID); break;

			default: return; 
		}
	}
}

function HPW_BackUp(sEditorID)
{
	mydocument = HPW_GetIFrameDocument(sEditorID);

	if (bBackupFlag) // action if undo was clicked
	{
		var aRemoved = aBackup.splice(bBackupFlag, aBackup.length - bBackupFlag);
		for (var i = 0; i < aRemoved.length; i++)
		{
			delete aRemoved[i]; //delete obsolete array items
		}
		aBackup[aBackup.length] = mydocument.getElementById(sEditorID+"_content").innerHTML;
		vUndoPos = aBackup.length - 1;
		bBackupFlag = false;
		mydocument.getElementById(sEditorID+"_content").focus();
	}
	else
	{//write to backup array
		aBackup[aBackup.length] = mydocument.getElementById(sEditorID+"_content").innerHTML;
		vUndoPos = aBackup.length - 1; 
		bBackupFlag = false;
		mydocument.getElementById(sEditorID+"_content").focus();
	}
}

/*function HPW_LookBackup()
{// monitor our Array data
	var e = 'flag:'+bBackupFlag+'\r\nundo_pos:'+vUndoPos+'\r\n';
	e += 'aBackup.length:'+aBackup.length+'\r\n';
	for (i=0; i<aBackup.length; i++)
	{
		e+= 'Backup item '+i+':'+aBackup[i]+'\r\n';
	} 
	document.getElementById('bup_a').value = e;
}*/

function HPW_Undo(sEditorID)
{
	var mydocument = HPW_GetIFrameDocument(sEditorID);
	if (aBackup.length)
	{
		if (vUndoPos == 0) {mydocument.getElementById(sEditorID+"_content").focus(); return;} // Anfang der Backups?
		if (bBackupFlag == false) {HPW_BackUp(sEditorID);} // Mache ein Backup vom aktuellen Inhalt
		mydocument.getElementById(sEditorID+"_content").innerHTML = aBackup[vUndoPos - 1];
		vUndoPos = vUndoPos - 1;
		bBackupFlag = vUndoPos + 1;
		//HPW_LookBackup();
		mydocument.getElementById(sEditorID+"_content").focus();
	}
}

function HPW_Redo(sEditorID)
{
	var mydocument = HPW_GetIFrameDocument(sEditorID);

	if (vUndoPos == aBackup.length - 1) {mydocument.getElementById(sEditorID+"_content").focus(); return;} //end of backup array
	mydocument.getElementById(sEditorID+"_content").innerHTML = aBackup[vUndoPos + 1];
	vUndoPos = vUndoPos + 1;
	bBackupFlag = vUndoPos + 1;
	//HPW_LookBackup();
	mydocument.getElementById(sEditorID+"_content").focus();
}

//////////////////////////////////////////////////////////////////////
// Tabellenfunktionen...
// Zeile löschen...
function HPW_DeleteTableRow(sEditorID, oTr, oTable)
{
	HPW_BackUp(sEditorID);
	oTr.removeNode(true);
	if (!oTable.getElementsByTagName("TR").length) {oTable.removeNode(true);}
	oTable = oTr = oTd = null;
}

// Zeile hinzufügen...
function HPW_InsertTableRow(sEditorID, oTr, sLocation)
{
	HPW_BackUp(sEditorID);
	oNewTr = oTr.cloneNode(true);
	var oTds = oNewTr.getElementsByTagName("TD");
	/*for (var i = 0; i<oTds.length; ++i)
	{
		oTds[i].innerHTML = '&nbsp;';
	}*/
	oTr.insertAdjacentElement(sLocation, oNewTr);
	oTable = oTr = oTd = null;
}

// Spalte löschen...
function HPW_DeleteTableCol(sEditorID, oTd, oTable)
{
	HPW_BackUp(sEditorID);
	var pos;
	oTd = oTd.previousSibling;
	for (pos = 1; oTd; pos += oTd.colSpan, oTd = oTd.previousSibling);
	var oParent = oTable.getElementsByTagName("TR")[0];
	for (var oTr = oParent; oTr && oTr.tagName.toUpperCase() == "TR"; oTr = oTr.nextSibling)
	{
		var currentCol = 0;
		var oChild = oTr.getElementsByTagName("TD")[0];
		for (;oChild && oChild.tagName.toUpperCase() == "TD"; oChild = oChild.nextSibling)
		{
			currentCol += oChild.colSpan;
			if (currentCol >= pos)
			{
				if (oChild.colSpan > 1) {oChild.colSpan -= 1;}
				else {oChild.removeNode(true);}
				break;  
			}
		}
	}
	for (;oParent && oParent.tagName.toUpperCase() == "TR"; oParent = oParent.nextSibling)
	{
		var oTds = oParent.getElementsByTagName("TD");
		if (oTds.length == 0)
		{
			HPW_DeleteTableRow(oParent, oTable);
			--i;
		}
	}
	oTable = oTr = oTd = null;
}

// Spalte hinzufügen...
function HPW_InsertTableCol(sEditorID, oTd, oTable, sLocation)
{
	HPW_BackUp(sEditorID);
	var pos;
	var sOldBorder = oTd.style.border;
	if (sLocation == "left") {oTd = oTd.previousSibling;}
	for (pos = 1; oTd; pos += oTd.colSpan, oTd = oTd.previousSibling);
	var oTrs = oTable.getElementsByTagName("TR");
	for (var i = 0; i < oTrs.length; ++i)
	{
		var oTds = oTrs(i).getElementsByTagName("TD");
		var currentCol = 0;
		for (var j = 0; j < oTds.length; ++j)
		{
			currentCol += oTds(j).colSpan;
			if ((currentCol + 1) >= pos)
			{
				if ((oTds(j).colSpan > 1) && ((currentCol + 1) != pos)) {oTds(j).colSpan += 1;}
				else
				{
					var newTD = document.createElement("TD");
					if (pos == 1) {oTds(j).insertAdjacentElement('beforeBegin', newTD);}
					else {oTds(j).insertAdjacentElement('afterEnd', newTD);}
					newTD.style.border = sOldBorder;
					//newTD.innerHTML = "&nbsp;";
				}
				break;  
			}
		}
	}
	oTable = oTr = oTd = null;
}

// Zellen horizontal verschmelzen...
function HPW_MergeTableCellHorizontal(sEditorID, oTd, sDirection)
{
	HPW_BackUp(sEditorID);
	if (sDirection == 'left') {oTd = oTd.previousSibling;}
	oTd.innerHTML += oTd.nextSibling.innerHTML;
	oTd.colSpan += oTd.nextSibling.colSpan;
	oTd.nextSibling.removeNode(true);
	oTable = oTr = oTd = null;
}

// Zellen vertikal verschmelzen...
// var sTestColor = "#AA5555";
function HPW_MergeTableCellVertical(sEditorID, oTd, sDirection)
{
	HPW_BackUp(sEditorID);
	var pos, currentCol, ptrTD;
	var oTr = oTd.parentElement.nextSibling; // Hole ersten TR der Tabelle zu diesem TD
	
	// Suche die Zeile unter der untersten Zeile die zu dem aktiven TD gehört...
	for (var i = 1; i < oTd.rowSpan; i++) {oTr = oTr.nextSibling;}
	
	// Suche nach Colspans, die vor dem aktuellen TD existierten...
	for (pos = 0, ptrTD = oTd; ptrTD; pos += ptrTD.colSpan, ptrTD = ptrTD.previousSibling);

	var oTrNext = oTr;
	// var oTds = oTr.previousSibling.getElementsByTagName("TD"); // Hole die TDs im aktuellen TR
	var oTds = oTr.getElementsByTagName("TD"); // Hole die TDs im aktuellen TR
	var currentCol = 0;
	var vRowspanAnzahl = 0;
	for (var i = 0; i < oTds.length; ++i)
	{
		// oTds(i).style.backgroundColor = sTestColor; // "#AA5555";
		currentCol += oTds(i).colSpan;
		if (oTds(i).rowSpan > 1) {vRowspanAnzahl++;}
		// oTds(i).innerHTML = currentCol+" = "+pos;
		if (currentCol == pos)
		{
			oTd.rowSpan = oTd.rowSpan + oTds(i).rowSpan;
			oTrNext.getElementsByTagName("TD")[i-vRowspanAnzahl].removeNode(true);
			break;
		}
	}
	oTable = oTr = oTd = null;
	// if (sTestColor == "#AA5555") {sTestColor = "#55AA55";} else {sTestColor = "#AA5555";}
}

// Zelle löschen...
function HPW_DelTableCell(sEditorID, oTd, oTr)
{
	HPW_BackUp(sEditorID);
	if (oTr.getElementsByTagName("TD").length > 1) {oTd.removeNode(true);}
	oTable = oTr = oTd = null;
}

// Zelle Formatieren (Popup)...
function HPW_FormatTd(sEditorID, oTd)
{
	HPW_BackUp(sEditorID);
	oTd2 = oTd;
	oTr2 = oTr;
	oTable2 = oTable;
	
	var sUebergabe = "?sEditorID="+sEditorID;
	sUebergabe += "&sStyleWidth="+oTd2.style.width;
	sUebergabe += "&sStyleHeight="+oTd2.style.height;
	sUebergabe += "&sStyleAlign="+oTd2.style.textAlign;
	sUebergabe += "&sStyleValign="+oTd2.style.verticalAlign;

	// Rahmen...
	sUebergabe += "&sStyleBorderStyle="+oTd2.style.borderStyle;
	sUebergabe += "&sStyleBorderColor="+oTd2.style.borderColor.replace(/#/, "");
	sUebergabe += "&sStyleBorderWidth="+oTd2.style.borderWidth;

	// Hintergrund...
	sUebergabe += "&sStyleBgColor="+oTd2.style.backgroundColor.replace(/#/, "");
	sUebergabe += "&sStyleBgRepeat="+oTd2.style.backgroundRepeat;
	sUebergabe += "&sStyleBgPosition="+oTd2.style.backgroundPosition.replace(/\ /, "*");
	if ((oTd2.style.backgroundImage != "") && (oTd2.style.backgroundImage != "none")) {sUebergabe += "&sStyleBgImage="+oTd2.style.backgroundImage;}

	//HPW_ToggleContext(sEditorID);
	var hPopup = HPW_OpenManualPopup(sComboPath+"lib/editor/td.php"+sUebergabe,350,430,"TDFormatingWindow","no");
	hPopup.focus();
}

function HPW_FormatTd2(
					sAnwendenAuf, sStyleWidth, sStyleHeight, sStyleBgColor, sStyleAlign, sStyleValign,
					sStyleBorderStyle, sStyleBorderColor, sStyleBorderWidth,
					sStyleBgImage, sStyleBgRepeat, sStyleBgPositionX, sStyleBgPositionY
					)
{
	if (sAnwendenAuf == "cell")
	{
		// if (sStyleWidth == "nowidth")	{oTd2.style.removeAttribute("width", false);}
		if (sStyleWidth == "nowidth")	{oTd2.style.width = "";}
		else if (sStyleWidth != "")		{oTd2.style.width = sStyleWidth;}
		
		// if (sStyleHeight == "noheight")	{oTd2.style.removeAttribute("height", false);}
		if (sStyleHeight == "noheight")	{oTd2.style.height = "";}
		else if (sStyleHeight != "")		{oTd2.style.height = sStyleHeight;}
		
		// if (sStyleAlign == "noalign") {oTd2.style.removeAttribute("textAlign", false);}
		if (sStyleAlign == "noalign") {oTd2.style.textAlign = "";}
		else if (sStyleAlign != "")		{oTd2.style.textAlign = sStyleAlign;}
		
		// if (sStyleValign == "novalign")	{oTd2.style.removeAttribute("verticalAlign", false);}
		if (sStyleValign == "novalign")	{oTd2.style.verticalAlign = "";}
		else if (sStyleValign != "")		{oTd2.style.verticalAlign = sStyleValign;}

		// Rahmen...
		if (sStyleBorderStyle == "noborder")
		{
			oTd2.style.borderStyle = "";
			oTd2.style.borderColor = "";
			oTd2.style.borderWidth = "";
			// oTd2.style.removeAttribute("borderStyle", "false");
			// oTd2.style.removeAttribute("borderColor", "false");
			// oTd2.style.removeAttribute("borderWidth", "false");
		}
		else
		{
			if (sStyleBorderStyle != "") {oTd2.style.borderStyle = sStyleBorderStyle;}
			if (sStyleBorderColor != "") {oTd2.style.borderColor = "#"+sStyleBorderColor;} else {oTd2.style.borderColor = "";}
			if (sStyleBorderWidth != "") {oTd2.style.borderWidth = sStyleBorderWidth;}
		}

		// Hintergrund...
		// if (sStyleBgColor == "nocolor") {oTd2.style.removeAttribute("backgroundColor", false);}
		if (sStyleBgColor == "nocolor") {oTd2.style.backgroundColor = "";}
		else if (sStyleBgColor != "") {oTd2.style.backgroundColor = "#"+sStyleBgColor;}

		/*if (sStyleBgImage == "noimg")
		{
			oTd2.style.removeAttribute("backgroundImage", false);
			oTd2.style.removeAttribute("backgroundRepeat", false);
			oTd2.style.removeAttribute("backgroundPosition", false);
		}
		else
		{*/
			// if (sStyleBgImage == "noimg")	{oTd2.style.removeAttribute("backgroundImage", false);}
			if (sStyleBgImage == "noimg")	{oTd2.style.backgroundImage = "";}
			else if (sStyleBgImage != "") {oTd2.style.backgroundImage = "url("+sStyleBgImage+")";}
			
			// if (sStyleBgRepeat == "norepeating")	{oTd2.style.removeAttribute("backgroundRepeat", false);}
			if (sStyleBgRepeat == "norepeating")	{oTd2.style.backgroundRepeat = "";}
			else if (sStyleBgRepeat != "")				{oTd2.style.backgroundRepeat = sStyleBgRepeat;}
			
			if ((sStyleBgPositionX == "noalign") || (sStyleBgPositionY == "novalign"))
			{
				// oTd2.style.removeAttribute("backgroundPosition", false);
				oTd2.style.backgroundPosition = "";
			}
			else if ((sStyleBgPositionX != "") && (sStyleBgPositionY != ""))
			{
				oTd2.style.backgroundPosition = sStyleBgPositionX+" "+sStyleBgPositionY;
			}
		// }
	}
	else if (sAnwendenAuf == "row") {var oTds = oTr2.getElementsByTagName("TD");}
	else if (sAnwendenAuf == "table") {var oTds = oTable2.getElementsByTagName("TD");}
	
	if ((sAnwendenAuf == "row") || (sAnwendenAuf == "table"))
	{
		for (var i=0; i<oTds.length; i++)
		{
			// if (sStyleWidth == "nowidth")	{oTds(i).style.removeAttribute("width", false);}
			if (sStyleWidth == "nowidth")	{oTds(i).style.width = "";}
			else if (sStyleWidth != "")		{oTds(i).style.width = sStyleWidth;}
			
			// if (sStyleHeight == "noheight")	{oTds(i).style.removeAttribute("height", false);}
			if (sStyleHeight == "noheight")	{oTds(i).style.height = "";}
			else if (sStyleHeight != "")		{oTds(i).style.height = sStyleHeight;}

			// if (sStyleAlign == "noalign") {oTds(i).style.removeAttribute("textAlign", false);}
			if (sStyleAlign == "noalign") {oTds(i).style.textAlign = "";}
			else if (sStyleAlign != "")		{oTds(i).style.textAlign = sStyleAlign;}
			
			// if (sStyleValign == "novalign")	{oTds(i).style.removeAttribute("verticalAlign", false);}
			if (sStyleValign == "novalign")	{oTds(i).style.verticalAlign = "";}
			else if (sStyleValign != "")		{oTds(i).style.verticalAlign = sStyleValign;}
	
			// Rahmen...
			if (sStyleBorderStyle == "noborder")
			{
				// oTds(i).style.removeAttribute("borderStyle", false);
				// oTds(i).style.removeAttribute("borderColor", false);
				// oTds(i).style.removeAttribute("borderWidth", false);
				oTds(i).style.borderStyle = "";
				oTds(i).style.borderColor = "";
				oTds(i).style.borderWidth = "";
			}
			else
			{
				if (sStyleBorderStyle != "") {oTds(i).style.borderStyle = sStyleBorderStyle;}
				if (sStyleBorderWidth != "") {oTds(i).style.borderWidth = sStyleBorderWidth;}
				if (sStyleBorderColor != "") {oTds(i).style.borderColor = "#"+sStyleBorderColor;} else {oTds(i).style.borderColor = "";}
			}
	
			// Hintergrund...
			// if (sStyleBgColor == "nocolor") {oTds(i).style.removeAttribute("backgroundColor", false);}
			if (sStyleBgColor == "nocolor") {oTds(i).style.backgroundColor = "";}
			else if (sStyleBgColor != "") {oTds(i).style.backgroundColor = "#"+sStyleBgColor;}
			
			/*
			if (sStyleBgImage == "noimg")
			{
				oTds(i).style.removeAttribute("backgroundImage", false);
				oTds(i).style.removeAttribute("backgroundRepeat", false);
				oTds(i).style.removeAttribute("backgroundPosition", false);
			}
			else
			{*/
				// if (sStyleBgImage == "noimg")	{oTds(i).style.removeAttribute("backgroundImage", false);}
				if (sStyleBgImage == "noimg")	{oTds(i).style.backgroundImage = "";}
				else if (sStyleBgImage != "")	{oTds(i).style.backgroundImage = "url("+sStyleBgImage+")";}
				
				// if (sStyleBgRepeat == "norepeating")	{oTds(i).style.removeAttribute("backgroundRepeat", false);}
				if (sStyleBgRepeat == "norepeating")	{oTds(i).style.backgroundRepeat = "";}
				else if (sStyleBgRepeat != "")				{oTds(i).style.backgroundRepeat = sStyleBgRepeat;}
				
				if ((sStyleBgPositionX == "noalign") || (sStyleBgPositionY == "novalign"))
				{
					// oTds(i).style.removeAttribute("backgroundPosition", false);
					oTds(i).style.backgroundPosition = "";
				}
				else if ((sStyleBgPositionX != "") && (sStyleBgPositionY != ""))
				{
					oTds(i).style.backgroundPosition = sStyleBgPositionX+" "+sStyleBgPositionY;
				}
			// }
		}
	}
}

//////////////////////////////////////////////////////////////////////
// Hyperlinks...
// lösche Verlinkung...
function HPW_RemoveHyperLink(sEditorID, oAhref)
{
	if (oAhref)
	{
		HPW_BackUp(sEditorID);
		oAhref.removeNode(false);
	}
}

// Neuen HyperLink erstellen...
function HPW_CreateLinkBlank(sEditorID, vIsPopup)
{
	var sLink = document.getElementById(sEditorID+"_linkurl").value;
	//var sTarget = document.getElementById("").value;
	if ((sLink != "http://") && (sLink != ""))
	{
		HPW_BackUp(sEditorID);
		if (vIsPopup == 1)
		{
			var vBreite = prompt("Bitte geben Sie die Breite des fensters in Pixel an:", 500);
			var vHoehe = prompt("Bitte geben Sie die Hoehe des Fensters in Pixel an:", 400);
			var sName = prompt("Sie können Ihrem Fenster einen Namen geben, damit sich der Inhalt beim click auf einen anderen Link nicht verändert:", "MeinFenster");
			var vSrollen = prompt("Wenn der Inhalt des Fensters scrollbar sein soll, bitte 'yes' (standard) ansonten 'no' schreiben:", "yes");
			var sStartTag = "<a href='Javascript:;' onclick=HPW_OpenManualPopup('"+sLink+"',"+vBreite+","+vHoehe+",'"+sName+"','"+vSrollen+"'); target='_self'>";
		}
		else
		{
			var sStartTag = "<a href='"+sLink+"' target='_blank'>";
		}
		var sEndTag = "</a>";
		HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
	}	
}

//////////////////////////////////////////////////////////////////////
// Spezial Things...
function HPW_OpenDatabaseWindow(sEditorID, oTd)
{
	oTd2 =  oTd;
	var sUebergabe = "?sEditorID="+sEditorID;
	var hPopup = HPW_OpenManualPopup(sComboPath+"lib/editor/database.php"+sUebergabe,320,430,"DatabaseWindow","no");
	hPopup.focus();
}

function HPW_OpenImgWindow(sEditorID, oMyImg)
{
	oImg2 = oMyImg;
	var sUebergabe = "?sEditorID="+sEditorID;
	var hPopup = HPW_OpenManualPopup(sComboPath+"lib/editor/img.php"+sUebergabe,320,430,"ImgWindow","yes");
	hPopup.focus();
}

function HPW_SetColorAnzeige(sEditorID)
{
	var ColorText = document.getElementById(sEditorID+"_MainColor").value;
	var Ergebnis = ColorText.match(/([0-9a-f]+)/gi);
	if (Ergebnis) {ColorText = RegExp.$1;} else {ColorText = "";}
	if ((ColorText.length == 0) || (ColorText.length == 3) || (ColorText.length == 6))
	{
		document.getElementById(sEditorID+"_MainColor").value = ColorText;
		if (ColorText.length > 0) {document.getElementById(sEditorID+"_MainColorColor").style.backgroundColor = "#"+ColorText;}
		else {document.getElementById(sEditorID+"_MainColorColor").style.backgroundColor = "#FFFFFF";}
	}
	else
	{
		ColorText = document.getElementById(sEditorID+"_MainColorColor").style.backgroundColor;
		if (ColorText.length > 0)
		{
			document.getElementById(sEditorID+"_MainColor").value = ColorText.replace(/#/gi, "");
		}
		else
		{
			document.getElementById(sEditorID+"_MainColor").value = "";
		}
	}

	//document.getElementById(sEditorID+"_MainColorColor").style.backgroundColor = "#"+document.getElementById(sEditorID+"_MainColor").value;
}

function HPW_InsertImageFromURL(sEditorID)
{
	var sImgUrl = prompt("Bitte geben Sie die Url Adresse zu dem Bild ein: ", "http://");
	if ((sImgUrl != "http://") && (sImgUrl != ""))
	{
		HPW_BackUp(sEditorID);
		var sStartTag = "";
		var sEndTag = "<img src='"+sImgUrl+"' border='0'>";
		HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
	}
}

function HPW_InsertDokumentLink(sEditorID, sDateiUrl, sDateiName)
{
	if ((sDateiUrl != "http://") && (sDateiUrl != ""))
	{
		HPW_BackUp(sEditorID);
		var sStartTag = "<a href='"+sDateiUrl+"' target='_blank'>";
		var sEndTag = sDateiName+"</a>";
		HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
	}
}

function HPW_InsertImage(sEditorID, sImgUrl)
{
	if ((sImgUrl != "http://") && (sImgUrl != ""))
	{
		HPW_BackUp(sEditorID);
		var sStartTag = "";
		var sEndTag = "<img src='"+sImgUrl+"' border='0'>";
		HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
	}
}

function HPW_InsertPopupImageFromURL(sEditorID, sPath)
{
	var sImgUrl = prompt("Bitte geben Sie die Url Adresse zu dem Vorschaubild ein: ", "http://");
	var sPopupImgUrl = prompt("Bitte geben Sie die Url Adresse zu dem Bild in voller größe ein: ", "http://");
	var vBreite = prompt("Geben Sie ein wie breit das Popup-Fenster sein soll: ", "300");
	var vHoehe = prompt("Geben Sie ein wie hoch das Popup-Fenster sein soll: ", "200");
	if ((sImgUrl != "http://") && (sPopupImgUrl != "http://") && (sImgUrl != "") && (sPopupImgUrl != ""))
	{
		HPW_BackUp(sEditorID);
		//var sStartTag = "<a href='javascript:;' onclick=\"HPW_OpenManualPopup(sPath+'lib/popup_bilder.php?url='+sPopupImgUrl,vBreite,vHoehe,'PopupBild','no');\" target='_self'>";
		var sStartTag = "<a href='javascript:;' onclick=\"HPW_OpenManualPopup('"+sPopupImgUrl+"',"+vBreite+","+vHoehe+",'PopupBild','no');\" target='_self'>";
		sStartTag += "<img src='"+sImgUrl+"' border='0'>";
		var sEndTag = "</a>";
		HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
	}
}

function HPW_SetSpecialChar(sID, sEditorID)
{
	HPW_BackUp(sEditorID);
	var oSelect = document.getElementById(sEditorID+sID);
	var sCode = oSelect.options[oSelect.selectedIndex].value;
	var sFont = "Arial";
	var sStartTag = "<span style='font-face:"+sFont+";'>&#x"+sCode+";</span>";
	var sEndTag = "";
	HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag);
}

function HPW_ChangeSelectedStyle(sID, sEditorID)
{
	HPW_BackUp(sEditorID);
	var oSelect = document.getElementById(sEditorID+sID);
	var sStyle = oSelect.options[oSelect.selectedIndex].value;
	HPW_DoTagEditCommand(sEditorID, "<span style='"+sStyle+"'>", "</span>");
	oSelect.selectedIndex = 0;
}

function HPW_ChangeSelectedStyleMoz(sID, sEditorID, sCommand)
{
	HPW_BackUp(sEditorID);
	var oSelect = document.getElementById(sEditorID+sID);
	var sStyle = oSelect.options[oSelect.selectedIndex].value;
	HPW_DoRichEditCommand(sEditorID, sCommand, sStyle);
	oSelect.selectedIndex = 0;
}

/* Tabelle einfügen: Alte Version...
function HPW_CreateNewTable(sEditorID, vBrowser)
{
	HPW_BackUp(sEditorID);
	var vAnzahlSpalten = prompt("Bitte geben Sie die Anzahl an Spalten an:", 3);
	var vAnzahlZeilen = prompt("Bitte geben Sie die Anzahl an Zeilen an:", 1);
	var vSpaltenbreite = prompt("Bitte geben Sie die breite der Spalten an:", 165);
	var vCellspacing = prompt("Bitte geben Sie Abstand zwischen den Spalten an:", 20);

	var vGesamtBreite = 0;
	for (var t=0; t<parseInt(vAnzahlSpalten); t++)
	{
		if ((parseInt(vCellspacing) > 0) && (t > 0)) {vGesamtBreite = parseInt(vGesamtBreite) + parseInt(vCellspacing);}
		vGesamtBreite = parseInt(vGesamtBreite) + parseInt(vSpaltenbreite);
	}

	var sStartTag = "<table cellpadding='0' cellspacing='0' style='width:"+vGesamtBreite+"px; table-layout:fixed;'>";
	var sEndTag = "";

	for (var i=0; i<vAnzahlZeilen; i++)
	{
		if (i == 0) {sStartTag += "<tr>";} else {sEndTag += "<tr>";}
		for (var t=0; t<vAnzahlSpalten; t++)
		{
			if ((i == 0) && (t == 0)) {sStartTag += "<td style='vertical-align:top; width:"+vSpaltenbreite+"px;'>"; sEndTag += "</td>";}
			else
			{
				if ((vCellspacing > 0) && (t>0)) {sEndTag += "<td style='vertical-align:top; width:"+vCellspacing+"px;'></td>";}
				sEndTag += "<td style='vertical-align:top; width:"+vSpaltenbreite+"px;'></td>";
			}
		}
		sEndTag += "</tr>";
	}
	sEndTag += "</table>";
	HPW_DoTagEditCommand(sEditorID, sStartTag, sEndTag, vBrowser);
}
*/

function HPW_CreateNewContent(sEditorID)
{
	HPW_BackUp(sEditorID);
	var myframe = HPW_GetIFrameDocument(sEditorID).getElementById(sEditorID+"_content");
	// Inhalt leeren...
	myframe.innerHTML = "";
	document.getElementById(sEditorID+"_TextMode").value = "";
}

function HPW_OpenContent(sEditorID, vTemplatesID)
{
	HPW_BackUp(sEditorID);
	// Templatebrowser...
	var seite = sComboPath+"lib/tmpbrowser.php?vTemplatesID="+vTemplatesID+"&sEditorID="+sEditorID;
	HPW_OpenManualPopup(seite,500,400,"Templatebrowser","yes");
}

function HPW_SaveEditorContent(sFormID, sInputID, sEditorID)
{
	// Daten abgleichen und ins Formular übertragen...
	if (document.getElementById(sEditorID+"_ShowHTML").value == 0)
	{
		var myframe = HPW_GetIFrameDocument(sEditorID).getElementById(sEditorID+"_content");
		document.getElementById(sEditorID+"_TextMode").value = myframe.innerHTML;
	}
	else
	{
		var sText = document.getElementById(sEditorID).value;
		document.getElementById(sEditorID+"_TextMode").value = sText;
	}
	
	// Formular abschicken...
	document.getElementById(sFormID).submit();
}

function HPW_SaveEditorContents(sFormID, sEditorID, vEditorAnzahl)
{
	for (var i=0; i<vEditorAnzahl; i++)
	{
		// Daten abgleichen und ins Formular übertragen...
		if (document.getElementById(sEditorID+i+"_ShowHTML").value == 0)
		{
			var myframe = HPW_GetIFrameDocument(sEditorID+i).getElementById(sEditorID+i+"_content");
			document.getElementById(sEditorID+i+"_TextMode").value = myframe.innerHTML;
		}
		else
		{
			var sText = document.getElementById(sEditorID+i).value;
			document.getElementById(sEditorID+i+"_TextMode").value = sText;
		}
	}
	
	// Formular abschicken...
	document.getElementById(sFormID).submit();
}
