/* Listado de funciones java script */

function limpiarBuscador(){
	document.getElementById('buscador').value = "";
}

function ponerBuscador(){
	document.getElementById('buscador').value = "Buscador";
}

function activarPsicoterapia(){
	// Función para mostrar el menú de Psicoterapia
	
	if (document.getElementById('itemsLateralPsicoterapia').style.display == 'block'){
			document.getElementById('itemsLateralPsicoterapia').style.display = 'none';
		document.getElementById('difuminadoMenuPisoterapiaCorto').style.display = 'none';	
	}else{
		document.getElementById('itemsLateralPsicoterapia').style.display = 'block';
		document.getElementById('difuminadoMenuPisoterapiaCorto').style.display = 'block';	
	}
	document.getElementById('itemsLateralFormacion').style.display = 'none';
	document.getElementById('difuminadoMenuFormacionCorto').style.display = 'none';
	document.getElementById('itemsLateralPeritajesCorto').style.display = 'none';
	document.getElementById('difuminadoMenuPeritajesCorto').style.display = 'none';
}

function activarFormacion(){
	// Función para mostrar el menú de formación
	if (document.getElementById('itemsLateralFormacion').style.display == 'block'){
		document.getElementById('itemsLateralFormacion').style.display = 'none';
		document.getElementById('difuminadoMenuFormacionCorto').style.display = 'none';
	}else{
		document.getElementById('itemsLateralFormacion').style.display = 'block';
		document.getElementById('difuminadoMenuFormacionCorto').style.display = 'block';
	}
	document.getElementById('itemsLateralPeritajesCorto').style.display = 'none';
	document.getElementById('difuminadoMenuPeritajesCorto').style.display = 'none';
	document.getElementById('itemsLateralPsicoterapia').style.display = 'none';
	document.getElementById('difuminadoMenuPisoterapiaCorto').style.display = 'none';
}

function activarPeritajes(){
	// Función para mostrar el menú de peritajes
	if (document.getElementById('itemsLateralPeritajesCorto').style.display == 'block'){
		document.getElementById('itemsLateralPeritajesCorto').style.display = 'none';
		document.getElementById('difuminadoMenuPeritajesCorto').style.display = 'none';
	}else{
		document.getElementById('itemsLateralPeritajesCorto').style.display = 'block';
		document.getElementById('difuminadoMenuPeritajesCorto').style.display = 'block';
	}
	document.getElementById('itemsLateralFormacion').style.display = 'none';
	document.getElementById('difuminadoMenuFormacionCorto').style.display = 'none';
	document.getElementById('itemsLateralPsicoterapia').style.display = 'none';
	document.getElementById('difuminadoMenuPisoterapiaCorto').style.display = 'none';
}

// Funciones para cargar los videos de youtube

function activarVideo(seleccion){

	var video = "http://www.youtube.com/embed/";
	var iframe, scroll;	
	
	// Solución para todos los navegadores 
	// document.documentElement.scrollTop solo funciona en Firefox
	// Añadiendo document.body que funciona en chrome obtenemos el scroll
	scroll = document.documentElement.scrollTop + document.body.scrollTop + 100;
	document.getElementById('contenedorVideo').style.marginTop = scroll + 'px';
	switch (seleccion){
		case 0:
			video = video + "HAKxcrqaeB8";
			break;
		case 11:
			video = video + "qpo4xE7ekyA";
			infantil = document.getElementById('videosRelajacionInfantil').offsetTop;
			break;
		case 12:
			video = video + "rpwhYbeHJJw";
			infantil = document.getElementById('videosRelajacionInfantil').offsetTop;
			break;
		case 13:
			video = video + "UkLfyZWDLP0";
			infantil = document.getElementById('videosRelajacionInfantil').offsetTop;
			break;
		case 14:
			video = video + "uAKAYX19Mdo";
			infantil = document.getElementById('videosRelajacionInfantil').offsetTop;
			break;
		case 21:
			video = video + "yd50qMhAQkQ";
			tecnicaRelajacion = document.getElementById('videosTecnicaRelajacion').offsetTop;
			break;
		case 22: 
			video = video + "akbr59YbGd4";
		 	tecnicaRelajacion = document.getElementById('videosTecnicaRelajacion').offsetTop;
			break;
		case 31: 
			video = video + "QXqCCcdnZ-A";
			break;
		case 32: 
			video = video + "NitCi2sOm-4";
			break;
		case 33: 
			video = video + "v3Xd5luqFPk";
			break;
	}
	
	iframe = "<iframe title='YouTube video player' type='text/html' width='500' height='350' src= '" + video + "' frameborder='0' allowFullScreen></iframe>"
	
	document.getElementById('video').innerHTML = iframe;
	
	document.getElementById('contenedorVideo').style.display = 'block';
}

function cerrarVideo(){
	// Función para cerrar el video de youtube
	document.getElementById('contenedorVideo').style.display = 'none';
	document.getElementById('video').innerHTML = "<img src = '../imagenes/ajax-loader.gif' />"
}

function validarFormulario(){
	// Función para validar el formulario
	var mail, nombre, copia, correcto;
	
	document.getElementById('errorFormulario').innerHTML = ""
	
	var patronMail = /(\w|\-)+([\.]?(\w|\-)+)*@(\w)+([\.]?(\w|\-)+)*$/
	var devolver = false;
	
	mail = document.getElementById('email').value;
	copia = document.getElementById('copiaEnvio').checked;
	nombre = document.getElementById('nombre').value;
	telefono = document.getElementById('telefono').value;
	
	if (nombre == ""){
		document.getElementById('errorFormulario').innerHTML = "<strong>El Nombre no puede ser vacío</strong>";
	}else{
		if (mail !=""){	
			correcto = mail.search(patronMail);
			if (correcto == 0){
				devolver = true;
			}else{
				devolver = false;
				document.getElementById('errorFormulario').innerHTML = "<strong>Formato incorrecto en el E-mail.</strong>";
			}
		}else{
			if (telefono == ""){
				document.getElementById('errorFormulario').innerHTML = "<strong>El teléfono o la dirección son obligatorios.</strong>";
			}
			if (copia == true){
				document.getElementById('errorFormulario').innerHTML = "<strong>La dirección E-mail no puede estar vacía para enviar copia.</strong>";
			}
		}
	}
	
	
	return devolver
}
