var Ant = null;

function AltaEmailParaTodos ()
{
	var Ajax = new TAjax ();
	
	if (ValidarDatosAlta ())
	{	Ajax.onCargar = function (oPeticion) 
										{ var Aux = oPeticion.asText ();
											if (Aux.substr (0, 2) == 'OK') window.location = '/fuentes/finalta.php?Identificador=' + oPeticion.Identificador + '&Clave=' + oPeticion.Clave;
											else alert (Aux.substr (2));
										}
		Ajax.Identificador = document.Email.Identificador.value;
		Ajax.Clave         = document.Email.Clave.value;
		Ajax.Formulario (document.Email);
		Ajax.Cargar ('/fuentes/altaemailparatodos.php');
	}
}


function AvisoLegal ()
{
	var Ventana = new TVentana ();

	Ventana.Ancho       = 550;
	Ventana.Alto        = 400;
	Ventana.Nombre      = 'AvisoLegal';
	Ventana.URL         = '/plantillas/avisolegal.html';
	Ventana.Open (true);
}


function ArticulosHistoria (id)
{
	var Ventana = new TVentana ();

	Ventana.Ancho      = 515;
	Ventana.Alto       = 500;
	Ventana.Nombre     = 'Articulos';
	Ventana.URL        = '/fuentes/articulos.php';
	Ventana.Open (true);
}


function CaracteresValidos (Cadena)
{
	var l      = Cadena.length;
	var i      = 0;
	var Result = true;
	var Car    = 0;
	
	while (Result && i < l)
	{	Car = Cadena.charCodeAt (i++);
		Result = (Car >= 48 && Car <=  57) ||			// del 0 al 9
		         (Car >= 65 && Car <=  90) ||			// de la A a la Z
		         (Car >= 97 && Car <= 122) ||			// de la a a la z
		         Car == 45 || Car == 46 || Car == 95; 	// - . _
	}
	return (Result);
}


function ComprobarID ()
{
	var Identificador = document.Email.Identificador.value.Trim ();

	if (ValidarIdentificador (Identificador))
	{	var Ajax = new TAjax ();
		
		Ajax.onCargar = function (oPeticion) 
		                { if (oPeticion.asText () == 'OK') alert ('El identificador: "' + oPeticion.Id + '" está disponible.');
		                	else alert ('El identificador: "' + oPeticion.Id + '" NO ESTÁ DISPONIBLE.');
			              }
		Ajax.Id      = Identificador;
		Ajax.Vars.Id = Identificador;
		Ajax.Cargar ('/fuentes/comprobaridentificador.php');
	}
}


function DescargarPDF (iId)
{
	var Ventana = new TVentana ();

	Ventana.Nombre = 'PDF';
	Ventana.URL    = '/contenidos/empleo/' + iId + '.pdf';
	Ventana.Open (true);
}


function Efecto (iId)
{
	TEfectos.prototype.Incremento  = 15;
	
	idEfecto ('idEfecto' + iId).Vertical();
}


function EnviarPregunta (oFormulario)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (oFormulario))
	{ if (oFormulario.Lopd.checked) {
			Ajax.onCargar = function () { 
											alert ('Su pregunta ha sido enviada correctamente.'); 
											oFormulario.Nombre.value   = '';
											oFormulario.Email.value = ''; 
											oFormulario.Pregunta.value = ''; 
											oFormulario.Lopd.checked   = false; }
			Ajax.Formulario (oFormulario);
			Ajax.Cargar ('/fuentes/enviarpregunta.php');
	  } else alert ('Debe aceptar la política de privacidad y confidencialidad.');
	}
}


function EnviarSac (Formulario)
{
	var Ajax = new TAjax ();

	if (ValidarFormulario (Formulario))
	{	if (Formulario.Lopd.checked) {
			Ajax.onCargar = function () { $ ('idFormulario', 'style.display', 'none'); $ ('idEnvioOK', 'style.display', 'block'); }
			Ajax.Formulario (Formulario);
			Ajax.Cargar ('/fuentes/enviar_sac.php');
		} else alert ('Debe aceptar la política de privacidad y confidencialidad.');		
	}
}


function FormEmailParaTodos ()
{	
	var Ventana = new TVentana ();

	Ventana.Ancho       = 515;
	Ventana.Alto        = 500;
	Ventana.Nombre      = 'Email';
	Ventana.URL         = '/plantillas/emailparatodos.html';
	Ventana.Open (true);
}


function InitMenu ()
{
	$ ('idMenu-' + Opc1 + Opc2 , 'className', 'Seleccionado');
	$ ('idOpc-' + Opc1 , 'className', 'Seleccionado');
}


function Lopd ()
{
	var Ventana = new TVentana ();

	Ventana.Ancho       = 550;
	Ventana.Alto        = 300;
	Ventana.Nombre      = 'Lopd';
	Ventana.URL         = '/plantillas/lopd.html';
	Ventana.Open (true);
}


function NuevaVentana (Ancho, Alto, URL, NombreVentana)
{
	var Ventana = new TVentana ();

	Ventana.Ancho      = Ancho;
	Ventana.Alto       = Alto;
	Ventana.ScrollBars = false;
	Ventana.Nombre     = NombreVentana;
	Ventana.URL        = URL;
	Ventana.Open (true);
}


function onClickHemeroteca (oDataSet)
{
	var Ventana = new TVentana ();
	
	Ventana.Ancho  = 700;
	Ventana.Alto   = 500;
	Ventana.Redimensionar = true;
	Ventana.Nombre = 'Hemeroteca';
	Ventana.URL    = '/fuentes/paginahemeroteca.php' +
	                 '?Id=' + oDataSet.FieldByName ('Id') +
	                 '&Revista=' + oDataSet.FieldByName ('Revista') +
	                 '&Pagina=' + oDataSet.FieldByName ('Pagina');
	Ventana.Open (true);	                 
}


function ValidarDatosAlta ()
{
	var Clave     = document.Email.Clave.value.Trim ();
	var CodPostal = document.Email.CodPostal.value.Trim ();
	var Poblacion = document.Email.Poblacion.value.Trim ().toUpperCase();
	var Provincia = document.Email.Provincia.value.Trim ().toUpperCase ();
	var Pais      = document.Email.Pais.value.Trim ().toUpperCase();
	
	if (! ValidarIdentificador (document.Email.Identificador.value.Trim ()))
		document.Email.Identificador.focus ();
	else if (Clave == '')
	{	alert ('Tiene que indicar una contraseña');
		document.Email.Clave.focus ();
	} else if (Clave.length < 6)
	{	alert ('La contraseña tiene que tener al menos 6 caracteres.');
		document.Email.Clave.focus ();
	} else if (Clave.length > 15) 
	{	alert ('La contraseña no puede contener más de de 15 caracteres.');
		document.Email.Clave.focus ();
	} else if (! CaracteresValidos (Clave)) 
	{	alert ('La contraseña contiene caracteres inválidos.');
		document.Email.Clave.focus ();
	} else if (document.Email.Clave2.value.Trim () != Clave) 
	{	alert ('La contraseña y su confirmación son distintas.');
		document.Email.Clave.focus ();
	} else if (document.Email.Pregunta.value.Trim () == '') 
	{	alert ('Tiene que indicar una pregunta para recordar la contraseña.');
		document.Email.Pregunta.focus ();
	} else if (document.Email.Respuesta.value.Trim () == '') 
	{	alert ('Tiene que indicar una respuesta para recordar la contraseña.');
		document.Email.Respuesta.focus ();
	} else if (document.Email.Nombre.value.Trim () == '') 
	{	alert ('Tiene que indicar un nombre.');
		document.Email.Nombre.focus ();
	} else if (document.Email.Apellidos.value.Trim () == '') 
	{	alert ('Tiene que indicar los apellidos.');
		document.Email.Apellidos.focus ();
	} else if (document.Email.DNI.value.Trim () == '') 
	{	alert ('Tiene que indicar un DNI.');
		document.Email.DNI.focus ();
	} else if (! ValidarNIF (document.Email.DNI))
	{	alert ('El DNI no es correcto.');
		document.Email.DNI.focus ();
	} else if (document.Email.Fecha.value.Trim () == '') 
	{	alert ('Tiene que indicar una fecha.');
		document.Email.Fecha.focus ();
	} else if (! MascaraFecha (document.Email.Fecha, 'fecha')) void (0);
	else if (document.Email.Calle.value.Trim () == '') 
	{	alert ('Tiene que indicar una calle.');
		document.Email.Calle.focus ();
	} else if (document.Email.Numero.value.Trim () == '') 
	{	alert ('Tiene que indicar un número.');
		document.Email.Numero.focus ();
	} else if (CodPostal == '') 
	{	alert ('Tiene que indicar un código postal.');
		document.Email.CodPostal.focus ();
	} else if (Poblacion == '') 
	{	alert ('Tiene que indicar una población.');
		document.Email.Poblacion.focus ();
	} else if (Provincia == '') 
	{	alert ('Tiene que indicar una provincia.');
		document.Email.Provincia.focus ();
	} else if (Pais == '') 
	{	alert ('Tiene que indicar un país.');
		document.Email.Pais.focus ();
	} else if (! document.Email.chkAcepto.checked)
	{	alert ('Tiene que aceptar las condiciones de uso del servicio.');
		document.Email.chkAcepto.focus ();
	} else if (Provincia != 'SEVILLA' || Pais != 'ESPAÑA')
		alert ('Usted no cumple las condiciones de registro.\n' + 
		       'Por favor lea atentamente las condiciones de\n' +
		       'uso del servicio, o repase sus datos.');
	else if (CodPostal  == '41300' && (Poblacion == 'SAN JOSE DE LA RINCONADA' || 
	                                   Poblacion == 'SAN JOSÉ DE LA RINCONADA' ||
	                                   Poblacion == 'SAN JOSE' ||
	                                   Poblacion == 'SAN JOSÉ'))
	{	return (true);
	} else if (CodPostal == '41309' && Poblacion == 'LA RINCONADA')
	{	return (true);
	} else
		alert ('Usted no cumple las condiciones de registro.\n' + 
		       'Por favor lea atentamente las condiciones de\n' +
		       'uso del servicio, o repase sus datos.');
	return (false);	
}


function ValidarIdentificador (Identificador)
{
	if (Identificador == '') alert ('Tiene que indicar un identificador');
	else if (Identificador.length < 6) alert ('El identificador tiene que tener al menos 6 caracteres.');
	else if (Identificador.length > 25) alert ('El identificador no puede tener más de 25 caracteres.');
	else if (! CaracteresValidos (Identificador)) alert ('El identificador contiene caracteres inválidos.');
	else return true;
	
	return false;
}


function ValidarNIF (Control)
{
	var Nif      = Control.value.Trim ().toUpperCase ();
	var Digitos  = 'TRWAGMYFPDXBNJZSQVHLCKE';
	var i        = 0;
	var Aux      = '';
	var l        = Nif.length;
	var Car      = 0;
	var Letras   = 0;
	var Result   = false;
	var Valor    = 0;
	
	for (i = 0; i < l; i++)
	{	Car = Nif.charAt (i);
		if (Car >= '0' && Car <= '9') Aux += Car;
		else if (Car >= 'A' && Car <= 'Z')
		{	Letras++;
			Aux += Car;
		}
	}
	l      = Aux.length;
	Result = Letras == 1 && l > 8 && Aux.charAt (l - 1) >= 'A';
	if (Result)
	{	Valor = Aux.substr (0, l - 1).asInteger ();
		Result = Valor && Digitos.charAt (Valor % 23) == Aux.charAt (l - 1);
		if (Result) Control.value = Aux;
	}	
	return (Result);
}


function VerArticulo (IdArticulo)
{
	document.location = '/fuentes/articulo.php?Id=' + IdArticulo;
}


function VerPostal (Postal)
{
	var Ventana = new TVentana ();

	Ventana.Ancho      = 10;
	Ventana.Alto       = 10;
	Ventana.SetTop (10);
	Ventana.ScrollBars = false;
	Ventana.Nombre     = 'Postales';
	Ventana.URL        = '/fuentes/postal.php?Codigo=' + Postal;
	Ventana.Open (true);
}


function VerOferta (Oferta)
{
	var Ventana = new TVentana ();

	Ventana.Ancho = 515;
	Ventana.Alto  = 550;
	Ventana.ScrollBars = true;
	Ventana.Nombre     = 'Empleo';
	Ventana.URL        = '/fuentes/empleopublico.php?Id=' + Oferta;
	Ventana.Open (true);
}


function VerNoticia (idNoticia)
{
	var Ventana = new TVentana ();

	Ventana.Ancho      = 515;
	Ventana.Alto       = 500;
	Ventana.Nombre     = 'Noticia';
	Ventana.URL        = '/fuentes/noticia.php?Id=' + idNoticia;
	Ventana.Open (true);
}

//**********************************************

function RejillaRevistas (Pagina, Buscar)
{

	var Rejilla = new TRejilla ('idRejRevistas');

	Rejilla.VerRevista    	  = false;
	Rejilla.onActivarFila     = onSeleccionar;
	Rejilla.Vars.Pagina   		= Pagina;
	Rejilla.Vars.Buscar   		= Buscar;
	Rejilla.VerTablaSinDatos  = false; // Sólo muestra tabla cuando existen resultados.
	Rejilla.Cargar ('/fuentes/hemeroteca.php');
	Rejilla.VerSinResultado ('<p>No se han encontrado revistas con el criterio de b&uacute;squeda: <strong>' + Buscar + '</strong></p>'+
													 '<p>Le recomendamos que pruebe a elegir otros criterios de b&uacute;squeda.</p>');
}


function onSeleccionar (Rejilla, Fil, Col)
{
	if (Rejilla.VerRevista)
	{	var Ventana = new TVentana ();
		Ventana.Ancho  				= 700;
		Ventana.Alto   				= 500;
		Ventana.Redimensionar = true;
		Ventana.Nombre 				= 'Hemeroteca';
		Ventana.URL    				= '/fuentes/paginahemeroteca.php' +
		                 				'?Id=' + Rejilla.ByName ('Id') + '&Revista=' + Rejilla.ByName ('Revista') +
		                 				'&Pagina=' + Rejilla.ByName ('Pagina');
		Ventana.Open (true);	       
	} else Rejilla.VerRevista = true;
}


function PuedoVotar (Formulario)
{  
	var i           = 0;
	var Aux         = -1;
	var RadioButton = Formulario.Respuesta;
	
	while (i < RadioButton.length && Aux == -1)
	{	if (RadioButton [i].checked) { Aux = i; }
		i++;
	}
	
	if (Aux < 0)	alert ('Tiene que elegir una respuesta.')
	else return (true);
	
	return (false);	
	
}



function ValidarBuscar (Buscar)
{
	if (Trim (document.Buscar.Par4.value) == '' && Buscar == '')
	{	alert ('Tiene que indicar una busqueda.');
		return (false);
	} else return (true);
}


// Perfil Del Contratante

function Ampliar (iPerfil, iId)
{
	var sId = 'idPerfil' + iPerfil + '-' + iId;

	if (Ant) idEfecto ('idPerfil' + Ant).Vertical ();
	if (Ant != iPerfil + '-' + iId)
	{	if (Ant) $ ('idTR' + Ant, 'className', 'Normal');
		$ ('idTR' + iPerfil + '-' + iId, 'className', 'Seleccionado');
		idEfecto (sId).Vertical ();
		Ant = iPerfil + '-' + iId;
	} else Ant = null;
}

function Hover (iPerfil, iId)
{

	if (Ant != iPerfil + '-' + iId)
		$ ('idTR' + iPerfil + '-' + iId, 'className', 'Hover');
}


function Out (iPerfil, iId)
{
	if (Ant != iPerfil + '-' + iId)
		$ ('idTR' + iPerfil + '-' + iId, 'className', 'Normal');
}



function EncuentroDigital (iIdEncuentro)
{
	document.location = '/fuentes/encuentrodigital.php?IdEncuentro=' + iIdEncuentro;
}




function VerEncAnteriores () 
{
	$ ('IdEncAnteriores', 'style.display', 'block');
}

function VentanaInicio ()
{
	var Ventana = new TWindow ();

	Ventana.ClickVelo = true;
	Ventana._Clase = 'VentanaInicio';
 	Ventana.Cargar ('/fuentes/ventanainicio.php');
}



function VentanaVideo (sVideo, bCerrarOnVelo)
{
	var Ventana = new TVentanas ();
	
	Ventana.Tipo         = 2;
	Ventana.Ancho        = 515;
	Ventana.Alto         = 416;
	Ventana.CerrarEnVelo = bCerrarOnVelo;
	Ventana.onCargar = function (oVentana)
											{
												var Div   = document.createElement ('DIV');
												var Video = new TVideo ();
												
												Div.id = 'idVerVideo';
												Div.style.paddingTop = '15px';
												oVentana.Contenedor.appendChild (Div);
												Video.Ancho   = 475;
												Video.Alto    = 356;
												Video.Video   = sVideo;
												Video.Empezar = true;
												Video.Cargar ('idVerVideo');
											}
	Ventana.Cargar ();											
}




