	function launchMap(a) {
		popWin = window.open("http:\/\/maps.tommybahama.com\/popup_map.html?" + a, "map", "width=610,height=480,scrollbars=no,status=no,toolbar=no,location=no,resizable=yes");
		popWin.focus(); 
	}
	function showTheMap(a,c,s,z) {
		//showModal('index.html','10','10');
		var divMap = document.getElementById('divMap');
		divMap.style.left='100px';
		divMap.style.top='-100px';
		divMap.style.display='block';
		divMap.style.zIndex=1100;
		loadMap(a,c,s,z);
	}

    function padDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0';
            } 
        } 
        return pd + n.toString(); 
    } 


	function  resetZip(f) {
		f.zip.value = '';
	}

	function resetCity(f) {
		if (f.zip.value.length > 0){ 
			f.city.value = '';
			f.state.selectedIndex = 0;		
		}
	}
	
	function formatResponse(request, xml) {
		var divWrapperResults = document.getElementById('divWrapperResults');
		var divResults = document.getElementById('divResults');
		var divLoading = document.getElementById('divLoading');
		var divSplash = document.getElementById('divSplash');
		var x;
		var temp;
		var strRequest = request.toString();
		var strHTML = '';
		var strTableHead = '';
		//alert(xml.getElementsByTagName('city'));
		var storeNodes = xml.getElementsByTagName('store');
		var cityNodes =  xml.getElementsByTagName('city');
		var locationNode;
		var mallNode;
		var address1Node;
		var address2Node;
		var cityNode;
		var stateNode;
		var zipNode;
		var phoneNode;
		var sortNode;
		var strMapQuery;
		var intCurrentSortId = null;
		var blnPartnerHeader = 0;
		var blnTBHeader = 0;
		var intCount = 1;
		
		var strEscapeClause = 'j' + 'avascrip' + 't:showModal' + '(';
		
		
		if (storeNodes.length > 0) {
			for (x = 0; x < storeNodes.length; x++ ) {
				
				locationNode =  storeNodes[x].getElementsByTagName('location_name');
				mallNode =  storeNodes[x].getElementsByTagName('mall_name');
				sortNode =  storeNodes[x].getElementsByTagName('location_sort_id');
				address1Node =  storeNodes[x].getElementsByTagName('address_1');
				address2Node =  storeNodes[x].getElementsByTagName('address_2');
				cityNode = storeNodes[x].getElementsByTagName('city');
				stateNode = storeNodes[x].getElementsByTagName('state');
				zipNode = storeNodes[x].getElementsByTagName('zip_code');
				phoneNode = storeNodes[x].getElementsByTagName('phone');
				
				
				strMapQuery = 'location=' + encodeChars(locationNode.item(0).firstChild.nodeValue) + '&address1=' + address1Node.item(0).firstChild.nodeValue + '&city=' + cityNode.item(0).firstChild.nodeValue + '&state=' + stateNode.item(0).firstChild.nodeValue + '&zip=' + zipNode.item(0).firstChild.nodeValue;

				if ((address1Node.item(0).firstChild.nodeValue.indexOf("UNIVERSITY VILLAGE MALL") > -1) && (zipNode.item(0).firstChild.nodeValue == "98105")) {
					strMapQuery += "&ll=47.66189012941084,-122.29956865310669";
				}
				if ((address1Node.item(0).firstChild.nodeValue.indexOf("11506 CENTURY OAKS TERRACE") > -1) && (zipNode.item(0).firstChild.nodeValue == "78758")) {
					strMapQuery += "&ll=30.39923368095944,-97.72501945495605";
				}
				if ((address1Node.item(0).firstChild.nodeValue.indexOf("10177 N. KINGS HIGHWAY") > -1) && (zipNode.item(0).firstChild.nodeValue == "29577")) {
					strMapQuery += "&ll=33.793087,-78.765277";
				}
				if ((address1Node.item(0).firstChild.nodeValue.indexOf("1 MOHEGAN SUN BLVD") > -1) && (zipNode.item(0).firstChild.nodeValue == "6382")) {
					strMapQuery += "&ll=41.49257087656359,-72.09619045257568";
				}
				if ((address1Node.item(0).firstChild.nodeValue.indexOf("1 ATLANTIC OCEAN") > -1) && (zipNode.item(0).firstChild.nodeValue == "8401")) {
					strMapQuery += "&ll=39.35381,-074.43421";
				}
				if ((address1Node.item(0).firstChild.nodeValue.indexOf("VILLAGE OF MERRICK PARK") > -1) && (zipNode.item(0).firstChild.nodeValue == "33146")) {
					strMapQuery += "&ll=25.732138,-80.261095";
				}

				if (x==0) {
					if (sortNode.item(0).firstChild) {
						if (sortNode.item(0).firstChild.nodeValue == '1') {
							strHTML += '<div class="header_listing">TOMMY BAHAMA STORES<\/div>';
							blnTBHeader = 1;
						} else if  (sortNode.item(0).firstChild.nodeValue == '2') {
								strHTML += '<div class="header_listing">TOMMY BAHAMA PARTNERS IN PARADISE<\/div>';						
						} 
						blnPartnerHeader = 1;
					} else {
						strHTML += '<div class="header_listing">TOMMY BAHAMA PARTNERS<\/div>';
					}

					strHTML += strTableHead; // start the HTML table
					
				} else {
					if (sortNode.item(0).firstChild) {
						if  ((sortNode.item(0).firstChild.nodeValue == '2') && (intCurrentSortId != sortNode.item(0).firstChild.nodeValue)) {
							if (intCount%2==0) {
								strHTML += '<\/div>';
							}
							strHTML += '<div class="listing_rule"><\/div><div class="header_listing">TOMMY BAHAMA PARTNERS IN PARADISE<\/div>';
							intCount = 1;			
						}
					} else {
						if (intCurrentSortId != null) {
							if (intCount%2==0) {
								strHTML += '<\/div>';
							}
							strHTML += '<div class="listing_rule"><\/div><div class="header_listing">TOMMY BAHAMA PARTNERS<\/div>';
							intCount = 1;
						}
					}

				}
				
				if (intCount%2==1) {
					strHTML += '<div class="listing"><div class="listing_leftcol">';
				} else {
					strHTML +=  '<div class="listing_rightcol">';
				}
				
				strHTML += '<div style="margin-top:12px;">';
				strHTML += '<b>' + locationNode.item(0).firstChild.nodeValue + '<\/b>';
				if (mallNode.item(0).firstChild) {
					strHTML += '	<br \/><b>' + mallNode.item(0).firstChild.nodeValue + '<\/b>';
				}

				strHTML += '	<br \/>' + address1Node.item(0).firstChild.nodeValue;
				if (address2Node.item(0).firstChild) {
					strHTML += '	<br \/>' + address2Node.item(0).firstChild.nodeValue;
				}
				
				strHTML += '	<br \/>' + cityNode.item(0).firstChild.nodeValue + ', ' + stateNode.item(0).firstChild.nodeValue + ' ' + padDigits(zipNode.item(0).firstChild.nodeValue, 5);
				if (phoneNode.item(0).firstChild) {
					strHTML += '	<br \/>' + phoneNode.item(0).firstChild.nodeValue;
				}				
				strHTML += '<br />	<div class="listing_button"><a href="javascript:launchMap(\'' + escape(strMapQuery) + '\');"><img src="\/media\/TB001\/images\/static\/stores_restaurants\/button_view_map.jpg" border="0" alt="View Map" \/><\/a><\/div>';
				strHTML += '<\/div>';
				
				if (intCount%2==1) {
					strHTML += '<\/div>';
				} else {
					strHTML += '<\/div><\/div>';
				}
				
				if (sortNode.item(0).firstChild) {
					intCurrentSortId = sortNode.item(0).firstChild.nodeValue;
				} else {
					intCurrentSortId = null;
				}
				
			
				//strHTML += x + ':' + storeNodes[x].nodeValue + '<br>';
				//alert(cityNodes[1].nodeValue);
				/////////////////////strHTML += '</div>';
				intCount ++;
			}
		} else {
//			strHTML += '<tr>';
			strHTML += 'Sorry, no results were found for your search.';
//			strHTML += '<\/tr>';
		}
//		strHTML += '<\/table>';
//		strHTML += '<\/div>';
		
		try {
			divSplash.style.display = 'none';
		} catch (e) {
			// new results page doesn't have a divSplash
		}

		divWrapperResults.style.display = 'block';
		divLoading.style.display = 'none';
		divResults.innerHTML = strHTML;
		document.body.style.cursor = 'default';
		
	}
	
	
	// this is called by the page; checks for querystring, and formats it for search
	function searchStores() {
	
		var d = '';
		var z = '';
		var c = '';
		var s = '';
		var p = '';
		var spanQuery = document.getElementById('spanQuery');
		var strQueryString = document.location.search.replace("?", "");
		var arrNameValuePairs;
		var objLoading = document.getElementById('divLoading');
		
		if (strQueryString.length > 0) {
			arrNameValuePairs = strQueryString.split("&");
			for (i=0;i<arrNameValuePairs.length;i++){
				arrQSPair = arrNameValuePairs[i].split("=");
				strQSName = arrQSPair[0].toString();
				strQSValue = arrQSPair[1].toString();
				if (strQSName=='distance') {
					d = strQSValue;
				}
				if (strQSName=='selRadius') {
					d = strQSValue;
				}
				if (strQSName=='zip') {
					z = strQSValue;
				}
				if (strQSName=='city') {
					c = strQSValue;
					c = c.replace(',', '');
				}
				if (strQSName=='state') {
					s = strQSValue;
				}
				if (strQSName=='product_type') {
					p = strQSValue;
				}
				if (strQSName=='txtCityZip') {
					if (isNumeric(trim(arrQSPair[1]))) {
						z = trim(strQSValue);
					} else {
						c = trim(strQSValue);
						c = c.replace(',', '');
					}
				}
			}

			if ((c.length > 0) || (z.length > 0)) {
				objLoading.style.display = 'block';
				var product_type = "-1";
				var strCityInput = c;
				
				// The Fort Lauderdale fix: in the database, it's "Fort".  So you want the input to be that.
				strCityInput = strCityInput.replace("Ft ", "Fort ");
				strCityInput = strCityInput.replace("Ft. ", "Fort ");
				strCityInput = strCityInput.replace("ft ", "Fort ");
				strCityInput = strCityInput.replace("ft. ", "Fort ");
				
				document.body.style.cursor = 'wait';
				
				for (i=0; i<p.length; i++) {
					if (p[i].checked) {
						product_type = p[i].value;
					}
				}
	
				spanQuery.innerHTML = 'You searched for "' + c + ' ' + z + '" within ' + d + ' miles'; 
	
				var strURL = '/cgi-bin/maploc.pl';
				var strQueryString = 'producttype=' + product_type + '&zip=' + z + '&distance=' + d + '&state=' + s + '&city=' + escape(strCityInput);
				var strFullURL = strURL + '?' + strQueryString;
				
				// special handling of Mexico zip codes and cities:
				var objMexicoXML;
				if ((z=='23410') || (strCityInput.toLowerCase()=='cabo')) {
					showMexico('23410');
				} else if ((z=='77500') || (strCityInput.toLowerCase()=='cancun')) {
					showMexico('77500');
				} else if ((z=='77710') || (strCityInput.toLowerCase()=='playa del carmen')) {
					showMexico('77710');
				} else {
					//alert(strCityInput.toLowerCase());
					//new Ajax(strFullURL, {method: 'get', onComplete:formatResponse}).request();
					//new mootools call to replace Ajax class  in MT v1.0
					var x = new Request({
					url: strFullURL,
					method: 'get',
					onComplete:formatResponse
					}).send();
					
					
					
				}
			
				//prompt('url',strFullURL);
				//http://www.tommybahama.com/cgi-bin/maploc.pl?producttype=-1&state=&city=seattle&zip=&distance=50
				//http://maps.tommybahama.com/storelocator.jsp?producttype=-1&state=&city=seattle&zip=&distance=50
				

			} else { // no query; show search form.
				
			}
			
		}	
	}
	
	// this is called when you click the search "go" button
	function submitStoreSearch() {

		var objTextInput = document.getElementById('txtCityZip');
		objTextInput.value = objTextInput.value.replace(',', '');
		var objRadius = document.getElementById('selRadius');
		
		location.href = '/TBG/Stores_Restaurants/Locator_Results.jsp?txtCityZip=' + objTextInput.value + '&selRadius=' + objRadius.options[objRadius.selectedIndex].value;
	}
	
	function resetStoreSearch() {
		var divWrapperResults = document.getElementById('divWrapperResults');
		var divResults = document.getElementById('divResults');
		var divLoading = document.getElementById('divLoading');
		var divSplash = document.getElementById('divSplash');
		divSplash.style.display = 'block';
		divWrapperResults.style.display = 'none';
		divLoading.style.display = 'none';
		divResults.innerHTML = '';
	}
	
	function submitPartnerSearch() {
		var objTextInput = document.getElementById('txtCityZip');
		objTextInput.value = objTextInput.value.replace(',', '');
		var objRadius = document.getElementById('selRadius');
		if ((objTextInput.value=='City or Zip Code') || (objTextInput.value=='')) {
			alert('Please enter a city or zip code to search for.');
		} else {
			location.href = '/TBG/Stores_Restaurants/Locator.jsp?city=' + objTextInput.value + '&distance=' + objRadius.options[objRadius.selectedIndex].value;
		}
	}
	
	function inputFocus(e,strDefaultText) {
		if (e.value==strDefaultText) {
			e.value = '';
		}
	}
	
	function inputBlur(e,strDefaultText) {
		if (e.value=='') {
			e.value = strDefaultText;
		}
	}
	
	function checkEnter(e){ //e is event object passed from function invocation
		var characterCode; //literal character code will be stored in this variable
		
		if (e && e.which) { //if which property of event object is supported (NN4)
			e = e;
			characterCode = e.which; //character code is contained in NN4's which property
		} else {
			e = event;
			characterCode = e.keyCode //character code is contained in IE's keyCode property
		}
		if (characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
			submitStoreSearch(); //submit the form
			return false;
		} else {
			return true;
		}
	}
	
	function showMexico(z) {
		var arrMexico = $$('.mexico');
		for (i=0;i<arrMexico.length;i++) {
			arrMexico[i].style.display = 'none';
		}
		var objMexico = document.getElementById('divMexico');
		var objShowMe = document.getElementById('divMexico_'+z);
		var divWrapperResults = document.getElementById('divWrapperResults');
		var divResults = document.getElementById('divResults');
		var divLoading = document.getElementById('divLoading');
		var divSplash = document.getElementById('divSplash');
		try {
			divSplash.style.display = 'none';
		} catch (e) {
			// new results page doesn't have a divSplash
		}
		divWrapperResults.style.display = 'block';
		divLoading.style.display = 'none';
		//divResults.innerHTML = objMexico.innerHTML;
		objMexico.style.display = 'block';
		objShowMe.style.display = 'block';
		document.body.style.cursor = 'default';
	}

