/* 
////////////////////////
// BY NWI 
// Inspired by : http://css.alsacreations.com/Construction-de-menus-en-CSS/Un-menu-deroulant-en-CSS-et-XHTML-vertical-et-horizontal
////////////////////////
*/
/////////////////////////////////////////////////////////////////////////////////////


window.onload= init;
var oldElement = null;
var menuLeftBackground_on;
var menuLeftBackground_off;
var menuRightBackground_on;
var menuRightBackground_off;
var menuLeftBackground_on_open;
var expandableAll;
var idMenu;
var exception = false;
function init()
{
	// check section	
	idMenu = getURLParam('id')
	
	// check Menu presence! 
	var leftMenu = document.getElementById('leftMenu');
	var rightMenu = document.getElementById('rightMenu');
	
	if(leftMenu) 
	{ 
		menuLeftBackground_on ='url(/img/layout/white_arrow.gif) #bf4377 5px 9px no-repeat';
		menuLeftBackground_on_open ='url(/img/layout/white_arrow_down.gif) #bf4377 5px 9px no-repeat';
		menuLeftBackground_off ='url(/img/layout/white_arrow.gif) #EC6290 5px 9px no-repeat';	
		//initMenu('sLeftMenu','StyleLeftMenu',idMenu)
	}
			
	if(rightMenu) 
	{
		menuRightBackground_on ='url(/img/layout/dark_arrow.gif) #FFF0E6 5px 9px no-repeat';
		menuRightBackground_on_open ='url(/img/layout/dark_arrow_down.gif) #FFF0E6 5px 9px no-repeat';
		menuRightBackground_off ='url(/img/layout/dark_arrow.gif) #F3E0D3 5px 9px no-repeat';
		initMenu('sRightMenu','StyleRightMenu',null)
	}	
}
/////////////////////////////////////////////////////////////////////////////////////
// USEFULL FUNCTION FROM : http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
// RETRIEVE THE value of a param in an URL.
function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 )
	{
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
				if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
				{
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
				}	
		}
	}
	return strReturn;
}




/////////////////////////////////////////////////////////////////////////////////////
function initMenu(element, styled, section)
	{
	// PUT RIGHT STYLE
	
	if(section)
	{
		dd = document.getElementById('StyleLeftMenu' +section);
		if (dd)
			{
			dd.className='open'
			}
		
	}
	// DISPLAY ACTION FOR EVERYELEMENT.

		for (var i = 1; i<=20; i++) 
		{
			if (document.getElementById(element+i)) 
			{		
				
				if(i == section)
				{
				document.getElementById(element+i).style.display='block';
				
				}
				else
				{
				document.getElementById(element+i).style.display='none';
				
				}			
			}			
			switch(element)
			{
				case 'sLeftMenu':
				var over_m = menuLeftBackground_on 
				var out_m = menuLeftBackground_off
				var over_m_open = menuLeftBackground_on_open
				var expandableAll = false;
				var menuToUse = 'StyleLeftMenu';
				break;
				
				case 'sRightMenu':			
				var over_m = menuRightBackground_on
				var out_m = menuRightBackground_off
				var over_m_open = menuRightBackground_on_open
				var expandableAll = true;
				var menuToUse = 'StyleRightMenu';
				break;
			}		
			
			if (document.getElementById(styled+i)) {			
					document.getElementById(styled+i).onclick = function() {
					if(this.getAttribute('href') && this.getAttribute('href')!=''){window.location=this.getAttribute('href');}
					var elementID = new Array();
					elementID = this.id.split(styled);					
					ShowMenu(element + elementID[1], element,expandableAll,this);
						
					
				}
				document.getElementById(styled+i).onmouseover = function() {
				
					if (this.className=='open')
					{
						this.style.background=over_m_open;
						
					}
					else
					{
						this.style.background=over_m;					
					}				
				}
				document.getElementById(styled+i).onmouseout = function() {
				if (this.className=='open')
					{
						
						this.style.background=over_m_open;
					}
					else
					{
						this.style.background=out_m;					
					}
					
				}
			}
		}
		
		
		
}
/////////////////////////////////////////////////////////////////////////////////////

function ShowMenu(id,element,expandableAllSection,dtClicked) 
	{	
	switch(element)
			{
				case 'sLeftMenu':
				var over_m = menuLeftBackground_on;
				var out_m = menuLeftBackground_off;
				var over_m_open = menuLeftBackground_on_open;
				var expandableAll = false;
				var menuToUse = 'StyleLeftMenu';
				break;
				
				case 'sRightMenu':			
				var over_m = menuRightBackground_on;
				var out_m = menuRightBackground_off;
				var over_m_open = menuRightBackground_on_open;
				var expandableAll = true;
				var menuToUse = 'StyleRightMenu';
				break;
			}		
	
	for (tt = 1 ; tt<=6 ; tt++)
			{
					 //document.getElementById('StyleLeftMenu' + tt);
				if (document.getElementById(menuToUse + tt))							
					{
						if (!expandableAllSection) 
						{
							if (document.getElementById(menuToUse + tt) != dtClicked)
							{
								var eDt = document.getElementById(menuToUse + tt)
								eDt.className='close';
								eDt.style.background = out_m
							}
							else
							{
								var eDt = document.getElementById(menuToUse + tt)
								eDt.className='open';
								eDt.style.background = over_m_open
							}		
							
						}	
						else
							{
								if (dtClicked.className == 'open')
								{
								
								dtClicked.style.background = out_m;
								dtClicked.className = 'close';								
								} 
								else if (dtClicked.className == 'close')
								{
								
								dtClicked.style.background = over_m_open;
								dtClicked.className = 'open';					
								}								
							}		
					}
			}
		
	
	var d = document.getElementById(id);
	if (!d){return;}
	if (expandableAllSection) {
		if(d.style.display == 'none')
		{
			d.style.display ='block';			
		}
		else
		{
			d.style.display ='none';
			dtClicked.style.background =  out_m;
			dtClicked.className='close';
		}	
	}
	else
	{
		if(oldElement == d) 
		{
		
			d.style.display='none'; 	
			oldElement =null;
			dtClicked.style.background =  out_m;
			dtClicked.className='close';
		 
		} 
		else 
		{
		if(!expandableAllSection) 
			{
				for (var i = 1; i<=10; i++) 
				{	
		 		if (document.getElementById(element+i)) 
						{		
							document.getElementById(element+i).style.display='none';				
							
						}
					}	
			}
			
			if (d) {			
			d.style.display='block';
			}
			oldElement = d;
		}	
	}	
}
/////////////////////////////////////////////////////////////////////////////////////
function getAnchor(whatMenu,menu)
{
	
	exception= true
	var elementExeption = document.getElementById(whatMenu);
	var menuExeption = document.getElementById(menu);

	if(elementExeption  && menuExeption)
	{
	elementExeption.className ='open';
	menuExeption.style.display = 'block';	
	elementExeption.style.background = menuRightBackground_on_open;
	}
	
}


var over_m ='url(/img/layout/white_arrow.gif) #bf4377 5px 9px no-repeat';
var over_m_open ='url(/img/layout/white_arrow_down.gif) #bf4377 5px 9px no-repeat';
var out_m ='url(/img/layout/white_arrow.gif) #EC6290 5px 9px no-repeat';	

function LeftMenuMouseOver(item) 
{
    if (item.className=='open')
    {
	    item.style.background=over_m_open;
    	
    }
    else
    {
	    item.style.background=over_m;					
    }				
}
function LeftMenuMouseOut(item) {
    if (item.className=='open')
    {
    	
	    item.style.background=over_m_open;
    }
    else
    {
	    item.style.background=out_m;					
    }

}

var openMenu;
var openSubMenu;


function highlightItem(item)
{
    item.className='open';
}
function unhighlightItem(item)
{
    item.className='close';
    item.style.background=out_m;					
}
function hideMenu(item)
{
    item.style.display='none';
}


function LeftMenuClick(item) 
{
    if(openMenu)
        unhighlightItem(openMenu);
    if(openSubMenu)
        hideMenu(openSubMenu);
    highlightItem(item);
    openMenu = item;
}

function setOpenMenu(itemID)
{
    openMenu= document.getElementById(itemID);
}


function setOpenSubMenu(itemID)
{  
    openSubMenu= document.getElementById(itemID);
}