// este JS contiene todos los metodos que son comunes a la mayoria de las plantillas
// coloque metodos aqui, solo si esta seguro que esto es de utilidad para todos, de los
// contrario, arme rancho en otro lado
// author Oliver ACE
// since  27 dec 2002
//////////////////////////////////////////////////////////////////////////////////////
var win = null;

var isIE=document.all?true:false;
// filtroNumero:
// impide que en un campo de texto se digite algo diferente a un numero
// usese como <input type="text"  onkeydown="filtro(this)"  onkeyup="filtro(this)" onblur="filtro(this)" onclick="filtro(this)" />
//////////////////////////////////////////////////////////////////////////////////////
function filtroNumeroInt(texto){// numeros enteros
  texto.value=texto.value.toUpperCase().replace(/([^0-9])/g,"");
}
function filtroNumeroDec(texto){// numeros decimales
  texto.value=texto.value.toUpperCase().replace(/([^0-9\.])/g,"");
}
function filtroLetras(texto){// letras en Mayuscula
  texto.value=texto.value.toUpperCase().replace(/([^A-Z\Ñ\ñ\á\Á\ó\Ó\í\Í\é\É\ú\Ú\+\-\*\ \(\)\/\[\]\^\%\!\@\#\?\,\;\~\`\<\>])/g,"");
}
function filtroUpperCase(texto){
  texto.value=texto.value.toUpperCase().replace(/([^0-9^A-Z\ \Ñ\ñ\á\Á\ó\Ó\í\Í\é\É\ú\Ú\+\-\*\(\)\/\[\]\^\%\!\@\#\?\,\;\~\`\<\>])/g,"");;
}
function filtroLowerCase(texto){
  texto.value=texto.value.toLowerCase();
}

// options: [para showmodal]

// *dialogHeight: 100px ancho 
// *dialogWidth : 100px alto
// center:{ yes | no | 1 | 0 | on | off }
// help:{ yes | no | 1 | 0 | on | off }
// *resizable:{ yes | no | 1 | 0 | on | off }
// scroll:{ yes | no | 1 | 0 | on | off }
// *status:{ yes | no | 1 | 0 | on | off }

// para window.open
// *height = number
// *left = number
// menubar = { yes | no | 1 | 0 }
// *resizable = { yes | no | 1 | 0 }
// scrollbars = { yes | no | 1 | 0 }
// *status = { yes | no | 1 | 0 }
// titlebar = { yes | no | 1 | 0 }
// toolbar = { yes | no | 1 | 0 }

// para aplicacion
// options es un string, los valores que alli aparezcan se toman como true
// CENTER    : ventana centrada
// SCROLL    : tiene scroll
// STATUS    : tiene barra status
// NOTITLEBAR: no tiene barra de título
// MENUBAR   : tiene barra de menu
// HELP      : tiene boton de ayudas
// RESIZABLE : se puede mod tanano
// MODAL     : es ventana modal
// TOOLBAR   : barra herramientas
// LOCATION  : info de ubicacion [http:// blablabla.com]
// <!-- link nombre ancho alto opciones -->
var dialogWin = new Object();
function openWindow(mypage,myname,w,h,options){
  //--hallamos los parametros
if ((!options)||(options==null)) alert('no hay opciones definidas en ventana emergente!! ['+mypage+']');
  var help     = (options.toUpperCase().indexOf("HELP")      != -1)?'1':'0';
  var modal    = (options.toUpperCase().indexOf("MODAL")     != -1)?'1':'0';
  var modeLess = (options.toUpperCase().indexOf("MODELESS")  != -1)?'1':'0';
  var maxim    = (options.toUpperCase().indexOf("MAXIM")     != -1)?'1':'0';
  var center   = (options.toUpperCase().indexOf("CENTER")    != -1)?'1':'0';
  var scroll   = (options.toUpperCase().indexOf("SCROLL")    != -1)?'1':'0';
  var toolbar  = (options.toUpperCase().indexOf("TOOLBAR")   != -1)?'1':'0';
  var location = (options.toUpperCase().indexOf("LOCATION")  != -1)?'1':'0';
  var status   = (options.toUpperCase().indexOf("TOOLBAR")   != -1)?'1':'0';
  var menubar  = (options.toUpperCase().indexOf("MENUBAR")   != -1)?'1':'0';
  var resizable= (options.toUpperCase().indexOf("RESIZABLE") != -1)?'1':'0';
  var notitlebar=(options.toUpperCase().indexOf("NOTITLEBAR")!= -1)?'1':'0';//? no aplica a todos los browwsers, ie es <titlebar>
  var semiModal= (options.toUpperCase().indexOf("SEMIMODAL") != -1)?'1':'0';
  var borde    = (options.toUpperCase().indexOf("BORDE")     != -1)?'Raised':'Sunken';
  var left     = 20;
  var top      = 20;
  var day      = new Date();
  var now      = day.getTime();
  
  if  (maxim=='yes'){ // si es maximizada 
      left= 0;
      top = 0;
      if (modal=='yes'){
        w   = (screen.width)?screen.width:640;
        h   = (screen.height)?(screen.height-9):480;
        
      }else{
        w   = (screen.width)?screen.width-12:640;
        h   = (screen.height)?(screen.height-73):480;
      }
  }else{
    left = (screen.width) ? (screen.width-w)/2 : 0;
    top  = (screen.height) ? (screen.height-h)/2 : 0;
  }
  if ((modal=='yes')&&(isIE)){
    datosObj = loadObj();
    window.name=''+myname;
    if (center=='yes') win = window.showModalDialog(""+mypage,datosObj,"dialogHeight: "+h+"px; dialogWidth: "+w+"px; dialogTop:       px; dialogLeft:        px; edge:"+borde+"; center:Yes;help:"+help+"; resizable:"+resizable+"; status:"+status+"; scroll"+scroll+";");
    else               win = window.showModalDialog(""+mypage,datosObj,"dialogHeight: "+h+"px; dialogWidth: "+w+"px; dialogTop:"+top+"px; dialogLeft:"+left+"px; edge:"+borde+"; center: No;help:"+help+"; resizable:"+resizable+"; status:"+status+"; scroll"+scroll+";");
    if (win) openWindow(mypage,myname,w,h,options);
  }else if((modeLess=='yes')&&(isIE)){
   alert(1);
    datosObj = new Object();
    datosObj.name = ''+myname;
    window.name=''+myname;
    if (center=='yes') win = window.showModelessDialog(""+mypage,datosObj,"dialogHeight: "+h+"px; dialogWidth: "+w+"px; dialogTop:       px; dialogLeft:        px; edge:"+borde+"; center:Yes;help:"+help+"; resizable:"+resizable+"; status:"+status+"; scroll"+scroll+";");
    else               win = window.showModelessDialog(""+mypage,datosObj,"dialogHeight: "+h+"px; dialogWidth: "+w+"px; dialogTop:"+top+"px; dialogLeft:"+left+"px; edge:"+borde+"; center: No;help:"+help+"; resizable:"+resizable+"; status:"+status+"; scroll"+scroll+";");
  }else if((semiModal=='yes')&&(isIE)){
   alert(2);
    if (center=='yes') settings = 'height='+h+',width='+w+',top='+top+',left='+left+',scrollbars='+scroll+', status='+status+',resizable='+resizable+',menubar='+menubar;
    else               settings = 'height='+h+',width='+w+',top='+top+',left='+left+',scrollbars='+scroll+', status='+status+',resizable='+resizable+',menubar='+menubar;
    dialogWin.win = window.open(mypage,myname,settings);
    dialogWin.win.focus();
    //checkModal();
  }else{ 
    //alert('screen.width='+screen.width+'-- screen.height='+screen.height);
    if (center=='yes') settings = 'width='+w+',height='+h+',left='+left+',top='+top+',scrollbars='+scroll+', status='+status+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar+',location='+location;
    else               settings = 'width='+w+',height='+h+',left='+left+',top='+top+',scrollbars='+scroll+', status='+status+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar+',location='+location;
    eval("page" + now + " = window.open(mypage,'"+myname+"','"+settings+"');"); // tiene que ser con eval!
  }
}
//-----cargado de datos para enviar por opcion modal
function loadObj(){
    datosObj = new Object();
    datosObj.name = ''+myname;
    datosObj.nodoSelect = nodoSelect; // seleccion de nodo
    datosObj.makeSubmit = makeSubmit; // submit en ventana modal
    datosObj.enviarObs  = enviarObs;  // creacion de observación
    datosObj.enviarProv = enviarProv; // seleccion de proveedor
    datosObj.enviarSumi = enviarSumi; // seleccion de 1 suministro
    datosObj.enviaNSumi = enviaNSumi; // seleccion de N suministros
    datosObj.anularCoti = anularCoti; // anular una cotización
    datosObj.enviaOrden = enviaOrden; // envio de ordenes de compra
    datosObj.selElement = selElement; // seleccion elemento en maestros
    datosObj.cambioChkB = cambioChkB; // cambio de checkbox en inventarios
    datosObj.selElemen2 = selElemen2; // seleccion elemento en maestros
    datosObj.selElemen3 = selElemen3; // seleccion elemento en maestros
    datosObj.anularRequ = anularRequ; // anulando uan requisicion
    datosObj.sendSubmit = sendSubmit; // generioc de change and send
    datosObj.codificado = codificado; // cuando se codifica un suministro
    datosObj.borraFondo = borraFondo; // refrescar el fondo de la aplicación para que no quede huella!
return datosObj;
}
    //--FUNCIONES TRASLADADAS AL PADRE----------------
    function borraFondo(){
      if (window.parent.frames["frmMenu"]!=null){
        if(window.parent.frames["frmMenu"].frames["fondoFrame"]!=null){
          var locat = window.parent.frames[1].frames["fondoFrame"].location.pathname;
          var reld  = (locat.toUpperCase().indexOf("FONDO.JSP") != -1)?false:true;
          if (reld) window.parent.frames[1].frames["fondoFrame"].location='fondo.jsp';
        } 
      }else      
        if(window.top.frames[1].frames["fondoFrame"]!=null){
          var locat = window.top.frames[1].frames["fondoFrame"].location.pathname
          var reld  = (locat.toUpperCase().indexOf("FONDO.JSP") != -1)?false:true;
          if (reld) window.top.frames[1].frames["fondoFrame"].location='fondo.jsp';
      }
    }
    function makeSubmit(){ document.form.submit();}
    // maestros --------------------------------------
    function selElement(obj,valor){
      if (form.elements[obj]) form.elements[obj].value = valor;
    }
    function selElemen2(obj1,obj2,vala,valb){
      if (form.elements[obj1]) form.elements[obj1].value = vala;
      if (form.elements[obj2]) form.elements[obj2].value = valb;
    }
    function selElemen3(obj1,obj2,obj3,vala,valb,valc){
      if (form.elements[obj1]) form.elements[obj1].value = vala;
      if (form.elements[obj2]) form.elements[obj2].value = valb;
      if (form.elements[obj3]) form.elements[obj3].value = valc;
    }
    // inventarios -----------------------------------
    function cambioChkB(obj,valor){
      if (form.elements[obj]) form.elements[obj].checked = valor;
    }
    // envia y submit --------------------------------
    function sendSubmit(obj,valor,quehc){
       form.elements[obj].value      = valor;
       form.elements.queHacer.value  = quehc;
    }
    // ordenes de compra -----------------------------
    function enviaOrden(dat,quh){
       form.elements.numeroOrden.value=dat;
       form.elements.queHacer.value   =quh;
    }
    // cotizaciones ----------------------------------
    function anularCoti(cot,quh){
      form.elements.cotizacion.value=cot;
      form.elements.queHacer.value  =quh;
    }
    function codificado(val1,val2){
        form.elements.codificado(val1,val2);
    }
    // suministros -----------------------------------
    function enviarSumi(codigo, nombre){
        form.elements.codigoSuministro.value=codigo;
        form.elements.nombreGenerico.value  =nombre;
    }
    function enviaNSumi(listaSumi,tipo){
      form.elements.listaSuministros.value=listaSumi;
      form.elements.tipoSuministro.value  =tipo;
    }
    // proveedores -----------------------------------
    function enviarProv(dato1,dato2,dato3){
      if((dato1!=null)&&(dato2!=null)&&(dato3!=null)){
        form.elements.tipoIdentificacion.value=dato1;
        form.elements.identificacion.value    =dato2;
        form.elements.razonSocial.value       =dato3;
      }
    }
    // requisiciones----------------------------------
    function anularRequ(data){
      form.elements.queHacer.value='anular';
      form.elements.numeroDocumentoReq.value = data; 
      document.form.submit();
    }
    // observacion -----------------------------------
    function enviarObs(nombre,valor,queha){
      form.elements[nombre].value = valor;
      form.elements.queHacer.value= queha;
    }
    // arbol -----------------------------------------
    //window.dialogArguments.location.reload(true);}
    function nodoSelect(nodo,codigoNodo){
          form.elements.nodo.value      =nodo;
            form.elements.codigoNodo.value=codigoNodo;
    }

function dosclick(){
  alert('para acceder a la opción debe realizar un click sencillo (no doble click!)');
}
function exitWin(){
  alert('adios');
  self.close();
}

function keyDown(e){
  var ieKey = window.event.keyCode ;
}

function showLayer(whichLayer){
  if (document.getElementById){ 
    var style2 = document.getElementById(whichLayer).style;
    style2.display = "block";
  }else if (document.all){      
    var style2 = document.all[whichLayer].style;
    style2.display = "block";
  }else if (document.layers){   
    var style2 = document.layers[whichLayer].style;
    style2.display = "block";
  }
}

function hideLayer(whichLayer){
  if (document.getElementById){ 
    var style2 = document.getElementById(whichLayer).style;
    style2.display = "none";
  }else if (document.all){      
    var style2 = document.all[whichLayer].style;
    style2.display = "none";
  }else if (document.layers){   
    var style2 = document.layers[whichLayer].style;
    style2.display = "none";
  }
}
// botonCHG
// permite que un boton cambie de valor al presionar sobre el. Ver ordenamiento
//////////////////////////////////////////////////////////////////////////////////////
function botonCHG(yy,ww){
       if (yy.value=="<" ){  yy.value=  ">" ;  ww.value=  ">" ; yy.title='Mayor Que';     }
  else if (yy.value==">" ){  yy.value= "!=" ;  ww.value= "!=" ; yy.title='Diferente A';   }
  else if (yy.value=="!="){  yy.value=  "=" ;  ww.value=  "=" ; yy.title='Igual A';       }
  else if (yy.value=="=" ){  yy.value= "[]";   ww.value= "[]";  yy.title='Que contenga A';}
  else if (yy.value=="[]"){  yy.value= "<"  ;  ww.value= "<"  ; yy.title='Menor Que';     }
  else if (yy.value=="?"){   yy.value= "<"  ;  ww.value= "<"  ; yy.title='Menor Que';     }
}
// ordenPOR
// permite generar los campos necesario para que la clase sepa por que campo debe ordenar
//////////////////////////////////////////////////////////////////////////////////////
function ordenPOR(campo){
  document.form.campoAOrdenar.value=campo;
  if(document.form.tipodeOrden.value=='desc'){ document.form.tipodeOrden.value='asc';}
  else                                       { document.form.tipodeOrden.value='desc';}
  document.form.queHacer.value="";
  document.form.submit();
}
// borrarFiltro
// borra todos los campos de texto que comiencen por 'fitrarPor' y todos los selectBox
//////////////////////////////////////////////////////////////////////////////////////
function borrarFiltro(){
    f = document.form;
    for (i=0; i<f.elements.length;i++){
      var elemento = f.elements(i).name;
      var tipoelem = f.elements(i).type;
      if (elemento.indexOf('filtrarPor')==0) f.elements(i).value='';
      if (tipoelem=='select-one') f.elements(i).options[0].selected=true;
      if (tipoelem=='selectbox')  f.elements(i).options[0].selected=true;
   }

}
// --------------------------------------------
function se(e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 28){showLayer('xyz');tID=setTimeout("hideLayer('xyz')", 14500);}
if (keycode == 13){hideLayer('xyz');}
return true;
}
  //if (keycode == 13){
  //       myfield.form.submit();
  //       return false;
  //}else  return true;
// para evitar que se utilice el right click para que copien el codigo fuente
// tambien impide seleccionar texto en cuadro de texto
////////////////////////////////////////////////////////////////////////////////
//document.oncontextmenu = nocontextmenu;
//document.onmousedown   = norightclick;
//document.onmouseup     = norightclick;
function nocontextmenu() {
  event.cancelBubble = true, event.returnValue = false;
  return false;
}
function norightclick(e)
{
  if (window.Event)
     if (e.which == 2 || e.which == 3)
        return false;
     else if ( event && ( event.button == 2 || event.button == 3 ) )
     {
       event.cancelBubble = true;
       event.returnValue = false;
       return false;
   }
}
if ( document.layers ) document.captureEvents( Event.MOUSEUP | Event.MOUSEDOWN );



 
