//#######################################
//## PNEWS Java-Script                 ##
//#######################################
//<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) {
	if (document.newsf.newsformat.value == 'html') {
		AddToField(hrcform, "<hr />");
	} else {
		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 != ""))
			if (document.newsf.newsformat.value == 'html') {
				AddToField(hrcform, "<a href=\""+linkurl+"\">"+linktext+"</a> ");
			} else {
				AddToField(hrcform, "[url="+linkurl+"]"+linktext+"[/url] ");
			}
		}
}


//########### 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 != ""))
			if (document.newsf.newsformat.value == 'html') {
				AddToField(hrcform, "<a href=\"mailto:"+linkurl+"\">"+linktext+"</a> ");
			} else {
				AddToField(hrcform, "[email="+linkurl+"\"]"+linktext+"[/email] ");
			}
		}
      //hrcform.news.focus();
}

//########### Text FETT  ########################
function htmlbold(hrcform) {
      boldtext = prompt("Text der FETT formatiert werden soll:","");

	if ((boldtext != null) && (boldtext != "")) {
		if (document.newsf.newsformat.value == 'html') {
			AddToField(hrcform,"<b>"+boldtext+"</b> ");
		} else {
			AddToField(hrcform,"[b]"+boldtext+"[/b] ");
		}
       //hrcform.news.focus();
    }
}

//########### Text Kursiv  ########################
function htmlitalic(hrcform) {
      italictext = prompt("Text der KURSIV formatiert werden soll:","");

	if ((italictext != null) && (italictext != "")) {
		if (document.newsf.newsformat.value == 'html') {
			AddToField(hrcform,"<i>"+italictext+"</i> ");
		} else {
			AddToField(hrcform,"[i]"+italictext+"[/i] ");
		}
       //hrcform.news.focus();
    }
}

//########### Text Unterstrichen  ########################
function htmlunderlined(hrcform) {
      ultext = prompt("Text der Unterstrichen formatiert werden soll:","");

	if ((ultext != null) && (ultext != "")) {
		if (document.newsf.newsformat.value == 'html') {
			AddToField(hrcform, "<u>"+ultext+"</u> ");
		} else {
			AddToField(hrcform, "[u]"+ultext+"[/u] ");
		}
       //hrcform.news.focus();
     }
}

//########### Text Zentriert  ########################
function htmlcenter(hrcform) {
      centertext = prompt("Text der ZENTRIERT formatiert werden soll:","");

	if ((centertext != null) && (centertext != "")) {
		if (document.newsf.newsformat.value == 'html') {
			AddToField(hrcform,"<center>"+centertext+"</center> ");
		} else {
			AddToField(hrcform,"[center]"+centertext+"[/center] ");
		}
       //hrcform.news.focus();
      }
}


//########### Bildeinfügen  ########################
function htmlimg(hrcform) {
      imgurl = prompt("URL zum Bild eingeben:","http://");

	if ((imgurl != null) && (imgurl != "")) {
		if (document.newsf.newsformat.value == 'html') {
			AddToField(hrcform, "<img src=\""+imgurl+"\" border=\"0\"> ");
		} else {
			AddToField(hrcform, "[img="+imgurl+"] ");
		}
       //hrcform.news.focus();
      }
}

//#### 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();
}


