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))
  // 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 (getElt(name)) {
    getElt(name)[1-n].style.display = "none";
    getElt(name)[n].style.display = "block";
  }
  else document.reload(alt);
}

function toggleBlock(name,n) {
  for (var i=0; i<getElt(name).length; i++) getElt(name)[i].style.display = (n==i)?"block":"none";
}

/*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";
  }
}*/

// 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 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;
}

// --- 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 getEltTop (elt) {
  if (!elt || elt == null) return 0;
  if (is.ns4comp)     return (elt.top);
  else if (is.ie4comp) return (elt.style.pixelTop);
  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 getWinHeight() 
{ if (is.ns4comp) return(window.innerHeight);
  else if (is.ie4comp) return(document.body.clientHeight);
  else if (is.ns6comp) return(window.innerHeight);
}

function getWinScrollLeft()
{ if (is.ns4comp) return(window.pageXOffset);
  else if (is.ie4comp) return(document.body.scrollLeft);
  else if (is.ns6comp) return(window.pageXOffset);
}

function getWinScrollTop()
{ if (is.ns4comp) return(window.pageYOffset);
  else if (is.ie4comp) return(document.body.scrollTop);
  else if (is.ns6comp) return(window.pageYOffset);
}

// --- MOUSE EVENT PROPERTIES ---

function getMouseWinTop(e) {
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageY)
	{
		posy = e.pageY;
	}
	else if (e.clientY)
	{
		posy = e.clientY + document.body.scrollTop;
	}
  return posy;
}

function getMouseWinLeft(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX)
	{
		posx = e.pageX;
	}
	else if (e.clientX)
	{
		posx = e.clientX + document.body.scrollLeft;
	}
  return posx;
}

// --- CLASS ---
function getEltClassName(elt) {
  return elt.className;
}

function setEltClassName(elt,val) {
  elt.className = val;
}

// --- BACKGROUND ---

function setEltBg(elt,val) {
  val = (val.indexOf("url(") != -1)?val:("url('"+val+"')");
  elt.style.backgroundImage = val;
}
