function getObject(objectName)
{	
  var objItem;
  
  if (document.all)
    objItem = document.all[objectName];
  else
  {
    objItem = document.getElementById(objectName);
    if (objItem==null)
      objItem= document.getElementsByName(objectName)[0];
    if (document.getElementsByName(objectName).length>1)
      objItem=document.getElementsByName(objectName);	
  }

  return objItem;
}

function getName (object)
{
  return (object.name) ? object.name : object.id;
}

function alterDivs (obj)
{
  while (obj)
  {
    if (obj.tagName == "DIV")
    {
      obj.className = "MENUITEM";
      obj.onmouseover = menuItemHighlight;
      obj.onmouseout = menuItemDeHighlight;
      obj.style.cursor = "default";
    }
    else
      alterDivs (obj.firstChild);
    
    obj = obj.nextSibling;
  }    
}

function createRollOver (divId, minWidth, minHeight)
{
  div = getObject (divId);
  div.className = "MENUTITLE";
  div.onmouseover = menuHighlight;
  div.onmouseout = menuPreDeHighlight;
  div.style.cursor = "default";
  
  menu = getObject (divId + "_menu");
  menu.className = "MENU_SHOW"; 
  
  if (minWidth && menu.offsetWidth < minWidth)
    menu.style.width = minWidth;
    
  if (minHeight && menu.offsetHeight < minHeight)
    menu.style.height = minHeight;

  menu.maxHeight = menu.offsetHeight;
  menu.time = 10;
  menu.acc = menu.maxHeight / Math.pow (menu.time / 2, 2);
  menu.step = 0;
  menu.thisHeight = 0;
  menu.style.top = -menu.offsetHeight + "px";
  
  menu.onmouseover = function()
  {
    my_parent = getObject (divId);
    my_parent.onmouseover();
  }
  
  menu.onmouseout = function()
  {
    my_parent = getObject (divId);
    my_parent.onmouseout();
  }

  alterDivs (menu.firstChild);

	container = getObject (divId + "_container");
	container.style.visibility = 'visible';

}

function menuHighlight ()
{
  if (this.my_timer)
  {
    clearTimeout (this.my_timer);
    this.my_timer = null;
  }
  
  if (this.className != "MENUTITLE_SELECTED")
  {
    this.className = "MENUTITLE_SELECTED";
    
    objMenu = getObject (getName (this) + "_menu");
    
    if (objMenu.my_timer)
    {
      clearTimeout (objMenu.my_timer);
      objMenu.my_timer = null;
    }

    objMenu.direction = 1;
    objMenu.style.zIndex = 20;
    objMenu.my_timer = setTimeout ("menuScroll ('" + getName (objMenu) + "')", 100);
  }
}

function menuScroll (divId)
{
  div = getObject (divId);
  //alert(divId);
  
  //ShowDiv(window, divId, '');
  
  if (div.my_timer)
  {
    clearTimeout (div.my_timer);
    div.my_timer = null;
  }
  
  div.step += div.direction; 
  
  if (div.step < (div.time / 2))
  {
    div.thisHeight = .5 * div.acc * Math.pow (div.step, 2);
    div.style.top = (-div.offsetHeight + div.thisHeight) + "px";
  }
  else
  {
    div.thisHeight = (div.maxHeight) - .5 * div.acc * Math.pow (div.time - div.step, 2);
    div.style.top = (-div.offsetHeight + div.thisHeight) + "px";
  }

  if (((div.direction == 1) && (div.step < div.time)) || ((div.direction == -1) && (div.step > 0)))
    div.my_timer = setTimeout ("menuScroll ('" + divId + "')", 10);
}

function menuPreDeHighlight ()
{
  this.my_timer = setTimeout ("menuDeHighlight ('" + getName (this) + "')", 200); 
}

function menuDeHighlight (divId)
{
  obj = getObject (divId);
  clearTimeout (obj.my_timer);
  obj.my_timer = null;

  obj.className = "MENUTITLE";
  
  objMenu = getObject (divId + "_menu");
  objMenu.style.zIndex = 19;
  
  if (objMenu.my_timer)
    clearTimeout (objMenu.my_timer);

  objMenu.direction = -1;
  objMenu.my_timer = setTimeout ("menuScroll ('" + divId + "_menu')", 10);
}

function menuItemHighlight()
{
  this.className = "MENUITEM_SELECTED";
}

function menuItemDeHighlight()
{
  this.className = "MENUITEM";
}

function createRollOvers ()
{
	createRollOver ('menu_about');
	createRollOver ('menu_solution');
	createRollOver ('menu_contact');
	createRollOver ('menu_login');
	createRollOver ('menu_sinscrire');
	createRollOver ('menu_services');
	createRollOver ('menu_outils');
}

function createRollOvers_brain ()
{
	createRollOver ('menu_classification');
	createRollOver ('menu_fiche');
	createRollOver ('menu_recherche');
	createRollOver ('menu_outil');
	createRollOver ('menu_quitter');
	
}


function createRollOvers_collectivite ()
{
	createRollOver ('menu_mes_procedures');
	createRollOver ('menu_administration');
	createRollOver ('menu_statistique');
	createRollOver ('menu_outil');
	createRollOver ('menu_quitter');
	createRollOver ('menu_messagerie');
}

function createRollOvers_entreprise ()
{
	createRollOver ('menu_mes_procedures_entreprise');
	createRollOver ('menu_administration');
	//createRollOver ('menu_statistique');
	createRollOver ('menu_outil');
	createRollOver ('menu_quitter');
	createRollOver ('menu_messagerie');
}


function createRollOvers_collectivite_jvs ()
{
	createRollOver ('menu_administration');
	createRollOver ('menu_messagerie');
	createRollOver ('menu_statistique');
}


function openpopup (sURL)
{
//	window.open ('/' + sURL, 'PopupWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	window.open ( sURL, 'PopupWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
};


function openpopupSize (sURL, iWidth, iHeight)
{

	window.open (sURL, 'PopupWin', 'toolbar=no,location=no,directories=no,status=no, menubar=no, scrollbars=yes, resizable=no,height='+iHeight+',width='+iWidth);
};

function openCustomPopup (sURL, sParams)
{

	window.open (sURL, 'PopupWin', sParams);
};

function OpenWindow (sURL, sName, sParams, iWidth, iHeight)
{
	window.open (sURL, sName, sParams+',height='+iHeight+',width='+iWidth);
};


function openHelppopup (sURL)
{
	iWidth='340';
	iHeight='425';
	openpopupSize (sURL, iWidth, iHeight);

};




//Multi-browser compatible function that returns a reference to any object in the page
function GetObject(strWindow, strObjectName,strParent)
{	
	var objItem;
	
	if (document.all)
		objItem = strWindow.document.all[strObjectName];
	else
	{
		objItem = strWindow.document.getElementById(strObjectName);
		if (objItem==null)
			objItem=strWindow.document.getElementsByName(strObjectName)[0];
		if (strWindow.document.getElementsByName(strObjectName).length>1)
			objItem=strWindow.document.getElementsByName(strObjectName);	
	}

	return (objItem);
};


function cOn(td,color)
{
	if(document.getElementById||(document.all && !(document.getElementById)))
		td.style.backgroundColor=color;
}

function cOut(td,color)
	{
	if(document.getElementById||(document.all && !(document.getElementById)))
		td.style.backgroundColor=color;
}

//Function that hides/shows the righr input box depending on selected country
function ShowStateList(CountryID)
{
	if(CountryID ==41) {	//canada
		GetObject(window,'canprovdiv','').style.display = "inline";
		GetObject(window,'usprovdiv','').style.display = "none";
		GetObject(window,'otherprovdiv','').style.display = "none";
	}
	else if(CountryID ==250) {	//USA
		GetObject(window,'canprovdiv','').style.display = "none";
		GetObject(window,'usprovdiv','').style.display = "inline";
		GetObject(window,'otherprovdiv','').style.display = "none";
	}
	else {
		GetObject(window,'canprovdiv','').style.display = "none";
		GetObject(window,'usprovdiv','').style.display = "none";
		GetObject(window,'otherprovdiv','').style.display = "inline";
	}
};

//More compatible ShowDiv and HideDiv functions
//Use these instead of the ones above
//										--Arbi
function HideDiv(strWindow, strDivID, strParent)
{
	objDIV = GetObject(strWindow, strDivID, strParent);
	if (typeof(objDIV) == 'object')
	{
		objDIV.style.display = "none";
		objDIV.style.visibility = "hidden";	
		
	}

};

function ShowDiv(strWindow, strDivID, strParent)
{
	objDIV = GetObject(strWindow, strDivID, strParent);
	//alert ('showdiv');
	if (typeof(objDIV) == 'object')
	{
		objDIV.style.display = "";
		objDIV.style.visibility = "visible";
	
	}
};

function ShowHideDiv(strWindow, strDivID, strParent)
{
	objDIV = GetObject(strWindow, strDivID, strParent);
	//alert(typeof(objDIV));
	if (typeof(objDIV) == 'object')
		if (objDIV.style.visibility=='visible')
			HideDiv (strWindow,strDivID,strParent) ;
		else
			ShowDiv (strWindow,strDivID,strParent) ;
};