var cur = ''
var scur = ''

showcontactadres = function(contactadresid) {
 navRoot = document.getElementById("contactadressen");
 for (i=0; i<navRoot.childNodes.length; i++) {
  node = navRoot.childNodes[i];
  if (node.className == "contactadres" && node.style.display != 'none' && node.id != contactadresid) {
   //node.childNodes[0].childNodes[0].innerHTML = "&#9658;";
   hidecontactadres(node.id);
  }
 }
 //$(contactadresid).childNodes[0].childNodes[0].innerHTML = "&#9660;";
 new Effect.toggle(contactadresid,'blind');
 cur = contactadresid;
 return false;
}

hidecontactadres = function(contactadresid) {
 new Effect.toggle(contactadresid,'blind');
 return false;
}

showspecialismecontactadres = function(specialisme_contactadresid) {
 navRoot = document.getElementById("specialismen_contactadressen");
 for (i=0; i<navRoot.childNodes.length; i++) {
  node = navRoot.childNodes[i];
  if (node.className == "specialisme_contactadres" && node.style.display != 'none' && node.id != specialisme_contactadresid) {
   hidespecialismecontactadres(node.id);
  }
 }
 new Effect.toggle(specialisme_contactadresid,'blind');
 scur = specialisme_contactadresid;
 return false;
}

hidespecialismecontactadres = function(specialisme_contactadresid) {
 new Effect.toggle(specialisme_contactadresid,'blind');
 return false;
}

checkNBForm = function(form) {
if (form.initialen.value == "" || form.initialen.value == "initialen") {
 alert( "Voer hier uw voorletters in" );
 form.initialen.focus();
 return false ;
}
if (form.achternaam.value == "" || form.achternaam.value == "achternaam") {
 alert( "Voer hier uw achternaam in" );
 form.achternaam.focus();
 return false ;
}
valid = new RegExp("^[a-zA-Z0-9]+([.]?[a-zA-Z0-9_-]+)*[@]([a-zA-Z0-9_-]+[.])+([a-zA-Z]{2,4})$").exec(form.email.value);
if (form.email.value == ""  || form.email.value == "email adres" || !valid) {
 alert( "Voer hier uw mail adres in" );
 form.email.focus();
 return false ;
}
return true;
}
function checkinput(inputname,message,form,type) {
 thabool = 0;
 //if (type == 'string'){ if (form[inputname].value != '') { thabool = 1; } }
 if (type == 'int' || type == 'integer'){
  valid = new RegExp("^[0-9]+$").exec(form[inputname].value);
  if (valid) { thabool = 1; } 
 }
 else if (type == 'email'){  
  valid = new RegExp("^[a-zA-Z0-9]+([.]?[a-zA-Z0-9_-]+)*[@]([a-zA-Z0-9_-]+[.])+([a-zA-Z]{2,4})$").exec(form[inputname].value);
  if (valid) { thabool = 1; } 
 }
 else { if (form[inputname].value != '') { thabool = 1; } } // String
 if (thabool == 0) {
  alert(message);
  Fat.fade_element(inputname);
  thisinput = document.getElementsByName(inputname)[0];
  form[inputname].focus();
  thisinput.className = thisinput.className+' warning';
  divje = thisinput.parentNode;
  divje.className = divje.className+' warning';
  return false;
 } else { return true; }
}
function checkJSDate(inputname,message,form,type,force){
 var el = form[inputname];
 var valid = new RegExp("^^[0-3][0-9][-]([0][0-9]|[1][0-2])[-][0-9]{4}$").exec(el.value);
 if((!valid && el.value != '')||(!valid && force)){
   alert("Ongeldige format. voorbeeld: dd-mm-yyyy");
   Fat.fade_element(inputname);
   el.focus();
   return false;
 }else if(valid){
    day =parseInt(el.value.substr(0,2),10);
    month = parseInt(el.value.substr(3,2),10)-1;
    year = el.value.substr(6,4);
    dteDate=new Date(year,month,day);
    if(month != dteDate.getMonth() || day != dteDate.getDate() || year != dteDate.getFullYear()){
      alert("Niet bestaande datum ingevoerd" );
      Fat.fade_element(inputname);
      el.focus();
      return false;
    }
 }
 return true;
}

submitcheckNBForm = function(form) {
 if(checkNBForm(form)) {
  form.submit();
 }
}

function getSize(){
  maxW=parseInt(0);
  maxH=parseInt(0);
  mode=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
                if(parseInt(myWidth) > maxW){maxW=myWidth;}
                if(parseInt(myHeight) > maxH){maxH=myHeight;}
                mode=1;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
                if(parseInt(myWidth) > maxW){maxW=myWidth;}
                if(parseInt(myHeight) > maxH){maxH=myHeight;}
                mode=2;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
                if(parseInt(myWidth) > maxW){maxW=myWidth;}
                if(parseInt(myHeight) > maxH){maxH=myHeight;}
                mode=3;
	}
  if (parseInt(document.body.clientHeight) > parseInt(maxH)){maxH=document.body.clientHeight;}
  if (parseInt(document.body.clientWidth) > parseInt(maxW)){maxW=document.body.clientWidth ;}
  var popovers = $('body').select('.popover_container');
  if(popovers.length > 0){
    poph = parseInt(popovers[0].offsetTop+popovers[0].scrollHeight+20);
    popw = parseInt(popovers[0].offsetLeft+popovers[0].scrollWidth+20);
    if(poph>maxH){
      maxH = poph;
    }
    if(popw > maxW){
      maxW = popw;
    }
  }
  return Array(myWidth,myHeight,maxW,maxH,mode);
}
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function genPopOver(holder){
  if(!$(holder)){
    var text = '<div id=\"'+holder+'\" class=\"popover_container\" style=\"display:none;\"><div class=\"ajax_loader\"><img class=\"ajax_loader\" src=\"\/loader.gif\" alt=\"loading\" \/><\/div><\/div>'; //style=\"display:none;\"
    $('body').insert({Bottom:text});
    showPopOver(holder);
  }
  genPopOverBack();
}
function genPopOverBack(){
  ssize = getSize();
  var divs = $('body').select('div.popover_container');
  var back = '<div id=\"popover_back\" style=\"width:'+ssize[2]+'px;height:'+ssize[3]+'px;\"></div>';
  removePopOverBack();
  if(divs.length > 0){
    divs[0].insert({Before:back});
  }else{
    $('body').insert({Bottom:back});
  }
  resizePopOverBack();
}
function resizePopOverBack(){
 ssize = getSize();
 if($('popover_back')){
  $('popover_back').style.width = ssize[2]+'px';
  $('popover_back').style.height = ssize[3]+'px';
 }
}
function removePopOverBack(){
  if($('popover_back')){
    $('popover_back').remove();
  }
}
function clearPopOvers(){
  var divs = $('body').select('div.popover_container');
  for(var i=0;i<divs.length;i++){
   divs[i].remove();
  }
  removePopOverBack();
}
function closePopOver(holder){
 new Effect.Fade(holder,{duration:0.5,afterFinish:function(){$(holder).remove();removePopOverBack();}});
}
function showPopOver(holder){
 var ssize = getSize(); //Array(myWidth,myHeight,maxW,maxH,mode);
 $(holder).style.display = '';
 var height = $(holder).offsetHeight;
 var width = $(holder).offsetWidth;
 $(holder).style.display = 'none';
 var left = parseInt((ssize[0]-width)/2);
 $(holder).style.left = left+'px';
 var scrolltop = f_scrollTop();
 var top = parseInt(scrolltop)+parseInt(parseInt(ssize[1]-height)/2);
 $(holder).style.top = top+'px'; 
 $(holder).style.display ='';
 new Effect.Appear(holder,{duration:0.5});
}
var defaultheight = 300;
function resizePopOverHeight(id){
  el = $(id);
  var diffspace = 22;
  if(el.scrollHeight <= defaultheight){
    return '';
  }
  else if((el.scrollHeight-diffspace) < el.getHeight()){
    //el.style.height = el.scrollHeight+"px";
    new Effect.Morph(el,{style:'height:'+defaultheight+'px',afterFinish:function(){resizePopOverBack();}});
  }else{
    //el.style.height = el.scrollHeight+"px";
    defaultheight = el.getHeight()-diffspace;
    new Effect.Morph(el,{style:'height:'+(el.scrollHeight-(diffspace-4))+'px',afterFinish:function(){resizePopOverBack();}});
  } 
}
genPopPage = function genPopPage(holder,cscript){
  genPopOver(holder);
  new Ajax.Updater(holder,'/genpoppage',{evalScripts:true,parameters:'js=1&mode=popover&popholder='+holder+'&cscript='+cscript} );
/*  new Ajax.Updater(holder,'/genpoppage',{parameters:'js=1&mode=popover&popholder='+holder+'&cscript='+cscript,evalScripts:true,onComplete:function(){showPopOver(holder);}});*/
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

showActiveStyleSheet = function(el) {
 if (el != null) {
  nodes = $('contentstyles').childElements();
  for(var i=0;i<nodes.length;++i) {
   nodes[i].style.textDecoration = 'none';
   if(nodes[i].id == el.id) {
    nodes[i].style.textDecoration = 'underline';
   }
  }
 }
 else {
  setActiveStyleSheet('default');
 }
}
