/*
if(window.self.location.href != window.top.location.href){
	window.top.location.replace(window.self.location.href);
}
*/

// simple accessible popup
// example: href="normalurl.html" onclick="return openPopup(this.href,800,600, 1, 1, 1, 1, 0, 0);"
function XY_openPopup(i, width, height, location, menubar, resizable, scrollbars, status, toolbar) {
	window.open(i, 'popup', 'width='+width+',height='+height+',location='+location+',menubar='+menubar+',resizable='+resizable+',scrollbars='+scrollbars+',status='+status+',toolbar='+toolbar);
	return false;
}

function openPopup(i, width, height, location, menubar, resizable, scrollbars, status, toolbar) {
	window.open(i, 'popup', 'width='+width+',height='+height+',location='+location+',menubar='+menubar+',resizable='+resizable+',scrollbars='+scrollbars+',status='+status+',toolbar='+toolbar);
	return false;
}

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;
	}
}

function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		Result = obj.getAttributeNode("class").value;
	}
	return result;
}

function flipFlopTables() {
    var evenColor = " flip";
    var oddColor = " flop";
	var table = document.getElementsByTagName("table");
	
	for(var g = 0; g < table.length; g++){
		var even = true
		
		if(table[g].className == 'flipFlop'){
		    var tbodies = table[g].getElementsByTagName("tbody");

			for (var h = 0; h < tbodies.length; h++) {
				var trs = tbodies[h].getElementsByTagName("tr");

				for (var i = 0; i < trs.length; i++) {
					if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
						var tds = trs[i].getElementsByTagName("td");
						var ths = trs[i].getElementsByTagName("th");

						for (var j = 0; j < tds.length; j++) {
							var mytd = tds[j];
							
							if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
								if (mytd.className == "noDownload"){ // for multiple download table
									mytd.className += even ? evenColor : oddColor;
								} else {
									mytd.className = even ? evenColor : oddColor;
								}
							}
						}
						for (var l = 0; l < ths.length; l++) {
							var myth = ths[l];
							
							if (! hasClass(myth) && ! myth.style.backgroundColor) {
								myth.className = even ? evenColor : oddColor;
							}				
						}
						if(tds[0]){	tds[0].className += " tdLeftSide"}
					}
					even =  ! even;
				}
			}
		}
	}
}

function markExternalLinks() {
	var aA = document.getElementsByTagName('a');
	for (var i=0;i<aA.length;++i) {
		if ((aA[i].href.indexOf(document.location.host) === -1) && (aA[i].href.indexOf('mailto') === -1)) {
			aA[i].className += ' externalLink';
			aA[i].target = '_blank';
		}
	}
}

addEvent(window, "load", flipFlopTables);
addEvent(window, "load", markExternalLinks);
