////////////////////////////////////////////////////////
/* default lib javascript */
////////////////////////////////////////////////////////


//------------------------------------------------------
// init

//window.onload = init;
function init(){

  
// 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
//------------------------------------------------------




//------------------------------------------------------
// Toggle scripts

// classnames to toggle
var o="open";
var c="closed";


// el : object to attach an event 
// t  : optional nodeName to switch classNames. Default is 'LI'
function celtMenu(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 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";
    }
  }
}

// toggle
function cToggle(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);
      }
    }
  }
}

// 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);
  }
}

// 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){if(b){e.className=e.className.replace(a,"").trim();e.className=(e.className+" "+b).trim();}else{e.className=a;}}
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

var fa = new String();

var errorTypes = {
  required: new errorType(false, /^\s+|\B$/, "Laat dit veld niet leeg, \neen lege veld of een 'spatie' is niet toegestaan.")
}

function errorType( frmError, reg, errMsg ) {
  this.frmError = frmError;
  this.errMsg = errMsg;
  this.reg = reg;
}

function validateForm(e,elmId,tval){
  var i = document.getElementById(elmId);
  var f = fpd(i,'FORM')
  if(fa=="")fa = f.action;
  var t = chkInput(i.value, eval("errorTypes."+tval));
  if (t.frmError) {
    f.action = null;
    alert(t.errMsg);
    return false;
  } else {
    f.action = fa;
    //f.action();
    return true;
  }
}

function chkInput(i, t){
  if (t.reg.test(i)) {
   t.frmError = true;
  }
  return t;
}

// 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
//------------------------------------------------------


//------------------------------------------------------
// global rollover

/* EK: nog niet getest!

function quickRollover(elemID){
	var e = (elemID) ? document.getElementById(elemID) : document.getElementsByTagName('BODY')[0];
	var rollimg = e.getElementsByTagName('IMG');
	if (rollimg.length == 0 ) { return }
	var preloads = new Object();
	for (var i=0;i<rollimg.length;i++) {
		if (rollimg[i].src.indexOf('off.gif') >= 0 ) {
  		if (!rollimg[i].id || rollimg[i].id == undefined) { rollimg[i].id = 'img'+i }
  		preloads['off'+rollimg[i].id] = new Image;
  		preloads['off'+rollimg[i].id].src = rollimg[i].src.split("_")[0] + '_off.gif';
  		preloads['on'+rollimg[i].id] = new Image;
  		preloads['on'+rollimg[i].id].src = rollimg[i].src.split("_")[0] + '_on.gif';
  		rollimg[i].onmouseover = function() {this.src=preloads['on'+this.id].src;}
  		rollimg[i].onmouseout = function() {this.src=preloads['off'+this.id].src;}
    }
	}
}
*/

// End global rollover
//------------------------------------------------------


//  EOF
