var IE = document.all?true:false;
var totop = 'totop';
var bHigh = 0; var bWide = 0;
var ImageID = new Object();  var ImageID_img1 = new Object(); var ihandle = '';
var bILensIDs = '%20'; var bImgIDs = '%20'; var IHeight = '118,200'; var IWidth = '160,200';

function loadJSF(file,handle,ind) {
  var head = document.getElementsByTagName('head').item(0);
  var scriptAdd = document.getElementById(handle+ind);
  if (scriptAdd) head.removeChild(scriptAdd);
  var scriptAdded = document.createElement('script');
  scriptAdded.src = file;
  scriptAdded.type = 'text/javascript';
  scriptAdded.id = handle+ind;
  head.appendChild(scriptAdded);
}

function Layout() {

	if (IE) {
		bHigh = document.documentElement.clientHeight; // quirks mode use document.body.clientHeight in strict;
		bWide = document.documentElement.clientWidth;
	} else { // Firefox places %20 into dom for spaces
		bHigh = window.innerHeight;
		bWide = window.innerWidth;
	};
	
	if (document.getElementById(totop) && bHigh>document.getElementById(totop).offsetTop) {
		document.getElementById(totop).parentNode.removeChild(document.getElementById(totop));
	};
};

function printpage()
  {
  window.print()
  };

var mapleft = maptop = 0;
var userX; var userY;
var RFX = new Array(); var RFXCSS = new Array();
var RegLabelID = 'reglabel';
var RegMapID = 'regnavmap';
var RegLabel = null; var map = null;
var primehtml = '';
RFX[1] = 'Le portage du nord'; RFXCSS[1] = 'grandportage1';
RFX[2] = 'Le lac Sup&eacute;rieur'; RFXCSS[2] = 'superieur1';
RFX[3] = ''; RFXCSS[3] = '';
RFX[4] = 'Le Saint-Laurent'; RFXCSS[4] = 'saintlaurent1';
RFX[5] = 'La rivi&egrave;re des Outaouais'; RFXCSS[5] = 'outaouais1';
RFX[6] = ''; RFXCSS[6] = '';
RFX[7] = 'La baie Georgienne'; RFXCSS[7] = 'georgienne1';
RFX[8] = 'Le coeur de l\'Ontario'; RFXCSS[8] = 'coeurde1';
RFX[9] = 'Le lac Ontario'; RFXCSS[9] = 'lacontario1';
RFX[10] = 'La p&eacute;ninsule du Sud'; RFXCSS[10] = 'peninsule1';

function RegionNAV(RFXID) {
RegLabel = document.getElementById(RegLabelID);
if (primehtml == '') {
	primehtml = RegLabel.innerHTML; };
// document.onmouseover = getMouseXY;
// RegLabel.style.top = maptop + userY - RegLabel.offsetHeight/2 + 'px';
// RegLabel.style.left = mapleft + userX - RegLabel.offsetWidth + 'px';
RegLabel.innerHTML = RFX[RFXID];
RegLabel.className = RFXCSS[RFXID];
};

function RegionNAVOut(RFXID) {
if (RFXID == 4) { document.getElementById(RegLabelID).className = 'BaseC PrimaryBGColour';
} else { document.getElementById(RegLabelID).className = 'BaseB PrimaryBGColour';
};
document.getElementById(RegLabelID).innerHTML = primehtml;
};


function getMouseXY(e) {
	findPos(RegMapID);
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		userX = e.pageX;
		userY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		userX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft - 3;
		userY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop - 3;
	}
	userX -= mapleft; userY -= maptop;
	return true;
};


function findPos(map2) {
	map3 = document.getElementById(map2);
	mapleft = maptop = 0;
	if (map3.offsetParent) {
		do {
			mapleft += map3.offsetLeft;
			maptop += map3.offsetTop;
			} while (map3 = map3.offsetParent);
	}
	return [mapleft,maptop];
};

function loadVNImage(ihandle,key,IWidth,IHeight,memberid,infohtml)
{		 
	if (key == '') { key = '%20'; };
	
	mrg = '0px'; bdr = '2px solid';
	
	if (memberid && memberid != 0) {
		loadJSF('/DNIncludes/IIDRandomJS2i.cfm?n=1&lk=1&h='+IHeight+'&w='+IWidth+'&ih='+ihandle+'&k='+key+'&mrg='+escape(mrg)+'&bdr='+escape(bdr)+'ihtml='+infohtml+'&op='+memberid,ihandle,'1');
	} else {
		loadJSF('/DNIncludes/IIDRandomJS2i.cfm?n=1&lk=1&h='+IHeight+'&w='+IWidth+'&ih='+ihandle+'&k='+key+'&mrg='+escape(mrg)+'&bdr='+escape(bdr)+'ihtml='+infohtml,ihandle,'1');
	};
	
	infohtml = infohtml.replace('<specialimage>',eval(ihandle));
	return infohtml;
}

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object- source http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BF8004D72D6
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

function changeopimage(caller,op,IW,IH)
{	ImageID = document.getElementById(caller.id);
	if(!IH) { var IH = ImageID.height;}; if(!IW) { var IW = ImageID.width;};
	loadJSF('/DNIncludes/IIDRandomJS2.cfm?n=1&lk=1&h='+IH+'&w='+IWidth+'&DomID='+caller.parentNode.id+'&k=%20&mrg='+escape(ImageID.style.margin)+'&bdr='+escape(ImageID.style.border)+'&op='+op+'&iout='+bILensIDs,'opstack','1');

}

function changeopimage2(IID,op,IW,IH)
{	ImageID = document.getElementById(IID);
	if (ImageID.firstChild.nodeName == 'IMG') { temp = ImageID.firstChild.id;} else { temp = ImageID.firstChild.firstChild.id;};
	ImageID_img1 = document.getElementById(temp);
	if(!IH) { var IH = ImageID.height;}; if(!IW) { var IW = ImageID.width;};
	loadJSF('/DNIncludes/IIDRandomJS2.cfm?n=1&lk=1&h='+IH+'&w='+IWidth+'&DomID='+IID+'&k=%20&mrg='+escape(ImageID_img1.style.margin)+'&bdr='+escape(ImageID_img1.style.border)+'&op='+op+'&iout='+bILensIDs,'opstack','1');

}

function convertToDMS (val) {
  var valStr = val.toString();
  var parts = valStr.split(".");
  var degStr = parts[0];
  if (!parts[1]) {
    return (degStr + "&#176 0' 0'' ");
  }
  var dummyStr = (Number("0." + parts[1]) * 60).toString();
  parts = dummyStr.split(".");
  var minStr = parts[0];
  if (!parts[1]) {
    return (degStr + "&#176 " + minStr + "' 0'' ");
  }
  var secStr = roundDecimals(Math.round(Number("0." + parts[1]) * 60)).toString();
  return (degStr + "&#176 " + minStr + "' " + secStr + "'' ");
}

function convertLatToDMS (val) {
  if (val < 0) {
    return convertToDMS (Math.abs(val)) + "S";
  } else {
    return convertToDMS (Math.abs(val)) + "N";
  }
}

function convertLngToDMS (val) {
  if (val < 0) {
    return convertToDMS (Math.abs(val)) + "W";
  } else {
    return convertToDMS (Math.abs(val)) + "E";
  }
}

function roundDecimals (val) { 
  var dummy = Math.pow (10, precision);
  return Math.round(val*dummy)/dummy;
}

var source=null; var target=null; var sourceds=null; var mapgutter = 24; var oldHeight=''; var oldWidth=''; var oldLeft=0; var oldTop=0;
var toggle=-1;
function fillPage (source2) {
	/*alert(source.id); alert(source.previousSibling.id);*/
	source = source2;
	if (IE) {
		var bHigh2 = document.documentElement.clientHeight-mapgutter; // quirks mode use document.body.clientHeight in strict;
		var bWide2 = document.documentElement.clientWidth;
	} else { // Firefox places %20 into dom for spaces
		var bHigh2 = window.innerHeight;
		var bWide2 = window.innerWidth;
	};
	var scrollOffset = source.parentNode.parentNode.parentNode.offsetHeight-mapgutter-bHigh2

	
	findPos(source.id);
	
	window.scrollTo(0,maptop-mapgutter/2);

	target = source.previousSibling;
	if (oldHeight == '') {
		oldHeight = target.offsetHeight-target.style.borderTopWidth.replace('px','')-target.style.borderBottomWidth.replace('px','');
		oldWidth = target.offsetWidth-target.style.borderLeftWidth.replace('px','')-target.style.borderRightWidth.replace('px','');
		findPos(target.id); oldLeft = mapleft; oldTop = maptop;
		sourceds = source.childNodes;
	}
	if (target.style.height == oldHeight+'px') {
		target.style.height = bHigh2-mapgutter*2.5+'px'; target.style.width = bWide2-mapgutter*3.75+'px';
		target.style.position = 'absolute'; target.style.top = maptop+mapgutter/2+parseInt(target.style.borderTopWidth.replace('px',''))*2+'px'; target.style.left = mapgutter*1.5-target.style.borderLeftWidth.replace('px','') + 'px'; target.style.zIndex='1900';
		source.className = source.className.replace('o3','o8 BaseB');
		source.style.height = bHigh2-mapgutter+'px'; source.style.width = bWide2-mapgutter*2.5+'px';
		source.style.position = 'absolute'; source.style.top = maptop+'px'; source.style.left = mapgutter-target.style.borderLeftWidth.replace('px','')*2 + 'px'; source.style.zIndex='1800';

		for (var i = 0; i < sourceds.length; i++) {
			sourceds[i].style.visibility='visible';
			if (i>1) {
				sourceds[i].style.marginTop = bHigh2-mapgutter*2.25+'px';
			}
		};

	} else {
		source.className = source.className.replace('o8 BaseB','o3');
		target.style.height = source.style.height = oldHeight+'px';
		target.style.width = source.style.width = oldWidth+'px';
		target.style.position = source.style.position = 'relative';
		target.style.top = source.style.top = '0px'; target.style.left = source.style.left = '0px';
		source.style.zIndex='1900'; target.style.zIndex='1800';
		for (var i = 0; i < sourceds.length; i++) {
			sourceds[i].style.visibility='hidden';
			if (i>1) {
				sourceds[i].style.marginTop = '0px';
			}
		};
	};
	maptype=map.getCurrentMapType();
	mapzoom=map.getZoom();
	initialize();
};