// MULTIPLE ONLOADS

// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

// Call the following with your function as the argument
// SafeAddOnload(yourfunctioname);

// END MULTIPLE ONLOADS

function element(id) {
	if(document.getElementById != null) {
		return document.getElementById(id);
	}
	if (document.all != null) {
		return document.all[id];
	}
	if (document.layers != null) {
		return document.layers[id];
	}
	return null;
}
function elements(ids) {
	a = new Array();
	for(var i in ids) {
		a.push(element(ids[i]));
	}
	return a;
}
function nobubble(e)
{
	if (!e) var e = window.event;
	if (e) {
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
//		if (e.preventDefault) e.preventDefault();
	}
}
var bmtimer = null;

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

/*var browser = new Browser();

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {
  var el;

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  if (getContainerWith(el, "DIV", "browsemenu") == null) {
	browsemenuhide();
  }
}*/

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}
function send_form(name,action) {
	var el = document.getElementById(name);
	if (action) el.action=action;
	el.submit();
}

/* Rekel cookies */

function RekelCookie(name) {
	if (!name) name = 'rekel';
	if (document.cookie.length) { 
		this.cookies = ' ' + document.cookie; 
	}
	this.cookiename = name;
}

RekelCookie.prototype.setCookie = function (key, value) {
	c = this.getCookieContents();
	if(c) { a = c.split(','); }
	else a = new Array();
	b = new Array();
	if (a.length) {
		for(var i in a) {
			if(a[i].substr(0,key.length+1)!=key+':') {
				b.push(a[i]);
			}
		}
	}
	if (value!=false) b.unshift(key+":"+value);
	c = this.cookiename + "=" + b.join(',');
	document.cookie = c;
}

RekelCookie.prototype.getCookieContents = function () {
	if (document.cookie.length) {
		this.cookies = ' ' + document.cookie; 
		var start = this.cookies.indexOf(' ' + this.cookiename + '=');
		if (start == -1) { return null; }
		var end = this.cookies.indexOf(";", start);
		if (end == -1) { end = this.cookies.length; }
		end -= start;
		var cookie = this.cookies.substr(start,end);
		return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
	}
	else { return null; }
}

RekelCookie.prototype.getCookie = function (key) {
	c = this.getCookieContents();
	if (c) {
		if (a = c.split(',')) for(var i in a) {
			if(a[i]==key) {
				return 1;
			}
		}
		return null;
	}
	else { return null; }
}

/* ! Rekel cookies */

function enquete_submit(formname) {
	var antwoord=0;
	var form = element(formname);
	if (form.elements['enquete'][0].checked) antwoord = 1;
	else if (form.elements['enquete'][1].checked) antwoord = 2;
	else if (form.elements['enquete'][2].checked) antwoord = 3;
	else return false;
	var div_vraag = element('enquete_vraag');
	var div_antwoord = element('enquete_antwoord'+antwoord);
	div_vraag.style.display='none';
	div_antwoord.style.display='';
}

function postcodelookup() {
	var f = document.forms[0];
	if (!f.elements['f[postcode]'].value) return;
	if (!f.elements['f[huisnummer]'].value) return;
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

	xmlhttp.open("GET", "services/postcodelookup.php?query="+f.elements['f[postcode]'].value+f.elements['f[huisnummer]'].value,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		var x = xmlhttp.responseXML;
		var e = '';
		if (x) {
			e = x.getElementsByTagName('straatnaam');
			var straatnaam = '';
			if (e && e[0]) {
				straatnaam = e[0].firstChild.data;
			}
			e = x.getElementsByTagName('plaatsnaam');
			var plaatsnaam = '';
			if (e && e[0]) {
				plaatsnaam = e[0].firstChild.data;
			}
			e = x.getElementsByTagName('provincienaam');
			var provincienaam = '';
			if (e && e[0]) {
				provincienaam = e[0].firstChild.data;
			}
			e = x.getElementsByTagName('cebucocode');
			var cebucocode = '';
			if (e && e[0]) {
				cebucocode = e[0].firstChild.data;
			}
			var f = document.forms[0];
			if (straatnaam) {
				if (f.elements['f[straatnaam]']) f.elements['f[straatnaam]'].value=straatnaam;
			}
			if (plaatsnaam) {
				if (f.elements['f[woonplaats]']) f.elements['f[woonplaats]'].value=plaatsnaam;
			}
			if (provincienaam) {
				if (f.elements['f[provincie]']) f.elements['f[provincie]'].value=provincienaam;
			}
			if (cebucocode) {
				if (f.elements['f[cebucocode]']) f.elements['f[cebucocode]'].value=cebucocode;
			}
		}
	  }
	 }
	 xmlhttp.send(null)
}
function postcodelookup2() {
	var f = document.forms[0];
	if (!f.elements['f[factuuradres_postcode]'].value) return;
	if (!f.elements['f[factuuradres_huisnummer]'].value) return;
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

	xmlhttp.open("GET", "services/postcodelookup.php?query="+f.elements['f[factuuradres_postcode]'].value+f.elements['f[factuuradres_huisnummer]'].value,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		var x = xmlhttp.responseXML;
		var e = '';
		if (x) {
			e = x.getElementsByTagName('straatnaam');
			var straatnaam = '';
			if (e && e[0]) {
				straatnaam = e[0].firstChild.data;
			}
			e = x.getElementsByTagName('plaatsnaam');
			var plaatsnaam = '';
			if (e && e[0]) {
				plaatsnaam = e[0].firstChild.data;
			}
			var f = document.forms[0];
			if (straatnaam) {
				if (f.elements['f[factuuradres_straatnaam]']) f.elements['f[factuuradres_straatnaam]'].value=straatnaam;
			}
			if (plaatsnaam) {
				if (f.elements['f[factuuradres_plaats]']) f.elements['f[factuuradres_plaats]'].value=plaatsnaam;
			}
		}
	  }
	 }
	 xmlhttp.send(null)
}
