////////////////////////////////////////////////////////
/* default lib javascript */
////////////////////////////////////////////////////////


//------------------------------------------------------
// init

window.onload = init;
function init(){

  autoRunZappMenu('navList','A')

// Trigger Replace Select
// (document.all && !window.print) ? null : setForm();

// Trigger Slideshow
// runSlides();

}

// End init
//------------------------------------------------------


//------------------------------------------------------
// IE Detect (Windows only!)

var detect = navigator.userAgent.toLowerCase();

// use this variable to check if browser is Internet Explorerfor Windows
var WinIE;

if (checkIt('msie')) WinIE = true;
if (checkIt('opera')||checkIt('mac')) WinIE = false;
function checkIt(string){
  place = detect.indexOf(string) + 1;
  return place;
}
// End IE Detect
//------------------------------------------------------


//------------------------------------------------------
// Jump to the next input 'elm' after 'n' chracters

function jumpTab(elm,n){
  if (elm.value.length>=n){
    var pe=fcd((fns((fpd(elm,'DIV')),'DIV')),'INPUT');
    pe.focus();
  }
}
//------------------------------------------------------


//------------------------------------------------------
// toggle all checkboxes within element id (elID)

function checkAll(elID){
  var el=document.getElementById(elID);
  var e=fpd(el,'UL');
  var i = e.getElementsByTagName('INPUT');
  el.onclick=function(){
    this.checked = (this.checked) ? true : false;
    for(n=0;n<i.length;n++){
      if(i[n]==this)continue;
      if(!i[n].checked)i[n].checked=true;
    }
  }
  for(n=0;n<i.length;n++){
    if(i[n]==el)continue;
    i[n].onclick=function(){
      if(!this.checked)el.checked=false;
    }
  }
}
//------------------------------------------------------


//------------------------------------------------------
// setting the wrapper width by setting it's ID name

function sPW(sw,ws,wl,we){
  var s = new gMS();
  we.id = ( s.w > sw ) ? wl : ws;
}
//------------------------------------------------------

//------------------------------------------------------
// returns web client window width and height [crossbrowser]

function gMS(w,h){
  if( typeof( window.innerWidth ) == 'number' ) {
    this.w = window.innerWidth;
    this.h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    this.w = document.documentElement.clientWidth;
    this.h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    this.w = document.body.clientWidth;
    this.h = document.body.clientHeight;
  }
}
//------------------------------------------------------


//------------------------------------------------------
// Font sizing script

if (getCookie('basesize')=='' || getCookie('basesize')=='NaN'){setCookie('basesize', 75, 30)}
var bn=parseInt(getCookie('basesize'));
function sizing(n){
  if ((getCookie('basesize'))=='') { alert('Mededeling:\nHet schalen van lettertypes maakt gebruik van cookies.\nDeze browser kan momenteel daar geen gebruik van maken.\nControleer je privacy instellingen in de browser opties.'); bn=75; return; }
  bn=parseInt(bn+n);
  if (parseInt(bn)>=135&&n==10) { bn = 135; return; }
  if (parseInt(bn)<=55&&n==-10) { bn = 55; return; }
  setCookie('basesize', parseInt(bn), 30);
  window.location.reload();
}

function writeSize(){
  var setSize ="";
  setSize += "<style type='text/css' rel='alternative'>body{font-size:"+bn+"%;}<\/style>"
  document.write(setSize)
}
// End Font sizing script
//------------------------------------------------------



//------------------------------------------------------
// Toggle scripts

// classnames to toggle
var o="open";
var c="closed";

// Zappwerk menu
// el : object to attach an event
// t  : optional nodeName to switch classNames. Default is 'LI'
function zappMenu(el,t){
  if (!WinIE) return
  var t = ( t=="" || t==undefined || t==null ) ? 'LI' : t
  var e = fpd(el,t);
  var u = fpd(e,'UL');
  attachMenuEvent(e,u)
}

function autoRunZappMenu(startObjId,tag){
  //if (!WinIE) return ;
  
  var t = ( tag=="" || tag==undefined || tag==null ) ? 'A' : tag ;
  try{
  var s = document.getElementById(startObjId).getElementsByTagName(t);
  for (n=0;n<s.length;n++) {
    if (s[n].className == "folder" ){
      var e = fpd(s[n],'LI');
      e.id=(e.id)+n;
      attachMenuEvent(e);
    }
  }
  }catch(exception){
  }
}

function attachMenuEvent(e,u){
  if (u!=null) {
    var l = u.getElementsByTagName('LI');
    for(n=0;n<l.length;n++){
      if (l[n].className.indexOf(c)>-1) {
        l[n].id=(u.id)+n;
        switchClassName(e,c,c);
      }
    }
  }
  var eul = e.getElementsByTagName('UL')[0];
  if (eul){
    e.onmouseover = function(){
      switchClassName(e,c,o);
      eul.style.zIndex="300";
    }
    e.onmouseout = function(){
      setTimeout("switchClassName(document.getElementById('"+e.id+"'),o,c)", 200);
      eul.style.zIndex="0";
    }
  }
}

// Zappwerk toggle
function zappToggle(el,t){
  var t = ( t=="" || t==undefined || t==null ) ? 'LI' : t
  var e = fpd(el,t);
  var u = fns(e,'UL');
  var l = u.getElementsByTagName('LI');
  for(n=0;n<l.length;n++){
    l[n].id=(u.id)+n;
    if (l[n].className.indexOf(o)>-1) {
      switchClassName(e,o,c);
    }else{
      if (l[n].className.indexOf(c)>-1) {
        switchClassName(e,c,o);
      }
    }
  }
}

// Zappwerk toggle [generic]
function listToggle(el,t){
  var t = ( t=="" || t==undefined || t==null ) ? 'LI' : t
  var e = fpd(el,t);
  if (e.className.indexOf(o)>-1) {
    switchClassName(e,o,c);
  }else if(e.className.indexOf(c)>-1) {
    switchClassName(e,c,o);
  }
}

// Zappwerk toggle all [generic]
function toggleAll(id,tag,s){
  var h = document.getElementById(id).getElementsByTagName(tag);
  for(n=0;n<h.length;n++){
    if (h[n].className.indexOf('makerBox')>-1){
      if (s.indexOf(o)>-1 && h[n].className.indexOf(o)>-1 ) {
        switchClassName(h[n],o,c);
      }else if(s.indexOf(c)>-1 && h[n].className.indexOf(c)>-1) {
        switchClassName(h[n],c,o);
    }
    }
  }
}
// End Toggle scripts
//------------------------------------------------------



//------------------------------------------------------
// Classname & node handlers

function addCSSClass(elem,cn){elem.className=(elem.className+" "+cn).trim();}
function removeCSSClass(elem,cn){elem.className=elem.className.replace(cn,"").trim();}
String.prototype.trim=function(){return this.replace( /^\s+|\s+$/, "" );}
function switchClassName(e,a,b){e.className=e.className.replace(a,"").trim();e.className=(e.className+" "+b).trim();}
function fpd(elem,e){var o=elem;while(o.parentNode.nodeName!=e.toUpperCase()){o=o.parentNode;}return o.parentNode;}
function fps(elem,e){var o=elem;while(o.previousSibling.nodeName!=e.toUpperCase()){o=o.previousSibling;}return o.previousSibling;}
function fns(elem,e){var o=elem;while(o.nextSibling.nodeName!=e.toUpperCase()){o=o.nextSibling;}return o.nextSibling;}
function fcd(elem,e){var o=elem;if(o.firstChild.nodeName==e.toUpperCase()){return o.firstChild;}else{while(o.nextSibling.nodeName!=e.toUpperCase()){o=o.nextSibling;}return o.nextSibling;}}

// End Classname & node handlers
//------------------------------------------------------



//------------------------------------------------------
// Form validation

 function validateForm(formid){

        var submitForm = true;
        var labels = document.getElementsByTagName('LABEL');

        for (var i=0; i<labels.length; i++)
        {

          // check if field is required
          if(labels[i].parentNode.className.indexOf('required') > -1) {

            // get form element
            formelement = fns(labels[i].parentNode,'DIV').childNodes[0];
            // get validationtype
            classname = fns(labels[i].parentNode,'DIV').className;
            arValidationType = classname.split(' ');
            if(arValidationType[0] == 'checkbox' || arValidationType[0] == 'radio') {
              validationType = arValidationType[0];
            }
            else {
              // if there is no type validationtype = undefined, they wil be checked if empty
              validationType = arValidationType[1];
            }

            // check for validation
            if (!checkifValid(validationType,formelement)) {
                formelement.focus();
                doError(labels[i].parentNode,'showError');
                submitForm = false;
            } else doError(labels[i].parentNode,'errormessage');

         }
       }
       return submitForm;
     }

     function doError(element,classname) {
       var checkclass = '';
       if (classname == 'showError') checkclass = 'errormessage';
       else if (classname == 'errormessage') checkclass = 'showError';
        if (element.className == checkclass) {
         element.className = classname;
       }
       else if (element.className == 'clr') {
         return false;
       }
       else {
         doError(element.nextSibling,classname);
       }
     }

     // returns true or false
     function checkifValid(validationType,element) {
       var emailfilter   =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
       var yearfilter    =/^[0-9]{4}$/
       var zipcodefilter =/^[0-9]{4}[a-z]{2}$/i
       var phonefilter   =/^([0-9]{10})|([0-9]{2,4}-[0-9]{6,8})$/
       var extension     =/^.*\.(pdf|doc)$/i

       if(validationType == 'checkbox' || validationType == 'radio') {
         elements = element.parentNode.getElementsByTagName('INPUT');
         for (var i=0; i<elements.length; i++) {
           if (elements[i].checked) return true;
         }
         return false;
       }
       else {
          value = element.value;
          //alert(validationType + "||" + value);
         if(value == "") return false;
         else if(validationType == 'email' && !emailfilter.test(value))     return false;
         else if(validationType == 'day' && (value < 1 || value > 31))      return false;
         else if(validationType == 'month' && (value < 1 || value > 12))    return false;
         else if(validationType == 'year' && !yearfilter.test(value))       return false;
         else if(validationType == 'zipcode' && !zipcodefilter.test(value)) return false;
         else if(validationType == 'phone' && !phonefilter.test(value))     return false;
         else if(validationType == 'file' && !extension.test(value))        return false;
         else return true;
       }

     }

// End Form validation
//------------------------------------------------------



//------------------------------------------------------
// Basic popup script

// * Open a popup window to the specified uri
// * - url The location to open to popup.
// * - type The type of popupwindow(1(default) = 275 * 550, 2 = 535 * 600, 3 = 535 * 600)
// * - name The name of the window(_blank is default)

// HTML EXAMPLE:
/* <a href="popup.html" onclick="return !linkPopup(this, popupTypes.type1);" target="popup">popup link</a> */


var popupTypes = {
  type1: new PopupType(650, 480)
}

function PopupType(width, height) {
  this.width = width;
  this.height = height;
}

function openPopup(aUrl, aType, aName) {
  var aWidth, aHeight;
  if (typeof aType == 'undefined' || !(aType.width && aType.height)) {
    aType = popupTypes.type1;
  }
  aWidth = aType.width;
  aHeight = aType.height;
  var optionString = "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, width=" + aWidth + ", height=" + aHeight
  var aWindow = window.open(aUrl, (aName) ? aName : "_blank", optionString);
  if (aWindow) {
    aWindow.focus();
    return true;
  } else {
    return false;
  }
}

// * Opens a popup using the href and target attributes from the a tag
// * - src the ancor tag(this)
// * - aType a popup type for the width and height(default = popupTypes.type1)
function linkPopup(src, aType) {
  return openPopup(src.getAttribute('href'), aType || popupTypes.type1,(src.getAttribute('target') || '_blank'));
}

// END: Basic popup script
//------------------------------------------------------


//------------------------------------------------------
// Cookie functions [quirksmode.org]

function setCookie(name,value,days) {
  if (days)	{
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }	else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(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;
}

function eraseCookie(name) {
  setCookie(name,"",-1);
}

// END Cookie functions
//------------------------------------------------------


//------------------------------------------------------
// slideshow

var timer, numberOfPictures, slide;
var counter = 0
var pic = new Array()
var fadeTime = 3
var viewingTime = 4000

function getslides(containerID){
  slide = document.getElementById(containerID)
  pic = slide.getElementsByTagName('IMG');
  numberOfPictures = pic.length
  if (numberOfPictures<=0) return;
  slide.style.backgroundImage='url('+pic[0].src+')';
}

function runSlides(){
  if (numberOfPictures<=0) return;
  if (WinIE){
    slide.style.filter="blendTrans(duration=fadeTime)"
    slide.filters.blendTrans.Apply()
  }
  slide.style.backgroundImage='url('+pic[counter].src+')';
  if (WinIE){
    slide.filters.blendTrans.Play();
  }
  counter++;
  if (counter > (numberOfPictures-1)) counter=0;
  timer = setTimeout('runSlides()', viewingTime);
}
// END slideshow
//------------------------------------------------------


//------------------------------------------------------
// Prototype push if missing

if ( typeof Array.push == 'undefined' )
Array.prototype.push = function() {
  var arg, i = 0;
  while( arg = arguments[i++] ) {
    this[this.length] = arg;
  }
  return this.length;
}
// END Prototype push if missing
//------------------------------------------------------


//------------------------------------------------------
// Textarea character counter

function countChars(e,elID,n){
  var c=document.getElementById(elID);
  if(e.value.length>(n-1)) { e.value = e.value.slice(0,(n-1)); }
  c.value = (n-(e.value).length)-1;
}
function runCharCount(e){
  e.onkeypress();
}
// END Textarea character counter
//------------------------------------------------------


//------------------------------------------------------
// Replace Select
// http://easy-designs.net/articles/replaceSelect/
// EK: has a problem with scrolling

function selectReplacement(obj) {
  obj.className += ' replaced';
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
  var opts = obj.options;
  for (var i=0; i<opts.length; i++) {
    var selectedOpt;
    if (opts[i].selected) {
      selectedOpt = i;
      break;
    } else {
      selectedOpt = 0;
    }
  }
  for (var i=0; i<opts.length; i++) {
    var li = document.createElement('li');
    var txt = document.createTextNode(opts[i].text);
    li.appendChild(txt);
    li.selIndex = opts[i].index;
    li.selectID = obj.id;
    li.onclick = function() {
      selectMe(this);
    }
    if (i == selectedOpt) {
      li.className = 'selected';
      li.onclick = function() {
        this.parentNode.className += ' selectOpen';
        this.onclick = function() {
          selectMe(this);
        }
      }
    }
    if (window.attachEvent) {
      li.onmouseover = function() {
        this.className += ' hover';
      }
      li.onmouseout = function() {
        this.className =  this.className.replace(new RegExp(" hover\\b"), '');
      }
    }
    ul.appendChild(li);
  }
  obj.parentNode.insertBefore(ul,obj);
}
function selectMe(obj) {
  var selChange = fpd(obj,'FORM');
  var lis = obj.parentNode.getElementsByTagName('li');
  for (var i=0; i<lis.length; i++) {
    if (lis[i] != obj) {
      lis[i].className='';
      lis[i].onclick = function() {
        selectMe(this);
      }
    } else {
      setVal(obj.selectID, obj.selIndex);
      obj.className='selected';
      obj.parentNode.className = obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
      obj.onclick = function() {
        obj.parentNode.className += ' selectOpen';
        this.onclick = function() {
          selectMe(this);
        }
      }
      selChange.submit()
    }
  }
}
function setVal(objID, selIndex) {
  var obj = document.getElementById(objID);
  obj.selectedIndex = selIndex;
}
function setForm() {
  var s = document.getElementsByTagName('select');
  for (var i=0; i<s.length; i++) {
    selectReplacement(s[i]);
  }
}

// END: Replace Select
//------------------------------------------------------


//  EOF

