function Resize()
{
	var pageWidth;
	var pageHeight;
	var headerAreaHeight;
	var coverArea = document.getElementById("modalFormArea_coverArea");

	if (coverArea != null)
	{
		coverArea.style.height = 0;
		coverArea.style.width = 0;
	}

	// Set widths
	if (pageBody.clientWidth < 800)
		pageWidth = 800;
	else
		pageWidth = pageBody.clientWidth;
		
	if (coverArea != null)
	{
		coverArea.style.width = pageWidth;
	}
		
	if (document.getElementById("clientArea_area") != null)
	{
		if (document.getElementById('clientArea_menu_empty') != null &&
			document.getElementById('clientArea_menu_empty').style.display == 'none')
		{
			clientArea_area.style.width = pageWidth - 120;
		}
		else
		{
			clientArea_area.style.width = 20;
			clientArea_area.style.width = clientArea_container.clientWidth - clientArea_menu_empty.clientWidth - 4;
		}
	}

	// Set heights (based on widths)
	if (pageBody.clientHeight < 200)
		pageHeight = 200;
	else
		pageHeight = pageBody.clientHeight;
		
	if (coverArea != null)
	{
		coverArea.style.height = pageHeight;
	}
	
	if (coverArea != null)
	{
		coverArea.style.left = 0;
		coverArea.style.top = 0;
		
		var modalWidth = modalFormArea_formArea.offsetWidth;
		var modalHeight = modalFormArea_formArea.offsetHeight;

		modalFormArea_formArea.style.display = "none";
		
		modalFormArea_formArea.style.left = (pageWidth - modalWidth) / 2;
		modalFormArea_formArea.style.top = (pageHeight - modalHeight) / 2;
		
		modalFormArea_formArea.style.display = "";
		
		//in case a modalForm has a 'modalIFrame', set it on the right place 
		//so that controls like listboxes can not overlap the modalForm
		var modalIFrame = document.getElementById('modalIFrame');
		if (modalIFrame != null)
		{
		    modalIFrame.style.width = modalFormArea_formArea.offsetWidth;
            modalIFrame.style.height = modalFormArea_formArea.offsetHeight;
            modalIFrame.style.top = modalFormArea_formArea.style.top;
            modalIFrame.style.left = modalFormArea_formArea.style.left;
        }
	}

	if (document.getElementById("menuArea_switchValue") != null)
	{
		var switchValue = document.getElementById("menuArea_switchValue").value;
		switchMenu(switchValue);
	}
}

// Find a webelement in the contents of the container 'container'
// Search the element according to the last part of its name,
// which should be equal to 'namePostfix'
// This function is recursive: each item that is a container 
// will also be searched, until the item has been found
// The search is depth-first
function GetChild(container, namePostfix)
{
	var childnamePostfix;
	var childname;
	var idx;
	
	// Check all items in the container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		childname = container.childNodes[idx].id;
		
		if (childname != null && childname.length >= namePostfix.length)
		{
			// Searched item possibly found; check name
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix)
				// The last part of the name is equal to 'namePostfix'
				// so the searched item is found: return it
				return container.childNodes[idx];
		}
		
		// Search the children in the container of the current item
		child = GetChild(container.childNodes[idx], namePostfix);
		if (child != null)
			// In the container of this item the searched item is found
			// So return it
			return child;
	}
	
	// The searched item has not been found; return nothing (null)
	return null;
}

// (Un)select recursively all children with the right namePostfix in the container, 
function SelectChildren(container, namePostfixCheckBox, selected)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfixCheckBox
		if (childname != null && childname.length >= namePostfixCheckBox.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfixCheckBox.length, childname.length);

			if (childnamePostfix == namePostfixCheckBox)
				// The name of the child is OK; (un)check the child
				child.checked = selected;
		}
		
		// (Un)select the children of the current child
		SelectChildren(child, namePostfixCheckBox, selected);
	}
}

// (Un)select recursively the last child with the right namePostfix in the container, 
function SelectLastChildCheckBox(container, namePostfix, selected)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = container.childNodes.length - 1; idx >= 0; idx--)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfixCheckBox
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix)
			{
				// The name of the child is OK; (un)check the child
				child.checked = selected;
				return true;
			}
		}
		
		// (Un)select the children of the current child
		if (SelectLastChildCheckBox(child, namePostfix, selected))
			return true;
	}
	
	return false;
}

// (Un)select recursively the last child with the right namePostfix in the container, 
function SelectFirstChildCheckBox(container, namePostfix, selected)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx <= container.childNodes.length - 1; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfixCheckBox
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix)
			{
				// The name of the child is OK; (un)check the child
				child.checked = selected;
				return true;
			}
		}
		
		// (Un)select the children of the current child
		if (SelectFirstChildCheckBox(child, namePostfix, selected))
			return true;
	}
	
	return false;
}

// Enable/disable recursively all children with the right namePostfix in the container, 
function EnableChildren(container, namePostfix, enabled)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfix
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix)
				// The name of the child is OK; enable/disable the child
				child.parentNode.disabled = !enabled;
		}
		
		// (Un)select the children of the current child
		EnableChildren(child, namePostfix, enabled);
	}
}

// Enable/disable recursively (unselected) children with the right namePostfix in the container, 
function EnableSelectedChildren(container, namePostfix, selected, enabled)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfix
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix)
				// The name of the child is OK
				if (child.checked == selected)
					// The child is selected; (un)check the child
					child.parentNode.disabled = !enabled;
		}
		
		// (Un)select the children of the current child
		EnableSelectedChildren(child, namePostfix, selected, enabled);
	}
}

// Check recursively if the container has selected/unselected children with the right namePostfix
function HasSelectedChild(container, namePostfix, selected)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfix
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix && child.checked == selected)
				// The name of the child is OK and the child is checked; return true
				return true;
		}
		
		if (HasSelectedChild(child, namePostfix, selected))
			return true;
	}
	return false;
}

// Check recursively if the container has enabled/disabled children with the 
// right namePostfix
function HasDisabledChild(container, namePostfix, disabled)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfix
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix && child.disabled == disabled)
				// The name of the child is OK and the child is checked; return true
				return true;
		}
		
		if (HasDisabledChild(child, namePostfix, disabled))
			return true;
	}
	
	return false;
}

// Count recursively the number of selected/unselected children with the right namePostfix 
// in the container
function CountSelectedChildren(container, namePostfix, selected)
{
	var childnamePostfix;
	var childname;
	var child;
	var idx;
	var count;
	
	count = 0;
	
	// Check all items in the current container
	for (idx = 0; idx < container.childNodes.length; idx++)
	{
		child = container.childNodes[idx];
		childname = child.id;
		
		// Check if the name ends with the namePostfix
		if (childname != null && childname.length >= namePostfix.length)
		{
			childnamePostfix = childname.substring(childname.length - namePostfix.length, childname.length);

			if (childnamePostfix == namePostfix && child.checked == selected)
				// The name of the child is OK and the child is checked; return true
				count++;
		}
		
		count += CountSelectedChildren(child, namePostfix, selected);
	}
	
	return count;
}

function SetInitialSelection(container, itemSelectedName, itemIdName, selectionContainerName, selectedViewIdName, selectedSpanIdName)
{
	var itemSelected = GetChild(container, itemSelectedName);
	var itemId = GetChild(container, itemIdName);
	var selectedViewId = GetChild(container, itemIdName);
	var selectionContainer = document.getElementById(selectionContainerName);
	if ((itemSelected != null) && (itemId != null) && (selectedViewId != null) && (selectionContainer != null))
	{
		var selectedViewId = GetChild(selectionContainer, selectedViewIdName);
		var selectedSpanId = GetChild(selectionContainer, selectedSpanIdName);
		if ((selectedViewId != null) && (selectedSpanId != null))
		{
			var previousSelection = document.getElementById(selectedSpanId.value);
			if (previousSelection != null)
			{
				itemSelected.className = "itemSelected";
				
				selectedViewId.value = itemId.value;
				selectedSpanId.value = itemSelected.id;
			}
		}	
	}	
}

function InitSelection(containerName, itemIdName, selectionContainerName, selectedViewIdName, selectedClassName)
{
	var selectionContainer = document.getElementById(selectionContainerName);
	if (selectionContainer != null)
	{
		var selectedViewId = GetChild(selectionContainer, selectedViewIdName);
		if (selectedViewId != null)
		{
			var selectedViewId = selectedViewId.value;
			var itemSelected = GetSelectedItem(containerName, itemIdName, selectedViewId);
			if (itemSelected != null)
				itemSelected.className = selectedClassName;
		}
	}
}

function SetSelection(container, itemIdName, selectionContainerName, selectedViewIdName)
{
	var itemSelected = container;
	var itemId = GetChild(container, itemIdName);
	var selectedViewId = GetChild(container, itemIdName);
	var selectionContainer = document.getElementById(selectionContainerName);
	if ((itemSelected != null) && (itemId != null) && (selectedViewId != null) && (selectionContainer != null))
	{
		var selectedViewId = GetChild(selectionContainer, selectedViewIdName);
		if (selectedViewId != null)
		{
			var previousSelection = GetSelectedItem(container.id, itemIdName, selectedViewId.value);
			if (previousSelection != null)
			{
				var selectionClass = previousSelection.className;
				var notSelectionClass = itemSelected.className;
				
				itemSelected.className = selectionClass;
				previousSelection.className = notSelectionClass;
				
				selectedViewId.value = itemId.value;
			}
		}	
	}	
}

function GetSelectedItem(containerName, itemIDName, itemID)
{
	var containers = document.getElementsByName(containerName);
	var container = null;
	var itemId = null;
	
	if (containers != null)
	{
		for (idx = 0; idx < containers.length; idx++)
		{
			container = containers[idx];			
			itemId = GetChild(container, itemIDName);
			if (itemId != null)
				if (itemId.value == itemID)
					return container;
		}
	}
	return null;
}

function switchMenu(x)
{
	if(x == 1)
	{
		if (document.getElementById('menuArea_area') != null)
			document.getElementById('menuArea_area').style.display = '';
		if (document.getElementById('headerArea_menu_empty') != null)
			document.getElementById('headerArea_menu_empty').style.display = '';
		if (document.getElementById('clientArea_menu_empty') != null)
			document.getElementById('clientArea_menu_empty').style.display = '';
		if (document.getElementById('footerArea_menu_empty') != null)
			document.getElementById('footerArea_menu_empty').style.display = '';
		if (document.getElementById('menuArea_switch') != null)
			document.getElementById('menuArea_switch').innerHTML = '<table border="0"><tr><td><a href="#" onClick="switchMenu(0);"><img src="img/menu_hide.gif" width="17" height="17" border="0"></a></td><td><a href="#" onClick="switchMenu(0);">verberg menu</a></td></tr></table>';
	}
	else if(x == 0)
	{
		if (document.getElementById('menuArea_area') != null)
			document.getElementById('menuArea_area').style.display = 'none';
		if (document.getElementById('headerArea_menu_empty') != null)
			document.getElementById('headerArea_menu_empty').style.display = 'none';
		if (document.getElementById('clientArea_menu_empty') != null)
			document.getElementById('clientArea_menu_empty').style.display = 'none';
		if (document.getElementById('footerArea_menu_empty') != null)
			document.getElementById('footerArea_menu_empty').style.display = 'none';
		if (document.getElementById('menuArea_switch') != null)
			document.getElementById('menuArea_switch').innerHTML = '<table border="0"><tr><td><a href="#" onClick="switchMenu(1);"><img src="img/menu_show.gif" width="17" height="17" border="0"></a></td><td><a href="#" onClick="switchMenu(1);">toon menu</a></td></tr></table>';
	}
	
	if (document.getElementById("menuArea_switchValue") != null)
		document.getElementById("menuArea_switchValue").value = x;

	// Set widths
		
	var pageWidth;
	if (pageBody.clientWidth < 800)
		pageWidth = 800;
	else
		pageWidth = pageBody.clientWidth;

	if (document.getElementById("clientArea_area") != null)
	{
		if (document.getElementById('clientArea_menu_empty') != null &&
			document.getElementById('clientArea_menu_empty').style.display == 'none')
		{
			clientArea_area.style.width = pageWidth - 120;
		}
		else
		{
			clientArea_area.style.width = 20;
			clientArea_area.style.width = clientArea_container.clientWidth - clientArea_menu_empty.clientWidth - 4;
		}
	}
}

function UncheckAllRadioButtons(control)
{
	var child;
	var i;
	
	if (control != null)
	{	
	    var n = control.childNodes.length;
	
	    for (i = 0; i < n; i++)
	    {
		    child = control.childNodes[i];
    		
		    if (child.type == "radio")
		    {	
			    child.checked = false;
		    }
    		
		    // recurse for more radioButtons
		    UncheckAllRadioButtons(child);
	    }
    }
}

function CheckFirstRadioButton(control)
{
	var child;
	var i;
	var n = control.childNodes.length;
	
	for (i = 0; i < n; i++)
	{
		child = control.childNodes[i];
		
		if (child.type == "radio")
		{	
			child.checked = true;
			return true;
		}
		else
		{
			// recurse if no radiobutton has been found yet
			if (CheckFirstRadioButton(child)) return true;
		}
	}
	return false;
}

function EnableOrDisableControlAndAllChildren(control, doDisable)
{
	var child;
	var i;
	
	if (control != null)
	{
       	var n = control.childNodes.length;	
	
	    if(n > 0)
	    {
	        control.disabled = doDisable;
	    }
	    
	    for (i = 0; i < n; i++)
	    {
	       child = control.childNodes[i];	
       		
	       // recurse
	       EnableOrDisableControlAndAllChildren(child, doDisable);
	    }
	}
}

function HasSelectedRadioButton(control)
{
	var child;
	var i;
	var n = control.childNodes.length;
	
	// Check all items in the current containercontrol
	for (i = 0; i < n; i++)
	{
		child = control.childNodes[i];
		childType = child.type;
		
		if (child.type == "radio" && child.checked)
		{	
			return true;
		}
		else
		{
			// recurse if no checked radiobutton has been found yet
			if (HasSelectedRadioButton(child)) return true;
		}
	}
	return false;
}

// fire the correct button handler after user presses Enter button
function clickButton(e, buttonid)
{ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object')
      { 
            if(navigator.appName.indexOf("Netscape")>(-1))
            { 
                  if (e.keyCode == 13)
                 { 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
            { 
                  if (event.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
}

/*
function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}
*/

function positionModal(divID)
{
    var elem = document.getElementsByTagName(divID);
    if (elem != null)
    {    
        for (i = 0; i < elem.length; i++)
        {
            var div = elem[i];
            if (div != null && div.className == 'modalForm' )
            {
                div.style.marginLeft = "-" + parseInt(div.offsetWidth / 2) + "px";
                div.style.marginTop = "-" + parseInt(div.offsetHeight / 2) + "px";
            }  
        }
    }
}

function toggleMenu(linkName, containerName)
{
    var link = document.getElementById(linkName);
    var container = document.getElementById(containerName);
    var subnavigatie = document.getElementById("subnavigatie");
    var contentboxDossier = document.getElementById("collapsableContentboxDossier");
    var contentBreed = document.getElementById("collapsableContentBreed");

    if (link.innerHTML  == "Verberg menu")
    {
        subnavigatie.className = "collapsedSubnavigatie";
        contentboxDossier.className = "expandedContentboxDossier";
        contentBreed.className = "expandedContentBreed";
        container.className = "showMenu";
        link.innerHTML = "Toon menu";
    }
    else
    {
        subnavigatie.className = "";
        contentboxDossier.className = "contentboxDossier";
        contentBreed.className = "contentBreed";
        container.className = "hideMenu";
        link.innerHTML = "Verberg menu";
    }    
}

