
//  Language dependant msgs
if (lang== 'nl') {
	jd_saveUnknownLocation = 'U kunt een onbekende locatie niet opslaan.';
	jd_saveMaxZoom = 'Gelieve zo volledig in te zoomen voor u de kaart opslaat.';
}

if (lang == 'en') {
	jd_saveUnknownLocation = 'You cannot save an unknown location.';
	jd_saveMaxZoom = 'Please zoom to the maximum level before you save the new location.';
}

if (lang == 'fr') {
	jd_saveUnknownLocation = 'You cannot save an unknown location.';
	jd_saveMaxZoom = 'Please zoom to the maximum level before you save the new location.';
}

var map=null;
function loadGmap_example(lat, lon) {
	if ((lat == undefined) || (lon == undefined)) {return;}

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap"));
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
					//document.getElementById("message").innerHTML = center.toString();
		});
    myLat = parseFloat(lat);
    myLon = parseFloat(lon);
    map.addControl(new GLargeMapControl());
    map.addControl(new GScaleControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(myLat, myLon), 17);  
  }
}

function hideGmap() {
	document.getElementById("gmap").style.display = 'none';
	//document.getElementById("gmapTitle").style.display = 'none';
	try {document.getElementById("gmapNoMapText").style.display = 'block';} catch(e) {}
	try {document.getElementById("gmapsVizier").style.display = 'none';} catch (e) {}
	try {document.getElementById("gmapOwnerChange").style.display = 'none';} catch (e) {}
	try {	
		//document.getElementById("gmapContainer").style.display = 'none';
	} catch (e) {}
	return;
}

function showGmap() {
	document.getElementById("gmap").style.display = 'block';

	try {document.getElementById("gmapNoMapText").style.display = 'none';} catch (e) {}
	try {document.getElementById("gmapOwnerChange").style.display = 'none';} catch (e) {}
	//document.getElementById("gmapTitle").style.display = 'block';
	try {document.getElementById("gmapsVizier").style.display = 'block';} catch (e) {}
	try {document.getElementById("gmapContainer").style.display = 'block';} catch (e) {}
	return;
}

function searchForGmap(address) {
  showGmap();	
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap"));
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			try {
				document.getElementById("verifiedGeop").innerHTML = center.toString();
			} catch (e) {}
		});
	}
	else {
		hideGmap();
		return;
	}
	address=address.value;
	
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
    function(point) {
    	if (!point) {
      	//alert(address + ' not found... replace msg by show not found msg');
	      	
	      hideGmap();	
	      $('addressUndefined').style.display='block';
	      
	    } else {
	    	map.setCenter(point, 14);

	    	var marker = new GMarker(point);
	    	map.addOverlay(marker);
		    map.addControl(new GLargeMapControl());
		    map.addControl(new GScaleControl());
		    map.addControl(new GMapTypeControl());
	    }
	  }
	);


}



function loadGmap(zoomFactor) {
	if (!zoomFactor) {zoomFactor=17;}

	if (geopType=='u') {
		// Unknown to Google... Don't search again and hide the Gmap
		hideGmap();
		return;
	}
	
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap"));
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			showGmap();
			//try {
			//	document.getElementById("verifiedGeop").innerHTML = center.toString();
			//} catch (e) {}
		});
	}
	else {
		hideGmap();
	}

  myLat = parseFloat(lat);
  myLon = parseFloat(lon);

  map.addControl(new GLargeMapControl());
  map.addControl(new GScaleControl());
  map.addControl(new GMapTypeControl());

	if ((lat!='') && (lon!='')) {
    myLat = parseFloat(lat);
    myLon = parseFloat(lon);
	  myGLatLng = new GLatLng(myLat, myLon);  
	  var marker = new GMarker(myGLatLng);
    map.setCenter(myGLatLng, zoomFactor);
    map.addOverlay(marker);
   return;
	}

	// Start Geocode request to Google
	//address = document.getElementById("houseAddress").innerHTML;
	address = $('searchAddress').value;
	address = address.replace(/<br>/gi, ', ');
		
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
    function(point) {
    	if (!point) {
      	//alert(address + ' not found...');
        mGeop='undefined,undefined';
	      setTimeout("sGeop(mGeop, 'g');",5000);
	      hideGmap();	
	    } else {
	    	map.setCenter(point, 14);
	    	var marker = new GMarker(point);
	    	map.addOverlay(marker);
	    	var center = map.getCenter();
	    	mGeop = center.toString();	
	    	showGmap();
	    	setTimeout("sGeop(mGeop, 'g');",4000);
	    }
	  }
	);
}


function loadManageGmap(zoomFactor) {
	if (!zoomFactor) {zoomFactor=17;}

	if (geopType=='u') {
		// Unknown to Google... Don't search again and hide the Gmap
		hideGmap();
		// Display box can't find address
		document.getElementById('addressUndefined').style.display='block';
		return;
	}

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap"));
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			try {
				document.getElementById("verifiedGeop").innerHTML = center.toString();
			} catch (e) {}
		});
		showGmap();
	}
	else {
		hideGmap();
	}

  myLat = parseFloat(lat);
  myLon = parseFloat(lon);

  map.addControl(new GLargeMapControl());
  map.addControl(new GScaleControl());
  map.addControl(new GMapTypeControl());

	if ((lat!='') && (lon!='')) {
    myLat = parseFloat(lat);
    myLon = parseFloat(lon);
	  myGLatLng = new GLatLng(myLat, myLon);  
	  var marker = new GMarker(myGLatLng);
    map.setCenter(myGLatLng, zoomFactor);
    map.addOverlay(marker);
   return;
	}

	// Start Geocode request to Google
	address = $('searchAddress').value;

	address = address.replace(/<br>/gi, ', ');
	geocoder = new GClientGeocoder();
	geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
	      			hideGmap();	
	      			$('addressUndefined').style.display='block';
            } else {
              map.setCenter(point, 14);
	  					var marker = new GMarker(point);
              map.addOverlay(marker);
              var center = map.getCenter();
							mGeop = center.toString();	
							setTimeout("sGeop(mGeop, 'g');",5000);
            }
          }
        );
}

function sGeop(mGeop, mType) {
	mGeop = mGeop.replace(/[( )]/g, '');
	mGeop = mGeop.split(',');
	mAddress = '';

	if (mType=='v') {
		$('errorMessages').innerHTML = '';
		mAddress = $('searchAddress').value;
	}

	if (mType=='g') {
		mAddress = $("houseAddress").innerHTML;
		mAddress = mAddress.replace(/<br>/gi, ', ');
	}
	if (!map) {return;}
	if (mType=='v') {
		if (mGeop=='') {
			alert(jd_saveUnknownLocation); return false;
		}
		if (map.getZoom()<17) {
			alert(jd_saveMaxZoom); return false;
		}
	}

	new Ajax.Request('/c/hk/sGeop.php',
  {
  	encoding: 'iso-8859-1',
    method:'post',
    parameters: {addressID: addressID, lat: mGeop[0], lon: mGeop[1], mType : mType, searchAddress : mAddress},
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
	    // Silent on detail house....  print on save verified geops
			if (mType=='v') {
				if (response == '200') {
					// Do Redirect
					locationStr = './detail_house.php?houseID=' + houseID;
					//$('errorMessages').innerHTML = locationStr;;
					window.location = locationStr;
				} else {
					$('errorMessages').innerHTML = response;
				}
				
			}
    }
  });	
}


function createFineTunePane_old(houseID) {
	// Will open a new window with absolute positioned elements
	myLocation = "./change_house_location.php?houseID=" + houseID;
	mw = window.open(myLocation, "width=500,height=500,menubar=no, resizable=no");
	return mw;
}


