function EsNumerico(exp_validar) {

	var numeros = "0123456789";
	
	if (exp_validar.length==0)return(false);

	for (var n=0; n < exp_validar.length; n++){
		if(numeros.indexOf(exp_validar.charAt(n))==-1)return(false);	
	}
	return(true);
}

function checkForInt(evt) {
  //notice that the check is != null now, as the tab key has a value of 0
  var charCode = ( evt.which != null ) ? evt.which : event.keyCode
  //charCodes < 32 include tab, delete, arrow keys, etc
  return (charCode < 32 || (charCode >= 48 && charCode <= 57))
};


//Crea objeto AJAX
function http_request() {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp
};

function buscar_nacional(){
  var contenedor;
  var numero;

  contenedor = document.getElementById('resultado-redfija');
  numero = document.getElementById('numero-field').value;
  
//  if (numero.length < 8){
//    alert("El número debe contener 8 digitos");
//    return false;
//  }

  if(!EsNumerico(numero)){
  	alert ("Valor incorrecto")
	return false;
  }


  ajax=http_request();

  ajax.open("GET", "av-modules/microservicios/busca_redfija/buscar_redfija.php?numero="+numero, true);

  ajax.onreadystatechange=function() {
    if (ajax.readyState==1)
    {
      contenedor.innerHTML = '<img src="../../av-includes/images/proceso-redfija.gif" />';
    }
    else if(ajax.readyState==4)
    {
      if(ajax.status==200)
      {
        contenedor.innerHTML = ajax.responseText;
      }
      else
      {
        contenedor.innerHTML = "Error: ";
      }
    }
  }

   ajax.send(null)
};

