/************************************************************************
		SE INICIALIZAN LAS VARIABLES GLOBALES
************************************************************************/
//	PARA EL SCROLL VERTICAL DE EXTRACTOS
	var inicio = 0;
	var deslizador = 90;
	var efecto = null;

/************************************************************************
		FUNCIONES VARIAS
************************************************************************/	
// 	SE RECIBE EL IDENTIFICADOR DE LA FILA 
function resaltarFila(id, cantidad)
{
	var i;
	for(i = 0; i < cantidad; i++){
		$('e_fila'+i).setStyle('background-color','#fff');
		$('e_fila'+i).setStyle('color','#080808');
	}
	
	$('e_fila'+id).setStyle('background-color','#000180');
	$('e_fila'+id).setStyle('color','#fff');
}

//	PARA VISUALIZAR LOS EXTRACTOS DEL EXPEDIENTE
function bajar(cant)
{
	efecto = new Fx.Style('scroll', 'margin-top', 
	{
		duration: 800	//DURACION PARA EL DESLIZAMIENTO
	});
	var limite_sup = deslizador * cant * (-1); 
	
	if(inicio != limite_sup && cant != 1){
		inicio -= deslizador;
		efecto.start(inicio);
	}	
}
function subir(cant)
{
	efecto = new Fx.Style('scroll', 'margin-top', 
	{
		duration: 800	//DURACION PARA EL DESLIZAMIENTO
	});
	if(inicio){
		inicio += deslizador;
		efecto.start(inicio);
	}	
}

//SE INICIALIZAN LOS VALORES PARA UTILIZAR EL SCROLL VERTICAL DE EXTRACTOS 
function inicializar_scroll_extractos()
{
	//			 Fx.Style('idElemento', 'propiedadCSS')
	efecto = new Fx.Style('scroll', 'margin-top', 
	{
		duration: 800	//DURACION PARA EL DESLIZAMIENTO
	});
}	

//	AL MOVERSE POR LAS FILAS DEL LISTADO SE VISUALIZAN SUS DATOS DEBAJO
function refrescarDatos(anio, tipo, numero, fecha_entrada_expe, nombre, iniciador, categoria)
{
	//alert('Anio: '+anio+'\nTipo: '+tipo+'\nNumero: '+numero+'\nFecha: '+fecha_entrada_expe+'\nNombre: '+nombre+'\nInicia: '+inicia+'\nAutor: '+autor+'\nCategoria: '+categoria+'\nTema: '+tema);
	
	$('p_datos_nombre').innerHTML = nombre;
	$('p_datos_inicia').innerHTML = iniciador;
	$('p_datos_categ').innerHTML = categoria;
	//$('p_datos_autor').innerHTML = autor;
	//$('p_datos_tema').innerHTML = tema;
	
	var url = 'temas.php?anio='+anio+'&tipo='+tipo+'&numero='+numero+'';
	refrescar(url, 'capa_temas');
	
	var url = 'autores.php?anio='+anio+'&tipo='+tipo+'&numero='+numero+'';
	refrescar(url, 'capa_autores');
	
	var url = 'extractos.php?enviado=ok&anio='+anio+'&tipo='+tipo+'&numero='+numero+'&fecha_entrada_expe='+fecha_entrada_expe+'';
	//alert('Url: '+url);
	refrescar(url, 'capa_extractos');
	
	//SE INICIALIZAN LOS VALORES PARA UTILIZAR EL SCROLL VERTICAL DE EXTRACTOS 
	inicializar_scroll_extractos();
}

//	SE MUESTRA EL RESULTADO DE LA URL EN UN DIV CONTENEDOR CON AJAX
function refrescar(url, capa_destino)
{
	//alert('Url: '+url+'\n Destino: '+capa_destino);
	
	var miAjax = new Ajax(url,
	{
		method: 'get',
		data:'',
		update: $(capa_destino)
	});
	miAjax.request();
}

var nav4 = window.Event ? true : false;
function soloEnteros(evt)  // se obliga al usuario que ingrese solo numeros
{ 
	// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
	var key = nav4 ? evt.which : evt.keyCode; 
	return (key <= 13 || (key >= 48 && key <= 57));
} 

var tecla = window.Event ? true : false;
function fechaConBarra(evt)  // se obliga al usuario que ingrese solo numeros y '/' para la fecha
{ 
	// NOTA: Backspace = 8, Enter = 13, barra '/' = 47, '0' = 48, '9' = 57 
	var key = tecla ? evt.which : evt.keyCode; 
	return ((key <= 13 || key == 47) || (key >= 48 && key <= 57));
} 

function validarBuscador()
{
	var mensaje = '';
	var error = false;

	if ( $('anio').value == '' )
	{
		mensaje += "Por favor, ingrese un a"+'\u00f1'+"o, gracias";
		error = true;
	} 
	else 
	{
		if ( $('anio').value < 1983 )
		{
			mensaje += "\n Por favor, ingrese un a"+'\u00f1'+"o mayor a 1983.";
			error = true;
		}
	}
	if ( $('numero').value == '' )
	{
		mensaje += "\n Por favor, ingrese un n"+'\u00fa'+"mero, gracias";
		error = true;
	}

	if (!error)
	{
		$('formBuscador').submit();
		return true;
	}
	else
	{
		alert(mensaje);
		$('anio').focus();
		return false;
	}
}

function validarAnio()
{
	if($('anio').value < 1983){
		alert("Por favor, ingrese un a"+'\u00f1'+"o mayor a 1983.");
		$('anio').focus();
		return false;
	}
/*	if($('anio').value > 2010){
		alert('Por favor, ingrese un anio anterior al actual.');
		$('anio').focus();
		return false;
	}
*/
	return true;
}

function validarListado()
{
	var mensaje = '';
	var error = false;

	if($('fecha_entrada_expe').value == ''){
		mensaje += 'Por favor, ingrese una fecha de entrada, gracias';
		error = true;
	}
					
	if(!error){
		$('formListado').submit();
		return true;
	}else{
		alert(mensaje);
		$('fecha_entrada_expe').focus();
		return false;
	}
}



