function locatestore(locationdata, radius){
	var AJAX = {
		url: 'ajax/findstore.mhtml',
		content: {
			'searchterm':locationdata,
			'radius':radius
		},
		handleAs:"json-comment-filtered",
		load: function(response){
			var source;
			var numstores=0;
			if(typeof(response['error'])!='undefined'&&response['error']!=''){
				source = "<table><tr><td><center><u><b>Too Many Searches!</b></u></center>We value our dealers' privacy, and have committed to protecting our dealer database from unscrupulous hackers. One of the ways we do this is to limit the number of searches that can be performed per day per person.  Although we're sure you aren't a hacker, it seems that our security system has been a wee bit too sensitive. We would love to find a dealer near you, so just give us a call or email us from the \"Contact Us\" link and we'll get you all set up!  Thank you for your interest in Papart&eacute; and we look forward to hearing from you!</td></tr></table>";
			}else{
				source = "<table width=100%>";
				var storelist = new Object();
				var distances = new Array();
				for(var i=0; i<response['matches'].length; i++){
					var dist = gpsDistance(response['matches'][i]['mylat'],response['matches'][i]['mylon'],response['matches'][i]['storelat'],response['matches'][i]['storelon'],'miles');
					dist = Math.round(dist) + '';
					while(dist.length < 5){
						dist = '0'+dist;
					}
					if(typeof(storelist['D_'+dist])=='undefined'){
						storelist['D_'+dist] = new Array();
						distances.push('D_'+dist);
					}
					storelist['D_'+dist].push(response['matches'][i]);
				}
				distances.sort();
				for(distance in distances){
					for(var i=0; i<storelist[distances[distance]].length; i++){
						if(parseInt(distances[distance].split('_')[1], 10) <= storelist[distances[distance]][i]['radius']){
							source += "<tr><td colspan=2><b>"+storelist[distances[distance]][i]['storename']+" ("+parseInt(distances[distance].split('_')[1], 10)+" miles)</b></td></tr>";
							source += "<tr><td style=\"padding-left: 20px;\">";
							var addr = storelist[distances[distance]][i]['address1']+"<br>";
							if(storelist[distances[distance]][i]['address2'] != ""){
								addr += storelist[distances[distance]][i]['address2']+"<br>";
							}
							addr += storelist[distances[distance]][i]['city']+", ";
							addr += storelist[distances[distance]][i]['state']+" ";
							addr += storelist[distances[distance]][i]['zip'];
							source += addr+"<br>";
							source += storelist[distances[distance]][i]['phone']+"</td>";
							source += "<td style=\"text-align:center;cursor:pointer;cursor:hand;padding-left: 20px;\" onClick=\"var win = window.open('http://maps.google.com/maps?q="+escape(addr.replace("<br>"," "))+"');win.focus();\"><img src=images/mapicon.png><br>Map It!</td></tr>";
							numstores++;
						}
					}
				}
				source += "</table>";
				if(numstores == 0){
					source = "<table><tr><td align=center><u><b>No Matches Found for \""+locationdata+"\"</b></u></td></tr><tr><td><b>Search Tips:</b></td></tr><tr><td style=\"padding-left: 20px;\"><ul><li>Try a larger search radius</li><li>Try another zip code in the same town</li><li>Try just a ZIP code</li><li>Try City, ST</li><li>Make sure the state is the standard two-letter Postal Abbreviation</li><li>Don't enter any street or address information, start with the city or town.</li></ul></td></tr><tr><td><b>Sample Searches:</b></td></tr><tr><td style=\"padding-left: 20px;\"><ul><li>San Diego, CA</li><li>72144</li><li>Baton Rouge, LA 34253</li><li>New Farmington DE 12345-2342</li><li>75484-1538</li></ul></td></tr></table>";
				}
			}
			var popup = createPopup(200, 200, "Dealers Near You ("+numstores+")", {"width":"500","maxheight":"400"});
			popup.innerHTML = source;
		},
		error: function(data){
			alert("a"+data);
		},
		timeout: 30000
	};
	dojo.xhrPost(AJAX);
}

function gpsDistance(lat1,lon1,lat2,lon2,units){
	var R;
	if(units=='miles'){
		var R = 3963;
	}else if(units=='kilometers'){
		var R = 6371;
	}else if(units=='feet'){
		var R = 20924640;
	}else if(units=='meters'){
		var R = 3963000;
	}
	var dLat = (lat2-lat1)/57.29577951;
	var dLon = (lon2-lon1)/57.29577951;
	lat1 = lat1/57.29577951;
	lat2 = lat2/57.29577951;
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
			Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	return(R * c);
}

function goToUrl(url, args){
	var qs=[];
	for(var key in args){
		qs.push(key+'='+encodeURIComponent(args[key]));
	}
	document.location = url+'?'+qs.join("&");
}

function getInputValuesByName(name){
	var values = new Array();
	var inputs = document.getElementsByTagName('*');
	for(var i=0; i<inputs.length; i++){
		var input = inputs.item(i);
		if(input.tagName != 'INPUT' && input.tagName != 'TEXTAREA'){
			continue;
		}
		if(	input.getAttribute('name') == name 
			&& ((input.type.toUpperCase() == 'RADIO' && input.checked)
				|| (input.type.toUpperCase() == 'CHECKBOX' && input.checked)
				|| (input.type.toUpperCase() != 'RADIO' && input.type.toUpperCase() != 'CHECKBOX')
				)
			){
			values.push(input.value);
		}
	}
	return(values);
}

