function insertAtCaret (input, text) {
    // Dont act if HTMLarea is active
    /*if (done) {
        alert("Sorry, je kunt een smiley niet aanklikken om in te voegen wanneer je gebruik maakt van de WYSIWYG editor. Voeg de smiley handmatig in.");
    }*/

    if (input.setSelectionRange) {
        input.focus();
        var selectionStart = input.selectionStart;
        var selectionEnd = input.selectionEnd;
        input.value = input.value.substring(0, selectionStart)
                   + text + input.value.substring(selectionEnd);
        input.setSelectionRange(selectionStart + text.length, 
                   selectionStart + text.length);
        input.focus();
    }
    else if (document.selection) {
        input.focus();
        var range = document.selection.createRange();
        if (range.parentElement() == input)
            range.text = text;
    }
}

function getId(e) {
    return document.all ? document.all(e) : document.getElementById(e);
}

function toggleSection(name) {
    var item = getId(name);

    if (item.style.display=='none') {
        item.style.display='';
    } else {
        item.style.display='none';
    }
}

function OpenPic (imagename, imageheight, imagewidth, title) {
        // Calculate placement on the screen
        var top = ((screen.availHeight / 2) - (imageheight / 2));
        var left = ((screen.availWidth / 2) - (imagewidth / 2));
        if (top < 0) top = 0;
        if (left < 0) left = 0;

        // Popup
        var popupwidth=imagewidth;
        var popupheight=imageheight;
        newWindow = window.open("<?=$_SERVER[PHP_SELF]?>?dummy=yes","newWindow","width="+popupwidth+",height="+popupheight+",top="+top+",left="+left);
    	newWindow.document.open();
    	newWindow.document.write('<html>');
        newWindow.document.write('<head>');
        newWindow.document.write('<title>'+title+' (Sluit scherm met linkermuisknop, opslaan met rechtermuisknop)</title>');
        newWindow.document.write('</head>');
        newWindow.document.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor="#000000">');  
    	newWindow.document.write('<table height="100%" width='+imagewidth+' border="0" cellspacing="0" cellpadding="0" align="center" valign="center" height='+imageheight+' >');
        newWindow.document.write('<tr><td>');
        newWindow.document.write('<img border="0" src="'+imagename+'" width='+imagewidth+' height='+imageheight+' alt="Klik met linkermuisknop om scherm te sluiten. Klik met rechtermuisknop om deze afbeelding op te slaan." >'); 
	    newWindow.document.write('</td></tr>');
        newWindow.document.write('</table>');
        newWindow.document.write("<script language=JavaScript1.2>");
        newWindow.document.write("function clicked(e) {");
        newWindow.document.write(" if (!e) var e = window.event;");
        newWindow.document.write(" if ((e.which && e.which == 3) || (e.button && e.button == 2)) { /* rightclick */ }");
        newWindow.document.write(" else { self.close(); }");
        newWindow.document.write("}");
        newWindow.document.write("document.onmousedown=clicked;");
        newWindow.document.write("<\/script></body></html>"); // @#$@#$ (took a while to get this fixed)
    	newWindow.document.close();
	    newWindow.focus();
}
