//Vectores de keys
var ControlKey = new Array(8, 9, 13, 16, 17, 18, 35, 36, 37, 38, 39, 40, 46, 116);
var NumberKey = new Array(48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105);
var DecimalKey = new Array(110, 188, 190);

//Verifica si un key es del tipo Control
//Recibe el código del key
//Devuelve true si lo es
function keyControl(nKey){
   for (i = 0; i < ControlKey.length; i++){
       if (nKey == ControlKey[i]){
          return (true);
       }
   }
   return (false);
}

//Verifica si un key es del tipo Numerico
//Recibe el código del key
//Devuelve true si lo es
function KeyNumber(nKey){
   for (i = 0; i < NumberKey.length; i++){
       if (nKey == NumberKey[i]){
          return (true);
       }
   }
   return (false);
}

//Verifica si un key es del tipo Decimal
//Recibe el código del key
//Devuelve true si lo es
function KeyDecimal(nKey){
   for (i = 0; i < DecimalKey.length; i++){
       if (nKey == DecimalKey[i]){
          return (true);
       }
   }
   return (false);
}


//CheckBOX
function CheckAll(){
  for (var i = 0; i < document.form.elements.length; i++) {
      if (document.form.elements[i].type == 'checkbox'){
         document.form.elements[i].checked = !(document.form.elements[i].checked);
      }
  }
}

//Confirmación de eliminación
function confirmar_eliminacion(){
  return confirm("Desea eliminar los registros seleccionados?");
}



//Confirmación de eliminación
function confirmar_eliminacion_img()
{
	return confirm("Confirma eliminar esta imagen del articulo?");
}


/*
Valida un fecha ingresada
Recibe el número de día, de mes y de año
Devuelve true si es válida
*/
function ValidDate(day, mon, year){
    res = true;
            
    var DayMonth = new Array();
    
    DayMonth[0] = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    DayMonth[1] = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
    
    if( (mon<1) || (mon>12) )
        res = false;
    else
    {
        i = ( year%4==0 && ( (year%100!=0) || (year%400==0) ) ) ? 1:0 ;
        d = DayMonth[i][mon];
        if( (day<1) || (day>d) )
            res = false;
    }
    
    return res;        
}

/*
Abre una ventana de acuerdo a la dirección recibida
Recibe el ancho, el alto y el nombre de la página
*/
function OpenWindow(location, nWidth, nHeight, sNombre){
   settings = "width="+nWidth+", height="+nHeight+", top='+TopPosition+', left=+RightPosition+, scrollbars = yes, resizable = no, fullscreen = no, toolbar = no, location = no, menubar = no, status = no";
   newindow = window.open(location,sNombre, settings);
}

/*
Esconde un objeto recibido
Devuelve 1 si muestra el objeto
0 si lo oculta
*/
function OcultaObjeto(sNombre){
    if (document.getElementById(sNombre).style.display == "none"){
      document.getElementById(sNombre).style.display = "";
      return 1;
    }
    else{
      document.getElementById(sNombre).style.display = "none";
      return 0;
    }
}

/*
Convierte una cadena a mayúscula
Recibe la cadena a convertir, el evento que los dispara y el objeto del textbox
Devuele la cadena convertida
*/
function aMayuscula(sCadena, e, ObjText){
   if (!keyControl(e)){
      var sCadenaMayus = sCadena.toUpperCase();
      ObjText.value = (sCadenaMayus);
   }
}

/*
Permite ingresar en un campo sólo números (con decimales)
Recibe el evento que los dispara
Devuele true si es correcto
*/
function aNumero(e){
   if ((KeyNumber(e)) || (keyControl(e)) || (KeyDecimal(e))){
      return (true);
   }
   else{
        return (false);
   }
}

/*
Permite ingresar en un campo sólo números enteros
Recibe el evento que los dispara
Devuele true si es correcto
*/
function aEntero(e){
   if ((KeyNumber(e)) || (keyControl(e))){
      return (true);
   }
   else{
        return (false);
   }
}

// CODIGO DE ROLLOVER DE COLOR DE CELDAS

function cOvr(src) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
}
}

function cOut(src) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
}
}

function mOvr(src,clrOver) {
if (!src.contains(event.fromElement)) {
src.style.cursor = 'hand';
src.bgColor = clrOver;
}
}

function mOut(src,clrIn) {
if (!src.contains(event.toElement)) {
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}

function mClk(src) {
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();
}
}

//FECHA
function mostrarFechaActual(){
         var vDiaSemana = new Array();
         var vMeses = new Array();
         vDiaSemana[0] = 'Domingo';
         vDiaSemana[1] = 'Lunes';
         vDiaSemana[2] = 'Martes';
         vDiaSemana[3] = 'Miércoles';
         vDiaSemana[4] = 'Jueves';
         vDiaSemana[5] = 'Viernes';
         vDiaSemana[6] = 'Sábado';
         vMeses[0] = 'Enero';
         vMeses[1] = 'Febrero';
         vMeses[2] = 'Marzo';
         vMeses[3] = 'Abril';
         vMeses[4] = 'Mayo';
         vMeses[5] = 'Junio';
         vMeses[6] = 'Julio';
         vMeses[7] = 'Agosto';
         vMeses[8] = 'Septiembre';
         vMeses[9] = 'Octubre';
         vMeses[10] = 'Noviembre';
         vMeses[11] = 'Diciembre';

         fecha = new Date();
         dia = fecha.getDay();
         document.write(vDiaSemana[dia]);
         document.write(" ");
         numero = fecha.getDate();
         document.write(numero);
         document.write(" de ");
         mes = fecha.getMonth();
         document.write(vMeses[mes]);
         document.write(" de ");
         ano = fecha.getYear();
         document.write(ano);
}

// DETECCION DE RESOLUCION PARA TAMAÑO POPUP
agent = navigator.userAgent;
if (parseInt(agent.substring(8,9)) > 3) {
if (screen.width >= 800) {
winwidth = 760;
winheight = 520;
} else {
winwidth = 620;
winheight = 420;
}
}
if (parseInt(agent.substring(8,9)) <= 3) {
winwidth = 620;
winheight = 420;
}

// POPUP NORMAL CENTRADO
function popup(url,name,width,height,resize,scroll) {
var dialogWin = new Object();
dialogWin.width = width;
dialogWin.height = height;
now = new Date();
var millis=now.getTime();
var mstr=""+millis;
if (navigator.appName == "Netscape") {
dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2);
dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2);
var attr = 'screenX=' + dialogWin.left + ',screenY=' + dialogWin.top + ',resizable=' + resize + ',width=' + dialogWin.width + ',height=' + dialogWin.height + ',scrollbars=' + scroll + ',menubar=no,location=no,toolbar=no,status=no,directories=no';
} else if (document.all) {
dialogWin.left = (screen.width - dialogWin.width) / 2;
dialogWin.top = (screen.height - dialogWin.height) / 2;
var attr = 'left=' + dialogWin.left + ',top=' + dialogWin.top + ',resizable=' + resize + ',width=' + dialogWin.width + ',height=' + dialogWin.height + ',scrollbars=' + scroll + ',menubar=no,location=no,toolbar=no,status=no,directories=no';
}
window.open(url,name,attr);
}



// COMPATIBILIZACION TAMAÑO TEXTBOX
function textbox(nombre, tamanio, valor, evento)
{
if (navigator.appName.substring(0,1)=="M") {
document.write('<input style="font-family: Tahoma,Verdana,Arial,Helvetica; font-size: 8pt" type=text name='+ nombre +' size=' + tamanio + ' value=\"' + valor + '\" ' + evento + '>');
} else  {
document.write('<input type=text name='+ nombre +' size=' + (tamanio-3) + ' value=\"' + valor +  '\" ' + evento + '>');
}
}

function textboxpass(nombre, tamanio, valor)
{
if (navigator.appName.substring(0,1)=="M") {
document.write('<input style="font-family: Tahoma,Verdana,Arial,Helvetica; font-size: 8pt" type=password name='+ nombre +' size=' + tamanio + ' value=' + valor +'>');
} else  {
document.write('<input type=password name='+ nombre +' size=' + (tamanio-3) + ' value=' + valor +'>');
}
}






