//alert ("it's loaded");

// The following dynamic function runs the regional selection js functionality
// START
window.onload = function()
{
	if(TakesCookies())
		{
		if ( !Get_Cookie('province') ) 
			{
			setVisible('layer1');
			}
		else
			{
			var prov = Get_Cookie('province');
			if (window.location.search.substring(1).indexOf('region=') < 0)
				{
				checkSite(prov);
				}
			else	//has region querystring value set on another site, set cookie for this site to match
				{
				var newProv = querySt('region');
				if (prov != newProv)
					{
					Set_Cookie('province', newProv, 90, '/', '', '', false);Do_Nav(newProv);
					}
				}
			}
		}
}
// END

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
	ft = gy[i].split("=");
	if (ft[0] == ji) 
		{
		return ft[1];
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


// Array to Preload the images, add new images to preload to the end of the list
function doPreload()
{
   var the_images = new Array('/template_files/images/gnav_home-on.gif','/template_files/images/gnav_contact-on.gif','/template_files/images/gnav_myeastlink-on.gif','/template_files/images/gnav_support-on.gif','/template_files/images/button_myeastlink-on.gif','/template_files/images/back-on.gif','/template_files/images/backtotop-on.gif');
   preloadImages(the_images);
}

function preloadImages(the_images_array) {
   for(var loop = 0; loop < the_images_array.length; loop++)
   {
 	var an_image = new Image();
	an_image.src = the_images_array[loop];
   }
}

function jump(menu) 
	{
	window.open(menu.choice.options[menu.choice.selectedIndex].value);
	//ref=window.open(menu.choice.options[menu.choice.selectedIndex].value);
	//splitc=ref.lastIndexOf("*");
	//target="";
	//if (splitc!=-1)
	//{loc=ref.substring(0,splitc);
	//target=ref.substring(splitc+1,1000);}
	//else {loc=ref; target="_self";};
	//if (ref != "") {land(loc,target);}
	}

// Pop up for McAfee Section
//Begin News Pop-up window
	function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=500,height=430");
	}

////////////// FUNCTIONS FOR REGIONAL SELECTION CODE START HERE //////////////////////////////
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function checkSite(prov)
{
	var url = window.location.href;
	var newURL;
	if (prov == 'ON')	//Central site
	{
		if (url.indexOf('central/') < 0)	//the string "central" is not in the current url. It should be, put it in there except for the CCCM directory.
		{
			Do_Nav(prov);
		}
	}
	else if (prov == 'QC')	//Quebec site
	{
		if (url.indexOf('quebec/') < 0)	//the string "quebec" is not in the current url. It should be, put it in there except for the CCCM directory.
		{
			Do_Nav(prov);
		}
	}
	else if (prov == 'MB' || prov == 'AB' || prov == 'BC')	//Western site
	{
		if (url.indexOf('west/') < 0)	//the string "west" is not in the current url. It should be, put it in there except for the CCCM directory.
		{
			Do_Nav(prov);
		}
	}
	else
	{
		if (url.indexOf('central/') > 0)	//the string "central" IS in the current url. It shouldn't be, take it out.
		{
			Do_Nav(prov);
		}
	}
}

function Set_Cookie(name, value, expires, path, domain, secure, bShow)
{ 
	var d = new Date();
	var delCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + d.toUTCString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
	document.cookie = delCookie;

	if(TakesCookies())
	{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		if ( expires )
		{
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );

		var curCookie = name + "=" + escape(value) +
		  ((expires) ? "; expires=" + expires_date.toUTCString() : "") +
		  ((path) ? "; path=" + path : "") +
		  ((domain) ? "; domain=" + domain : "") +
		  ((secure) ? "; secure" : "");
		document.cookie = curCookie;
	}
	if (bShow)
		{
		setVisible('layer1');
		}
  }

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function Do_Nav(region)
{
	var url = window.location.href;
	if (url.indexOf('/CCCM/') < 0 && url.indexOf('/employmentequity/') < 0)
	{
		window.location = '/template_files/region_redirect.asp?r=' + region + '&p=' + window.location.href;
	}
}

var dmObjectsCheck=1; 
function dm_ext_ruleObjectHide() 
{ 
// Safari detect 
   if ((parseInt(navigator.productSub)>=20020000) && (navigator.vendor.indexOf('Apple Computer') != -1) && (navigator.product=='Gecko')) 
     return true; 
   else 
     return false; 
} 
	x = 20;
	y = 70;
function setVisible(obj)
{
	dm_ext_ruleObjectHide();

	var element;
	var dimmer;
	if (document.getElementById && (element = document.getElementById('layer1')) && (dimmer = document.getElementById('dimmer')))
	{
		dimmer.style.visibility = (element.style.visibility == 'visible') ? 'hidden' : 'visible';
		dimmer.style.width = window.screen.width;
		dimmer.style.height = window.screen.height;
		element.style.visibility = (element.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
}

function placeIt(obj)
{
	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px' ;
	obj.style.top = theTop + 'px' ;
	setTimeout("placeIt('layer1')",500);
}

function TakesCookies()
{
    var GetsCookie = (navigator.cookieEnabled)?true:false
    // If the browser does not support cookie check
    if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)
    {
        // Try setting up a test cookie
        document.cookie = "SampleCookie";
        // And see if it got set successfully
        GetsCookie = (document.cookie.indexOf("SampleCookie")!=-1)?true:false
    }
    return GetsCookie;
}
// FUNCTIONS FOR REGIONAL SELECTION CODE END HERE


//Scripts carried over from old

function on(pic)
{
	if (document.images)
	{
	document.images[pic].src=eval(pic + "On.src");
	}
}
function off(pic)
{
	if (document.images)
	{
	document.images[pic].src=eval(pic + "Off.src");
	}
}

	backtotopOn=new Image(64, 14)
	backtotopOn.src= "/images/site/backtotop-on.gif";
	backtotopOff=new Image(64, 14)
	backtotopOff.src= "/images/site/backtotop-off.gif";
	backtotop1On=new Image(64, 14)
	backtotop1On.src= "/images/site/backtotop-on.gif";
	backtotop1Off=new Image(64, 14)
	backtotop1Off.src= "/images/site/backtotop-off.gif";
	backtotop2On=new Image(64, 14)
	backtotop2On.src= "/images/site/backtotop-on.gif";
	backtotop2Off=new Image(64, 14)
	backtotop2Off.src= "/images/site/backtotop-off.gif";
	backtotop3On=new Image(64, 14)
	backtotop3On.src= "/images/site/backtotop-on.gif";
	backtotop3Off=new Image(64, 14)
	backtotop3Off.src= "/images/site/backtotop-off.gif";
	backtotop4On=new Image(64, 14)
	backtotop4On.src= "/images/site/backtotop-on.gif";
	backtotop4Off=new Image(64, 14)
	backtotop4Off.src= "/images/site/backtotop-off.gif";
	backtotop5On=new Image(64, 14)
	backtotop5On.src= "/images/site/backtotop-on.gif";
	backtotop5Off=new Image(64, 14)
	backtotop5Off.src= "/images/site/backtotop-off.gif";
	backtotop6On=new Image(64, 14)
	backtotop6On.src= "/images/site/backtotop-on.gif";
	backtotop6Off=new Image(64, 14)
	backtotop6Off.src= "/images/site/backtotop-off.gif";
	backtotop7On=new Image(64, 14)
	backtotop7On.src= "/images/site/backtotop-on.gif";
	backtotop7Off=new Image(64, 14)
	backtotop7Off.src= "/images/site/backtotop-off.gif";
	backtotop8On=new Image(64, 14)
	backtotop8On.src= "/images/site/backtotop-on.gif";
	backtotop8Off=new Image(64, 14)
	backtotop8Off.src= "/images/site/backtotop-off.gif";
	backtotop9On=new Image(64, 14)
	backtotop9On.src= "/images/site/backtotop-on.gif";
	backtotop9Off=new Image(64, 14)
	backtotop9Off.src= "/images/site/backtotop-off.gif";
	backtotop10On=new Image(64, 14)
	backtotop10On.src= "/images/site/backtotop-on.gif";
	backtotop10Off=new Image(64, 14)
	backtotop10Off.src= "/images/site/backtotop-off.gif";
	
function popup(mypage, myname, w, h, scroll)
{
	var winl = (screen.width - w) / 2 - 10;
	var wint = (screen.height - h) / 2 - 40;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}