	var initialLocation;
	var browserSupportFlag =  new Boolean();
  
  function findMeIndex() {
	  
	  if(navigator.geolocation) {
	      browserSupportFlag = true;
	      navigator.geolocation.getCurrentPosition(function(position) {
	        var iLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
		  	
	        geocoder = new google.maps.Geocoder();
		    geocoder.geocode( { 'latLng': iLocation}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		    	  if (results[0]) {
		    		  $('#GeoidFullAddress').val(results[0].formatted_address);
		    	  }
	
		      } else {
		        alert("Geocode was not successful for the following reason: " + status);
		      }
		    }); 
	        
	      }, function() {
	        handleNoGeolocation(browserSupportFlag);
	      });
	    // Try Google Gears Geolocation
	    } else if (google.gears) {
	      browserSupportFlag = true;
	      var geo = google.gears.factory.create('beta.geolocation');
	      geo.getCurrentPosition(function(position) {
	        initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
	      	return initialLocation;
	      }, function() {
	        handleNoGeoLocation(browserSupportFlag);
	      });
	    // Browser doesn't support Geolocation
	    } else {
	      browserSupportFlag = false;
	      handleNoGeolocation(browserSupportFlag);
	    }
	    
	    function handleNoGeolocation(errorFlag) {
	      if (errorFlag == true) {
	        alert("Geolocation service failed.");
	      } else {
	        alert("Your browser doesn't support geolocation.");
	      }
	    }
	  
  }
    
  function getAssembledAddress()
  {
	  	var description = $('#GeoidDescription').val();
	    var street_address = $('#GeoidAddress1').val();
	    var city = $('#GeoidCity').val();
	    var state = $('#GeoidState').val();
	    var neighborhood = $('#GeoidNeighborhood').val();
	    var country_code = $('#GeoidCountryCode').val();
	    var country = $('#GeoidCountryCode').selectedTexts();
	    
		if ((street_address.length > 0) && (city.length > 0)) {
			searchStr = street_address;
			if (neighborhood.length > 0) {
				searchStr += ', ' + neighborhood + ', ' + city; 
			}
			else {
				searchStr += ', ' + city;
			}
			if (state.length > 0){
				searchStr += ', ' + state;
			}
			if (country_code.length > 0){
				searchStr += ', ' + country;
			}
		}
		else
		{
			alert("Not enough parameters");
			return false;
		}

		return searchStr;
  }
  
  function reloadMaps()
  {
	  
  }

  function codeLatLngAdd() {
	  
		geocoder = new google.maps.Geocoder();
	    var myOptions = {
	      zoom: 18,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    
	    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	    if (($('#GeoidLat').val().length > 1 ) && ($('#GeoidLong').val().length > 1))
	    {
	    	/* Lat/Long GeoCode */
    	    var lat = parseFloat($('#GeoidLat').val());
    	    var lng = parseFloat($('#GeoidLong').val());
	    	var latlng = new google.maps.LatLng(lat, lng);
	    	geocoder.geocode({'latLng': latlng}, function(results, status) {
	    	if (status == google.maps.GeocoderStatus.OK) {
	    		fillFields(results,0); // for reverse geocoding, 0 is most accurate
	    		//console.log(results); // debug
	    		if (results[0]) {
	    	          map.setZoom(18);
	    	          map.setCenter(latlng);
	    	          marker = new google.maps.Marker({
	    	              position: latlng, 
	    	              map: map,
	    	              icon: 'http://media.geoid.me/img/pin.png'
	    	          }); 
	    	        }
	    	      } else {
	    	        alert("Geocoder failed due to: " + status);
	    	      }
	    	    });
	    	
	    }
  }
  function codeAddress(full_address) {
	  
	  	geocoder = new google.maps.Geocoder();
	    
		    geocoder.geocode( { 'address': full_address}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		    	  choosen_id = resultIdChoose(results);
		    	  
		    	  
		    	  fillFields(results,choosen_id);
	
		      } else {
		        alert("Geocode was not successful for the following reason: " + status);
		      }
		    }); 

	    
	  }
  
  function codeLatLng(latlng) {
	  
	  	geocoder = new google.maps.Geocoder();
		    geocoder.geocode( { 'latLng': latlng}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		    	  if (results[0]) {
		    		  alert(results[0].full_address);
		    		  return results[0].full_address;
		    	  }
	
		      } else {
		        alert("Geocode was not successful for the following reason: " + status);
		      }
		    }); 

	    
	  }
  
  function getFullAddress() {
	  initialLocation = findMe();
	  full_address = codeLatLng(initialLocation);
	  alert(full_address);
	  $('#GeoidFullAddress').val(full_address);
      
  }
