function google()
{
	ebaywin=window.open("http://www.preisvergleich.net/redirects/ebay.php","","scrollbars=yes,resizeable=yes,menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes");
	ebaywin.blur();
	window.focus();
	razywin=window.open("http://www.foren.de/popup/index.htm","","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=410,height=360,left=307,top=233");
}
																	
function DoPrompt(action)
{
   document.REPLIER.beitrag.value=document.REPLIER.beitrag.value+action;
   document.REPLIER.beitrag.focus();
}

function storeCaret (textEl)
{
        if (textEl.createTextRange)
        textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text)
{
	if (navigator.appVersion.indexOf("MSIE")!=-1)
	{
		if (textEl.createTextRange && textEl.caretPos) {
			var caretPos = textEl.caretPos;
		        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			text + ' ' : text;
		}
		else
			textEl.value  = textEl.value + text;
	} else DoPrompt(text);
		document.REPLIER.beitrag.focus();
}

function insertURL ()
{
	url=prompt('Bitte die URL eingeben (www...):','');
	if (url!=null) {
		titel=prompt('Und nun bitte den Text eingeben, der im Beitrag angezeigt werden soll:','');
		if (titel!=null) {
			AroundSelection(document.REPLIER.beitrag,'[url=' + url + ']' + titel + '[/url]','');
		}
	}
}

function insertIMG ()
{
	img=prompt('Bitte die URL des Images eingeben (www...):','');

	if (img!=null) {
		AroundSelection(document.REPLIER.beitrag,'[img]' + img + '[/img]','');
	}
}
	
function insertEmail ()
{
	email=prompt('Bitte die Emailadresse eingeben:','');
	
	if (email!=null) {
		titel=prompt('Und nun bitte den Text eingeben, der im Beitrag angezeigt werden soll:','');
		
		if (titel!=null) {
			AroundSelection(document.REPLIER.beitrag, '[url=mailto:' + email + ']' + titel + '[/url]','');
		}
	}
}

function insertList() {
	anzahl=prompt('Anzahl der Punkte (max. 9):','1');
	
	if (anzahl>=10) {
		anzahl=9;
	}
	
	if (anzahl!=null || isNaN(anzahl)==false) {
		liststring='[list]';
		
		for (var i=1; i<=anzahl; i++) {
			liststring += '\r\n[punkt][/punkt]';
		}
		
		liststring+='\r\n[/list]';
		
		AroundSelection(document.REPLIER.beitrag, liststring,'');
	}
}

function InsertZitat()
{
	person=prompt('Bitte den Namen der zu zitierenden Person eingeben.','');
	
	if (person!=null) {
	        var nicklength = person.length;
	
		for (var i=0; i<=nicklength; i++)
		{
			person = person.replace('[','');
			person = person.replace(']','');
		}
		
		AroundSelection(document.REPLIER.beitrag,'[Zitat=' + person + '][/Zitat]','');
	}
}

function AroundSelection(textarea, links, rechts) {
	var input = textarea;
	input.focus();
	/* is IE ? */
        if(typeof document.selection != 'undefined') {
		/* Einfügen des Formatierungscodes */
	        var range = document.selection.createRange();
		var insText = range.text;
		range.text = links + insText + rechts;
		/* Anpassen der Cursorposition */
		range = document.selection.createRange();
		if (insText.length == 0) {
			range.move('character', -rechts.length);
		} else {
			range.move('character', links.length);
			range.moveEnd('character', insText.length);
		}
		range.select();
	}
	/* Gecko-Browser */
	/* test		 */
	else if(typeof input.selectionStart != 'undefined')
	{
		var sStart = input.selectionStart;
		var sEnd = input.selectionEnd;
		var sInsText = input.value.substring(sStart, sEnd);
		input.value = input.value.substr(0, sStart) + links + sInsText + rechts + input.value.substr(sEnd);
		var cpos;
		textarea.focus();
		if (sInsText.length == 0) {
			cpos = sStart + links.length;
			input.selectionStart = cpos;
			input.selectionEnd = cpos;
		} else {
			input.selectionStart = sStart + links.length;
			input.selectionEnd = sStart + links.length + sInsText.length;
		}
	} else {
		textarea.value = textarea.value + links + rechts;
	}
	//textarea.focus();
}
