	var geocoder;
	var addresses = new Array();
	
			var shops = null;
		

	function trim(str)
	{
		if ((str != null) && (str.length > 0))
		{
			return str.replace(/^\s*|\s*$/g,"");
		}

		return "";
	}
	
	function sendMessage(fe, strValue) 
	{
		var code;
		var e = fe || window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if (code == 13)
		{
			Chat.submit(strValue);
		}
	}

	function sendZip(fe, strValue) 
	{
		var code;
		var e = fe || window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if (code == 13)
		{
			getshops(strValue);
		}
	}

	function getshops(zip)
	{
		zip = trim(zip);
		
		if ((zip.length != 5) && (zip.length != 6))
		{
			document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
			'Please enter a 5 digit zip code for the US or a 6 character postal code for Canada.' + ' </p> ';
		}
		else
		{
			document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
			'Please wait while we look for shops in your area...' + ' </p> ';

			document.getElementById("getshops").disabled = true;

			var url = 'inc/get-shops.php';
			var params = 'zip=' + zip;
			var loader = new net.ContentLoader(url, updateshops, null, "POST", params);
		}
	}

	function is_numeric(strString)
	{
	    //  check for valid numeric strings	
		var strValidChars = "0123456789";
		var strChar;
		var blnResult = true;

		if (strString.length == 0) return false;

		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
		{
			strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1)
			{
				blnResult = false;
			}
		}
	   return blnResult;
	}

	function updateshops()
	{
		try		
		{
			loadNewShops(this.req.getResponseHeader("ZipShops"));
			
			// name of metro if it exists
			var metro = this.req.getResponseHeader("Metro");
			metro = (metro == null) ? '': metro;

			if (metro == '')
			{
				document.getElementById("bestrad").innerHTML = '';
				document.getElementById("chatheadline").innerHTML = '';
			}
			else
			{
				document.getElementById("bestrad").innerHTML = 'Same Day Delivery or Pickup in the ' + metro + ' Area!';
				document.getElementById("chatheadline").innerHTML = 
				'<img src="http://www.radiator.com/inc/localheadline.php?text=' + metro + '&config=border" /><br />'
				;

			}
			
			document.getElementById("chatter").style.background = 'url("../inc/chatimage.php?area=' + metro + '") no-repeat';
			

			// zip input element
			var zipInputElt = document.getElementById("getshops");
			zipInputElt.disabled = false;
			zipInputElt.value = ' Zip Code ';
		}
		catch(e)
		{
		}
	}

	function load() 
	{
		if (GBrowserIsCompatible())
		{
			geocoder = new GClientGeocoder();
			
			
			document.getElementById("bestrad").innerHTML = '';
			document.getElementById("chatheadline").innerHTML = '';

			
			
			if (shops != null)
			{

				var myhtml = '';
				for(i = 0; i < shops.streets.length; i++)
				{
					myhtml += ' <p class="shopinfo"> ' + shops.streets[i].replace(/^(\s*\d+\s)*/g, '') + ', <br />'
					+ shops.cities[i] + ', ' + shops.states[i] + ' ' + shops.zips[i] + ' </p> ';
				}
				if (myhtml != '')
				{
					document.getElementById("top3shops").innerHTML = myhtml;
				}
				else
				{
					document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
					'Sorry, no shops found in this Zip Code. Please try another Zip Code.' + ' </p> ';
				}
				
				// for (i = 0; i < shops.shopaddresses.length ; i++ )
				// {
				// 	geocoder.getLocations(shops.shopaddresses[i], loadNewAddresses); 			
				// }
			}
			else
			{
				document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
				'Please enter your Zip Code below to find shops in your area.' + ' </p> ';
			}			
		}
    }

	function loadNewShops(zipshops)
	{
		if (zipshops)
		{
			// var geocoder = new GClientGeocoder();
			// addresses = new Array();
			eval('var shops = ' + zipshops);

			var myhtml = '';
			for(i = 0; i < shops.streets.length; i++)
			{
				myhtml += ' <p class="shopinfo"> ' + shops.streets[i].replace(/^(\s*\d+\s)*/g, '') + ', <br />'
				+ shops.cities[i] + ', ' + shops.states[i] + ' ' + shops.zips[i] + ' </p>';
			}
			if (myhtml != '')
			{
				document.getElementById("top3shops").innerHTML = myhtml;
			}
			else
			{
				document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
				'Sorry, no shops found in this Zip Code. Please try another Zip Code.' + ' </p> ';
			}

			// for(i = 0; i < shops.shopaddresses.length; i++)
			// {
			// 	geocoder.getLocations(shops.shopaddresses[i], loadNewAddresses); 			
			// }
		}
		else
		{
			document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
			'Sorry, no shops found in this Zip Code. Please try another Zip Code.' + ' </p> ';
		}
		
	}
	
	function loadNewAddresses(response)
	{
		if (!response || response.Status.code != 200) 
		{
		} 
		else 
		{
			try
			{
				place = response.Placemark[0];
				addresses[addresses.length] = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName.replace(/^(\s*\d+\s)*/g, '') + ', <br />'			
					+ place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName + ', ' 
					+ place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName + ' '
					+ place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;

			}
			catch (e)
			{
				var addrs = response.Placemark[0].address.split(',');
				alert(response.Placemark[0].address);
				// addresses[addresses.length] = addrs[0] + ', <br />' + (addrs[1] + addrs[2]).substring(0, (addrs[1] + addrs[2]).length - 4);
 			}			
		}

		var myhtml = '';
		for (i = 0; i < addresses.length; i++ )
		{
			myhtml += ' <p class="shopinfo"> ' + addresses[i] + ' </p> ';
		}
		if (myhtml != '')
		{
			document.getElementById("top3shops").innerHTML = myhtml;
		}
		else
		{
			document.getElementById("top3shops").innerHTML = ' <p class="shopinfo"> ' +
			'Sorry, no shops found in this Zip Code. Please try another Zip Code.' + ' </p> ';
		}
	}
