//#######################################
//## pHTMLeditor                       ##
//#######################################
//<script language="Javascript" src="htmlcodes.js"></script>

//############ Add Text to Field ###############################
function AddToField(Field,AddCode)
{
	if ( Field.createTextRange && Field.caretPos )
	{
		var caretPos = Field.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? AddCode + ' ' : AddCode;
	}
	else
	{
		Field.value += AddCode;
	}
	Field.focus();
}

//########### horizontale Linie
function htmlline(hrcform) {
	AddToField(hrcform, "<hr>");
}

//########### Setzt einen URL-Link ein ########################
function htmllink(hrcform) {
    linktext = prompt("Titel des Links:","");
    linkurl = prompt("URL des Links:","http://");
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			AddToField(hrcform, "<a href=\""+linkurl+"\">"+linktext+"</a> ");
	}
}

//########### Setzt einen Email-Link ein ########################
function htmlemail(hrcform) {
    linktext = prompt("Name des Empfängers:","");
    linkurl = prompt("Email Adresse:","");
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			AddToField(hrcform, "<a href=\"mailto:"+linkurl+"\">"+linktext+"</a> ");
	}
}

//########### Text FETT  ########################
function htmlbold(hrcform) {
    boldtext = prompt("Text der FETT formatiert werden soll:","");
	if ((boldtext != null) && (boldtext != "")) {
		AddToField(hrcform,"<b>"+boldtext+"</b> ");
    }
}

//########### Text Kursiv  ########################
function htmlitalic(hrcform) {
    italictext = prompt("Text der KURSIV formatiert werden soll:","");
	if ((italictext != null) && (italictext != "")) {
			AddToField(hrcform,"<i>"+italictext+"</i> ");
    }
}

//########### Text Unterstrichen  ########################
function htmlunderlined(hrcform) {
    ultext = prompt("Text der Unterstrichen formatiert werden soll:","");
	if ((ultext != null) && (ultext != "")) {
		AddToField(hrcform, "<u>"+ultext+"</u> ");
    }
}

//########### Text Zentriert  ########################
function htmlcenter(hrcform) {
    centertext = prompt("Text der ZENTRIERT formatiert werden soll:","");
	if ((centertext != null) && (centertext != "")) {
		AddToField(hrcform,"<center>"+centertext+"</center> ");
    }
}

//########### Bildeinfügen  ########################
function htmlimg(hrcform) {
    imgurl = prompt("URL zum Bild eingeben:","http://");
	if ((imgurl != null) && (imgurl != "")) {
		AddToField(hrcform, "<img src=\""+imgurl+"\" border=\"0\"> ");
    }
}

//#### speichert die Cursorposition ####
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

//end