/*   JSgui/page_pre.js
   created 2009-07-09 by Yann GUIDON
   version 2009-07-27 : detect french pages
*/

const version_date="2009-08-10";

//////////// create the hooks for opcode tags

function link_opcodes() {
  var target_address="tools/opcode_map.html#";
  // detect the page's language
  if (document.location.pathname.indexOf("_fr.html")>0)
    target_address="tools/opcode_map_fr.html#";

  // Scan all the <a> tags
  var u=document.getElementsByTagName('a');
  for (var i in u){
    var t=new String(u[i].innerHTML);
    // assembly
    if (u[i].className=="opcode") {
      u[i].href=prfx+target_address+t;
    }
  }
}


/// found at http://simonwillison.net/2004/May/26/addLoadEvent/
/// the oldest added function will be called first

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// another version where the last is called first :
function addLoadEventBefore(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      func();
      if (oldonload) {
        oldonload();
      }
    }
  }
}

addLoadEvent(link_opcodes);

