/*
-----------------------------------------------
Common JavaScript
Version: 16 November 2006
----------------------------------------------- */


/* Add Load Event
----------------------------------------------- */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
	window.defaultStatus='Broom Consultants';
	highlightCurrentSection();
	newWindowLinks();
});


/* Highlight Current Section
----------------------------------------------- */

var arrVal = 2; // 1 = check filename, 2 = check parent directory

function extractPageName(hrefString) {
	var arr = hrefString.split('.');
	if(arr.length >= 2) {
		if(hrefString.match('.html')) {
			arr = arr[arr.length-2].split('/');
		} else {
			arr = arr[arr.length-1].split('/');
		}
		return arr[arr.length-arrVal].toLowerCase();
	} else {
		return "x";
	}
}

function setActiveMenu(arr, crtPage) {
	for(var i=0; i < arr.length; i++)
	if(extractPageName(arr[i].href) == crtPage) {
		arr[i].className = "current";
		arr[i].parentNode.className = "current";
	}
}

function highlightCurrentSection() {
	if(document.location.href) {
		hrefString = document.location.href;
	} else {
		hrefString = document.location;
	}
	if (document.getElementById("menu")!=null) {
		setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));
	}
}


/* New Window Links
----------------------------------------------- */

// Filetypes to open in new window
var filetypes = '.wmv|.pdf';

// Base URL of site
var baseUrl = document.domain;

// Find links and attach onclick handlers
function newWindowLinks() {
	var links = document.getElementsByTagName('a');
	for (var i = 0; links[i]; i++) {	
		var a = links[i];
		if (!a.href) continue;
		if ((!a.href.indexOf('http://') && !a.href.match('^http://([^.]+[.])?(' + baseUrl + ')')) || a.href.match(filetypes)) {
			a.onclick = openInNewWindow;
		}
	}
}
	
// Open link in new window unless modifier key is pressed
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	} else {
		var newWindow = window.open(this.getAttribute('href'));
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

