function importXML(xmlFile, xmlDisplay) { 
	var param = new Array();
	for (var a=2; a<arguments.length; a++) {
		param[a-2] = arguments[a];
	}

	if (window.ActiveXObject) { 
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () { 
			if (xmlDoc.readyState == 4) xmlDisplay(param);
		}
	} else if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = function() { 
			xmlDisplay(param);
		}
	} else {
		alert('Please use an XML capable browser such as Internet Explorer 6 or Firefox 1.x');
		return;
	}
	
	xmlDoc.async = false;
	xmlDoc.load("xml/" + xmlFile);
}

// remove one level white space nodes in XML (specifically for Mozilla browsers)
function removeWhitespaceNodes(XMLnode) {
	var notWhitespace = /\S/;		// regular expression for non-whitespaces

	for (var i=0; i<XMLnode.childNodes.length; i++) {
		if ((XMLnode.childNodes[i].nodeType == 3) && (!notWhitespace.test(XMLnode.childNodes[i].nodeValue))) {
			XMLnode.removeChild(XMLnode.childNodes[i]);
			i--;
		}
	}
	return XMLnode;
}

// remove three level white space nodes in XML (specifically for Mozilla browsers)
function removeAllWhitespaces(XMLnode) {
	for (var i=0; i<XMLnode.length; i++) {
		removeWhitespaceNodes(XMLnode[i]);
		for (var j=0; j<XMLnode[i].childNodes.length; j++) {
			removeWhitespaceNodes(XMLnode[i].childNodes[j]);
			for (var k=0; k<XMLnode[i].childNodes[j].childNodes.length; k++) {
				removeWhitespaceNodes(XMLnode[i].childNodes[j].childNodes[k]);
			}
		}
	}
	return XMLnode;
}



function menuContent() {
	var allPages = xmlDoc.getElementsByTagName("pages");
	removeAllWhitespaces(allPages);
	
	for (var j=0; j<allPages[0].childNodes.length; j++) {
		var onhover, onclick

		var drop = allPages[0].childNodes[j].childNodes.length; 
		onhover = (drop==0) ? "onmouseover=\"hoverOn(this);\" onmouseout=\"hoverOff(this);\" " : "onmouseover=\"hoverOn(this); toggleMenu(this, 'drop');\" onmouseout=\"hoverOff(this); toggleMenu(this, 'drop');\" ";
		onclick = "onclick=\"document.location.href='" + allPages[0].childNodes[j].attributes[1].value + "'\" ";

		document.write("<div class=\"top\" " + onhover + ">");
		document.write("<div " + onclick + ">" + allPages[0].childNodes[j].attributes[0].value + "</div>");
		if (drop!=0) {
			document.write("<div class=\"drop\" style=\"display: none; background-color: #fff;\">");
			for (var k=0; k<drop; k++) {
				var expand = allPages[0].childNodes[j].childNodes[k].childNodes.length; 
				var sid = addZero(j) + "," + addZero(k);
				
				onhover = (expand==0) ? "onmouseover=\"hoverOn(this);\" onmouseout=\"hoverOff(this);\" " : "onmouseover=\"hoverOn(this); toggleMenu(this, 'expand');\" onmouseout=\"hoverOff(this); toggleMenu(this, 'expand');\" ";
				onclick = "onclick=\"document.location.href='article.html?id=" + sid + "&file=" + allPages[0].childNodes[j].childNodes[k].attributes[1].value + "'\" ";

				document.write("<div class=\"cat\" " + onhover + ">");
				document.write("<div " + onclick + ">" + allPages[0].childNodes[j].childNodes[k].attributes[0].value + "</div>");
				
				if (expand!=0) {
					document.write("<div class=\"expand\" style=\"display: none; background-color: #fff;\">");
					for (var l=0; l<expand; l++) {
						var pid = sid + "," + addZero(l);
						document.write("<div class=\"art\" onmouseover=\"hoverOn(this);\" onmouseout=\"hoverOff(this);\" onclick=\"document.location.href='article.html?id=" + pid + "&file=" + allPages[0].childNodes[j].childNodes[k].childNodes[l].attributes[1].value + "'\">" + allPages[0].childNodes[j].childNodes[k].childNodes[l].attributes[0].value + "</div>");
					}
					document.write("</div>");
				}
				document.write("</div>");
			}
			document.write("</div>");
		}
		document.write("</div>");
	}
}

// randomize call-to-action slogans
function callToAction() {
	var calls = xmlDoc.getElementsByTagName("calls");
	removeAllWhitespaces(calls);
	
	var selector = Math.floor(calls[0].childNodes.length*Math.random());

	for (var m=0; m<calls[0].childNodes[selector].childNodes.length; m++) {
		document.write("<div style=\"position: absolute; left: " + calls[0].childNodes[selector].childNodes[m].attributes[0].value + "px; top: " + calls[0].childNodes[selector].childNodes[m].attributes[1].value + "px; font-weight: normal; font-size: " + calls[0].childNodes[selector].childNodes[m].attributes[2].value + "px; color: " + calls[0].childNodes[selector].childNodes[m].attributes[3].value + ";\">")
		document.write(calls[0].childNodes[selector].childNodes[m].firstChild.nodeValue);
		document.write("</div>")
	}
}

// display news headlines (on the home page)
function newsHeadlines() {
	var lines = 0;
	
	var news = xmlDoc.getElementsByTagName("news");
	removeAllWhitespaces(news);

	for (var n=0; n<news[0].childNodes.length; n++) {
		if (news[0].childNodes[n].attributes[0].value=="true") {
			document.write("<p><a onfocus=\"this.blur();\" href=\"news.html?id=" + addZero(n) + "\">" + news[0].childNodes[n].childNodes[0].firstChild.nodeValue + "</a></p>");
			lines += Math.round(news[0].childNodes[n].childNodes[0].firstChild.nodeValue.length/45)+1;
		}
	}
	
	var bottomHeight = "min-height: " + lines*20 + "px;";
	document.getElementById("bottom").setAttribute("style", bottomHeight);
}

// display news headline (on the news page)
var newsHeadline, newsContent, newsNav, moreNews; 

function thisNews() {
	var newsID = parseInt(arguments[0][0]);

	var news = xmlDoc.getElementsByTagName("news");
	removeAllWhitespaces(news);

	thisHeadline = "<div class=\"h2\">" + news[0].childNodes[newsID].childNodes[0].firstChild.nodeValue + "</div>";
	thisContent  = news[0].childNodes[newsID].childNodes[1].firstChild.nodeValue;

/*	
	newsNav = "<div id=\"navigator\">";
	newsNav += "<div id=\"left\">";
	var prevNewsID, nextNewsID;
	
	if (newsID>0) {
		prevNewsID = addZero(newsID-1);
		newsNav += "<table><tr><td>"
		newsNav += "<img src=\"images/arrow_left.gif\" class=\"west\" /></td>";
		newsNav += "<td><a onfocus=\"this.blur();\" href=\"news.html?id=" + prevNewsID + "\">";
		newsNav += news[0].childNodes[newsID].previousSibling.childNodes[0].firstChild.nodeValue;
		newsNav += "</a></td></tr></table>";
	} 
	newsNav += "</div>";
	newsNav += "<div id=\"right\">";
	if (newsID<news[0].childNodes.length-1) {
		nextNewsID = addZero(newsID+1);
		newsNav += "<table><tr><td>"
		newsNav += "<a onfocus=\"this.blur();\" href=\"news.html?id=" + nextNewsID + "\">"
		newsNav += news[0].childNodes[newsID].nextSibling.childNodes[0].firstChild.nodeValue;
		newsNav += "</a></td>";
		newsNav += "<td><img src=\"images/arrow_right.gif\" class=\"east\" /></td></tr></table>";
	}
	newsNav += "</div>";
	newsNav += "</div>";
*/
	var lines = new Array;
	lines[0]=lines[1]=0;

	moreNews="";
	
	for (var column=0; column<2; column++) {
		var margin = (column==0) ? " style=\"margin-right: 30px;\"" : "";
		moreNews += "<div class=\"more\"" + margin + ">";
		for (var n=0; n<news[0].childNodes.length; n++) {
			if (parseInt(getFieldValue("id"))!=n && news[0].childNodes[n].attributes[0].value=="true" && news[0].childNodes[n].attributes[2].value==column) {
				moreNews += "<p><a onfocus=\"this.blur();\" href=\"news.html?id=" + addZero(n) + "\">" + news[0].childNodes[n].childNodes[0].firstChild.nodeValue + "</a></p>";
				lines[column] += Math.round(news[0].childNodes[n].childNodes[0].firstChild.nodeValue.length/45)+1; 
			}
		}
		moreNews += "</div>";
	}
	moreNews = "<div id=\"text\" style=\"min-height: " + Math.max(lines[0],lines[1])*14 + "px;\">" + moreNews + "</div>";
}


var articleHeader="", articleNav="", moreArticles="";

function articleTopic() {
	var id_arr = arguments[0][0].split(",");
	
	for (var n=0; n<id_arr.length; n++) {
		id_arr[n] = parseInt(id_arr[n]);
	}
	
	var allPages = xmlDoc.getElementsByTagName("pages");
	removeAllWhitespaces(allPages);
	
// display first / second / third-level topics : when third-level topic is displayed, second-level topic will be ignored
	articleHeader += "<div id=\"topic\" style=\"background-color: " + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].attributes[2].value + ";\">";
	articleHeader += "<div class=\"h1\">" + allPages[0].childNodes[id_arr[0]].attributes[0].value + "</div>";
	if (id_arr.length>2) {
		articleHeader += "<div class=\"h2\">" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes[id_arr[2]].attributes[0].value + "</div>";
	} else {
		articleHeader += "<div class=\"h2\">" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].attributes[0].value + "</div>";
	}
	articleHeader += "</div>";
/*	
// create previous/next article navigation	
	articleNav = "<div id=\"navigator\">";
	articleNav += "<div id=\"left\">";
	var prevID, nextID;
	
	if (id_arr.length>2 && id_arr[2]>0) {
		prevID = addZero(id_arr[0]) + "," + addZero(id_arr[1]) + "," + addZero(id_arr[2]-1);
		articleNav += "<img src=\"images/arrow_left.gif\" class=\"west\" />";
		articleNav += "<a onfocus=\"this.blur();\" href=\"article.html?id=" + prevID + "&file=" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes[id_arr[2]].previousSibling.attributes[1].value + "\">"
		articleNav += allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes[id_arr[2]].previousSibling.attributes[0].value;
		articleNav += "</a>";
	} else if (id_arr.length<3 && id_arr[1]>0) {
		prevID = addZero(id_arr[0]) + "," + addZero(id_arr[1]-1);
		articleNav += "<img src=\"images/arrow_left.gif\" class=\"west\" />";
		articleNav += "<a onfocus=\"this.blur();\" href=\"article.html?id=" + prevID + "&file=" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].previousSibling.attributes[1].value + "\">"
		articleNav += allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].previousSibling.attributes[0].value;
		articleNav += "</a>";
	}
	articleNav += "</div>";
	articleNav += "<div id=\"right\">";
	if (id_arr.length>2 && id_arr[2]<allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes.length-1) {
		nextID = addZero(id_arr[0]) + "," + addZero(id_arr[1]) + "," + addZero(id_arr[2]+1);
		articleNav += "<img src=\"images/arrow_right.gif\" class=\"east\" />";
		articleNav += "<a onfocus=\"this.blur();\" href=\"article.html?id=" + nextID + "&file=" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes[id_arr[2]].nextSibling.attributes[1].value + "\">"
		articleNav += allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].childNodes[id_arr[2]].nextSibling.attributes[0].value;
		articleNav += "</a>";
	} else if (id_arr.length<3 && id_arr[1]<allPages[0].childNodes[id_arr[0]].childNodes.length-1) {
		nextID = addZero(id_arr[0]) + "," + addZero(id_arr[1]+1)
		articleNav += "<img src=\"images/arrow_right.gif\" class=\"east\" />";
		articleNav += "<a onfocus=\"this.blur();\" href=\"article.html?id=" + nextID + "&file=" + allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].nextSibling.attributes[1].value + "\">"
		articleNav += allPages[0].childNodes[id_arr[0]].childNodes[id_arr[1]].nextSibling.attributes[0].value;
		articleNav += "</a>";
	}
	articleNav += "</div>";
	articleNav += "</div>";
*/
	var lines = new Array;
	lines[0]=lines[1]=0;
	
	for (var column=0; column<2; column++) {
		var margin = (column==0) ? " style=\"margin-right: 30px;\"" : "";
		moreArticles += "<div class=\"more\"" + margin + ">";
		for (i=0; i<allPages[0].childNodes.length; i++) {
			for (j=0; j<allPages[0].childNodes[i].childNodes.length; j++) {
				if (allPages[0].childNodes[i].childNodes[j].attributes[4].value==column && allPages[0].childNodes[i].childNodes[j].attributes[3].value=="true") {
					moreArticles += "<a onfocus=\"this.blur();\" class=\"more2nd\" href=\"article.html?id=" + addZero(i) + "," + addZero(j) + "&file=" + allPages[0].childNodes[i].childNodes[j].attributes[1].value + "\">" + allPages[0].childNodes[i].childNodes[j].attributes[0].value + "</a><br/>";
					for (k=0; k<allPages[0].childNodes[i].childNodes[j].childNodes.length; k++) {
						if ((id_arr.length<3 || k!= id_arr[2]) && (allPages[0].childNodes[i].childNodes[j].childNodes[k].attributes[2].value=="true")) {
							moreArticles += "<a onfocus=\"this.blur();\" class=\"more3rd\" href=\"article.html?id=" + addZero(i) + "," + addZero(j) + "," + addZero(k) + "&file=" + allPages[0].childNodes[i].childNodes[j].childNodes[k].attributes[1].value + "\">" + allPages[0].childNodes[i].childNodes[j].childNodes[k].attributes[0].value + "</a><br/>";
							lines[column]++;
						}
					}
							lines[column]++;
					moreArticles += "<br/>";
				}
			}
		}
		moreArticles += "</div>";
	}
	moreArticles = "<div id=\"text\" style=\"min-height: " + Math.max(lines[0],lines[1])*20 + "px;\">" + moreArticles + "</div>";
}


function articleContent() {
	var content = xmlDoc.getElementsByTagName("content");
	document.write(content[0].firstChild.nodeValue);
}


// display thank you content on contact.html and kc.html
function formReturn() {
	if (getFieldValue('form')=="sent") {
		toggleLayer("mailForm");
		toggleLayer("thankYou");
	}
} 