var gFrameWin;
var gFrameObj;
var gFrameOrigH;
var gFrameOrigW;

function gobackToTerms(){
 return;
}

function gobackToChgpwd(){
 return;
}

function IsLoggedIntoPortal(){
  var track_cookie = OMP_GetCookie("OMP_TRACK");

	if(track_cookie!="" && track_cookie!=null){
		return true;
	} else {
		return false;
	}

}

function omp_log_io(){
	if(isLoggedIn){
		omp_logout();	
	} else {
		// When users click the login link set OMP_LANDPAGE
		// so user will end up right back at same page after logging in.
		// (unless they are on the login page when they click the login link)
		var landPage = parent.document.location.href;
		landPage = replaceChars(landPage,"http://","https://");
		if(landPage.indexOf("/omp_login.cfm")>0){
			landPage="";
		}
		OMP_SetCookie("OMP_LANDPAGE", landPage);
		omp_login();
	}
}

function omp_login(){
 parent.document.location=URL_DOMAIN_SECURE.substring(0,URL_DOMAIN_SECURE.length - 1) + URL_MAGMA_BASE + "omp_login.cfm?LANG="+ ompLang;
}

function omp_logout(){
 parent.document.location=ompLogoutURL;
}

/* ****************************************************************************** */

function toggleLanguage() {
	var targURL = document.location.href;
	var ix1 = 0;
		
	if (ompLang == "en") {
		ix1 = targURL.indexOf("-e.cfm");
		if (ix1 > 0) {
			targURL = targURL.substring(0,ix1) + "-f.cfm";	
		} else {
			targURL = replaceChars(targURL,"LANG=en","LANG=fr");
			if(targURL.indexOf("LANG=fr")<0){
				targURL = targURL + ((document.location.search!="")?"&":"?") + "LANG=fr";
			}
		}
		if(targURL != document.location.href) OMP_SetCookie("MF_MPL_LANG", "CFR");
	} else {
		ix1 = targURL.indexOf("-f.cfm");
				if (ix1 > 0) {
					targURL = targURL.substring(0,ix1) + "-e.cfm";	
		} else {
			targURL = replaceChars(targURL,"LANG=fr","LANG=en");
			if(targURL.indexOf("LANG=en")<0){
				targURL = targURL + ((document.location.search!="")?"&":"?") + "LANG=en";
			}
		}			
		if(targURL != document.location.href) OMP_SetCookie("MF_MPL_LANG", "ENG");
	}
	
	targURL = replaceChars(targURL,"&emsg=","&emsg_=");
	targURL = replaceChars(targURL,"&site2pstoretoken=","&site2pstoretoken_=");
	
	parent.document.location=targURL;
}

function loadingText(){
// This is the only language dependant text in the HTML template.
// HTML templates cannot hold multilingual information like other
// the portal objects.
	var engTxt = "Loading, please wait...";
	var frnTxt = "T&eacute;l&eacute;chargement en cours. Veuillez patienter svp...";
	var oFrm = document.getElementById("ompFrame");
	var lDiv = document.getElementById("loadingDiv");
	if(oFrm){
		lDiv.style.left=(getAbsoluteLeft("ompFrame") - parseInt(getposOffset(document.getElementById('mainPageDiv'), "left"))) + "px";
		lDiv.style.top=(getAbsoluteTop("ompFrame")) + "px";
		
   		lDiv.style.width = oFrm.style.width + ((oFrm.style.width.indexOf("px")>0)?"":"px"); 
		lDiv.style.height="400px";
			
		if (ompLang == "fr") {
			document.write(frnTxt);
		} else {
			document.write(engTxt);
		}
	} else {
		lDiv.style.display="none";
	}	
	
}

function print_window() {
	var print_ompFrame = document.getElementById("ompFrame");
	if (print_ompFrame) {
		print_ompFrame.contentWindow.focus();
		print_ompFrame.contentWindow.print();
	} else {
		window.print();
	}
}


/* ****************************************************************************** */
/* Functions to launch EEDO E-learning course. */
/* ****************************************************************************** */
function EEDOPopUp(EEDO_SERVER_SCRIPT){
   var blockedMsg = "Your browser's pop-up blocker is enabled.\nTo get all of the functionality of the CMPA website, we recommend that you ensure that pop-ups are not blocked. Please include cpcptpd2.cmpa-acpm.ca to the list of sites that allow pop-ups, or disable the pop-up blocker while using the CMPA website.";
   var EEDO_Lang = "EN";
   if(ompLang=="fr"){
	  EEDO_Lang = "FR";
      blockedMsg = "Le bloqueur de fen\u00eatres-pub de votre navigateur est activ\u00e9.\nAfin d'optimiser la fonctionnalit\u00e9 du site Web de l'ACPM, nous vous recommandons de vous assurer que les fen\u00eatres-pub ne sont pas bloqu\u00e9es. Veuillez ajouter cpcptpd2.cmpa-acpm.ca \u00e0 la liste de sites qui acceptent les fen\u00eatres-pub ou d\u00e9sactiver le bloqueur de fen\u00eatres-pub lorsque vous consultez le site Web de l'ACPM.";	
   }

   var elUrl = EEDO_SERVER_SCRIPT + "&lang=" + EEDO_Lang + "&ps_token=" + URLEncode(OMP_GetCookie("PS_TOKEN"))
   //*******************************************************************************************************************
   // *** ALWAYS LAUNCH EEDO COURSE WITH THESE WINDOW ATTRIBUTES: 'width=790,height=544,top=0,left=0,scrollbars=yes' ***
   //*******************************************************************************************************************
   var elWin = window.open(elUrl,'','width=790,height=544,top=0,left=0,scrollbars=yes');
   if(elWin==null){
		alert(blockedMsg);
		if(ompLang=="fr"){
			document.location="/portal/page/portal/OMP_MPL_DOCSRC/tools/mpl_technical_faq-f.html";
		} else {
			document.location="/portal/page/portal/OMP_MPL_DOCSRC/tools/mpl_technical_faq-e.html";
		}
   }

}

function launchElearning(EEDO_SERVER_SCRIPT){
    var browserMsg="At this time, the browser you are using is not supported by CMPA's Education online.";
    var notMemberMsg="You do not have access to this area as Education online is only accessible to members. We apologize for the inconvenience.";
	 if(ompLang=="fr"){
		 browserMsg="\u00c0 l'heure actuelle, le navigateur que vous utilisez n'est pas reconnu par l'\u00c9ducation en ligne de l'ACPM.";    
		 notMemberMsg="L'\u00c9ducation en ligne \u00e9tant accessible uniquement aux membres, vous n'avez pas acc\u00e8s \u00e0 cette section. Nous nous excusons de tout inconv\u00e9nient que cela pourrait vous causer.";
     }
	
   if(isMember!=true){
		alert(notMemberMsg);
		return ;		
	}
   var agt=navigator.userAgent.toLowerCase();

   if (agt.indexOf("msie") == -1 && agt.indexOf("firefox") == -1) {
	   alert(browserMsg);
	   if(ompLang=="fr"){
	   	document.location="/portal/page/portal/OMP_MPL_DOCSRC/tools/mpl_technical_faq-f.html";
	   } else {
	   	document.location="/portal/page/portal/OMP_MPL_DOCSRC/tools/mpl_technical_faq-e.html";
	   }
       return;
   }
	
	if ( elearnAvailable ){
	//Launch hidden IFrame that triggers e-learning pop-up on load.
	//This will activate pop-up blockers and allow us to display our message and redirect to our help page.	
	if(document.getElementById("el_launch")){
		document.getElementById("el_launch").src=document.getElementById("el_launch").src;
	} else {
	  var IframeHTML="<IFRAME id=\"el_launch\" style=\"display:none;\" src=\"" + URL_MAGMA_BASE + "/blank.html\" onLoad=\"EEDOPopUp('" + EEDO_SERVER_SCRIPT + "');\"></IFRAME>";
      document.body.innerHTML+=IframeHTML;
	}
	} else {
		//OMP_InternalLink("OMP_SST_DOCLIB/OMP_CONTENT/unavailable");
		parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
	}
	
}

/* ****************************************************************************** */

/* ****************************************************************************** */
/* Cookie related Functions.                                                                                                                  */
/* ****************************************************************************** */
function OMP_SetCookie (name, value) { 
	var expires=null;
	var path="/";
	var domain="cmpa-acpm.ca";
	var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + '; path=' + path + '; domain=' + domain;
	document.cookie = curCookie;
}
   
function OMP_DelCookie (name) {
	var expires = "Thu, 01-Jan-70 00:00:01 GMT";
	var path="/";
	var domain="cmpa-acpm.ca";
	var curCookie = name + '=' + escape(null) + ((expires) ? '; expires=' + expires : '') + '; path=' + path + '; domain=' + domain;
	document.cookie = curCookie;
}

function OMP_GetCookie(CookieName) {
    var lf = "\n";
    var CookieString = document.cookie;
    var CookieSet = CookieString.split (';');
    var SetSize = CookieSet.length;
    var CookiePieces;
    var ReturnValue = "";
    var x = 0;
    for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
		CookiePieces = CookieSet[x].split ('=');
		if (CookiePieces[0].substring (0,1) == ' ') {
			CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
		}
		if (CookiePieces[0] == CookieName) {
			/* split function doesn't handle cookie that contains "=" */
			for(var z = 2;z<CookiePieces.length;z++){
				CookiePieces[1]+= "=" + CookiePieces[z];
			}
			return CookiePieces[1];
		}
     }
     if (ReturnValue=="") return null;
 }
 
/* ****************************************************************************** */

// Function to URL encode data.
function URLEncode(inVal) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";			// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = inVal;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			  	// Can't encode this character, substitute dash instead.
				encoded += "-";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

/* DEPRECATED
function _MF_openPublicURL(url) {
	if (url.indexOf('.pdf') > 0) {
		window.open(URL_MAGMA_BASE + url,null,"height=450,width=634,status=yes,resizable,toolbar=no,menubar=no,location=no");
	} else {
		url = url.replace(/cmpa_docs\/(english|french)\/(content|resource_files)\/(\w+\/common\/(\w+\/)*\w+)-(e|f)\.html/g, "$3");
		OMP_InternalLink('OMP_COM_DOCLIB/' + url);
	}
}

function _MF_OpenMenuItem(mitem) {
	var len = ps_xlat_arr.length;
    for (var i = 0; i < len; i++) {
        if (ps_xlat_arr[i].name == mitem) {
			if ( ps_xlat_arr[i].url != "" ){
				if ( ps_xlat_arr[i].url.indexOf("portal") == 0 )
					parent.document.location = URL_PORTAL_BASE + ps_xlat_arr[i].url;
				else
					parent.document.location = ps_xlat_arr[i].url;
				return;
			} else if ( ps_xlat_arr[i].omp_menu_item != "" ){
				mitem = ps_xlat_arr[i].omp_menu_item;
				break;
			}
        }
    }
       
	omp_openMenuItem(mitem);
}


function newLocation(mf_nurl, nwin) {
	if (nwin == 2) {
		var dloc = document.location.href;
		if (mf_nurl.indexOf(".pdf") < 0) {
			nwin = 0;
		} else {
			nwin = 1;
		}
 
		if (mf_nurl.indexOf("www.cmpa") < 0 && dloc.indexOf("https:") == 0) {
			mf_nurl= mf_nurl.replace(/http:/gi, 'https:');
		}
	}
 
	if (nwin == 0) {
		var newURL = "https://cpcptpd2.cmpa-acpm.ca/psp/CPCPTPD2/CUSTOMER/CUST/e/" + "?url=" + escape(mf_nurl);
		parent.document.location = newURL;
	} else {
		window.open(mf_nurl);
	}
};
*/


/* ********************************************************** */
/* ********************************************************** */
/* Functions for when IFRAME is used to load content.         */
/* (SST pages, Google Mini results,...)                       */
/* ********************************************************** */
/* ********************************************************** */
function ompFrameUnload(){ 
	gFrameWin = null;
	
	// ** Hide the pop-up menu **
	hidemenu();
}

function showContent(frmComm) {
   
	if(!frmComm && document.getElementById("ompFrame")){
		var ofm = document.getElementById("ompFrame");
		ofm.style.height= "1000px";
		ofm.style.width= "585px";		
	}
	parent.document.getElementById("loadingDiv").style.display = "none";		

	if(document.getElementById("ompFrame")) parent.document.getElementById("ompFrame").style.visibility = "visible";
	
}

function ompFrameLoad(ompFrm) {
	
	if (ompFrm) gFrameWin = ompFrm;
  
	gFrameObj = parent.document.getElementById("ompFrame");
	
	gFrameObj.style.display = "";
	
	var sizes = getWinDocSizes(gFrameWin);
	gFrameObj.style.height = sizes.docHeight + 'px';
	//gFrameObj.style.width = sizes.docWidth + 'px';
	
	//parent.document.getElementById("mainPageDiv").style.height=getWinDocSizes().docHeight + 'px';
	
	showContent(1);
 }

/* Used to get a specified URL parameter.  Useful for transferring URL parameters from parent to SST IFrames */
function gup (name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if (results == null) {
		return "";
	} else {
		return results[1];
	}
}

/* Used to navigate to a specified page.  It is called from inside SST Iframes using parent.OMP_InternalLink(); */
/* Not used on public site
var rootURL = document.location.host;
function OMP_InternalLink(url) {
	document.location.href = 'https://' + rootURL + '/portal/page/portal/' + url;
}
*/

/* Placed in the onload of every SST Iframe, this code resizes the iframe, and then scrolls to the top to fix a bug in FF for documents with no-doctypes*/
function OMP_SST_onLoad (that) {

    that.contentWindow.document.domain = "cmpa-acpm.ca";
    ompFrameLoad(that.contentWindow);
    startTimeoutCounter();
    
    //Fix for Firefox and Safari for non-doctyped SST’s.
    if (!document.all) {
		var sizes = getWinDocSizes(that.contentWindow);
        that.height = sizes.docHeight;
        that.width = sizes.docWidth;
        that.contentWindow.scrollBy(-1000,-1000);
    }
	try {
		window.scrollBy(-2000,-1000);
	} catch(e){
	}
}

function addReturnToTop(){
   var topText = "Return to top";
   if(ompLang=="fr"){
	topText = "Haut de la page";
   }
   document.write('<a href="#top">' + topText + '</a>');
}

function displayReturnToTop(){

	try {
		var windowHeight = getViewportHeight();
		var top = document.getElementById("returnToTopDiv");
		if ( top != null ){
			if ( getAbsoluteTop("returnToTopDiv") > windowHeight )
				top.style.visibility="visible";
			else
				top.style.visibility="hidden";
		} 
		
		//document.getElementById("mainPageDiv").style.height = document.documentElement.scrollHeight;
		
		//document.getElementById("mainPageDiv").style.height = document.body.scrollHeight;
		/*
		var mpdHeight=document.getElementById("mainPageDiv").scrollHeight;			
		if(windowHeight>mpdHeight){
			document.getElementById("mainPageDiv").style.height=windowHeight;
		}
		*/
		
	} catch ( e ) {
		var top = document.getElementById("returnToTopDiv");
		if ( top != null ){
			top.style.visibility="visible";
		}
	}	

	
		
}

/*feedback function */
function openFeedback () {
	var param = "&mfCurrentURL=" + URLEncode(document.location.href);
	//OMP_InternalLink("&OMP_SST_DOCLIB/OMP_CONTENT/OMP_SST_FF" + param);
	omp_openSST("CRM", "OMP_CONTENT/OMP_SST_FF", param);
}

function max(ar) {
	var max = ar[0];
	var len = ar.length;
	for (var i = 1; i < len; i++) {
		if (ar[i] > max) {
			max = ar[i];
		}
	}
	return max;
}

function getWinDocSizes(win) {
    win = win ? win : window;
    var ua = navigator.userAgent.toLowerCase();
    var isIE = ua.indexOf("msie") != -1;
    var isSafari = ua.indexOf("safari") != -1;
    if (isIE) {
        var docX1 = win.document.documentElement.scrollWidth;
        var docY1 = win.document.documentElement.scrollHeight;
        var docX2 = win.document.body.scrollWidth;
        var docY2 = win.document.body.scrollHeight;
    } else if (isSafari) {
        var docX1 = win.document.documentElement.scrollWidth;
        var docY1 = win.document.documentElement.scrollHeight;
        var docX2 = 0;
        var docY2 = 0;
    } else {
        gFrameObj.style.height = win.document.body.clientHeight + "px";
        var docX2 = win.document.documentElement.scrollWidth;
        var docY2 = win.document.documentElement.scrollHeight;
        var docX1 = 0;
        var docY1 = 0;
    }
    return {docHeight:parseInt(max([docY1, docY2])), docWidth:parseInt(max([docX1, docX2]))};
}

function getWinDocSizes1(win) {

    win = win ? win : window;

    var ua = navigator.userAgent.toLowerCase();
    var isIE = ua.indexOf("msie") != -1;
    var isSafari = ua.indexOf("safari") != -1;
    if (isIE) {
        var docX1 = win.document.documentElement.scrollWidth;     
        var docY1 = win.document.documentElement.scrollHeight;      
        var docX2 = win.document.body.scrollWidth;       
        var docY2 = win.document.body.scrollHeight;        
    } else if (isSafari) {
        var docX1 = win.document.documentElement.scrollWidth;
        var docY1 = win.document.documentElement.scrollHeight;
        var docX2 = 0;
        var docY2 = 0;
    } else {
		
	//gFrameObj.style.width =  (win.document.body.clientWidth - 16)+ "px";
	if(typeof(gFrameObj)!="undefined") gFrameObj.style.height =  win.document.body.clientHeight + "px";
       
	var docX2 = win.document.documentElement.scrollWidth;
	var docY2 = win.document.documentElement.scrollHeight;
	var docX1 = 0;
	var docY1 = 0;
		
    }
  
    return {docHeight:parseInt(max([docY1, docY2])), 
		    docWidth:parseInt(max([docX1, docX2]))};
}

function getWinDocSizes2(win) {

    win = win ? win : window;

    var ua = navigator.userAgent.toLowerCase();
    var isIE = ua.indexOf("msie") != -1;
    var isSafari = ua.indexOf("safari") != -1;
    if (isIE) {
        var docX1 = win.document.documentElement.scrollWidth;     
        var docY1 = win.document.documentElement.scrollHeight;      
        var docX2 = win.document.body.scrollWidth;       
        var docY2 = win.document.body.scrollHeight;        
    } else if (isSafari) {
        var docX1 = win.document.documentElement.scrollWidth;
        var docY1 = win.document.documentElement.scrollHeight;
        var docX2 = 0;
        var docY2 = 0;
    } else {
       /* var docX1 = win.document.documentElement.offsetWidth;
        var docY1 = win.document.documentElement.offsetHeight;
        var docX2 = win.document.body.clientWidth;
        var docY2 = win.document.body.clientHeight;
        var docX3 = win.document.body.scrollWidth;
        var docY3 = win.document.body.scrollHeight;
	var docX4 = win.document.documentElement.scrollWidth;
	var docY4 = win.document.documentElement.scrollHeight;
	*/
	if(win!=parent){
		var docX1 = win.parent.documentElement.offsetWidth;
		var docY1 = win.parent.documentElement.offsetHeight;
		var docX4 = win.parent.documentElement.scrollWidth;
		var docY4 = win.parent.documentElement.scrollHeight;
	} else {
		var docX1 = 0;
		var docY1 = 0;
		var docX4 = 0;
		var docY4 = 0;
	}
	var docX2 = win.clientWidth;
	var docY2 = win.clientHeight;
	var docX3 = win.scrollWidth;
	var docY3 = win.scrollHeight;
	
    }
  
    return {docHeight:parseInt(max([docY1, docY2, docY3, docY4])), 
		    docWidth:parseInt(max([docX1, docX2, docX3, docX4]))};
}

getViewportHeight = function() {
  var height = 0;
  if( document.documentElement && document.documentElement.clientHeight ) {
    height = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight ) {
    height = document.body.clientHeight;
  }
  else if( window.innerHeight ) {
    height = window.innerHeight - 18;
  }
  return height;
};


function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}


function replaceChars(inVal,fChar,rChar) {

temp = "" + inVal;

while (temp.indexOf(fChar)>-1) {
  pos= temp.indexOf(fChar);
  temp = "" + (temp.substring(0, pos) + rChar + temp.substring((pos + fChar.length), temp.length));
}
return temp;
}


function omp_openSST(app, sst, params){

   var sst_lang="ENG";
   if (ompLang == "fr") {
	sst_lang="CFR";
   }

   var PUB_FEECALC_URL = URL_GST_BASE + "s/WEBLIB_MF_FCCPT.MF_ISCRIPT3.FieldFormula.IScript_FeeCalc?prepop=reg&languageCd="+sst_lang  

   if(isLoggedIn==false && sst=="OMP_SST_FC"){  
   	if ( sstAvailable) {
		window.open(PUB_FEECALC_URL,'','width=630,height=550,top=0,left=0,scrollbars=yes');
	} else {
			//OMP_InternalLink("OMP_SST_DOCLIB/OMP_CONTENT/unavailable");
			parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
			
	}
   } else if(app=="JBS") {   	
   		if ( sstAvailable && jbsAvailable ) {
			document.location= URL_JBOSS_BASE + sst + "?" + params;
		} else {
			//OMP_InternalLink("OMP_SST_DOCLIB/OMP_CONTENT/unavailable");
			parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
		}		   		   
   } else {
 
 	var landing_url = URL_PORTAL_BASE + "portal/page/portal/OMP_MBR_DOCLIB/omp_sst_link?app=" + app + "&languageCd=" + sst_lang + "&sst=" + sst + "&params=" + escape(params);
	
	if(isLoggedIn==true){
		document.location= landing_url;
	} else {
		if ( sstAvailable) {
			OMP_SetCookie("OMP_LANDPAGE", landing_url);
			omp_login();
		} else {
			//OMP_InternalLink("OMP_SST_DOCLIB/OMP_CONTENT/unavailable");
			parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
		}			
	}
   }

}
 
/* 
function launchEbms(ebmsPage)
{
	window.open(URL_CRM_BASE + "?ICType=Script&" +
			"ICScriptProgramName=WEBLIB_MF_EBMS.MF_ISCRIPT1.FieldFormula.IScript_EbmsSignon&" +
			"predirect=true&ebmsPage=" + escape(ebmsPage)); 
}
*/

function launchEbms(ebmsPage){
	var sst_lang="ENG";
	if (ompLang == "fr") {
		sst_lang="CFR";
	}
	if(isLoggedIn){
		if ( sstAvailable && ebmsAvailable ) {
			window.open(URL_CRM_BASE + "s/WEBLIB_MF_EBMS.MF_ISCRIPT3.FieldFormula.IScript_EbmsSignon?" +
					"predirect=true&ebmsPage=" + escape(ebmsPage) +
					"&languageCd=" + sst_lang);
		} else {
			//OMP_InternalLink("OMP_SST_DOCLIB/OMP_CONTENT/unavailable");
			parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
		}
	} else {	

		if ( sstAvailable && ebmsAvailable ) {	
			/* "https://www.cmpa-acpm.ca" */
			/* OMP_SetCookie("OMP_LANDPAGE", URL_DOMAIN_SECURE.substring(0,URL_DOMAIN_SECURE.length - 1) + URL_MAGMA_BASE + "docs/education/test-ebms-" + ompLang.substring(0,1) + ".cfm?ebm=" + escape(ebmsPage)); */
			OMP_SetCookie("OMP_LANDPAGE", document.location.href.replace("http:","https:") + "?ebm=" + escape(ebmsPage));
			omp_login();
		} else {		
			parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
		}
	}
}



function omp_sessionKeepAlive(isPopUp, ps_token, sysdate){
var winObj=document;
 var tmpDate = sysdate.replace(/\./g, "");
 var gmtDate = new Date(tmpDate);
 gmtDate = gmtDate.toGMTString();
 gmtDate = gmtDate.split(",")[1];
 gmtDate = gmtDate.replace(/ /g, "_");
 gmtDate = gmtDate.replace("UTC", "GMT");
 gmtDate = gmtDate.substr(1);
 document.cookie="PS_TOKEN=" + ps_token + "; path=/; domain=cmpa-acpm.ca";
 document.cookie="PS_TOKENEXPIRE=" + gmtDate + "; path=/; domain=cmpa-acpm.ca";
 
 if(isPopUp==1){
 	opener.startTimeoutCounter();
 	window.close();
}

}


function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 24;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


function omp_pubSpacer(sw){

   document.write('<IMG SRC="' + URL_MAGMA_BASE + 'images/omp_spacer.gif?sw=' + escape(sw) + '&id=' + randomString() + '" BORDER="0">');

}


function setTitles(eTitle,fTitle){

   if(parent.ompLang=='fr'){
	parent.document.title=fTitle;
   } else {
	parent.document.title=eTitle;
   }
	
   parent.document.getElementById('breadcrumbs').innerHTML='>'+parent.document.title

}


function URLDecode(encStr)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = encStr;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
           if (ch == "+") {
               plaintext += " ";
                   i++;
           } else if (ch == "%") {
                        if (i < (encoded.length-2) 
                                        && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
                                        && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
                                plaintext += unescape( encoded.substr(i,3) );
                                i += 3;
                        } else {
                                plaintext += "%[ERROR]";
                                i++;
                        }
                } else {
                   plaintext += ch;
                   i++;
                }
        } // while
   return plaintext;
};

		
function deleteAllCookies(){
  var ck = document.cookie.split("; ");
  var expires = " expires=Thu, 1 Jan 1970 00:00:00 UTC";
  for(var i=0;i<ck.length;i++){
    var cN = ck[i].split("=")[0];
    document.cookie=cN+"=; path=/;"+expires;
    //document.cookie=cN+"=;"+expires;
  }
}


function stripHTML(strHTML){
//Strips the HTML tags from strHTML

  strHTML=strHTML.replace(/<(.|\n)+?>/g, "");

  //Replace all < and > with &lt; and &gt;
  strHTML = strHTML.replace(/</g, "&lt;")
  strHTML = strHTML.replace(/>/g, "&gt;")
 
  return strHTML;
  
}

function openForgotPassword(url){
window.open (url, "cmpa_forgot_password","menubar=0,resizable=1,width=600,height=400");
}


function cancelEvent(event){
	if ( event != null ){
		event.cancelBubble = true;
		event.returnValue = false;
		if ( event.stopPropagation )
			event.stopPropagation();
		if ( event.preventDefault )
			event.preventDefault();
	}
	return false;
}

function openElearn(event, activityId, userProfileOverride){
	if ( navigator.userAgent.indexOf("Firefox") > 0  || navigator.userAgent.indexOf("Safari") > 0 ){
		if ( ompLang.indexOf("e") >= 0 ){
			alert("At this time, the browser you are using is not supported by CMPA's Education online.");
		} else {
			alert(String.fromCharCode(192) + " l' heure actuelle, le navigateur que vous utilisez n'est pas reconnu par l'" + String.fromCharCode(201) + "ducation en ligne de l'ACPM");
		}
		return cancelEvent(event);
	}
	if ( elearnAvailable && (userProfileOverride == null || userProfileOverride == true)){
		/* window.open('https://www.cmpa-acpm.ca'+URL_MAGMA_BASE+'feedback/user_profiling-' + ompLang.substring(0,1) + '.cfm?nextpage=' + activityId,'','width=790,height=544,top=0,left=0,scrollbars=yes'); */
		var elearnWindow = window.open(URL_DOMAIN_SECURE.substring(0,URL_DOMAIN_SECURE.length - 1)+URL_MAGMA_BASE+'feedback/user_profiling-' + ompLang.substring(0,1) + '.cfm?nextpage=' + activityId,'','width=790,height=544,top=0,left=0,scrollbars=yes');
		testPopUpBlocker(elearnWindow);
	} else if (elearnAvailable && !userProfileOverride){
		//skip user profiling
		var elearnWindow = window.open(URL_ELEARNING_BASE + "NewLinx/CourseLogon.php?UserID=guest&CourseID=" + activityId,'','width=790,height=544,top=0,left=0,scrollbars=yes');
		testPopUpBlocker(elearnWindow);
	} else if ( elearnAvailable == false ){
		parent.document.location = URL_MAGMA_BASE + "docs/temp_unavailable-" + ompLang.substring(0,1) + ".cfm";
	}
	return cancelEvent(event);
}

function testPopUpBlocker(win){
	if ( win == null ){
		if ( ompLang.indexOf("e") >= 0 ){
			alert("Your browser's pop-up blocker is enabled. To get all of the functionality from the CMPA website, we recommend that you ensure that pop-ups are not blocked.  Please include *.cmpa-acpm.ca to the list of sites that allow pop-ups, or disable the pop-up blocker while using the CMPA website.");
		} else {
			alert("Afin d'optimiser la fonctionnalit" + String.fromCharCode(233) + " du site Web de l'ACPM, nous vous recommandons de vous assurer que les fen" + String.fromCharCode(234) + "tres-pub ne sont pas bloqu" + String.fromCharCode(233) + "es. Les bloqueurs de fen" + String.fromCharCode(234) + "tres-pub permettent habituellement " + String.fromCharCode(224) + " certains sites d'utiliser les fen" + String.fromCharCode(234) + "tres-pub. Veuillez ajouter l'adresse *.cmpa-acpm.ca " + String.fromCharCode(224) + " la liste de sites qui acceptent les fen" + String.fromCharCode(234) + "tres-pub ou d" + String.fromCharCode(233) + "sactiver le bloqueur de fen" + String.fromCharCode(234) + "tres-pub lorsque vous consultez le site Web de l'ACPM.");
		}
	}
}


