//Global variable definitions

var map; // Instance of the Google Map that we are working with (needed to
			// resolve scope issues)
var mapSearch;
var myDataTable; // Instance of the Yahoo Data Table that we are working with
					// (needed to resolve scope issues)
var myPaginator; // Instance of the Yahoo Paginator class being used on the
					// Yahoo Data Table (needed to resolve scope issues)

// Global arrays to hold wifi locations
var wifiLocations = new Array();
var mtsLocations = new Array();
var billLocations = new Array();
var dealerLocations = new Array();

// Global arrays to hold rows in the Yahoo tables
var wifiRows = new Array();
var mtsRows = new Array();
var billRows = new Array();
var dealerRows = new Array();

var searchFixes = new Array();

searchFixes[0] = new Array(3);
searchFixes[0][0] = "Portage la Prairie";
searchFixes[0][1] = "49.9712078829541";
searchFixes[0][2] = "-98.28678131103516";

searchFixes[1] = new Array(3);
searchFixes[1][0] = "Thompson";
searchFixes[1][1] = "55.74440992120792";
searchFixes[1][2] = "-97.84930229187012";

searchFixes[2] = new Array(3);
searchFixes[2][0] = "Landmark";
searchFixes[2][1] = "49.66957208236023";
searchFixes[2][2] = "-96.82019233703613";

var urlPrefix = "/storelocator/";

// This function is used to pan the Google map to a specific hotspot and will
// display the popup text for that hotspot
function moveToMarker(lat, lng, name, type, address1, address2, city, phoneNum,
		hours, billsAccepted, servicesList) {
	map.setZoom(13);
	map.panTo(new GLatLng(lat, lng), 100);

	var html = getHtml(name, type, address1, address2, city, phoneNum, hours,
			billsAccepted, servicesList);

	map.openInfoWindowHtml(new GLatLng(lat, lng), html);
	// GEvent.trigger(map.Gmarker[1], "click");
}
function getHtml(name, type, address1, address2, city, phoneNum, hours,
		billsAccepted, servicesList) {
	var html = "<div class='HotSpot_Text'><h2>" + name + "</h2>"

	if (name != type && type != "")
		html += "<strong>Location Type:</strong> " + type + "<br /><br />"

	if (address1 != "")
		html += address1 + "<br />"

	if (address2 != "") {
		html += address2 + "<br />"
	}

	if (city != "")
		html += city + ", MB<br />"

	if (phoneNum != "")
		html += phoneNum + "<br /><br />"

	if (hours != "")
		html += "<div class='listHeading'>Hours:</div> <div class='list'>"
				+ hours + "</div><br />"

	if (servicesList != null && servicesList.length > 0)
		html += "<div class='listHeading'>MTS Services:</div> <div class='list'>"
				+ servicesList + "</div><br />"

	if (billsAccepted != null && billsAccepted.length > 0)
		html += "<strong>Bill Payments Accepted:</strong> " + billsAccepted
				+ "</div>"

	return html
}

// This function will instantiate the Google map, set up the initial settings,
// as well as adding a local search bar and marker manager to the map
function startmap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(54.44449176335762, -98.1298828125), 5);
		map.addControl(new GLargeMapControl());

		// Options to be applied to the local search bar
		var searcherOptions = {
			searchFormHint :"Search the map: postal code, address, city, etc.",
			suppressZoomToBounds :true,
			resultList :G_GOOGLEBAR_RESULT_LIST_SUPPRESS,
			onSearchCompleteCallback :

			function(searcher) {
				if (searcher.results.length != 0) {
					map.setCenter(new GLatLng(
							parseFloat(searcher.results[0].lat),
							parseFloat(searcher.results[0].lng)), 13);

				}
			}
		}

		mapSearch = new google.maps.LocalSearch(searcherOptions)

		map.addControl(mapSearch, new GControlPosition(G_ANCHOR_TOP_LEFT,
				new GSize(80, 10)));

		// GEvent.addListener(map, "zoomend", function(oldLevel,
		// newLevel){scaleIcons(oldLevel, newLevel);});

		return map;

	}
}

// This function will create a WiFi hotspot to be added to the map
function createMarker(lat, lng, name, type, address1, address2, city, phoneNum,
		hours, billsAccepted, servicesList, icon) {
	var marker = new GMarker(new GLatLng(lat, lng), icon);

	// Show this marker's index in the info window when it is clicked
	var html = getHtml(name, type, address1, address2, city, phoneNum, hours,
			billsAccepted, servicesList);

	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;

}
//
//var startWithWifi = false;
var filterEnabled = false; //if true don't show mts, dealer, and bill pegs
var wifiFilterEnabled = false; //if true, don't show wifi pegs
var pm = location.search;
if(pm != null && pm.indexOf("wifi") != -1) {
	//startWithWifi = true;
	wifiFilterEnabled = false;
	filterEnabled = true;
}
else {
	filterEnabled = false;
	wifiFilterEnabled = true;
}
//alert(startWithWifi);
//
// Create the WiFi hotspot icon
var wifiIcon = new GIcon();
wifiIcon.image = urlPrefix + "images/map_icon_wifi.png";
wifiIcon.shadow = urlPrefix + "images/map_icon_shadow.png";
wifiIcon.iconSize = new GSize(20, 32);
wifiIcon.shadowSize = new GSize(24, 19);
wifiIcon.iconAnchor = new GPoint(10, 32);
wifiIcon.infoWindowAnchor = new GPoint(10, 16);
// icon.infoShadowAnchor = new GPoint(12, 19);

// Create the MTS Connect icon
var MTSicon = new GIcon();
MTSicon.image = urlPrefix + "images/map_icon_connect.png";
MTSicon.shadow = urlPrefix + "images/map_icon_shadow.png";
MTSicon.iconSize = new GSize(20, 32);
MTSicon.shadowSize = new GSize(24, 19);
MTSicon.iconAnchor = new GPoint(10, 32);
MTSicon.infoWindowAnchor = new GPoint(10, 16);
// MTSicon.infoShadowAnchor = new GPoint(12, 19);

// Create the Store Location icon
var dealerIcon = new GIcon();
dealerIcon.image = urlPrefix + "images/map_icon_store.png";
dealerIcon.shadow = urlPrefix + "images/map_icon_shadow.png";
dealerIcon.iconSize = new GSize(20, 32);
dealerIcon.shadowSize = new GSize(24, 19);
dealerIcon.iconAnchor = new GPoint(10, 32);
dealerIcon.infoWindowAnchor = new GPoint(10, 16);
// Storeicon.infoShadowAnchor = new GPoint(12, 19);

// Create the Bill Payment icon
var billIcon = new GIcon();
billIcon.image = urlPrefix + "images/map_icon_bill.png";
billIcon.shadow = urlPrefix + "images/map_icon_shadow.png";
billIcon.iconSize = new GSize(20, 32);
billIcon.shadowSize = new GSize(24, 19);
billIcon.iconAnchor = new GPoint(10, 32);
billIcon.infoWindowAnchor = new GPoint(10, 16);
// Billicon.infoShadowAnchor = new GPoint(12, 19);

GSearch.setOnLoadCallback(startmap);

// ********************************************Code to setup the Yahoo
// Table***********************************
YAHOO.util.Event
		.addListener(
				window,
				"load",
				function() {
					YAHOO.example.DynamicData = new function() {
						var data = {
							Name :"Name",
							Address :"Address",
							City :"City",
							Type :"Type",
							Services :"Services",
							NameValue :"NameValue",
							CityValue :"CityValue"
						};

						// Define the columns of the Yahoo Data Table
						var myColumnDefs = [ {
							key :"Name",
							label :"Location",
							sortable :true,
							sortOptions : {
								field :"NameValue"
							}
						}, {
							key :"Address",
							resizeable :true
						}, {
							key :"City",
							label :"City/Town",
							resizeable :true,
							sortable :true,
							sortOptions : {
								field :"CityValue"
							}
						}, {
							key :"Type",
							label :"Location Type",
							resizeable :true,
							sortable :true
						}, {
							key :"Services",
							label :"MTS Services",
							resizeable :true
						}

						];

						this.myDataSource = new YAHOO.util.DataSource( []);
						this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
						this.myDataSource.responseSchema = {
							fields : [ "Name", "Address", "City", "Type",
									"Services", "NameValue", "CityValue" ]
						};

						// This function will load the xml file containing the
						// WiFi hotspots
						function GetXMLdoc(xmlFile) {
							xmlDoc.async = false;
							xmlDoc.load(xmlFile);
						}

						// This function will create an xml document object
						// which will be used to load the external xml file.
						// Different types of xml document objects will be
						// created depending on which browser is being used.

						function loadXML(filename) {
							var xmlDoc;
							if (window.ActiveXObject) {
								// If the ActiveXObject exists then we are using IE.
								xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
							} else if (document.implementation && document.implementation.createDocument) {
								// Mozilla, Firefox, Opera, etc. support document.implmentation.createDocument for loading XML files.
								xmlDoc = document.implementation.createDocument("","",null);
							} else {
								return;
							}
						
							//Internet Explorer
							try {
								// No asynchronous load.
								xmlDoc.async=false;
								xmlDoc.load(filename);
								return xmlDoc;
							} catch(e) {
								//Firefox
								try {
								   /* xmlDoc=document.implementation.createDocument("","",null);
								    xmlDoc.async=false;
								    xmlDoc.load(filename);*/
								    
								    //chrome, safari
								    var xmlhttp = new window.XMLHttpRequest();
								xmlhttp.open("GET", filename, false);
								xmlhttp.send(null);
								xmlDoc = xmlhttp.responseXML.documentElement;
								} catch(e) {alert(e.message)}
							}
						
							try {
								return(xmlDoc);
							} catch(e) {alert(e.message)}
							return(null);
						}


						// Load xml data
						var xmlDoc = loadXML(urlPrefix + "Stores.xml");

						// Instantiate Google map object
						var map = startmap();

						var stores = xmlDoc.getElementsByTagName("mts-store")

						// Create Yahoo Paginator object
						myPaginator = new YAHOO.widget.Paginator( {
							rowsPerPage :15
						});
						var oConfigs = {
							paginator :myPaginator,
							initialRequest :"results=" + stores.length
						};

						// Instantiate Yahoo Data Table
						this.myDataTable = new YAHOO.widget.DataTable("basic",
								myColumnDefs, this.myDataSource, oConfigs);
						myDataTable = this.myDataTable;

						var i = 0
						// Loop through all WiFi Hotspots in the XML document
						for (i = 0; i < stores.length; i++) {
							// temporary array to hold all information within a
							// hotspot node
							var isConnect = false;
							var isBillPayment = false;

							var storePhone, storeName, storeAddress, storeAddress2, storeCity, storeHours, storeLat, storeLon, storeProducts, storeType, storeBill;

							// Get all information within the current wifi
							// hotspot node
							if (stores[i].getElementsByTagName("name")[0] != null) {
								storeName = stores[i]
										.getElementsByTagName("name")[0].firstChild.nodeValue;

								storeName = storeName.replace(/'/, "&rsquo;");

							}

							else
								continue;

							if (stores[i].getElementsByTagName("address1")[0] != null) {
								storeAddress = stores[i]
										.getElementsByTagName("address1")[0].firstChild.nodeValue;

								storeAddress = storeAddress.replace(/'/,
										"&rsquo;");
							}

							else
								continue;

							if (stores[i].getElementsByTagName("address2").length > 0
									&& stores[i]
											.getElementsByTagName("address2")[0] != null) {
								storeAddress2 = stores[i]
										.getElementsByTagName("address2")[0].firstChild.nodeValue;

								storeAddress2 = storeAddress2.replace(/'/,
										"&rsquo;");
							}

							else
								storeAddress2 = ""

							if (stores[i].getElementsByTagName("city-town")[0] != null) {
								storeCity = stores[i]
										.getElementsByTagName("city-town")[0].firstChild.nodeValue;

								storeCity = storeCity.replace(/'/, "&rsquo;");
							}

							else
								continue;

							if (stores[i].getElementsByTagName("phone")[0] != null) {
								storePhone = stores[i]
										.getElementsByTagName("phone")[0].firstChild.nodeValue;
							}

							if (stores[i].getElementsByTagName("hours")[0] != null) {
								storeHours = stores[i]
										.getElementsByTagName("hours")[0].firstChild.nodeValue;

								storeHours = storeHours.replace(/\n/g, " ");
								storeHours = storeHours.replace(/\r/g, " ");
							}

							if (stores[i].getElementsByTagName("latitude")[0] != null) {
								storeLat = stores[i]
										.getElementsByTagName("latitude")[0].firstChild.nodeValue;
							}

							if (stores[i].getElementsByTagName("longitude")[0] != null) {
								storeLon = stores[i]
										.getElementsByTagName("longitude")[0].firstChild.nodeValue;
							}

							var storeType = stores[i]
									.getElementsByTagName("types");

							if (storeType.length == 0
									|| storeType[0]
											.getElementsByTagName("locationType").length == 0)
								continue;
							else {
								storeType = storeType[0]
										.getElementsByTagName("locationType")[0].firstChild.nodeValue;
							}
							var storeServices = stores[i]
									.getElementsByTagName("services");

							if (storeServices.length == 0
									|| storeServices[0]
											.getElementsByTagName("mtsService").length == 0) {
								continue;
							}

							else {
								storeServices = storeServices[0]
										.getElementsByTagName("mtsService")
							}

							var storeBills = stores[i]
									.getElementsByTagName("bills");

							if (storeBills.length == 0
									|| storeBills[0]
											.getElementsByTagName("paymentsAccepted").length == 0)
								continue;
							else {
								storeBills = storeBills[0]
										.getElementsByTagName("paymentsAccepted")[0].firstChild.nodeValue;

							}

							var servicesList = "";

							for ( var j = 0; j < storeServices.length; j++) {

								servicesList += storeServices[j].firstChild.nodeValue
										+ "<br />";

							}

							// use the information gathered above to create the
							// "Locate on Map" link
							// var storeLink = "<a href='#'
							// onclick='moveToMarker(" + storeLat + "," +
							// storeLon + ", &#39;" + storeName + "&#39;, &#39;"
							// + storeTypeString +"&#39;, &#39;" + storeAddress
							// + ", " + storeCity + "&#39;)' >" + storeName +
							// "</a>"

							// Add information into a new row in the Yahoo Data
							// Table

							// Determine which category the current wifi hotspot
							// falls into, create a marker for that hotspot, add
							// it to the marker manager, and add the marker and
							// table row to their respective arrays

							var cityLink = "<a href='#' onclick='mapSearch.execute(&#39;"
									+ storeCity
									+ ", MB&#39;);'>"
									+ storeCity
									+ "</a>"

							for ( var j = 0; j < searchFixes.length; j++) {
								if (storeCity == searchFixes[j][0])
									cityLink = "<a href='#' onclick='moveToMarker("
											+ searchFixes[j][1]
											+ ","
											+ searchFixes[j][2]
											+ ", &#39;"
											+ storeCity
											+ " MB&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39; )' >"
											+ storeCity + "</a>"
							}

							/*
							 * if (storeCity == "Thompson" || storeCity ==
							 * "Portage la Prairie" || storeCity == "Landmark") {
							 * if (storeCity == "Thompson") var cityLink = "<a
							 * href='#' onclick='mapSearch.execute(&#39;Thompson
							 * Dr " + storeCity + ", MB&#39;);'>" + storeCity + "</a>"
							 * 
							 * else if(storeCity == "Portage la Prairie") var
							 * cityLink = "<a href='#'
							 * onclick='mapSearch.execute(&#39;Saskatchewan Ave " +
							 * storeCity + ", MB&#39;);'>" + storeCity + "</a>"
							 * 
							 * else if(storeCity == "Landmark") var cityLink = "<a
							 * href='#' onclick='mapSearch.execute(&#39;first
							 * Ave " + storeCity + ", MB&#39;);'>" + storeCity + "</a>" }
							 */
							if (storeType == "MTS Connect Store") {
								var marker = createMarker(storeLat, storeLon,
										storeName, storeType, storeAddress,
										storeAddress2, storeCity, storePhone,
										storeHours, storeBills, servicesList,
										MTSicon);

								var storeLink = "<a href='#' onclick='moveToMarker("
										+ storeLat
										+ ","
										+ storeLon
										+ ", &#39;"
										+ storeName
										+ "&#39;, &#39;"
										+ storeType
										+ "&#39;, &#39;"
										+ storeAddress
										+ "&#39;, &#39;"
										+ storeAddress2
										+ "&#39;, &#39;"
										+ storeCity
										+ "&#39;, &#39;"
										+ storePhone
										+ "&#39;, &#39;"
										+ storeHours
										+ "&#39;, &#39;"
										+ storeBills
										+ "&#39;, &#39;"
										+ servicesList
										+ "&#39; )' >"
										+ storeName + "</a>"

								var tableRow = {
									Name :storeLink,
									Address :storeAddress,
									City :cityLink,
									Type :storeType,
									Services :servicesList,
									NameValue :storeName,
									CityValue :storeCity
								}

								mtsLocations.push(marker);
								mtsRows.push(tableRow);

								map.addOverlay(marker);
								//if(startWithWifi)
								if(filterEnabled)	
									marker.hide();
							}

							else if (storeType == "Bill Payments") {
								var marker = createMarker(storeLat, storeLon,
										storeName, storeType, storeAddress,
										storeAddress2, storeCity, storePhone,
										storeHours, storeBills, servicesList,
										billIcon);
								var storeLink = "<a href='#' onclick='moveToMarker("
										+ storeLat
										+ ","
										+ storeLon
										+ ", &#39;"
										+ storeName
										+ "&#39;, &#39;"
										+ storeType
										+ "&#39;, &#39;"
										+ storeAddress
										+ "&#39;, &#39;"
										+ storeAddress2
										+ "&#39;, &#39;"
										+ storeCity
										+ "&#39;, &#39;"
										+ storePhone
										+ "&#39;, &#39;"
										+ storeHours
										+ "&#39;, &#39;"
										+ storeBills
										+ "&#39;, &#39;"
										+ servicesList
										+ "&#39; )' >"
										+ storeName + "</a>"

								var tableRow = {
									Name :storeLink,
									Address :storeAddress,
									City :cityLink,
									Type :storeType,
									Services :servicesList,
									NameValue :storeName,
									CityValue :storeCity
								}

								billLocations.push(marker);
								billRows.push(tableRow);

								map.addOverlay(marker);
								//if(startWithWifi)
								if(filterEnabled)
								 	marker.hide();
							}

							else if (storeType == "MTS Dealer") {
								var marker = createMarker(storeLat, storeLon,
										storeName, storeType, storeAddress,
										storeAddress2, storeCity, storePhone,
										storeHours, storeBills, servicesList,
										dealerIcon);
								var storeLink = "<a href='#' onclick='moveToMarker("
										+ storeLat
										+ ","
										+ storeLon
										+ ", &#39;"
										+ storeName
										+ "&#39;, &#39;"
										+ storeType
										+ "&#39;, &#39;"
										+ storeAddress
										+ "&#39;, &#39;"
										+ storeAddress2
										+ "&#39;, &#39;"
										+ storeCity
										+ "&#39;, &#39;"
										+ storePhone
										+ "&#39;, &#39;"
										+ storeHours
										+ "&#39;, &#39;"
										+ storeBills
										+ "&#39;, &#39;"
										+ servicesList
										+ "&#39; )' >"
										+ storeName + "</a>"

								var tableRow = {
									Name :storeLink,
									Address :storeAddress,
									City :cityLink,
									Type :storeType,
									Services :servicesList,
									NameValue :storeName,
									CityValue :storeCity
								}

								dealerLocations.push(marker);
								dealerRows.push(tableRow);

								map.addOverlay(marker);
								//if(startWithWifi)
								if(filterEnabled)
									marker.hide();
							}

							else if (storeType == "Wi-Fi Hotspot") {
								var marker = createMarker(storeLat, storeLon,
										storeName, storeType, storeAddress,
										storeAddress2, storeCity, "", "", "",
										"", wifiIcon);
								var storeLink = "<a href='#' onclick='moveToMarker("
										+ storeLat
										+ ","
										+ storeLon
										+ ", &#39;"
										+ storeName
										+ "&#39;, &#39;"
										+ storeType
										+ "&#39;, &#39;"
										+ storeAddress
										+ "&#39;, &#39;"
										+ storeAddress2
										+ "&#39;, &#39;"
										+ storeCity
										+ "&#39;, &#39;&#39;, &#39;&#39;)' >"
										+ storeName + "</a>"

								var tableRow = {
									Name :storeLink,
									Address :storeAddress,
									City :cityLink,
									Type :storeType,
									Services :servicesList,
									NameValue :storeName,
									CityValue :storeCity
								}

								wifiLocations.push(marker);
								wifiRows.push(tableRow);

								map.addOverlay(marker);
								if(wifiFilterEnabled)
									marker.hide();
							}

						}
					}

					mtsRows.sort();
					billRows.sort();
					dealerRows.sort();
					wifiRows.sort();

					reloadTable()

				})

// This function will check to see which hotspot categories the user wishes to
// see, and will empty and reload the data table with only the selected hotspot
// categories. This function is called from within the toggleLocations function
// below.

function reloadTable() {
	// Reset paginator to page 1 and delete every row in the data table
	myPaginator.setPage(1, false);
	myDataTable.deleteRows(0, myDataTable.getRecordSet().getLength())

	// If the user selected the MTS hotspots, load all MTS table rows into the
	// table
	if (document.toggleSelection.mts.checked) {
		var tempArr = new Array();
		for(x in mtsRows)
		{
			if(displayService(mtsRows[x].Services))
				tempArr.push(mtsRows[x]);
		}
		myDataTable.addRows(tempArr);
	}

	// If the user selected the Fatport hotspots, load all Fatport table rows
	// into the table
	if (document.toggleSelection.dealer.checked) {
		var tempArr = new Array();
		for(x in dealerRows)
		{
			if(displayService(dealerRows[x].Services))
				tempArr.push(dealerRows[x]);
		}
		myDataTable.addRows(tempArr);
	}

	// If the user selected the Library hotspots, load all Library table rows
	// into the table
	if (document.toggleSelection.bills.checked) {
		myDataTable.addRows(billRows);
	}

	// If the user selected the Salisbury House hotspots, load all Salisbury
	// House table rows into the table
	if (document.toggleSelection.wifi.checked) {
		myDataTable.addRows(wifiRows);
	}

}

//Check the service name against the name of the checkbox on the page. return true if the checkbox for a service in the list is checked.
function displayService(serviceList)
{
	if(serviceList)
		{
		var services = serviceList.split("<br />");
		for(service in services)
		{

			if(services[service] != "")
			{
				if(document.getElementsByName(services[service]).length > 0)
				{

					if(document.getElementsByName(services[service])[0].checked)
					{
						return true;
					}
				}
			}
		}
	}
	return false;
}

// This function will display or hide markers on the Google Map based on which
// category the markers are in. This function is called whenever a checkbox from
// the web form is clicked on. This function accepts an instance of the checkbox
// that was just clicked as a parameter.



function toggleLocations(category) {

	// If the MTS Connect checkbox was clicked
	if (category.value == "mts") {
		// Loop through all MTS Connect map markers
		for ( var i = 0; i < mtsLocations.length; i++) {
			var marker = mtsLocations[i];
			var serviceList = mtsRows[i].Services;
			// If the current MTS Connect marker is hidden, show this marker
			if (displayService(serviceList) && category.checked==true) {
				marker.show();
			}

			// Else, if the marker is already being shown, hide it.
			else {
				marker.hide();
			}
		}

	}

	// If the MTS Dealer checkbox was clicked...
	if (category.value == "dealer") {
		// Loop through all MTS Dealer locations on the map
		for ( var i = 0; i < dealerLocations.length; i++) {
			var marker = dealerLocations[i];
			var serviceList = dealerRows[i].Services;
			// If the current MTS Dealer marker is currently hidden, show it
			if (displayService(serviceList) && category.checked==true) {
				marker.show();
			}

			// If the marker is currently being shown, hide it
			else {
				marker.hide();
			}
		}

	}

	// If the bill payment checkbox was clicked on...
	if (category.value == "bills") {
		// Loop through the bill payment locations on the map
		for ( var i = 0; i < billLocations.length; i++) {
			var marker = billLocations[i];

			// If the current bill payment marker is being hidden, show it
			if (marker.isHidden()) {
				marker.show();
			}

			// If the marker is currently being shown, hide it
			else {
				marker.hide();
			}
		}

	}

	// If the wifi checkbox was clicked...
	if (category.value == "wifi") {
		// Loop through all wifi locations on the map
		for ( var i = 0; i < wifiLocations.length; i++) {
			var marker = wifiLocations[i];
			var serviceList = wifiRows[i].Services;
			
			if (displayService(serviceList) && category.checked==true) {
				marker.show();
			}

			// If the marker is currently being shown, hide it
			else {
				marker.hide();
			}
/*			// If the current wifi marker is being hidden, show it
			if (marker.isHidden()) {
				marker.show();
			}

			// If the current marker is being shown, hide it
			else {
				marker.hide();
			}*/
		}

	}

	// Call the reloadTable() method so that the changes on the map reflect the
	// content in the Data Table
	reloadTable();
}
