// JavaScript Document
_mSvgEnabled = true ;
_mSvgForced  = true ;

var center ;
var centerLat;
var centerLng;
var marker = [] ;
var line ;
var geocoder ;
var icon ;
var map;
var visi = 'visible';
var visi2 = 'visible';
var visic ='visible';
var visic2 ='visible';
var marcadores = new Array();
var availabilities = new Array();
var list;

var xmlobj = null;
var city_data = null;
var region_data = null;
var country_data = null;

var forward_page = '';
var forward_var1 = null;
var forward_var2 = null;
var found = true;
      // ====== Array for decoding the failure codes ======
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";


function load()
{

 map = new GMap2(document.getElementById("map"));
 var start = new GLatLng(35.127771,-89.967041);
 map.setCenter(start, 1);
 centerLat = start.y;
 centerLng = start.x;
 map.addControl(new GSmallMapControl());
 map.addControl(new GScaleControl()) ;
 icon = new GIcon();
 icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
 icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
 icon.iconSize = new GSize(12, 20);
 icon.shadowSize = new GSize(22, 20);
 icon.iconAnchor = new GPoint(6, 20);
 icon.infoWindowAnchor = new GPoint(11, 11);
 geocoder = new GClientGeocoder() ;
}

function loadMapLL(lat, lng,zoom)
{
 map = new GMap2(document.getElementById("map"));
 centerMapLL(lat,lng,zoom);

 map.addControl(new GLargeMapControl());
 map.addControl(new GScaleControl()) ;
 icon = new GIcon();
 icon.image = "mm_20_red.png";
 icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
 icon.iconSize = new GSize(18, 19);
 icon.shadowSize = new GSize(22, 20);
 icon.iconAnchor = new GPoint(6, 20);
 icon.infoWindowAnchor = new GPoint(11, 11);
 geocoder = new GClientGeocoder() ;
}


function centerMap(address,zoom){
	geocoder.getLatLng( address, function(pointer)
	{
		if (!pointer){
			alert( address + " unable to be mapped by Google.\n\nPlease confirm information is correct and proceed.");
		}
		else{
 			centerLat = pointer.y;
 			centerLng = pointer.x;
			map.setCenter(pointer,zoom);
		}
	}) ;
}


function centerMapWMarker(addr,city,state,country,zoom){
	var address;
	if(state!='')
		address = addr + ', ' + city + ', ' + state + ', ' + country;
	else
		address = addr + ', ' + city + ', ' + country;
	geocoder.getLocations( address, function(result)
	{
		//alert(reasons[result.Status.code]);
		 if (result.Status.code == G_GEO_SUCCESS) {
			var p = result.Placemark[0].Point.coordinates;
			var pointer = new GLatLng(p[1],p[0]);
 			centerLat = pointer.y;
 			centerLng = pointer.x;
			map.setCenter(pointer,zoom);
			var marker = new GMarker(pointer, icon);
			var html = '<div style="font-size:10px; height: 40px;width:95px;"><b>Property located:</b><br>' + addr + '<br>' + city +', ' + country+'</div>';
			GEvent.addListener(marker, "click", function() {
               marker.openInfoWindowHtml( html, {pixelOffset:new GSize(32,5), maxWidth:100} ) ;

			});
			map.addOverlay(marker);
			marker.openInfoWindowHtml(html);
			//locationLabel(true);
			try {
				document.getElementById('propLat').value = p[1];
				document.getElementById('propLong').value = p[0];
			}catch(exc) {}
		}
		else {
			found = false;
			try {
				toConfirm();
			}catch(e) {
				try {
					toConfirmProperty();
				}catch(e) {
				}
			}
		}
	});
}

function centerMapLL(lat, lng, zoom){
	var pointer = new GLatLng(lat,lng)
	map.setCenter(pointer,zoom);
 	centerLat = pointer.y;
 	centerLng = pointer.x;
}

function addMarker(property_id, addr, city, state, country, lat, long, beds, baths, sqft) {
	var pointer;
	var zoom = 12;
	var marker = null;
	if(lat!=0 && long!=0) {
		pointer = new GLatLng(lat, long);
		marker = new GMarker(pointer, icon);
	}
	else {
		var address;
		if(state!='')
			address = addr + ', ' + city + ', ' + state + ', ' + country;
		else
			address = addr + ', ' + city + ', ' + country;
		if(geocoder == null || geocoder == 'undefined')
			geocoder = new GClientGeocoder();
		geocoder.getLocations( address, function(result)
		{
			//alert(reasons[result.Status.code]);
			 if (result.Status.code == G_GEO_SUCCESS) {
				var p = result.Placemark[0].Point.coordinates;
				pointer = new GLatLng(p[1],p[0]);
				centerLat = pointer.y;
				centerLng = pointer.x;
				map.setCenter(pointer,zoom);
				marker = new GMarker(pointer, icon);
				//locationLabel(true);

			}
		});
	}
	var html = '<div style="width:280px;"><table border="0" cellpadding="0" cellspacing="3">';
	html = html + '<tr><td width="100"><img src="pictures/'+property_id+'.jpg" width="100" height="80" style="border:1px solid #000;" onerror="this.src = \'images/nopic.jpg\';"></td>';
	html = html + '<td width="180" valign="top"><div style="font-size:13px; font-weight:bold;"><a href="#">Click here for more details</a></div>';
	html = html + '<div style="margin-top:4px; font-size:10px; overflow:hidden;"><strong>address: </strong>'+addr+'</div>';
	html = html + '<div style="font-size:10px; overflow:hidden;"><strong>city: </strong>'+city+'</div>';
	html = html + '<div style="font-size:10px; overflow:hidden;"><strong>country: </strong>'+country+'</div>';
	html = html + '<div style="font-size:10px; width:48%; float:left;"><strong>bedrooms: </strong>'+beds+'</div>';
	html = html + '<div style="font-size:10px; width:48%; float:right;"><strong>bathrooms: </strong>'+baths+'</div>';
	html = html + '</td></tr></table></div>';
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	map.addOverlay(marker);
	marcadores[marcadores.length] = createMarkerObject(pointer, marker, property_id, addr, city, state, country, lat, long, beds, baths, sqft);
}

function createMarkerObject(pointer, marker, property_id, addr, city, state, country, lat, long, beds, baths, sqft, mn, date_in, date_out) {

	var x = new Array();
	x.pointer = pointer;
	x.marker = marker;
	x.id = property_id;
	x.addr = addr;
	x.city = city;
	x.state = state;
	x.country = country;
	x.lat = lat;
	x.long = long;
	x.beds = beds;
	x.baths = baths;
	x.sqft = sqft;
	x.mn = mn;
	if(date_in == null || date_in=='undefined')
		x.date_in = new Date();
	else
	 x.date_in = date_in;
	if(date_out == null || date_out=='undefined')
		x.date_out = new Date();
	else
	 x.date_out = date_out;

	return x;
}

// send http POST request
function sendRequest(doc, func, url_enc_param){
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
        xmlobj.abort();
    }
    try{
        xmlobj=new XMLHttpRequest();
	//alert('standard mozilla ajax');

    }
    catch(e){
        try{
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            xmlobj=null;
            return false;
		//alert('no ajax');
        }
    }
    xmlobj.onreadystatechange=func;
    xmlobj.open('POST',doc,true);
	xmlobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    xmlobj.send(url_enc_param);
}

var objs = [];
objs['city']=null;
objs['region']=null;
objs['country']=null;
var vals = [];
vals['city']=null;
vals['region']=null;
vals['country']=null;


// send http POST request with custom xmlobj
function sendRequest2(obj, doc, func, url_enc_param){
    if(objs[obj]!=null&&objs[obj].readyState!=0&&objs[obj].readyState!=4){
        objs[obj].abort();
    }
    try{
        objs[obj]=new XMLHttpRequest();
	//alert('standard mozilla ajax');

    }
    catch(e){
        try{
            objs[obj]=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            objs[obj]=null;
            return false;
		//alert('no ajax');
        }
    }
    objs[obj].onreadystatechange=func;
    objs[obj].open('POST',doc,true);
	objs[obj].setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    objs[obj].send(url_enc_param);
}




function cityHandler() {
    if(objs['city'].readyState==4){
        if(objs['city'].status==200){
			//alert(objs['city'].responseText);
			city_data = eval( objs['city'].responseText );
			if(city_json!=null){
				city_data = city_json;
				var sel = document.getElementById('city_select');
				sel.options.length = 0;
				sel.options[0] = createDefaultOption('city');
				for(var i=1; i <= city_data.cities.length; i++) {
					var option = document.createElement("OPTION");
					option.value = city_data.cities[i-1].id;
					option.text = city_data.cities[i-1].name;
					//alert(vals['city']);
					if(vals['city']!=null) {
						if(vals['city'] == option.value) {
							option.selected = 'selected';
							sel.selectedIndex = i-1;
						}
					}
					sel.options[i] = option;
				}
				vals['city']=null;
			}
        }
    }
}

function regionHandler() {
    if(objs['region'].readyState==4){
        if(objs['region'].status==200){
			//alert(objs['region'].responseText);
			region_data = eval( objs['region'].responseText );
			if(region_json!=null) {
				region_data = region_json;
				var sel = document.getElementById('region_select');
				sel.options.length = 0;
				sel.options[0] = createDefaultOption('region');
				for(var i=1; i <= region_data.regions.length; i++) {
					var option = document.createElement("OPTION");
					option.value = region_data.regions[i-1].id;
					option.text = region_data.regions[i-1].name;
					if(vals['region']!=null) {
						if(vals['region'] == option.value) {
							option.selected = 'selected';
							sel.selectedIndex = i-1;
						}
					}
					sel.options[i] = option;
				}
				document.getElementById('city_select').options.length = 0;
				document.getElementById('city_select').options[0] = createDefaultOption('region first');
				vals['region']=null;
			}
        }
    }
}

function countryHandler() {
    if(objs['country'].readyState==4){
        if(objs['country'].status==200){
			//alert(objs['country'].responseText);
			country_data = eval( objs['country'].responseText );
			if(country_json!=null) {
				country_data = country_json;
				var sel = document.getElementById('country_select');
				sel.options.length = 0;
				sel.options[0] = createDefaultOption('country');
				for(var i=1; i <= country_data.countries.length; i++) {
					var option = document.createElement("OPTION");
					option.value = country_data.countries[i-1].id;
					option.text = country_data.countries[i-1].name;
					if(vals['country']!=null) {
						if(vals['country'] == option.value){
							option.selected = 'selected';
							sel.selectedIndex = i-1;
						}
					}
					sel.options[i] = option;
				}
				document.getElementById('region_select').options.length = 0;
				document.getElementById('region_select').options[0] = createDefaultOption('country first');
				document.getElementById('city_select').options.length = 0;
				document.getElementById('city_select').options[0] = createDefaultOption('region first');
				vals['country']=null;
			}
        }
    }
}
function changeCountries2(world_id, val) {
	//alert(world_id);
	vals['country'] = val;
	sendRequest2('country', 'GetLocationJSON.jsp', countryHandler, 'type=COUNTRY&world_id='+world_id);
}

function changeRegions2(country_id, val) {
	vals['region'] = val;
	sendRequest2('region', 'GetLocationJSON.jsp', regionHandler, 'type=REGION&country_id='+country_id);
}

function changeCities2(region_id, val) {
	vals['city'] = val;
	//alert(vals['city']);
	sendRequest2('city', 'GetLocationJSON.jsp', cityHandler, 'type=CITY&region_id='+region_id);
}

function changeCountries(world_id) {
	//alert(world_id);
	sendRequest2('country', 'GetLocationJSON.jsp', countryHandler, 'type=COUNTRY&world_id='+world_id);
}

function changeRegions(country_id) {
	sendRequest2('region', 'GetLocationJSON.jsp', regionHandler, 'type=REGION&country_id='+country_id);
	if(country_id!=-1) {
		try {
			for(var i=0; i<country_data.countries.length;i++) {
				if(country_data.countries[i].id == country_id) {
					centerMapLL(country_data.countries[i].latitude,country_data.countries[i].longitude,3);
					break;
				}
			}
		}catch(e){}
	}
}

function changeCities(region_id) {
	sendRequest2('city', 'GetLocationJSON.jsp', cityHandler, 'type=CITY&region_id='+region_id);
}


function centerCity(city_id) {
	if(city_id !=-1) {
		for(var i=0; i<city_data.cities.length;i++) {
			if(city_data.cities[i].id == city_id) {
				centerMapLL(city_data.cities[i].latitude,city_data.cities[i].longitude,10);
				break;
			}
		}
	}
}

function createDefaultOption(opt) {
	var option = document.createElement("OPTION");
	option.text = 'Select a '+opt;
	option.value = -1;
	return option;
}

function toConfirm() {
	var div = document.getElementById('review');
	var text = '<span style="font-size:11px;"><b>Personal data:</b><br>name: '+document.owner.name.value+'<br>phone: '+document.owner.phone.value+'<br><br>';
	text += '<b>Login data:</b><br>email: '+document.owner.email.value+'<br>password: '+document.owner.password.value+'<br><br>';
	text += '<b>Owner\'s mailing address:</b><br>country: '+document.owner.country_select.options[document.owner.country_select.selectedIndex].text+'<br>';
	text += 'region/state: '+document.owner.region_select.options[document.owner.region_select.selectedIndex].text+'<br>';
	text += 'city: '+document.owner.city_select.options[document.owner.city_select.selectedIndex].text+'<br>';
	text += 'address: '+document.owner.address.value;
	text += '</span>';
	div.innerHTML = text;
}

function toConfirmProperty() {
	var div = document.getElementById('review');
	var text = '<span style="font-size:11px;"><b>Property data:</b><br>bedrooms: '+document.propertyy.bedrooms.value+'<br>bathrooms: '+document.propertyy.bathrooms.value+'<br>';
	text += 'square footage: '+document.propertyy.sqft.value+'<br><br>';
	text += '<b>Address data:</b><br>country: '+document.propertyy.country_select.options[document.propertyy.country_select.selectedIndex].text+'<br>';
	text += 'region/state: '+document.propertyy.region_select.options[document.propertyy.region_select.selectedIndex].text+'<br>';
	text += 'city: '+document.getElementById('city_select').options[document.getElementById('city_select').selectedIndex].text+'<br>';
	text += 'address: '+document.getElementById('address').value;
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function sendMail(to, subject, message, handler) {
	sendRequest('sendMail.php', handler, 'email='+to+'&subject='+subject+'&message='+message);
}

function sendeMail(bad) {
         if(bad == 'yes') {
         document.getElementById('message').innerHTML = 'Email address cannot be found!<br><br>Re-submit your email address or <a href="owner_login.jsp">Register here</a>';
          }
			else {
				document.getElementById('message').innerHTML = 'Input your email address for your account';
			}

}


function lostPasswordHanler() {
    if(xmlobj.readyState==4){
        if(xmlobj.status==200){
			var x = xmlobj.responseText;
			if(x == 'sent') {
				document.getElementById('message').innerHTML = 'Your password was sent to your e-mail.';
			}
			else {
				document.getElementById('message').innerHTML = 'Impossible to send e-mail.';
			}
        }
    }
}

function nullHandler() {
    if(xmlobj.readyState==4){
        if(xmlobj.status==200){
			//alert(xmlobj.responseText);
        }
    }
}

function registerPerson(name, address, city_id, phone, email, password, enabled, forward_p, city, region_name, country_id, country_name, postal_code) {
	//alert(enabled);
	if(email==''){
		alert('Email is a required field.');
		return false;
	}
	if(name==''){
		alert('Name is a required field.');
		return false;
	}
	if(password=='') {
		alert('Password is a required field.');
		return false;
	}

	forward_page = forward_p;
	forward_var1 = email;
	forward_var2 = password;
	var param = 'operation=INSERT&name='+name+'&address='+address+'&city_id='+city_id+'&phone='+phone+'&email='+email+'&password='+password+'&city='+city+'&region_name='+region_name+'&country_id='+country_id+'&country_name='+country_name+'&postal_code='+postal_code;
	if(enabled!=null) {
		param += '&enabled='+enabled;
		//alert(param);
		sendRequest('registerOwnerS.jsp', registerHandler, param);
		sendMail(email, 'Thank you for registering at FRBO.com', 'Hello '+name+',\nThank you for registering at FRBO.com.\nYour login is: '+email+'\nYour password is: '+password+'\n\nFRBO.com\n', nullHandler);
	} else {
		sendRequest('registerOwnerS.jsp', registerHandler, param);
		sendMail(email, 'Thank you for registering at FRBO.com', 'Hello '+name+',\nThank you for registering at FRBO.com.\nYour login is: '+email+'\nYour password is: '+password+'\n\nFRBO.com\n', nullHandler);
	}
}

function updatePerson(name, address, city_id, phone, email, password, enabled, forward_p, region_name, city4,country_id, country_name, postal_code, owner_id) {
	//alert(enabled);
	forward_page = forward_p;
	forward_var1 = null;
	forward_var2 = null;
	var param = 'operation=UPDATE&name='+name+'&address='+address+'&city_id='+city_id+'&phone='+phone+'&email='+email+'&password='+password+'&city='+city4+'&region_name='+region_name+'&country_id='+country_id+'&country_name='+country_name+'&postal_code='+postal_code+'&owner_id='+owner_id;
	if(enabled!=null) {
		param += '&enabled='+enabled;
		//alert(param);
		sendRequest('registerOwnerS.jsp', registerHandler, param);
	} else {
		sendRequest('servlet/RegisterRenter', registerHandler, param);
	}
}

function registerHandler() {
    if(xmlobj.readyState==4){
	alert(xmlobj);
        if(xmlobj.status==200){
			//alert(xmlobj.responseText);
			forw = forward_page;
			if(forward_var1 != null && forward_var2!= null )
				forw += '?email='+forward_var1+'&password='+forward_var2;
			if(xmlobj.responseText != '' && xmlobj.responseText != null)
				forw += '?property_id='+xmlobj.responseText;
			window.location = forw;
			forward_var1 = null;
			forward_var2 = null;
			forward_page = null;
        }
    }
}

function registerProperty(owner_id, property_id, address, city_id, d_property, d_location, beds, baths, sqft, forward_p, lat, long, name, email, city_name, region_name, country_name, postal_code) {
	if(address==''){
		alert('Address is a required field.');
		return false;
	}
	if(city_id <= 0){
		alert('City is a required field.');
		return false;
	}
	if(beds==''){
		alert('Bedrooms is a required field.');
		return false;
	}
	if(baths==''){
		alert('Bathrooms is a required field.');
		return false;
	}

	forward_page = forward_p;
	var param = 'operation=INSERT&owner_id='+owner_id+'&property_id='+property_id+'&address='+address+'&city_id='+city_id+'&description_property='+d_property+'&description_location='+d_location+'&bedrooms='+beds+'&bathrooms='+baths+'&sqft='+sqft+'&lat='+lat+'&long='+long+'&city_name='+city_name+'&region_name='+region_name+'&country_name='+country_name;
	sendRequest('registerPropertyS_dev2.jsp', registerHandler, param);
	if(email!=null && email!='undefined') {
		sendMail(email, 'Thank you for registering at FRBO.com', 'Hello '+name+',\n\nThe listing was successful. You can manage your listing in the owner area once you log in.\n\nThanks.\n\nThe FRBO.com Team\n', nullHandler);
	}
}

function updateProperty(owner_id, address, city_id, d_property, d_location, beds, baths, sqft, forward_p, lat, long, property_id, enabled) {
	forward_page = forward_p;
	var compl = '';
	if(enabled!=null && enabled!='undefined')
		compl = '&enabled='+enabled;
	var param = 'operation=UPDATE&owner_id='+owner_id+'&address='+address+'&city_id='+city_id+'&description_property='+d_property+'&description_location='+d_location+'&bedrooms='+beds+'&bathrooms='+baths+'&sqft='+sqft+'&lat='+lat+'&property_id='+property_id+'&long='+long+compl;
	//alert(param);
	sendRequest('registerPropertyS.jsp', registerHandler, param);
}

function goto() {
	var cit = document.getElementById("city_select");
    var cit2= cit.options[cit.selectedIndex].text.replace(/ /g, "-");
    var reg = document.getElementById("region_select");
    var reg2= reg.options[reg.selectedIndex].text.replace(/ /g, "-");
    var coun = document.getElementById("country_select");
    var coun2= coun.options[coun.selectedIndex].text.replace(/ /g, "-");
    if(cit.options[cit.selectedIndex].value != -1) {

        window.location = coun2+'/'+reg2+'/'+cit2+'/'+cit.options[cit.selectedIndex].value+'.html';
	}
	else if (coun != null) {
		window.location = 'country.jsp?country_id='+coun.options[coun.selectedIndex].value;
	}
}

function emptyMarkers() {
	marcadores = new Array();
}

function insertMarker(property_id, addr, city, state, country, lat, long, beds, baths, sqft, mn, date_in, date_out) {
	var pointer;
	var marker = null;
	var letteredIcon = new GIcon();
	letteredIcon.image = "http://www.frbo.com/markers/orange"+mn+".png";
	letteredIcon.shadow = "http://www.frbo.com/markers/orange100.png";
	 letteredIcon.iconSize = new GSize(25, 25);
	 letteredIcon.shadowSize = new GSize(25, 25);
	 letteredIcon.iconAnchor = new GPoint(10, 20);
	 letteredIcon.infoWindowAnchor = new GPoint(15, 5);
	markerOptions = { icon:letteredIcon };
	if(lat!=0 && long!=0) {
		pointer = new GLatLng(lat, long);
		marker = new GMarker(pointer, letteredIcon);
		marcadores[marcadores.length] = createMarkerObject(pointer, marker, property_id, addr, city, state, country, lat, long, beds, baths, sqft, mn, date_in, date_out);
	}
	else {
		var address;
		if(state!='')
			address = addr + ', ' + city + ', ' + state + ', ' + country;
		else
			address = addr + ', ' + city + ', ' + country;
		if(geocoder == null || geocoder == 'undefined')
			geocoder = new GClientGeocoder();
		geocoder.getLocations( address, function(result)
		{
			 //alert(reasons[result.Status.code]);
			 if (result.Status.code == G_GEO_SUCCESS) {
				var p = result.Placemark[0].Point.coordinates;
				pointer = new GLatLng(p[1],p[0]);
				marker = new GMarker(pointer, icon );
				//locationLabel(true);
				marcadores[marcadores.length] = createMarkerObject(pointer, marker, property_id, addr, city, state, country, lat, long, beds, baths, sqft, mn, date_in, date_out);
			}
		});
	}

}

function showMarkers(bed_min, bed_max, bath_min, bath_max, date_in, date_out, close_search) {
	var point=null;
	map.clearOverlays();
	for(var i=0; i < marcadores.length; i ++) {
		if(bed_min <= marcadores[i].beds && bed_max >= marcadores[i].beds) {
			if(bath_min <= marcadores[i].baths && bath_max >= marcadores[i].baths) {
				var dtobj = availabilities[marcadores[i].id];
				if(dtobj == null || (date_in==null || date_out==null) ) {
					plotMarker(marcadores[i]);
					point = marcadores[i].pointer;
				}
				else if(dtobj!=null){
					for(var j=0; j < dtobj.length; j++) {
						if(( date_in >= dtobj[j].date_in && date_out <= dtobj[j].date_out )|| date_in==null || date_out==null) {
							plotMarker(marcadores[i]);
							point = marcadores[i].pointer;
							break;
						}
					}
				}
				//if(( date_in <= marcadores[i].date_in && date_out >= marcadores[i].date_out )|| date_in==null || date_out==null) {
					//plotMarker(marcadores[i]);
					//point = marcadores[i].pointer;
				//}
			}
		}
	}
	if(close_search!=null && close_search != 'undefined') {
		//todo
		if(close_search == true)
			map.setCenter(point,10);

	}
	else if(point!=null) {
		map.setCenter(point,5);
	}
}

function plotMarker(mark) {
	var html = '<div style="width:200px;"><table border="0" cellpadding="0" cellspacing="2">';
	html = html + '<tr><td width="100"><img src="../../../pictures/'+mark.id+'.jpg" width="100" height="80" style="border:1px solid #000;" onerror="this.src = \'http://www.frbo.com/images/nopic.jpg\';"></td>';
	html = html + '<td width="100" valign="top"><div style="font-size:12px; font-weight:bold;"><a href="../../../property.jsp?id='+mark.id+'">Click for details<br />';
	html = html + '<div style="margin-top:4px; font-size:10px; overflow:hidden;">'+mark.addr+'</div>';
	html = html + '<div style="font-size:10px; overflow:hidden;">'+mark.city+'</div>';
	html = html + '<div style="font-size:10px; overflow:hidden;">'+mark.country+'</div>';
	html = html + '<div style="font-size:10px; width:48%; float:left;"><strong>beds: </strong>'+mark.beds+'</div>';
	html = html + '<div style="font-size:10px; width:48%; float:right;"><strong>baths: </strong>'+mark.baths+'</div>';
	html = html + '</td></tr></a></div></table></div>';
	GEvent.addListener(mark.marker, "click", function() {
		mark.marker.openInfoWindowHtml(html);
	});
	map.addOverlay(mark.marker);
}

function insertAvailability(property_id, date_in, date_out) {
	var p_id = property_id + '';
	if(availabilities[p_id] == null)
		availabilities[p_id] = new Array();
	availabilities[p_id][availabilities[p_id].length] =	createAvailObject(property_id, date_in, date_out);
}

function createAvailObject(property_id, date_in, date_out) {
	var x = new Array();
	x.id = property_id;
	x.date_in = date_in;
	x.date_out = date_out;
	return x;
}

function searchCity() {
	var bed_min = document.cityf.bed_min.options[document.cityf.bed_min.selectedIndex].value;
	var bed_max = document.cityf.bed_max.options[document.cityf.bed_max.selectedIndex].value;
	var bath_min = document.cityf.bath_min.options[document.cityf.bath_min.selectedIndex].value;
	var bath_max = document.cityf.bath_max.options[document.cityf.bath_max.selectedIndex].value;
	var year_min = document.cityf.year_min.options[document.cityf.year_min.selectedIndex].value;
	var month_min = document.cityf.month_min.options[document.cityf.month_min.selectedIndex].value;
	var day_min = document.cityf.day_min.options[document.cityf.day_min.selectedIndex].value;
	var year_max = document.cityf.year_max.options[document.cityf.year_max.selectedIndex].value;
	var month_max = document.cityf.month_max.options[document.cityf.month_max.selectedIndex].value;
	var day_max = document.cityf.day_max.options[document.cityf.day_max.selectedIndex].value;

	var date_in = new Date(parseInt(year_min),parseInt(month_min), parseInt(day_min));
	var date_out = new Date(parseInt(year_max),parseInt(month_max), parseInt(day_max));

	showMarkers(bed_min, bed_max, bath_min, bath_max, date_in, date_out, false);
}

function searchCountry() {
	/*
	var year_min = '2007';
	var month_min = '1';
	var day_min = '1';
	var year_max = '2015';
	var month_max = '12';
	var day_max = '31';

	var date_in = new Date(parseInt(year_min),parseInt(month_min), parseInt(day_min));
	var date_out = new Date(parseInt(year_max),parseInt(month_max), parseInt(day_max));
	*/
	showMarkers(1, 99, 1, 99, null, null, true);
}


function loaddev(latlook, lonlook) {

        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(latlook,lonlook);
        geocoder = new GClientGeocoder();
        map.setCenter(center, 15);
        var marker = new GMarker(center, {draggable: true});
        map.addOverlay(marker);
        document.getElementById("lat").innerHTML = center.lat().toFixed(6);
        document.getElementById("lng").innerHTML = center.lng().toFixed(6);
        document.getElementById("lat").value = center.lat().toFixed(6);
        document.getElementById("lng").value = center.lng().toFixed(6);
        toOrigLatLon2(latlook, lonlook);

	    GEvent.addListener(marker, "dragend", function() {
        var point = marker.getPoint();
	    map.panTo(point);
        document.getElementById("lat").innerHTML = point.lat().toFixed(6);
        document.getElementById("lng").innerHTML = point.lng().toFixed(6);
        document.getElementById("lat").value = point.lat().toFixed(6);
        document.getElementById("lng").value = point.lng().toFixed(6);
        toConfirmLatLon();

        });


	    GEvent.addListener(map, "moveend", function() {
		map.clearOverlays();
        var center = map.getCenter();
		var marker = new GMarker(center, {draggable: true});
		map.addOverlay(marker);
		document.getElementById("lat").innerHTML = center.lat().toFixed(6);
	    document.getElementById("lng").innerHTML = center.lng().toFixed(6);
        document.getElementById("lat").value = center.lat().toFixed(6);
        document.getElementById("lng").value = center.lng().toFixed(6);
        toConfirmLatLon();

	    GEvent.addListener(marker, "dragend", function() {
        var point =marker.getPoint();
	    map.panTo(point);
        document.getElementById("lat").innerHTML = point.lat().toFixed(6);
	    document.getElementById("lng").innerHTML = point.lng().toFixed(6);
        document.getElementById("lat").value = point.lat().toFixed(6);
        document.getElementById("lng").value = point.lng().toFixed(6);
        toConfirmLatLon();

        });
        });
    }

function centerMapWMarker2(addr,city,state,country,zoom){
    geocoder = new GClientGeocoder();
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    var address;

		address = addr + ', ' + city + ', ' + state + ', ' + country;


	if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            }
    	    else {
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
	            document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                toConfirmLatLon();
		        map.clearOverlays();
			    map.setCenter(point, 14);
                var marker = new GMarker(point, {draggable: true});
                map.addOverlay(marker);

        	    GEvent.addListener(marker, "dragend", function() {
                var point = marker.getPoint();
        	    map.panTo(point);
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
                document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                   toConfirmLatLon();
                });


        	    GEvent.addListener(map, "moveend", function() {
        		map.clearOverlays();
                var center = map.getCenter();
        		var marker = new GMarker(center, {draggable: true});
        		map.addOverlay(marker);
        		document.getElementById("lat").innerHTML = point.lat().toFixed(6);
        	    document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);

        	    GEvent.addListener(marker, "dragend", function() {
                var point =marker.getPoint();
        	    map.panTo(point);
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
        	    document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                toConfirmLatLon();
        });
        });
           }
          }
        );
      }
    }

function toOrigLatLon() {
   var div = document.getElementById('review');
		var text = '<span style="font-size:12px; text-align: left; color:#448; vertical-align:top; padding-top: 5px;">' ;
     text += '<table width="680"><tr><td width="195"><b>Property data:</b><br>';
     text += 'bedrooms: '+document.propertyy.bedrooms.value+'<br>';
     text +='bathrooms: '+document.propertyy.bathrooms.value+'<br>';
	 text += 'sq ft: '+document.propertyy.sqft.value+'<br></td>';

     text += '<td width="195"><b>Address data:</b><br>';
     text +=  document.getElementById('address').value+'<br><br>';

     text += '';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td>';
     text += '<td> To get a precise location of your property, move the Red icon to the exact location. ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '</td></tr></table>';
     text += '<input type="hidden" name="lat" value="'+document.getElementById('lat').value+'">';
     text += '<input type="hidden" name="long" value="'+document.getElementById('lng').value+'">';
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function toConfirmLatLon() {
   var div = document.getElementById('review');
	var text = '<span style="font-size:11px; text-align: left;">' ;
     text += '<table><tr><td><b>Property data:</b><br>';
     text += 'bedrooms: '+document.propertyy.bedrooms.value+'<br>';
     text +='bathrooms: '+document.propertyy.bathrooms.value+'<br>';
	 text += 'sq ft: '+document.propertyy.sqft.value+'<br></td>';

     text += '<td><b>Address data:</b><br>';
     text +=  document.propertyy.address.value+'<br>';
     text +=  document.propertyy.city_name.value+', ';
	 text +=  document.propertyy.region_name.value+'<br>';
     text +=  document.propertyy.country_name.value+'<br>';

     text += '</td><td>';
     text += '<b>Geocode Location:</b><br>';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td></tr><br>';
     text += '</td></tr><tr><td colspan="3"> ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '</td></tr></table>';
     text += '<input type="hidden" name="lat" value="'+document.getElementById('lat').value+'">';
     text += '<input type="hidden" name="long" value="'+document.getElementById('lng').value+'">';
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function centerMapWMarkerLatLon(lat, lng,zoom ,addr)     {

        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(lat,lng);
        geocoder = new GClientGeocoder();
        map.setCenter(center, 15);
        var marker = null;
	    var letteredIcon = new GIcon();
	    letteredIcon.image = "http://www.frbo.com/markers/orange1.png";
	    letteredIcon.shadow = "http://www.frbo.com/markers/orange100.png";
	    letteredIcon.iconSize = new GSize(25, 25);
	    letteredIcon.shadowSize = new GSize(25, 25);
	    letteredIcon.iconAnchor = new GPoint(10, 20);
	    letteredIcon.infoWindowAnchor = new GPoint(15, 5);
	    markerOptions = { icon:letteredIcon };
        var marker = new GMarker(center, letteredIcon);
        map.addOverlay(marker);


}

function toOrigLatLon2(latlook,lonlook) {
  var div = document.getElementById('review');
	var text = '<span style="font-size:11px; text-align: left;">' ;
     text += '<table><tr><td><b>Property data:</b><br>';
     text += 'bedrooms: '+document.propertyy.bedrooms.value+'<br>';
     text +='bathrooms: '+document.propertyy.bathrooms.value+'<br>';
	 text += 'sq ft: '+document.propertyy.sqft.value+'<br></td>';

     text += '<td><b>Address data:</b><br>';
     text +=  document.propertyy.address.value+'<br>';
     text +=  document.propertyy.city_name.value+', ';
	 text +=  document.propertyy.region_name.value+'<br>';
     text +=  document.propertyy.country_name.value+'<br>';

    text += '</td><td>';
     text += '<b>Geocode Location:</b><br>';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td></tr><br>';
     text += '</td></tr><tr><td colspan="3"> ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '</td></tr></table>';
     text += '<input type="hidden" name="lat" value="'+latlook+'">';
     text += '<input type="hidden" name="long" value="'+lonlook+'">';
	if(!found)

		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function toConfirmProperty2() {
   	var div = document.getElementById('review');
	var text = '<span style="font-size:11px; text-align: left;">';
    text += '</td></tr><tr><td>';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td></tr><br>';
     text += '<tr><td colspan="2"> To get a precise location of your property, move the Red icon to the exact location. ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '</td></tr></table>';
     text += '<input type="hidden" name="lat" value="'+document.getElementById('lat').value+'">';
     text += '<input type="hidden" name="long" value="'+document.getElementById('lng').value+'">';
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function toConfirmProperty1() {
	var div = document.getElementById('review');
	var text = '<span style="font-size:11px;text-align: left;">';
    text += '</td></tr><tr><td width="390">';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td>';
     text += '<td> To get a precise location of your property, move the Red icon to the exact location. ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '</td></tr></span></table>';
     text += '<input type="hidden" name="lat" value="'+document.getElementById('lat').value+'">';
     text += '<input type="hidden" name="long" value="'+document.getElementById('lng').value+'">';
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}

function loadreg() {

        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(35.127771,-89.967041);
        geocoder = new GClientGeocoder();
        map.setCenter(center, 1);
        var marker = new GMarker(center, {draggable: true});
        map.addOverlay(marker);
        document.getElementById("lat").innerHTML = center.lat().toFixed(6);
        document.getElementById("lng").innerHTML = center.lng().toFixed(6);
        document.getElementById("lat").value = center.lat().toFixed(6);
        document.getElementById("lng").value = center.lng().toFixed(6);
        toConfirmProperty1();

	    GEvent.addListener(marker, "dragend", function() {
        var point = marker.getPoint();
	    map.panTo(point);
        document.getElementById("lat").innerHTML = point.lat().toFixed(6);
        document.getElementById("lng").innerHTML = point.lng().toFixed(6);
        document.getElementById("lat").value = point.lat().toFixed(6);
        document.getElementById("lng").value = point.lng().toFixed(6);
        toConfirmProperty1();

        });


	    GEvent.addListener(map, "moveend", function() {
		map.clearOverlays();
        var center = map.getCenter();
		var marker = new GMarker(center, {draggable: true});
		map.addOverlay(marker);
		document.getElementById("lat").innerHTML = center.lat().toFixed(6);
	    document.getElementById("lng").innerHTML = center.lng().toFixed(6);
        document.getElementById("lat").value = center.lat().toFixed(6);
        document.getElementById("lng").value = center.lng().toFixed(6);
        toConfirmProperty1();

	    GEvent.addListener(marker, "dragend", function() {
        var point =marker.getPoint();
	    map.panTo(point);
        document.getElementById("lat").innerHTML = point.lat().toFixed(6);
	    document.getElementById("lng").innerHTML = point.lng().toFixed(6);
        document.getElementById("lat").value = point.lat().toFixed(6);
        document.getElementById("lng").value = point.lng().toFixed(6);
        toConfirmProperty1();

        });
        });
    }

function centerMapWMarker3(addr,city,state,country,zoom){
    geocoder = new GClientGeocoder();
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
   var address;
	if(addr =='' && city == '' && state == '')
		address = country;
    else if(addr =='' && city == '')
        address = state + ',' + country;
    else if(addr =='')
        address = city + ',' + state + ','+ country;
    else if(addr =='' && state == '')
		address = city + ',' +country;
    else if(city =='' && state == '')
		address = addr + ',' +country;
    else if(state == '')
		address = addr + ',' +city+ ',' +country;
	else
		address = addr + ',' + city + ',' + state + ','+ country;


	if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            }
    	    else {
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
	            document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                toOrigLatLon_reg(addr,city,state,country);
		        map.clearOverlays();
			    map.setCenter(point, 14);
                var marker = new GMarker(point, {draggable: true});
                map.addOverlay(marker);

        	    GEvent.addListener(marker, "dragend", function() {
                var point = marker.getPoint();
        	    map.panTo(point);
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
                document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                toOrigLatLon_reg(addr,city,state,country);
                });


        	    GEvent.addListener(map, "moveend", function() {
        		map.clearOverlays();
                var center = map.getCenter();
        		var marker = new GMarker(center, {draggable: true});
        		map.addOverlay(marker);
        		document.getElementById("lat").innerHTML = center.lat().toFixed(6);
        	    document.getElementById("lng").innerHTML = center.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);

        	    GEvent.addListener(marker, "dragend", function() {
                var point =marker.getPoint();
        	    map.panTo(point);
                document.getElementById("lat").innerHTML = point.lat().toFixed(6);
        	    document.getElementById("lng").innerHTML = point.lng().toFixed(6);
                document.getElementById("lat").value = point.lat().toFixed(6);
                document.getElementById("lng").value = point.lng().toFixed(6);
                toOrigLatLon_reg(addr,city,state,country);
        });
        });
           }
          }
        );
      }
    }

function toOrigLatLon_reg(addr,city,state,country) {
   var div = document.getElementById('review');
		var text = '<span style="font-size:12px; text-align: left; color:#448; vertical-align:top; padding-top: 5px;">' ;
     text += '<table width="680"><tr><td width="195"><b>Property data:</b><br>';
     text += 'bedrooms: '+document.propertyy.bedrooms.value+'<br>';
     text +='bathrooms: '+document.propertyy.bathrooms.value+'<br>';
	 text += 'sq ft: '+document.propertyy.sqft.value+'<br></td>';

     text += '<td width="195"><b>Address data:</b><br>';
     text +=  addr+'<br>';
     text +=  city+', ' + state+'<br>';
     text +=  country+'<br>';

     text += '';
     text += 'Latitude:  '+document.getElementById('lat').value+'<br>';
     text += 'Longitude: '+document.getElementById('lng').value+'</td>';
     text += '<td> To get a precise location of your property, move the Red icon to the exact location. ';
     text += 'Use the zoom buttons on the left of the map to help locate the exact location. Use hybrid to help to find exact home.';
     text += '<input type="hidden" name="lat" value="'+document.getElementById('lat').value+'">';
     text += '<input type="hidden" name="long" value="'+document.getElementById('lng').value+'">';
     text += '</td></tr></table>';
	if(!found)
		text += '<br><span style="color:#f00;">This address was not found by google maps.<br>If this is the right address you may continue.</span>';
	text += '</span>';
	div.innerHTML = text;
	found = true;
}
function loadPropDetail(addr,city,state,country,Lat8,Lon8, rent, zoom)
{
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GScaleControl()) ;
	icon = new GIcon();
	icon.image = "http://www.frbo.com/markers/orange1.png";
    icon.shadow = "http://www.frbo.com/markers/orange1.png";
    icon.shadowSize = new GSize(25, 25);
    icon.shadowSize = new GSize(25, 25);
	icon.iconAnchor = new GPoint(10, 10);
	icon.infoWindowAnchor = new GPoint(11, 11);
	geocoder = new GClientGeocoder() ;
	var address;
	if(state!='')
		address = addr + ',' + city + ',' + state + ',' + country;
	else
		address = addr + ',' + city + ',' + country;
    if (rent== '-')
       loadMapLL2(Lat8,Lon8,15);
    else
    geocoder.getLatLng( address, function(pointer)
	{
		if (!pointer){
            centerMapLL2(Lat8,Lon8,15);
            var marker = new GMarker(Lat8,Lon8, icon);
			map.addOverlay(marker);


		}
		else{
			centerLat = pointer.y;
			centerLng = pointer.x;
			map.setCenter(pointer,zoom);
			var marker = new GMarker(pointer, icon);
			map.addOverlay(marker);
		}
	});
}

function centerMapLL2(lat, lng, zoom){
	var pointer = new GLatLng(lat,lng)
	map.setCenter(pointer,zoom);
 	centerLat = pointer.y;
 	centerLng = pointer.x;
    var marker = new GMarker(pointer, icon);
	map.addOverlay(marker);
}
function centerMapWMarker_f(addr,city,state,country,zoom){


    geocoder = new GClientGeocoder();
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
   	if(addr =='' && city == '' && state == '')
		address = country;
    else if(addr =='' && city == '')
        address = state + ',' + country;
    else if(addr =='')
        address = city + ',' + state + ','+ country;
    else if(addr =='' && state == '')
		address = city + ',' +country;
    else if(city =='' && state == '')
		address = addr + ',' +country;
    else if(state == '')
		address = addr + ',' +city+ ',' +country;
	else
		address = addr + ',' + city + ',' + state + ','+ country;


	if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            }
		else{
            centerLat = point.y;
 			centerLng = point.x;
            map.setCenter(point,zoom);
			var marker = new GMarker(point, {draggable: true});
		   	var html = '<b>Property located:</b><br>' + addr + '<br>' + city +', ' + country;
			map.addOverlay(marker);
            toOrigLatLon_f(addr,city,state,country,address);
            GEvent.addListener(marker, "dragend", function() {
                var point = marker.getPoint();
        	    map.panTo(point);
                 centerLat = point.y.toFixed(6);
 			     centerLng = point.x.toFixed(6);
                 addr1 = centerLat;
                 toOrigLatLon_f(addr,city,state,country,address);

                });
               GEvent.addListener(map, "moveend", function() {
        		map.clearOverlays();
                var center = map.getCenter();
        		var marker = new GMarker(center, {draggable: true});
        		map.addOverlay(marker);


        	    GEvent.addListener(marker, "dragend", function() {
                var point =marker.getPoint();
        	    map.panTo(point);
                centerLat = point.y.toFixed(6);
 			    centerLng = point.x.toFixed(6);
                toOrigLatLon_f(addr,city,state,country,address);


        });
        });

        }
	});
}
}




function toOrigLatLon_f(addr,city,state,country,address) {
    var div = document.getElementById('review');
	var text =  '<table><tr><td valign="top" width="160">';
        text +=  addr+'<br>';
        text +=  city+', ';
        text +=  state+'<br>';
        text +=  country+'<br><br>';
        text += 'Latitude:     '+centerLat+'<br>';
        text += 'Longitude: '+centerLng+'</td><td valign="top" style="padding-left: 20px; color:#FF0000"><br><br>';
        text += 'To get a precise location of your property, move the Red icon on the map to the exact location. ';
        text += '<input type="hidden" name="lat" value="'+centerLat+'">';
        text += '<input type="hidden" name="long" value="'+centerLng+'">';
        text +=   '</td></tr></table>';
	div.innerHTML = text;


}