// JavaScript Document
<!--Santiago - GMaps-->
//Santiago - Referencias para la API de GoogleMaps
//http://code.google.com/intl/es-ES/apis/maps/documentation/reference.html

//Santiago - Insertar GMaps paso a paso
//http://www.taringa.net/posts/ebooks-tutoriales/2098444/Google-Maps,-toda-la-info-para-ponerlos-en-tu-web_.html

	var map;
	
	function initialize() {
	//alert ('initialize()');
	if (GBrowserIsCompatible()) {
		//Santiago - Defino variable para centrar mapa y posicionar marcador
		//http://maps.google.com.ar/maps?f=q&source=s_q&hl=es&geocode=&q=sagrada+familia+359,+cordoba,+argentina&aq=&sll=-38.341656,-63.28125&sspn=34.259869,56.513672&ie=UTF8&hq=&hnear=Av+Sagrada+Familia+359,+C%C3%B3rdoba&ll=-31.395215,-64.23462&spn=0.00229,0.005493&z=18
		var pos = new GLatLng(-31.395215, -64.23462);
		
		//Santiago - Creo el objeto para instanciar al mapa y lo centro
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(pos, 14);

		//Santiago - Defino la interfase del mapa, dejo la que trae por defecto por los botones y el navegador
		var customUI = map.getDefaultUI();
		customUI.maptypes.hybrid = false;
		map.setUI(customUI);
		map.addControl(new GOverviewMapControl());

		//Santiago - Cambio el icono predeterminado por uno propio
		var icon = new GIcon();
		icon.image = "http://www.imcnet.com.ar/imagenes/gmaps_icn.png";
		icon.iconSize = new GSize(64, 64);
		//Santiago - Movemos la ubicacion del bullet para que no tape el nombre de las calles en el mapa (no esta centrado)
		//icon.iconAnchor = new GPoint(32, 32);
		icon.iconAnchor = new GPoint(32, 64);
		icon.infoWindowAnchor = new GPoint(0, 0);
		markerOptions = { icon:icon };
		
		//Santiago - Creo el marcador y la ventana emergente con el código html
		var marcador = new GMarker(pos, markerOptions);
		var cont = '<img src="http://www.imcnet.com.ar/imagenes/gmaps_img.jpg" align="left" /><p style="font-family:Trebuchet MS, Arial, Helvetica, sans-serif; font-size:11px; color:#666; text-indent: 40px;text-align:justify;">Nacimos con la consigna de ofrecer la mejor asistencia médica integral, y cardiológica en particular, haciendo hincapié en la prevención y contención de los pacientes, incorporando la tecnología más avanzada, promoviendo la formación de profesionales y el desarrollo de la investigación.</p>';
		
		map.openInfoWindowHtml(pos, cont, {maxWidth: '420'});

		GEvent.addListener(marcador,"click", function() {map.openInfoWindowHtml(pos, cont, {maxWidth: '420'});});
		map.addOverlay(marcador);
		
		//Santiago - Agregamos el codigo necesario para hacer la busqueda de recorridos
		gdir = new GDirections(map, document.getElementById("directions"));
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);
		
		//Santiago - Elimino el Zoom mediante la rueda del mouse para que el usuario pueda desplazarse en la página sin inconvenientes
		map.disableScrollWheelZoom();
		//alert (map.scrollWheelZoomEnabled(true));
		}
	}
	
	//Santiago - Agregamos el codigo necesario para hacer la busqueda de recorridos
		var map;
		var gdir;
		var geocoder = null;
		var addressMarker;
		
		function setDirections(fromAddress, cordenadas) {
			destino_final = 'Sagrada Familia 359, Cordoba, Argentina';
			idioma = 'es';
			if (fromAddress != "" & cordenadas == false) {
				document.getElementById("directions").style.height = "480px";
				/*alert("busca SIN coordenadas, por direccion");
				alert(fromAddress);*/
				map.closeInfoWindow();
				gdir.load("from: " + fromAddress + ", Cordoba, Argentina" + " to: " + destino_final,{ "locale": idioma});
			}
			else if (fromAddress != "" & cordenadas == true) {
				document.getElementById("directions").style.height = "480px";
				/*alert("busca CON coordenadas, por coordenadas");
				alert(fromAddress);*/
				map.closeInfoWindow();
				gdir.load("from: " + fromAddress + " to: " + destino_final,{ "locale": idioma});
			}
			else {
				alert("Para utilizar el marcador de recorridos, debe ingresar una dirección de inicio");
			}
		}
		
		function handleErrors() {
			if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
			alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
			alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
			alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
			//else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
			//alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_BAD_KEY)
			alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
			else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
			alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
			else alert("An unknown error occurred.");
		}
		
		function onGDirectionsLoad() { 
		// Use this function to access information about the latest load()
		// results.
		// e.g.
		// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
		// and yada yada yada...
		}
	//Santiago - Agregamos el codigo necesario para hacer la busqueda de recorridos

<!--Santiago - GMaps-->

<!--Santiago - Cambia color de celdas-->
	function cambiar_color_over(celda){celda.style.backgroundColor="#CCCCCC"}
	function cambiar_color_out(celda){celda.style.backgroundColor="#F2F2F2"}
<!--Santiago - Cambia color de celdas-->
