/* Module contains code to parse list of clubs found in clubs.xml 
 * and display in two columns.
 */

function showList(clubs, iStart, iEnd) {
	document.write("<dl class='clubs'>");
	for (var i = iStart; i < iEnd; i++) {
		document.write("<dt>");
		websites = clubs[i].getElementsByTagName("website");
		if (websites.length > 0) {
			document.write("<a href='");
			document.write(websites[0].childNodes[0].nodeValue);
			document.write("'>");
		}
		document.write(clubs[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
		if (websites.length > 0) {
			document.write("</a>");
		}
		document.write("</dt>");
		document.write("<dd>");
		document.write(clubs[i].getElementsByTagName("address1")[0].childNodes[0].nodeValue);
		document.write("<br/>");
		address2 = clubs[i].getElementsByTagName("address2");
		if (address2.length > 0) {
			document.write(address2[0].childNodes[0].nodeValue);
			document.write("<br/>");
		}
		document.write(clubs[i].getElementsByTagName("city")[0].childNodes[0].nodeValue);
		document.write(", ");
		document.write(clubs[i].getElementsByTagName("state")[0].childNodes[0].nodeValue);
		document.write(" ");
		document.write(clubs[i].getElementsByTagName("zip")[0].childNodes[0].nodeValue);
		document.write("<br/>");
		document.write("<span class='nvname'>Instructor: </span>");
		document.write("<span class='nvvalue'>");
		document.write(clubs[i].getElementsByTagName("instructor")[0].childNodes[0].nodeValue);
		document.write("</span><br/>");
		document.write("<span class='nvname'>Phone: </span>");
		document.write("<span class='nvvalue'>");
		document.write(clubs[i].getElementsByTagName("phone")[0].childNodes[0].nodeValue);
		document.write("</span>");
		email = clubs[i].getElementsByTagName("email");
		if (email.length > 0) {
			document.write("</span><br/>");
			document.write("<span class='nvname'>Email: </span>");
			document.write("<span class='nvvalue'>");
			document.write("<a href='mailto:");
			document.write(email[0].childNodes[0].nodeValue);
			document.write("'>");
			document.write(email[0].childNodes[0].nodeValue);
			document.write("</a></span><br/>");
		}
		document.write("</dd>");
	}
	document.write("</dl>");
}

var xmlhttp;
if (window.XMLHttpRequest) {
	xmlhttp = new XMLHttpRequest();
} else {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "clubs.xml", false);
xmlhttp.send("");
var xmlDoc = xmlhttp.responseXML;

/* if (window.ActiveXObject) {
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	// document.write("<p>ActiveX</p>");
} else if (document.implementation.createDocument) {
	xmlDoc = document.implementation.createDocument("", "", null);
	// document.write("<p>document.implementation</p>");
} else {
	document.write("<p>Club listing unavailable with current security settings. Please download the <a href='clubs.xls'>Excel Club List</a> instead.</p>");
}
xmlDoc.async = "false";
xmlDoc.load("clubs.xml");
*/

var clubs = xmlDoc.getElementsByTagName("club");

// Display in table to make 2 columns.
document.write("<table class='columns'>"); 
document.write("<tr>");

// First column gets first half. If there is an
// odd number, make sure the first column is longer.
document.write("<td>");
var c1stColumn = Math.round(clubs.length/2);
showList(clubs, 0, c1stColumn);
document.write("</td>");

// Second column gets second half.
document.write("<td>");
showList(clubs, c1stColumn, clubs.length);
document.write("</td>");

document.write("</tr>");
document.write("</table>");

