    var map;
    var geocoder;
	var address;

    function initialize() {
      geocoder = new GClientGeocoder();
    }

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {
		//alert("Status Code:" + response.Status.code);
		//alert(address)
    
      if (!response || response.Status.code != 200) {
		 if(address.length==6)
		 {
			 showLocation(2);
		 }
		 else
		 {
			  alert("Please input valid postal code");
		 }
		 //alert("Please input valid postal code");
        
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        geocoder.getLocations(point, showAddressNew);

      }
    }
	
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
	
	function showAddress(response) {
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
	address=place.address;
	address=address.split(",",-1);
	address=address.reverse();
	if(address.length>2)
	{
	city=address[2].trim();
	}
	else
	{
		city="";
    }
	//document.write(place.address);
	document.getElementById('city').value =city;
	document.forms.search_form.submit();

	
  }
}

	function showAddressNew(response){
		try{
		if (!response || response.Status.code != 200) {
        alert("Please input valid postal code");
      	} else {
			place1 = response.Placemark[0];
			point1 = new GLatLng(place1.Point.coordinates[1],
								place1.Point.coordinates[0]);

		document.getElementById('center_x').value = place1.Point.coordinates[1];
		document.getElementById('center_y').value = place1.Point.coordinates[0];
       geocoder.getLocations(point1, showAddress);


       // document.forms.search_form.submit(); 
		
		  }
		}
		catch(ex)
		{
			alert(ex);
		}
	}

    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation(type) {
		if(type==1)
		{
	      address = document.getElementById('postal').value;
		}
		else
		{
		  address =address.substring(0,3);
		}
      geocoder.getLocations(address, addAddressToMap);
	 
    }

