/*
Generic functions for www.ylab.nl
Copyright (c) 2003 Ylab, Utrecht, NL
Author: Yohan Creemers
version 1.0
*/

//generic event handling
/*
window.onerror = function(msg, url, line){
  window.status = "Er is een fout opgetreden. Meld dit a.u.b. aan de webmaster. " + line + ": " + msg;
  return true;
}*/

var scrollFunctions = new Array();
function addScrollFunction(f){scrollFunctions[scrollFunctions.length] = new Function(f);}
window.onscroll = function() {for (var i=0; i<scrollFunctions.length; i++){scrollFunctions[i]();}}

var loadFunctions = new Array();
function addLoadFunction(f)  {loadFunctions[loadFunctions.length] = new Function(f);}
window.onload   = function() {for (var i=0; i<loadFunctions.length; i++){loadFunctions[i]();}}

addLoadFunction("window.status = document.title;");

//preload hover images when document is loaded
var hoverImages = new Array();
addLoadFunction("if (hoverImages.length==0){return;} for (var i=0; i<hoverImages.length; i++){(new Image()).src = hoverImages[i];}");

/*Prepare image for hover effect
  Sample use:
  <img onload="imgHover('img01')">
  <img onload="imgHover(this)">
  <img onload="imgHover(this, 'hover.gif')">
  <img onload="imgHover(this, 'text=image')">

  img: image object or image id;
  srcHover: url of hover image [optional]
           : when omitted, the postfix "-hover" is added to the original image path
           : when containing an is-character (=) a part of the original url is altered (e.g. 'text=image')
*/
function imgHover(img, srcHover, hotspot){
  //Initialize only once
  img = id2object(img);
  if (img.initialized){return;}

  //Set properties
  img.initialized = true;//been here
  img.srcNormal = img.src;
  if (srcHover){
    if (srcHover.indexOf("=") != -1){
      //replace part of original url
      var pair = srcHover.split("=");
      img.srcHover=img.src.replace(pair[0],pair[1])
    }
    else{img.srcHover = srcHover;}
  }
  else{
    //add -hover by default
    var extpos = img.src.lastIndexOf(".");
    img.srcHover = img.src.substring(0,extpos) + "-hover" + img.src.substring(extpos);
  }
  hoverImages[hoverImages.length] = img.srcHover;
  //Assign hotspot events
  if (arguments.length < 3){var el=img;}
  else {var el = id2object(hotspot)}
  el.onmouseover = function() {img.src = img.srcHover;}
  el.onmouseout  = function() {img.src = img.srcNormal;}

}

//Convert id into object
function id2object(el){
  if (typeof(el)=="string"){el = document.getElementById(el);}
  return el;
}

//set a style property or fail gracefully
function setStyle(objectId, prop, value){
  var obj = document.getElementById(objectId);
  if ((obj) && (obj.style[prop] != value)){
    obj.style[prop] = value;
  }
}

/*display mailto link
  Sample use:
  printMail("Pim");
  printMail("Pim", "Secretaris");

  username: the username part of the email address
  linktext: the visible text of the hyperlink [optional]
*/
function printMail(username, linktext){
  username = username.toLowerCase() + "@ylab.nl";
  if (!linktext) {linktext = username;}
  //document.write(linktext.link("mailto:" + username));
  document.write('<a href="mailto:' + username + '" class="email">' + linktext + '</a>');
}

/*open popup window
  Sample use:
  <a href="url" title="Pagina opent in een nieuw venster" onclick="return openPopup(this.href, 500, 600, true);" >De pagina</a>

  url      : location of the desired document
  width    : width of the popup window [optional]
  height   : height of the popup window [optional]
*/
function openPopup(url, width, height, resizable, toolbar, menubar) {
  var args = new Array();
  if (width){
    width = Math.min(width, screen.availWidth);
    args.push("width=" + width);
    args.push("left=" + (screen.width - width)/2);
  }
  if (height){
    height = Math.min(height, screen.availHeight);
    args.push("height=" + height);
    args.push("top=" + (screen.height - height)/2);
  }
  if (resizable){args.push("resizable=yes,scrollbars=yes");}
  if (toolbar){args.push("toolbar=yes");}
  if (menubar){args.push("menubar=yes");}
  window.status=args.join();
  window.open(url, '', args.join());
  return false;
}

function styleAbbr() {
  if(document.all){
    var oldBodyText = document.body.innerHTML;
    var reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
    var newBodyText = oldBodyText.replace(reg, '<abbr $1><span class=\"abbr\" $1>$2</span></abbr>');
    document.body.innerHTML = newBodyText;
    alert(oldBodyText==newBodyText);
  }
}


