//////// SUBMENU HANDLING ////////

// ds: toggleMenu ( 'id' )
//     used to open en close the submenu's
function toggleMenu(id) {
  if ( getStyle(id, 'display') == 'none' ) {
    // open clicked submenu
    setStyle(id, 'display', 'block');
    setStyle(id.substr(0, id.length - 5), 'display', 'none');
  } else {
    // close clicked submenu
    setStyle(id, 'display', 'none');
    setStyle(id.substr(0, id.length - 5), 'display', 'block');
  }
}

function toggleDiv(id) {
  if ( getStyle(id, 'display') == 'none' ) {
    // open clicked submenu
    setStyle(id, 'display', 'block');
  } else {
    // close clicked submenu
    setStyle(id, 'display', 'none');
  }
}




// ds: getStyle ( 'elementName', 'style' )
//     used to get the value of a style element
function getStyle(obj, style) {
  // get the value to the element
  return document.getElementById(obj).style[style];
}




// ds: setStyle ( 'elementName', 'style', 'value' )
//     used to set the value of a style element
function setStyle(obj, style, value) {
  // set the new value to the element
  document.getElementById(obj).style[style] = value;
}




// ds: setClass ( 'elementName', 'value' )
//     used to assign a class to a style element
function setClass(obj, value) {
  // set the new value to the element
  document.getElementById(obj).className = value;
}




//////// LAYER HANDLING FUNCTIONS ////////

// ds: hideLayer ( 'layerName' )
//     internal functon to hide a layer
function hideLayer(layerName) {

  var layerType = getLayerType(layerName);
  
  if ( layerType != "NA" ) {
    // set the new value according to the cssType
    if ( layerType == "visibility" ) {
      var newStyle = "hidden";
    } else if ( layerType == "display" ) {
      var newStyle = "none";
    } else {
      alert ("hideLayer: geen juist layerType kunnen achterhalen...[" + layerType + "]");
    }
  
    // set the new value to the element
    document.getElementById(layerName).style[layerType] = newStyle;
  } else {
    alert ("hideLayer: layer met de naam '" + this.name + "." + layerName + "' bestaat niet...");
  }
}




// ds: showLayer ( 'layerName' )
//     internal function to show a layer
function showLayer(layerName) {

  var layerType = getLayerType(layerName);

  if ( layerType != "NA" ) {
    // set the new value according to the cssType
    if ( layerType == "visibility" ) {
      var newStyle = "visible";
    } else if ( layerType == "display" ) {
      var newStyle = "inline";
    } else {
      alert ("showLayer: geen juist layerType kunnen achterhalen...[" + layerType + "]");
    }
  
    // set the new value to the element
    document.getElementById(layerName).style[layerType] = newStyle;
  } else {
    alert ("showLayer: layer met de naam '" + this.name + "." + layerName + "' bestaat niet...");
  }
}




// ds: getLayerType( layername )
//     internal function used to get the method used to show and hide
//     a layer (display / visibility)

function getLayerType ( layerName ) {
  // check if 'visibility' or 'display' is used
  var layerTypeValue = getStyle(layerName, 'visibility');

  switch ( layerTypeValue ) {
    case 'visible':
      var layerType = 'visibility';
      break;
    case 'hidden':
      var layerType = 'visibility';
      break;
    case 'inherit':
      var layerType = 'display';
      break;
    case 'NA':
      var layerType = 'NA';
      break;
  }
  return layerType;
}




// ds: getStyle ( 'layerName', 'style' )
//     used to return the value of a style element of a layer

function getStyle(obj, style) {
  // catch browsers that don't understand 'getElementById'
  if (!document.getElementById) return;
  
  var obj = getRef(obj);

  if ( obj != null ) {
    var value = obj.style[style];

    // if the style isn't set with JS get it from the defaultView	 
    if (!value) {
      if (document.defaultView) {
    	  value = document.defaultView.getComputedStyle(obj, "").getPropertyValue(style);
  	  } else if (obj.currentStyle) {
    	  value = obj.currentStyle[style];
      }
    } 
  } else {
    value = "NA";
  }

  return value;
}




// ds: getRef( layername )
//     internal function used to get the path to an object
function getRef(obj){
  if (typeof obj == "string") {
    obj = document.getElementById(obj);
  }
  return obj;
}




// ds: preLoad( img1, img2, img3, etc)
//     used to preload images
function preLoad() {
 if (document.images) {
  if (typeof document.pics == 'undefined'){
   document.pics = new Object();
  }
  document.pics.loadedImages = new Array();
  var argLength = preLoad.arguments.length;
  for(arg=0;arg<argLength;arg++) {
   document.pics.loadedImages[arg] = new Image();
   document.pics.loadedImages[arg].src = preLoad.arguments[arg];
  }
 }
}



//     SwapImage
function MM_findObj(n, d) { //v3.0
  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); 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];}
}
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_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];}}
}


// openWindow()
// MM rip om een window te openen met een nieuwe URL
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
// end openWindow()


function popup(URL, id, setScroll, size, popupWidth, popupHeight) {
 
  // set the size in pixels if popupHeight or popupWidth is not defined
  if (!popupWidth || !popupHeight) {
  	switch(size) {
	  	case 1:
        var popupWidth = 275;
        var popupHeight = 300;
			  break;
  		case 2:
        var popupWidth = 275;
        var popupHeight = 650;
	  		break;
		  case 3:
        var popupWidth = 600;
        var popupHeight = 450;
			  break;
  	}
  }

  // put the window in the middle of the screen
  var winLeft = (screen.width - popupWidth) / 2;
  var winTop = (screen.height - popupHeight) / 2;

  eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=" + setScroll + ",location=0,statusbar=0,menubar=0,resizable=0,width=" + popupWidth + ",height=" + popupHeight + ",left = " + winLeft + ",top = " + winTop + "');");
}
