//ensure that all onload events are executed
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
		} else if (obj.attachEvent){
			var r = obj.attachEvent('on'+evType, fn);
			return r;
			} else {
			return false;
			}
	}
//load up the onload events
addEvent(window, 'load', iconLink);

function iconLink() {
if (document.appendChild && document.replaceChild && document.getElementsByTagName && document.createElement && !navigator.appName != "Microsoft Internet Explorer") {
	if(w = document.getElementById('main')) var links = w.getElementsByTagName('a');
	if(w = document.getElementById('fullmain')) var links = w.getElementsByTagName('a');
	if(links.length == 0) return;

		for (var i = 0; i < links.length; i++) {
			//only alter links that have a different hostname and that haven't been already crawled, and aren't newWindow already.
			var host = "pennypacker.net"; //replace("www.", window.location.hostname);
			if(links[i].hostname.indexOf(host) == -1 && links[i].className.substring(0,7) != 'nocrawl' && !links[i].onclick) {
				//create a new span
				var s = document.createElement('span');
				//recreate the link
				var o = document.createElement('a');
					o.setAttribute('href', links[i].href);
					if(links[i].title != "") {
						o.setAttribute('title', links[i].title);
						} else {
						o.setAttribute('title', links[i].href);
						}
					o.setAttribute('class', 'nocrawl');
				//populate the o link with the text from the original link
					o.appendChild(links[i].firstChild);
					
				//create a new link
				var a = document.createElement('a');
					a.setAttribute('href', links[i].href);
					a.setAttribute('onclick', "window.open(this.href, 'newwin'); return false;");
					a.setAttribute('class', 'nocrawl newwin');
					a.setAttribute('title', 'Open this link in a New Window');
				//create a child of the link, the image
				var icon = document.createElement('img');
					icon.setAttribute('src', '/s/jp/i/new_win_icon.png');
					icon.setAttribute('alt', 'Open this link in a New Window');
	
				//compile the new span
				a.appendChild(icon);
				s.appendChild(o);
				s.appendChild(a);
	
				//replace original links
				links[i].parentNode.replaceChild(s, links[i]);
				
				}
					
		}
	}
}
