function opensearch () {
	window.open("search.php", "_blank","toolbar=no,location=no,menubar=no,scrollbars=yes,width=540,height=560,status=yes");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function submit() { 
        window.open("submit.php", "_blank","toolbar=no,location=no,menubar=no,scrollbars=yes,width=490,height=525,resizeable=no,status=no"); 
} 

function reply(id) { 
	window.open("submit.php?replyTo=1&id="+id, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=425,resizeable=no,status=no"); 
	windowopen = 1; 
} 

function lock(id) { 
	window.open("close.php?close=1&id="+id, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=490,resizeable=no,status=no"); 
}

function quote(id,quoteid) { 
	win = open("submit.php?replyTo=1&id="+id+"&quote="+quoteid, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=425,resizeable=no,status=no"); 
} 
 
function reopen(id) { 
	window.open("close.php?open=1&id="+id, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=490,resizeable=no,status=no"); 
} 
 
function info(name) { 
	window.open("userinfo.php?name="+name, "_blank","toolbar=no,location=no,menubar=no,scrollbars=yes,width=400,height=480,resizeable=no,status=no"); 
} 
 
function logout() { 
	window.open ("logout.php", "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=300,resizeable=no,status=no"); 
} 
 
function edit(id) { 
	window.open ("edit.php?id="+id, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=375,resizeable=no,status=no"); 
} 
 
function del(id) { 
	window.open ("delete.php?id="+id, "_blank","toolbar=no,location=no,menubar=no,scrollbars=no,width=490,height=490,resizeable=no,status=no"); 
} 

/* ------------------------------------------------------------- */
/* Code voor de submit en edit schermen                          */
/* ------------------------------------------------------------- */
function ready() {
	window.opener.location.reload();
	setTimeout("window.close()",2000);
}
	
function addText(insText) {
	var input = document.edit.text;
	input.focus();
	if( input.createTextRange ) {
		document.selection.createRange().text += insText;
	} else if( input.setSelectionRange ) {
		var len = input.selectionEnd;
		input.value = input.value.substr( 0, len )
	 	+ insText + input.value.substr( len );
		input.setSelectionRange(len+insText.length,len+insText.length);
	} else { input.value += insText; }
		// Todo: dit verplaatsen naar eigenfunctie?
	document.getElementById('smilie_table').style.display = 'none';
}

/* TODO:
/  - cursor in tags als leeg, anders erachter
/  - popup voor lege waarden in img?
*/ 
function surroundText(text1, text2) {
	var input = document.edit.text;
	input.focus();
	if( input.createTextRange ) {				// IE
		document.selection.createRange().text = text1 + document.selection.createRange().text + text2;
	} else if( input.setSelectionRange ) {		// FireFox etc.
		var len = input.selectionEnd;
		input.value = input.value.substr( 0, input.selectionStart )
	 	+ text1 + input.value.substr( input.selectionStart, input.selectionEnd - input.selectionStart ) 
		+ text2 + input.value.substr( input.selectionEnd ) ;
		input.setSelectionRange(len+text1.length,len+text1.length);
	} else { /*input.value += insText;*/ }
	// Todo: dit verplaatsen naar eigenfunctie?
	document.getElementById('color_table').style.display = 'none';
}
function addUrl() {
	var input = document.edit.text;
	input.focus();
	if( input.createTextRange ) {				// IE
		text = document.selection.createRange().text;
		text = createLink(text);
		document.selection.createRange().text = text;
	} else if( input.setSelectionRange ) {		// FireFox etc.
		var len = input.selectionEnd;
		text = input.value.substr(input.selectionStart, input.selectionEnd - input.selectionStart);
		text = createLink(text);
		input.value = input.value.substr( 0, input.selectionStart )
	 	+ text + input.value.substr( input.selectionEnd ) ;
		input.setSelectionRange(len+text.length,len+text.length);
	}

}

function createLink(text) {
	if (/^(http:\/\/|www\.)/i.test(text)) {
		if ((val = prompt('Voer omschrijving in:', text)))
			text = '[url="'+text+'"]'+val+'[/url]';
	} else {
		val = prompt('Voer de URL in:','http:\/\/');
		if (val && val != 'http:\/\/') {
			if (text == '') text = '[url]'+val+'[/url]';
			else text = '[url='+val+']'+text+'[/url]';
		}
	}
	return text;
}
function toggleColors (obj) {
	offset = -80;
	table = document.getElementById('color_table');
	if (table.style.display == 'block') {
		table.style.display = 'none';
	} else {
		table.style.display = 'block';
		pos = findPos(obj);
		//alert (pos[1] + "-" + pos[0]);
		table.style.top = pos[1] + 'px';
		table.style.left = pos[0] + offset + 'px';
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function togglePass() {
 if (document.getElementById('passbox').style.visibility == 'visible') {
    document.getElementById('passbox').style.visibility = 'hidden';
    document.getElementById('passtext').style.visibility = 'hidden';
  } else {
    document.getElementById('passbox').style.visibility = 'visible';
    document.getElementById('passtext').style.visibility = 'visible';
  }
}
function toggleSmilies (obj) {
	offset = -323;
	table = document.getElementById('smilie_table');
	if (table.style.display == 'block') {
		table.style.display = 'none';
	} else {
		table.style.display = 'block';
		pos = findPos(obj);
		//alert (pos[1] + "-" + pos[0]);
		table.style.top = pos[1] + 'px';
		table.style.left = pos[0] + offset + 'px';
	}
}
function switchTables() {
	var smt1 = document.getElementById('smt1');
	var smt2 = document.getElementById('smt2');
	if (smt1.style.display == 'none') {
		smt1.style.display = '';
		smt2.style.display = 'none';
	} else {
		smt1.style.display = 'none';
		smt2.style.display = '';
	}
}