function preview( id )
{
	var input = escape( document.getElementById( id ).value );
	popUp( '../preview.php?input=' + input, 640, 480 );
}

function previewNews( id )
{
	var input = escape( document.getElementById( id ).value );
	popUp( 'preview.php?input=' + input, 640, 480 );
}

function ubb(opentag, closetag, form, id) {
	var field = document.forms[form].elements[id];
	if (document.selection) {
		field.focus();
		sel = document.selection.createRange();
		sel.text = opentag + sel.text + closetag;
	} else if (field.selectionStart || field.selectionStart == "0") {
		var selLength = field.textLength;
		var selStart = field.selectionStart;
		var selEnd = field.selectionEnd;
		if (selEnd == 1 || selEnd == 2) selEnd = selLength;
		var s1 = (field.value).substring(0,selStart);
		var s2 = (field.value).substring(selStart, selEnd)
		var s3 = (field.value).substring(selEnd, selLength);
		field.value = s1 + opentag + s2 + closetag + s3;
		field.focus();
	}
}

function ubb_url(form, id) {
	var field = document.forms[form].elements[id];
	
	if (document.selection) {
		field.focus();
		var selection = document.selection.createRange();

		if(selection.text) {
			var url = prompt("Het adres:", "http://");
			selection.text = "[url="+url+"]"+selection.text+"[/url]";
		} else {
			var url = prompt("Het adres:", "");
			var url_title = prompt("De naam van link:", "");
			field.value += "[url="+url+"]"+url_title+"[/url]";
		}
	} else if (field.selectionStart || field.selectionStart == '0') {
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;

		if (startPos != endPos) {
			var url = prompt("Het adres:", "http://");
			field.value = field.value.substring(0, startPos)
			+ "[url="+url+"]"
      			+ field.value.substring(startPos, endPos)
			+ "[/url]"
			+ field.value.substring(endPos, field.value.length);
			field.focus();
		} else {
			var url = prompt("Het adres:", "http://");
			var url_title = prompt("De naam van link:", "");
			field.value = field.value.substring(0, startPos)
			+ "[url="+url+"]"+url_title+"[/url]"
			+ field.value.substring(endPos, field.value.length);
			field.focus();
		}
	}
}