
var curSelVal = "";
var startPos = 0;
var endPos = 0;

function insert(tag, value) {
	if (document.selection) {
		document.form_plaats_bericht.bericht.focus();
		var selection = document.selection.createRange();
		selection.text = '[' + tag + ']' + value + '[/' + tag + ']';
  	}
  	else if (document.form_plaats_bericht.bericht.selectionStart || document.form_plaats_bericht.bericht.selectionStart == '0') {
		var startPos = document.form_plaats_bericht.bericht.selectionStart;
		var endPos = document.form_plaats_bericht.bericht.selectionEnd;

		document.form_plaats_bericht.bericht.value = document.form_plaats_bericht.bericht.value.substring(0, startPos)
		+ '[' + tag + ']' + value + '[/' + tag + ']' + document.form_plaats_bericht.bericht.value.substring(endPos, document.form_plaats_bericht.bericht.value.length);
  	}
  	else {
		document.form_plaats_bericht.bericht.value += '[' + tag + ']' + value + '[/' + tag + ']';
  	}
}
function insertWithAttribute(tag, value, attr) {
	if (document.selection) {
		document.form_plaats_bericht.bericht.focus();
		var selection = document.selection.createRange();
		selection.text = '[' + tag + '=' + attr + ']' + value + '[/' + tag + ']';
  	}
  	else if (document.form_plaats_bericht.bericht.selectionStart || document.form_plaats_bericht.bericht.selectionStart == '0') {
		var startPos = document.form_plaats_bericht.bericht.selectionStart;
		var endPos = document.form_plaats_bericht.bericht.selectionEnd;

		document.form_plaats_bericht.bericht.value = document.form_plaats_bericht.bericht.value.substring(0, startPos)
		+ '[' + tag + '=' + attr + ']' + value + '[/' + tag + ']' + document.form_plaats_bericht.bericht.value.substring(endPos, document.form_plaats_bericht.bericht.value.length);
  	}
  	else {
		document.form_plaats_bericht.bericht.value += '[' + tag + '=' + attr + ']' + value + '[/' + tag + ']';
  	}
}

function insertList (tag,pr) {
	var list='';
	var loop = 1;
	while (loop) {
		loop =  prompt(pr,'');
		if (loop!='') list += "\r\n" + '[*]' + loop;
	}
	if (loop!=null) {
		list += "\r\n";
		insert('list', list);
	}
}

function insertTagWithURL (tag,pr,def) {
	var url = prompt(pr,def);
	if (url) insert(tag, url);
}

function insertLink (tag,pr1,def1,pr2,def2) {
	var url = prompt(pr1,def1);
	if (url) { 
		var title = prompt(pr2,def2);
		if (title=='') {
			insert(tag, url);
		} else {
			if (title) insertWithAttribute(tag, title, url);
		}
	}
}
function insertKop (tag,pr1,def1) {
	var subtitel = prompt(pr1,def1);
	if (subtitel) { 
		
			insert(tag, subtitel);
		
	}
}

function storeCurVal(obj, start, end) {
	// function not called if IE 4+
	startPos = obj.selectionStart;
	endPos = obj.selectionEnd;
	curSelVal = document.form_plaats_bericht.bericht.value;
}

function getSel(tag) {
	if(document.selection){
		oldString = document.selection.createRange().text;
		if	(oldString != "") {
			document.selection.createRange().text = '[' + tag + ']' + oldString + '[/' + tag + ']';
		} else {
			insert(tag,'');
		}
		curSelVal = "";
		startPos = 0;
		endPos = 0;
		return false;
	 } else if(window.getSelection) {
		oldString = curSelVal;
		newString = '';
		finalString = '';
		len = curSelVal.length; // length of current string
		if (len > 0 && document.form_plaats_bericht.bericht.value.length > 0) {
			// get from beginning of string to start position
			firstPart = oldString.substring(0, startPos);
			// get from end of selection to end of total string
			lastPart = oldString.substring(endPos, len);
	
			// store the new string
			for (i=startPos; i<endPos; i++) {
			 newString += oldString[i];
			}
			// surround it with the proper tag
			finalString = '[' + tag + ']' + newString + '[/' + tag + ']';
		
			// rewrite it back into the textarea
			document.form_plaats_bericht.bericht.value = firstPart + finalString + lastPart;
		} else {
			insert(tag,'')
			curSelVal = "";
		}
		curSelVal = "";
		startPos = 0;
		endPos = 0;
	} 
}

function toggle(v) {
	obj = document.getElementById ( 'keepmeposted' );
	if (obj.style.display=='none') {
		obj.style.display = 'block';
 	} else {
		obj.style.display = 'none';
 	}
}
