var ActiveMenu = 0

function OpenMainMenu (mhid, ele, oc) {

	// Hide elements which are always on top
	var result = GetElementsByClassName('flashobject','div');
	for (i=0; i<result.length; i++) {
		result[i].style.display = 'none'
	}	
	
	// Close menu which is opened
	if (document.getElementById('MenuDiv') || ActiveMenu == mhid) {
		HideMainMenu ();
	}	

	// Set active menu
	ActiveMenu = mhid;
	
	// Create submenu
	// Div
	var MenuDiv = document.createElement ('div')
	MenuDiv.setAttribute ('id', 'MenuDiv')
	MenuDiv.style.position = 'absolute'
	MenuDiv.zIndex = '9'
	MenuDiv.style.left = '-2px'
	MenuDiv.style.top = '49px'
	MenuDiv.style.zIndex = '9999'
	document.getElementById('menu'+mhid).appendChild (MenuDiv)
	
	// Table
	var sm_table = document.createElement ('table')
	sm_table.setAttribute('id', 'sm_table');
	sm_table.cellPadding = '0';
	sm_table.cellSpacing = '0';
	sm_table.className = 'submenu'
	
	// Tbody
	var sm_tb = document.createElement ('tbody')
	sm_table.appendChild (sm_tb)
	
	// For each submenu item create a row
	for (var i in menu[mhid]['submenu']) {
		
		var sm_tr = document.createElement ('tr')
		sm_tb.appendChild (sm_tr)
		
		var sm_td = document.createElement ('td')
		sm_td.className = 'main_submenuitem_out'
		sm_td.onmouseover = new Function ('this.className="main_submenuitem_over"')
		sm_td.onmouseout = new Function ('this.className="main_submenuitem_out"')
		sm_td.onclick = new Function ('Loading("Een ogenblik geduld alstublieft..", "200px"); document.location="?m=' + menu[mhid]['keyname'] + '&s=' + menu[mhid]['submenu'][i]['keyname'] + '&enter=1"')
		
		var submenuTitle = menu[mhid]['submenu'][i]['title'];
		
		// Some html special characters string replace
		submenuTitle = submenuTitle.replace("&#039;","'");
		
		// Set submenu
		sm_td.appendChild (document.createTextNode (submenuTitle))
		sm_tr.appendChild (sm_td)
	}
	
	MenuDiv.appendChild (sm_table)
	MenuDiv.style.display = 'block'
	
	// IE fix with an iframe so a submenu will also shown above a combobox
	if (!browser) {
	    if (!document.getElementById('ie_fix_iframe_menudiv')) {
	        var ie_iframe = document.createElement('iframe')
	        ie_iframe.setAttribute('id', 'ie_fix_iframe_menudiv')
	        ie_iframe.setAttribute('frameborder', 0)
	        ie_iframe.style.position = 'absolute'
	        ie_iframe.style.zIndex = '9998'
	        ie_iframe.style.top = '0px'
	        ie_iframe.style.left = '10px'
	        ie_iframe.src = 'include/empty.html'
	        document.getElementById('menu'+mhid).appendChild (ie_iframe)
	    } else {
	        var ie_iframe = document.getElementById('ie_fix_iframe_menudiv')
	    }
	    
	    ie_iframe.style.left = MenuDiv.style.left
	    ie_iframe.style.top = MenuDiv.style.top
	    ie_iframe.style.width = MenuDiv.offsetWidth
	    ie_iframe.style.height = MenuDiv.offsetHeight
	}	
}

// Close menu
function HideMainMenu () {
	
	// Hide elements which are always on top
	var result = GetElementsByClassName('flashobject','div');
	for (i=0; i<result.length; i++) {
		result[i].style.display = 'block'
	}	
	
	if (ActiveMenu) {
		
		// Close iframe when it was created
	    if (document.getElementById ('ie_fix_iframe_menudiv')) {
	        document.getElementById('menu'+ActiveMenu).removeChild(document.getElementById('ie_fix_iframe_menudiv'))
	    }
	    
	    // Close Submenu
	    if (document.getElementById ('MenuDiv')) {	
			document.getElementById('menu'+ActiveMenu).removeChild (document.getElementById('MenuDiv'))
	    }
	    
		ActiveMenu = 0
	}	
}

/**
*
* Simple version
*
*/

mainMenuTimer = setTimeout('',0);
activeMainMenu = null;

function openMenu(id) {
	clearTimeout(mainMenuTimer);
	closeMenu();
	document.getElementById(id).style.display = 'block';
	activeMainMenu = id;
}

function closeMenu() {
	if(activeMainMenu != null){
		document.getElementById(activeMainMenu).style.display = 'none';
		activeMainMenu = null;
	}
}
