
var map;
var geocoder;

function cambiarLocal(id) {
	var local = locales[id];
	$('#local_horario').html(local.horario);
	$('#local_nombre').html(local.nombre + "<span></span>");
	$('#local_foto img').attr("src", local.foto);
	
	/*$('#map_canvas img').attr("src", 'http://maps.google.com/maps/api/staticmap?center='+ local.mapa +'&zoom=15&size=318x180&maptype=roadmap&markers=size:med|color:red|'+ local.mapa +'&sensor=false');
	$('#map_canvas a').attr("href", 'http://maps.google.com/maps?q='+ local.mapa);*/
	
	findLocation(local.mapa);
}


function initialize() {
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(-34.594782,-58.429254), 15);
  //map.openInfoWindow(map.getCenter(), document.createTextNode("Av.Rivadavia 6862,Buenos Aires"));
  geocoder = new GClientGeocoder();
  var point = new GLatLng(-34.594782,-58.429254);
  map.addOverlay(new GMarker(point)); 
}

// 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) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
	alert("Sorry, we were unable to geocode that address");
  } else {
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
	marker = new GMarker(point);
	map.addOverlay(marker);
	map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]));
	GEvent.addListener(marker, "click", function() {
		window.open('http://maps.google.com/maps?q='+document.forms[0].q.value,"_blank");
	});
	//marker.openInfoWindowHtml(place.address);
  }
}

// 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() {
  var address = document.forms[0].q.value;
  geocoder.getLocations(address, addAddressToMap);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  document.forms[0].q.value = address;
  showLocation();
}



function cambiarFormulario(id) {
	//hash = window.location.hash;
	//id = hash.replace("#", "");
	
	$("#contacto nav li").each(function () {
		/*$(this).removeClass('mayoristasactivo');
		$(this).removeClass('franquiciasactivo');
		$(this).removeClass('sugerenciasactivo');
		$(this).removeClass('marketingactivo');*/
		$(this).removeClass('activo');
	});
	
	$("#formulario form").each(function () {
		if ($(this).attr('id') != id) {
			$(this).addClass('ocultar');
		} else {
			$(this).removeClass('ocultar');
			$(this).addClass('mostrar');
		}
	});

	$('#contacto nav .'+id).parent().addClass('activo');
	$('.mensaje_error').attr('style', 'display:none;');
}

/*MUESTRA Y OCULTA DIVS*/
function oculta(id){
	 var elDiv = document.getElementById(id);
	 elDiv.style.display='none';
}
function muestra(id){
	 var elDiv = document.getElementById(id);
	 elDiv.style.display='block';	 
}

/*****************/
function onFoco(yo,texto){
	if ( $(yo).val() == texto ) {
		$(yo).val("");
		$(yo).removeClass("onfoco");
	}
}
function onBlur(yo,texto){
	if ( $(yo).val() == "") {
		$(yo).val(texto);
		$(yo).addClass("onfoco");
	}
}


