function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// navigation

function setButtons() {
   // Call this function in the onload of the body.
   // If you have any images in your document that have filenames that start with but_
   // it will create an onmouseover and onmouseout for those images.
   // the onmouseover image that will be loaded has the same name as the original filename
   // but ends with _over, e.g. but_overons.gif will load but_overons_over.gif
   // ../images/but_overons.jpg will load ../images/but_overons_over.jpg
   // when an img tag has got an id='active' the mouseover image is loaded by default, and no
   // mouseover and mouseout changes will occur
   //
   images = document.getElementsByTagName('img');
   for(i=0;i<images.length;i++) {
      var dirs = images[i].src.substring(0, images[i].src.lastIndexOf('/'));
      var file = images[i].src.substring(images[i].src.lastIndexOf('/')+1);
      if(file.substring(0, 4) == 'but_') {
         var name = file.split('.');
         if(name.length > 2) {
            basename = '';
            for(j=0;j<name.length-1;j++) {
               basename += name[j];
            }
         }else {
            basename = name[0];
         }
         extention = name[name.length-1];
         nameout  = dirs+'/'+basename+'.'+extention;
         nameover = dirs+'/'+basename+'_over.'+extention;
         // preload the mouseover image...
         //
         img = document.createElement('img');
         img.src=nameover;
         
         // set the eventhandlers
         //
         //alert(a);
         if(images[i].id == 'active') {
            images[i].src=nameover;
         }else {
            eval("images[i].onmouseover = function() { this.src='"+nameover+"'; }");
            eval("images[i].onmouseout = function() { this.src='"+nameout+"'; }");
         }
      }
   }
}

// Het Field object wordt gebruikt bij de validatie van de formuliervelden
// Gebruik als volgt:
//
//       fields[0] = new Field('naam',            true,  'verplicht0');
//       fields[1] = new Field('bedrijf',         false, 'verplicht1');
//       fields[2] = new Field('adres',           false, 'verplicht2');
//       fields[3] = new Field('postcode+plaats', false, 'verplicht3', 'postcode("postcode")');
//       fields[4] = new Field('telefoon',        false, 'verplicht4', 'telefoon("telefoon")');
//       fields[5] = new Field('email',           true,  'verplicht5', 'email("email")');
//       
//       Validate();
//       function Validate(field) {
//          for(var i=0;i<fields.length;i++) {
//             fields[i].Validate(field);
//          }
//       }
//
//  SYNTAX: Field(name, required, image, validation)
//  als required == false ==> Validation == true ==> zwarte text, anders rode text
//  als required == trure ==> Validation == true ==> groen vinkje, anders rood uitroepteken
//  wanneer twee velden samen één validatie combineren zoals postcode en plaats, dan in naam met + scheiden.
//  image is de naam van de imagetag waarin het vinkje of uitroepteken geladen wordt. (of pixel.gif indien niet verplicht)
//  roep in de onchange en onclick van ieder veld de validate functie aan...
//
function Field(name, required, image, validation) {
   // Properties
   //
   this.name      = name;
   if(name.indexOf('+') > -1) {
     this.names = name.split('+');
     this.element  = false;
     this.elements = Array();
     for(i=0;i<this.names.length;i++) {
        this.elements[i] = document.getElementById(this.names[i]);
     }
   }else {
      this.elements  = false;
      this.element   = document.getElementById(name);
   }
   this.required  = required;
   this.imagetag  = document.getElementById(image);
   this.imagename = image;
   if(typeof(validation) == 'undefined') {
      this.validation = '1==1';
   }else {
      this.validation = validation;
   }
   
   // method declaratie
   //
   this.setImage     = field_setImage;
   this.setTextcolor = field_setTextcolor;
   this.Validate     = field_Validate;
   this.isEmpty      = field_isEmpty;
   this.isRequired   = field_isRequired;
   
   // method implementatie
   //
   function field_setImage(valid) {
      if(valid) {
         this.imagetag.src = 'http://www.lync.nl/images/verplicht1.gif';
      }else {
         this.imagetag.src = 'http://www.lync.nl/images/verplicht2.gif';
      }
      if(!this.required) {
         this.imagetag.src = 'http://www.lync.nl/images/pixel.gif';
      }
   }
   function field_setTextcolor(color) {
      if(this.elements) {
         for(var i=0;i<this.elements.length;i++) {
            this.elements[i].style.color = color;
         }
      }else {
         this.element.style.color = color;
      }
   }
   function field_Validate(field) {
      if(this.required) {
         this.setTextcolor('#000000');
         if(this.isEmpty()) {
            // WEL verplicht, WEL leeg
            //
            this.setImage(false);
            result = false;
         }else {
            eval('result = ('+this.validation+');');
            if(result) {
               // WEL verplicht, NIET leeg, WEL geldig
               //
               this.setImage(true);
            }else {
               // WEL verplicht, NIET leeg, NIET geldig
               //
               this.setImage(false);
            }
         }
      }else {
         this.setImage(false);
         if(!this.isEmpty(true)) {
            eval('result = ('+this.validation+');');
            if(result) {
               // NIET verplicht WEL geldig
               //
               this.setTextcolor('#000000');
            }else {
               // NIET verplicht NIET geldig
               //
               if(this.elements) {
                  for(var i=0;i<this.elements.length;i++) {
                     if(this.elements[i].value.length > 0) {
                        this.elements[i].style.color = '#E02A78';
                     }else {
                        this.elements[i].style.color = '#000000';
                     }
                  }
               }else {
                     if(this.element.value.length > 0) {
                        this.element.style.color = '#E02A78';
                     }else {
                        this.element.style.color = '#000000';
                     }
               }
            }
         }else {
            this.setTextcolor('#000000');
            result = true;
         }
      }
      return result;            
   }
   function field_isEmpty(allfields) {
      if(this.elements) {
         result = false;
         var j=0;
         for(var i=0;i<this.elements.length;i++) {
            if(this.elements[i].value.length < 1) {
               result = true;
               j++;
            }
         }
         if(allfields) {
            if(j==this.elements.length) {
               result = true;
            }else {
               // Niet alle velden zijn leeg
               //
               result = false;
            }
         }
      }else {
         if(this.element.value.length > 0) {
            result = false;
         }else {
            result = true;
         }
      }
      return result;
   }
   function field_isRequired() {
      return this.required;
   }
}
function postcode(field) {
   objElement = document.getElementById(field);
   strValue = objElement.value
   var parts = new Array();
   parts[0] = strValue.substring(0,4)
   parts[1] = strValue.substring(4,6)
   if(parts[0].match(/^[1-9][0-9]{3}$/) && parts[1].match(/^[A-Za-z]{2}$/)){
      //eval("document.theForm."+objElement.name+".value = parts[0]+" "+parts[1]
      objElement.value = parts[0]+" "+parts[1];
      arrMatch = true;
   }
   else {
      var arrMatch=new RegExp("^[1-9][0-9]{3}[ ][A-Za-z]{2}$").exec(strValue);
   }
   if(!arrMatch) { 
      result = false;
   }else {
      result = true;
   }
   return result;
}

function telefoon(field) {
   strValue = document.getElementById(field).value;
   var arrMatch=new RegExp("^[0][0-9](([-][0-9][0-9])|([0-9][-][0-9])|([0-9][0-9][-]))[0-9]{6}$").exec(strValue);
   var arrMatch=new RegExp("^[0-9\-\+\(\) ]{10,15}$").exec(strValue);
   if(!arrMatch) { 
      result = false;
   }else {
      result = true;
   }
   return result;
}
function email(field) {
   strValue = document.getElementById(field).value;
   var arrMatch=new RegExp("^[A-Za-z0-9_-]+([.][A-Za-z0-9_-]+){0,4}[@][A-Za-z0-9_-]+([.][A-Za-z0-9_-]+){1,3}$").exec(strValue)
   if(!arrMatch) { 
      result = false;
   }else {
      result = true;
   }
   return result;
}
function empty(field) {
   strValue = document.getElementById(field).value;
   return (strValue.length < 1);
}

function setCookie(name, value, expires, path, domain) {
   document.cookie = name + "=" + escape(value) + 
   ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
   ((path == null)    ? "" : "; path=" + path) +
   ((domain == null)  ? "" : "; domain=" + domain);
}
function getCookie(name) {
   var cname = name + "=";               
   var dc = document.cookie;             
   var result = null;
   if(dc.length > 0) {
      begin = dc.indexOf(cname);       
      if(begin != -1) { 
         begin += cname.length;       
         end = dc.indexOf(";", begin);
         if(end == -1) {
            end = dc.length;
         }
         result = unescape(dc.substring(begin, end));
      } 
   }
   return result;
}
function setFormCookies(form) {
   elms = document.forms[form].elements
   var expiration = new Date();
   expiration.setTime(expiration.getTime() + 43200000); // (30 dagen in milliseconden)
   for(var i=0;i<elms.length;i++) {
      if(elms[i].type == 'text') {
         setCookie(form+'_'+elms[i].name, elms[i].value, expiration);
      }
   }
}
function getFormCookies(form) {
   elms = document.forms[form].elements
   for(var i=0;i<elms.length;i++) {
      val = getCookie(form+'_'+elms[i].name);
      if(val) {
         elms[i].value = val;
      } 
   }   
}         

function getFormVariables(form) {
   elms = document.forms[form].elements;
   var result = '';
   for(var i=0;i<elms.length;i++) {
     if(((elms[i].type == 'checkbox') && (elms[i].checked)) || (elms[i].type != 'checkbox')) {
        result += '&'+escape(elms[i].name)+'='+escape(elms[i].value);
     }
   }
   result = result.substring(1);
   return result;
}

/* Onderstaande code zit nu in lyncstats.js dat van de lyncstats.lync.nl wordt geïnclude

// Every page gets a hit object, so we can register the hits
//
function setLinkStats() {
   // Call this function in the onload of the body.
   // By specifying a linkname in the target property of the anchor tags
   // a hit with the specified name will be logged in the database for every click
   // the real target can be placed behind the ; 
   // e.g. <a href="home.html" target="homepage;"> 
   // or <a href="home.html" target="homepage;_blank">
   // When you only want a target and no hitcount, make sure no ; is used in the target property
   // If the href contains JavaScript, don't use the target to register a hit but do it like this:
   // <a href="JavaScript:registerHit('LoginButton', 'submit()');document.theForm.submit();">
   //
   anchors = document.body.getElementsByTagName('a');
   for(i=0;i<anchors.length;i++) {
     if(anchors[i].target.indexOf(';') != -1) {
        arr = anchors[i].target.split(';');
        linkname          = arr[0];
        anchors[i].target = arr[1];
        destination       = anchors[i].href;
        eval("anchors[i].onclick = function() {registerHit('"+linkname+"', '"+destination+"') }");
     }
   }
   registerHit('__pageopened', ''); // Het huidige pagina bezoek registreren.
}

var hit = new AjaxObject('hit', '../php/main.php', 'hitRegistered');
function hitRegistered(txt, arr) {
   //alert(txt);
}
function registerHit(linkname, destination) {
   var browser = navigator.appCodeName;
   var version = navigator.appVersion;
   var source  = document.title.split('#')[0]; // somehow the title contains the hash on a refresh...
   var referrer= document.referrer.split('#')[0]; // remove hash;
   var referrer= referrer.split('?')[0]; // remove vars;
   hit.Load('c-Object=hit&c-Action=RegisterHit&link='+linkname+'&source='+source+'&dest='+destination+'&referrer='+referrer);
}
*/