function trim(value) {
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}

function zoekform_onclick() {
    var id = document.getElementById("zoekform");
	if (id.q.value) {
	    id.q.value = trim(id.q.value);
	    if (id.q.value) {
       		id.submit();
       	}
	}
}

function zoekform_onsubmit() {
    var id = document.getElementById("zoekform");
	if (id.q.value) {
	    id.q.value = trim(id.q.value);
	    if (id.q.value) {
       		return true;
       	}
	}
	return false;
}

function routeform_onclick() {
    var id = document.getElementById("routeform");
	if (id.saddr.value) {
		id.saddr.value = trim(id.saddr.value);
     	if ((id.saddr.value.search(/^\d{4}[a-zA-Z]{2}$/)) != -1) {
      		id.submit();
       	} else {
			alert("U heeft het veld postcode niet juist ingevuld. Vul de postcode in met notatie 1234AB");
			id.reset();
		}
	}
}

function routeform_onsubmit() {
    var id = document.getElementById("routeform");
	if (id.saddr.value) {
		id.saddr.value = trim(id.saddr.value);
     	if ((id.saddr.value.search(/^\d{4}[a-zA-Z]{2}$/)) != -1) {
   			return true;	
       	}
		alert("U heeft het veld postcode niet juist ingevuld. Vul de postcode in met notatie 1234AB");
		id.reset();
	}
	return false;
}

function bladwijzer(bladwijzer) {
	if (window.location.hash) {
		var oTbw = window.location.hash.replace("#","T");
		if (document.getElementById(oTbw) != null) {
			document.getElementById(oTbw).className = "bladwijzer";
		}
		var oWbw = window.location.hash.replace("#","W");
		if (document.getElementById(oWbw) != null) {
			document.getElementById(oWbw).className = "bladwijzer";
		}
	}
	var nTbw = 'T' + bladwijzer;
	if (document.getElementById(nTbw) != null) {
		document.getElementById(nTbw).className = "bladwijzeraan";
	}
	var nWbw = 'W' + bladwijzer;
	if (document.getElementById(nWbw) != null) {
		document.getElementById(nWbw).className = "bladwijzeraanwide";
	}
}

function bladwijzeronload() {
	if (window.location.hash) {
		var nTbw = window.location.hash.replace("#","T");
		if (document.getElementById(nTbw) != null) {
			document.getElementById(nTbw).className = "bladwijzeraan";
		}
		var nWbw = window.location.hash.replace("#","W");
		if (document.getElementById(nWbw) != null) {
			document.getElementById(nWbw).className = "bladwijzeraanwide";
		}
	}
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return [ scrOfY ];
}

function windowHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return [ myHeight ];
}

function settopposdivsidebar() {
	var hs = document.getElementById('sidebar').offsetHeight;
	var ts = 0;
	ts = document.getElementById('sidebar').offsetTop;
	if ((document.documentElement.clientHeight >  hs) && (document.documentElement.scrollTop > ts)) {
		document.getElementById('sidebar').style.top =(document.documentElement.scrollTop - ts) + 'px';
	} else { 
		document.getElementById('sidebar').style.top = '156px';
	}
    settimeout(settopposdivsidebar(),10000);
}

window.onscroll = function () {
	var sb = document.getElementById("sidebar");
	var ts = 156;
	var sy = getScrollY();
	var wh = windowHeight();
	nt = 156;
	if ((wh > sb.offsetHeight) && (sy > ts)) {
		nt = sy;
	} 
    sb.style.top = nt + 'px';
}

window.onload = function () {
	var sb = document.getElementById("sidebar");
	var ts = 156;
	var sy = getScrollY();
	var wh = windowHeight();
	nt = 156;
	if ((wh > sb.offsetHeight) && (sy > ts)) {
		nt = sy;
	} 
    sb.style.top = nt + 'px';
}

window.onresize = function () {
	var sb = document.getElementById("sidebar");
	var ts = 156;
	var sy = getScrollY();
	var wh = windowHeight();
	nt = 156;
	if ((wh > sb.offsetHeight) && (sy > ts)) {
		nt = sy;
	} 
    sb.style.top = nt + 'px';
}
