// *** FUNCIÓN CAMBIA PROVINCIA *** //
// *** Parametros:			Provincia string.
// *** Devuelve:			void.
// *** Descripción:		Ubica al mapa en la provincia.

function CambiaPais(Pais) {
	document.getElementById("GoogleZoom").value = 4;
	var Pais 		= document.getElementById("pais_inmueble").value;
	var Direccion 	= Pais;
	
	MostrarUbicacion(Direccion);
}


function CambiaProvincia(Provincia) {
	document.getElementById("GoogleZoom").value = 6;
	var Pais 		= document.getElementById("pais_inmueble").value;
	var Direccion 	= Provincia+", "+Pais;
	
	MostrarUbicacion(Direccion);
}
// *** FIN FUNCIÓN CAMBIA PROVINCIA *** //


// *** FUNCIÓN CAMBIA CIUDAD *** //
// *** Parametros:			Ciudad string.
// *** Devuelve:			void.
// *** Descripción:		Ubica al mapa en la Ciudad.
function CambiaCiudad(Ciudad) {
	if (Ciudad != "") {
		document.getElementById("GoogleZoom").value = 11;
		var Pais 		= document.getElementById("pais_inmueble").value;
		var Provincia 	= document.getElementById("provincia_inmueble").value;
		var Direccion 	= Ciudad+", "+Provincia+", "+Pais;
		
		MostrarUbicacion(Direccion);
	}
}
// *** FIN FUNCIÓN CAMBIA CIUDAD *** //



function CambiaDireccion(Direccion) {
	if (Direccion != "") {
		document.getElementById("GoogleZoom").value = 16;
		var Pais 		= document.getElementById("pais_inmueble").value;
		var Provincia 	= document.getElementById("provincia_inmueble").value;
		var Ciudad 	= document.getElementById("localidad_inmueble").value;
		var Direccion 	= Direccion+", "+Ciudad+", "+Provincia+", "+Pais;
		
		MostrarUbicacion(Direccion);
	}
}
// *** FIN FUNCIÓN CAMBIA DIRECCION *** //


// *** FUNCIÓN STRPOS *** //
// *** Parametros:			str string, ch char.
// *** Devuelve:			i int.
// *** Descripción:		Encuentra la posición de un caracter.
function strpos(str, ch) {
	for (var i = 0; i<str.length; i++) {
		if (str.substring(i, i-1) == ch) {return i};
	}
	return -1;
}


// *** FUNCIÓN UBICAR MAPA *** //
// *** Parametros:			Respuesta object.
// *** Devuelve:			void.
// *** Descripción:		Ubica al mapa.
function UbicarMapa(Respuesta) {
	if (!Respuesta || Respuesta.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address.");
	} else {
		var Ubicacion 		= Respuesta.Placemark[0];
		var GoogleX1 		= Ubicacion.Point.coordinates[1];
		var GoogleY1 		= Ubicacion.Point.coordinates[0];
		var GoogleZoom 	= parseInt(document.getElementById("GoogleZoom").value);
		
		map.setCenter(new GLatLng(GoogleX1, GoogleY1), GoogleZoom);
	}
}
// *** FIN FUNCIÓN UBICAR MAPA *** //


// *** FUNCIÓN MOSTRAR UBICACION *** //
// *** Parametros:			Direccion string.
// *** Devuelve:			void.
// *** Descripción:		Utiliza geocoder.
function MostrarUbicacion(Direccion) {
	geocoder.getLocations(Direccion, UbicarMapa);
}
// *** FIN FUNCIÓN MOSTRAR UBICACION *** //


// *** FUNCIÓN AGREGAR PROPIEDAD *** //
// *** Parametros:			GoogleX1 string, GoogleY1 string, MarcadorTexto string, IdPropiedad string, TipoPropiedad string.
// *** Devuelve:			void.
// *** Descripción:		Utiliza geocoder.
function AgregarPropiedad(GoogleX1, GoogleY1, MarcadorTexto, IdPropiedad, TipoPropiedad) {
	var IconoActual = new GIcon(baseIcon);
	IconoActual.image = "images/iconos/icono_" + TipoPropiedad + ".png";
	OpcionesMarcador = { icon:IconoActual };
	
	var Marcador = new GMarker(new GLatLng(GoogleX1, GoogleY1), OpcionesMarcador);
	GEvent.addListener(Marcador, "click", function() {
		Marcador.openInfoWindowHtml(MarcadorTexto);
	});
	
	// Guardo los marcadores en un array.
	Propiedades[IdPropiedad] = Marcador;
	
	map.addOverlay(Marcador);
}

function AgregarPropiedad2(GoogleX1, GoogleY1, MarcadorTexto, IdPropiedad, TipoPropiedad) {
	var IconoActual = new GIcon(baseIcon);
	IconoActual.image = "images/iconos/icono_" + TipoPropiedad + ".png";
	OpcionesMarcador = { icon:IconoActual };
	
	var Marcador = new GMarker(new GLatLng(GoogleX1, GoogleY1), OpcionesMarcador);
	GEvent.addListener(Marcador, "click", function() {
		Marcador.openInfoWindowHtml("Please Select State");
	});
	
	// Guardo los marcadores en un array.
	Propiedades[IdPropiedad] = Marcador;
	
	map.addOverlay(Marcador);
	
}

// *** FIN FUNCIÓN AGREGAR PROPIEDAD *** //


// *** MUESTRA PROPIEDAD *** //
// *** Parametros:			IdPropiedad string.
// *** Devuelve:			void.
// *** Descripción:		Abre ventana del marcador de la propiedad.
function MuestraPropiedad(IdPropiedad) {
	GEvent.trigger(Propiedades[IdPropiedad], "click");
}
// *** FIN MUESTRA PROPIEDAD *** //


// *** CAMBIAR MENU *** //
// *** Parametros:			Opcion string.
// *** Devuelve:			void.
// *** Descripción:		Función para un menú con submenues.
function cambiaMenu(Opcion) {
	if (Opcion != "") {
		var estadoActual = document.getElementById(Opcion).style.display;
		
		var Uls = document.getElementById("contenedor-menu").getElementsByTagName("ul");
		for (var i=0;i<Uls.length;i++) {
			var filtro = /^(mnu|subMnu)/;
			if (Uls.item(i).getAttributeNode("id").value == Opcion) {
				if (Opcion.indexOf("subMnu") != -1) {
					var Padre = Uls.item(i).parentNode;
					if (navigator.appName == "Microsoft Internet Explorer") {Padre = Padre.parentNode;}
					
					Padre.style.display = "";
					var Imagen = Padre.getAttributeNode("id").value;
				} else {
					var Imagen = Opcion;
				}
				
				if (estadoActual == "") {
					Uls.item(i).style.display = "none";
				} else {
					Uls.item(i).style.display = "";
				}
			} else if(filtro.test(Uls.item(i).getAttributeNode("id").value)) {
				Uls.item(i).style.display = "none";
			}
		}
		
		try {
			Imagen = Imagen.replace("mnu", "");
			document.getElementById("ImagenMenuFondo").src = "../img/mnuFondo_"+Imagen+".gif";
		} catch(e) {}
	}
}
// *** FIN CAMBIAR MENU *** //

