﻿// Javascrip SEP
<!--

	function botoniel(botonvalue)
		{
		if (botonvalue=='Buscar')
			{
				if (document.Form1.txtNombre.value=='')
				{
					alert('Escriba el nombre del ciudadano antes de buscar');}
				else
				{
					document.Form1.TextBoxStatus.value = "Espere un Momento...";
					__doPostBack('btnBuscar','');
					window.status = " Buscando...";
				}
			}
		else{__doPostBack('btnIEl','');}
		}

// linea 6 document.crashjijiji();
function keyRestrict(e, validchars) {
 var key='', keychar='';
 key = e.keyCode;
 if (key == null) return true;
 keychar = String.fromCharCode(key);
 keychar = keychar.toLowerCase();
 validchars = validchars.toLowerCase();
 if (validchars.indexOf(keychar) != -1)
  return true;
 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
  return true;
 return false;
}
function keyRestrictAndEnter(e, validchars,boton) {
 var key='', keychar='';
 key = e.keyCode;
 if (key == null) return true;
 keychar = String.fromCharCode(key);
 keychar = keychar.toLowerCase();
 validchars = validchars.toLowerCase();
 if (validchars.indexOf(keychar) != -1)
  return true;
 if ( key==null || key==0 || key==8 || key==9 || key==27 )
  return true;
 if (key==13) __doPostBack(boton,'');
 return false;
}
function ForzaTexto(objeto)
{
	var texto='';
	if (objeto!=null){texto=objeto.text;}
	return texto;
}

	function EsFecha(valor)
	{
	var intRes = 0;
	var _today = new Date();
		var vdia = valor.substring(0,2);
		var vmes = valor.substring(3,5);
		var vano = valor.substring(6,10);
		var dias = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
		if (vdia > dias[vmes-1]){intRes=intRes+1;}
		if (vmes > 12){intRes=intRes+2;}
		if (vano < 1900 || vano > _today.getFullYear()){intRes=intRes+4;}
		return intRes;
	}

function AutoCompletaFecha(ctrlFechaEn)
{
	var fecha = document.getElementById(ctrlFechaEn);
	switch (fecha.value.length) 
	{
	case 2: 
		fecha.value = fecha.value + "/";
		break
	case 5: 
		fecha.value = fecha.value + "/";
		break
	case 99:
		var twodigits = fecha.value.substring(6,8);
		var anterior = fecha.value.substring(0,6);
		var fourdigits =0;
		if (twodigits>20){
		fourdigits = "19" + twodigits;}
		else if (twodigits<20){
		fourdigits = "20" + twodigits;}
		else {}
		fecha.value = anterior + fourdigits;
		break
	case 10:
			var sifecha = EsFecha(fecha.value);
			if (sifecha==0){
			}
			else{
			var tipoError ="";
			//alert("Fecha invalida");
			}
		break
	}
}

function calcular_edad(controlFecha,controlEdad)
{ 
	var fecha = document.getElementById(controlFecha);
	var edaden = document.getElementById(controlEdad);
	hoy=new Date();
	//hoy.setMonth(8);
	//hoy.setUTCDate(1);//Aqui se modifica la fecha limite
	hoy.setFullYear(parent.rtop.document.Form1.txtCiclo.options[0].text.substring(0, 4), 08, 01);
	//alert(hoy.getFullYear() + '*' + hoy.getMonth() + '*' + hoy.getDate());
    	var edad=0;
    	var array_fecha = fecha.value.split("/");
    	if (array_fecha.length!=3) 
       	{
		edad = 0; 
		return;
	}
    	//valida ano, mes y dia 
    	var dia =0;
    	dia = parseInt(array_fecha[0],10); 
    	if (isNaN(dia)) 
       	{
		edad = 0; 
	}
    	var mes = 0;
    	mes = parseInt(array_fecha[1],10); 
    	if (isNaN(mes)) 
       	{
		edad = 0; 
	}
    	var ano =0;
    	ano = parseInt(array_fecha[2],10); 
    	if (isNaN(ano)) 
       	{
		edad = 0; 
	}
	if (ano>hoy.getYear()) 
	{
		edad = 0;
	}
    	if (ano<=99) 
 	{
       		if (ano<=(hoy.getYear()-2000)) 
			ano +=2000 ;
    		else 
			ano +=1900;
    		fecha.value = array_fecha[0] + '/' + array_fecha[1] + '/' + ano;
 	}
 	//resta de a�os
    	edad=hoy.getYear() - ano - 1; 
    if ((hoy.getMonth() + 1) - mes > 0) 
	{
       		edad= edad+1; 
       		//alert('aumenta edad por mes');
			//alert(hoy.getMonth());
			//alert(mes);
	}
    else
    	{
 			//else hoy.getMonth() = mes 
 			if ( (hoy.getMonth() + 1) - mes == 0 )
 			{
    			if (hoy.getDate() - dia >= 0) //
    			{
       				edad= edad + 1 ;
       				//alert('aumenta edad por dia');
 					//alert(hoy.getDate());
 					//alert(dia);
       			}
       		}
  	}
  	if (ano<1750) 
		alert ('Corrija el a�o en la fecha de nacimiento'); //previene ceros e idioteces
	// document.getElementById(controlFecha).value = dia + '/' + mes + '/' + ano;
    	edaden.value = edad ;
    	try
    	{
    		doAlertas('be');
    	}
    	catch(error)
    	{
    		window.status = error;
    	}
} 

	function deshabilitaControles(nombrectrl,des)
	{
		var controles = document.getElementsByName(nombrectrl);
		var i;
		for (i=0; i<controles.length;i++)
		{
		controles[i].disabled = des;
		}
	}

	function validaFecha(fecha)
	{
		switch (fecha.length) 
		{
		case 2: 
		  document.Form1.txtFechaNac.value = fecha + "/";
		  break
		case 5: 
		  document.Form1.txtFechaNac.value = fecha + "/";
		  break
		case 99:
		  var twodigits = fecha.substring(6,8);
		  var anterior = fecha.substring(0,6);
		  var fourdigits =0;
		  if (twodigits>20){
		  fourdigits = "19" + twodigits;}
		  else if (twodigits<20){
		  fourdigits = "20" + twodigits;}
		  else {}
		  document.Form1.txtFechaNac.value = anterior + fourdigits;
		  break
		case 10:
			  var sifecha = EsFecha(fecha);
			  if (sifecha==0){blurfecha=0;
			    }
			    else{		 blurfecha=1;
			    alert(alertaFecha(sifecha));
			    }
		  break
		}
	}
	function MuestraVentana(PathPagina,targetBl) {	

  mBusqueda = window.open(PathPagina, targetBl, 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=640,height=480,left = 80,top = 60');
}
	function MuestraVentanaBig(PathPagina,targetBl) {	

  mBusqueda = window.open(PathPagina, targetBl, 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=760,height=480,left = 80,top = 60');
}

	function EsNumero(valor)
	{
 	 var boolRes = false;
		if (valor.length > 0)
		{
 		  var x = valor.charAt(valor.length - 1);
		  var numeros = '0123456789/';
		  for (i=0;i<numeros.length;i++)
		  {
		  	if (x.indexOf(numeros.charAt(i)) > -1){boolRes=true;}
		  }
		  //if (x > -1){return true}
		  //else {return false}
		}
	 return boolRes;
	}
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function MuestraVentana(PathPagina,targetBl) {	
  mBusqueda = window.open(PathPagina, targetBl, 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=640,height=480,left = 80,top = 60');
}

-->

