function findPOISByDistance(zipcode, radius) {
	var zipexp = /^\d{5}$/;
	if ( zipcode.match(zipexp) ) {
		//hbxCall("/locations/fm", "zipcode/"+zipcode);
		//Perform the search
	    $.get("ajax/find_stores_in_range.asp",
	        {
	            zipcode: zipcode,
	            radius: radius
	        },
	        function(results) {
	            $("#locations").html(results);
	            if (fmMapObj1 !== undefined) {
	                showStreetInstructions();
	                 fmCustomSearchPOIsZipcode(zipcode, radius);
	            }
	        }
	    );
	} else {
		displaySearchResults("");
	}
}

function findStateStores(event, state, page) {
    //hbxCall("/locations/fm", state);
    if (page === undefined) {
        page = '';
    }
	$.get("ajax/find_stores_by_state.aspx", 
	    { state: state, page: page },
	    function(results){
	        $("#locations").html(results);
	    }
	);
}
function clearStoreList() {
    $("#locations").html();
}

function hbxCall(mlc, pn) {
	/*var escapedPN = pn.replace(/ /g,"+");
	var escapedMLC = mlc.replace(/ /g,"+");
	_hbPageView( escapedPN, escapedMLC );*/
}

function searchZip() {
	findPOISByDistance($('input.zipcodesearch').val(), $("#radius").val());
}

function initSearchZip(radius, zip) {
    $('input.zipcodesearch').val() = zip;
    $("#radius").val() = radius;
	searchZip();
}
	
function submitenter(e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
        searchZip();
        return false;
	} else {
		return true;
	}
}

function initMapWithPOI(poi_id, state) {
	fmCustomShowDBMMap(poi_id);
	findStateStores('', state);
}

function showUSInstructions() {
	hideInstructions();
	$("#USLevelInstructions").show();		
}

function showStreetInstructions() {
	hideInstructions();
	$("#StreetLevelInstructions").show();
}

function hideInstructions() {
	$("#USLevelInstructions").hide();
	$("#StreetLevelInstructions").hide();
}