// KnowledgeWise Web Design
// JavaScript
// 2009

// Event Binding Function
function addLoadListener(fn) {
  if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', fn, false);
  } else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  } else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  } else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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'), '_blank');
		if (newWindow) {
			if (!newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.getElementsByTagName) {
		var links = document.getElementsByTagName('a');
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (/\bnew\-window\b/.test(link.className)) {
				link.onclick = openInNewWindow;
			}
		}
	}
}

function emAddress() {
	var user = [["&#100;&#97;&#118;&#105;&#100;", "&#107;&#110;&#111;&#119;&#108;&#101;&#100;&#103;&#101;&#119;&#105;&#115;&#101;&#46;&#99;&#111;&#46;&#117;&#107;", "Enquiry%20via%20OMSM%20Website"], ["&#119;&#101;&#98;&#100;&#101;&#115;&#105;&#103;&#110;","&#107;&#110;&#111;&#119;&#108;&#101;&#100;&#103;&#101;&#119;&#105;&#115;&#101;&#46;&#99;&#111;&#46;&#117;&#107;", "Enquiry%20via%20Website"]];
	var locations = document.getElementsByTagName('span');
	var link = "";
	var thissubject = "";
	for(i=0; i<locations.length; i++) {
		if (/\bme\b/.test(locations[i].className)) {
			for(u=0; u<user.length; u++) {
				adid = "a" + u;
				adobj = document.getElementById(adid);
				if(locations[i] == adobj) {
					link = user[u][0] + "&#64;" + user[u][1];
					thissubject = "?subject=" + user[u][2];
					locations[i].innerHTML = "<a href=\"mailto:"+link+thissubject+"\">"+link+"<\/a>";
				}
			}
		}
	}
}


addLoadListener(getNewWindowLinks);
addLoadListener(emAddress);

