// Valida el formulario de recomendación
var map = null;
var geocoder = null;
function EnviaRecomendacion(){
	error=0 ;
	campos="" ;
	frm=document.forms["recomendar"]
	if(frm.elements["rem_email"].value=="") 
	{
		error+=1 ;
		if(campos!="")
			campos+="\n" ;
		campos+="email remitente" ;
	}
	if(frm.elements["dest1_email"].value=="" && frm.elements["dest2_email"].value=="" && frm.elements["dest3_email"].value=="") 
	{
		error+=1 ;
		if(campos!="")
			campos+="\n" ;
		campos+="email destinatario 1 o email destinatario 2 o email destinatario 3" ;
	}
	if(error==0)
		frm.submit() ;
	else
	{
		if(error==1)
			alert("El campo\n" + campos + "\nes de cumplimentación obligatoria.") ;
		else
			alert("Los campos\n" + campos + "\nson de cumplimentación obligatoria.") ;
	}
}

window.onload = function () {
	if (document.getElementById('menu_lateral')) {
	
		var menu=document.getElementById('menu_lateral');
		var opciones=menu.getElementsByTagName('li');
		
		for (i=0;i<opciones.length; i++) {
	
			opciones[i].onmouseover=function() {
			
				this.className+=' over';
				
				
			}
			opciones[i].onmouseout=function() {
				this.className=this.className.split('over').join('');
				;
			}
		}
	}
	if (document.getElementById('imgs_instalaciones')) {
		var imagenes=document.getElementById('imgs_instalaciones');
		var fotos=imagenes.getElementsByTagName('a');
		
		for (i=0;i<fotos.length;i++) {
			
			fotos[i].onclick=function() {
				var id=this.id.split('enlace').join('');
			
				for (j=1;j<=fotos.length;j++) {
					document.getElementById('instalacion'+j).style.display='none';
				}
				document.getElementById('instalacion'+id).style.display='block';
				
				return false;
			}
		}
		document.getElementById('instalacion1').style.display='block';
	}
	if (document.getElementById("map")) {
	if (GBrowserIsCompatible()) {
		//alert('eh');
        map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
showAddress ('Calle Velazquez 25 28001 Madrid');
showAddress2 ('Calle Jorge Juan 19 28001 Madrid');
      }
	}
	if (document.getElementById("formu_contacto")) {
	
		var email=document.getElementById('email');
		if (email.checked) {
			document.getElementById('contacto_email').style.display='block';
		}
		
		var direccion=document.getElementById('direccion');
		var telefono=document.getElementById('telefono');
		if (direccion.checked) {
			document.getElementById('contacto_direccion').style.display='block';
		}
		if (telefono.checked) {
			document.getElementById('contacto_telefonico').style.display='block';
		}
		email.onclick = function () {
			if (this.checked) {
				document.getElementById('contacto_email').style.display='block';
			}
			else {
				document.getElementById('contacto_email').style.display='none';
			}
		}
		direccion.onclick = function () {
			if (this.checked) {
				document.getElementById('contacto_direccion').style.display='block';
			}
			else {
				document.getElementById('contacto_direccion').style.display='none';
			}
		}
		telefono.onclick = function () {
			if (this.checked) {
				document.getElementById('contacto_telefonico').style.display='block';
			}
			else {
				document.getElementById('contacto_telefonico').style.display='none';
			}
		}
		
		
	}
	if (document.getElementById('formu_oferta') && (document.getElementById('centros').value!='')) {
		
		var cadena_centros=
		document.getElementById('centros').value;
		
		var aux=cadena_centros.split('?%?');
	
		for (i=0;i<aux.length;i++) {
		var n_centro = document.getElementById('nuevo_centro')
		var aux2=aux[i].split('|#|');
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Tipo de vía: '+aux2[0]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Nombre de vía: '+aux2[1]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Número: '+aux2[2]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Piso: '+aux2[3]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Puerta: '+aux2[4]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Código Postal: '+aux2[5]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Ciudad: '+aux2[6]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro)
		var p=document.createElement('p');
		p.setAttribute("style","margin-bottom:0; margin-left:50px");
		var texto=document.createTextNode('Provincia: '+aux2[7]);
		p.appendChild(texto);
		document.getElementById('listado_centros').insertBefore(p,n_centro);
		var capa=document.createElement('div');
		capa.setAttribute('class','hr');
		var sep=document.createElement('hr');
		document.getElementById('listado_centros').insertBefore(capa,n_centro);
		}
	}
	if (document.getElementById('formu_cita')) {
		var boton=document.getElementById('compania');
		boton.onclick=function() {
			if (this.checked) {
				document.getElementById('empresa').style.display='block';
			}
		}
		var boton2=document.getElementById('particular');
		boton2.onclick=function() {
			if (this.checked) {
				document.getElementById('empresa').style.display='none';
			}
		}
		if (boton.checked) {
			document.getElementById('empresa').style.display='block';
		}
	}
}

function createMarker(point, number) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("<b>" + number + "</b>");
  });
  return marker;
}

function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 15);
        var marker = new GMarker(point);
       map.addOverlay(createMarker(point,'Oficina 1, Calle Velazquez 25'));
        //marker.openInfoWindowHtml("<b>Gabinete Médico Velázquez<b>");
      }
    }
  );
}
function showAddress2(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 15);
        var marker = new GMarker(point);
       map.addOverlay(createMarker(point,'Oficina 2, Calle Jorge Juan 19'));
        //marker.openInfoWindowHtml("<b>Gabinete Médico Velázquez<b>");
      }
    }
  );
}