//#######################################
//## PFORUM Java-Script  HRC           ##
//#######################################
//<script language="Javascript" src="hrccodes.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 hrcline(hrcform) {
	AddToField(hrcform, "[hr]");
}


//########### Setzt einen URL-Link ein ########################
function hrclink(hrcform) {
      linktext = prompt("Titel des Links:","");
      linkurl = prompt("URL des Links:","http://");
 	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			AddToField(hrcform, "[URL="+linkurl+"]"+linktext+"[/URL] ");
		else
			AddToField(hrcform, "[URL]"+linkurl+"[/URL] ");
		}
	//hrcform.focus();
}

//########### Setzt einen Email-Link ein ########################
function hrcemail(hrcform) {
      linkemail = prompt("EMail Adresse eingeben:","");

	if ((linkemail != null) && (linkemail != "")) {
		AddToField(hrcform, "[EMAIL]"+linkemail+"[/EMAIL] ");
      }
	//hrcform.focus();
}

//########### Setzt einen Quote ein ########################
function hrcquote(hrcform) {
      hquote = prompt("Quote Text eingeben:","");

	if ((hquote != null) && (hquote != "")) {
		AddToField(hrcform, "[quote]"+hquote+"[/quote] ");
      }
	//hrcform.focus();
}

//########### Setzt einen Code ein ########################
function hrccode(hrcform) {
      hcode = prompt("Code eingeben:","");

	if ((hcode != null) && (hcode != "")) {
		AddToField(hrcform, "[code]"+hcode+"[/code] ");
      }
	//hrcform.focus();
}

//########### Text FETT  ########################
function hrcbold(hrcform) {
    	boldtext = prompt("Text der FETT formatiert werden soll:","");
    	if ((boldtext != null) && (boldtext != "")) {
	  AddToField(hrcform,"[b]"+boldtext+"[/b] ");
    	}
	//hrcform.focus();	
}

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

	if ((italictext != null) && (italictext != "")) {
	  AddToField(hrcform, "[i]"+italictext+"[/i] ");
      }
	//hrcform.focus();
}

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

	if ((ultext != null) && (ultext != "")) {
	  AddToField(hrcform, "[u]"+ultext+"[/u] ");
      }
	//hrcform.focus();
}

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

	if ((centertext != null) && (centertext != "")) {
	  AddToField(hrcform, "[center]"+centertext+"[/center] ");
      }
	//hrcform.focus();
}


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

	if ((imgurl != null) && (imgurl != "")) {
	  AddToField(hrcform, "[img]"+imgurl+"[/img] ");
      }
	//hrcform.focus();
}


//########### Smilies einsetzen ####################
function postsmile(code) {
	code = ' ' + code + ' ';
	if (document.pfform.post.createTextRange && document.pfform.post.caretPos) {
		var caretPos = document.pfform.post.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? code + ' ' : code;
		document.pfform.post.focus();
	} else {
	document.pfform.post.value  += text;
	}
	//hrcform.focus();
}


// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}


