window.onload = setRollovers

window.onunload = globalOnUnLoad



var gaPageName = "";



function globalOnLoad()

{

GetAnchors();

}



function globalOnUnLoad()

{

}



function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != 'function') {

    window.onload = func;

  } else {

    window.onload = function() {

      oldonload();

      func();

    }

  }

}



function GetAnchors() {

  var elements = new Array('a', 'area');

  for (var j=0; j < elements.length; j++) {

    var x = document.getElementsByTagName(elements[j]);

    for (var i=0;i<x.length;i++) {

      if (x[i].className.indexOf('newWindow') != -1) {

        x[i].onkeypress = openNewWindow;

        x[i].onclick = openNewWindow;

        x[i].setAttribute("title", "New Window");

      } else if (x[i].className.indexOf('popup') != -1) {

        x[i].onkeypress = openNewWindow;

        x[i].onclick = openNewWindow;

        x[i].setAttribute("title", "Pop-up Window");

      } else if (x[i].className.indexOf('catchCode') != -1) {

        //Will not add if one of the above is used,

        //so opneNewWindow also checks

        x[i].onkeypress = gaCatchCode;

        x[i].onclick = gaCatchCode;

      } else if (isAssetDoc(x[i])) {

        var fileExt = getFileExt(x[i]);

        x[i].onkeypress = openNewWindow;

        x[i].onclick = openNewWindow;

        x[i].setAttribute("title", fileExt.toUpperCase()+" file");

      }

    }

  }

}



function gaCatchCode(e) {

  urchinTracker(GetGAPath(this));

}



function GetGAPath(obj) {

  return "/catchcode/" + getValueFromClass(obj, 'ga');

}



function openNewWindow(e) {

  if (this.className.indexOf('catchCode') != -1) {

    urchinTracker(GetGAPath(this));

  } else if (isAssetDoc(this)) {

    var url = this.href;

    var parentHost = window.location.protocol+"//"+window.location.host;

    if (url.substring(0,parentHost.length)==parentHost) {

      url = url.substr(parentHost.length);

    } else if (url.substring(0,23)=="http://www.chevron.ca/") {

      url = url.substr(23);  

    }

    urchinTracker(url);

  }

  var features = '';

  var start;

  var end;

  var width;

  var height;

  var thisurl = this.href ? this.href : "";

  width = parseInt(getValueFromClass(this, 'w'))>0 ? getValueFromClass(this, 'w') : '';

  height = parseInt(getValueFromClass(this, 'h'))>0 ? getValueFromClass(this, 'h') : '';

  if (height.length>0 || width.length>0) {

    features += height.length>0 ? 'height='+height+',' : '';

    features += width.length>0 ? 'width='+width+',' : '';

  }

  features += getFeatures(this);

   

  if (features.length>0) {

    if (features.substr(features.length-1,1) == ",")

      features = features.substr(0, features.length-1);

    window.open(this.href, '_new', features);

  } else {

    window.open(this.href);

  }

  return false;

}



function getValueFromClass(obj, attrib) {

  if (obj.className.indexOf(" "+attrib) != -1) {

    start = obj.className.indexOf(" "+attrib) + 1

    end = obj.className.indexOf(" ", start);

    end = (end == -1) ? obj.className.length - start : end - start;

    var aLength = attrib.length;

    return obj.className.substr(start+aLength, end-aLength);

  } else {

    return "";

  }

}



function isAssetDoc(obj) {

  var types = new Array("pdf", "doc", "xls");

  var fileExt = getFileExt(obj);

  

  for(i=0; i<types.length;i++) {

    if (types[i] == fileExt) {

      return true;

    }

  }

  return false;

}



function getFileExt(obj) {

  var url = obj.href;

  return url.substr(url.lastIndexOf(".")+1);

}



function getFeatures(obj) {

  var features = "";

  if (obj.className.indexOf(" scroll") != -1) {

    features += "scrollbars=yes,";

  }

  return features;

}




/*



setRollovers() scans the HTML page for any img tag that

has the class "rollover". When it finds one, it attaches

the mouseover events.



*/



function setRollovers()

{ imgs = document.getElementsByTagName("img")

  for (i=0;i<imgs.length;i++)

  { if (/rollOver/.test(imgs[i].className))

    { imgs[i].parentNode.onmouseover=function(){roll(this,true);}

      imgs[i].parentNode.onmouseout=function(){roll(this,false);}

      imgs[i].parentNode.onfocus=function(){roll(this,true);}

      imgs[i].parentNode.onblur=function(){roll(this,false);}

    }

  }

  setSelected()

  setTargets()

  globalOnLoad()

}









/*



setSelected() highlights the current section by matching

the body id to an image alt attribute.



*/



function setSelected()

{ sectionName = document.getElementsByTagName("body")[0].id

  imgs = document.getElementsByTagName("img")

  for (i=0;i<imgs.length;i++)

  { altValue = imgs[i].getAttribute("alt")

    if 

    (

    ((sectionName == "who") && (altValue == "Who We Are")) || 

    ((sectionName == "operations") && (altValue == "Canadian Operations")) || 

    ((sectionName == "health") && (altValue == "Health, Environment and Safety")) || 

    ((sectionName == "careers") && (altValue == "Careers")) || 

    ((sectionName == "community") && (altValue == "Community Engagement")) || 

    ((sectionName == "news") && (altValue == "News and Events")) || 

    ((sectionName == "contact") && (altValue == "Contact Us")) || 

    ((sectionName == "siteindex") && (altValue == "Site Index")) 

    )

    { srcImage = imgs[i].getAttribute("src")

		  srcImage = srcImage.substring(0,srcImage.length - 7)

			srcImage = srcImage + "sel.gif"

			imgs[i].setAttribute("src",srcImage)

      return

    }

  }

}









/*



setTargets() adds the target attribute to <a> tags that

have rel="newWin"



*/



function setTargets()

{ var anchors = document.getElementsByTagName("a")

  for (var i=0; i<anchors.length; i++)

  { var anchor = anchors[i]

    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "newWin") 

    { anchor.target = "_blank"

    }

  } 

}











/*



roll() handles the image rollovers.



*/



function roll(node,status)

{	nodeImg = node.firstChild

	srcImage = nodeImg.getAttribute("src")

	

	if (status)

	{	navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)

		if (navState == "off")

		{	srcImage = srcImage.substring(0,srcImage.length - 7)

			srcImage = srcImage + "on.gif"

			nodeImg.setAttribute("src",srcImage)

		}

	}

	else

	{	navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)

		if ((navState != "sel") && (navState != "off"))

		{	srcImage = srcImage.substring(0,srcImage.length - 6)

			srcImage = srcImage + "off.gif"

			nodeImg.setAttribute("src",srcImage)

		}

	}

}