/*
     $Revision$
     $Id$

     File:          logger.js
     Description:   Wordt bij OTAP==O bijgeladen om SELECT in logfile klikbaar te maken
*/

function showSQL(sql)
{
    window.genericsql = sql;
    var url = "../mgt/mgt_genericsql.asp?sql=opener"; // requires window.opener and is safe
    window.open(url);
}

document.addEventListener("DOMContentLoaded", function(event) {
  var clearform = document.getElementById('clearform');
  clearform.style.display = 'block';
  var times = document.getElementsByClassName('tm');
  if (times.length > 500)
  {
    elem = document.createElement("div");
    elem.innerHTML = '<em>Te veel (' + times.length + ') SELECTs, geen automatische linkjes</em>'
    document.body.insertBefore(elem,document.body.childNodes[0]);
    return;
  }
  for (var i = 0; i < times.length; i++)
  {
    var tddata = times[i].nextElementSibling;
    if (tddata.innerText.substr(0, 6).toUpperCase() == 'SELECT')
    {
        var linkje = '<a href="#" onclick="showSQL(this.parentElement.innerText);return false;" title="View SQL">SELECT</a>';
        tddata.innerHTML = tddata.innerHTML.replace(/SELECT/i, linkje); // Doet alleen de eerste
    }
  }
});