//Added RPetrino - for store locator nav form field (pass either zip or city / state)
//Updated RGrossman - for store locator nav form field on tjx-based pages
var callerFrm;
var urlPath;
var loc;
var locToGeocode;
function submitLocator(caller,path){
    var country = "US";
	callerFrm = caller;
	urlPath = path;
	loc = caller.findStoreSrchBox.value;
	if ( loc == "" || loc == "zip code OR city & state" ) {
		caller.action = path + 'locator.asp';
		return true;
	}
	else {
		caller.geolat.value = "";
		caller.geolong.value = "";
        locToGeocode = loc + " " + country;
		
		var fileref=document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", "http://www.google.com/jsapi?key=" + key + "&callback=loadMaps");
        document.getElementsByTagName("head")[0].appendChild(fileref);

	}			
	return false;				
}
function loadMaps() {
    google.load("maps","2",{"callback":function eurGeocode() {	
	        if (GBrowserIsCompatible()) { 
		        var errmsg = "We apologize.  We're not able to find the town/postcode.  Please try again";
		        var geocoder = new GClientGeocoder();
		        geocoder.getLocations( locToGeocode, 
						        function(response) {
							        if ( !response || response.Status.code != 200 ) {
								        callerFrm.action = urlPath + 'locator.asp';
							        } else {
								        var place = response.Placemark[0];
								        //if (place.AddressDetails.Country.CountryNameCode == "GB") place.AddressDetails.Country.CountryNameCode="UK";
								        //if (place.AddressDetails.Country.CountryNameCode != locToGeocode.substr(locToGeocode.length - 2,2)) {
								        //	alert(errmsg);
								        //}
								        //else {
									        callerFrm.geolat.value = place.Point.coordinates[1];
									        callerFrm.geolong.value = place.Point.coordinates[0];	
									        callerFrm.submit();
								        //}
							        }
						        });
	        } 
	        else {
		        alert("We apologize. Your browser is not compatible with Google Maps.");
	        }
        }
    });
}
