function ltrim (s) {

	return s.replace( /^\s*/, "" );
}

function rtrim (s) {

	return s.replace( /\s*$/, "" );
}

function trim (s) {

	return rtrim(ltrim(s));
}

function formatStr (v) {
	
	if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    document.selection.createRange().text = '<' + v + '>' + str + '</' + v + '>';
}

function insertLink () {
    
	if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var my_link = prompt('Geef URL:', 'http://');
    if (my_link != null)
        document.selection.createRange().text = '<a target=\"_blank\" href="' + my_link + '">' + str + '</a>';
}
function lbreak(){
     document.editor.pagebody.value = document.editor.pagebody.value + "<br>\n";
}

function displayHTML(form) {
	
	var inf = form.pagebody.value.replace(/\s\s/g,'<br>');
	if ( form.img_url.value != "" ) {
		var pic = form.img_url.value;
	}
	win = window.open(", ", 'popup', 'height=500,width=550,toolbar = no, status = no');
	win.document.write('<html><head><title>Preview</title>')
	win.document.write('</head><body  bgcolor="#FFFFFF" topmargin="15" leftmargin="15">');
	if (pic) {
		win.document.write('<center><img src="' + pic + '" border="1"></center><br>');
	}
	win.document.write("" + inf + "");
	win.document.write('</body></html>');
	win.document.close();
}

function picpopup(link, width, height) {

	win = window.open(", ", 'picpopup', 'height=' + height + ',width=' + width + ',toolbar = no, status = no');
	win.document.write('<html><head><title>Foto</title>')
	win.document.write('</head><body  bgcolor="#FFFFFF" topmargin="0" leftmargin="0">');
	win.document.write('<center><a href="#" OnClick="window.close()"><img src="' + link + '" border="0"></a></center><br>');
	win.document.write('</body></html>');
	win.document.close();

}