   function getParentNode(elem, searchtag)
   {
     while(elem.tagName.toLowerCase() != searchtag)
     {
       if(!elem.parentNode)
         return false;
       elem = elem.parentNode;
     }
     return elem;
   }
   
   function findParent(elem, searchtag) {
    return getParentNode(elem,searchtag);
  }
  
  /* Array intersect script with thanks to dakyd:
   * http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21924445.html
   */  
  function array_intersect(arr1, arr2) {
    arr1.sort();
    arr2.sort();

    var common = new Array();
    for (var i = 0, n = arr1.length, j = 0, k = arr2.length; (i < n) && (j < k); i ++) {
      if (arr1[i] == arr2[j]) {
        common.push(arr1[i]);
        j ++;
      } else if (arr1[i] > arr2[j]) {
        j ++;
        i --;
      }
    }
    
    return common;
  }

  var tdisabled = "table,row_before,row_after,sub,sup,fontselect,spacer,styleselect,help,delete_row,rowseparator,col_before,col_after,delete_col,removeformat,visualaid,hr,charmap,separator,"   
  var tbefore1 = "";
  var tafter1  = "";
  var tbefore2 = "";
  var tafter2  = "";
  if(typeof TMCEopts != "undefined") {
    tdisabled = tdisabled.replace(TMCEopts, '');
  } 
  if(typeof TMCEoptss != "undefined") {
    tbefore1 = array_intersect(TMCEoptss, new Array("")).join(",");
    tbefore2 = array_intersect(TMCEoptss, new Array("forecolor","backcolor")).join(",");
    tafter1  = array_intersect(TMCEoptss, new Array("")).join(",");
    tafter2  = array_intersect(TMCEoptss, new Array("")).join(",");
  }
  
  
   
  try {
    tinyMCE.init({
    mode : "specific_textareas"
    ,textarea_trigger : "richtext"
    ,language : "nl"
    ,theme_advanced_toolbar_location : "top"
    ,theme_advanced_toolbar_align : "left"
    ,theme_advanced_disable  : tdisabled
    ,theme_advanced_buttons1_add_before : tbefore1
    ,theme_advanced_buttons1_add : "rwdevimages," + tafter1
    ,theme_advanced_buttons2_add_before : tbefore2
    ,theme_advanced_buttons2_add : tafter2
    //,document_base_url : "<?=URL_SITE;?>"
    ,relative_urls : false
    ,remove_script_host : false
    ,auto_reset_designmode : true
    ,plugins:"rwdevimages"
    ,rwdevimages_base : true
    });
  } catch(e) {
  }
  
  function toolTipOver(elem, id) {
    if(!elem.className) {
      elem.className = "ToolTipActive";
    } else {
      elem.className += " ToolTipActive";
    }
    d = document.getElementById(id);
    if(!d) {return;}
    if(!d.className) {
      d.className =  "ToolTipActive";
    } else {
      d.className += " ToolTipActive";
    }
  }
  
  function toolTipOut(elem, id) {
    elem.className = elem.className.replace("ToolTipActive","");
    d = document.getElementById(id);
    if(!d) return;
    d.className = d.className.replace("ToolTipActive","");
  }
  
  var TabBoxes = new Array();
  
  function TabBoxesInit() {
    for(i = 0; i < TabBoxes.length; i++) {
      TabBoxes[i].init();
    }
  }
  
  function TabBox(boxElemId, tabNodeIds) {
    if(TabBoxes.length == 0) {
      this.oldinit = window.onload;
      window.onload = function() {setTimeout('TabBoxesInit();',100);}
      window.onload = TabBoxesInit;
    }
    this.boxElemId = boxElemId;
    this.tabNodeIds = tabNodeIds;
    this.tabs = new Array();
    this.boxElem = '';
    TabBoxes.push(this);
    
    this.init = function() {
      if(this.oldinit) {
          this.oldinit();
      }
      /* Retrieve tab container */
      this.boxElem = document.getElementById(this.boxElemId);
      
      /* Retrieve Elements */
      for(elemId in this.tabNodeIds) {
        if(document.getElementById(elemId)) {
          document.getElementById(elemId).TabObj = this;
          document.getElementById(elemId).TabLabel = this.tabNodeIds[elemId];
          this.tabs.push(document.getElementById(elemId));
        }
      }  
      
      /* Create tabs */
      var tabIndex = 0;
      
      var tabs = document.createElement('div');
          tabs.className = "TabContainer";
      
      var initTabId = ((i = window.location.href.indexOf('#')) > 0 ? window.location.href.substring(i+1) : "");
      
      for(i = 0; i < this.tabs.length; i++) {
        var tab = document.createElement('a');
        tab.innerHTML = this.tabs[i].TabLabel;
        tab.className = "Tab";
        tab.href = "#" + this.tabs[i].id;
        tab.name = this.tabs[i].id;
        tab.TabObj = this;
        tab.TabObjIndex = i;
        tab.divID = this.tabs[i].id.replace(/[^\w]/,'');
        tab.onclick = function() {
          this.TabObj.selectTab(this.TabObjIndex);
        }
        this.tabs[i].style.display = "none";
        this.tabs[i].TabTab = tab;
        tabs.appendChild(tab);
        if(initTabId == tab.divID) {
          tabIndex = i;
        }
      }
      
      this.selectTab(tabIndex);
      
      /* Add tabs to html */
      if(this.boxElem) {
        this.boxElem.insertBefore(tabs, this.boxElem.firstChild);
      }
    }
    
    this.selectTab = function(tabIndex) {
      for(i = 0; i < this.tabs.length; i++) {
        this.tabs[i].style.display = (tabIndex==i ? "" : "none");
        this.tabs[i].TabTab.className = (tabIndex==i ? "Tab TabActive" : "Tab");
      }
    }
  }
