// JavaScript Document for /am/customsource/sbw/leadership_opps.cfm

// 08/20/2007	J.Skemp		Made text changes per B.Drake.
// 09/18/2007	J.Skemp		Changed blockquotes to divs, and added appropriate lines, since the indenting was not liked.

//Function that allows multiple calls to functions upon loading of the web page
function addOnloadEvent(fnc) {
	if ( typeof window.addEventListener != "undefined" )
		window.addEventListener( "load", fnc, false );
	else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", fnc );
	}
	else {
		if ( window.onload != null ) {
			var oldOnload = window.onload;
			window.onload = function ( e ) {
				oldOnload( e );
				window[fnc]();		
			};
		}
		else 
			window.onload = fnc;
	}
}
// Returns the value of a radio input.
function getValueOfRadio() {
	var val = '';
	for (i = 0; i < document.form_leadership_opps.leadership_groupRType.length; i++) {
		if (document.form_leadership_opps.leadership_groupRType[i].checked == true) {
			val = document.form_leadership_opps.leadership_groupRType[i].value;
			break;
		}
	}
	return val;
}

function leadership_content_swap(currentItem,totalItems,baseNameDiv) { // Make sure we have numeric values for those that should be numeric.
	if (isNumeric(currentItem) && isNumeric(totalItems)) { // Make sure we have numeric values for those that should be numeric.
		var divContentDisplay = document.getElementById('leadership_link_content');
		divContentDisplay.setAttribute('style','display:block;');
		divContentDisplay.style.display = 'block';

		var divContentDisplay = document.getElementById('leadership_content');
		divContentDisplay.setAttribute('style','display:none;');
		divContentDisplay.style.display = 'none';

		for (var x = 1; x <= totalItems; x++) {
			tempObject = document.getElementById(baseNameDiv + x);
			tempObject.setAttribute('style','display:none;');
			tempObject.style.display = 'none';
		}
		if (currentItem <= totalItems) {
			tempObject = document.getElementById(baseNameDiv + currentItem);
			tempObject.setAttribute('style','display:block;');
			tempObject.style.display = 'block';
		}
	}
}

function submitTheForm() {
	importDatabaseRecords(document.getElementsByName('leadership_groupRType').value, document.getElementById('GroupName').value);
}
//Function that loads the drop downs with default values of All being assigned and None for the called from parameter
function loadDropDowns() {
	var divContentDisplay = document.getElementById('leadership_link_content');
	divContentDisplay.setAttribute('style','display:block;');
	divContentDisplay.style.display = 'block';
	
	leadership_content_swap(1,3,'leadership_link_');

	var divContentDisplay = document.getElementById('leadership_content');
	divContentDisplay.setAttribute('style','display:none;');
	divContentDisplay.style.display = 'none';

	var subcmtContentDisplay = document.getElementById('leadership_block_static');
	divContentDisplay.setAttribute('style','display:none;');
	divContentDisplay.style.display = 'none';


	var loadingMessage = document.createTextNode("Loading ...");

	document.getElementById('leadership_groupName').innerHTML = '';

	var divTag = document.createElement('div');
	divTag.setAttribute('id','GroupType');
	divTag.id = 'GroupType';  
	divTag.appendChild(loadingMessage);
	document.getElementById('leadership_groupType').appendChild(divTag);

	var divTag = document.createElement('div');
	divTag.setAttribute('id','GroupName');
	divTag.id = 'GroupName';  
	divTag.appendChild(loadingMessage);
	document.getElementById('leadership_groupName').appendChild(divTag);
	
	importDropDowns('All', 'All', 'LoadTheDropDowns');
}

//Calls the onload function to load the drop downs upon loading of the web page
addOnloadEvent(loadDropDowns);

//Function that imports the drop down data from the xml document by receiving the value of the group type drop down, group select drop down and where this function was called from, creating an xml document object, calling the display drop down function and loading the url which creates an xml document for the pertinent information using server side processing.  The server side process page receives the group type value, group select value, the called from value and the particular request (getting the drop downs); so therefore, the server knows what to process
function importDropDowns(GroupTypes, GroupNames, CalledFrom) {
	if (document.implementation && document.implementation.createDocument) {
		xmlDoc1 = document.implementation.createDocument("", "", null);
		xmlDoc1.onload = displayDropDowns;
	}
	else if (window.ActiveXObject) {
		xmlDoc1 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc1.onreadystatechange = function () {
			if (xmlDoc1.readyState == 4) displayDropDowns()
		};
	}
	// Next works, but must be after ActiveXObject check for it to work in IE 7 ...
	else if (window.XMLHttpRequest) {
		xmlDoc1 = new XMLHttpRequest();
		xmlDoc1.onreadystatechange = function() {
			if (xmlDoc1.readyState == 4) displayDropDowns()
		};
	}
	else {
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc1.load("/am/customsource/sbw/leadership_opps_process.cfm?GroupTypes=" + GroupTypes + "&GroupNames=" + GroupNames + "&CalledFrom=" + CalledFrom + "&theRequest=getDropDowns");
	// Enable the Go button.
	goButton = document.getElementById('leadership_opps_go');
	goButton.setAttribute('style','display:none;');
	goButton.style.display = 'none';
	// Hide the error message.
	tempObject = document.getElementById('leadership_opps_error');
	tempObject.setAttribute('style','display:none;');
	tempObject.style.display = 'none';
}

//Function that reads through the xml document tags and pulls the information into drop downs for display on the web page.
function displayDropDowns() {
	// Get the listing of group types (cmt/div/sec)
	/*var x = xmlDoc1.getElementsByTagName('groupTypes');
	if (x[0] && x[0].getAttribute('value') != 0) { // Grab <groupTypes value="*x*">
		var tempHolder = document.createElement('div');
		tempHolder.setAttribute('id','GroupType');
		tempHolder.id = 'GroupType';
		for (j=0;j<x[0].childNodes.length;j++) {
			if (x[0].childNodes[j].nodeType != 1) continue;
			var radioTag = document.createElement('input');
			var isRSelected = x[0].childNodes[j].getAttribute('selected');
			if (isRSelected == 'yes') {
				radioTag.setAttribute('checked','checked');
				radioTag.checked = 'checked';
			}
			//alert('isRSelected? ' + isRSelected); //Testing.
			radioTag.setAttribute('id','type_' + j);
			radioTag.id = 'type_' + j;
			radioTag.setAttribute('name','leadership_groupRType');
			radioTag.name = 'leadership_groupRType';
			radioTag.setAttribute("onclick","importDropDowns(getValueOfRadio(), document.getElementById('GroupName').value, 'TypeDropDown');");  
			var functionName = "dropDownChange1";
			var theFunction = "radioTag.onclick = function " + functionName + j + "() { importDropDowns(getValueOfRadio(), document.getElementById('GroupName').value, 'TypeDropDown'); };";
			radioTag.onchange = eval(theFunction);
			radioTag.setAttribute('type','radio');
			radioTag.type = 'radio';
			radioTag.setAttribute('value',x[0].childNodes[j].getAttribute('value'));
			radioTag.value = x[0].childNodes[j].getAttribute('value');
			//var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
			//radioTag.appendChild(tagValue);
			tempHolder.appendChild(radioTag);
			var labelTag = document.createElement('label');
			labelTag.setAttribute('htmlFor','type_' + j);
			labelTag.htmlFor = 'type_' + j;
			labelTag.innerHTML = x[0].childNodes[j].getAttribute('value');
			tempHolder.appendChild(labelTag);
		}	
		if (document.getElementById('leadership_groupType').hasChildNodes()) {
			document.getElementById('leadership_groupType').removeChild(document.getElementById('GroupType'));
		}
		document.getElementById('leadership_groupType').appendChild(tempHolder);
	}
	
	
	
	*/
	// Get the listing of individual groups that match the group type
	var x = xmlDoc1.getElementsByTagName('groupNames');
	if (x[0] && x[0].getAttribute('value') != '0') {

		// Create the select tag code.
		var selectTag = document.createElement('select');
		selectTag.setAttribute('name','GroupName');
		selectTag.name = 'GroupName';
		selectTag.setAttribute('id','GroupName');
		selectTag.id = 'GroupName';
		selectTag.setAttribute("onChange","importDropDowns(document.getElementsByName('leadership_groupRType').value, document.getElementById('GroupName').value, 'TypeDropDown');submitTheForm();");  
		//this.form.submit() is not working here ...
		var functionName = "dropDownChange2";
		var theFunction = "selectTag.onchange = function " + functionName + "() { importDropDowns(document.getElementsByName('leadership_groupRType').value, document.getElementById('GroupName').value, 'TypeDropDown');submitTheForm(); };";
		//this.form.submit() is not working here ... too.
		selectTag.onchange = eval(theFunction);  
		selectTag.setAttribute('style','width:287px');
		selectTag.style.width = '287px';

		for (j=0;j<x[0].childNodes.length;j++) {
			if (x[0].childNodes[j].nodeType != 1) continue;
			var optionTag = document.createElement('option');
			var isSelected = x[0].childNodes[j].getAttribute('selected');
			if (isSelected == 'yes') {
				optionTag.setAttribute('selected','selected');
				optionTag.selected = 'selected';
			}
			optionTag.setAttribute('value',x[0].childNodes[j].getAttribute('value'));
			optionTag.value = x[0].childNodes[j].getAttribute('value');
			var tagValue = document.createTextNode(x[0].childNodes[j].firstChild.nodeValue);
			optionTag.appendChild(tagValue);
			selectTag.appendChild(optionTag);					
		}	
		if (document.getElementById('leadership_groupName').hasChildNodes()) {
			document.getElementById('leadership_groupName').removeChild(document.getElementById('GroupName'));
			document.getElementById('leadership_groupName').appendChild(selectTag);
		}
		else {
			document.getElementById('leadership_groupName').appendChild(selectTag);
		}
	}
}
// Gets the records for display.
function importDatabaseRecords(GroupTypes, GroupNames) {
	if (document.getElementById("GroupName").value != 'All') {
		document.getElementById("leadership_opps_content").innerHTML = "<div align='center'><h2>Searching....</h2><br><img src='/am/graphics/bigrotation.gif'></div>";
		if (document.implementation && document.implementation.createDocument) {
			xmlDoc3 = document.implementation.createDocument("", "", null);
			xmlDoc3.onload = displayDatabaseRecords;
		}
		else if (window.ActiveXObject) {
			xmlDoc3 = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc3.onreadystatechange = function () {
				if (xmlDoc3.readyState == 4) displayDatabaseRecords()
			};
		}
		else {
			alert('Your browser can\'t handle this script');
			return;
		}
		xmlDoc3.load("/am/customsource/sbw/leadership_opps_process.cfm?GroupTypes=" + GroupTypes + "&GroupNames=" + GroupNames + "&theRequest=getDatabaseRecords");  
	} else {
		document.getElementById("leadership_opps_content").innerHTML = "<div align='center'><p class='error'>Please choose a group.</p></div>";
	}
}

// Actually displays the contents to the page.
function displayDatabaseRecords() {

	var divContentDisplay = document.getElementById('leadership_link_content');
	divContentDisplay.setAttribute('style','display:none;');
	divContentDisplay.style.display = 'none';
	var divContentDisplay = document.getElementById('leadership_content');
	divContentDisplay.setAttribute('style','display:block;');
	divContentDisplay.style.display = 'block';

	var w = xmlDoc3.getElementsByTagName('records');
	var RecordCount = Number(w[0].getAttribute('recordCount'));
	var divTagRecords = document.createElement('div');  
	divTagRecords.setAttribute('id','DatabaseRecords');  
	divTagRecords.id = 'DatabaseRecords';
	divTagRecords.setAttribute('style','margin-left:5px;');
	divTagRecords.style.margin='5px';
	document.getElementById('leadership_opps_subcmt').innerHTML = '';
  
    
	//The script that displays the first line of records  
	var x = xmlDoc3.getElementsByTagName('record');
	if (x.length == 0) {
		var fontTag = document.createElement('font');
		var bTag = document.createElement('b');
		fontTag.setAttribute('style','color:red');  
		fontTag.style.color = 'red';
		var theMessage = document.createTextNode("No results found for your search. Please try again.");
		bTag.appendChild(theMessage);
		fontTag.appendChild(bTag);  
		divTagRecords.appendChild(fontTag);    
	}

	for (i=0;i<x.length;i++) {
		// Find and add the title of the group.
		var tempElement = null;
		if (document.getElementById('leadership_opps_description').hasChildNodes()) {
			document.getElementById('leadership_opps_description').innerHTML = '';
		}
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) continue;
			var theFieldName = x[i].childNodes[j].nodeName;
			if (theFieldName == "groupTitle") {
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				var tempElement = document.createElement('h2');
				tempElement.appendChild(theFieldValue);
				document.getElementById('leadership_opps_description').appendChild(tempElement);
				tempElement = null;
			}
			if (theFieldName == "groupDescription") {
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				var tempElement = document.createElement('p');
				tempElement.appendChild(theFieldValue);
				document.getElementById('leadership_opps_description').appendChild(tempElement);
				document.getElementById('leadership_opps_description').appendChild(document.createElement('br'));
				tempElement = null;
			}
		}
		// Find the position data.
		var tempElement = null;
		if (document.getElementById('leadership_opps_position').hasChildNodes()) {
			document.getElementById('leadership_opps_position').innerHTML = '';
		}
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) continue;
			var theFieldName = x[i].childNodes[j].nodeName;

			if (theFieldName == "positions") {
				var tempElement = document.createElement('h3');
				var theFieldValue = document.createTextNode('Leadership Positions');
				tempElement.appendChild(theFieldValue);
				document.getElementById('leadership_opps_position').appendChild(tempElement);
				tempElement = null;

				for (k=0;k<x[i].childNodes[j].childNodes.length;k++) {
					var tempPositionTitle = "";
					var tempPositionDescription = "";
					var tempPositionTime = "";
					for (m=0;m<x[i].childNodes[j].childNodes[k].childNodes.length;m++) { // Loop through the position element's children.
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "positionTitle") {
							var tempPositionTitle = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
						}
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "positionDescription") {
							var tempPositionDescription = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
						}
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "positionTime") {
							var tempPositionTime = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
						}
					}
					if (tempPositionTitle.length > 0) {
						var theFieldValue = document.createElement('div');
						var tempText1 = document.createElement('h4');
						tempText1.appendChild(document.createTextNode(tempPositionTitle));
						var tempText2 = document.createElement('div'); // changed from blockquote
						if (tempPositionDescription.length > 0 || tempPositionTime.length > 0) {
							if (tempPositionDescription.length > 0) {
								tempText2.appendChild(document.createTextNode(tempPositionDescription))
							}
							if (tempPositionDescription.length > 0 && tempPositionTime.length > 0) {
								tempText2.appendChild(document.createElement('br'));
								tempText2.appendChild(document.createElement('br'));
							}
							if (tempPositionTime.length > 0) {
								tempText2.appendChild(document.createTextNode('Time estimate: '));
								tempText2.appendChild(document.createTextNode(tempPositionTime));
							}
						}
						theFieldValue.appendChild(tempText1); //Position title
						theFieldValue.appendChild(tempText2); //Position details
						document.getElementById('leadership_opps_position').appendChild(theFieldValue);
					}
				}
			}
		}
		// Find the subcommittee data.
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) continue;
			var theFieldName = x[i].childNodes[j].nodeName;
			if (theFieldName == "subcommittees") {

				var subcmtContentDisplay = document.getElementById('leadership_block_static');
				divContentDisplay.setAttribute('style','display:block;');
				divContentDisplay.style.display = 'block';

				var tempElement = document.createElement('h3');
				var theFieldValue = document.createTextNode('Subcommittees');
				tempElement.appendChild(theFieldValue);
				document.getElementById('leadership_opps_subcmt').appendChild(tempElement);
				tempElement = null;
				
				// Create a new table to store subcmt data.
				var tableElementSubcmts = document.createElement('table');
				tableElementSubcmts.setAttribute('style','width:96%;');
				tableElementSubcmts.setAttribute('summary','');
				tableElementSubcmts.setAttribute('cellpadding','6');
				var tbodyElementSubcmts = document.createElement('tbody');
	
				for (k=0;k<x[i].childNodes[j].childNodes.length;k++) {
					var tempPositionTitle = "";
					var tempPositionDescription = "";
					var tempPositionTime = "";
					for (m=0;m<x[i].childNodes[j].childNodes[k].childNodes.length;m++) { // Loop through the subcommittee element's children.
						var tdElementSubcmtsLeft = document.createElement('td');
						var tdElementSubcmtsRight = document.createElement('td');
						tdElementSubcmtsLeft.setAttribute('style','font-style:italic;font-weight:bold;');
						tdElementSubcmtsLeft.style.fontStyle = 'italic'; // IE
						tdElementSubcmtsLeft.style.fontWeight = 'bold'; // IE
						tdElementSubcmtsLeft.setAttribute('valign','top');
						tdElementSubcmtsLeft.vAlign = 'top'; // IE
						tdElementSubcmtsRight.setAttribute('valign','bottom');
						tdElementSubcmtsRight.vAlign = 'bottom'; // IE
	
						//Add the title of the subcmt.
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeTitle") {
							var tempSubcommitteeTitle = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr'); //Row
							var tempElement3 = document.createElement('td'); //Column
							tempElement3.setAttribute('colspan','2');
							var theFieldValue = document.createElement('h4'); //Heading
							theFieldValue.appendChild(document.createTextNode(tempSubcommitteeTitle));
							tempElement3.appendChild(theFieldValue);
							tempElement2.appendChild(tempElement3);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeDescription") {
							var tempSubcommitteeDescription = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Description:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeDescription));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteePositions") {
							//var tempSubcommitteePositions = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Positions:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
	
							for (n=0;n<x[i].childNodes[j].childNodes[k].childNodes[m].childNodes.length;n++) {
								var tempSubcommitteeTitle = "";
								var tempSubcommitteeDescription = "";
								var tempSubcommitteeTimeEstimate = "";
								// TESTING
								//if (x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].nodeType == 1) alert(x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].nodeName);
								for (p=0;p<x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes.length;p++) { // Loop through the position element's children.
									// TESTING
									//if (x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].nodeType == 1) alert(x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].nodeName);
									if (x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].nodeName == "subcommitteeTitle") {
										var tempSubcommitteeTitle = x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].firstChild.nodeValue;
										//alert(tempSubcommitteeTitle);
										
									}
									if (x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].nodeName == "subcommitteeDescription") {
										var tempSubcommitteeDescription = x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].firstChild.nodeValue;
									}
									if (x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].nodeName == "subcommitteeTimeEstimate") {
										var tempSubcommitteeTimeEstimate = x[i].childNodes[j].childNodes[k].childNodes[m].childNodes[n].childNodes[p].firstChild.nodeValue;
									}
								}
								if (tempSubcommitteeTitle.length > 0) {
									var theFieldValueSubcmt = document.createElement('div');
									var tempTextSubcmt1 = document.createElement('strong');
									tempTextSubcmt1.appendChild(document.createTextNode(tempSubcommitteeTitle));
									var tempTextSubcmt2 = document.createElement('div'); // changed from blockquote
									tempTextSubcmt2.appendChild(document.createElement('br')); // Add padding since we removed the blockquote
									if (tempSubcommitteeDescription.length > 0 || tempSubcommitteeTimeEstimate.length > 0) {
	
										if (tempSubcommitteeDescription.length > 0) {
											tempTextSubcmt2.appendChild(document.createTextNode(tempSubcommitteeDescription))
										}
										if (tempSubcommitteeDescription.length > 0 && tempSubcommitteeTimeEstimate.length > 0) {
											tempTextSubcmt2.appendChild(document.createElement('br'));
											tempTextSubcmt2.appendChild(document.createElement('br'));
										}
										if (tempSubcommitteeTimeEstimate.length > 0) {
											tempTextSubcmt2.appendChild(document.createTextNode('Time estimate: '));
											tempTextSubcmt2.appendChild(document.createTextNode(tempSubcommitteeTimeEstimate));
										}
										if (tempSubcommitteeDescription.length > 0 || tempSubcommitteeTimeEstimate.length > 0) {
											tempTextSubcmt2.appendChild(document.createElement('br')); // Add padding since we removed the blockquote
											tempTextSubcmt2.appendChild(document.createElement('br')); // Add padding since we removed the blockquote
										}
									}
									theFieldValueSubcmt.appendChild(tempTextSubcmt1);
									theFieldValueSubcmt.appendChild(tempTextSubcmt2);
									tdElementSubcmtsRight.appendChild(theFieldValueSubcmt);
									tempElement2.appendChild(tdElementSubcmtsRight);
								}
							}
	
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeMeetFrequency") {
							var tempSubcommitteeMeetFrequency = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Meetings Per Year:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeMeetFrequency));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeTeleconference") {
							var tempSubcommitteeTeleconference = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Meet by Phone:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeTeleconference));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeMeetLocation") {
							var tempSubcommitteeMeetLocation = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Meeting Location:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeMeetLocation));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeGroupSize") {
							var tempSubcommitteeGroupSize = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Leadership Group Size:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeGroupSize));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeProcess") {
							var tempSubcommitteeProcess = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Appointment/Election Process:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeProcess));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteePrereq") {
							var tempSubcommitteePrereq = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Prerequisites To Joining:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteePrereq));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
		
						if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeName == "subcommitteeTerms") {
							var tempSubcommitteeTerms = x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue;
							var tempElement2 = document.createElement('tr');
							tdElementSubcmtsLeft.appendChild(document.createTextNode('Term Limits:'));
							tempElement2.appendChild(tdElementSubcmtsLeft); //Left cell
							
							tdElementSubcmtsRight.appendChild(document.createTextNode(tempSubcommitteeTerms));
							tempElement2.appendChild(tdElementSubcmtsRight);
							
							tbodyElementSubcmts.appendChild(tempElement2);
						}
					}
				}
	
				tableElementSubcmts.appendChild(tbodyElementSubcmts);
				document.getElementById('leadership_opps_subcmt').appendChild(tableElementSubcmts);
			}
		}
		// Add content to the table block.
		var tempElement = null;
		if (document.getElementById('leadership_opps_details').hasChildNodes()) {
			document.getElementById('leadership_opps_details').innerHTML = '';
		}
		var tableElementContent = document.createElement('table');
		tableElementContent.setAttribute('style','width:96%;');
		tableElementContent.setAttribute('summary','');
		tableElementContent.setAttribute('cellpadding','6');
		var tbodyElementContent = document.createElement('tbody');

		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) continue;
			var theFieldName = x[i].childNodes[j].nodeName;

			var tdElementLeft = document.createElement('td');
			var tdElementRight = document.createElement('td');
			tdElementLeft.setAttribute('style','font-style:italic;font-weight:bold;');
			tdElementLeft.style.fontStyle = 'italic'; // IE
			tdElementLeft.style.fontWeight = 'bold'; // IE
			tdElementLeft.setAttribute('valign','top');
			tdElementLeft.vAlign = 'top'; // IE
			tdElementRight.setAttribute('valign','bottom');
			tdElementRight.vAlign = 'bottom'; // IE

			if (theFieldName == "groupMeetFrequency") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Meetings Per Year:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupTeleconference") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Meet by Phone:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupMeetLocation") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Meeting Location:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupSize") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Leadership Group Size:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupProcess") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Appointment/Election Process:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupPrereq") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Prerequisites To Joining:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupTerms") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Term Limits:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var theFieldValue = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
				tdElementRight.appendChild(theFieldValue);
				tempElement.appendChild(tdElementRight);

				tbodyElementContent.appendChild(tempElement);
			}

			if (theFieldName == "groupWebPage") {
				var tempElement = document.createElement('tr');
				var theFieldValue = document.createTextNode('Web page:');
				tdElementLeft.appendChild(theFieldValue);
				tempElement.appendChild(tdElementLeft);
				
				var tempLinkURL = "";
				var tempLinkTitle = "";
				for (k=0;k<x[i].childNodes[j].childNodes.length;k++) {
					//if (x[i].childNodes[j].childNodes.nodeType != 1) continue;
					
					if (x[i].childNodes[j].childNodes[k].nodeName == "groupWebURL") {
						var tempLinkURL = x[i].childNodes[j].childNodes[k].firstChild.nodeValue;
					}
					if (x[i].childNodes[j].childNodes[k].nodeName == "groupWebTitle") {
						var tempLinkTitle = x[i].childNodes[j].childNodes[k].firstChild.nodeValue;
					}
				}
				// If you found a URL and a link title, create an element for them.
				if (tempLinkURL.length > 0 && tempLinkTitle.length > 0) {
					var theFieldValue = document.createElement('a');
					theFieldValue.setAttribute('href',tempLinkURL);
					theFieldValue.appendChild(document.createTextNode(tempLinkTitle));
					tdElementRight.appendChild(theFieldValue);
					tempElement.appendChild(tdElementRight);
				}
				tbodyElementContent.appendChild(tempElement);
			}
			tableElementContent.appendChild(tbodyElementContent);
			document.getElementById('leadership_opps_details').appendChild(tableElementContent);



			// Find and add the contact information for the group.
			var tempElement = null;
			if (document.getElementById('leadership_opps_contact').hasChildNodes()) {
				document.getElementById('leadership_opps_contact').innerHTML = '';
			}
			if (theFieldName == "groupContacts") {
				var tempContactTitle = "";
				var tempContactName = "";
				var tempContactCompany = "";
				var tempContactAddress1 = "";
				var tempContactAddress2 = "";
				var tempContactCity = "";
				var tempContactState = "";
				var tempContactZip = "";
				var tempContactCountry = "";
				var tempContactPhone = "";
				var tempContactFax = "";
				var tempContactEmail = "";
				var tempContactsHolder = "";
				for (k=0; k<x[i].childNodes[j].childNodes.length; k++) {
					var theFieldName = x[i].childNodes[j].childNodes[k].nodeName;
					var tempContactTitle = "";
					var tempContactName = "";
					var tempContactCompany = "";
					var tempContactAddress1 = "";
					var tempContactAddress2 = "";
					var tempContactCity = "";
					var tempContactState = "";
					var tempContactZip = "";
					var tempContactCountry = "";
					var tempContactPhone = "";
					var tempContactFax = "";
					var tempContactEmail = "";
					if (theFieldName == "groupContact") {
						var tempContactsHolder = document.createElement('div');
						for (m=0; m<x[i].childNodes[j].childNodes[k].childNodes.length; m++) {
							if (x[i].childNodes[j].childNodes[k].childNodes[m].nodeType != 1) continue;
							var theFieldName2 = x[i].childNodes[j].childNodes[k].childNodes[m].nodeName;
							//alert(theFieldName2);
							// Agri works okay
							var tempElement = document.createElement('p');
							if (theFieldName2 == "groupContactTitle") {
								var tempContactTitle = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactName") {
								var tempContactName = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
								//alert(tempContactName);
							}
							if (theFieldName2 == "groupContactCompany") {
								var tempContactCompany = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactAddress1") {
								var tempContactAddress1 = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactAddress2" && !(!(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue))) {
								var tempContactAddress2 = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactCity") {
								var tempContactCity = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactState") {
								var tempContactState = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactZip") {
								var tempContactZip = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactCountry") {
								var tempContactCountry = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactPhone") {
								var tempContactPhone = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactFax") {
								var tempContactFax = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
							if (theFieldName2 == "groupContactEmail") {
								var tempContactEmail = document.createTextNode(x[i].childNodes[j].childNodes[k].childNodes[m].firstChild.nodeValue);
							}
						}
						if (tempContactTitle != "") {
							boldElement = document.createElement('strong');
							boldElement.appendChild(tempContactTitle);
							tempElement.appendChild(boldElement);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactName != "") {
							tempElement.appendChild(tempContactName);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactCompany != "") {
							tempElement.appendChild(tempContactCompany);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactAddress1 != "") {
							tempElement.appendChild(tempContactAddress1);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactAddress2 != "") {
							tempElement.appendChild(tempContactAddress2);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactCity != "") {
							tempElement.appendChild(tempContactCity);
						}
						if (tempContactCity != "" && tempContactState != "") {
							tempElement.appendChild(document.createTextNode(', '));
						}
						if (tempContactCity != "") {
							tempElement.appendChild(tempContactState);
						}
						if (tempContactZip != "") {
							tempElement.appendChild(document.createTextNode(' '));
							tempElement.appendChild(tempContactZip);
						}
						if (tempContactCity != "" || tempContactState != "" || tempContactZip != "") {
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactCountry != "") {
							tempElement.appendChild(tempContactCountry);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactPhone != "") {
							tempElement.appendChild(document.createTextNode('Phone: '));
							tempElement.appendChild(tempContactPhone);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactFax != "") {
							tempElement.appendChild(document.createTextNode('Fax: '));
							tempElement.appendChild(tempContactFax);
							tempElement.appendChild(document.createElement('br'));
						}
						if (tempContactEmail != "") {
							tempElement.appendChild(tempContactEmail);
							tempElement.appendChild(document.createElement('br'));
						}

						tempContactsHolder.appendChild(tempElement);

						document.getElementById('leadership_opps_contact').appendChild(tempContactsHolder);
					}
				}
			}
		}
	}
/*	for (i=0;i<x.length;i++) {
		// Find and add the contact information for the group.
		var tempElement = null;
		if (document.getElementById('leadership_opps_contact').hasChildNodes()) {
			document.getElementById('leadership_opps_contact').innerHTML = '';
		}
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) continue;
			var theFieldName = x[i].childNodes[j].nodeName;
			if (theFieldName == "groupContacts") {
				for (j=0;j<x[i].childNodes.length;j++) {
					if (x[i].childNodes[j].nodeType != 1) continue;
					if (x[i].childNodes[j].nodeName == "groupContact") {
						for (k=0;k<x[i].childNodes[j].childNodes.length;k++) {
							if (x[i].childNodes[j].childNodes[k].nodeType != 1) continue;
							var theFieldName = x[i].childNodes[j]childNodes[k].nodeName;
						}
					}
				}
			}
		}
	}*/
	if (document.getElementById('leadership_opps_content').hasChildNodes()) {
		document.getElementById('leadership_opps_content').innerHTML = '';	
	}
}
