var totalItems = 0;
// The following are specified on the calling page
//var contact_us_details_URL = "members/xml/member_details.xml";
var table_header ="<table width='350px'><tbody>";
var table_footer ="<\/tbody><\/table>";
var chairman_details = "";
var secretary_details = "";

 $(document).ready(function(){
	$.ajax({
		type: "GET",
		url: contact_us_details_URL ,
		dataType: "xml",
      error: function(XMLHttpRequest, textStatus, errorThrown) {
		  alert(XMLHttpRequest);
		  alert(textStatus);
		  alert(errorThrown);
		} , 
		success: function(xml) {
			var title = $(xml).find('title').text();
			var last_updated = $(xml).find('last_updated').text();
			var textcontainer = $('#section_3');
			totalItems = $(xml).find('member_type').length;
			var strText = table_header;
			$(xml).find('member_type').each(function(){
				var member_type = $(this).attr('member_type');
				if (member_type == "full") {
					var full_member_data = this;
					$(full_member_data).find('member').each(function(){
						var office_1 = $(this).find('office_1').text();
						var office_2 = $(this).find('office_2').text();
						if (office_1 == "Chairman" || office_2 == "Chairman"){
							var first_name = $(this).find('first_name').text();
							var first_name_array=first_name.split(" ");
							first_name = first_name_array[0];
							var last_name = $(this).find('last_name').text();
							var phone = $(this).find('phone').text();
							var mobile = $(this).find('mobile').text();
							chairman_details = "<tr><td class='bold_text'>Chairman</td><td>" + first_name + " " + last_name + "<\/td><td class='blue_bold'>" + phone + "<\/td><\/tr>";
						} 
						if (office_1 == "Secretary" || office_2 == "Secretary"){
							var first_name = $(this).find('first_name').text();
							var first_name_array=first_name.split(" ");
							first_name = first_name_array[0];
							var last_name = $(this).find('last_name').text();
							var phone = $(this).find('phone').text();
							var mobile = $(this).find('mobile').text();
							secretary_details = "<tr><td class='bold_text'>Secretary</td><td>" + first_name + " " + last_name + "<\/td><td class='blue_bold'>" + phone + "<\/td><\/tr>";
						
						}
					});
				}
			});
			strText += table_header + chairman_details + secretary_details + table_footer; 
			if (last_updated.length) {
				strText += "<p style='text-align:center;font-style:italic;font-weight: 600;'\>Contact information last updated: " + last_updated + "<\/p\><hr \/\><p \/\>";
			}
			textcontainer.append(strText);
		}
	});
});