

var capas = new Array('submeventos','submgrupo');

var TELEFERICO = {
	
	init : function()
	 {		 
		 if(document.getElementById('info-disclaimer'))
		 {
		 	document.getElementById('info-disclaimer').onclick = function()
		 	{
		 		TELEFERICO.popup();
				return false;
		 	}//fin if
		 }//fin if		
		if(document.getElementById('info-disclaimer2'))
		 {
		 	document.getElementById('info-disclaimer2').onclick = function()
		 	{
		 		TELEFERICO.popup();
				return false;
		 	}//fin if
		 }//fin if		
		 
		  //NEWSLETTERS
		 if(document.getElementById('formuNewslettersNoticias'))
		 {
		 	//Guardamos en variables algunos campos para un código más legible
			
		 	var nac_diaNot  = document.getElementById('cmbFechaNacDayNot');
		 	var nac_mesNot  = document.getElementById('cmbFechaNacMonthNot');
		 	var nac_agnoNot = document.getElementById('cmbFechaNacYearNot');
		 	var vis_diaNot  = document.getElementById('cmbUltVistDayNot');
		 	var vis_mesNot  = document.getElementById('cmbUltVistMonthNot');
		 	var vis_agnoNot = document.getElementById('cmbUltVistYearNot');					
			
			var telefonoNot = document.getElementById('txtTelefonoNot');
		 	var movilNot    = document.getElementById('txtMovilNot');		 	

		 	telefonoNot.onkeypress = TELEFERICO.dejarMeterTelefono;
		 	movilNot.onkeypress    = TELEFERICO.dejarMeterTelefono;

		 	//Envio del fomulario
		 	document.getElementById('btnEnvNewsNoti').onclick = function()
		 	{
		 		var msg = '';
		 		
		 		var camposObligatorios = new Array('txtEmailNot', 'E-mail', 'email');		 		
		 		
		 		msg = TELEFERICO.kValida(camposObligatorios);
	 		   
				if(!TELEFERICO.comprobarFecha(nac_diaNot.value, nac_mesNot.value, nac_agnoNot.value))
					msg += 'La fecha de nacimiento debe ser correcta. \n';
				else
				{		 		
		
					var edad = TELEFERICO.calcularEdad(nac_diaNot.value, nac_mesNot.value, nac_agnoNot.value);
			
					if(edad < 14) 
					{				
						msg += 'Debes tener mas de 14 años.\n';
					}//fin if
					
				
				}//fin else				   
				/*if(!TELEFERICO.comprobarFecha(vis_diaNot.value, vis_mesNot.value, vis_agnoNot.value))
					msg += 'La fecha de última visita debe ser correcta. \n';*/
		 			
		 		if(msg)
		 			alert(msg);
		 		else
		 			document.getElementById('formuNewslettersNoticias').submit();
		 			//alert('Todo bien');
		 	}//fin funcion


		 	//Guardamos en variables algunos campos para un código más legible
		 	//Ofertas
		 	var nac_diaOfer  = document.getElementById('cmbFechaNacDayOfer');
		 	var nac_mesOfer  = document.getElementById('cmbFechaNacMonthOfer');
		 	var nac_agnoOfer = document.getElementById('cmbFechaNacYearOfer');

		 	//Envio del fomulario
		 	document.getElementById('btnEnvNewsOfert').onclick = function()
		 	{		 		
		 		var msg = '';

		 		var camposObligatorios = new Array('txtEmailOfer', 'E-mail', 'email',
		 										   'txtCpOfer', 'Código postal', 'numero',
		 										   'cmbPaisOfer', 'País de residencia', '');		 										   		 		

				msg = TELEFERICO.kValida(camposObligatorios);
				
				if(!TELEFERICO.comprobarFecha(nac_diaOfer.value, nac_mesOfer.value, nac_agnoOfer.value))
					msg += 'La fecha de nacimiento debe ser correcta. \n';
				else
				{		 		
		
					var edad = TELEFERICO.calcularEdad(nac_diaOfer.value, nac_mesOfer.value, nac_agnoOfer.value);
			
					if(edad < 14) 
					{				
						msg += 'Debes tener mas de 14 años.\n';
					}//fin if
					
				
				}//fin else
		 		if(msg)
		 			alert(msg);
		 		else
		 			document.getElementById('formuNewslettersOfertas').submit();
		 			//alert('Todo bien');
		 	}//fin funcion		 	
		 	

		 }//FIN NEWSLETTERS NOTICIAS		  
		 
		 
		 //ENVIAR A UN AMIGO
		 if(document.getElementById('formuEnviarAmigo'))
		 {
		  	//Envio del fomulario
		 	document.getElementById('btnEnvNewsOfert').onclick = function()
		 	{		 		
		 		var msg = '';

		 		var camposObligatorios = new Array('txtEmail', 'E-mail', 'email',
		 										   'txtNombre', 'Nombre', '');		 										   		 		

				msg = TELEFERICO.kValida(camposObligatorios);
		 		
		 		var contEmailAmigo = 0;
		 		
		 		for(var i = 1; i < 5; ++i)
		 		{
		 			if(document.getElementById('txtEmailAmigo_' + i).value == '')
		 				++contEmailAmigo;
		 			else  if (!TELEFERICO.comprobarEmail(document.getElementById('txtEmailAmigo_' + i).value))
		 				msg += 'El correo de tu amigo '+ i +' debe ser correcto. \n';
		 		}//fin for
		 				
		 		if(contEmailAmigo == 4)
		 			msg += 'Debes introducir al menos el e-mail de un amigo. \n';
		 		
		 		if(msg)
		 			alert(msg);
		 		else
		 			document.getElementById('formuEnviarAmigo').submit();
		 			//alert('Todo bien');
		 	}//fin funcion
		 }//FIN ENVIAR A UN AMIGO			 
		 
		 
		 //ENCUESTA
		 if(document.getElementById('formuEncuesta'))
		 {
		 	var nac_dia  = document.getElementById('cmbFechaNacDay');
		 	var nac_mes  = document.getElementById('cmbFechaNacMonth');
		 	var nac_agno = document.getElementById('cmbFechaNacYear');

			
			//Envio del fomulario
		 	document.getElementById('btnEnvEncuesta').onclick = function()
		 	{		 		
		 		var msg = '';

		 		var camposObligatorios = new Array('txtEmail', 'E-mail', 'email',
		 										   'txtNombre', 'Nombre', '',
		 										   'txtApellido1', 'Primer apellido', '');		 										   		 		

		 		msg = TELEFERICO.kValida(camposObligatorios);			
								    		   
				if(!TELEFERICO.comprobarFecha(nac_dia.value, nac_mes.value, nac_agno.value))
					msg += 'La fecha de nacimiento debe ser correcta. \n';
		 		else
				{		 		
		
					var edad = TELEFERICO.calcularEdad(nac_dia.value, nac_mes.value, nac_agno.value);
			
					if(edad < 14) 
					{				
						msg += 'Debes tener mas de 14 años.\n';
					}//fin if
					
				
				}//fin else
		 		if(msg)
		 			alert(msg);
		 		else
		 			document.getElementById('formuEncuesta').submit();
		 			//alert('Todo bien');
		 	}//fin funcion		 
		 }//FIN ENCUESTA
		 
		 
		 //ENVIAR OPINIÓN		 
		 if(document.getElementById('formuOpinion'))
		 {			
			//meter esto en una funcion
			document.getElementById('txtOpinion').onkeypress = function(e) {									  
			  
				/*if (this.value.length > 65000) 
				{
					var key;
					var keychar;

					if (window.event)
						key = window.event.keyCode;
					else if (e)
						key = e.which;
					else
						return true;
					
					keychar = String.fromCharCode(key);

					// control keys
					if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
						return true;

					return false;
				}//fin if*/
				
				return true; 
			}//fin función
			
			document.getElementById('txtOpinion').onkeyup = function(e) {
			
				if(this.value.length > 65000)
					this.value = this.value.substr(0,65000);
			}
			
			
			//Guardamos en variables algunos campos para un código más legible
		 	var nac_dia  = document.getElementById('cmbFechaNacDay');
		 	var nac_mes  = document.getElementById('cmbFechaNacMonth');
		 	var nac_agno = document.getElementById('cmbFechaNacYear');
		 	var vis_dia  = document.getElementById('cmbUltVistDay');
		 	var vis_mes  = document.getElementById('cmbUltVistMonth');
		 	var vis_agno = document.getElementById('cmbUltVistYear');			
			
			//Envio del fomulario
			document.getElementById('btnEnvOpinion').onclick = function()
			{
		 		var msg = '';

		 		var camposObligatorios = new Array('txtEmail', 'E-mail', 'email',
		 										   'txtNombre', 'Nombre', '',
		 										   'txtApellido1', 'Primer apellido', '',
												   'txtApellido2', 'Segundo apellido', '',
		 										   'txtOpinion', 'Opinión', '');		 										   		 		

		 		msg = TELEFERICO.kValida(camposObligatorios);

				if(!TELEFERICO.comprobarFecha(nac_dia.value, nac_mes.value, nac_agno.value))
					msg += 'La fecha de nacimiento debe ser correcta. \n';
				else
				{		 		
		
					var edad = TELEFERICO.calcularEdad(nac_dia.value, nac_mes.value, nac_agno.value);
			
					if(edad < 14) 
					{				
						msg += 'Debes tener mas de 14 años.\n';
					}//fin if
					
				
				}//fin else	

				/*if(!TELEFERICO.comprobarFecha(vis_dia.value, vis_mes.value, vis_agno.value))
					msg += 'La fecha de última visita debe ser correcta. \n';
*/		 		
		 		if(msg)
		 			alert(msg);
		 		else
		 			document.getElementById('formuOpinion').submit();
		 			//alert('Todo bien');	 				 	
			}//fin función 	 	
		 }//FIN ENVIAR OPINIÓN
	 	
	 	
	 	
	 	
	 	
	 	
	 	TELEFERICO.ocultaCapas();
	 	
		var menu_links = document.getElementById('listamenu').getElementsByTagName('a');
		
		if (document.getElementById('flash-home')) {
			var cpflash = document.getElementById('flash-home');
		}
		else {
			var cpflash = document.getElementById('flash-centro');
		}
		
		cpflash.onmouseover = function() { TELEFERICO.ocultaCapas(); }
		 

		/**
		 * Esto añade el evento a cada elemento del menu
		 */
		for(var mn=0; mn<menu_links.length; ++mn)
		 {
			menu_links[mn].onmouseover = function()
			 {
				TELEFERICO.ocultaCapas();
				switch(this.id)
				 {
					case 'a-eventos':		TELEFERICO.muestraCapa('submeventos');
		 	 	 							break;	
		 	 	 	case 'a-grupo':		TELEFERICO.muestraCapa('submgrupo');
		 	 	 		break;														
		 	 	 }

				return false;
			 }
		 }
	},
	 
	muestraCapa : function(capa)
	 {
		document.getElementById(capa).style.display = 'block';
	 },
	 
	ocultaCapas : function()
	 {
	 	for(var cp=0; cp<capas.length; ++cp)
	 	 	document.getElementById(capas[cp]).style.display = 'none';
	 },
	 
	 popup : function()
	 {
		window.open('../sites/info-huella.html', '_blank', 'width=400,height=300'); 
		return false;
	 }, 	 
	 
	dejarMeterEntero : function(e)
	{			
		var key;
		var keychar;
		
		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
				
		keychar = String.fromCharCode(key);
		
		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
			return true;

		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;
		else
			return false;			
	}, //fin funcion
	
 	validarEntero : function(valor)
 	{
     	valor = parseInt(valor);

    	if (isNaN(valor)) 
       		return false;
    	else            
       		return true;      
	}, //fin funcion
	
	comprobarFecha : function(dia, mes, agno)
	{
		var febrero;
				
		if(!TELEFERICO.validarEntero(dia) || !TELEFERICO.validarEntero(mes) || !TELEFERICO.validarEntero(agno))
			return false;
				
		if(mes == 2)
		{			
			if(agno % 4 != 0)
				febrero = 28;
			else
			{
				if(agno % 100 == 0)
				{
					if(agno % 400 == 0)					
						febrero = 29;				
					else					
						febrero = 28;
				}//fin if
				else
					febrero = 29;
			}//fin else

			if(dia > febrero)
				return false;
		}//fin if
				
		if(mes < 1 || mes > 12)
			return false;
		else if((mes == 4 || mes == 6 || mes == 9 || mes == 11) && (dia > 30 || dia < 1))
			return false;
		else if((mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12) && (dia > 31 || dia < 1))
			return false;
					
		return true;			
	}, //fin funcion
	
	calcularEdad : function(dia, mes, agno)
	{
		hoy = new Date();
	
		fechaIntroducida = new Date (agno, mes, dia)	
	
		//resto los a�os de las dos fechas
		edad=hoy.getFullYear() - agno - 1; //-1 porque no se si ha cumplido a�os ya este a�o

		//si resto los meses y me da menor que 0 entonces no ha cumplido a�os. Si da mayor si ha cumplido
		if (hoy.getMonth() + 1 - mes < 0)
		{	//+ 1 porque los meses empiezan en 0
			return edad;
		}//fin if
		if (hoy.getMonth() + 1 - mes > 0)
		{
			edad++;
			return edad;
		}//fin if
			
		//entonces es que eran iguales. miro los dias
		//si resto los dias y me da menor que 0 entonces no ha cumplido a�os. Si da mayor o igual si ha cumplido
			
		if (hoy.getUTCDate() - dia >= 0)
		{
			edad++;
			return edad;
		}//fin if

		return edad;
	}, //fin funcion
	
    comprobarEmail : function(email)
	{		
		var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		
		if (filter.test(email))
			return true;
		else
			return false;
	}, //fin funcion
	
	kValida : function(cObligatorios)
	{
		 var msg = '';	 
		 
		 /************** Trim de campos *********************/
		 
		 var cTodos = document.getElementsByTagName('input');
		 
		 for(var i = 0; i < cTodos.length; ++i)
		 	cTodos[i].value = cTodos[i].value.replace(/^\s+|\s+$/g, '');
		 			
		 cTodos = document.getElementsByTagName('textarea');
		 		
		 for(var i = 0; i < cTodos.length; ++i)
		 	cTodos[i].value = cTodos[i].value.replace(/^\s+|\s+$/g, '');
		 	
		 /************** Fin trim de campos *****************/
		 		
		 for(var i = 0; i < cObligatorios.length; i += 3)
		 {		 	
		 	if(document.getElementById(cObligatorios[i]).value.length == 0)
		 		msg += 'Debes rellenar el campo \"' + cObligatorios[i + 1] + '\". \n';
		 	else if(cObligatorios[i + 2] == 'email')
		 	{
				if(!TELEFERICO.comprobarEmail(document.getElementById(cObligatorios[i]).value))
					msg += 'El campo \"' + cObligatorios[i + 1] + '\" debe ser correcto. \n'; 	
		 	}//fin else if
		 }//fin for
		 
		 
		 /******* VALIDACIONES ESPECIFICAS *************/
		 
		  //Validamos los telefonos
		 var tlfs = new Array('txtTelefono', 'teléfono',
		 					  'txtMovil', 'móvil');
		 
		
		 for(i = 0; i < tlfs.length; i += 2)
		 {
			 if(document.getElementById(tlfs[i]))
			 {
				if(document.getElementById(tlfs[i]).value.length > 0 &&
		 		    document.getElementById(tlfs[i]).value.length < 6)
		 			msg += 'El campo \"' + tlfs[i + 2] + '\" debe tener una longitud superior a 6 carácteres.\n';
		 	}//fin if
		 }//fin for
		 
		 //Validamos la dirección
		 if(document.getElementById('txtDireccion'))
		 {
			if(document.getElementById('txtDireccion').value.length > 0 &&
		 	   document.getElementById('txtTelefono').value.length <= 4)
		 	   msg += 'El campo \"dirección\" debe tener una longitud superior a 4 carácteres.\n';
		 	 else if(document.getElementById('txtMovil').value.search(/[0-9]/) == -1)
		 	 	msg += 'El campo \"dirección\" debe tener al menos un número.\n';
		 }//fin if
		 
		 //Validamos el resto de campos
		 var otros = new Array('txtPais', 'país', 
		 					   'txtNombre', 'nombre', 
		 					   'txtApellido1', 'apellido 1',
		 					   'txtApellido2', 'apellido 2');
		 					
		 for(i = 0; i < otros.length; i += 2)
		 {
		 	if(document.getElementById(otros[i]))
		 	{
				if(document.getElementById(otros[i]).value.length > 0 &&
		 	   	   document.getElementById(otros[i]).value.length <= 2)
		 	   		msg += 'El campo \"' + otros[i + 1] + '\" debe tener una longitud superior a 2 carácteres.\n';
		 	 	else if(document.getElementById(otros[i]).value.search(/[0-9]/) > -1)
		 	 		msg += 'El campo \"' + otros[i + 1] + '\" no debe tener números.\n';		 
		 	}//fin if
		 }//in for		 
		 
		 
		 /******* FIN VALIDACIONES ESPECIFICAS *************/
		 
		 return msg;
	}, //fin funcion
	
	dejarMeterTelefono : function(e)
	{			
		var key;
		var keychar;
		
		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
				
		keychar = String.fromCharCode(key);		

		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
			return true;

		// numbers
		else if ((("0123456789\.\/\+").indexOf(keychar) > -1))
			
			if(("\+").indexOf(keychar) > -1 && this.value.length > 0)
				return false;
			else			
				return true;
		else
			return false;			
	}//fin funcion	 
	 
}


var variableslide = new Array();
var currentslide = 0;

var contentcontainer = "";
var crossrotateobj;
		
var delay = 3000;


/* LOAD */

function addLoadEvent(fn)
 {
	var old = window.onload;
	if(typeof window.onload != 'function')
		window.onload = fn;
	else
		window.onload = function()
		 {
			old();
			fn();
		 }
 }

addLoadEvent( function() { TELEFERICO.init(); } );

