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_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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
	
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}	

function popSite1(site){
	var mainWin = window.open(site,'mainWin','width=775,height=725,scrollbars=1,menubar=0,status=0,toolbar=0,location=0,resizable=0,screenX=0,screenY=0,left=0,top=0');
	mainWin.focus();
}

function popSite2(site){
	var mainWin = window.open(site,'mainWin','width=775,height=675,scrollbars=1,menubar=0,status=0,toolbar=0,location=0,resizable=0,screenX=0,screenY=0,left=0,top=0');
	mainWin.focus();
}


function popSign(site){
	var mainWin = window.open(site,'mainWin','width=175,height=175,scrollbars=0,menubar=0,status=0,toolbar=0,location=0,resizable=0,screenX=0,screenY=0,left=0,top=0');
	mainWin.focus();
}

function openMapRoot(){
	exactX =(screen.width - 700)/2;
	exactY = (screen.height -425)/2;
	interactiveMap = window.open('map/map_operation.html',"interactiveMap","width=700,height=425,toolbar=0,scrollbars=0,menubar=0,left=" + exactX + ",top=" + exactY);
	interactiveMap.focus();
}

function openMapDir(){
	exactX =(screen.width - 700)/2;
	exactY = (screen.height -425)/2;
	interactiveMap = window.open('../map/map_operation.html',"interactiveMap","width=700,height=425,toolbar=0,scrollbars=0,menubar=0,left=" + exactX + ",top=" + exactY);
	interactiveMap.focus();
}

function openRegionMap(){
	exactX =(screen.width - 700)/2;
	exactY = (screen.height -425)/2;
	interactiveMap = window.open('/map/map_region.html',"interactiveMap","width=700,height=425,toolbar=0,scrollbars=0,menubar=0,left=" + exactX + ",top=" + exactY);
	interactiveMap.focus();
}

function popSiteGallery(site){
	var mainWin = window.open(site,'mainWin','width=410,height=590,scrollbars=1,menubar=0,status=0,toolbar=0,location=0,resizable=0,screenX=0,screenY=0,left=0,top=0');
	mainWin.focus();
}

function openMapDir(){
	exactX =(screen.width - 700)/2;
	exactY = (screen.height -425)/2;
	interactiveMap = window.open(comenvir + '/map/map_operation.html',"interactiveMap","width=700,height=425,toolbar=0,scrollbars=0,menubar=0,left=" + exactX + ",top=" + exactY);
	interactiveMap.focus();
}

// David hawkings to open windows on the Transmission home page.
function openWindow(theURL)
{
        newWin = window.open(theURL,'cal','dependent=no,width=300,height=350,top=175,left=250,titlebar=yes,resizable=yes'); 
}      

// for wireless demo.  See David Hawkings
function windowOp() 
{
   window.open(envir +"/Wireless/demo/main.htm","_demopage","height=630,width=420,resizable=no,menubar=no,location=no,status=no,toolbar=no,personalbar=no,scrollbars=yes,alwaysRaised=yes,screenX=0,screenY=0")
}

// for search functionality.  See Trevor Churchill
function focusOnSearch()
{           
            if(document.layers){
                        document.searchBox.document.searchForm.Terms.value='';
            }else {
                        document.searchForm.Terms.value='';
            }
}

function runSearch()
{           
            if(document.layers){
                        document.searchBox.document.searchForm.submit();
            }else {
                        document.searchForm.submit();
            }
}


// David Hawkings 
// go to the url indicated by the current directory and the value of the selected option in the passed in select list.
// This function is for use by report index pages such as stop_plan on the Alberta site or volume_planners on mainline site.

function getReport(report_list) {
	var	filename = report_list.options[report_list.selectedIndex].value;
	var url = location.href.substring(0, location.href.lastIndexOf("/") + 1);
	url += filename;
    var newWin = window.open(url,'report'); 
	newWin.focus();
}

// David hawkings
// February 2, 2004

// Build Breadcrumb
function buildBreadCrumb () {
  try {
	  var topDir = getPathArray()[0];
    var topDirDisplayName = translateDir(topDir);
		document.write('<tr>');
		document.write('    <td nowrap><a href="/index.html" class="breadCrumbGray">TransCanada Home</a></td> ');
		document.write('    <td><img src="/CS_Common/images/breadCrumb_arrow.gif" width="22" height="8"></td>');
		document.write('    <td nowrap><a href="/gas_transmission/index.html" class="breadCrumbGray">Pipelines</a></td> ');
		document.write('    <td><img src="/CS_Common/images/breadCrumb_arrow.gif" width="22" height="8"></td>');
		document.write('    <td nowrap><a href="/' + topDir + '/index.html" class="breadCrumbBlue">' + topDirDisplayName + '</a></td>');
		document.write('</tr>');
  }
  catch (e) {
    alert("Error: " + e.name + "\nMessage: " + e.message); 
  }
}

function translateDir(dir) {
  switch (dir) {
    case "Alberta":
      return "Alberta System";
//    case "BC_System":
//      return "BC System";
    case "Mainline":
      return "Canadian Mainline";
    case "Foothills":
      return "Foothills System";
    case "Transmission":
      return "Gas Transmission";
    case "Customer_Express":
      return "Customer Express";
    default:
      return dir;
  }
}


// return location path in array format
function getPathArray(){
	var dirArray = location.pathname.split("/");
  dirArray.shift();
  if (dirArray[4] == "STAGING"){
    dirArray = dirArray.slice(5);
  }
  else if (dirArray[4] == "WORKAREA"){
    dirArray = dirArray.slice(6);
  }
  return dirArray;
}

// Determine if the given link represents the current location or its parent folders
function isCurrent(link){
  var patharray = getPathArray();
  var path = patharray.join("/");
  path = "/" + path;
  var topdir = patharray[0];
  var seconddir = topdir + "/" + patharray[1];
  var topindex = topdir + "/index.htm";
  var secondindex = seconddir + "/index.htm";

  if (link.indexOf(topindex) != -1){  // The link is index page for the current section
    return true;
  }
  if (link.indexOf(secondindex) != -1){ // The link is the index page for the current sub section
    return true;
  }
  if (link == path){ // The link is the current page.
    return true;
  }
  return false;
}
