﻿// Multiple Onload Functions to be called
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();
			};
		}
	}
}

/*////////////////////////////////////////////////////////////
Get Elements By Class Script by Distin Diaz
Source: http://www.dustindiaz.com/getelementsbyclass/
////////////////////////////////////////////////////////////*/
function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null ) { node = document; }
	if ( tag == null ) { tag = '*'; }
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className ) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function externalLinks() {
	var links = document.getElementsByTagName('a');
	for(var i = 0; i < links.length; i++) {
		if ( links[i].rel == 'external' ) {
		    var res = true;
          //  links[i].title = links[i].title + " (opens in a new window)";
            links[i].onclick = function (e) {
                if ( confirm('Open in a new window?') ) {
                    window.open(this.href);
                    return false;
                }
                return true;
            }
            links[i].onkeypress = function(e) {
                if (!(e.shiftKey || e.ctrlKey || e.altKey || (e.keyCode == 9) ) ) {
                    if ( confirm('Open in a new window?') ) {
                        window.open(this.href);
                        return false;
                    }
                    return true;
                }
            }
        }
    }
}


addLoadListener(externalLinks);


