
/**
 * (c) InfoProjects bv. - www.infoprojects.nl
 *
 * $Revision: 1.17 $
 * $Date: 2010/08/09 12:42:05 $
 * $Author: bas $
 */

function externalLinks() {
  var contents = getElt('page');
  if(contents) {
    if (!document.getElementsByTagName) {
      return;
    }
    var anchors = document.getElementsByTagName('a');
    for(var i=0; i<anchors.length; i++) {
      if(anchors[i].className == 'blank' || anchors[i].className == 'extern') {
        anchors[i].onclick = function() {
          return !window.open(this.href);
        }
      }
      if(anchors[i].className == 'print') {
        anchors[i].onclick = function() {
          print();
        }
      }
    }
  }
}

function flashMovies() {
  var contents = getElt('page');
  if(contents) {
    if (!document.getElementsByTagName) {
      return;
    }
    var anchors = document.getElementsByTagName('a');
    for(var i=0; i<anchors.length; i++) {
      if(anchors[i].className.indexOf("flashMovie") == 0) {
        var href = anchors[i].getAttribute("href");
        var coords = anchors[i].getAttribute("title").split(",");
        createFlashPlayer(anchors[i],href,coords[0],coords[1]);
      }
    }
  }
}

function createFlashPlayer(targetObj,flashMovieUrl,flashMovieWidth,flashMovieHeight) {
  parentObj = targetObj.parentNode;
  parentObj.removeChild(targetObj);
  var o = document.createElement("object");
  o.width = flashMovieWidth;
  o.height = flashMovieHeight;

  var p1 = document.createElement("param");
  p1.name = "movie";
  p1.value = flashMovieUrl;
  o.appendChild(p1);

  var p2 = document.createElement("param");
  p2.name = "quality";
  p2.value = "high";
  o.appendChild(p2);

  var p3 = document.createElement("param");
  p3.name = "allowScriptAccess";
  p3.value = "always";
  o.appendChild(p3);

  var p4 = document.createElement("param");
  p4.name = "wmode";
  p4.value = "transparent";
  o.appendChild(p4);

  var em = document.createElement("embed");
  em.src = flashMovieUrl;
  em.type = "application/x-shockwave-flash";
  em.quality = "high";
  em.allowScriptAccess = "always";
  em.wmode = "transparent";
  em.width = flashMovieWidth;
  em.height = flashMovieHeight;

  try {
    o.appendChild(em);
    parentObj.appendChild(o);
  }
  catch (e) {
    parentObj.appendChild(em);
  }
}


function parseDigitString(s) {
  while (s.length>1 && s.substring(0,1)=="0") {
    s=s.substring(1,s.length);
  }
  return (isNaN(parseInt(s))?0:parseInt(s));
}

function putDigitString(num,digits) {
  num = "" + num;
  while (num.length<digits) {
    num="0" + num;
  }
  return (num);
}

function getClient() {
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase()
  var apv=navigator.appVersion.toLowerCase()
  this.major = parseInt(navigator.appVersion)
  this.minor = parseFloat(navigator.appVersion)
  // browserversion
  this.opera = (agt.indexOf('opera')!=-1);
  this.ns  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
  this.ns4 = (this.ns && (this.minor >= 4.03) && (this.major < 5))
  this.ns6 = (this.ns && (this.major == 5) || this.opera)
  this.gecko = (this.ns && (this.major >= 5))
  this.ie   = (agt.indexOf("msie") != -1)
  this.ie4  = (this.ie && (this.major == 3))
  this.ie45 = (agt.indexOf('msie 4.5') != -1);
  this.ie5  = (this.ie && (this.major == 4))
  this.ie6  = (agt.indexOf('msie 6') != -1)
  this.ie7  = (agt.indexOf('msie 7') != -1)
  this.ie8  = (agt.indexOf('msie 8') != -1)
  // platform
  this.mac = (apv.indexOf("macintosh")>0);
  this.win = (apv.indexOf("win")>0);
  // compatible browsers
  this.ie4comp = ((this.ie4 && !this.mac) || this.ie45 || this.ie5)
  this.ns4comp = (this.ns4);
  this.ns6comp = (this.gecko || this.ns6);
  this.comp = (this.ie4comp || this.ns4comp || this.ns6comp);
  return (this)
}

var is = new getClient();

function openWindow(url,attr) {
  popup = window.open(url,"popup",attr);
  return false;
}

function openPopup(url,name,attr) {
  popup = window.open(url,name,attr);
  return false;
}

function toggleMenu(name,n,alt) {
  if (document.all) {
    if (document.all[name]) {
      document.all[name][1-n].style.display = "none";
      document.all[name][n].style.display = "block";
    }
    else document.reload(alt);
  }
}

function toggleBlock(name,n) {
  if (document.all) {
    for (var i=0; i<document.all[name].length; i++) document.all[name][i].style.display = (n==i)?"block":"none";
  }
}

var centerTop=false;

function updateTopButton() {
  if(getElt("top_button")) {
    var topButton = getElt("top_button");
    if(getWinScrollTop() > 0) {
      setEltVisibility(topButton,'visible');
      setEltDisplay(topButton,'block');
      setEltPosition(topButton,'absolute');

      var difR = 0;

      var difC = ((getWinWidth() - 996)/2) + offsetRight;

      if(eval(centerTop) && maxTopWinWidth && ((parseInt(getWinWidth()))>maxTopWinWidth)) {
        difR = getWinWidth() - difC;
      }
      // breder dan maxwidth
      else if(maxTopWinWidth && (getWinWidth()>maxTopWinWidth)) {
        difR = maxTopWinWidth - offsetRight;
      }
      //smaller dan maxwidth
      else {
        difR = (getWinWidth() - offsetRight);
      }

      setEltLeft(topButton,difR);
      var difT = (getWinHeight() - offsetBottom) + getWinScrollTop();

      setEltTop(topButton,difT);
    } else {
      setEltVisibility(topButton,'hidden');
      setEltDisplay(topButton,'none');
    }
  }
}

// Functie om een methode 'onResize' uit te voeren
function onResize(method) {
  if(is.ns4comp || is.ns6comp) {
    return window.onresize = method;
  } else {
    document.body.onresize = method;
  }
}

// Functie om een methode 'onScroll' uit te voeren
function onScroll(method) {
  if(is.ns4comp || is.ns6comp) {
    return window.onscroll = method;
  } else {
    document.body.onscroll = method;
  }
}

// Functie om een methode 'onMouseMove' uit te voeren
function onMouseMove(method) {
  if (is.ns4comp) document.captureEvents(Event.MOUSEMOVE)
  document.onmousemove = method;
}

function getImage(img) {
  return document.images[img];
}

function swapImage(img,src) {
  document.images[img].src = src;
}

function swapImageAlt(img,alt) {
  document.images[img].alt = alt;
}

function getForm(name) {
  return document.forms[name];
}

function getElt(id) {
  return document.getElementById(id);
}

// --- POSITION ---

function setEltPosition (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.position = value;
  else if (is.ie4comp) elt.style.position = value;
  else if (is.ns6comp) elt.style.position = value;
}

// --- DISPLAY ---

function setEltDisplay (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.display = value;
  else if (is.ie4comp) elt.style.display = value;
  else if (is.ns6comp) elt.style.display = value;
}

function getEltDisplay(elt) {
  if(!elt || elt == null) {
    return;
  }
  if(is.ns4comp) {
    return (elt.display);
  } else if(is.ie4comp) {
    return (elt.style.display);
  } else if(is.ns6comp) {
    return (elt.style.display);
  }
}

// --- VISIBILITY ---

function setEltVisibility (elt, value) {
  if (!elt || elt == null) return;
  if (is.ns4comp) elt.visibility = value;
  else if (is.ie4comp) elt.style.visibility = value;
  else if (is.ns6comp) elt.style.visibility = value;
}

// --- POSITION ---

function setEltLeft (elt, x) {
  if (!elt || elt == null) return;
  if (is.ns4comp)      elt.left=x;
  else if (is.ie4comp) elt.style.pixelLeft=x;
  else if (is.ns6comp) elt.style.left = (x + "px");
}

function setEltTop (elt, y) {
  if (!elt || elt == null) return;
  if (is.ns4comp)      elt.top=y;
  else if (is.ie4comp) elt.style.pixelTop=y;
  else if (is.ns6comp) elt.style.top= (y + "px");
}

function setEltHeight (elt, y) {
  if (!elt || elt == null) return;
  if (is.ns4comp)      elt.height=y;
  else if (is.ie4comp) elt.style.pixelHeight=y;
  else if (is.ns6comp) elt.style.height= (y + "px");
}

function getEltLeft (elt) {
  if (!elt || elt == null) return 0;
  if (is.ns4comp)      return (elt.left);
  else if (is.ie4comp) return (elt.offsetLeft);
  else if (is.ns6comp) return (elt.offsetLeft);
}

function getEltTop (elt) {
  if (!elt || elt == null) return 0;
  if (is.ns4comp)      return (elt.top);
  else if (is.ie4comp) return (elt.offsetTop);
  else if (is.ns6comp) return (elt.offsetTop);
}

function getEltWidth (elt) {
  if (!elt || elt == null) return 0;
  if (is.ns4comp)      return(elt.document.width);
  else if (is.ie4comp) return (elt.offsetWidth);
  else if (is.ns6comp) return (elt.offsetWidth);
}

function getEltHeight (elt){
  if (!elt || elt == null) return 0;
  if (is.ns4comp)      return(elt.document.height);
  else if (is.ie4comp) return (elt.clientHeight);
  else if (is.ns6comp) return (elt.offsetHeight);
}

// --- CLIPPING ---

function setEltClip (elt, cliptop, clipright, clipbottom, clipleft)
{ if (is.ns4comp) {
    elt.clip.left   = clipleft;
    elt.clip.top    = cliptop;
    elt.clip.right  = clipright;
    elt.clip.bottom = clipbottom;
  }
  else if (is.ie4comp)  elt.style.clip = 'rect(' + cliptop + ' ' +
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
  else if (is.ns6comp)  elt.style.clip = 'rect(' + cliptop + ' ' +
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

// --- WINDOW PROPERTIES ---

function getWinWidth()
{ if (document.documentElement && !is.ie6) return (document.documentElement.clientWidth);
  else if (is.ns4comp) return(window.innerWidth);
  else if (is.ie4comp) return(document.body.clientWidth);
  else if (is.ns6comp) return(window.innerWidth);
}

function getWinHeight()
{ if (document.documentElement && !is.ie6) return (document.documentElement.clientHeight);
  else if (is.ns4comp) return(window.innerHeight);
  else if (is.ie4comp) return(document.body.clientHeight);
  else if (is.ns6comp) return(window.innerHeight);
}

function getWinScrollLeft()
{ if (document.documentElement && !is.ie6) return (document.documentElement.scrollLeft);
  else if (is.ns4comp) return(window.pageXOffset);
  else if (is.ie4comp) return(document.body.scrollLeft);
  else if (is.ns6comp) return(window.pageXOffset);
}

function getWinScrollTop()
{ if (document.documentElement && !is.ie6) return (document.documentElement.scrollTop);
  else if (is.ns4comp) return(window.pageYOffset);
  else if (is.ie4comp) return(document.body.scrollTop);
  else if (is.ns6comp) return(window.pageYOffset);
}

// --- MOUSE EVENT PROPERTIES ---

var curMouseY = 0;
function getMouseWinTop(e) {
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageY)
  {
    posy = e.pageY;
  }
  else if (e.clientY)
  {
    if (document.documentElement && !is.ie6) posy = e.clientY + document.documentElement.scrollTop;
    else posy = e.clientY + document.body.scrollTop;
  }
  curMouseY = posy;
  return posy;
}

function updateXY(e) {
  getMouseWinLeft(e);
  getMouseWinTop(e);
}

var curMouseX = 0;
function getMouseWinLeft(e) {
  var posx = 0;
  if (!e) var e = window.event;
  if (e.pageX)
  {
    posx = e.pageX;
  }
  else if (e.clientX)
  {
    if (document.documentElement && !is.ie6) posx = e.clientX + document.documentElement.scrollLeft;
    else posx = e.clientX + document.body.scrollLeft;
  }
  curMouseX = posx;
  return posx;
}

// --- CLASS ---
function getEltClassName(elt) {
  return elt.className;
}

function setEltClassName(elt,val) {
  elt.className = val;
}

function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
  if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

// --- BACKGROUND ---

function setEltBg(elt,val) {
  val = (val.indexOf("url(") != -1)?val:("url('"+val+"')");
  elt.style.backgroundImage = val;
}