var G_GEO_UNKNOWN_ADDRESS = 602;

var arryStores = new Array(2000);
var arryStates = new Array(new Array("AL", "ALABAMA",7),
									new Array("AK", "ALASKA", 5),
									new Array("AZ", "ARIZONA", 6),
									new Array("AR", "ARKANSAS", 7),
									new Array("CA", "CALIFORNIA", 6),
									new Array("CO", "COLORADO", 7),
									new Array("CT", "CONNECTICUT", 9),
									new Array("DE", "DELAWARE", 8),
									new Array("DC", "DISTRICT OF COLUMBIA", 10),
									new Array("FL", "FLORIDA", 7),
									new Array("GA", "GEORGIA", 7),
									new Array("HI", "HAWAII", 7),
									new Array("ID", "IDAHO", 7),
									new Array("IL", "ILLINOIS", 7),
									new Array("IN", "INDIANA", 7),
									new Array("IA", "IOWA", 7),
									new Array("KS", "KANSAS", 7),
									new Array("KY", "KENTUCKY", 7),
									new Array("LA", "LOUISIANA", 7),
									new Array("ME", "MAINE", 7),
									new Array("MD", "MARYLAND", 8),
									new Array("MA", "MASSACHUSETTS", 8),
									new Array("MI", "MICHIGAN", 7),
									new Array("MS", "MISSISSIPPI", 7),
									new Array("MO", "MISSOURI", 7),
									new Array("MT", "MONTANA", 6),
									new Array("NE", "NEBRASKA", 7),
									new Array("NV", "NEVADA", 6),
									new Array("NH", "NEW HAMPSHIRE", 8),
									new Array("NJ", "NEW JERSEY", 8),
									new Array("NM", "NEW MEXICO", 6),
									new Array("NY", "NEW YORK", 8),
									new Array("NC", "NORTH CAROLINA", 7),
									new Array("ND", "NORTH DAKOTA", 7),
									new Array("OH", "OHIO", 7),
									new Array("OK", "OKLAHOMA", 7),
									new Array("OR", "OREGON", 7),
									new Array("PA", "PENNSYLVANIA", 7),
									new Array("PR", "PUERTO RICO", 8),
									new Array("RI", "RHODE ISLAND", 9),
									new Array("SC", "SOUTH CAROLINA", 7),
									new Array("SD", "SOUTH DAKOTA", 7),
									new Array("TN", "TENNESSII", 7),
									new Array("TX", "TEXAS", 6),
									new Array("UT", "UTAH", 6),
									new Array("VT", "VERMONT", 7),
									new Array("VA", "VIRGINIA", 7),
									new Array("WA", "WASHINGTON", 7),
									new Array("WV", "WEST VIRGINIA", 7),
									new Array("WI", "WISCONSIN", 7),
									new Array("WY", "WYOMING", 7),
									new Array("AB", "ALBERTA", 5),
									new Array("BC", "BRITISH COLUMBIA", 5),
									new Array("MB", "MANITOBA", 5),
									new Array("NB", "NEW BRUNSWICK", 7),
									new Array("NL", "NEWFOUNDLAND", 7),
									new Array("NT", "NORTHWEST TERRITORIES", 5),
									new Array("NS", "NOVA SCOTIA", 7),
									new Array("NU", "NUNAVUT", 5),
									new Array("ON", "ONTARIO", 5),
									new Array("PE", "PRINCE EDWARD ISLAND", 8),
									new Array("QC", "QUEBEC", 5),
									new Array("SK", "SASKATCHEWAN", 6),
									new Array("YT", "YUKON", 5)
									);

var iStorePageDisplayed = 1;
var iStorePages = 0;
var iCurrentPage = 0;
var gbFoundState
var gstrAddress = "";
var giZoom
var address = "";
var gstrCurrentDate = "";
var gfmtGrandOpen = "";
var gxmlGrandOpen = "";
var gbZoomClicked = false;
var gLat = "";
var gLng = "";
var gStoreLat = "";
var gStoreLng = "";
var gMinLat = "";
var gMaxLat = "";
var gMaxLng = "";
var gMinLng = "";
var gdirn = "";
var gbStoreIsAddrA = "";
var strFrom;
var strTo;
var gmarkers = [];
var gbFoundCookie;
var marker = "";
var map="";
var searchStoreUrl = "";
var searchUrl = "";
var storeNumber = "";
var gstrStoreNumber = "";
var radius = "";
var giRadius = "";
var gbMainPage = "";
var lat = "";
var lng = "";
var geo = true;
var currentPageVar = false;
var stores = [];
var totalPages = false;
var storeHeight = 168;
var storesPerPage = 3;
var pageMultiplier = 50;
var minZoomLevel = 3;
var maxZoomLevel = 17;
// var startAddress = false;
var msg = "";
var aquariums = [];
var adoptions =[];
var doggie_day_camp = [];
var grooming = [];
//var photography =[];
var training = [];
var boarding = [];
var veterinary = [];

String.prototype.trim = function() 
	{
   return this.replace(/^\s+|\s+$/g, "");
	}
	
window.onunload = function()
   {   
   GUnload()
   };

//isGeoLoco: function(lat,lng)  
function isGeoLoco(strLat,strLng)  
	{
	gbMainPage = true;
	fncSetDate();
	//add listener for user clicking on map
	gbFoundCookie = fncGetCookie();
	if(gbFoundCookie)
		{
		fncGetPreferredStore();
		return;
		}
	if(strLat && strLng)
		{
		lat = strLat;  //set location
		lng = strLng;
		firstLoad();
		}
	else
		{
		geo = false;
		}
	}

function fncSetDate()
	{
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	if(month < 10)
		month = "0" + month;
	var day = currentTime.getDate();
	if(day < 10)
		day = "0" + day;
	var year = currentTime.getFullYear();
	gstrCurrentDate = year + "-" + month + "-" + day;
	}

function firstLoad()
	{
	var point = new GLatLng(lat,lng);
	map = new GMap2($('map'));
	setup(map,point,"true");
	}

function fncGetPreferredStore()
	{		
	var strHTML;
	
	map = new GMap2(document.getElementById("map"));
	//get the customer's store
	searchStoreUrl = "storeSearch.php?storeNumber=" + storeNumber;
	GDownloadUrl(searchStoreUrl, function(data)
			{
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName('store');
			radius = 15;
			var point = new GLatLng(lat,lng);
			//now get the stores in the area
			gLat = lat;
			gLng = lng;
			searchUrl = 'results.php?lat=' + lat + '&lng=' + lng + '&radius=' + radius;
			setup(map,point,"true");
			search_location = "";
			search_radius = ""; 
			search_aquariums = ""
			search_adoptions = ""; 
			search_ddc = "";
			search_grooming = "";
//			search_photography = "";
			search_training = "";
			search_boarding = "";
			search_veterinary = "";

			ReloadMap(true, search_location, search_radius, search_adoptions, search_ddc, search_grooming, search_training, search_boarding, search_veterinary);
		
			map.setCenter(point, 11);
			getStores();

			})
	
	}

//START OF MAP UPDATE CASCADE
//function	ReloadMap(bFirstLoad, sL, sR)
//function	ReloadMap(bFirstLoad, search_location, search_radius, search_adoptions, search_ddc, search_grooming, search_photography, search_training, search_boarding, search_veterinary) // Chris
function	ReloadMap(bFirstLoad, search_location, search_radius, search_adoptions, search_ddc, search_grooming, search_training, search_boarding, search_veterinary) // Chris
		{
		arryadoptions = [];
		if(search_adoptions.length > 0)
			{
			arryadoptions.push(search_adoptions)			
			}

		arrydoggie_day_camp = [];
		if(search_ddc.length > 0)
			{
			arrydoggie_day_camp.push(search_ddc)
			}
			
		arrygrooming = [];
		if(search_grooming.length > 0)
			{
			arrygrooming.push(search_grooming)
			}
			
//		arryphotography = [];
//		if(search_photography.length > 0)
//			{
//			arryphotography.push(search_photography)
//			}
			
		arrytraining = [];
		if(search_training.length > 0)
			{
			arrytraining.push(search_training)
			}
			
		arryboarding = [];
		if(search_boarding.length > 0)
			{
			arryboarding.push(search_boarding)
			}
			
		arryveterinary = [];
		if(search_veterinary.length > 0)
			{
			arryveterinary.push(search_veterinary)
			}
		if(bFirstLoad)
			return;
		if(search_location.length > 0)
			{
			addresss = search_location
			}
		geo = false;
		radius = search_radius;
		address = search_location //.trim()
				
		//validation
		if(!address)
			{
			return false
			}
		else if (address == '00000')
			{
			 return false
			}
		getLocation();
} //end reload map

function	setLocation()
   {
	var strAddress;
	var i;
	
	//get the new center point
	var point = new GLatLng(lat,lng)
	//pan to center of address
	if(map)
		{
		map.panTo(point)
		if(address.length > 0)
			{
			if(!gbFoundState)
				{
				if(radius <= 20)
					map.setCenter(point,11);
				else if(radius > 20 && radius < 75)
					map.setCenter(point, 10);
				else
					map.setCenter(point, 9);
				}
			else
				{
				map.setCenter(point, giZoom);
				}
			}
		}
	else
	   {
		map = new GMap2($('map'));
		map.setup(map,point,"true")
		return;
   	}
	if(geo) 
		{
		map.setCenter(point, 4);
		return getStores();
		}
		
	//create or move marker to address
	if(marker)
	   {
		marker.setPoint(point)
		map.setCenter(point, 4);
	   }
	else
	   {
		//attach marker to map
		marker = new GMarker(point, redIcon());
		}
	if(trimString($('location').value) != "")
		{
		if(!gbFoundState)
			{
//			average the stores locations to get a map center
//       this has a timing problem between retrieving the stores and this code being run
//			alert("set point gMinLat=" + gMinLat + " gMaxLat=" + gMaxLat);
//			alert("set point gmaxlng=" + gMinLng + " gMaxLng=" + gMaxLng);
//			lat = parseFloat(gMaxLat) + parseFloat(gMinLat);
//			alert("lats added=" + lat);
//			lat = lat / 2;
//			alert("lats div 2=" + lat);
//			lng = parseFloat(gMaxLng) + parseFloat(gMinLng);
//			lng = lng / 2;
//			alert("2 final lat=" + lat + " final lng=" + lng + " radius=" + radius);
			
			point2 = new GLatLng(lat,lng);
			if(radius <= 20)
				map.setCenter(point2,10);
			else if(radius > 20 && radius < 75)
				map.setCenter(point2, 9);
			else
				map.setCenter(point2, 8);
			}
		}
	}

function	setup(map,point,bSetCenter) 
	{
	//get map container
	var obj = map.getContainer()
	//up
	$E('div',obj,{className:'control panUp',onclick:function(){ map.panDirection(0,+1)}});
	//down
	$E('div',obj,{className:'control panDown',onclick:function(){map.panDirection(0,-1)}});
	//left
	$E('div',obj,{className:'control panLeft',onclick:function(){map.panDirection(+1,0)}});
	//right
	$E('div',obj,{className:'control  panRight',onclick:function(){map.panDirection(-1,0)}});
	//add zoom control

	//in
	$E('div',obj,{id:'zoomIn',className:'control zoomIn',onclick:function()
		{
		gbZoomClicked = false; //don't need to reload store markers
		zoom(map,+1);
		}});
	//out
	$E('div',obj,{id:'zoomOut',className:'control zoomOut',onclick:function()
		{
		gbZoomClicked = true;
		zoom(map,-1);
		}});
	
	//add map type
	//map
	$E('div',obj,{id:'cmap',className:'control2 cmap',onclick:function(){mapType(map,0)}});
	//sat
	$E('div',obj,{id:'csat',className:'control2 csat',onclick:function(){mapType(map,1)}});
	//hybrid
	$E('div',obj,{id:'chybrid',className:'control2 chybrid',onclick:function(){mapType(map,2)}});
	//map.setCenter(point, 10);
	if(bSetCenter == "true")
		map.setCenter(point, 4);
		//get rid of bubble shadow
	map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.display = 'none';
	
	//add listener for where the user has clicked the map
	GEvent.addListener(map, "click", function(overlay, point)
		{
//		map.clearOverlays();
		if (point) 
			{
			gLat = point.lat();
			gLng = point.lng();
			}
		})
	
	//add listener for map zoom event
	//set radius based upon zoom level and display the stores
	GEvent.addListener(map, "zoomend", function(oldzoom,zoom)
		{ 
		if(!gbZoomClicked && zoom < 8)
			{
			return;
			}
      frmradius = null;
		try
			{
			if(document.forms[1].miles)
				{
			   frmradius = document.getElementById('miles').value;
				}
			}
		catch(err)
			{
			return;	
			}
		if(frmradius == null)
			{
			return;
			}
		gbZoomClicked = false;
		switch(zoom)
			{
			case 17:
			case 16:
			case 15:
			case 14:
			case 13:
			case 12:
			case 11:
			case 10:
				if(giRadius < 20)
				   giRadius = 20;
				break;
			case 9:
				if(giRadius < 40)
					giRadius = 40;
				break;
			case 8:
				if(giRadius < 80)
					giRadius = 80;
				break;
			case 7:
				if(giRadius < 120)
					giRadius = 120;
				break;
//			case 7:
//				if(giRadius < 200)
//					giRadius = 200;
//				break;
//			case 6:
//				if(giRadius < 500)
//					giRadius = 500;
	//			break;
	//		case 5:
//				if(giRadius < 999)
	//				giRadius = 999;
//				break;
			default:
				   giRadius = 100;
			}
		searchUrl = 'results.php?lat=' + gLat + '&lng=' + gLng + '&radius=' + giRadius;
		getStores();		
		})
	}

function zoom(map,dir)
	{
	if(dir>0)
		{
		if(maxZoomLevel>(parseInt(map.getZoom())))
			{
			map.zoomIn()
			}
		}
	else if(dir<0)
		{
		if(minZoomLevel<(parseInt(map.getZoom())))
			{
			map.zoomOut()
			}
		}
//		map.adjustZoomButtons(map);
	}

function	mapType(map,i)
	{
	map.setMapType(G_DEFAULT_MAP_TYPES[i]);
	adjustMapButtons(map);
	}

function	adjustMapButtons(map)
	{
	Element.removeClassName('cmap','cmapOn');
	Element.removeClassName('csat','csatOn');
	Element.removeClassName('chybrid','chybridOn');
		
	var type = map.getCurrentMapType().getName();
	if(type == 'Map')
		{
		Element.addClassName('cmap','cmapOn');
		}
	else if(type == 'Satellite')
		{
		Element.addClassName('csat','csatOn');
		}
	else if(type == 'Hybrid')
		{
		Element.addClassName('chybrid','chybridOn');
		}
	}

function	getStores()
   {	
	var iNumberOfStores = 0;
	arryStores = null;
	arryStores = new Array();
	strStoreHTML = "";
	//get the returned XML file and work with the results
	// url = results.php  lat, lng and radius
	GDownloadUrl(searchUrl, function(data)
		{
		var xml = GXml.parse(data);
		var markers = xml.documentElement.getElementsByTagName('store');
		map.clearOverlays();
		gmarkers = [];
//		var sidebar = document.getElementById('results-container');
		var sidebar = document.getElementById('results-container');
		gMaxLat = 0;
		gMinLat = 999;
		gMaxLng = -999;
		gMinLng = 0;
		for (var i = 0; i < markers.length; i++)
			{  
			// add store info for pop-up
//			strStoreInfoHTML = fncStoreInfoHTML(markers[i], i);
			strStoreInfoHTML = fncStoreInfoHTML(markers[i], iNumberOfStores);
			strServicesInfoHTML = fncServicesInfoHTML(markers[i]);
			strDirectionsInfoHTML = fncDirectionsInfoHTML(markers[i]);
			storeNumber = markers[i].getAttribute('storenumber');
			address = strStoreHTML;
			lat = markers[i].getAttribute('latitude')
			lng = markers[i].getAttribute('longitude')
			if(lat < gMinLat)
				{
				gMinLat = lat;
				}
			if(lat > gMaxLat)
				gMaxLat = lat;
			if(lng < gMinLng)
				gMinLng = lng;
			if(lng > gMaxLng)
				gMaxLng = lng;
			//create sidebar HTML for this store 
			if(gxmlGrandOpen >= gstrCurrentDate)
				{
				strStoreHTML = "<div class='info-container'><div class='marker'><img src='/_images/indicator-green.gif' alt='Store' /></div>"
				}
			else
				{
				strStoreHTML = "<div class='info-container'><div class='marker'><img src='/_images/indicator-red.gif' alt='Store' /></div>"
				}
			strStoreHTML += "<h3><a href='/result-details.php?store=" + storeNumber + "'>" + xmlName + "<br> Store #" + storeNumber + "</a></h3>";
			if(gxmlGrandOpen >= gstrCurrentDate)
				strStoreHTML = strStoreHTML + "<h4>Opening " + gfmtGrandOpen + "</h4>";
			strStoreHTML += "<p>" + xmlAddress + "<br />"
			strStoreHTML += xmlCityStZip + "<br />";
			strStoreHTML += xmlPhone + "<br />";
			strStoreHTML += xmlDist + " miles</p>";
			strHref = "javascript:fncShowOnMap(" + iNumberOfStores + ",false)";
			strStoreHTML += "<p><a href='" + strHref + "' title='Show on map'>Show on map</a></p>";
			strStoreHTML += "<p><a href='/result-details.php?store=" + storeNumber + "'> See Details</a></p>";
			
			strZipcode = markers[i].getAttribute('zipcode')
			if(strZipcode.substring(0,1) >= 'A' && strZipcode.substring(0,1) <= 'Z' || strZipcode.substring(0,1) >= 'a' && strZipcode.substring(0,1) <= 'z')
			   {
				strHTML += "<p class='store-link'></p>";			
				}
			else
			   {
				strStoreHTML += "<p><a href='http://petsmart.shoplocal.com/petsmart/new_user_entry.aspx?citystatezip=" +xmlCityStZip + "&AdRef=sl_detailpage'>View in-store specials</a></p>";			
				}
			strStoreHTML += "<div class='clear-floats'></div></div>";
				
			var point2 = new GLatLng(lat,lng)
			//if the user has checked one of the boxes
//			if(arryadoptions.length > 0 || arrydoggie_day_camp.length > 0 ||
//				arrygrooming.length > 0 || arryphotography.length > 0 ||
//				arrytraining.length > 0 || arryboarding.length > 0 ||
//				arryveterinary.length > 0)
			if(arryadoptions.length > 0 || arrydoggie_day_camp.length > 0 ||
				arrygrooming.length > 0  ||
				arrytraining.length > 0 || arryboarding.length > 0 ||
				arryveterinary.length > 0)
				{
				var xmlAdopt = markers[i].getAttribute('adopt')
				var xmlDoggie_day_camp = markers[i].getAttribute('daycamp')
				var xmlGroom = markers[i].getAttribute('groom')
//				var xmlPhoto = markers[i].getAttribute('Photo')
				var xmlTrain = markers[i].getAttribute('train')
				var xmlBoard = markers[i].getAttribute('board')
				var xmlVet = markers[i].getAttribute('vet')
				
			//if the current store matches one of the checked boxes
			//combining all of the "if"'s into one statement caused a php error
			//create the marker, but check to see if we should add it to the map
				if(arryadoptions.length > 0 && xmlAdopt != "A")
					{
					continue;
					}
				if(arrydoggie_day_camp.length > 0  && xmlDoggie_day_camp != "D")
					{								
					continue;
					}
				if(arrygrooming.length > 0 && xmlGroom != "G")
					{								
					continue;
					}
//				if(arryphotography.length > 0 && xmlPhoto != "P")
//					{								
//					continue;
//					}
				if(arrytraining.length > 0 && xmlTrain != "T")
					{					
					continue;
					}
				if(arryboarding.length > 0 && xmlBoard != "B")
					{								
					continue;
					}
				if(arryveterinary.length > 0 && xmlVet != "V")
					{								
					continue;
					}
				//passed all the edits, so add the store marker
				//save the store info for the sidebar					
				arryStores[iNumberOfStores] = strStoreHTML;
				//create the marker and info window HTML
	         tabs = new Array();
	         var tabLabel = "Store Info";
	         var tabHtml = strStoreInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
	         var tabLabel = "Services";
	         var tabHtml = strServicesInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
	         var tabLabel = "Directions";
	         var tabHtml = strDirectionsInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
				var marker = createTabbedMarker(point2, tabs, storeNumber);
				map.addOverlay(marker);
				iNumberOfStores++;
				}
			else  // no box was checked
				{
				//save the store info for the sidebar				
				arryStores[iNumberOfStores] = strStoreHTML;
				//create the marker and info window HTML
	         tabs = new Array();
	         var tabLabel = "Store Info";
	         var tabHtml = strStoreInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
				var tabLabel = "Services";
	         var tabHtml = strServicesInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
				
	         var tabLabel = "Directions";
	         var tabHtml = strDirectionsInfoHTML;
	         tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
				
				var marker = createTabbedMarker(point2, tabs, storeNumber);
				map.addOverlay(marker);
				iNumberOfStores++;
				}
			}			
		//show number of stores in the area
		strNumberOfStores = "<h2><span>" + iNumberOfStores + " </span>";
		strNumberOfStores = strNumberOfStores + "Stores Found</h2>";
		strNumberOfStores = strNumberOfStores + "<div class='divider-white'></div>"
		strNumberOfStores = strNumberOfStores + "<p><a href='http://stores.petsmart.com/grand-openings/' title='Check our Grand Openings'>Check our Grand Openings <img src='/_images/white-arrow.jpg' alt='arrow' align='absmiddle' /></a></p>"
		document.getElementById('results-top').innerHTML = strNumberOfStores;
				
		//add store count and prev - next buttons to start of store list
		var iRemainder = iNumberOfStores % 3;
	   iStorePages = ( iNumberOfStores - iRemainder ) / 3;
		if(iRemainder > 0)
			iStorePages = iStorePages + 1;
		strPageCountHTML = "<p id='page-indicator'>Showing page <strong>1</strong> of <strong>" + iStorePages + "</strong></p>" ;
		strPageCountHTML = strPageCountHTML + "<img src='/_images/btn-previous-inactive.jpg' alt='Previous' class='previous-button' />"
		if(iStorePages > 1)
			{
		strPageCountHTML = strPageCountHTML + "<div onclick='fncStoreHTML(true)' id='topNextPage'>";
		strPageCountHTML = strPageCountHTML + "<img src='/_images/btn-next-active.jpg' alt='Next' class='next-button' /></div>"					
			}
		else
			{
		strPageCountHTML = strPageCountHTML + "<img src='/_images/btn-next-inactive.jpg' alt='Next' class='next-button' />"
			}
		// add line 
		strPageCountHTML = strPageCountHTML + "<div class='clear-floats'></div><div class='divider-blue'></div>"
		//get the stores for the first page
		if(iNumberOfStores > 0 && iNumberOfStores < 4)
			iCurrentPage = 1;
		else
			iCurrentPage = 0;
		strStoreHTML = strPageCountHTML + fncStoreHTML(true);	
		// add line before the last prev - next buttons			
		strStoreHTML = strStoreHTML + "<div class='divider-blue'></div>"
		//add prev - next buttons to end of store list
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-previous-inactive.jpg' alt='Previous' class='previous-button' />"
		if(iStorePages > 1)
			{
			strStoreHTML = strStoreHTML + "<div onclick='fncStoreHTML(false)' id='bottomNextPage'>";	
			strStoreHTML = strStoreHTML + "<img src='/_images/btn-next-active.jpg' alt='Next' class='next-button' /><div class='clear-floats'></div></div>"					
			}
		else
			{
			fncStoreHTML(false);
			}			
		}
	)		
		
	var paraObj = { }
	var pars = Transform.toQueryString(paraObj);
}

function	locatorService(url,pars,callBack)
   {
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: encodeURI(pars),onComplete: callBack})
	}

function fncStoreInfoHTML(marker, imarker_num)
{
xmlStoreNumber = marker.getAttribute('storenumber');
xmlName = marker.getAttribute('name');
xmlAddress = marker.getAttribute('address')
xmlCityStZip = marker.getAttribute('city') + ", " + marker.getAttribute('state') + " " + marker.getAttribute('zipcode')
xmlPhone = marker.getAttribute('phone')
xmlDist = marker.getAttribute('miles')
gxmlGrandOpen = marker.getAttribute('grandopen');
if(gxmlGrandOpen != null)
	gfmtGrandOpen = gxmlGrandOpen.substring(5,7) + "/" + gxmlGrandOpen.substring(8,10) + "/" + gxmlGrandOpen.substring(0,4);
xmlStoreOpen = fncFixHours(marker.getAttribute('Store_open'));
xmlStoreClose = fncFixHours(marker.getAttribute('Store_close'));
xmlSundayStoreOpen = fncFixHours(marker.getAttribute('Sunday_Store_open'));
xmlSundayStoreClose = fncFixHours(marker.getAttribute('Sunday_Store_close'));
iIndex = xmlDist.indexOf(".");
xmlDist = xmlDist.substring(0,iIndex + 3)				

strHTML = '<table id="store-info" cellpadding="0" cellspacing="0" border="0">';
strHTML += '<tr>';
strHTML += '<td valign="top" width="95">';
strHTML += '<img src="/_images/bouncing-ball.jpg" width="82" height="62" border="0" class="store-img" />';

strHTML += '<p class="store-link"><a href="/result-details.php?store=' + xmlStoreNumber + '" title="Get Details">Get Details</a></p>';

strCommand = "'javascript:fncShowOnMap(" + imarker_num + ",true)'"
strHTML += '<p class="store-link"><a href=' + strCommand + ' title="Get Directions">Get Directions</a></p>';

strZipcode = marker.getAttribute('zipcode')
if(strZipcode.substring(0,1) >= 'A' && strZipcode.substring(0,1) <= 'Z' || strZipcode.substring(0,1) >= 'a' && strZipcode.substring(0,1) <= 'z')
   {
	strHTML += "<p class='store-link'></p>";			
	}
else
   {
	strHTML += "<p class='store-link'><a href=http://petsmart.shoplocal.com/petsmart/new_user_entry.aspx?citystatezip=" + marker.getAttribute('zipcode') + "&AdRef=sl_detailpage'>View in-store<br>specials</a></p>";			
	}

strHTML += '</td>'
strHTML += '<td valign="top">';
strHTML += '<h3><a href="/result-details.php?store=' + xmlStoreNumber + '" title="' + xmlName + '">' + xmlName + " #" + xmlStoreNumber + '</a></h3>';
fncSetDate();
if(gxmlGrandOpen >= gstrCurrentDate)
	{
	strHTML += "<h4>Grand Opening: " + gfmtGrandOpen + "</h4>";
	}
strHTML += '<p>' + xmlAddress +'<br />' + xmlCityStZip + '<br />' + xmlPhone + '<br />' + xmlDist + ' Miles</p>';

if(xmlStoreOpen.substring(0,5) == "00:00")
	{
	strHTML += '<p class="store-hours">Monday-Saturday: Closed<br />';
}
else
	{
  	strHTML += '<p class="store-hours">Monday-Saturday: ' + xmlStoreOpen.substring(0,5) + ' a.m. - ' + xmlStoreClose.substring(0,5) + ' p.m.<br />';
	}
if(xmlSundayStoreOpen.substring(0,5) == "00:00")
	{
	strHTML += 'Sunday: Closed</p>';
	}
else
	{
	if(xmlStoreNumber == 399)
	   strHTML += 'Sunday: ' + xmlSundayStoreOpen.substring(0,5) + ' p.m. - ' + xmlSundayStoreClose.substring(0,5) + ' p.m.</p>';
	else	
   	strHTML += 'Sunday: ' + xmlSundayStoreOpen.substring(0,5) + ' a.m. - ' + xmlSundayStoreClose.substring(0,5) + ' p.m.</p>';
	}

strHTML += '<p class="store-note">Please call store to confirm hours.</p>';
strHTML += '</td>';
strHTML += '</tr>';
strHTML += '</table>';
strHTML += '<input name="storeNumber" type="hidden" value="' + xmlStoreNumber + '" size="40" id="storeNumber" />';
return strHTML	
}

function fncFixHours(strTime)
{
strResult = strTime;
if(strTime.length < 5 || strTime == "00:00")
	{
   strResult = "00:00";
	}
else if(strTime.substring(0, 1) == "0")
	{
   strResult = strTime.substring(1,5);
	}
return strResult;
}

function fncServicesInfoHTML(marker)
{
arryServices = new Array();

if(marker.getAttribute('aquarium') == "Q")
	{
	arryServices.push('<a href="http://aquarium-services.petsmart.com" title="Aquarium Services">Aquarium Services</a>');
	}
if(marker.getAttribute('adopt') == "A")
	arryServices.push('<a href="http://adoptions.petsmart.com/" title="Adoptions">Adoptions</a>');
if(marker.getAttribute('daycamp') == "D")
	arryServices.push('<a href="http://doggiedaycamp.petsmart.com/" title="Doggie DayCamp">Doggie DayCamp</a>');
if(marker.getAttribute('groom') == "G")
	arryServices.push('<a href="http://grooming.petsmart.com/" title="Grooming">Grooming</a>');
//if(marker.getAttribute('Photo') == "P")
//	arryServices.push('<a href="http://promotions.petsmart.com/landing/pet-photography/" title="Photography">Photography</a>');
if(marker.getAttribute('train') == "T")
	arryServices.push('<a href="http://training.petsmart.com/" title="Training">Training</a>');
if(marker.getAttribute('board') == "B")
	arryServices.push('<a href="http://petshotel.petsmart.com/" title="PetsHotel">PetsHotel</a>');
if(marker.getAttribute('vet') == "V")
	arryServices.push('<a href="http://banfield.petsmart.com/" title="Banfield">Banfield</a>');


strHTML =  '<table id="store-services" cellpadding="0" cellspacing="0" border="0">';
strHTML += '<tr><td colspan="2"><h4>Store Services</h4></td></tr><tr>';
for(i = 0; i < arryServices.length; i = i + 2) 
	{
	strHTML += '<td valign="top" class="services">' + arryServices[i] + '<br />';
	if(arryServices[i+1] != null)
		strHTML += arryServices[i+1] + '</td>';
	else
	   strHTML += '<td></td>';
	}
strHTML += '</tr></table>';
return strHTML;
}

/*function fncDirectionsInfoHTML(marker)
{
strHTML = "<b>Address:</b><br><br>";
strHTML += "Placement on map is approximate<br><br>";
strHTML += "&nbsp;<b>" + marker.getAttribute('address') + "</b><br><br>";
xmlCityStZip = marker.getAttribute('city') + ", " + marker.getAttribute('state') + " " + marker.getAttribute('zipcode')
strHTML += "&nbsp;<b>" + xmlCityStZip + "</b><br><br>";
strHTML += "Get directions from here:<br><br>";

strHTML += "<form name='InfoDirections' id='InfoDirections' action='#' onsubmit='return fncStoreDetailPage()'>";
strHTML += "<input name='infoFromAddr' type='text' value=''  size='40' id='infoFromAddr' maxlength='300'/>";
strHTML += "</form>";

strHTML += "<div onclick='fncStoreDetailPage()' id=''>";
strHTML += "<img src='/_images/btn-get-directions.png' alt='Get Directions' align='right'/></div>"					
return strHTML;
}
*/
function fncStoreHTML(bNextPage)
	{
	var strStoreHTML;
	var iCntr = 0;
	
	if(bNextPage == true)
		iCurrentPage++;
	else
		iCurrentPage--;
	//generate store sidebar html
	strStoreHTML = "<p id='page-indicator'>Showing page <strong>" + iCurrentPage + "</strong> of <strong>" + iStorePages + "</strong></p>" ;
	//update the top page buttons
	//previous button
	if(iCurrentPage < 2)
		{
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-previous-inactive.jpg' alt='Previous' class='previous-button' />";
		}
	else
		{
		strStoreHTML = strStoreHTML + "<div onclick='fncStoreHTML(false)' id='topPrevPage'>";
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-previous-active.jpg' alt='Previous' class='previous-button' /></div>";
		}
	//next button
	if(iCurrentPage < iStorePages)
		{
		strStoreHTML = strStoreHTML + "<div onclick='fncStoreHTML(true)' id='topNextPage'>";
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-next-active.jpg' alt='Next' class='next-button' /></div>";	
		}
	else
		{
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-next-inactive.jpg' alt='Next' class='next-button' />";
		}
	strStoreHTML = strStoreHTML + "<div class='clear-floats'></div><div class='divider-blue'></div>";
	//add the store information
	strStores = "";
	iStartCntr = iCurrentPage*3 -3;
	iEndCntr = iCurrentPage*3;
	for(iCntr = iStartCntr;iCntr < iEndCntr;iCntr++)
		{
		if(arryStores[iCntr] != null)
			strStores = strStores + arryStores[iCntr];
		else
			strStores = strStores + "<br><br><br><br><br><br><br><br><br><br>";
		}
	strStoreHTML = strStoreHTML + strStores;
	
	// update the bottom page buttons
	strStoreHTML = strStoreHTML + "<div class='divider-blue'></div>";
	//add prev - next buttons to end of store list
	if(iCurrentPage > 1)
		{
		strStoreHTML = strStoreHTML + "<div onclick='fncStoreHTML(false)' id='bottomPrevPage'>";
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-previous-active.jpg' alt='Previous' class='previous-button' /></div>";
		}
	else
		{
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-previous-inactive.jpg' alt='Previous' class='previous-button' />";					
		}
	if(iCurrentPage < iStorePages)
		{
		strStoreHTML = strStoreHTML + "<div onclick='fncStoreHTML(true)' id='bottomNextPage'>";
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-next-active.jpg' alt='Next' class='next-button' /><div class='clear-floats'></div></div>";					
		}
	else
		{
		strStoreHTML = strStoreHTML + "<img src='/_images/btn-next-inactive.jpg' alt='Next' class='next-button' /><div class='clear-floats'></div>";	
		}
//	document.getElementById('results-container').innerHTML = strStoreHTML;
	document.getElementById('results-container').innerHTML = strStoreHTML;
//	document.getElementById('results-container').innerText  = strStoreHTML;
	}

function createTabbedMarker(point, tabs, storeNumber) 
	{
   var marker;
	if(gxmlGrandOpen >= gstrCurrentDate)
		{
	   marker = new GMarker(point,greenIcon());
		}
	else
		{
	   marker = new GMarker(point,redIcon());
		}
   var marker_num = gmarkers.length;
   marker.marker_num = marker_num;
   marker.tabs = tabs;
   gmarkers[marker_num] = marker;
   GEvent.addListener(gmarkers[marker_num], "click", function() 
		{
		if(gbMainPage)
			{
	      if(map.getZoom() < 10)
				pt = new GLatLng(point.lat() + .3, point.lng());
			else if(map.getZoom() == 13 || map.getZoom() == 14)
				pt = new GLatLng(point.lat() + .01, point.lng());		
			else if(map.getZoom() == 15)
				pt = new GLatLng(point.lat() + .005, point.lng());		
			else if(map.getZoom() == 16)
				pt = new GLatLng(point.lat() + .001, point.lng());		
			else if(map.getZoom() == 17)
				pt = new GLatLng(point.lat() + .0005, point.lng());		
			else if(map.getZoom() > 17)
				pt = new GLatLng(point.lat() + .0001, point.lng());		
			else
				pt = new GLatLng(point.lat() + .04, point.lng());
			}
		else // store detail page
			{
			pt = fncDetailPanInfoBox(point);
			}
		map.panTo(pt);
		marker.openInfoWindowTabsHtml(gmarkers[marker_num].tabs,{suppressMapPan:true});
      });
   return marker;
    }

function fncDetailPanInfoBox(point)
	{
	izoomLevel = map.getZoom();
	switch(izoomLevel)
		{
		case 1:
		case 2:
		case 3:
		case 4:
			pt = new GLatLng(point.lat() + 10, point.lng());
			break;
   	case 5:
			pt = new GLatLng(point.lat() + 5, point.lng());
			break;
   	case 6:
			pt = new GLatLng(point.lat() + 2.5, point.lng());
			break;
		case 7:
			pt = new GLatLng(point.lat() + 1.2, point.lng());
			break;
	   case 8:
			pt = new GLatLng(point.lat() + .7, point.lng());
			break;
	   case 9:
			pt = new GLatLng(point.lat() + .3, point.lng());
			break;
	   case 10:
			pt = new GLatLng(point.lat() + .15, point.lng());
			break;
		case 11:
			pt = new GLatLng(point.lat() + .05, point.lng());			
			break;
		case 12:
			pt = new GLatLng(point.lat() + .04, point.lng());			
			break;
		case 13:
			pt = new GLatLng(point.lat() + .02, point.lng());
			break;
		case 14:
			pt = new GLatLng(point.lat() + .01, point.lng());		
			break;
		case 15:
			pt = new GLatLng(point.lat() + .005, point.lng());		
			break;
		case 16:
			pt = new GLatLng(point.lat() + .0025, point.lng());		
			break;
		case 17:
			pt = new GLatLng(point.lat() + .001, point.lng());		
			break;
		case 18:
			pt = new GLatLng(point.lat() + .0005, point.lng());		
			break;
		default:
			pt = new GLatLng(point.lat() + .0003, point.lng());		
		}
return pt;
}

function	startIcon()
   {
	var icon = new GIcon();
	icon.image = "../_images/indicator-A.gif";
	icon.shadow = "";
	icon.iconSize = new GSize(28, 43);
	icon.shadowSize = new GSize(0, 0);
	icon.iconAnchor = new GPoint(14, 43);
	icon.infoWindowAnchor = new GPoint(13, 40);
	return icon
	}

function	endIcon()
   {
	var icon = new GIcon();
	icon.image = "../_images/indicator-B.gif";
	icon.shadow = "";
	icon.iconSize = new GSize(28, 43);
	icon.shadowSize = new GSize(0, 0);
	icon.iconAnchor = new GPoint(14, 43);
	icon.infoWindowAnchor = new GPoint(13, 40);
	return icon
	}

function	greenIcon()
   {
	var icon = new GIcon();
	icon.image = "../_images/marker-green.png";
	icon.shadow = "";
	icon.iconSize = new GSize(28, 43);
	icon.shadowSize = new GSize(0, 0);
	icon.iconAnchor = new GPoint(14, 43);
	icon.infoWindowAnchor = new GPoint(13, 40);
	return icon
	}
	
function	redIcon()
   {
	var icon = new GIcon();
	icon.image = "../_images/marker-red.png";
	icon.shadow = "";
	icon.iconSize = new GSize(28, 43);
	icon.shadowSize = new GSize(0, 0);
	icon.iconAnchor = new GPoint(14, 43);
	icon.infoWindowAnchor = new GPoint(13, 40);
	return icon;
	}

function fncShowOnMap(iMarker_num, bShowDirections)
	{
	pt = gmarkers[iMarker_num].getPoint();
	newpt = new GLatLng(pt.lat() + .02, pt.lng());
	map.panTo(newpt);
	if(bShowDirections)
	   gmarkers[iMarker_num].openInfoWindowTabsHtml(gmarkers[iMarker_num].tabs,{selectedTab:2, suppressMapPan:true});	
	else
	   gmarkers[iMarker_num].openInfoWindowTabsHtml(gmarkers[iMarker_num].tabs);
	}

function fncGetCookie()
	{
	//look for a cookie
	cookie=document.cookie;
	iStartPos = cookie.indexOf("Store") + 6;
   if(iStartPos < 6)
		return false;

   iEndPos = cookie.indexOf("|", iStartPos);
	storeNumber = cookie.substring(iStartPos, iEndPos);
	iStartPos = cookie.indexOf("lat") + 4;
	if(iStartPos < 4)
		return false;
	iEndPos = cookie.indexOf("|", iStartPos);
	lat = cookie.substring(iStartPos, iEndPos);
	iStartPos = cookie.indexOf("lng") + 4;
	if(iStartPos < 4)
		return false;
	iEndPos = cookie.indexOf("|", iStartPos);
	lng = cookie.substring(iStartPos, iEndPos);
	return true;
	}

function fncSetCookie()
	{
   var strStartAddr = "";
   storeNumber = gstrStoreNumber;
	dt = new Date();
	dt.setFullYear(dt.getFullYear() + 1);
	expires="expires=" + dt.toGMTString();
	strCookie = "Store=" + storeNumber + "|"

   strCookie += "lat=" + gLat + "|"
	strCookie += "lng=" + gLng + "|"	
   //strCookie += "lat=" + lat + "|"
	//strCookie += "lng=" + lng + "|"	
	document.cookie = strCookie + "; " + expires;
	gbFoundCookie = true;
	strStartAddr = document.getElementById('start-address').value;	
	if(strStartAddr.length == 0)
	   strStartAddr = "";
	fncStoreDetail(strStartAddr, storeNumber);
	}

function getLocation()
   {
	var geocoder = new GClientGeocoder();

	//if they entered only a state then zoom to the state level
	//otherwise use the radius to set the zoom
	strAddress = address.trim();
	strAddress = strAddress.toUpperCase();

	// check Canadian postal code and put in space if needed
	if(strAddress.length == 6)
		{
		if(   strAddress.substring(1,2) >= 0 
		   && strAddress.substring(1,2) <= 9
		   && strAddress.substring(3,4) >= 0 
		   && strAddress.substring(3,4) <= 9
		   && strAddress.substring(5,6) >= 0 
		   && strAddress.substring(5,6) <= 9)
		   {
				address = strAddress.substring(0,3) + " " + strAddress.substring(3,6);
			}
		}
	
	gbFoundState = false;
	for(i = 0; i < arryStates.length; i++)
		{
		if(arryStates[i][0] == strAddress || arryStates[i][1] == strAddress)
			{
			giZoom = arryStates[i][2];
			gbFoundState = true;
			if(strAddress == "DE" || strAddress == "DE" || strAddress == "ID" || strAddress == "IN" || strAddress == "OK")
				address = address + " USA";
			if(strAddress == "NB" || strAddress == "NL" || strAddress == "NT" || strAddress == "NU" || strAddress == "PE" || strAddress == "SK" || strAddress == "YT")
				address = address + " CANADA";
			}
		}
	//check if address is 3 numbers - if so then assume it is an area code
	//run through stores to try to find a store with that area code
	strPos1 = strAddress.substring(0,1);
	strPos5  = strAddress.substring(4,5);
	bAreaCode = false;
	if(strPos1 == "(" && strPos5 == ")")
		{
		strPos1 = strAddress.substring(1,2);
		strPos2  = strAddress.substring(2,3);
		strPos3  = strAddress.substring(3,4);
		strAddress = strPos1 + strPos2 + strPos3;
		bAreaCode = true;
		}
	if(strAddress.length == 3)
		{
		strPos1 = strAddress.substring(0,1);
		strPos2  = strAddress.substring(1,2);
		strPos3  = strAddress.substring(2,3);		
		strAddress = strPos1 + strPos2 + strPos3;
		bAreaCode = true;
		}
	if(bAreaCode)
		{
		if(strPos1 >= "0" && strPos1 <= "9" && strPos2 >= "0" && strPos2 <= "9" && strPos3 >= "0" && strPos3 <= "9")
			{
		  	searchUrl = 'results.php?lat=42&lng=96&radius=999';  //get all the stores
			//search through stores
			GDownloadUrl(searchUrl, function(data)
				{
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName('store');
				for (var i = 0; i < markers.length; i++)
					{  
					strAreaCode = markers[i].getAttribute('phone');
					strAreaCode = strAreaCode.substring(0,3);
					if(strAreaCode == strAddress)
						{
						lat = markers[i].getAttribute('latitude');
						lng = markers[i].getAttribute('longitude');
						gLat =lat;
						gLng =lng;
						giRadius = 75;
						break;
						}
					}
			  	searchUrl = 'results.php?lat=' + lat + '&lng=' + lng + '&radius=75';
				setLocation();
				})
			}
		return false;
		}
	point=null;
	geocoder.getLatLng(address,function(point)
		{
      if(point == null)
		   {
			return false;
			}
		else
		   {
			if(!gbFoundState)
				{
				$('miles').value = radius;
				}
			gLat = point.lat();
			gLng = point.lng();
			if(gbFoundState)
				{
				radius = 400;
				}
		   searchUrl = 'results.php?lat=' + point.lat() + '&lng=' + point.lng() + '&radius=' +radius 
		   lat = point.lat()
		   lng = point.lng()
			//check size of cache and remove if nessessary
			setLocation()
	 		}
		})
	}

function trimString (str) 
   {
   while (str.charAt(0) == ' ')
      str = str.substring(1);
   while (str.charAt(str.length - 1) == ' ')
      str = str.substring(0, str.length - 1);
   return str;
   }

function	resetPage(obj)
	{
	//clear bubble
	bubble.hide()
		
	//clear points
	map.clearMarkers(map,stores)
		
	currentPageVar = 1
	totalPages = Math.ceil(parseInt(obj.COUNT)/3);
	if(totalPages > 34) totalPages = 34;
	if(obj.COUNT == 0) totalPages = 1
	}

function fncStoreDetailPage()
{
gstrStoreNumber = document.getElementById('storeNumber').value;
strFromAddr = document.getElementById('infoFromAddr').value;
strDirectionsURL = "/result-details.php?store=" + gstrStoreNumber + "&fromAddr=" + strFromAddr;
window.location =strDirectionsURL;
return false;
}

function clearMarkers(map,stores)
   {
   if(stores.length>0)while(stores.length>0)map.removeOverlay(stores.shift());
	}

function fncDirectionsInfoHTML(marker)
{

strHTML = '<form name="get-directions" action="javascript:fncStoreDetailPage();"><table id="store-directions" cellpadding="0" cellspacing="0" border="0">';
strHTML += '<tr>';
strHTML += '<td colspan="2" valign="top">';
strHTML += '<h4>Address: <span>Placement on map is approximate</span></h4>';
strHTML += '<p><strong>' + marker.getAttribute('address') + '<br />' + marker.getAttribute('city') + ", " + marker.getAttribute('state') + " " + marker.getAttribute('zipcode') + '</strong></p>';
strHTML += '<h5>Get directions from here:</h5>';
strHTML += '</td>';
strHTML += '<tr>';
strHTML += '<td valign="top">';
strHTML += '<input name="infoFromAddr" type="text" value="" size="30" id="infoFromAddr" maxlength="300" />&nbsp;';
strHTML += '</td>';
strHTML += '<td valign="top">';
strHTML += '<input type="image" name="submit" id="directions-btn" alt="Get directions" src="/_images/btn-get-directions-infowindow.png" border="0" width="124" height="25" />';
strHTML += '</td>';
strHTML += '</tr>';
strHTML += '</table></form>';
return strHTML;
}

function changeImage(i) 
	{
	var marker = gdirn.getMarker(i);
   map.removeOverlay(marker);
   var icon = G_PAUSE_ICON;
   if (i == 0) icon = startIcon();
   if (i == gdirn.getNumRoutes()) icon = endIcon();
   var newMarker = new GMarker(marker.getLatLng(), {icon:icon});
   map.addOverlay(newMarker);
   }

function fncDrivingDirections(bDrivingDirections)
{
	strFrom = "";
	strTo = "";
//	document.getElementById('end-address').value = storeLocator.pars.address;
	if(document.getElementById('start-address') != null)
		{
		strFrom = document.getElementById('start-address').value ;
		}
	else
		{
		strFrom = address;
		}
	document.getElementById('end-address').value = address;
	if(document.getElementById('end-address') != null)
		{
		strTo = document.getElementById('end-address').value ;
		}
	else
		{
		strTo = address;
		  }
	map = new GMap2(document.getElementById("map"));
	if(!bDrivingDirections)
		{
		searchStoreUrl = "storeSearch.php?storeNumber=" + gstrStoreNumber;
		GDownloadUrl(searchStoreUrl, function(data)
			{
			var xml = GXml.parse(data);
			var markers = xml.documentElement.getElementsByTagName('store');
			gLat = markers[0].getAttribute('lat');
			gLng = markers[0].getAttribute('lng');
			strStoreInfoHTML = fncStoreInfoHTML(markers[0],0);
			strServicesInfoHTML = fncServicesInfoHTML(markers[0]);
			strDirectionsInfoHTML = fncDirectionsInfoHTML(markers[0]);
			var point = new GLatLng(gLat,gLng);
			setup(map,point,"true");
			//create the marker and info window HTML
	      tabs = new Array();
	      var tabLabel = "Store Info";
	      var tabHtml = strStoreInfoHTML;
		   tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
		   var tabLabel = "Services";
		   var tabHtml = strServicesInfoHTML;
		   tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
		   var tabLabel = "Directions";
		   var tabHtml = strDirectionsInfoHTML;
		   tabs.push(new GInfoWindowTab(tabLabel,tabHtml));
			marker = createTabbedMarker(point, tabs, storeNumber);
			map.addOverlay(marker);
			map.setCenter(point, 13);
			});
			return;
		}
	gdirn = new GDirections(map);
	var strSpaces = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	if(gbStoreIsAddrA)
		strFromTo = "from:" + gStoreLat + "," + gStoreLng + " to: " + strTo;
	else
		strFromTo = "from:" + strFrom + " to: " + gStoreLat + "," + gStoreLng;
	
	//add listener to wait for the "load" to complete
	// waiting for the "load" to finish is critical to getting the driving steps
	GEvent.addListener(gdirn,"load", function()
		{				
      setTimeout(function() 
			{
         for (var i=0; i < gdirn.getNumRoutes()+1; i++) 
				{
            changeImage(i);
          	}
        	},0);
		//set the top directions
		var strTopDirections = "<b>Driving directions to:</b>";
		strTopDirections += "<br><br>" + strTo
		strTopDirections += "<b> from </b>" + strFrom
		var route = gdirn.getRoute(0);
	
		strTopDirections = strTopDirections + "<br><br><b>" + route.getDistance().html + " - about " + route.getDuration().html + "</b>";		
		strEmailDirections ="http://maps.google.com/maps?f=d&source=s_d&saddr=" + strFrom + "&daddr=" + strTo ;
		strTopDirections += " <p id='directions-functions'><a href='javascript:fncPrintDirections()'>Print Directions</a> | <a href='" + strEmailDirections + "' target='_blank'>Email Directions</a></p>";
		document.getElementById('directions-top').innerHTML = strTopDirections;
		//set the middle directions
		var strMiddleDirections = "<table width='500' border='0' cellspacing='0' cellpadding='0' id='directions-list'>";
		strMiddleDirections += "<tr><td class='start-location-marker'><img src='/_images/indicator-A.gif' alt='Start Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td id='start-location'>" +strFrom + "</td><td></td></tr>";
		for (var j=0; j < route.getNumSteps(); j++)
			{
			var step = route.getStep(j);
			strMiddleDirections += "<tr><td></td><td>" + (j+1) + ".  " + step.getDescriptionHtml() + "</td>";
			strMiddleDirections += "<td>" + step.getDistance().html + "</td></tr>";
			}
		strMiddleDirections += "<tr><td class='end-location-marker'><img src='/_images/indicator-B.gif' alt='End Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td id='end-location'>" + strTo + "</td><td></td></tr>";
		strMiddleDirections += "</table>";
		strMiddleDirections += "<form name='get-directions' action='javascript:fncDrivingDirections(true);'>";
		strMiddleDirections += "<table border='0' cellspacing='0' cellpadding='0' width='358' id='modify-directions'>";
		strMiddleDirections += "<tr><td colspan='4'><strong>Alter Directions:</strong></td></tr>";
		strMiddleDirections += "<tr><td class='start-location-marker'><img src='/_images/indicator-A.gif' alt='Start Location' width='28' height='43' /></td>";
		if(gbStoreIsAddrA)
			strMiddleDirections += "<td colspan='2'><input name='start-address' type='text' id='start-address' value='" + strFrom + "' size='38' disabled /></td>";
		else
			strMiddleDirections += "<td colspan='2'><input name='start-address' type='text' id='start-address' value='" + strFrom + "' size='38' /></td>";
		
		strMiddleDirections += "<td rowspan='2'><a href='#' onclick=fncSwitchAddr()><img src='/_images/btn-switch-directions.png' alt='Switch Directions' width='16' height='39' /></a></td></tr>";
		
		strMiddleDirections += "<tr><td class='end-location-marker'><img src='/_images/indicator-B.gif' alt='End Location' width='28' height='43' /></td>";
		if(gbStoreIsAddrA)
			strMiddleDirections += "<td colspan='2'><input name='end-address' type='text' id='end-address' value='" + strTo + "' size='38' /></td></tr>";
		else
			strMiddleDirections += "<td colspan='2'><input name='end-address' type='text' id='end-address' value='" + strTo + "' size='38' disabled /></td></tr>";
		strMiddleDirections += "<tr><td>&nbsp;</td><td></td>";
		
//		if(bDetailPage)
		strMiddleDirections += "<td><input type='image' name='submit-directions' id='directions-area-btn' alt='Get directions' src='/_images/btn-get-directions.gif' border='0' width='124' height='25' align='right' /></td>";
//		else
//			strMiddleDirections += "<td><div onclick='fncDrivingDirections(false)' id='get-directions'>";
	
		strMiddleDirections += "<td>&nbsp;</td></tr></table></form>";
		strMiddleDirections += "<div class='clear-floats'></div>";
		strMiddleDirections += "</div>" //end of "middle" div 
		document.getElementById('directions-middle').innerHTML = strMiddleDirections;
		})

	GEvent.addListener(gdirn,"addoverlay", function()
		{				
		point = null;  // we are allowing google to center based upon the route, so we don't need a point
		setup(map,point,"false");
		})
	GEvent.addListener(gdirn, "error", handleErrors);

	//get the directions from google
	// when loaded the "load" listener will process the directions
	gdirn.load(strFromTo, {getSteps:true});
}

function handleErrors()
	{
	if (gdirn.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		{
		strFrom = document.getElementById('start-address').value ;
		strTo = document.getElementById('end-address').value ;
		//set the top directions
		var strTopDirections = "<b>Driving directions to:</b>";
		strTopDirections += "<br><br>" + strTo
		strTopDirections += "<b> from </b>" + strFrom;
		strTopDirections = strTopDirections + "<br><br>";
		strEmailDirections ="http://maps.google.com/maps?f=d&source=s_d&saddr=" + strFrom + "&daddr=" + strTo
		strTopDirections += " <p id='directions-functions'><a href='javascript:fncPrintDirections()'>Print Directions</a> | <a href='" + strEmailDirections + "'>Email Directions</a></p>";
		document.getElementById('directions-top').innerHTML = strTopDirections;
		//set the middle directions
		var strMiddleDirections = "<table width='500' border='0' cellspacing='0' cellpadding='0' id='directions-list'>";
		strMiddleDirections += "<tr><td></td><td><b><font color=red>Address could not be found. Please enter an address, city, state and zip code.</font></b></td></tr>";
		strMiddleDirections += "<tr><td class='start-location-marker'><img src='/_images/indicator-A.gif' alt='Start Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td id='start-location'>" + strFrom + "</td><td></td></tr>";
		strMiddleDirections += "<tr><td class='end-location-marker'><img src='/_images/indicator-B.gif' alt='End Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td id='end-location'>" + strTo + "</td><td></td></tr>";
		strMiddleDirections += "</table>";
		strMiddleDirections += "<form name='get-directions' action='javascript:fncDrivingDirections(true);'>";
		strMiddleDirections += "<table border='0' cellspacing='0' cellpadding='0' width='358' id='modify-directions'>";
		strMiddleDirections += "<tr><td colspan='4'><strong>Alter Directions:</strong></td></tr>";
		strMiddleDirections += "<tr><td class='start-location-marker'><img src='/_images/indicator-A.gif' alt='Start Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td colspan='2'><input name='start-address' type='text' id='start-address' value='" + strFrom + "' size='38' /></td>";
		
		strMiddleDirections += "<td rowspan='2'><a href='#' onclick=fncSwitchAddr()><img src='/_images/btn-switch-directions.png' alt='Switch Directions' width='16' height='39' /></a></td></tr>";
		
		strMiddleDirections += "<tr><td class='end-location-marker'><img src='/_images/indicator-B.gif' alt='End Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td colspan='2'><input name='end-address' type='text' id='end-address' value='" + strTo + "' size='38' /></td></tr>";
		strMiddleDirections += "<tr><td>&nbsp;</td><td></td>";
		strMiddleDirections += "<td><input type='image' name='submit-directions' id='directions-area-btn' alt='Get directions' src='/_images/btn-get-directions.gif' border='0' width='124' height='25' align='right' /></td>";
	
		strMiddleDirections += "<td>&nbsp;</td></tr></table></form>";
		strMiddleDirections += "<div class='clear-floats'></div>";
		strMiddleDirections += "</div>" //end of "middle" div 
		document.getElementById('directions-middle').innerHTML = strMiddleDirections;
		fncDrivingDirections(false);
		}
	//call with only store - will display map with store marker but no directions
//	fncStoreDetail("", gstrStoreNumber);
	}
	
function fncDirectionsNoStartPt()
{
	//if there is a st and end then call fncDrivingDirections(True)
//	else
		//set the top directions
		var strTopDirections = "<b>Driving directions to:</b>";
		strFrom = document.getElementById('start-address').value;
		strTo = document.getElementById('end-address').value;
		strTopDirections += "<br><br>" + strTo;
//		strTopDirections += "<b> from </b>" + strFrom
//		var route = dirn.getRoute(0);
	
//		strTopDirections = strTopDirections + "<br><br><b>" + route.getDistance().html + " - about " + route.getDuration().html + "</b>";
		strEmailDirections ="http://maps.google.com/maps?f=d&source=s_d&saddr=" + strFrom + "&daddr=" + strTo

		strTopDirections += " <p id='directions-functions'><a href='#' onclick='javascript:fncPrintDirections()'>Print Directions</a> | <a href='" + strEmailDirections + "'>Email Directions</a></p>";
		document.getElementById('directions-top').innerHTML = strTopDirections;
		//set the middle directions
		var strMiddleDirections = "<table width='500' border='0' cellspacing='0' cellpadding='0' id='directions-list'>";
		
		strMiddleDirections += "<tr></td>";
		strMiddleDirections += "<td ></td><td></td></tr>";
		strMiddleDirections += "<tr><td></td>";
		strMiddleDirections += "<td></td><td></td></tr>";		
		strMiddleDirections += "</table>";
		strMiddleDirections += "<form name='get-directions' action='javascript:fncDrivingDirections(true);'>";
		strMiddleDirections += "<table border='0' cellspacing='0' cellpadding='0' width='358' id='modify-directions'>";
		strMiddleDirections += "<tr><td colspan='4'><strong>Alter Directions:</strong></td></tr>";
		strMiddleDirections += "<tr><td class='start-location-marker'><img src='/_images/indicator-A.gif' alt='Start Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td colspan='2'><input name='start-address' type='text' id='start-address' value='" + strFrom + "' size='38' /></td>";
	
		strMiddleDirections += "<td rowspan='2'><a href='#' onclick=fncSwitchAddr()><img src='/_images/btn-switch-directions.png' alt='Switch Directions' width='16' height='39' /></a></td></tr>";
		
		strMiddleDirections += "<tr><td class='end-location-marker'><img src='/_images/indicator-B.gif' alt='End Location' width='28' height='43' /></td>";
		strMiddleDirections += "<td colspan='2'><input name='end-address' type='text' id='end-address' value='" + strTo + "' size='38' /></td></tr>";
		strMiddleDirections += "<tr><td>&nbsp;</td><td>&nbsp;</td>";
		
//		if(bDetailPage)
			strMiddleDirections += "<td><input type='image' name='submit-directions' id='directions-area-btn' alt='Get directions' src='/_images/btn-get-directions.gif' border='0' width='124' height='25' align='right' /></td>";
//		else
//			strMiddleDirections += "<td><div onclick='fncDrivingDirections(false)' id='get-directions'>";
		strMiddleDirections += "<td>&nbsp;</td></tr></table></form>";
		strMiddleDirections += "<div class='clear-floats'></div>";
		strMiddleDirections += "</div>" //end of "middle" div 
		document.getElementById('directions-middle').innerHTML = strMiddleDirections;
//		document.getElementById("directions-container").style.display='block';	
		document.getElementById("directions-container").style.display='none';	
}


function fncSwitchAddr()
	{
	if(gbStoreIsAddrA)
	   gbStoreIsAddrA = false;
	else
		gbStoreIsAddrA = true;

	strAddr1 = document.getElementById('start-address').value;
	document.getElementById('start-address').value = document.getElementById('end-address').value;
	document.getElementById('end-address').value = strAddr1;
	address = strAddr1;
	fncDrivingDirections(true);
	}

function fncStoreDetail(strStartAddr, strStoreNumber)
	{
	gbMainPage = false;
	gbStoreIsAddrA = false;
	if(strStartAddr.length > 0 && strStoreNumber.length > 0)
		{
		document.getElementById("directions-container").style.display='block';
		}
	else
		{
		document.getElementById("directions-container").style.display='none';
		}
//	storeNumber = strStoreNumber;	
	gstrStoreNumber = strStoreNumber;
	searchStoreUrl = "storeSearch.php?storeNumber=" + strStoreNumber;
	document.getElementById('start-address').value = strStartAddr;	
	
//	startAddress = strStartAddr;
	GDownloadUrl(searchStoreUrl, function(data)
		{
		var xml = GXml.parse(data);
		var xmlStore = xml.documentElement.getElementsByTagName('store');
		xmlName = xmlStore[0].getAttribute('name');
		xmlAddress = xmlStore[0].getAttribute('address');
		xmlCityStZip = xmlStore[0].getAttribute('city') + ", " + xmlStore[0].getAttribute('state') + " " + xmlStore[0].getAttribute('zipcode');
		address = xmlAddress + ", " + xmlCityStZip;
		xmlPhone = xmlStore[0].getAttribute('phone');
		xmlNotes = xmlStore[0].getAttribute('notes');

		if(fncFixHours(xmlStore[0].getAttribute('Store_open')) == "00:00")
			{
			xmlMFHours = "Closed";
			}
		else
			{
			xmlMFHours = fncFixHours(xmlStore[0].getAttribute('Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Store_close')) + " p.m.";
			}
		if(fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) == "00:00")
			{
			xmlSundayHours = "Closed";
			}
		else
			{
      	if(strStoreNumber == 399)
			   xmlSundayHours = fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.";
			else
			   xmlSundayHours = fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.";
			}
		
		strStoreHeader= "<h1>PetSmart store #" + strStoreNumber + " " + xmlName + "</h1>";
		
		document.getElementById('store-header').innerHTML = strStoreHeader;

	  strStoreInfo = "<h3>Address:</h3>";
      strStoreInfo += "<p>" + xmlAddress + "<br />";
	  strStoreInfo += xmlCityStZip + "<br />";
	  strStoreInfo += "<a href='javascript:fncOpenInfoWindow(0,2)'>Get Driving Directions</a></p>";
      strStoreInfo += "<h3>Phone:</h3>";
      strStoreInfo += "<p>" + xmlPhone + "</p>";
	  strStoreInfo += "<h3>Main Store Hours:</h3>"; 
	  strStoreInfo += "<p>Mon-Sat: " + xmlMFHours + "<br />";
	  strStoreInfo += "Sun: " + xmlSundayHours + "<br />"; 
	  strStoreInfo += "<em>Please call store to confirm hours.</em><br />";

	  strZipcode = xmlStore[0].getAttribute('zipcode');
		if(strZipcode.substring(0,1) >= 'A' && strZipcode.substring(0,1) <= 'Z' || strZipcode.substring(0,1) >= 'b' && strZipcode.substring(0,1) <= 'z')
			{
			strStoreInfo += "<br />";		
			}
		else
		   {
	     strStoreInfo += "<a href='http://petsmart.shoplocal.com/petsmart/new_user_entry.aspx?citystatezip=" + xmlStore[0].getAttribute('zipcode');
		  strStoreInfo += "&AdRef=sl_detailpage'>View in-store specials</a><br />";
			}

		//show store notes
		if(xmlNotes != "-")
			{
		   strStoreInfo += "<h3>Additional Information:</h3>";
			strStoreInfo += "<p>" + xmlNotes + "</p>";
			}
		strStoreInfo += "<p><a href='javascript:window.print()'>Print this page</a></p>";
		strStoreInfo += "<div class='divider-grey'></div>";
		
		gbFoundCookie = fncGetCookie();
		if(gbFoundCookie)
			{
			if(storeNumber == strStoreNumber)
				{
		      strStoreInfo += "<h3>This is my preferred store</h3>";
				}
			else
				{
			  strStoreInfo += "<h3><a href='javascript:fncSetCookie()'>Make this my preferred store</a></h3>";
				}
			}
		else
			{
	      strStoreInfo += "<h3><a href='javascript:fncSetCookie()'>Make this my preferred store</a></h3>";
			}
		strStoreInfo += "<p align='right'><a href='javascript:void(0)' onmouseover='Tip(\"<strong>Why should I make this my preferred store?</strong><p>The store you choose as your preferred store will appear at the top of the list each<br />time you search the PetSmart store locator. This will make it easy for you to find:<ul><li>Money-saving promotions featured at that store</li><li>New services available in the store</li><li>Clear, specific driving directions to that store from wherever you are</li><li>Updated store hours</li></ul><p>\")' onmouseout='UnTip()' title='What is this?'>- What is this?</a></p>";

		document.getElementById('store-details').innerHTML = strStoreInfo;
		fncStoreServices(xmlStore);
		strStoreAddr = xmlAddress + ", " + xmlCityStZip;
		document.getElementById('end-address').value =  strStoreAddr;
		gStoreLat = xmlStore[0].getAttribute('lat')
		gStoreLng = xmlStore[0].getAttribute('lng');
		if(strStartAddr.length > 0 && strStoreNumber.length > 0)
			{
			fncDrivingDirections(true);			
			}
		else
			{
			fncDrivingDirections(false);			
			}
		})
	} 
	
function fncOpenInfoWindow(iMarker,iTab)
{
marker.openInfoWindowTabsHtml(gmarkers[iMarker].tabs,{selectedTab:iTab, suppressMapPan:true});
pt = gmarkers[iMarker].getPoint();
newpt = fncDetailPanInfoBox(pt);
//newpt = new GLatLng(pt.lat() + .02, pt.lng());
map.panTo(newpt);
}

function fncPrintDirections()
{
strURL = "http://maps.google.com/maps?f=d&saddr=" + strFrom + "&daddr=" + strTo + "&hl=en&pw=2";
window.open(strURL);
}

function fncStoreServices(xmlStore)
	{
	var strStoreServices;
	
//ad column
	strStoreServices = "<div id='ad-column'>";
	strStoreServices += "<a href='http://help.petsmart.com/subscribe/'><img src='/_images/email-signup-ad.jpg' alt='e-mail exclusives' /></a></div>";

	//services column header
	if(xmlStore[0].getAttribute('vet') == "V" || xmlStore[0].getAttribute('board') == "B" || xmlStore[0].getAttribute('daycamp') == "D" || xmlStore[0].getAttribute('train') == "T" || xmlStore[0].getAttribute('groom') == "G")
		{
		strStoreServices += "<div id='services-column'><h2>Store Services</h2>";
		}
	else
		strStoreServices += "<div id='services-column'>";
		
	//"Back to Map" and "Get Driving Directions"
	strStoreServicesTop = "<p><a href='/index.php?location=" + xmlStore[0].getAttribute('zipcode') + "&radius=20'>Back to Map</a>  |  <a href='javascript:fncOpenInfoWindow(0,2)'>Get Driving Directions</a></p>";
	document.getElementById('services-top').innerHTML = strStoreServicesTop;
	
	//services
		if(xmlStore[0].getAttribute('aquarium') == "Q")
			{
    		strStoreServices += "<div class='clear-floats'></div>";
			strStoreServices += "<img src='/_images/img-aquarium-services.jpg' alt='Aquarium Services' class='service-img' />";
			strStoreServices += "<div class='service-description'><h3>Aquarium Services:</h3>";
			strStoreServices += "<p>Aquarium services for your home or business include aquarium delivery and installation plus flexible maintenance plans. Vacation feeding and emergency care also available. Servicing the entire Dallas metro area. For more information, drop by this store, call (800) 477-7247 or learn more now.</p>";
			strStoreServices += "<p><a href='http://aquarium-services.petsmart.com/'>Aquarium Services</a></p></div>";
			strStoreServices += "<div class='service-info'><h3>Phone:</h3>";
			strStoreServices += "<p>(800) 477-7247"
			
			if(fncFixHours(xmlStore[0].getAttribute('Store_open')) == "00:00")
				{
					strStoreServices += "<p>Monday-Saturday: Closed<br />";
				}
			else
				{
				strStoreServices += "<p>Monday-Saturday: " + fncFixHours(xmlStore[0].getAttribute('Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Store_close')) + " p.m.<br />";
				}
			strStoreServices += "Sunday: ";
			if(xmlStore[0].getAttribute('Sunday_Store_open') == "00:00")
				{
				strStoreServices += "Closed<br />";
				}
			else
				{
            if(xmlStore[0].getAttribute('storenumber') == 399)
					strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
				else
					strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
				}
				strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
				}
				
	
	
	if(xmlStore[0].getAttribute('vet') == "V")
		{
		strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
		
		strStoreServices += "<img src='/_images/img-vet.jpg' alt='Veterinarian Services' class='service-img' />";
		strStoreServices += "<div class='service-description'><h3>Banfield Veterinary Services:</h3>";
		strStoreServices += "<p>Banfield, The Pet Hospital&reg; has full-service veterinary care providers with affordable wellness programs that provide ongoing preventive care. Banfield offers convenient evening and weekend hours.</p>";
		strStoreServices += "<p><a href='http://banfield.petsmart.com/'>Banfield Veterinary Services</a></p></div>";
		strStoreServices += "<div class='service-info'><h3>Phone:</h3>";
		
		strStoreServices += "<p><em>"
		strBanfieldPhone = xmlStore[0].getAttribute('Banfield_phone');
		
		if(strBanfieldPhone != "0")
			{
			strStoreServices += strBanfieldPhone;
			}
		else
			{
			strStoreServices += xmlStore[0].getAttribute('phone') + ", ext. 1";
			}
		
		strStoreServices += "</em></p><h3>Hours:</h3><em>";
			
   	strBanfieldMonHours   = xmlStore[0].getAttribute('Banfield_monday_hours');
	   strBanfieldTuesHours  = xmlStore[0].getAttribute('Banfield_tuesday_hours');
   	strBanfieldWedHours   = xmlStore[0].getAttribute('Banfield_wednesday_hours');
   	strBanfieldThursHours = xmlStore[0].getAttribute('Banfield_thursday_hours');
   	strBanfieldFriHours   = xmlStore[0].getAttribute('Banfield_friday_hours');
   	strBanfieldSatHours   = xmlStore[0].getAttribute('Banfield_saturday_hours');
   	strBanfieldSunHours   = xmlStore[0].getAttribute('Banfield_sunday_hours');
		
   	strBanfieldMonHours   = strBanfieldMonHours.replace("AM","a.m.");
   	strBanfieldMonHours   = strBanfieldMonHours.replace("PM","p.m.");
	   strBanfieldTuesHours  = strBanfieldTuesHours.replace("AM","a.m.");
	   strBanfieldTuesHours  = strBanfieldTuesHours.replace("PM","p.m.");
   	strBanfieldWedHours   = strBanfieldWedHours.replace("AM","a.m.");
   	strBanfieldWedHours   = strBanfieldWedHours.replace("PM","p.m.");
   	strBanfieldThursHours = strBanfieldThursHours.replace("AM","a.m.");
   	strBanfieldThursHours = strBanfieldThursHours.replace("PM","p.m.");
   	strBanfieldFriHours   = strBanfieldFriHours.replace("AM", "a.m.");
   	strBanfieldFriHours   = strBanfieldFriHours.replace("PM", "p.m.");
   	strBanfieldSatHours   = strBanfieldSatHours.replace("AM","a.m.");
   	strBanfieldSatHours   = strBanfieldSatHours.replace("PM","p.m.");
   	strBanfieldSunHours   = strBanfieldSunHours.replace("AM", "a.m.");
   	strBanfieldSunHours   = strBanfieldSunHours.replace("PM", "p.m.");
		
		if(strBanfieldMonHours.substring(0,1) == "0")
		   strBanfieldMonHours = " ";
		else
			{
			if(strBanfieldMonHours != "Closed")	
      		strBanfieldMonHours   = strBanfieldMonHours.substring(0,3) + "day" + strBanfieldMonHours.substring(3,strBanfieldMonHours.length )
			}
			
		if(strBanfieldTuesHours.substring(0,1) == "0")
		   strBanfieldtuesHours = " ";
		else
			{
			if(strBanfieldTuesHours != "Closed")	
      		strBanfieldTuesHours  = strBanfieldTuesHours.substring(0,3) + "sday" + strBanfieldTuesHours.substring(3,strBanfieldTuesHours.length )
			}
			
		if(strBanfieldWedHours.substring(0,1) == "0")
		   strBanfieldWedHours = " ";
		else
			{
			if(strBanfieldWedHours != "Closed")	
      		strBanfieldWedHours   = strBanfieldWedHours.substring(0,3) + "nesday" + strBanfieldWedHours.substring(3,strBanfieldWedHours.length )
			}
			
		if(strBanfieldThursHours.substring(0,1) == "0")
		   strBanfieldThursHours = " ";
		else
			{
			if(strBanfieldThursHours != "Closed")	
   		strBanfieldThursHours = strBanfieldThursHours.substring(0,3) + "rsday" + strBanfieldThursHours.substring(3,strBanfieldThursHours.length )
			}
			
		if(strBanfieldFriHours.substring(0,1) == "0")
		   strBanfieldFriHours = " ";
		else
			{
			if(strBanfieldFriHours != "Closed")	
   		strBanfieldFriHours   = strBanfieldFriHours.substring(0,3) + "day" + strBanfieldFriHours.substring(3,strBanfieldFriHours.length )
			}
			
		if(strBanfieldSatHours.substring(0,1) == "0")
		   strBanfieldSatHours = " ";
		else
			{
			if(strBanfieldSatHours != "Closed")	
     		strBanfieldSatHours   = strBanfieldSatHours.substring(0,3) + "urday" + strBanfieldSatHours.substring(3,strBanfieldSatHours.length )
			}
			
		if(strBanfieldSunHours.substring(0,1) == "0")
		   strBanfieldSunHours = " ";
		else
			{
			if(strBanfieldSunHours != "Closed")	
      		strBanfieldSunHours   = strBanfieldSunHours.substring(0,3) + "day" + strBanfieldSunHours.substring(3,strBanfieldSunHours.length )
			}
		
		if(strBanfieldMonHours.substring(0,1) == " ")
			{
   	   strStartDay = "";		
		   strEndDay = "";
			}
		else
			{
   	   strStartDay = "Monday";		
		   strEndDay = "Monday";
			
		//Monday
   	if(strBanfieldMonHours.substring(8,29) != strBanfieldTuesHours.substring(9,30))
		   {
			if(strBanfieldMonHours == "Closed")
			   {
				strStoreServices += strStartDay + ": " + strBanfieldMonHours + "<br />";
				}
			else
				{
     			strStoreServices += strBanfieldMonHours + "<br />";	
				}
			strStartDay = "Tuesday";
			}
   	strEndDay = "Tuesday";

      //Tuesday
   	if(strBanfieldTuesHours.substring(9,30) != strBanfieldWedHours.substring(11,32))
		   {
			if(strBanfieldTuesHours == "Closed")
			   {
				if(strEndDay == "Tuesday")
   				strStoreServices += strStartDay + ": " + strBanfieldTuesHours + "<br />";				
				else
   				strStoreServices += strStartDay + "-" + strEndDay + ": " + strBanfieldTuesHours + "<br />";
				}
			else
				{
				if(strStartDay != "Tuesday")
      			strStoreServices += strStartDay + "-" + strBanfieldTuesHours + "<br />";	
				else
      			strStoreServices += strBanfieldTuesHours + "<br />";	
				}
			strStartDay = "Wednesday";
			}
   	strEndDay = "Wednesday";
			
		//Wednesday
   	if(strBanfieldWedHours.substring(11,32) != strBanfieldThursHours.substring(10,31))
		   {
			if(strBanfieldWedHours == "Closed")
			   {
				if(strEndDay == "Wednesday")
   				strStoreServices += strStartDay + ": " + strBanfieldWedHours + "<br />";				
				else
   				strStoreServices += strStartDay + "-" + strEndDay + ": " + strBanfieldWedHours + "<br />";
				}
			else
				{
				if(strStartDay != "Wednesday")
      			strStoreServices += strStartDay + "-" + strBanfieldWedHours + "<br />";	
				else
      			strStoreServices += strBanfieldWedHours + "<br />";	
				}
			strStartDay = "Thursday";
			}
		strEndDay = "Thursday";
		
		//Thursday
   	if(strBanfieldThursHours.substring(10,31) != strBanfieldFriHours.substring(8,29))
		   {
			if(strBanfieldThursHours == "Closed")
			   {
				if(strStartDay != "Thursday")
   				strStoreServices += strStartDay + ": " + strBanfieldThursHours + "<br />";
				else
   				strStoreServices += strStartDay + "-" + strEndDay + ": " + strBanfieldThursHours + "<br />";
				}
			else
				{
				if(strStartDay != "Thursday")
      			strStoreServices += strStartDay + "-" + strBanfieldThursHours + "<br />";	
				else
      			strStoreServices += strBanfieldThursHours + "<br />";	
				}
			strStartDay = "Friday";
			}
		strEndDay = "Friday";

      //friday
   	if(strBanfieldFriHours.substring(8,29) != strBanfieldSatHours.substring(10,31))
		   {
			if(strBanfieldFriHours == "Closed")
			   {
				if(strStartDay != "Friday")
   				strStoreServices += strStartDay + ": " + strBanfieldFriHours + "<br />";
				else
   				strStoreServices += strStartDay + "-" + strEndDay + ": " + strBanfieldFriHours + "<br />";
				}
			else
				{
				if(strStartDay != "Friday")
      			strStoreServices += strStartDay + "-" + strBanfieldFriHours + "<br />";	
				else
      			strStoreServices += strBanfieldFriHours + "<br />";	
				}
			strStartDay = "Saturday";
			}
		strEndDay = "Saturday";

      //Saturday / sunday
   	if(strBanfieldSatHours.substring(10,31) != strBanfieldSunHours.substring(8,29))
		   {
			if(strBanfieldSatHours == "Closed")
			   {
				if(strStartDay != "Friday")
               strStoreServices += strStartDay + ": " + strBanfieldSatHours + "<br />";
            else
               strStoreServices += strStartDay + "-" + strEndDay + ": " + strBanfieldSatHours + "<br />";
				}
			else
				{
				if(strStartDay != "Saturday")
				   strStoreServices += strStartDay + "-" + strBanfieldSatHours + "<br />";	
				else
				   strStoreServices += strBanfieldSatHours + "<br />";	
				}
			if(strBanfieldSunHours != "Closed")
     			strStoreServices += strBanfieldSunHours + "<br />";
			else
     			strStoreServices += "Sunday: " + strBanfieldSunHours + "<br />";
			}
		else
			{
  			strStoreServices += strStartDay + "-" +  strBanfieldSunHours + "<br />";
			}
			}
		strStoreServices += "</em><em>Please call store to confirm hours.</em></p></div>";
		}

	//  PetsHotel_open   PetsHotel_close
	if(xmlStore[0].getAttribute('board') == "B")
		{
		strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
		strStoreServices += "<img src='/_images/img-petshotel.jpg' alt='PetsHotel' class='service-img' />";
		strStoreServices += "<div class='service-description'><h3>PetsHotel:</h3>";
		strStoreServices += "<p>At PetSmart, we understand your special bond because we're pet parents, too. That's why we created PetSmart PetsHotel - a revolutionary alternative in day and overnight care.</p>";
		strStoreServices += "<p><a href='http://petshotel.petsmart.com/'>PetsHotel Services</a></p></div><div class='service-info'>";
		strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone');
		if(xmlStore[0].getAttribute('Phone_Board_Ext') != "-")
			strStoreServices += ", ext. " + xmlStore[0].getAttribute('Phone_Board_Ext') + "</p>";
		else
			strStoreServices += ", ext. 6</p>";	
//		strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone') + " ext. 6</p>";
		strStoreServices += "<h3>Hours:</h3>";
			if(fncFixHours(xmlStore[0].getAttribute('Store_open')) == "00:00")
				{
				strStoreServices += "<p>Monday-Saturday: Closed<br />";
				}
			else
				{
			strStoreServices += "<p>Monday-Saturday: " + fncFixHours(xmlStore[0].getAttribute('PetsHotel_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('PetsHotel_close')) + " p.m.<br />";
				}
		strStoreServices += "Sunday: " 
		if(xmlStore[0].getAttribute('PetsHotel_Sunday_open') == "00:00")
			{
			strStoreServices += "Closed<br />";
			}
		else
			{
         if(xmlStore[0].getAttribute('storenumber') == 399)
   			strStoreServices += fncFixHours(xmlStore[0].getAttribute('PetsHotel_Sunday_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('PetsHotel_Sunday_close')) + " p.m.<br />";
			else
   			strStoreServices += fncFixHours(xmlStore[0].getAttribute('PetsHotel_Sunday_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('PetsHotel_Sunday_close')) + " p.m.<br />";
			}
		strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
		}

		// Day camp
	if(xmlStore[0].getAttribute('daycamp') == "D")
		{
		strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
		strStoreServices += "<img src='/_images/img-doggie-day-camp.jpg' alt='Doggie Day Camp' class='service-img' />";
		strStoreServices += "<div class='service-description'><h3>Doggie Day Camp:</h3>";
		strStoreServices += "<p>PetSmart Doggie Day Camp is a place for your pooch to enjoy a fun-filled day of play and exercise when you can't be there. And, for every 10 days of camp or daycare in a month, you'll get one session free; ask an associate for details.</p>";
		strStoreServices += "<p><a href='http://petshotel.petsmart.com/doggie-day-camp/index.shtml'>Doggie Day Camp Services</a></p></div>";
		strStoreServices += "<div class='service-info'>";
		strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone');
		if(xmlStore[0].getAttribute('Phone_Daycamp_Ext') != "-")
			strStoreServices += ", ext. " + xmlStore[0].getAttribute('Phone_Daycamp_Ext');
		else
			strStoreServices += ", ext. 5</p>";		
		//strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone') + ", ext. 5</p>";
		strStoreServices += "<h3>Hours:</h3><p>Monday-Saturday: ";
		
		
		if(xmlStore[0].getAttribute('Store_open') == "00:00")
			{
			strStoreServices += "Closed<br />";
			}
		else
			{
		strStoreServices += fncFixHours(xmlStore[0].getAttribute('Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Store_close')) + " p.m.<br />";
			}
				
		strStoreServices += "Sunday: ";
		if(xmlStore[0].getAttribute('Sunday_Store_open') == "00:00")
			{
			strStoreServices += "Closed<br />";
			}
		else
			{
         if(xmlStore[0].getAttribute('storenumber') == 399)
   			strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
			else
	   		strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
			}
		strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
		}

		//training
		if(xmlStore[0].getAttribute('train') == "T")
			{
			strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
			strStoreServices += "<img src='/_images/img-training.jpg' alt='Training' class='service-img' />";
			strStoreServices += "<div class='service-description'><h3>Training:</h3>";
			strStoreServices += "<p>Through in-store training and positive reinforcement, PetSmart Accredited Pet Instructors will teach you how to achieve consistent behaviors from your pet, despite distractions. If you're not fully satisfied, you can take the class again for free - that's our SmartPet PromiseSM.</p>";
			strStoreServices += "<p><a href='http://training.petsmart.com/'>Training Services</a></p></div>";
			strStoreServices += "<div class='service-info'>";
			
		strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone');
		if(xmlStore[0].getAttribute('Phone_Train_Ext') != "-")
			strStoreServices += ", ext. " + xmlStore[0].getAttribute('Phone_Train_Ext');
		else
			strStoreServices += ", ext. 3</p>";
		//strStoreServices += "<h3>Phone:</h3><p>" + xmlStore[0].getAttribute('phone') + ", ext. 3</p>";
			strStoreServices += "<h3>Hours:</h3>";
			if(fncFixHours(xmlStore[0].getAttribute('Store_open')) == "00:00")
				{
					strStoreServices += "<p>Monday-Saturday: Closed<br />";
				}
			else
				{
			strStoreServices += "<p>Monday-Saturday: " + fncFixHours(xmlStore[0].getAttribute('Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Store_close')) + " p.m.<br />";
				}
			strStoreServices += "Sunday: ";
		if(xmlStore[0].getAttribute('Sunday_Store_open') == "00:00")
			{
			strStoreServices += "Closed<br />";
			}
		else
			{
         if(xmlStore[0].getAttribute('storenumber') == 399)
   			strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
			else
   			strStoreServices += fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_close')) + " p.m.<br />";
			}
			strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
			}

		//Grooming
		if(xmlStore[0].getAttribute('groom') == "G")
			{
			strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
			strStoreServices += "<img src='/_images/img-grooming.jpg' alt='Grooming' class='service-img' />";
			strStoreServices += "<div class='service-description'><h3>Grooming:</h3>";
			strStoreServices += "<p>The caring professionals at PetSmart Grooming Salons are available seven days a week and provide an array of services to ensure your pet is happy, healthy and looks great.</p>";
			strStoreServices += "<p><a href='http://grooming.petsmart.com/'>Grooming Services</a></p></div>";
			strStoreServices += "<div class='service-info'><h3>Phone:</h3>";
			
			strStoreServices += "<p>" + xmlStore[0].getAttribute('phone') 
			if(xmlStore[0].getAttribute('Phone_Groom_Ext') != "-")
				strStoreServices += ", ext. " + xmlStore[0].getAttribute('Phone_Groom_Ext');
			else
				strStoreServices += ", ext. 2</p>";
//			strStoreServices += "<p>" + xmlStore[0].getAttribute('phone') + ", ext. 4</p>";
			strStoreServices += "<h3>Hours:</h3>";
			
			if(fncFixHours(xmlStore[0].getAttribute('Store_open')) == "00:00")
				{
					strStoreServices += "<p>Monday-Saturday: Closed<br />";
				}
			else
				{
				strStoreServices += "<p>Monday-Saturday: " + fncFixHours(xmlStore[0].getAttribute('Grooming_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Grooming_close')) + " p.m.<br />";
				}
			strStoreServices += "Sunday: ";
			if(xmlStore[0].getAttribute('Grooming_Sunday_open') == "00:00")
				{
				strStoreServices += "Closed<br />";
				}
			else
				{
            if(xmlStore[0].getAttribute('storenumber') == 399)
   				strStoreServices += fncFixHours(xmlStore[0].getAttribute('Grooming_Sunday_open')) + " p.m. - " + fncFixHours(xmlStore[0].getAttribute('Grooming_Sunday_close')) + " p.m.<br />";
				else
   				strStoreServices += fncFixHours(xmlStore[0].getAttribute('Grooming_Sunday_open')) + " a.m. - " + fncFixHours(xmlStore[0].getAttribute('Grooming_Sunday_close')) + " p.m.<br />";
				}
				strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
				}
			
/*   Photo server was discontinued, but here's the code if they ever start it up again.
		//Photography
		if(xmlStore[0].getAttribute('photo') == "P")
			{
			strStoreServices += "<div class='clear-floats'></div><div class='divider-grey'></div>";
			strStoreServices += "<img src='/_images/img-pet-photography.jpg' alt='Photography='service-img' />";
			strStoreServices += "<div class='service-description'><h3>Grooming:</h3>";
			strStoreServices += "<p>PetSmart Pet Photography is the professional portrait service you've been waiting for. Conveniently located inside select PetSmart&reg; PetsHotel&reg; locations, PetSmart Pet Photography will help you capture all the special moments that earmark your pet's life. We deliver professional-quality photos you'll want to show off, share and cherish for years to come.</p>";
			strStoreServices += "<p><a href='http://promotions.petsmart.com/landing/pet-photography/'>Photography Services</a></p></div>";
			strStoreServices += "<div class='service-info'><h3>Phone:</h3>";
			strStoreServices += "<p>" + xmlStore[0].getAttribute('phone') + ", ext. 4</p>";
			strStoreServices += "<h3>Hours:</h3>";
			strStoreServices += "<p>Monday-Saturday: " + fncFixHours(xmlStore[0].getAttribute('Store_open')) + " a.m. - " + xmlStore[0].getAttribute('Store_close') + " p.m.<br />";
			strStoreServices += "Sunday: " + fncFixHours(xmlStore[0].getAttribute('Sunday_Store_open')) + " a.m. - " + xmlStore[0].getAttribute('Sunday_Store_close') + " p.m.<br />";
			strStoreServices += "<em>Please call store to confirm hours.</em></p></div>";
			}
*/
		//Adoptions
		if(xmlStore[0].getAttribute('adopt') == "A")
			{
			strStoreServices += "<div class='clear-floats'></div><br /><br />";
			strStoreServices += "<h2>Adoption Agencies</h2>";
			strStoreServices += "<p>For agency availability, please contact the PetSmart location.</p>";
			if(xmlStore[0].getAttribute('agencies') != null)
				{
				strAgencies = xmlStore[0].getAttribute('agencies');
				if(strAgencies.length > 0)
					{
					iStart = 0;
					while(iStart < strAgencies.length)
						{
						iEnd = strAgencies.indexOf("|",iStart);
						if(iEnd == - 1)
						   break;
						strStoreServices += "<p class='adoption-agency-result'>" + strAgencies.substring(iStart,iEnd) + "</p>";
						iStart = iEnd + 1;
						}
					if(iStart < strAgencies.length)
						strStoreServices += "<p class='adoption-agency-result'>" + strAgencies.substring(iStart,strAgencies.length) + "</p>";
					
					}
				}
			strStoreServices += "</div>";
			}

strStoreServices += "</div>";


	strStoreServices += "<div class='clear-floats'></div>";
	document.getElementById('services-middle').innerHTML = strStoreServices;		
	}

function pause(numberMillis) 
	{
   var now = new Date();
   var exitTime = now.getTime() + numberMillis;
   while (true) 
		{
      now = new Date();
      if (now.getTime() > exitTime)
	      return;
      }
   }
