
var storMenuObj;

var disappeardelay=1000  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=10 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
edgeoffset=dropmenuobj.y
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){

highLightStaticMenu(obj, 1);

if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
dropmenuobj.x=getposOffset(obj, "left");
dropmenuobj.y=getposOffset(obj, "top");
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px";
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";

mBack= document.getElementById("mnuBacker");

mBack.style.left=(parseInt(dropmenuobj.style.left) - parseInt(getposOffset(document.getElementById('mainPageDiv'), "left"))) + "px";
//mBack.style.left=getAbsoluteLeft(dropmenuobj.id);

mBack.style.top=dropmenuobj.style.top;
mBack.style.width=dropmenuobj.style.width;
mBack.style.height=dropmenuobj.offsetHeight;
mBack.style.display="block";
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
try{
	while (b.parentNode){
		if ((b = b.parentNode) == a){
			return true; 
		}
	}
} catch (e){}
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden";

document.getElementById("mnuBacker").style.display="none";

}
}

function delayhidemenu(i){
var oId=null;
if(!i){
  if(storMenuObj)
    oId= storMenuObj.id;
}
else {
  oId = 'sm'+i;
}

if (ie4||ns6)
delayhide=setTimeout("hidemenu('" + i + "')",disappeardelay);
highLightStaticMenu(document.getElementById(oId),0);
}

function clearhidemenu(){
highLightStaticMenu(storMenuObj,1);
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function highLightStaticMenu(mnuObj, hval){

if(hval==1) {
	storMenuObj = mnuObj;
	mnuObj.className="statMenuItemHL";
	
} else {

	mnuObj.className="statMenuItemNoHL";
}

var sobj;
var i = 1;
do
{
sobj = document.getElementById("sm"+i);
if(sobj){
	if(sobj!=mnuObj && sobj!=storMenuObj){
	   sobj.className="statMenuItemNoHL";
	}
}
i++;
}
while (sobj)


}

var menubaseID=new Array(); 
var basemenu=new Array();

var tlnkbaseID=new Array(); 
var basetlnk=new Array();

var qlnkbaseID=new Array(); 
var baseqlnk=new Array();

var flnkbaseID=new Array(); 
var baseflnk=new Array();


function omp_displayMenu(showHome){
 
var withChild; 
var noChild="onMouseOver=\"if(typeof hidemenu!='undefined'){ hidemenu()}; if(typeof highLightStaticMenu!='undefined'){ highLightStaticMenu(this,1); }\" onMouseout=\"if(typeof highLightStaticMenu!='undefined'){ highLightStaticMenu(this,0); }\"";

if(showHome==null) showHome=1;

document.write("<div id=\"statmenudiv\" width=\"100\">");
for(i=0;i<basemenu.length;i++) {
   if(showHome==1 || (showHome==0 && basemenu[i].indexOf('/member_portal_home')<0)){
	withChild="onMouseover=\"if (typeof dropdownmenu!='undefined'){ dropdownmenu(this, event, menu"+menubaseID[i]+", '260px') }\" onMouseout=\"if (typeof delayhidemenu!='undefined'){ delayhidemenu('"+menubaseID[i]+"')}\"";
	if(eval("menu"+menubaseID[i]+".length")==0) 
		document.write(basemenu[i].replace(/xxEVENTSxx/,noChild)); 
	else 
		document.write(basemenu[i].replace(/xxEVENTSxx/,withChild));
   }
}
document.write("</div>");

document.write('<iframe id="mnuBacker" src="'+URL_MAGMA_BASE+'blank.html" scrolling="no" frameborder="0" style="display:none;position:absolute;width:50px;height:120px;top:0px;left:0px;border:none;z-index:0"></iframe>');
}


function omp_displayToolbar(){

document.write('<TABLE class="omp_toolbar_table" cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD class=omp_toolbar>');

for(i=0;i<basetlnk.length;i++) {
	
	if(basetlnk[i].indexOf("javascript:toggleLanguage();")>=0){ 
		var newLocation = document.location.href;
		newLocation = (newLocation.indexOf("-e.cfm")>0)?newLocation.replace("-e.cfm", "-f.cfm"):newLocation.replace("-f.cfm", "-e.cfm");
		newLocation = (newLocation.indexOf("LANG=en")>0)?newLocation.replace("LANG=en", "LANG=fr"):newLocation.replace("LANG=fr", "LANG=en");
		basetlnk[i]=basetlnk[i].replace("javascript:toggleLanguage();",newLocation);
	}
	
	document.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + basetlnk[i].replace(/xxEVENTSxx/," ")); 
}

document.write('</TD><TD>&nbsp;</TD></TR><TR><TD class=omp_toolbar_bottom><IMG width="183" height=13 src="' + URL_MAGMA_BASE + 'images/menu-top.jpg" border=0></TD><TD class=omp_toolbar_bottom><IMG height=13 src="' + URL_MAGMA_BASE + 'images/toolbar-bottom.jpg" border=0></TD></TR></TBODY></TABLE>');

}


/* No prefix - navigate to URL */
/* Prefix items with MNU- to open a menu item */
/* Prefix items with NEW- to open URL in a new window */
function doQlink(qtxt)
{
 if(qtxt.indexOf("MNU-")==0)
 {
   MF_OpenMenuItem(qtxt.substring(4));
 }
 else if(qtxt.indexOf("NEW-")==0){
  window.open(qtxt.substring(4));
  document.getElementById('OMP_QUICKLINKS').selectedIndex=0;
}
else if(qtxt.indexOf("javascript:")==0){
  eval(qtxt.substring(11));
}
 else {
   parent.document.location=qtxt;
 }
}




function omp_displayQlinks(qlang){

document.write('<div id="omp_pub_qlinks" class="omp_qlinkDiv"><table width="155" border="0" cellpadding="0" cellspacing="0"><tr><td style="padding-bottom:5px;" align="center">');
document.write('<select id="OMP_QUICKLINKS" class="omp_qlink" style="width:155px;" onchange="if(this.selectedIndex>0){ doQlink(this.options[this.selectedIndex].value);};">');

if(qlang=='fr'){
	document.write('<option value="NULL" selected>Les plus populaires</option>');
} else {
	document.write('<option value="NULL" selected>Most popular</option>');
}

var qtxt = "";
for(i=0;i<baseqlnk.length;i++) {
	qtxt = baseqlnk[i].replace(/xxEVENTSxx/," ");
	qtxt = qtxt.replace(/<a /,"<option ");
	qtxt = qtxt.replace(/href=/,"value=");	
	qtxt = qtxt.replace(/<\/a>/,"</option>");
	document.write(qtxt); 
}

document.write('</select></td></tr></table></div>');

}


function omp_displayFooter(){

var html_out="";

for(i=0;i<baseflnk.length;i++) {
	if(baseflnk[i].indexOf("javascript:toggleLanguage();")>=0){ 
		var newLocation = document.location.href;
		newLocation = (newLocation.indexOf("-e.cfm")>0)?newLocation.replace("-e.cfm", "-f.cfm"):newLocation.replace("-f.cfm", "-e.cfm");
		baseflnk[i]=baseflnk[i].replace("javascript:toggleLanguage();",newLocation);
	}
	if(baseflnk[i].indexOf('xxEVENTSxx')<0){
	   html_out += baseflnk[i];
	} else {
	   html_out += " <nobr>" + baseflnk[i].replace(/xxEVENTSxx/," ") + "</nobr>";
	   if(i<(baseflnk.length-1)){
	      if(baseflnk[i+1].indexOf('xxEVENTSxx')>=0){
	         html_out += '&nbsp;&nbsp;|&nbsp;'
	      }
	   }
	}
}

document.write("<DIV id='omp_pub_footer' class='omp_footerLinks'>"+html_out+"</div>");

}

function omp_displayQlinksAdmin(){

document.write('<div id="omp_pub_qlinks" class="omp_qlinkDiv"><table width="155" border="0" cellpadding="0" cellspacing="0"><tr><td style="padding-bottom:5px;" align="center">');

if(ompLang=='fr'){
	document.write('<span class="omp_qlink">Liens rapides de l&#39;ACPM</span><br>');
} else {
	document.write('<span class="omp_qlink">CMPA Quick Links</span><br>');
}

var qtxt = "";
for(i=0;i<baseqlnk.length;i++) {
	qtxt = baseqlnk[i].replace(/xxEVENTSxx/,"onClick=\"doQlink(this.href);return false;\"");	
	document.write(qtxt+"<br>"); 
}

document.write('</td></tr></table></div>');

}

function omp_displayBreadcrumbs(){


var pgURL=parent.document.location.href;
var shortURL = pgURL.substr(pgURL.indexOf(URL_MAGMA_BASE) + URL_MAGMA_BASE.length, pgURL.length);

try{
var tUrl="";
for(i=0;i<basemenu.length;i++) {
	
	tUrl=basemenu[i];
			if(tUrl.indexOf(shortURL)>=0){			
				document.getElementById("omp_pub_breadcrumbs").innerHTML=">"+getLinkLabel(tUrl);
				return;
	}
	if(eval("menu"+menubaseID[i]+".length")>0) {
	for(var j=0;j<eval("menu"+menubaseID[i]+".length");j++){
		tUrl=eval("menu"+menubaseID[i]+"["+j+"]");
		if(tUrl.indexOf(shortURL)>=0){
			document.getElementById("omp_pub_breadcrumbs").innerHTML=">"+getLinkLabel(basemenu[i])+">"+getLinkLabel(tUrl);
			return;
		}
	}
	
	}
		
}
document.getElementById("omp_pub_breadcrumbs").innerHTML=">"+document.title;
} catch(ex){
  return;
}

}

function getLinkLabel(tUrl){

var ix1=tUrl.indexOf("</a>");

	for(var i=ix1-1;i>=0;i--){
		if(tUrl.substring(i,i+1)==">" && (tUrl.substring(i-1,i)=="\"" || tUrl.substring(i-1,i)=="'")){
			return (tUrl.substring(i+1,ix1));
			break;
		}
		
	}
return "";

}


function omp_openMenuItem(mnuName){

try{
var tUrl="";
for(i=0;i<basemenu.length;i++) {
	
	tUrl=basemenu[i];
	if(tUrl.indexOf(mnuName)>=0){	
		var lnkInfo = getLinkInfo(basemenu[i]).split("||");
		
		if(lnkInfo[1]==mnuName){
			parent.document.location.href=lnkInfo[0];
			return;
		}
	}
	if(eval("menu"+menubaseID[i]+".length")>0) {
	for(var j=0;j<eval("menu"+menubaseID[i]+".length");j++){
		tUrl=eval("menu"+menubaseID[i]+"["+j+"]");
		if(tUrl.indexOf(mnuName)>=0){
			var lnkInfo = getLinkInfo(tUrl).split("||");
					
			if(lnkInfo[1]==mnuName){
				parent.document.location.href=lnkInfo[0];
				return;
			}
		}
	}
	
	}
		
}
showMenuItemErrorAlert();

} catch(ex){
  showMenuItemErrorAlert();
}

}

function showMenuItemErrorAlert() {

	if(isMember){
		alert("Invalid menu item: " + mnuName);
	} else {
		document.location="/portal/page/portal/OMP_MBR_DOCLIB/Error_Pages/Page%20is%20not%20accessible";
	}

}


function getLinkInfo(tagHTML) { 

   var regex = /href\s*=\s*["]([\w\W]*?)["]/, g;   
   var ret = "";
   
   var m = regex.exec(tagHTML);
   if (m != null) {       
       ret = m[1];
   }

   regex = /name\s*=\s*["']([\w\W]*?)['"]/, g;
   m = regex.exec(tagHTML);
   if (m != null) {       
          ret = ret + "||" + m[1];
   }
   
   /* 
   var div = document.body.appendChild(document.createElement('div')); 
   div.style.display="none";
   div.innerHTML = tagHTML; 
   var ret = div.getElementsByTagName('a')[0].href + "||" + div.getElementsByTagName('a')[0].name; 
   document.body.removeChild(div); 
   */
   return ret; 
   
   
} 
