	var UserMarker=null;

	function LoadAllMarkers() {
		LoadPoints("1");
		return false;
	}

	var waitHtml = "";
	waitHtml += "<html>";
	waitHtml += "<head>";
	waitHtml += "<style>";
	waitHtml += ".blackheader {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;font-style: normal;font-weight: bolder;color: #000000;text-decoration: none;}";
	waitHtml += "</style>";
	waitHtml += "</head>";
	waitHtml += "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";			
	waitHtml += "<tr>";
	waitHtml += "   <td class=\"bodybtext\" align=\"center\">";
	waitHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";
	waitHtml += "   Building location markers, please wait...";
	waitHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";
	waitHtml += "</td>";
	waitHtml += "</tr>";
	waitHtml += "</table>";
	waitHtml += "</html>";	

	function GetLocationFullTitle()
	{
		var output = "";
		if (this.Number)
			output += "#" + this.Number + " - ";
		if (this.City)
			output += this.City + ", ";
		if (this.State)
			output += this.State;
		if (this.SType)
			output += "<BR>" + this.SType;
		return output;
	}

	function GetLocationAddress()
	{
		var output = "";
		if (this.Addr1)
			output += this.Addr1;
		if (this.Addr2)
			output += "<BR>" + this.Addr2;
		if (this.City)
			output += "<BR>" + this.City + ", ";
		if (this.State)
			output += this.State + " ";
		if (this.Zip)
			output += this.Zip;
		return output;
	}

	function GetLocationOneLineAddress()
	{
		var output = "";
		if (this.Addr1)
			output += this.Addr1;
//		if (this.Addr2)
//			output += " " + this.Addr2;
		if (this.City)
			output += " " + this.City + ", ";
		if (this.State)
			output += this.State + " ";
		if (this.Zip)
			output += this.Zip;
		return output;
	}

	function GetLocationExtraInfo()
	{
		var output = "";
		if (this.Phone)
			output += this.Phone;
		if (this.Fax)
			output += "<BR>" + this.Fax + " fax";
		if (this.GM)
			output += "<BR>" + this.GM + ", manager ";
		if (this.HrsMonFri)
			output += "<P>M-F: " + this.HrsMonFri;
		if (this.HrsSat)
			output += "<BR>Sat: " + this.HrsSat;
		if (this.HrsSun)
			output += "<BR>Sun: " + this.HrsSun;			
		return output;
	}

	function Location(storeObj)
	{
		var tag;
		var node;

		tag = storeObj.getElementsByTagName("Longitude");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Longitude = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Latitude");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Latitude = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Id");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Id = node.firstChild.data;
		}				
		
		tag = storeObj.getElementsByTagName("Number");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Number = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Name");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Name = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("SType");
		if (tag.length > 0)
		{
			node = tag[0];
			this.SType = node.firstChild.data;
		}		
		tag = storeObj.getElementsByTagName("Addr1");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Addr1 = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Addr2");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Addr2 = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("City");
		if (tag.length > 0)
		{
			node = tag[0];
			this.City = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("State");
		if (tag.length > 0)
		{
			node = tag[0];
			this.State = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Zip");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Zip = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Phone");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Phone = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("Fax");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Fax = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("GM");
		if (tag.length > 0)
		{
			node = tag[0];
			this.GM = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("HrsMonFri");
		if (tag.length > 0)
		{
			node = tag[0];
			this.HrsMonFri = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("HrsSat");
		if (tag.length > 0)
		{
			node = tag[0];
			this.HrsSat = node.firstChild.data;
		}
		tag = storeObj.getElementsByTagName("HrsSun");
		if (tag.length > 0)
		{
			node = tag[0];
			this.HrsSun = node.firstChild.data;
		}
		
		this.FullTitle = GetLocationFullTitle;
		this.Address = GetLocationAddress;
		this.OneLineAddress = GetLocationOneLineAddress;
		this.ExtraInfo = GetLocationExtraInfo;
	}

	function Result(resultObj)
	{
		this.precision = resultObj.getAttribute("precision");
		var tag = resultObj.getElementsByTagName("Latitude");
		if (tag.length > 0)
		{
			var node = tag[0];
			this.Latitude = node.firstChild.data;
		}
		tag = resultObj.getElementsByTagName("Longitude");
		if (tag.length > 0)
		{
			node = tag[0];
			this.Longitude = node.firstChild.data;
		}
	}
    
    function GetImageByType(type)
    {
		var imgUrl;
		switch(type)
		{
			// yikes
			case "1":
				imgUrl = imgRSC.src; //"markerRSC.png";
				break;
			case "3":
				imgUrl = imgPE.src; //"markerPE.png";
				break;
			case "U":
				imgUrl = imgYOU.src; //"markerYOU.png";
				break;
			default:
				imgUrl = imgRSC.src; //"markerRSC.png";
				break;
		}
		return imgUrl;  
    } 
    
	function centerPoint(lng, lat) {
		//map.centerAndZoom(new GPoint(lng, lat), 6);
		map.setCenter(new GLatLng(lat, lng), 6);
	}

	function centerPointWithZoom(lng, lat, zoom) {
		map.setCenter(new GLatLng(lat, lng), parseInt(zoom));
	}
	
	function LoadPoints(type)
	{
		var strImgKey = GetImageByType(type);
		var ndx = 0;		
		try 
		{					
			for (i = 0; i < arL.length; i++) 
			{			
				var so = arL[i].split('|');
				if (so[3] == type)
				{
					var point = new GLatLng(parseFloat(so[1]), parseFloat(so[0]));
					var marker = createMarker(point, i + 1, type);
					map.addOverlay(marker);
				}
			}					
		}
		catch(ex) {alert(ex.description);}			
	}	
	
	function ShowSingleLocation(type, id)
	{
		try 
		{					
			for (i = 0; i < arL.length; i++) 
			{			
				var so = arL[i].split('|');
				if (so[2] == id)
				{
					var point = new GLatLng(parseFloat(so[1]), parseFloat(so[0]));
					var marker = createMarker(point, i + 1, type);
					map.addOverlay(marker);									
				}
			}			
		}
		catch(ex) {}		
	}    
	
	function ShowLocations(divName, val, refresh)
	{
		var thisDiv = document.getElementById(divName);
		if (refresh)
		{
			GetStateList(val, thisDiv);
		}
		thisDiv.style.visibility = "visible";
	}
	function HideLocations(divName)
	{
		var thisDiv = document.getElementById(divName);
		thisDiv.style.visibility = "hidden";
	}
	function ShowHideMessage(valVisible)
	{		
		var thisDiv = document.getElementById("WaitMessage");
		if (valVisible == true)
		{
			thisDiv.innerHTML = waitHtml;
			thisDiv.style.visibility = "visible";
		}
		else
		{
			thisDiv.style.visibility = "hidden";
		}
		
	}
	
	// Create a marker whose info window displays the given number.
	function createMarker(point, number, type) {
		var icon = new GIcon(baseIcon);
		var imgUrl = GetImageByType(type);
		icon.image = imgUrl;
		var marker = new GMarker(point, icon);
		// create popup only for non-user defined markers
		if (number > -1)
		{		
			try 
			{						
				var so = arL[number-1].split('|');
				GEvent.addListener(marker, 'click', function() {
					GetLocationInfo(marker, point, so[2]);
				});
			}
			catch(ex) {}		
		}
		return marker;
	}

	function GetLocationInfo(marker, point, LocId)
	{
		// use generic factory method provided by google api
		var url = mpBase + "LocId=" + LocId;
		var request = GXmlHttp.create();
		request.open('GET', url, true);
		request.onreadystatechange = function() 
		{
			if (request.readyState == 4) 
			{			
				var xml = request.responseXML.documentElement;
				var locations = xml.getElementsByTagName("location");
				var numLocations = locations.length;
				if (numLocations == 1)
				{
					var thisLocation = new Location(locations[0]);
					var theHtml = "";
					theHtml += "<html>";
					theHtml += "<head>";
					theHtml += "<style>";
					theHtml += ".infotext A {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;font-style: normal;font-weight: normal;color: #CC0000;text-decoration: none;}";
					theHtml += ".infotext A:hover {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;font-style: normal;font-weight: normal;color: #000000;text-decoration: underline;}";
					theHtml += ".infotext {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;font-style: normal;font-weight: normal;color: #666666;text-decoration: none;}";
					theHtml += ".blackheader {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;font-style: normal;font-weight: bolder;color: #000000;text-decoration: none;}";
					theHtml += "</style>";
					theHtml += "</head>";
					theHtml += "<table>";
					theHtml += " <tr>";
					theHtml += "   <td class=\"bodytext\">";
					theHtml += "		<NOBR><span class=\"blackheader\">" + thisLocation.FullTitle() + "</span></NOBR>";
					theHtml += "		<hr noshade>";
					theHtml += "		<NOBR>" + thisLocation.Address() + "</NOBR>";
					theHtml += "		<br>";
					theHtml += "		<NOBR>" + thisLocation.ExtraInfo() + "</NOBR>";
					theHtml += "		<hr noshade>";
					theHtml += "		<NOBR><a target=\"top\" href=\"store.aspx?storeID=" + LocId + "\">Go to Store Page</a>&nbsp;|&nbsp;<a href=\"javascript:centerPointWithZoom(" + point.x + "," + point.y + ",15)\">Zoom into Map</a></NOBR>";
					theHtml += "		<hr noshade>";
					theHtml += "		<form target=\"_blank\" action=\"http://maps.google.com/maps\" method=\"get\">";
					theHtml += "		Get Directions to this Location<P><NOBR>From:&nbsp;";
					theHtml += "		<input size=\"30\" class=\"bodytext\" type=\"text\" name=\"saddr\" id=\"saddr\" value=\"\" />";
					theHtml += "		<input class=\"bodytext\" type=\"submit\" value=\"Go\" />";
					theHtml += "		<input type=\"hidden\" name=\"daddr\" value=\"" + thisLocation.OneLineAddress() + "\" />";
					theHtml += "		<input type=\"hidden\" name=\"hl\" value=\"en\" /></NOBR>";
					theHtml += "		</form>";
					theHtml += "</td>";
					theHtml += " </tr>";
					theHtml +="</table>";
					theHtml += "</html>";
					marker.openInfoWindowHtml(theHtml);    
				}
				else 
				{
					//alert("There was a problem retrieving the location information");
					var theHtml = "";
					var thisDiv = document.getElementById("StoreListing");
					theHtml += "<html>";
					theHtml += "<head>";
					theHtml += "<style>";
					theHtml += ".blackheader {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;font-style: normal;font-weight: bolder;color: #000000;text-decoration: none;}";
					theHtml += "</style>";
					theHtml += "</head>";
					theHtml += "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
					theHtml += "<tr>";
					theHtml += "   <td class=\"bodybtext\" align=\"center\">";			
					theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
					theHtml += "   <span class=\"bodybtext\">There was a problem retrieving the store location information.<BR>Please try again.</span><p><a href=\"javascript:HideLocations('StoreListing')\">Close this Window</a>";
					theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
					theHtml += "</td>";
					theHtml += "</tr>";
					theHtml += "</table>";
					theHtml += "</html>";
					thisDiv.innerHTML = theHtml;
					thisDiv.style.visibility = "visible";						
				}				
			}
		}
		request.send(null);	
	}		
	
	function GetGeocode(loc)
	{
		if (loc != "")
		{
			var request;
			// use generic factory method provided by google api;
			var url = mpBase + "Loc=" + loc;
			var request = GXmlHttp.create();			
			request.open('GET', url, true);
			request.onreadystatechange = function() 
			{
				if (request.readyState == 4) 
				{

					var xml = request.responseXML.documentElement;
					var gcode = xml.getElementsByTagName("Result");
					var numResults = gcode.length;
					if (numResults < 1)
					{
						var theHtml = "";
						var thisDiv = document.getElementById("StoreListing");
						theHtml += "<html>";
						theHtml += "<head>";
						theHtml += "<style>";
						theHtml += ".blackheader {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;font-style: normal;font-weight: bolder;color: #000000;text-decoration: none;}";
						theHtml += "</style>";
						theHtml += "</head>";
						theHtml += "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
						theHtml += "<tr>";
						theHtml += "   <td class=\"bodytext\" align=\"center\">";			
						theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
						theHtml += "   <span class=\"bodybtext\">There was an error translating your given address.<BR>Please correct the address and try again.</span><p><a href=\"javascript:HideLocations('StoreListing');parent.document.getElementById('txtLoc').select();\">Close this Window</a>";
						theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
						theHtml += "</td>";
						theHtml += "</tr>";
						theHtml += "</table>";
						theHtml += "</html>";
						thisDiv.innerHTML = theHtml;
						thisDiv.style.visibility = "visible";
					}
					else
					{
						// map first result only
						var zoom = 13;
						var thisResult = new Result(gcode[0]);
						//var point = new GPoint(thisResult.Longitude, thisResult.Latitude);
						var point = new GLatLng(thisResult.Latitude, thisResult.Longitude);
						
						//var marker = new GMarker(point);						
						//map.addOverlay(marker);						
						//var marker = createMarker(point, -1, "U");
						//map.addOverlay(marker);				
						
						try 
						{
							if (UserMarker) {map.removeOverlay(UserMarker);}
						}							
						catch (ex){}
						UserMarker = createMarker(point, -1, "U");
						map.addOverlay(UserMarker);						
						
						// determine zoom by precision
						switch (thisResult.precision)
						{
							case "address":
								zoom = 16;
								break;
							case "street":
								zoom = 15;
								break;
							case "zip+4":
								zoom = 12;
								break;
							case "zip+2":
								zoom = 12;
								break;
							case "zip":
								zoom = 12;
								break;
							case "city":
								zoom = 10;
								break;
							case "state":
								zoom = 6;
								break;
							case "country": 						
								zoom = 4;
								break;
							default:
								zoom = 4;
								break;	
						}						
						centerPointWithZoom(thisResult.Longitude, thisResult.Latitude, zoom);
					}	
				}
			}
			request.send(null);	
		}
	}
	function GetStateList(StateId, thisDiv)
	{
		// use generic factory method provided by google api
		var url = mpBase + "St=" + StateId;
		var request = GXmlHttp.create();
		request.open('GET', url, true);
		request.onreadystatechange = function() 
		{
			if (request.readyState == 4) 
			{			
				var theHtml = "";
				var tag;
				var node;
				var LocName = "error";
				var LocId = "0";
				var colSize = 30;

				var xml = request.responseXML.documentElement;
				var locations = xml.getElementsByTagName("location");
				var numLocations = locations.length;
				var tstyle = "redloc";				
				
				theHtml += "<html>";
				theHtml += "<head>";
				theHtml += "<style>";
				theHtml += ".blackheader {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 11px;font-style: normal;font-weight: bolder;color: #000000;text-decoration: none;}";
				theHtml += ".redloc {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;font-style: normal;font-weight: bolder;color: #CC0000;text-decoration: none;}";
				theHtml += ".greenloc {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;font-style: normal;font-weight: bolder;color: #009900;text-decoration: none;}";
				theHtml += "</style>";
				theHtml += "</head>";
				theHtml += "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">";
				if (numLocations > 0)
				{
					for (j = 0; j < numLocations; j++)
					{											
						var thisLocation = new Location(locations[j]);
						// header row
						if (j == 0)
						{
							theHtml += " <tr><td class=\"bodytext\" valign=\"top\" colspan=\"" + ((numLocations % colSize) + 1) + "\"><span class=\"blackheader\">" + thisLocation.State + "</span>&nbsp;|&nbsp;<a href=\"javascript:HideLocations('StoreListing')\">Close this Window</a></td></tr>";
							theHtml += " <tr>";
							theHtml += "<td class=\"bodytext\" valign=\"top\">";
							theHtml += "<table cellpadding=\"3\" cellspacing=\"0\">";													
						}
						// new columns as needed
						if ((j % colSize == 0) && (j > 0))
						{
							theHtml += "</table>";
							theHtml += "</td>";
							theHtml += "<td class=\"bodytext\" valign=\"top\">&nbsp;</td>";
							theHtml += "<td class=\"bodytext\" valign=\"top\">";
							theHtml += "<table cellpadding=\"3\" cellspacing=\"0\">";
						}
						theHtml += "<tr>";
						tstyle = "redloc";
						if (thisLocation.SType != "1") 
						{
							tstyle = "greenloc";
						}
						// weak
						var s1 = thisLocation.Name.substring(0, thisLocation.Name.indexOf('-'));
						var s2 = thisLocation.Name.substring(thisLocation.Name.indexOf(' - ')+2);
						theHtml += "<td>";												
						//theHtml += "<NOBR><span class=\"" + tstyle + "\">" + s1 + "</span><span class=\"bodybtext\">" + s2 + "</span></NOBR>";
						theHtml += "<NOBR><span class=\"bodybtext\">" + s2 + "</span></NOBR>";
						theHtml += "</td>";
						theHtml += "<td class=\"bodytext\">";
						theHtml += "<NOBR><a target=\"top\" href=\"store.aspx?storeID=" + thisLocation.Id + "\">Store Page</a>&nbsp;|&nbsp;<a href=\"javascript:ShowSingleLocation('" + thisLocation.SType + "'," + thisLocation.Id + ");centerPointWithZoom(" + thisLocation.Longitude + "," + thisLocation.Latitude + ",15" + ");HideLocations('StoreListing');\">Map</a></NOBR>";
						theHtml += "</td>";
						theHtml += " </tr>";
						
					}
					theHtml += "</table>";
					theHtml += "</td>";
					theHtml += " </tr>";					
				}
				else 
				{
					theHtml += "<tr>";
					theHtml += "   <td class=\"bodytext\" align=\"center\">";			
					theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
					theHtml += "   Error retrieving store locations&nbsp;|&nbsp;<a href=\"javascript:HideLocations('StoreListing')\">Close this Window</a>";
					theHtml += "<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;";	
					theHtml += "</td>";
					theHtml += "</tr>";
				}
				theHtml += "</table>";
				theHtml += "</html>";
				thisDiv.innerHTML = theHtml;			
			}
		}
		request.send(null);	
	}		