function insertAtCursor(textAreaId, myValue) {
	textArea = document.getElementById(textAreaId);
	
	js_curPos = js_getCursorPosition(textArea);
	
	textArea.value = textArea.value.substring(0, js_curPos['start']) + myValue + textArea.value.substring(js_curPos['end'], textArea.value.length);
	
	js_curPos['start'] += myValue.length
	js_curPos['end'] = js_curPos['start'];
	js_setCursorPosition(textArea, js_curPos)
}

function js_countTextAreaChars(text) {
    var n = 0;
    for (var i = 0; i < text.length; i++) {
        if (text.charAt(i) != '\r') {
            n++;
        }
    }
    return n;
}

function js_CursorPos(start, end) {
    this.start = start;
    this.end = end;
}

function js_getCursorPosition(textArea) {
    var start = 0;
    var end = 0;
    if (document.selection) { // IE...
        textArea.focus();
        var sel1 = document.selection.createRange();
        var sel2 = sel1.duplicate();
        sel2.moveToElementText(textArea);
        var selText = sel1.text;
        sel1.text = '01';
        var index = sel2.text.indexOf('01');
        start = js_countTextAreaChars((index == -1) ? sel2.text : sel2.text.substring(0, index));
        end = js_countTextAreaChars(selText) + start;
        sel1.moveStart('character', -2);
        sel1.text = selText;
    } else if (textArea.selectionStart || (textArea.selectionStart == '0')) { // Mozilla/Netscape...
        start = textArea.selectionStart;
        end = textArea.selectionEnd;
    }
    
    return new js_CursorPos(start, end);
}

function js_setCursorPosition(textArea, cursorPos) {
    if (document.selection) { // IE...
        var sel = textArea.createTextRange();
        sel.collapse(true);
        sel.moveStart('character', cursorPos.start);
        sel.moveEnd('character', cursorPos.end - cursorPos.start);
        sel.select();
    } else if (textArea.selectionStart || (textArea.selectionStart == '0')) { // Mozilla/Netscape...
        textArea.selectionStart = cursorPos.start;
        textArea.selectionEnd = cursorPos.end;
    }
    textArea.focus();
}

// Functie om voor het zoekformulier te zoeken op de website of op google
function setSearchformAction(p_s_action)
{
  if (p_s_action == 'indipenda')
  {
      document.getElementById('form_zoek').action = "zoekresultaat/";
      document.getElementById('trefwoord').name = "search_new";
      document.getElementById('form_zoek').target = "_self";
      document.getElementById('form_zoek').method = "post";
      document.getElementById('search_module_pages').disabled = false;
      document.getElementById('search_module_nieuws').disabled = false;
      document.getElementById('search_module_link').disabled = false;
      document.getElementById('search_module_addressbook_new').disabled = false;
  }
  else if (p_s_action == 'internet')
  {
      document.getElementById('form_zoek').action = "http://www.google.nl/search";
      document.getElementById('form_zoek').method = "get";
      document.getElementById('form_zoek').target = "_blank";
      document.getElementById('trefwoord').name = "q";
      document.getElementById('search_module_pages').disabled = true;
      document.getElementById('search_module_nieuws').disabled = true;
      document.getElementById('search_module_link').disabled = true;
      document.getElementById('search_module_addressbook_new').disabled = true;
  }
}