// JavaScript Document
var x;
x=$(document);
x.ready(inicializarEventos);

function inicializarEventos()
{
  var x=$("#Ced");
  x.keypress(buscarParticipante);
  $("#formBuscar").submit(validarCedula);
}


function buscarParticipante(e)
{
	if (e.which==13)
	{
		validarCedula();
		return false;
	}
   	return (e.which < 13 || (e.which >= 48 && e.which <= 57))
	
}

function validarCedula()
{
	var valorcedula=jQuery.trim($("#Ced").attr("value"));
	var mensajerror="";
	if (valorcedula!="")
		{
			if (valorcedula.length<5) 
				mensajerror="M&iacute;nimo 6 d&iacute;gitos para la c&eacute;dula<br />";
		} 
	else
		mensajerror="Indique su nro. de c&eacute;dula.<br />";
	if(mensajerror!="")
	{
		mensaje="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
		mensaje+="<tr><td height='5' colspan='3'>&nbsp;</td></tr>";
		mensaje+="<tr><td valign='top' align='left' width='29'><img src='imagenes/formulario/bt_informacion.jpg' width='29' height='29' border='0' alt='informacion' /></td>";
		mensaje+="<td width='5'></td><td class='mensajerrorindex' align='left'>"+mensajerror+"</td></tr>";		
		mensaje+="<tr><td height='5' colspan='3'>&nbsp;</td></tr>";
		mensaje+="<tr><td align='center' colspan='3'><a href='javascript:mostrarCapa(false);'><img src='imagenes/formulario/bt_regresar.gif' width='70' height='16' border='0' alt='regresar' /></a></td></tr>";	
		mensaje+="<tr><td height='5' colspan='3'>&nbsp;</td></tr>";						
		mensaje+="</table>";		

		$("#error").html(mensaje);
		mostrarCapa(true);
	}
	else
	{
	  $.ajax({
			   async:false,
			   type: "GET",
			   dataType: "html",
			   contentType: "application/x-www-form-urlencoded",
			   url:"AJAX/comprobar_ced_const_index.php",
			   data:"Ced="+valorcedula,
			   beforeSend:i_consultaPrincipal,
			   success:l_consultaPrincipal,
			   timeout:4000,
			   error:p_consultaPrincipal
			 }); 
	}
	return false;

}


function mostrarCapa(etiqueta)
{
	var error=$("#error");
	var historial=$("#busquedaHistorial");	
	
	if (etiqueta)
	{
		error.show("fast");
		historial.hide("fast");
	}
	else
	{
		error.hide("fast");
		historial.show("fast");
	}
}


function l_consultaPrincipal(datos)
{
  	if (datos==1)
	{
		parent.location.href="cofae.php?Pag=27&Codigo=PR06&Cod=2&Ced="+jQuery.trim($("#Ced").attr("value"));
	}
	else
	{
		mensaje="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
		mensaje+="<tr><td height='5'>&nbsp;</td></tr>"				
		mensaje+="<tr><td class='mensajerrorindex'>"+datos+"</td></tr>"
		mensaje+="<tr><td height='5'>&nbsp;</td></tr>"		
		mensaje+="<tr><td align='center'><a href='javascript:mostrarCapa(false);'><img src='imagenes/formulario/bt_regresar.gif' width='70' height='16' border='0' alt='regresar' /></a></td></tr>"			
		mensaje+="<tr><td height='5'>&nbsp;</td></tr>"							
		mensaje+="</table>";  
		$("#error").html(mensaje);
		mostrarCapa(true);
	}
}

function i_consultaPrincipal()
{
	mostrarCapa(true);
	var x=$("#error");
	x.html("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><img src='imagenes/ajax/loading.gif' width='32px' height='32px' border='0' alt='cargando' /></td></tr><tr><td class='mensajeCargando'>Cargando la informaci&oacute;n.</td></tr></table>");
}

function p_consultaPrincipal()
{
  $("#error").html("<br /><img src='imagenes/formulario/error.gif' width='32px' height='32px' alt='Cargando' /><br /><span class='mensajerror'>Problemas en el servidor.</span><br />");
}

