// JavaScript Document

/****************************************************
Funcion que averigua si el navegador es un IE

return true si el navegador es InternetExplorer
			 false si el navegador no es InternetExplorer 

FGI
*****************************************************/
function isIE() { return document.all ? true:false; }
	
/****************************************************
Funcion que averigua si el navegador es un NS

return true si el navegador es Netscape 
			 false si el navegador no es Netscape 

FGI
*****************************************************/
function isNS() { return document.layers ? true:false }

  
function isMozilla(){
  var nav = navigator.appCodeName;
  if(nav=='Mozilla') return true;
  else return false;
}

function isNombreFirefox(){
  var agente = navigator.userAgent ;
  if (agente.indexOf('Firefox') > -1) 
  {
      return true;
  }else return false;  
}

function muestraDatosNavegador(){
  var cadena = '';
  cadena += "Tipo: " + navigator.appCodeName + "\n";
  cadena += "Nombre: " + navigator.appName + "\n";
  cadena += "Version: " + navigator.appVersion  + "\n";
  cadena += "Producto: " + navigator.product   + "\n";
  cadena += "Construido: " + navigator.buildID  + "\n";
  cadena += "Agente: " + navigator.userAgent   + "\n";
  cadena += "Vendedor: " + navigator.vendor   + "\n";
  cadena += "Acepta cookies: " + navigator.cookieEnabled  + "\n";
  cadena += "Lengua: " + navigator.language  + "\n";
  cadena += "Tipos mime soportados: " + navigator.mimeTypes  + "\n";
  cadena += "Sistema operativo: " + navigator.oscpu  + "\n";
  cadena += "Plataforma: " + navigator.platform   + "\n";
  cadena += "Plugins instalados: " + navigator.plugins   + "\n";
  
  alert(cadena);
}


/****************************************
Prepara el action
SLA/*puntero_espera();*
*****************************************/
function actualizarListados(pObjForm,accion) {
    if (pObjForm.action.indexOf("?action=")==-1)
      {
        ac = new String("?action=");
        ac=ac.concat(accion);
        pObjForm.action=new String(pObjForm.action.concat(ac));     
        pObjForm.submit();
      }    
}

String.prototype.padL = function (nLength, sChar) {
	var sreturn = this; 
	while (sreturn.length < nLength)
 		{sreturn = String(sChar) + sreturn;} 
	return sreturn;
}
 
function date_onkeydown() {
if (window.event.srcElement.readOnly) return;
var key_code = window.event.keyCode; 
var oElement = window.event.srcElement;
if (window.event.shiftKey && String.fromCharCode(key_code) == "T")
{
var d = new Date();
oElement.value = String(d.getMonth() + 1).padL(2, "0") + "/" +  String(d.getDate()).padL(2, "0") + "/" + d.getFullYear();
window.event.returnValue = 0;
}
if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey)
{  
	if ((key_code > 47 && key_code < 58) || (key_code > 95 && key_code < 106))
{
if (key_code > 95) key_code -= (95-47);

 oElement.value = oElement.value.replace(/[mdy]/, String.fromCharCode(key_code));
}
if (key_code == 8) {   
if (!oElement.value.match(/^[mdy0-9]{2}\/[mdy0-9]{2}\/[mdy0-9]{4}$/))     
  oElement.value = "mm/dd/yyyy";
  
  oElement.value = oElement.value.replace(/([mdy\/]*)[0-9]([mdy\/]*)$/, function ($0, $1, $2) {  
  var idx = oElement.value.search(/([mdy\/]*)[0-9]([mdy\/]*)$/);
  
   if (idx >= 5) { 
   return $1 + "y" + $2;
   
                  } else if (idx >= 2) {                        return $1 + "d" + $2;
                    } else {                       return $1 + "m" + $2;
                    }                } );
           window.event.returnValue = 0;
        }    }    if (key_code != 9) {       event.returnValue = false;
    }
 }


/*
function onlyDigits(e,id) {
  var _ret = true;
  if (id==null)
    {
      alert('El id no puede ser nulo');
      return _ret;
    }
  if (e==null)
    {
      alert('El evento de teclado no puede ser nulo');
      return _ret;
    }
  if (isIE()) 
    {
      if (window.event.keyCode == 46) //IS_PERIOD
        {
          var completo = document.getElementById(id).value;
          if (completo.indexOf('.')!=-1)
            {
              window.event.keyCode=0;
              _ret = false;
            }
        }                       //46
      if (window.event.keyCode < 46 || window.event.keyCode > 57 || window.event.keyCode == 47) 
        {
          window.event.keyCode = 0;
          _ret = false;
        }
    }
  if (isNS()) 
    {
      if (e.which == IS_PERIOD) 
        {
          var completo = document.getElementById(id).value;
          if (completo.indexOf('.')!=-1)
            {
              e.which=0;
              _ret = false;
            }
        }
      if (e.which < 46 || e.which > 57 || e.which == 47) 
        {
          e.which = 0;
          _ret = false;
        }
    }
  return (_ret); 
}
*/


/*
function max_lengthDigits(max_length_entero,max_length_fraccion,id,mensaje_error,mensaje_error_entero,mensaje_error_decimal,e)
{
  if (id==null)
    {
      alert('El id no puede ser nulo');
      return true;
    }
  if (max_length_fraccion==null)
    {
      var entero = document.getElementById(id).value;
      if (max_length(max_length_entero-1,entero)==true)
        {
          if (mensaje_error_entero!=null)
            {
              error_Campo(id,mensaje_error_entero);
              return false;
            } else
              {
                return false;
              }
        } else
          {
            return true;
          }
    }
  var completo = document.getElementById(id).value;
  if (mas_de_un_punto(completo)==true)
    {
      if (mensaje_error!=null)
        {
          error_Campo(id,mensaje_error);
          return false;
        } else
          {
            return false;
          }
    } else
      {        
        var pos = completo.indexOf(","); //.
        if (pos!=-1)
          {
            if (pos<1)
              {
                if (mensaje_error!=null)
                  {
                    error_Campo(id,mensaje_error);
                    return false;
                  } else
                    {
                      return false;
                    }
              } else
                {                  
                  var entero = completo.substring(0,pos); //pos-1
                  var decimal = completo.substring(pos+1,completo.length);
                  if (max_length(max_length_entero,entero)==true)//max_length_entero-1
                    {
                      if (mensaje_error_entero!=null)
                        {
                          if (isIE()) e.keyCode = 0; 
                          if (isNS()) e.which = 0;
                          error_Campo(id,mensaje_error_entero);
                          return false;
                        } else
                          {
                            return false;
                          }
                    }
                  if (max_length(max_length_fraccion-1,decimal)==true)//max_length_fraccion-1*
                    {
                      if (mensaje_error_decimal!=null)
                        {
                          if (isIE()) e.keyCode = 0; 
                          if (isNS()) e.which = 0;
                          error_Campo(id,mensaje_error_decimal);
                          return false;
                        } else
                          {
                            return false;
                          }
                    }
                  return true;
                }
        } else
          {
            var tecla;
            if (isIE()) tecla = e.keyCode; 
            if (isNS()) tecla = e.which;
            var sigue;
            if(tecla!=44) sigue = max_length(max_length_entero-1,completo);//46
            else sigue = max_length(max_length_entero,completo)
            if (sigue==true)
              {                
                if (mensaje_error_entero!=null)
                  {
                    if (isIE()) e.keyCode = 0; 
                    if (isNS()) e.which = 0;
                    error_Campo(id,mensaje_error_entero);
                    return false;
                  } else
                    {
                      return false;
                    }
              }            
            return true;
          }
      }
}*/


/****************************************
Funcion que evalua si el dato pasado
como parametro posee supera el max_length
impuesto.
*****************************************/
function max_length_Campo(max_length,dato,id,mensaje_error)
{
  try{ idiomaTradu = document.getElementById('idiomaActual').value; } catch(e) {}
  if (idiomaTradu == undefined) idiomaTradu = "es_ES";
  
    
  
  if (id==null)
    {
      alert(obtenerTraduccion("id_nulo", idiomaTradu));
    }  
  if (max_length(max_length,dato)==true)
  	{
      if (mensaje_error!=null)
        {
          error_campo(id,mensaje_error);
          return false;
        } else
          {
            return false;
          }
    } else
      {
   			return true;
    	} 	
}

function onlyDate(e, id){

    var FORWARD_SLASH = 47;
    var _ret = true;
    
    try {
        idiomaTradu = document.getElementById('idiomaActual').value;
    } 
    catch (e) {
    }
    if (idiomaTradu == undefined) 
        idiomaTradu = "es_ES";
    
    
    if (id == null) {
        alert(obtenerTraduccion("id_nulo", idiomaTradu));
        return _ret;
    }
    if (e == null) {
        alert(obtenerTraduccion("evento_nulo", idiomaTradu));
        //alert('El evento de teclado no puede ser nulo');
        return _ret;
    }
    
    //si se ha pulsado el boton retroceso o suprimir
    if (isNS() || isMozilla()) {
        if (e.which == 8 || e.which == 46 || e.which == 0) {
            return false;
        }
    }
    var completo = document.getElementById(id).value;
    if (isIE()) {
    
        if (window.event.keyCode == FORWARD_SLASH) {
            if (((completo.length != 2) && (completo.length != 5)) || (completo.length > 10)) {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
    }
    if (isNS() || isMozilla()) {
    
        if (e.which == FORWARD_SLASH) {
            if (((completo.length != 2) && (completo.length != 5)) || (completo.length > 10)) {
                _ret = false;
            }
        }
    }
    
    if (completo.length == 0) {
        if (isIE()) {
            if (window.event.keyCode <= 51 && window.event.keyCode > 47) {
                _ret = true;
            }
            else {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
        else 
            if (isNS() || isMozilla()) {
                if (e.which <= 51 && e.which > 47) {
                    _ret = true;
                }
                else {
                    e.stopPropagation();
                    e.preventDefault();
                    _ret = false;
                }
            }
    }
    // Segundo caracter esta entre los valores 48 y 57 si el primer caracter
    // es el 0, 1, 2 en el caso de que sea un 3 los valores admitidos seran
    // 48 y 49
    else  if (completo.length == 1) {
        if ((completo.charAt(0) == '0') || (completo.charAt(0) == '1') || (completo.charAt(0) == '2')) {
            if (isIE()) {
                if (window.event.keyCode <= 57 && window.event.keyCode > 47) {
                    _ret = true;
                }
                else {
                    window.event.keyCode = 0;
                    _ret = false;
                }
            }
            else 
                if (isNS() || isMozilla()) {
                    if (e.which <= 57 && e.which > 47) {
                        _ret = true;
                    }
                    else {
                        e.stopPropagation();
                        e.preventDefault();
                        _ret = false;
                    }
                }
        }
        else {
            if (isIE()) {
                if (window.event.keyCode <= 49 && window.event.keyCode > 47) {
                    _ret = true;
                }
                else {
                    window.event.keyCode = 0;
                    _ret = false;
                }
            }
            else 
                if (isNS() || isMozilla()) {
                    if (e.which <= 49 && e.which > 47) {
                        _ret = true;
                    }
                    else {
                        e.stopPropagation();
                        e.preventDefault();
                        _ret = false;
                    }
                }
        }
    }
    // Se inserta un la barra y luego se da paso al numero en cuestion    
    else   if (completo.length == 2) {
        document.getElementById(id).value = document.getElementById(id).value + '/';
        if (isIE()) {
            if (window.event.keyCode <= 49 && window.event.keyCode > 47) {
                _ret = true;
            }
            else {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
        else 
            if (isNS() || isMozilla()) {
                if (e.which <= 49 && e.which > 47) {
                    _ret = true;
                }
                else {
                    e.stopPropagation();
                    e.preventDefault();
                    _ret = false;
                }
            }
    }
    else  if (completo.length == 3) {
        if (isIE()) {
            if (window.event.keyCode <= 49 && window.event.keyCode > 47) {
                _ret = true;
            }
            else {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
        else 
            if (isNS() || isMozilla()) {
                if (e.which <= 49 && e.which > 47) {
                    _ret = true;
                }
                else {
                    e.stopPropagation();
                    e.preventDefault();
                    _ret = false;
                }
            }
    }
    else  if (completo.length == 4) {
        if (isIE()) {
            if (completo.charAt(3) == '0') {
                if (window.event.keyCode <= 57 && window.event.keyCode > 47) {
                    _ret = true;
                }
                else {
                    window.event.keyCode = 0;
                    _ret = false;
                }
            }
            else {
                if (window.event.keyCode <= 50 && window.event.keyCode > 47) {
                    _ret = true;
                }
                else {
                    window.event.keyCode = 0;
                    _ret = false;
                }
            }
        }
        else  if (isNS() || isMozilla()) {
            if (completo.charAt(3) == '0') {
                if (e.which <= 57 && e.which > 47) {
                    _ret = true;
                }
                else {
                    e.stopPropagation();
                    e.preventDefault();
                    _ret = false;
                }
            }
            else {
                if (e.which <= 50 && e.which > 47) {
                    _ret = true;
                }
                else {
                    e.stopPropagation();
                    e.preventDefault();
                    _ret = false;
                }
            }
        }
    }
    else if (completo.length == 5) {
        document.getElementById(id).value = document.getElementById(id).value + '/';
        if (isIE()) {
            if (window.event.keyCode <= 57 && window.event.keyCode > 47) {
                _ret = true;
            }
            else {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
        else if (isNS() || isMozilla()) {
            if (e.which <= 57 && e.which > 47) {
                _ret = true;
            }
            else {
                e.stopPropagation();
                e.preventDefault();
                _ret = false;
            }
        }
    }
    else  if ((completo.length > 5) && (completo.length <= 10)) {
        if (isIE()) {
            if (window.event.keyCode <= 57 && window.event.keyCode > 47) {
                _ret = true;
            }
            else {
                window.event.keyCode = 0;
                _ret = false;
            }
        }
        else  if (isNS() || isMozilla()) {
            if (e.which <= 57 && e.which > 47) {
                _ret = true;
            }
            else {
                e.stopPropagation();
                e.preventDefault();
                _ret = false;
            }
        }
    }
    else {
        if (isIE()) {
            window.event.keyCode = 0;
            _ret = false;
        }
        else  if (isNS() || isMozilla()) {
            e.stopPropagation();
            e.preventDefault();
            _ret = false;
        }
    }
    return (_ret);
}







function Validar_Fecha (id, i, j , k){
  var idiomaTradu;
  var errorAnyo = '';
  var errorMes  = '';
  var errorDia  = '';
  
  //muestraDatosNavegador();
  pObj = document.getElementById(id);
  
  try{ idiomaTradu = document.getElementById('idiomaActual').value; } catch(e) {}
  if (idiomaTradu == undefined) idiomaTradu = "es_ES";
  
  if (pObj == null) 
  {
      alert(obtenerTraduccion("id_nulo", idiomaTradu));
      return false;
  }
  
  errorAnyo = obtenerTraduccion("errorAnyo", idiomaTradu);
  errorMes  = obtenerTraduccion("errorMes", idiomaTradu);
  errorDia  = obtenerTraduccion("errorDia", idiomaTradu);
     
  if ((pObj.value!='') && (Validar_Fecha_interna(pObj.id, errorAnyo, errorMes, errorDia) == false))
  {
      if (isNombreFirefox()) 
      {
          pObj.value = "";
      }
      else{
          pObj.focus();
          pObj.select();
      }
  }
}


function Validar_Fecha_interna(id,mensaje_error_ano,mensaje_error_mes,mensaje_error_dia)
{
  try{ idiomaTradu = document.getElementById('idiomaActual').value; } catch(e) {}
  if (idiomaTradu == undefined) idiomaTradu = "es_ES";
  if (id==null)
    {
      //alert('El id no puede ser nulo');
      alert(obtenerTraduccion("id_nulo", idiomaTradu));
      return false;
    }
	var Fecha= document.getElementById(id).value;	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

	// Valido el año
	if (isNaN(Ano) || Ano.length<4  || Ano.length>4 || parseFloat(Ano)<0)
    {
      if (mensaje_error_ano==null)
        {
          alert('Año inválido');      
          return false;
        } else
          {
            //error_Campo(id,mensaje_error_ano);
            alert(mensaje_error_ano);
            return false;
          }
    }
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12)
    {
      if (mensaje_error_mes==null)
        {
          alert('Mes inválido');
          return false;
        } else
          {
            //error_Campo(id,mensaje_error_mes);
            alert(mensaje_error_mes);
            return false;
          }
    }
	// Valido el Dia
  if (isNaN(Dia) ||Number(Dia)<1 ||Number(Dia)>31)
    {
      if (mensaje_error_dia==null)
        {
          alert('Día inválido');
          return false;
        } else
          {
            //error_Campo(id,mensaje_error_dia);
            alert(mensaje_error_dia);
            return false;
          }
    }
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) 
      {    
        if (mensaje_error_dia==null)
          {
            alert('Día inválido');
            return false;
          } else
            {
              
              //error_Campo(id,mensaje_error_dia);
              alert(mensaje_error_dia);
              return false;
            }
      }
	}
	
  //para que envie los datos, quitar las  2 lineas siguientes
 // alert("Fecha correcta.")
 return true;
}

function can_be_null(id,canbeNull,mensaje_error)
{
  try{ idiomaTradu = document.getElementById('idiomaActual').value; } catch(e) {}
  if (idiomaTradu == undefined) idiomaTradu = "es_ES";
  if (id==null)
    {
      //alert('El id no puede ser nulo');
      alert(obtenerTraduccion("id_nulo", idiomaTradu));
      return false;
    }
  if (canbeNull==null)
    {
      //alert('El parametro CanBeNull no puede ser nulo.');
      alert(obtenerTraduccion("canbenull_nulo", idiomaTradu));
      return false;
    }
  if (canbeNull==true)
    {
      return true;
    } else
      {
        var completo = document.getElementById(id).value;
        if (completo.length<1)
          {
            if (mensaje_error==null)
              {
                //alert('El campo '+document.getElementById(id).name+' no puede ser nulo');
                alert(obtenerTraduccion("fecha_campo1", idiomaTradu) + +document.getElementById(id).name+ obtenerTraduccion("fecha_campo2", idiomaTradu));
                return false;
              } else
                {
                  error_Campo(id,mensaje_error);
                }
          }
      }
}
/****************************************
Calcula la fecha y la hora actual, actualizando esta cada segundo
SNG
*****************************************/
function reloj() {
   if (!document.layers&&!document.all&&!document.getElementById)
    return
   var Digital=new Date()
   var hours=Digital.getHours()
   var minutes=Digital.getMinutes()
   var seconds=Digital.getSeconds()
   var dn="AM"
   /*
   if (hours>12){
   dn="PM"
   hours=hours-12
   }
   */
   /*
   if (hours==0)
   hours=12
   */
   if (minutes<=9)
    minutes="0"+minutes
   if (seconds<=9)
    seconds="0"+seconds
  //change font size here to your desire
   myclock="  "+hours+":"+minutes+":"
   //+seconds+" "+dn;
   +seconds;
   if (document.layers){
    document.layers.liveclock.document.write("Hora: "+myclock)
    document.layers.liveclock.document.close()
   }
   else if (document.all)
    liveclock.innerHTML="Hora: "+myclock
   else if (document.getElementById)
    document.getElementById("liveclock").innerHTML="Hora: "+myclock
    setTimeout("reloj()",1000)
    var	today13 =	new	Date();
    var	dateNow13	 = today13.getDate();
    var	monthNow13	 = today13.getMonth()+1;
    var	yearNow13	 = today13.getYear();
  
    var fechaDeHoy=String(dateNow13).padL(2,'0')+'-'+String(monthNow13).padL(2,'0')+'-'+yearNow13;
  //document.write("<span class='normal-font'>"+fechaHoy+"</span>");
    document.getElementById('fechahoy').innerHTML=fechaDeHoy;
}

/*function maxLongitudTooltip(ancho,cadena,id)
{
  var longitudmaxima = ancho + 5;
  if (cadena.length>longitudmaxima)
  { 
    contenido = '<span title="'+cadena+'">'+cadena.substring(0,longitudmaxima)+'<font class="listado_abreviatura">&raquo;<//font><//span>';
  }else contenido = cadena;
  document.writeln('<td width="'+ancho+'%" align="left" class="Facturacion-LineaFras'+id+'" ><label class="Facturacion-Label">'+contenido+'<//label><//td> ');
}*/


function comprobarFecha(pObj){
  var idiomaTradu;
  var errorAnyo = '';
  var errorMes  = '';
  var errorDia  = '';
  
  //muestraDatosNavegador();
  
  try{ idiomaTradu = document.getElementById('idiomaActual').value; } catch(e) {}
  if (idiomaTradu == undefined) idiomaTradu = "es_ES";
  
  errorAnyo = obtenerTraduccion("errorAnyo", idiomaTradu);
  errorMes  = obtenerTraduccion("errorMes", idiomaTradu);
  errorDia  = obtenerTraduccion("errorDia", idiomaTradu);
     
  if ((pObj.value!='') && (Validar_Fecha_interna(pObj.id, errorAnyo, errorMes, errorDia) == false))
  {
      if (isNombreFirefox()) 
      {
          pObj.value = "";
      }
      else{
          pObj.focus();
          pObj.select();
      }
  }
}

