
/*
********************************************************************
* Drop Down Menu JavaScript Functions
********************************************************************
File Name: /Scripts/menus.js
Author: Kevin Berquist - VisionOne, Inc.
Completion Date: 
Date of Last Revision: 1/15/2001
Last Revisor: Robert Schultz
Function: render and position drop down menu containers and options
OS: N/A
Requires: Internet Explorer / Netscape 4.0 or higher browser.
********************************************************************
*/

/*
********************************************************************
* Function: N/A
* Objective: Global Variables to determine browser type, menu 
			 container margins and padding,  drop down mouse 
			 event control, drop down menu HTML. 
* Input: N/A
* Output: N/A
********************************************************************
*/
var g_blnIe = (document.all) ? true:false;
var g_blnDom = (document.getElementById) ? true:false;
var g_intYOffset = 18;
var g_intYPadding = 3;
var g_intXOffset = -2;
var g_objCurrentLayer = null;
var g_blnInLayer = false;
var g_strMenuSeperator = "|";
var g_strMenuHTML = "";
var g_intWinOffset = 20;

/*
********************************************************************
* Function: _menuOver
* Objective: performs menu drop down process
* Input: sLayerName - HTML container name
	x - The X coordinate on the screen
	y - The Y coordinate on the screen
* Output: N/A
********************************************************************
*/
function _menuOver(sLayerName,x,y){
	g_blnInLayer = true;
	var objLayer = (g_blnDom) ? document.getElementById(sLayerName):document.layers[sLayerName];
	showLayer(objLayer);
	x = x + g_intXOffset
	positionLayer(objLayer,x,y);
	g_objCurrentLayer = objLayer;
}

/*
********************************************************************
* Function: buildMenu
* Objective: Writes out the full HTML for the menu after parsing all the
	functions.
* Input: N/A
* Output: N/A
********************************************************************
*/
function buildMenu(){
	document.write(g_strMenuHTML);
}

/*
********************************************************************
* Function: closeContainer
* Objective: write the appropriate closingHTML container tag based 
			 on user user platform
* Input: N/A
* Output: N/A
********************************************************************
*/
function closeContainer(){
	
	if(g_blnIe || g_blnDom)
		g_strMenuHTML += '</div>\n';
	else
		g_strMenuHTML += '</layer>\n';
	
}

/*
********************************************************************
* Function: getElemX
* Objective: returns the x position of the argument element
			 using get real left
* Input: objElem - HTML Container Object
* Output: integer
********************************************************************
*/
function getElemX(objElem){
	var intX = (g_blnIe || g_blnDom) ? getRealLeft(objElem):objElem.x;	
	return intX;
}

/*
********************************************************************
* Function: getElemY
* Objective: returns the y position of the argument element
			 using get real top
* Input: objElem - HTML Container Object
* Output: integer
********************************************************************
*/
function getElemY(objElem){
	var intY = (g_blnIe || g_blnDom) ? getRealTop(objElem):objElem.y;	
	intY += (g_blnIe || g_blnDom) ? objElem.offsetHeight:g_intYOffset;
	return intY + g_intYPadding;
}

/*
********************************************************************
* Function: getRealLeft
* Objective: finds the left edge of the element argument
* Input: objEl - HTML Container Object
* Output: integer
********************************************************************
*/
function getRealLeft(objEl) {
    intXPos = objEl.offsetLeft;
    objTempEl = objEl.offsetParent;
    while (objTempEl != null) {
        intXPos += objTempEl.offsetLeft;
        objTempEl = objTempEl.offsetParent;
    }
    return intXPos;
}

/*
********************************************************************
* Function: getRealTop
* Objective: finds the top edge of the element argument
* Input: objEl - HTML Container Object
* Output: integer
********************************************************************
*/
function getRealTop(objEl) {
    intYPos = objEl.offsetTop;
    objTempEl = objEl.offsetParent;
    while (objTempEl != null) {
        intYPos += objTempEl.offsetTop;
        objTempEl = objTempEl.offsetParent;
    }
    return intYPos;
}

/*
********************************************************************
* Function: hideLayer
* Objective: hides the current layer 
* Input: objElem - HTML Container Object
* Output: N/A
********************************************************************
*/
function hideLayer(objElem){
	if(!g_blnInLayer && objElem != null)
		if(g_blnDom)objElem.style.display='none';
		else objElem.visibility='hide';
}

/*
********************************************************************
* Function: layerOut
* Objective: sets global var g_blnInLayer = false called when mouse
		     leaves a current HTML container
* Input: N/A
* Output: N/A
********************************************************************
*/
function layerOut(){
	g_blnInLayer = false;
	startHide();
}

/*
********************************************************************
* Function: layerOver
* Objective: sets global var g_blnInLayer = true
* Input: N/A
* Output: N/A
********************************************************************
*/
function layerOver(){
	g_blnInLayer = true;
}

/*
********************************************************************
* Function: menuOut
* Objective: sets global var g_blnInLayer = false called when mouse
			 leaves a the menu bar
* Input: N/A
* Output: N/A
********************************************************************
*/
function menuOut(){
	g_blnInLayer = false;
	startHide();
}

/*
********************************************************************
* Function: menuOver
* Objective: begins the menu drop down process
* Input: objElem - HTML container object
	strLayerName - HTML container object name
* Output: N/A
********************************************************************
*/
function menuOver(objElem,strLayerName){
	if(g_objCurrentLayer != null) hideLayer(g_objCurrentLayer);
	_menuOver(strLayerName,getElemX(objElem),getElemY(objElem));
}

/*
********************************************************************
* Function: openContainerWithId
* Objective: write the appropriate opening HTML container tag based 
			 on user user platform
* Input: intId - The ElementID for the container
* Output: N/A
********************************************************************
*/
function openContainerWithId(intId){
	if(g_blnIe || g_blnDom)
		g_strMenuHTML += '<div id="' +intId+'" style="position:absolute;display:none;" onmouseover="javascript:layerOver();" onmouseout="javascript:layerOut();">\n';
	else
		g_strMenuHTML += '<layer id="'+intId+'" visibility="hide" onmouseover="javascript:layerOver();" onmouseout="javascript:layerOut();">\n';
	
}

/*
********************************************************************
* Function: positionLayer
* Objective: positions a HTML container object using x,y coordinates
* Input: objElem - HTML Container Object
	intX - the X coordinate on the screen
	intY - the Y coordinate on the screen
* Output: N/A
********************************************************************
*/
function positionLayer(objElem,intX,intY){
	var intLyrWdth = (g_blnIe || g_blnDom) ? objElem.offsetWidth:objElem.clip.width;
	var intScrnWdth = (g_blnIe) ? document.body.clientWidth:window.innerWidth;
	var intOffset = (((intLyrWdth + g_intWinOffset) + intX) > intScrnWdth) ? ((intX+intLyrWdth+g_intWinOffset) - intScrnWdth):0;
	if(g_blnDom){
		objElem.style.left=intX - intOffset;
		objElem.style.top=intY;
	}else{
		objElem.left=intX - intOffset;
		objElem.top=intY;
	}

}

/*
********************************************************************
* Function: showLayer
* Objective: shows a HTML container object
* Input: objElem - HTML Container Object
* Output: N/A
********************************************************************
*/
function showLayer(objElem){
	if(g_blnDom)objElem.style.display='block';
	else objElem.visibility='show';
}

/*
********************************************************************
* Function: startHide
* Objective: begins to hide the current layer by setting a countdown 
			hidelayer
* Input: N/A
* Output: N/A
********************************************************************
*/
function startHide(){
	setTimeout("hideLayer(g_objCurrentLayer)",300);
}

/*
********************************************************************
* Function: writeMenu
* Objective: write the menu drop down options in an HTML Table
* Input: strOps - The array holding all the link values
* Output: N/A
********************************************************************
*/
function writeMenu(strOps){
	g_strMenuHTML += '<table cellpadding=0 cellspacing=1 border=0 bgcolor="#FFFFFF"><tr><td>\n';
	g_strMenuHTML += '<table cellpadding=2 border=0 cellspacing=0  background=../images/bg_menu.gif>\n';
	for(var i = 0; i<strOps.length; i++){
		var strMenuOp = strOps[i].split(g_strMenuSeperator)
		g_strMenuHTML += '<tr><td bgcolor="#4F85A2" onmouseover=this.style.backgroundColor="#003366"; onmouseout=this.style.backgroundColor="#4F85A2"; nowrap>\n';
		g_strMenuHTML += '<font face=arial size=1> <a class="menulink3" href="'+strMenuOp[1]+'">'+strMenuOp[0]+'</a></font>\n';
		g_strMenuHTML += '</td></tr>\n';
	}
	g_strMenuHTML += "</table>\n";
	g_strMenuHTML += '</td></tr></table>\n';
}




	var objMenu1 = ['Gens d\'affaires|business.php','Travailleurs indépendants|workers.php','Étudiants|students.php','Parrainage|sponsorship.php', 'Réfugiés|refugees.php', 'Séjour temporaire|temp.php', 'Citoyenneté|citizenship.php'];
	
	
	openContainerWithId('objMenu1');
		writeMenu(objMenu1);
	closeContainer();
	/*openContainerWithId('objMenu2');
		writeMenu(objMenu2);
	closeContainer();
	openContainerWithId('objMenu3');
		writeMenu(objMenu3);
	closeContainer();*/
	
	buildMenu();

