// tools.js - function library
// (c) 2005 Q42 BV

var userAgent    = navigator.userAgent.toLowerCase();
var appVersion   = navigator.appVersion.toLowerCase();
var appName      = navigator.appName.toLowerCase();

// operating system and browser information
var isWin        = (appVersion.indexOf('windows') != -1);
var isOpera      = (userAgent.indexOf('opera') != -1);
var isIE         = (appName.indexOf('internet explorer') != -1) && !isOpera;
var isSafari     = (userAgent.indexOf('applewebkit') != -1);
var isMozilla    = (appName.indexOf('netscape') != -1) && !isSafari;

// build versionString
if (isSafari)
  var versionString = appVersion.substr(v.lastIndexOf("safari/") + 7, 3);
else if (isIE || isOpera)
  var versionString = appVersion.substring(appVersion.indexOf('msie') + 5);
else if (isMozilla)
  var versionString = userAgent.substring(userAgent.indexOf('rv:')+3, userAgent.indexOf('rv:') + 6);
else
  var versionString = appVersion;

// cast version to numeric
var version = parseFloat(versionString);
var ie50 = isWin && isIE && (version <= 5.01);

// array push and pop support for IE50 and others
if (!Array.prototype.push)
  Array.prototype.push = function(el)
  {
    this[this.length] = el;
  };

if (!Array.prototype.pop)
  Array.prototype.pop = function()
  {
    var el = this[this.length-1];
    this.length--;
    return el;
  };


// string trim
String.prototype.trim = function()
{
  var s=this;
  while (s.length>0 && s.charAt(0)==' ') s=s.substring(1);
  while (s.length>0 && s.charAt(s.length-1)==' ') s=s.substring(0,s.length-1);
  return s;
};

// crossPlatform attachEvent
function attachEventHandler(theEl, theEvent, theHandler)
{
  theEvent = theEvent.toLowerCase();
  if (isWin && isIE)
    theEl.attachEvent(theEvent, theHandler);
  else if (isMozilla)
  {
    if (theEl == document.body)
      theEl = document;
    if (theEvent == "ondragstart")
      theEvent = "ondraggesture";
    theEl.addEventListener(theEvent.substring(2), theHandler, true);
  }
};

// turn nnevent into normal event
function buildEvent(nnevent) {
  var evt =
  {
    x:nnevent.clientX,
    y:nnevent.clientY,
    clientX:nnevent.clientX,
    clientY:nnevent.clientY,
    srcElement:nnevent.target,
    keyCode:nnevent.which
  };
  return evt;
};

function getXMLDOM()
{
  if (isMozilla)
    return document.implementation.createDocument("text/xml", "", null);
  if (isIE)
    return new ActiveXObject("Microsoft.XMLDOM");
}
function getXMLHTTP()
{
  if (isMozilla)
    return new XMLHttpRequest();
  if (isIE)
    return new ActiveXObject("Microsoft.XMLHTTP");
}

function getElementsByTagNameAttributeValue(ancestorEl, tagName, attrName, attrValue)
{
  if (typeof(attrValue) == 'undefined')
    attrValue = null;
  var els = [];
  var a = ancestorEl.getElementsByTagName(tagName);
  for (var i=0; i<a.length; i++)
  {
    var el = a[i];
    if (attrName == "className")
      var val = el.className;
    else
      var val = el.getAttribute(attrName);
    if ((val != null) && ((attrValue == null) || (val == attrValue)))
      els.push(el);
  }
  return els;
};

function getParentElementByTagNameAttributeValue(el, tagName, attrName, attrValue)
{
  if (typeof(attrValue) == 'undefined')
    attrValue = null;

  tagName = tagName.toLowerCase();

  while (el && el.getAttribute && el.parentNode)
  {
    if (el.tagName && (el.tagName.toLowerCase() == tagName))
    {
      if (attrName == "className")
        var val = el.className;
      else
        var val = el.getAttribute(attrName);
      if ((val != null) && ((attrValue == null) || (val == attrValue)))
        return el;
    }
    el = el.parentNode;
  }

  return null;
};

/* TOOLS VAN CHRIS */
function updateFoto(src, bijschrift)
{
	var elFoto = document.getElementById('foto');
	var elBijschrift = document.getElementById('bijschrift');

	elFoto.setAttribute('src', src);
	elBijschrift.innerHTML = bijschrift;
}