// JavaScript Document
function isLegal(txt) {
var invalids = "#$^&*~<>/\|"
	for(i=0; i<invalids.length; i++) {
		if(txt.indexOf(invalids.charAt(i)) >= 0 ) {
		return false;}
     }
return true;}

function validaEmail(checkStr)
{var nI, sS, nN, nP;
 // Arroba ...
 sS = "@"; nN = 0; nP = 0;
 for(nI = 0; nI < checkStr.length; nI++)
 { if(checkStr.charAt(nI) == sS) 
  { nN++; nP = nI;
  }
 }
 if(nN == 0) return (false);
 if(nN > 1)  return (false);
 var nPArroba = nP;
 // Punto ...
 sS = "."; nN = 0; nP = 0;
 for(nI = 0; nI < checkStr.length; nI++)
 { if(checkStr.charAt(nI) == sS) 
  { nN++; nP = nI;
  }
 }
 if(nN == 0) return (false);
 var nPPunto = nP;
 // Posicion Arroba/Punto ...
 if(nPArroba > nPPunto) return (false);
 //
 return (true);
}

function validarfrmSubscribeCat() {
	var nom = document.getElementById("frmSubscribe.nom").value;
	var cognom = document.getElementById("frmSubscribe.cognom").value;
	var mail = document.getElementById("frmSubscribe.mail").value;

	if (nom == "") { 
		alert("Ha d'especificar un nom.")
		return false;}

	if (nom != "" ) { 
		if (isLegal(nom)==false) {
			alert("Caracters no permessos: #$^*~<>/\|");
			return false;}
	}

	if (cognom == "") { 
		alert("Ha d'especificar els cognoms.")
		return false;}

	if (cognom != "" ) { 
		if (isLegal(cognom)==false) {
			alert("Caracters no permessos: #$^*~<>/\|");
			return false;}
	}

	if (mail == "") { 
		alert("Ha d'indicar una direcció de correu electrònic.")
		return false;}

	if (mail != "") { 
		if (validaEmail(mail)==false) {
			alert("Format de correu electrònic no vàlid.");
			return false;}
	}

return true;}

function validarfrmSubscribeEsp() {
	var nom = document.getElementById("frmSubscribe.nom").value;
	var cognom = document.getElementById("frmSubscribe.cognom").value;
	var mail = document.getElementById("frmSubscribe.mail").value;

	if (nom == "") { 
		alert("Debe especificar un nombre.")
		return false;}

	if (nom != "" ) { 
		if (isLegal(nom)==false) {
			alert("Caracteres no permitidos: #$^*~<>/\|");
			return false;}
	}

	if (cognom == "") { 
		alert("Debe especificar los apellidos.")
		return false;}

	if (cognom != "" ) { 
		if (isLegal(cognom)==false) {
			alert("Caracteres no permitidos: #$^*~<>/\|");
			return false;}
	}

	if (mail == "") { 
		alert("Debe especificar una dirección de correo electrónico.")
		return false;}

	if (mail != "") { 
		if (validaEmail(mail)==false) {
			alert("Formato  de correo electrónico no válido.");
			return false;}
	}

return true;}

//jQuery for main menu
$(document).ready(function() {

	/*Funció accordion desplegable*/
	$("#menu h1").click(function(){
		$(this).next("ul").slideToggle("fast")
		.siblings("ul:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h1").removeClass("active");
	});

	
	/* animació sobre link per cada apartat*/
	//milliseconds
	var fadeInDuration = 75; 
	var fadeOutDuration = 25; 

	$('#club li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});

	$('#instalaciones li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});

	$('#servicios li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});

	$('#campo li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});

	$('#actvDeportiva li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});

	$('#infoSocios li a').hover(function() {
	 $(this).animate({ paddingLeft: '15px' }, fadeInDuration);
	 $(this).children('span').show().animate({ left: -10 }, fadeInDuration);
	}, function() {
	 $(this).animate({ paddingLeft: '10px' }, fadeInDuration);
	 $(this).children('span').animate({ left: -25 }, fadeOutDuration).fadeOut(fadeOutDuration); 
	});
});