// JavaScript Document

if (document.all)
  document.write('<link rel="stylesheet" href="css/styleIE.css" type="text/css">')

function abreMenu(tipo)
	{
	if(document.getElementById('submenu'+tipo).style.display=='none')
		document.getElementById('submenu'+tipo).style.display='inline';
	else
		document.getElementById('submenu'+tipo).style.display='none';
	}
	
//REDIRECCIONAMIENTOS	
function redirecciona(pag)
	{
	window.open(pag); 	
	}
function redirecciona2(pag)
	{
	alert(pag);
	window.open(pag); 	
	}
function redirecciona3(pag)
	{
	location.href=pag; 		
	}
	
//VALIDA FORMULARIO	
function valida()
	{
	var error = false;
	var tlfn_lleno=false;
	/***********DIVIDE DNI*******************/
	var cadena=document.getElementById('dni').value;
	var numDni=cadena.substring(0,8);
	var letDni=cadena.substring(8,9);
	/****************************************/
	
	if(document.getElementById('nombre').value == "")
		{
		alert("El formato del nombre no es v\xE1lido");
		error=true;	
		}
	if(document.getElementById('apellido').value == "" && error==false)
		{
		alert("El formato del apellido no es v\xE1lido");
		error=true;	
		}	
	if(!validaNIF(numDni,letDni) && error==false)
		{
		alert("El formato del Dni no es v\xE1lido");
		error=true;	
		}	
	if(!esFecha(document.getElementById('fNacim').value) && error==false)
		{
		alert("El formato de fecha no es v\xE1lido");
		error=true;	
		}		
	if(document.getElementById('sexo').value == "0" && error==false)
		{
		alert("Debe seleccionar un tipo de sexo.");
		error=true;	
		}	
	if(document.getElementById('nombreVia').value == "" && error==false)
		{
		alert("El formato de nombre de v\xEDa no es v\xE1lido");
		error=true;	
		}
	if(isNaN(document.getElementById('numero').value) || (document.getElementById('numero').value=="") && error==false)
		{
		alert("El n\xFAmero introducido no es v\xE1lido");
		error=true;	
		}		
	if( (isNaN(document.getElementById('cp').value) || document.getElementById('cp').value < 10000 || document.getElementById('cp').value > 99999) && error==false)
		{
		alert("El valor del campo 'C\xF3digo Postal' no es v\xE1lido");
		error=true;
		}
	if(document.getElementById('municipio').value == "" && error==false)
		{
		alert("El formato del municipio no es v\xE1lido");
		error=true;	
		}	
	if(!esTelefonoFijo(document.getElementById('telefono').value) && (document.getElementById('telefono').value) != ""   && error == false)
		{
		alert("El tel\xE9fono introducido no es v\xE1lido");
		error = true;
		}
	if(!esTelefonoMovil(document.getElementById('movil').value) && (document.getElementById('movil').value) != "" && error == false)
		{
		alert("El m\xF3vil introducido no es v\xE1lido");
		error = true;
		}
	if(document.getElementById('telefono').value == "" && document.getElementById('movil').value == "")
		{
		alert("Debes de rellenar el campo M\xF3vil o el campo Tel\xE9fono");
		error=true;	
		}		
	if (!mail_valido(document.getElementById('mail').value ) && (document.getElementById('mail').value) != "" && error==false)
		{
		alert("El formato del correo electr\xF3nico no es v\xE1lido");
		error = true;
		}
	if(isNaN(document.getElementById('numBoleto').value) || (document.getElementById('numBoleto').value=="") && error==false)
		{
		alert("El n\xFAmero de boleto introducido no es v\xE1lido");
		error=true;	
		}	
	if(isNaN(document.getElementById('numSerie').value) || (document.getElementById('numSerie').value=="") && error==false)
		{
		alert("El n\xFAmero de serie introducido no es v\xE1lido");
		error=true;	
		}			
		
	if(document.getElementById('si').checked == false && document.getElementById('no').checked == false )
		{
		alert("Debes de marcar si deseas recibir informaci\xF3n.");
		error=true;	
		}
	else if(document.getElementById('si').checked == true && document.getElementById('no').checked == true )
		{
		alert("Debes de marcar s\xF3lo una opci\xF3n en deseas recibir informaci\xF3n.");
		error=true;				
		}
	alert(error)
	if (error == false)
		{
		document.form1.submit();
		}	
	}
function mail_valido(cadena)
{
	var b=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
	if (!b.test(cadena))
		return false;
	return true;
}

function validaNIF(numero, let)
{
	  numero = numero % 23;
	  letra='TRWAGMYFPDXBNJZSQVHLCKET';
	  letra=letra.substring(numero,numero+1);
	  if (letra!= let.toUpperCase()) 
		return false;
	  return true;
}

function esTelefonoFijo(cadena){
	var validador=/^(9\d{8})|(9\d{2}(-| )?\d{3}(-| )?\d{3})|(9\d(-| )?\d{7})|(9\d(-| )?\d{3}(-| )?\d{4})$/;
	if(validador.test(cadena)==true){
		return true;
	}
	else{
		return false;
	}
}

function esTelefonoMovil(cadena){
	var validador = /^(6\d{8})|(6\d{2}(-)?\d{3}(-)?\d{3})|(6\d{2}( )?\d{3}( )?\d{3})$/
	if(validador.test(cadena)==true){
		return true;
	}
	else{
		return false;
	}
}	
function esFecha(cadena){
	var validador=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
	if(validador.test(cadena)==true){
		return true;
	}
	else{
		return false;
	}
}
function cargaVideo(video)
{
	var url = video.href;
	$('ifr_videos').src = url;
}
function cargaPagina(url,div,parametros)
{
	//new Ajax(url,{method: 'post', postBody:parametros, update:div}).request(); //codigo=3&nombre=$('nombre_caja').value
	new Request(
	{
		method: 'get',
		url: url,
		noCache: true,
		evalScripts: true,		
		onSuccess: function(texto){
		$(div).innerHTML = texto;}
	}).send(parametros);
}
function muestraGrowl (pagina, alto, ancho)
{
	var alto = alto / 2;
	var ancho = ancho / 2;
	var top = window.getScrollTop();//document.body.scrollTop;
	var left = window.getScrollLeft();//pageX = clientX + document.body.scrollLeft;document.body.scrollLeft; 
	var h = window.getHeight() / 2; //document.body.clientHeight;
	var w = window.getWidth() / 2; //document.body.clientWidth;
	var he = top+h-alto;
	var we = left+w-ancho;
	$('growlfondo').setStyles({'height':window.getScrollHeight()+'px','width':window.getWidth()+'px',	'top':'0px','left':'0px','display':'block'});
	$('growlfondo').style.opacity = "0.6";
	if(he <0 ) he = 0;
	document.getElementById('growlfondo').setAttribute('onclick', 'cierraGrowl()');
	//alert(window.getHeight()+ " - " + window.getScrollTop())
	/*var imgCargando = "<div style='text-align:center; font-size: 12px; font-weight:bold; color: #FFF; font-family:verdana;'><img src='/images/loading.gif' align='middle' border='0' /><br/>Loading...";*/
	$('growlmsg').setStyles({'top':he+50+'px','left':we - 200 +'px','width':(ancho * 2)+'px','height':(alto * 2)+'px','display':'block'});
	/*$('growlmsg').innerHTML = imgCargando;*/
	$('growlmsg').style.opacity = "1";
	
	if (pagina != "") //usado para poder imprimir un growl con el loading mientras se hace otra cosa. si la 'pagina' no se ha pasado no se hace el cargapagina, este es el caso del loading solo.
		cargaPagina(pagina, "growlmsg", '');
}
function cierraGrowl ()
{
	if($('ifr_videos')) $('ifr_videos').style.display = 'inline';
	$('growlfondo').innerHTML = '';
	$('growlmsg').innerHTM = '';
	$('growlfondo').style.display = 'none';
	$('growlmsg').style.display = 'none';
}

