// Copyright Acro Media Inc. 1998-2006, www.acromediainc.com

function copyrightYear(){
	if(document.getElementById('insertYear')) document.getElementById('insertYear').innerHTML = new Date().getFullYear();
}


function externalLinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
	}
}



//Checks to see if safari is on, boolean
var detect = navigator.userAgent.toLowerCase();
var safStatus,thestring;
function checkSafari(){	
	if (checkIt('safari')) safStatus = true;
	else safStatus = false;
	function checkIt(string){
		place = detect.indexOf(string) + 1;
		return place;
	}
}


siteOnLoad = function (){
	checkSafari();
	copyrightYear();
	externalLinks();
	loadXML();
}

function addLoadEvent(func){
	var oldOnLoad = window.onload;
	if(typeof window.onload != 'function'){ 
		window.onload = func;
	}
	else{ 
		window.onload = function(){ 
			oldOnLoad();
			func();
		}
	}
}

//XML Parser for NewsBox Imp

var xmlDoc;
var articles;
function loadXML() {
	// code for IE
	if (window.ActiveXObject) {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load("katon_articles.xml");
		getmessage();
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.load("katon_articles.xml");
		xmlDoc.onload=getmessage;
	}
	else {
		alert('Your browser cannot handle this script');
	}
}

function getmessage() {
	if (document.getElementById('newsBody')!=null) {
		articles = xmlDoc.getElementsByTagName("body").length;
		var ran_unrounded=Math.random()*articles;
		var ran_number=Math.floor(ran_unrounded);
		var xmlBodyText = xmlDoc.getElementsByTagName("body")[ran_number].childNodes[0].nodeValue;
		var newXMLBodyText = xmlBodyText.substr(0,250);
		if (xmlBodyText.length > 250) {
			newXMLBodyText = newXMLBodyText + " ... <a href='" + xmlDoc.getElementsByTagName("url")[ran_number].childNodes[0].nodeValue + "'>more</a>";
		}
		document.getElementById("newsBody").innerHTML = newXMLBodyText;
		document.getElementById("newsHeader").innerHTML = xmlDoc.getElementsByTagName("name")[ran_number].childNodes[0].nodeValue;
	}
}

addLoadEvent(siteOnLoad);

