// JavaScript Document
/*----------------------------------------------------------------
DESCRIPCIÓN: Ejecuta un popUp con las dimensiones dadas
PARAMETROS: (la ruta del script, el ancho del popUp, el alto del popUp)
----------------------------------------------------------------*/
var nav4 = window.Event ? true : false;

function numeros(evento)
{
  // NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
  var tecla = nav4 ? evento.which : evento.keyCode;
  return (tecla <= 13 || (tecla >= 48 && tecla <= 57));
};

function letras(evento)
{
  // NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
  var tecla = nav4 ? evento.which : evento.keyCode;
  return ( tecla <= 13 || ( tecla >= 97 && tecla <= 122 ) || (tecla >= 65 && tecla <= 90) || tecla == 32 || tecla == 'á'.charCodeAt(0) || tecla == 'Á'.charCodeAt(0) || tecla == 'é'.charCodeAt(0) || tecla == 'É'.charCodeAt(0) || tecla == 'í'.charCodeAt(0) || tecla == 'Í'.charCodeAt(0) || tecla == 'ó'.charCodeAt(0) || tecla == 'Ó'.charCodeAt(0) || tecla == 'ú'.charCodeAt(0) || tecla == 'Ú'.charCodeAt(0) || tecla == 'ñ'.charCodeAt(0) || tecla == 'Ñ'.charCodeAt(0) );
};



             
function abrir(direccion, pantallacompleta, herramientas, direcciones, estado, barramenu, barrascroll, cambiatamano, ancho, alto, izquierda, arriba, sustituir){ 
    var opciones = "fullscreen=" + pantallacompleta + 
                 ",toolbar=" + herramientas + 
                 ",location=" + direcciones + 
                 ",status=" + estado + 
                 ",menubar=" + barramenu + 
                 ",scrollbars=" + barrascroll + 
                 ",resizable=" + cambiatamano + 
                 ",width=" + ancho + 
                 ",height=" + alto + 
                 ",left=" + izquierda + 
                 ",top=" + arriba; 
    var ventana = window.open(direccion,"venta",opciones,sustituir); 

}                     


function abrirPopup(url,ancho,alto)
{
  var opciones="toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width="+ancho+",height="+alto;
  var Nueva_ventana;
  var tiempo=new Date();
  var hora=tiempo.getHours();
  var minuto=tiempo.getMinutes();
  var segundo=tiempo.getSeconds();
  var nombre=hora+minuto+segundo;
  Nueva_ventana = window.open(url,nombre,opciones); 
  Nueva_ventana.moveTo(0,0); 
}
/*----------------------------------------------------------------
DESCRIPCIÓN: Asegura la inserción de solo numeros en los campos de texto
PARAMETROS: (Evento)
----------------------------------------------------------------*/
function soloNumeros(e)
{
   var key;
   if(window.event)
      key = window.event.keyCode;   //IE
   else
      key = e.which;                //firefox
   if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 || key ==44 ))
      return false;
   else
      return true;
	  
}

/*----------------------------------------------------------------
DESCRIPCIÓN: convierte un string en la notacion 1.000.000,15 a un numero Flotante 1000000,15
PARAMETROS: (Evento)
----------------------------------------------------------------*/

function flotante(numero)
{
	numero=numero.split(".").join("");
	numero=numero.split(",");
	numero=numero.join(".");

	return parseFloat(numero);
}

/*----------------------------------------------------------------
DESCRIPCIÓN: le pone el formato de  miles a un numero flotante
PARAMETROS: (Evento)
----------------------------------------------------------------*/
function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}


