function genadres(ahref,stijl){
	ahref=ahref.replace('\%x.\%x','@');
	ahref=ahref.replace('\$.\$','mailto:');
	document.write('<a '+ahref+' class='+stijl+'>');
}
function genadres2(ahref){
	ahref=ahref.replace('\%x.\%x','@');
	ahref=ahref.replace('\$.\$','mailto:');
	document.write(ahref);
}
function TREScreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function TRESreadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function TRESeraseCookie(name) {
	TREScreateCookie(name,"",-1);
}

function checksize(sizevalue,sizetype,componentid,realwidth,realheight){
	if (realheight>0){
		if(document.getElementById('locksize'+componentid).value=='on'){
			if(sizetype==1){
				realsize=realheight/realwidth;
				if(sizevalue>0){
					document.getElementById('imageheight'+componentid).value=Math.round(realsize * sizevalue);
				}
			}
			if(sizetype==2){
				realsize=realwidth/realheight;
				if(sizevalue>0){
					document.getElementById('imagewidth'+componentid).value=Math.round(realsize * sizevalue);
				}
			}
		}
	}
}

function TR3S_checkIfUnderTen(temp){
  if(temp.length>=2)
	return temp
  else
	return '0'+temp;
}

function TR3S_findobject(naam){
  var obj;
  obj=(document.all) ? document.all[naam] : document.getElementById(naam);
  return obj;
}


function bbfontstyle2(bbopen, bbclose, component) {
	theSelection = document.selection.createRange().text;
	if (component.selectionEnd && (component.selectionEnd - component.selectionStart > 0))
	{
		component.focus();
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		
	}
  return;
}


// Zie insertAtCursor();
//  Aangepast om bbcode te kunnen gebruiken
function bbfontstyle(bbopen, bbclose, component) {
	//var txtarea = document.post.message;
	var txtarea = component;
	if(txtarea.style.display=='none'){
		//rich text area
		
	}
	else{
		theSelection = document.selection.createRange().text;
		if (document.selection) {
			txtarea.focus();
			sel = document.selection.createRange();
			sel.text = bbopen + theSelection + bbclose;
		}
		else if (txtarea.selectionStart || txtarea.selectionStart == '0')
		{
			var startPos = txtarea.selectionStart;
			var endPos = txtarea.selectionEnd;
			txtarea.value = txtarea.value.substring(0, startPos)
			+ bbopen + bbclose
			+ txtarea.value.substring(endPos, txtarea.value.length);
		} else {
			txtarea.value += bbopen + bbclose;
		}
		
		return;
	}

}

// Code om tekst toe te voegen op positie van de cursor ipv. einde van tekstveld
function insertAtCursor(myField, myValue)
{
	//IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

