function setBold(id) {
	Veld=document.getElementById(id).value; //.document.getSelection();
	Veld=document.getSelection();
	//Veld=getSelText();
	alert(Veld + " wordt vettig gemaakt!");
	//Text=document.selection.createRange().text;
	//document.selection.createRange().text = '[b]' + Text + '[/b]';
}
function setstyle(styleselector,id) {
	Field=document.getElementById(styleselector);
	Value=Field.selectedIndex;
	Field.selectedIndex=0;
	Options=Field.options;
	//alert(Options[Value].value);
	style=Options[Value].value;
	addTag(id,style);
	//alert("style=" + style);
}
function borderUp(field) {
	field.style.borderBottom="1px solid #333333";
	field.style.borderRight="1px solid #666666";
	field.style.borderTop="1px solid #ffffff";
	field.style.borderLeft="1px solid #dddddd";
}
function borderDown(field) {
	field.style.borderTop="1px solid #333333";
	field.style.borderLeft="1px solid #666666";
	field.style.borderBottom="1px solid #ffffff";
	field.style.borderRight="1px solid #dddddd";

	//field.style="border: 1px solid #555555;";
	//alert(field.style);
}

function getSelection(id) {
	var bits = [id.value,'','','']; 
	if (document.selection) {
		var vs = '#$%^%$#';
		var tr=document.selection.createRange()
		if (tr.parentElement() != id)
			return null;
		bits[2] = tr.text;
		tr.text = vs;
		fb = id.value.split(vs);
		tr.moveStart('character',-vs.length);
		tr.text = bits[2];
		bits[1] = fb[0];
		bits[3] = fb[1];
	} else {
		//if (id.selectionStart == id.selectionEnd)	return null;
		bits=(new RegExp('([\x00-\xff]{'+id.selectionStart+'})([\x00-\xff]{'+(id.selectionEnd - id.selectionStart)+'})([\x00-\xff]*)')).exec(id.value);
	}
	return bits;
}
function matchTags(str) {
	str = ' ' + str + ' ';
	ot = str.split(/\[.*?\]/i);
	ct = str.split(/\[\/.*?\]/i);
	//ot = str.split(/\[[B|U|I].*?\]/i);
	//ct = str.split(/\[\/[B|U|I].*?\]/i);
	return ot.length==ct.length;
}
function addTag(id,tag1,tag2) {
	Field=document.getElementById(id);
	bits = getSelection(Field);
	if (!tag2) tag2=tag1;
	if (bits) {
		if (!matchTags(bits[2])) {
			alert('Invalid Selection - Selection contains unmatched tags.');
			return;
		}
		Field.value = bits[1] + '[' + tag1 + ']' + bits[2] + '[/' + tag2 + ']' + bits[3];
	}
}
function addSingleTag(id,tag1,tag2) {
    //alert(id);
	Field=document.getElementById(id);
	bits = getSelection(Field);
	if (!tag2) tag2=tag1;
	if (bits) {
		if (!matchTags(bits[2])) {
			alert('Invalid Selection - Selection contains unmatched tags.');
			return;
		}
		Field.value = bits[1] + '[' + tag1 + ']' + bits[2] + bits[3];
	}
}
function reload(message,url) {
	alert(message);
	window.location=url;
}