window.name='sitio';

var enviarContacto = function(sitio){
	var nombre = document.getElementById('contacto_nombre').value;
	if(nombre!=""){
		var email = document.getElementById('contacto_email').value;
		if(email!=""){
			var texto = document.getElementById('contacto_texto').value;
			if(texto!=""){
				var exito = funciones.enviarContacto(sitio,document.getElementById('idioma').value,nombre,email,document.getElementById('contacto_telefono').value,texto)
				if (exito.indexOf('Error')==-1) {
				document.getElementById('respuestacontacto').innerHTML='<span class="notice">'+ exito +'</span>';
				document.getElementById('FormularioContacto').innerHTML='';
				}
				else document.getElementById('respuestacontacto').innerHTML='<span class="error">'+ exito +'</span>';
			}else {
				focusField('contacto_texto');
				document.getElementById('respuestacontacto').innerHTML='<span class="error">Debe introducir una consulta</span>';
			}
		}else {
			focusField('contacto_email');
			document.getElementById('respuestacontacto').innerHTML='<span class="error">Debe introducir un email</span>';
		}
	}else {
		focusField('contacto_nombre');
		document.getElementById('respuestacontacto').innerHTML='<span class="error">Debe introducir un nombre</span>';
	}
}

var focusField = function(id){
	document.getElementById(id).style.backgroundColor="#fdd";
	document.getElementById(id).focus();
}

var suscribirseNewsletter = function(sitio){
	var nombre = document.getElementById('nombre').value;
	if(nombre!=""){
		var email = document.getElementById('email').value;
		if(email!=""){
			var exito = funciones.suscribirseNewsletter(sitio,email,nombre);
			if (exito.indexOf('Error')==-1) {
				document.getElementById('respuestasuscripto').innerHTML='<span class="notice">'+ exito +'</span>';
				document.getElementById('formulariosuscripto').innerHTML='';
			}
			else document.getElementById('respuestasuscripto').innerHTML='<span class="error">'+ exito +'</span>';
		}else document.getElementById('respuestasuscripto').innerHTML='<span class="error">Debe introducir un email</span>';
	}
	else document.getElementById('respuestasuscripto').innerHTML='<span class="error">Debe introducir un nombre</span>';
}

var enviarAmigo = function(cgiString,sitio){
	var nombre = document.getElementById('enviar_amigo_nombre').value;
	if(nombre!=""){
		var email = document.getElementById('enviar_amigo_email').value;
		if(email!=""){
			var captcha = document.getElementById('captcha').value;
			if(captcha.toLowerCase()== 'y04qw' || captcha.toLowerCase() == 'yo4qw'){
				var exito = funciones.enviarAmigo(cgiString,sitio,email,nombre);
				if (exito) {
					document.getElementById('enviar_amigo_respuesta').innerHTML='<span class="notice">Gracias, su sugerencia ha sido enviada</span>';
					document.getElementById('enviar_amigo_formulario').innerHTML='';
				}
				else document.getElementById('enviar_amigo_respuesta').innerHTML='<span class="error">Lo sentimos, hubo alg&uacute;n problema en el env&iacute;o del correo. Seguramente el correo no exista.</span>';
			}else document.getElementById('enviar_amigo_respuesta').innerHTML='<span class="error">Lo sentimos pero no has escrito bien la palabra de la imagen</span>';
		}else document.getElementById('enviar_amigo_respuesta').innerHTML='<span class="error">Debe introducir un email</span>';
	}
	else document.getElementById('enviar_amigo_respuesta').innerHTML='<span class="error">Debe introducir un nombre</span>';
}

var loginSocio = function(sitio){
	var email = document.getElementById('email_socio').value;
	if(email!=""){
		var password = document.getElementById('email_password').value;
		if(password!=""){
			var exito = funciones.loginSocio(sitio,email,password);
			if (exito.indexOf('Error')==-1) {
				document.getElementById('respuestasocio').innerHTML='<span class="notice">Se ha logeado correctamente.</span>';
				document.getElementById('SocioLogin').innerHTML= exito;
			}
			else document.getElementById('respuestasocio').innerHTML='<span class="error">'+ exito +'</span>';
		}
		else{
			focusField('email_password');
			document.getElementById('respuestasocio').innerHTML='<span class="error">Debe introducir un password</span>';
		}
	}
	else{
		focusField('email_socio');
		document.getElementById('respuestasocio').innerHTML='<span class="error">Debe introducir un email</span>';
	}
}

var logoutSocio = function(){
	funciones.logoutSocio();
	window.location.reload();
}

function toggleById(obj)
{
      var showDiv = "#"+obj;
      $(showDiv).toggle("slow");
}

function slideToggleById(obj)
{
      var showDiv = "#"+obj;
      $(showDiv).slideToggle("slow");
}

/*Google Maps*/
var createGoogleMap = function(file){
	if (GBrowserIsCompatible()) {
	    var map = new GMap2(document.getElementById("map"));
	    map.addControl(new GSmallMapControl());
	    map.addControl(new GMapTypeControl());
	    map.setCenter(new GLatLng(41.39116941071428, 2.170743942260742), 10);
	    var bounds = new GLatLngBounds();
	    GDownloadUrl(file, function(data) {
	      var xml = GXml.parse(data);
	      var markers = xml.documentElement.getElementsByTagName("marker");
	      for (var i = 0; i < markers.length; i++) {
	        var name = markers[i].getAttribute("name");
	    	var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
	        bounds.extend(point);
	        var marker = createMarker(point,name);
	        map.addOverlay(marker);
	      }
	      map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	    });
	}
}

function createMarker(point,name) {
	var icono = new GIcon();
	icono.shadow = "/recursos/imgs/shadow50.png";
	icono.iconSize = new GSize(20, 34);
	icono.shadowSize = new GSize(37, 34);
	icono.iconAnchor = point;
	icono.infoWindowAnchor = point;
	icono.infoShadowAnchor = point;
	icono.image = "/recursos/imgs/marker-red.png";
	var marker = new GMarker(point, {icon:icono});
	var html = "<b>" + name + "</b>";
	/*var marker = new GMarker(point, {icon:icono});*/
	GEvent.addListener(marker, "click", function () {
		marker.openInfoWindowHtml(html);
	});
return marker;
}

/*function createMarker(point, name, address, type) {
  var marker = new GMarker(point, customIcons[type]);
  var html = "<b>" + name + "</b> <br/>" + address;
  GEvent.addListener(marker, 'click', function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}*/
