function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

function smartRollover() {
	if(document.getElementsByTagName) {
		var image = ["img","input"];
		for(var i=0; i < image.length; i++) {
			var images = document.getElementsByTagName(image[i]);
			for(var j=0; j < images.length; j++) {
				if(images[j].getAttribute("src").match("_off.")) {
					images[j].onmouseover = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
					}
					images[j].onmouseout = function() {
						this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
					}
				}
			}
		}
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.className.match("blank")) {
			anchor.target = "_blank";
		}
		if (anchor.getAttribute("href") && anchor.className.match("popup")) {
			winPop(anchor);
		}
	}
}
function winPop(element){
	var link = element.getAttribute('href');
	var option = element.getAttribute('rel');
	var size = option.split(':');
	element.onclick = function(){
		var wo = window.open(link,"popup","width="+ size[0] +",height="+ size[1] +",status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes");
		wo.focus();
		return false;
	}
}

function stripeTable(){
	if (!document.getElementsByTagName) return;
	var tableWraps = document.getElementsByTagName("div");
	for (var i=0; i<tableWraps.length; i++) {
		var tableWrap = tableWraps[i];
		if (tableWrap.className.match("stripeTable")) {
			stripes(tableWrap);
		}
	}
}
function stripes(element){
	var tableLines = element.getElementsByTagName("tr");
	for(var i=0; i<tableLines.length; i++){
		var tableLine = tableLines[i];
		tableLine.className = (i%2==0) ? "odd" : "even";
	}
}

addEvent(window,'load',smartRollover,false);
addEvent(window,'load',externalLinks,false);
addEvent(window,'load',stripeTable,false);