/*

  JJMenu by D.J.Jansen @ JDI-ICT
  2007-10-26

*/

function JJMenu (){
  this.Childs = [];
  this.MenuItems = [];
  this.MenuLists = [];
 
  this.Closing = [];
  this.Opening = [];

  this.AnimationOpenTime = 500;
  this.AnimationCloseTime = 250;

  this.minCPUResolution = 15;
 
  this.StandaardOpenTime = 360;

  this.MenuItemUpPostFix = 'Up';
  this.zIndex = 1;
}

function JJMenuItem( menu, element, idToOpen , idToKeepOpen ){
  this.Menu       = menu;
  this.Parent     = null;
  this.Index      = null;
  this.Element    = element;

  this.NormalClass = element.className;

  this.MouseOn     = false;

  this.ParentY    = element.offsetTop;
  this.ParentX    = element.offsetLeft;

  this.ToOpenID   = idToOpen;
  this.ToOpen     = null;
  if ( this.ToOpenID ){
    var List = new JJMenuList( menu, idToOpen, this );
    this.ToOpen     = List;

    if ( this.ToOpen ){

      List.FindElement();

      if ( List.Element ){
        List.Element.onmouseout = function (){
          List.MouseOut();
        }

        List.Element.onmouseover = function (){
          List.MouseOver();
        }
      }
    }

  }
  this.KeepOpenID = idToKeepOpen;
  if ( this.KeepOpenID ){
    this.KeepOpen   = this.Menu.SearchMenuList( this.KeepOpenID );
    this.Parent = this.KeepOpen;
  }

  this.Open = false;
 
  this.Menu.AddMenuItem( this );
}

JJMenuList.prototype.FindElement = function( ){
  if ( this.Element == null ){
    this.Element = document.getElementById( this.IDReference );

    if ( this.Element != null ){
      this.Element.style.display = 'block';
      this.DropDownY = this.Element.offsetHeight;
      this.Element.style.display = 'none';
      this.DropDownX = this.Element.offsetWidth;
      this.Element.style.left = this.Opener.ParentX + 'px';
      this.Element.style.top  = ( this.Opener.ParentY - this.DropDownY ) + 'px';
      this.BerekenAccelConst( this.DropDownY );
    }
  }
}

JJMenuItem.prototype.UpdateClassName = function( ChildOpen ){
  Class = "";

  if ( ChildOpen ){ 
    Class = this.NormalClass;
    ML = this.Menu.MenuItemUpPostFix.length;
    CL = Class.length;
    if ( Class.substring( CL - ML, CL ) != this.Menu.MenuItemUpPostFix ){ 
      Class += this.Menu.MenuItemUpPostFix;
    }
  } else {
    Class = this.NormalClass;
  }

  if ( this.Element.className != Class ){ 
    this.Element.className = Class;
  }
}

JJMenu.prototype.SearchMenuList = function ( idToSearch ){
  for( idx in this.MenuLists ){  
    MenuList = this.MenuLists[ idx ];
    if ( MenuList.IDReference == idToSearch ){ 
      return MenuList;
    }
  }
  return null;
}

function JJMenuList( menu, idref, opener ){
  this.IDReference = idref;
  this.Opener      = opener;
  this.Menu        = menu;

  this.Childs      = [];
  this.DropDownX   = 0;
  this.DropDownY   = 0;
  this.Open        = false;
  this.Direction   = "open";

  this.MouseOn     = false;

  this.accelOpenConst  = 0.0004;

  this.FindElement();
 
  this.StartTime            = null;
  this.ActionIntervalRunner = null;
  this.AutoCloseTimer       = null;
 
  this.Menu.AddMenuList( this );
}

JJMenuList.prototype.BerekenAccelConst = function( ) {
  Space = ( parseInt( this.Element.style.top ) - this.Opener.ParentY ) * -1;

  this.accelOpenConst = Space / this.Menu.AnimationOpenTime / this.Menu.AnimationOpenTime;
  this.accelCloseConst = Space / this.Menu.AnimationCloseTime / this.Menu.AnimationCloseTime;
}

JJMenu.prototype.RegisterToMenu = function( element, idToOpen, idToKeepOpen ){
  var menuitem = new JJMenuItem( this, element, idToOpen, idToKeepOpen );

  if ( menuitem.ToOpen || menuitem.KeepOpen ){ 

    this.AddToMenuOrder( menuitem );

    element.onmouseover = function (){
      menuitem.MouseMove();
    }

    element.onmouseover();

    element.onmouseout = function(){
      menuitem.MouseOut();
    }

    return true;
  } else {
    element.onmouseover = function(){ };
    return false;
  }
}

JJMenu.prototype.GetNewZIndex = function (){
  this.zIndex++;
  return this.zIndex;
}

JJMenu.prototype.AddMenuItem = function ( MenuItem ){
  var index = ( this.MenuItems.push( MenuItem ) ) - 1;
  MenuItem.Index = index;
}

JJMenu.prototype.AddMenuList = function ( MenuList ){
  var index = ( this.MenuLists.push( MenuList ) ) - 1;
  this.Closing[ index ] = false;
  this.Opening[ index ] = false;
  MenuList.Index = index;
}

JJMenu.prototype.AddToMenuOrder = function ( MenuItem ){

  ChildIndex = null;

  if ( MenuItem.KeepOpen ){ 
    for( var i in this.Childs ){ 
      if ( ChildIndex == null && this.Childs[ i ].ToOpen ){
        ChildIndex = this.Childs[ i ].ToOpen.AddToMenuOrder( MenuItem );
      }
    }
  } else { 
    ChildIndex = ( this.Childs.push( MenuItem ) ) - 1;
  }

  if ( ChildIndex ){
    this.MenuItems[ MenuItem.Index ].ChildIndex = ChildIndex;
  }

}

JJMenuList.prototype.AddToMenuOrder = function( MenuItem ){
  ChildIndex = null;
  if ( this.ToOpen == MenuItem.KeepOpen ){ 
    MenuItem.Parent = this;
    return this.Childs.push( MenuItem );
  }
  for( var i in this.Childs ){
    ChildIndex = this.Childs[ i ].AddToMenuOrder( MenuItem );
    if ( ChildIndex ){ 
      return ChildIndex;
    }
  }
  return null;
}


JJMenuList.prototype.MouseOut = function(){
  this.MouseOn     = false;
  this.CheckPossibleClose();
}

JJMenuList.prototype.MouseOver = function(){
  this.MouseOn     = true;
  this.CheckPossibleClose();
}

JJMenuItem.prototype.MouseOut = function( ){
  this.MouseOn     = false;
  if ( this.ToOpen ){
    this.ToOpen.CheckPossibleClose();
  }
}

JJMenuItem.prototype.MouseMove = function ( ){ 

  this.MouseOn     = true;

  if ( this.ToOpen != null ){
    this.ToOpen.StartOpenMenu();
  }

  if ( this.KeepOpen != null && this.Menu.Closing[ this.KeepOpen.Index ] == false ){
    this.KeepOpen.StartOpenMenu();
  }
}

JJMenu.prototype.CloseOtherThanMe = function( index ){
  for( var idx in this.Childs ){ 
    MenuItem = this.Childs[ idx ];
    cIndex = MenuItem.Index;
    if ( cIndex != index ){
      if ( MenuItem.ToOpen ){
        lIndex = MenuItem.ToOpen.Index;
        if ( this.Closing[ lIndex ] == false && ( MenuItem.ToOpen.Open || this.Opening[ lIndex ] == true ) ){ 
          MenuItem.ToOpen.StartCloseMenuList();
        } 
      }
    }
  }
}

JJMenuItem.prototype.CloseOtherThanMe = function( Index ){
  if ( this.Parent ) { 
    for( var idx in this.Childs ){ 
      MenuList = this.Childs[ idx ];
      if ( MenuList.Index != Index ){ 
        MenuList.StartCloseMenuList();
      }
    }
  } else {
     this.Menu.CloseOtherThanMe( this.Index );
  }
}

JJMenuList.prototype.StartOpenMenu = function () {

  this.FindElement();

  this.Opener.CloseOtherThanMe( this.Index );

  this.Element.style.zIndex = this.Menu.GetNewZIndex();

  if ( this.Menu.Opening[ this.Index ] == true ){
    return;
  }

  if ( this.Open == false || this.Menu.Closing[ this.Index ] == true ){ 

    this.StartTime = (new Date()).getTime();

    this.Opener.UpdateClassName( true );

    this.Element.style.top  = ( this.Opener.ParentY - this.DropDownY ) + 'px';

    this.Element.style.display = 'block';

    this.Menu.Closing[ this.Index ] = false;
    this.Menu.Opening[ this.Index ] = true;
    this.Direction = "open";

    clearInterval( this.ActionIntervalRunner );
    this.ActionIntervalRunner = setInterval( "JJMenu_SlideMenuList( " + this.Index + " )", this.Menu.minCPUResolution );
  } else { 
    if ( this.Open == true ){
      this.ResetCloseTimer();
    }
  }
}

JJMenu_SlideMenuList = function ( index ){
  if ( Menu.MenuLists[ index ] ){ 
    Menu.MenuLists[ index ].SlideMenuList();
  }
}

JJMenu_AutoCloseMenu = function ( index ){
  if ( Menu.MenuItems[ index ] ){
    Menu.MenuLists[ index ].StartCloseMenuList();
  }
}

JJMenuList.prototype.SlideMenuList = function(){
  var elapsed = (new Date()).getTime() - this.StartTime;

  Top = this.Opener.ParentY;

  if ( this.Direction == "open" ){ 
    var d = Math.round(Math.pow(this.Menu.AnimationOpenTime-elapsed, 2) * this.accelOpenConst);
    Top = this.Opener.ParentY - d;

  } else { 
    var d = Math.round(Math.pow(elapsed, 2) * this.accelCloseConst );

    Top = this.Opener.ParentY - d ; 
  }

  this.Element.style.top  = ( Top ) + 'px';

  if ( elapsed > ( this.Direction == "open" ? this.Menu.AnimationOpenTime : this.Menu.AnimationCloseTime) ) {
    if ( this.Direction == "open" ){
      this.EndOpenMenuList();
    } else { 
      this.EndCloseMenuList();
    }
  }
}

JJMenuList.prototype.EndOpenMenuList = function(){
  clearInterval( this.ActionIntervalRunner );
  this.Open = true;
  this.Element.style.top  = this.Opener.ParentY + 'px';

  this.Menu.Opening[ this.Index ] = false;
  this.ResetCloseTimer( false );
}

JJMenuList.prototype.CheckPossibleClose = function(){

  this.FindElement();

  if ( this.MouseOn == true ) {
    this.ClearCloseTimer();
    return false;
  }

  if ( this.Opener != null && this.Opener.MouseOn == true ){
    this.ClearCloseTimer();
    return false;
  }

  this.ResetCloseTimer();

  return true;
}

JJMenuList.prototype.ClearCloseTimer = function ( ToKidsTo ){
  if ( this.AutoCloseTimer ){
    clearInterval( this.AutoCloseTimer );
  }
}

JJMenuList.prototype.ResetCloseTimer = function ( ToKidsTo ){
  clearInterval( this.AutoCloseTimer );
  this.AutoCloseTimer = setTimeout( "JJMenu_AutoCloseMenu( " + this.Index + " )", this.Menu.StandaardOpenTime );
  if ( ToKidsTo ){ 
    HasKids = false;
    for( var idx in Childs ){ 
      MenuItem = Childs[ idx ];
      if ( MenuItem.ToOpen ){  
        if ( MenuItem.ToOpen.Open ){
          MenuItem.ToOpen.ResetCloseTimer( ToKidsTo );
          ToKidsTo = true;
        }
      }
    }
    ToKidsTo = HasKids;
  }
  if ( ! ToKidsTo ){
    if ( this.Opener.Parent ){ 
      this.Opener.Parent.ResetCloseTimer( false );
    }
  }
}

JJMenuList.prototype.StartCloseMenuList = function () {

  if ( ! this.CheckPossibleClose() ){
    return;
  }

  for( var idx in this.Childs ){
    MenuItem = this.Childs[ idx ].ToOpen;
    if ( MenuItem.ToOpen ){
      MenuItem.ToOpen.StartCloseMenuList();
    }
  }

  clearTimeout( this.AutoCloseTimer );
  if ( this.Open || this.Menu.Opening[ this.Index ] == true ) {
    this.StartTime = (new Date()).getTime();

    this.Direction  = "close";
    this.Menu.Closing[ this.Index ] = true;
    this.Menu.Opening[ this.Index ] = false;
    clearInterval( this.ActionIntervalRunner );
    this.ActionIntervalRunner = setInterval( "JJMenu_SlideMenuList( " + this.Index + " )", this.Menu.minCPUResolution );
  }
}

JJMenuList.prototype.EndCloseMenuList = function(){
  clearInterval( this.ActionIntervalRunner );
  this.Open = false;
  this.Opener.UpdateClassName( false );
  this.Element.style.display = 'none';
  this.Menu.Closing[ this.Index ] = false;
}

Menu = new JJMenu();

var IC_Photo_DarkLayer = null;
var IC_Photo_Popup_referer = null;

var IC_Photo_Settings = {
  MarginToBorders: 10,
  Title: 'Klik hier om te sluiten',
  CloseTitle: 'x',
  UseAltTag: true,
  UseCloseTag: true,
  UseDarkLayer: true,
  Padding: 15
};

function IC_Photo_Popup( Link, URL, Width, Height, Alt ){
  var Body = document.getElementsByTagName( 'body' ).item( 0 );
  var Html = document.getElementsByTagName( 'html' ).item( 0 );

  if ( ! IC_Photo_DarkLayer && IC_Photo_Settings.UseDarkLayer ){
    IC_Photo_DarkLayer = document.createElement( 'div' );
    IC_Photo_DarkLayer.id = 'IC_Photo_DarkLayer';
    Body.appendChild( IC_Photo_DarkLayer );
  }

  if ( IC_Photo_Popup_referer == null ){
    IC_Photo_Popup_referer = document.createElement( 'a' );
    IC_Photo_Popup_referer.id = 'IC_Photo_Popup_Holder';
    IC_Photo_Popup_referer.onclick = IC_Photo_Popup_Close;
    IC_Photo_Popup_referer.href = '#';
    IC_Photo_Popup_referer.title = IC_Photo_Settings.Title;

    if ( IC_Photo_Settings.UseAltTag ){
      var AltTag = document.createElement( 'span' );
      AltTag.className = 'AltLabel';
      AltTag.appendChild( document.createTextNode( Alt ) );
      IC_Photo_Popup_referer.appendChild( AltTag );
      IC_Photo_Popup_referer.Label = AltTag;
    }

    if ( IC_Photo_Settings.UseCloseTag ){
      var ATag = document.createElement( 'a' );
      ATag.className = 'CloseButton';
      ATag.href = '#';
      ATag.appendChild( document.createTextNode( IC_Photo_Settings.CloseTitle ) );
      IC_Photo_Popup_referer.appendChild( ATag );
    }
    Body.appendChild( IC_Photo_Popup_referer );
  }
  if ( IC_Photo_Popup_referer != null ) {
    IC_Photo_Popup_referer.style.display = 'block';

    IC_Photo_Popup_referer.style.height = ( Height + IC_Photo_Settings.Padding * 2 ) + 'px';
    IC_Photo_Popup_referer.style.width = ( Width + 30 ) + 'px';

    LabelHeight = 0;

    if ( IC_Photo_Settings.UseAltTag ){
      IC_Photo_Popup_referer.Label.innerHTML = Alt;

      if ( Alt != '' ){
        LabelHeight = IC_Photo_Popup_referer.Label.offsetHeight;

        IC_Photo_Popup_referer.style.height = ( Height + LabelHeight + IC_Photo_Settings.Padding * 2 ) + 'px';
      }
    }

    IC_Photo_Popup_referer.style.backgroundPosition = 'center ' + ( IC_Photo_Settings.Padding + LabelHeight ) + 'px';

    IC_Photo_Popup_referer.style.backgroundImage = 'url(' + URL + ')';

    IC_Image = null;
    for( i=0; i<Link.childNodes.length; i++ ){
      if ( Link.childNodes[ i ].tagName.toUpperCase() == 'IMG' ){
        IC_Image = Link.childNodes[ i ];
      }
    }
    if ( IC_Image ){
      Position = getPositionFrom( IC_Image );

      Left = ( Position.left + IC_Image.offsetWidth / 2 ) - IC_Photo_Popup_referer.offsetWidth / 2;

      Left = Math.min( Left, Body.offsetWidth - IC_Photo_Popup_referer.offsetWidth - IC_Photo_Settings.MarginToBorders );
      Left = Math.max( Left, IC_Photo_Settings.MarginToBorders );

      Top = ( Position.top + IC_Image.offsetHeight / 2 ) - IC_Photo_Popup_referer.offsetHeight / 2;
      WindowMax = Math.max( Body.offsetHeight, Html.offsetHeight );
      Top = Math.min( Top, WindowMax - IC_Photo_Popup_referer.offsetHeight - IC_Photo_Settings.MarginToBorders );
      Top = Math.max( Top, IC_Photo_Settings.MarginToBorders );

      IC_Photo_Popup_referer.style.top = Top + 'px';
      IC_Photo_Popup_referer.style.left = Left + 'px';

      if ( IC_Photo_Settings.UseDarkLayer ){
        IC_Photo_DarkLayer.style.display = 'block';
        DLHeight = Math.max( Body.offsetHeight, Html.offsetHeight, Top + IC_Photo_Popup_referer.offsetHeight );

        IC_Photo_DarkLayer.style.height = DLHeight + 'px';

      }
    }
  }
}


function IC_Photo_Popup_Close(){
  if ( IC_Photo_Popup_referer != null ){
    IC_Photo_Popup_referer.style.display = 'none';
  }
  if ( IC_Photo_Settings.UseDarkLayer && IC_Photo_DarkLayer != null ){
    IC_Photo_DarkLayer.style.display = 'none';
  }
  return false;
}

function getPositionFrom(element) {
  var Pos = {top:0,left:0};
  var absoluteAncestor = false;

  while ( element.offsetParent ) {

    Pos.top += element.offsetTop - element.scrollTop;
    Pos.left += element.offsetLeft - element.scrollLeft;

    element = element.offsetParent;

    if ( element.nodeName.toLowerCase() != 'html' ) {
      if ( element.currentStyle ) {
        if (element.currentStyle[ 'position' ] == 'absolute')
          absoluteAncestor = true;
      } else {
        if ( window.getComputedStyle ){
          if ( document.defaultView.getComputedStyle(element,null).getPropertyValue( 'position' ) == 'absolute' ){
            absoluteAncestor = true;
          }
        }
      }
    }
  }

  if ( ! absoluteAncestor ){
    var Body = document.getElementsByTagName( 'BODY' ).item( 0 );
    Pos.top += Body.offsetTop;
    Pos.left += Body.offsetLeft;
  }

  return Pos;
}



CurrentMenuOpen = null;
function MenuOpenList( ID ) {
  Element = document.getElementById( ID );
  if ( Element ){

    if ( CurrentMenuOpen ){
      CurrentMenuOpen.style.display = 'none';
    }

    Element.style.display = 'block';
    CurrentMenuOpen = Element;
  }
}


var DarkLayer = null;
OpenPictureNext = null;
OpenPicturePrev = null;
function OpenAfbeelding( idx ){
  if ( idx != null){
    url = Images[ idx ];
  }
  if ( url ){
    bodys = document.getElementsByTagName( 'body' );
    body = bodys[ 0 ];
    phj = document.getElementById( 'PopupHolder' );

    phjFoto = document.getElementById( 'PopupFoto' );

    phjSluiten = document.getElementById( 'Sluiten' );

    pvol = document.getElementById( 'PopupVolgende' );
    pvor = document.getElementById( 'PopupVorige' );

    if ( body && phj && phjFoto && pvol && pvor && phjSluiten ){


      if ( ! DarkLayer ){

        DarkLayer = document.createElement( 'div' );
        DarkLayer.className = 'DarkLayer';
        DarkLayer.style.height = GetWindowHeight() + 'px';
      }

      body.appendChild( DarkLayer );
      phj.style.display = 'block';
      phjFoto.style.backgroundImage = 'url(' + url + ')';

      pvor.style.display = Images[ idx - 1 ] ? 'block' : 'none';
      pvol.style.display = Images[ idx + 1 ] ? 'block' : 'none';

      phjSluiten.href = '#foto' + idx;

      OpenPictureNext = idx + 1;
      OpenPicturePrev = idx - 1;
    }
  }
}

function ClosePicture () {
  bodys = document.getElementsByTagName( 'body' );
  body = bodys[ 0 ];
  body.removeChild( DarkLayer );
  phj = document.getElementById( 'PopupHolder' );
  if ( phj ){
    phj.style.display = 'none';
  }
}
function GetWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight + 1;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight + 2;
  }
  return myHeight;
}

function waarschuwing() {
	//confirm("Weet u zeker dat u dit item wilt verwijderen?");
  /*var oke = confirm("Weet u zeker dat u dit item wilt verwijderen?");
    if(oke) {
      alert("Dit item is nu verwijderd");
    } else {
      alert("Geen actie uitgevoerd");
    }*/
}

function OpenHoeveelheidForm( OpenElement, FormName, FormElement, Type ){
  var HoeveelHeidForm = document.getElementById( 'HoeveelheidForm' );
  if ( HoeveelHeidForm ){
    HoeveelHeidForm.style.display = 'block';
    HoeveelHeidForm.FormName.value = FormName;
    HoeveelHeidForm.FormElement.value = FormElement;
    HoeveelHeidForm.FormType.value = Type;
    HoeveelHeidForm.A.value = '';
    HoeveelHeidForm.B.value = '';
    HoeveelHeidForm.H.value = '';
    if ( Type == 1 ){ 
      HoeveelHeidForm.H.value = 1;
    }
    var H = document.getElementById( 'Hoogte' );
    if ( H ){
      H.style.display = Type == 1 ? "none" : "inline";
    }
    HoeveelHeidForm.Totaal.value = '';

    if ( OpenElement ){ 
      var ContentMiddle = document.getElementById( 'ContentMiddle' );
      var Pos = getPositionFrom( OpenElement );
      var PosCM = getPositionFrom( ContentMiddle );
      var Top = Pos.top - PosCM.top - HoeveelHeidForm.offsetHeight / 2;
      Top = Math.max( 0, Top );
      HoeveelHeidForm.style.top = Math.floor( Top ) + 'px';
    }
  }
  return HoeveelHeidForm == null;
}

function SluitHoeveelheidForm( ){
  var HoeveelHeidForm = document.getElementById( 'HoeveelheidForm' );
  if ( HoeveelHeidForm ){
    HoeveelHeidForm.style.display = 'none';
    return true;
  }
  return false;
}

function Get_Float( F ){
  F = F.replace( ',', '.' );
  var Value = parseFloat( F );
  if ( isNaN( Value ) ){ 
    return 0;
  }
  return Value;
}

function DirectInvullenHF( ){
  var HoeveelHeidForm = document.getElementById( 'HoeveelheidForm' );
  if ( HoeveelHeidForm ){
    Totaal = HoeveelHeidForm.Totaal.value;
    var form = document.forms[ HoeveelHeidForm.FormName.value ];
    var Element = HoeveelHeidForm.FormElement.value;
    if ( form && Element ){
      if ( Totaal > 0 ){
        form[ Element ].value = Totaal;
      }
    }
    SluitHoeveelheidForm();
    return false;
  }
  return true;
}

function CalculateHF( f ){
  if ( f ){
    var a = Get_Float( f.A.value );
    var b = Get_Float( f.B.value );
    var h = Get_Float( f.H.value );
    var totaal = a * b * h;
    f.A.value = a;
    f.B.value = b;
    f.H.value = h;
    f.Totaal.value = totaal;
    return false;
  }
  return true;
}

function UpdateBezorgDatum(){
  var DatumField = document.getElementById( 'BezorgDatum' );
  var f = document.forms[ 'WinkelMand' ];
  if ( DatumField && f ){
    var Datum = DatumField.value;
    f.BezorgDatumDag.value = Datum.substring( 0, 2 );
    var Maand = parseInt( Datum.substring( 3, 5 ) );
    for( idx = 0; idx < f.BezorgDatumMaand.options.length; idx ++ ){
      if ( f.BezorgDatumMaand.options[ idx ].value == Maand ){ 
        f.BezorgDatumMaand.selectedIndex = idx;
      }
    }
    f.BezorgDatumJaar.value = Datum.substring( 6, 10 );
  }
}

/**
* in_array -- Checks if a value exists in an array
*
* Searches haystack for needle and returns TRUE if it is found in the array, FALSE otherwise.
* If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
* Note: If needle is a string, the comparison is done in a case-sensitive manner.
*
* @param mixed needle
* @param Array haystack
* @param Boolean strict false
* @author Mick <mick@vandermostvanspijk.nl>
* @copyright LGPL
* @todo make needle so that it might be an array
* @todo make strict working
* @version 1.0.2
*/
function in_array(_needle, _haystack, _strict) {
        var needle   = _needle;
        var haystack = _haystack;
        var strict   = _strict || false;

        for (var i = 0; i < haystack.length; i++) {
                if (haystack[i] == needle) {
                        return true;
                }
        }

        return false;
}

/**
* This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
*/
function sprintf() {
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}



var IC_Window_Config = {

  Objects : {
    IC_Body : null,
    IC_DarkLayer : null
  },

  Settings : {
    MarginToBorders: 10,
    UseDarkLayer: true
  }

};

function IC_Window( Settings, Contents ){
  this.Settings = Settings;

  this.InitLayers();

  this.Element = document.createElement( 'div' );

  if ( this.Element ){
    this.SetSize();
    this.SetPosition();
    this.Element.className = 'ICWindow';
    IC_Window_Config.Objects.IC_Body.appendChild( this.Element );
    this.Element.innerHTML = Contents;
  }
}

IC_Window.prototype = {

  InitLayers : function() {

    if ( ! IC_Window_Config.Objects.IC_Body ){
      IC_Window_Config.Objects.IC_Body = document.getElementsByTagName( 'body' ).item( 0 );
    }

    if ( IC_Window_Config.Objects.IC_Body && IC_Window_Config.Settings.UseDarkLayer ){
      IC_Window_Config.Objects.IC_DarkLayer = document.createElement( 'div' );
      IC_Window_Config.Objects.IC_DarkLayer.id = 'IC_DarkLayer';
      var self = this;
      IC_Window_Config.Objects.IC_DarkLayer.onclick = function(){
        self.SetVisibility( false );
      }
      IC_Window_Config.Objects.IC_Body.appendChild( IC_Window_Config.Objects.IC_DarkLayer );
    }

  },


  SetVisibilityLayer : function( Show ){
    if ( IC_Window_Config.Settings.UseDarkLayer && IC_Window_Config.Objects.IC_DarkLayer ){
      var WindowSize = this.getWindowSize();

      if ( Show ){
        IC_Window_Config.Objects.IC_DarkLayer.style.display = 'block';

        var DLHeight = Math.max( IC_Window_Config.Objects.IC_Body.offsetHeight, WindowSize.Height );
        var DLWidth = Math.max( IC_Window_Config.Objects.IC_Body.offsetWidth );
        IC_Window_Config.Objects.IC_DarkLayer.style.height = DLHeight + 'px';
        IC_Window_Config.Objects.IC_DarkLayer.style.width = DLWidth + 'px';
      } else {
        IC_Window_Config.Objects.IC_DarkLayer.style.display = 'none';
      }
    }
  },

  SetSize : function( Size ){
    var Size = Size ? Size : this.Settings.Size;
    if ( ! Size ) {
      Size = {Width: 200, Height: 200};
      this.Settings.Size = Size;
    }
    this.Element.style.width = Size.Width + 'px';
    this.Element.style.height = Size.Height + 'px';
    this.Settings.Size = Size;
  },

  SetPosition : function( Position ){
    var WindowSize = this.getWindowSize();

    var Position = Position  ? Position : this.Settings.Position;
    if ( ! Position ){
      Position = {Left:'center',Top:'center'};
      if ( this.Settings.AnkerFrom ){
        var AnkerPosition = getPositionFrom( this.Settings.AnkerFrom );
        Position.Left = Math.floor( ( AnkerPosition.left + this.Settings.AnkerFrom.offsetWidth / 2 ) - this.Settings.Size.Width / 2 );
        Position.Top = Math.floor( ( AnkerPosition.top + this.Settings.AnkerFrom.offsetHeight / 2 ) - this.Settings.Size.Height / 2 );
      }
      this.Settings.Position = Position;
    }


    if ( Position.Left == 'htmlcenter' || Position.Top == 'htmlcenter' ){
      ScrollRate = this.getScrollPosition();
    }

    if ( isNaN( Position.Left ) ) {
      if ( Position.Left == 'center' ){
        this.Element.style.left = '50%';
        this.Element.style.marginLeft = '-' + Math.floor( this.Settings.Size.Width / 2 ) + 'px';
      } else {
        if ( Position.Left == 'htmlcenter' ){
          Position.Left = ScrollRate.Left + Math.floor( WindowSize.Width / 2 - this.Settings.Size.Width / 2 );
          this.Element.style.left = Position.Left + 'px';
        } else {
          this.Element.style.left = Position.Left;
        }
      }
    } else {
      if ( Position.Left == 'center' ) {
        Position.Left = Math.floor( Math.max( IC_Window_Config.Objects.IC_Body.offsetWidth, WindowSize.Width ) / 2 - this.Settings.Size.Width / 2 );
      }
      if ( Position.Left <= IC_Photo_Settings.MarginToBorders ){
        Position.Left = IC_Photo_Settings.MarginToBorders;
      }
      this.Element.style.left = Position.Top + 'px';
    }

    if ( isNaN( Position.Top ) ) {
      if ( Position.Top == 'center' ){
        this.Element.style.top = '50%';
        this.Element.style.marginTop = '-' + Math.floor( this.Settings.Size.Height / 2 ) + 'px';
      } else {
        if ( Position.Top == 'htmlcenter' ){
          Position.Top = ScrollRate.Top + Math.floor( WindowSize.Height / 2 - this.Settings.Size.Height / 2 );
          this.Element.style.top = Position.Top + 'px';
        } else {
          this.Element.style.top = Position.Top;
        }
      }
    } else {
      if ( Position.Top == 'center' ) {
        Position.Top = Math.floor( Math.max( IC_Window_Config.Objects.IC_Body.offsetHeight, WindowSize.Height ) / 2 - this.Settings.Size.Height / 2 );
      }
      if ( Position.Top <= IC_Photo_Settings.MarginToBorders ){
        Position.Top = IC_Photo_Settings.MarginToBorders;
      }
      this.Element.style.top = Position.Top + 'px';
    }
  },

  SetVisibility : function( Show ) {
    if ( Show ){
      this.Element.style.display = 'block';
    } else {
      this.Element.style.display = 'none';
    }
    this.SetVisibilityLayer( Show );
  },

  getScrollPosition : function( ){
    var Position = { Left:0, Top:0 };
    Position.Left = document.body.scrollLeft;
    Position.Top  = document.body.scrollTop;
    if ( Position.Left == 0 ){
      if ( window.pageXOffset ){
        Position.Left = window.pageXOffset;
      } else {
        Position.Left = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
      }
    }
    if ( Position.Top == 0 ){
      if ( window.pageYOffset ){
        Position.Top = window.pageYOffset;
      } else {
        Position.Top = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
      }
    }
    return Position;
  },


  getWindowSize : function (){
    var viewportwidth;
    var viewportheight;
    if (typeof window.innerWidth != 'undefined')
    {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    } else {
      if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
      } else {
        viewportwidth = IC_Window_Config.Objects.IC_Body.clientWidth,
        viewportheight = IC_Window_Config.Objects.IC_Body.clientHeight
      }
    }
    return { Width:viewportwidth, Height:viewportheight };
  },

  getPositionFrom : function ( element ) {
    var Pos = {top:0,left:0};
    var absoluteAncestor = false;

    while ( element.offsetParent ) {

      Pos.top += element.offsetTop;
      Pos.left += element.offsetLeft;

      element = element.offsetParent;

      if ( element.nodeName.toLowerCase() != 'html' ) {
        if ( element.currentStyle ) {
          if (element.currentStyle[ 'position' ] == 'absolute')
            absoluteAncestor = true;
        } else {
          if ( window.getComputedStyle ){
            if ( document.defaultView.getComputedStyle(element,null).getPropertyValue( 'position' ) == 'absolute' ){
              absoluteAncestor = true;
            }
          }
        }
      }
    }

    if ( ! absoluteAncestor ){
      Pos.top += IC_Window_Config.Objects.IC_Body.offsetTop;
      Pos.left += IC_Window_Config.Objects.IC_Body.offsetLeft;
    }

    return Pos;
  }

}

Wnd = null;

function OpenTekstVenster( IdToFind ){
  var TekstField = document.getElementById( IdToFind );
  if ( TekstField ){
    var Contents = TekstField.innerHTML;
 
    Contents += '<input type="button" onclick="Wnd.SetVisibility(false);" class="MFSubmitButton" value="Sluiten">';

    Wnd = new IC_Window( {Size:{Width:600,Height:476},Position:{Left:'htmlcenter',Top:'htmlcenter'}}, Contents );

    Wnd.SetVisibilityLayer( true );
    Wnd.SetVisibility( true );   

    return true;
  }
  return false;
}

