var oData = [];
var eMail=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
var Numeros = /\d/;

function DisEle(oObjeto,sDis){
    if (sDis=="D") {
        document.getElementById(oObjeto).disabled = true;
    }
    if (sDis=="d") {
        document.getElementById(oObjeto).disabled = false;
    }
}
function GetVal(oObjeto){
    return document.getElementById(oObjeto).value;
}
function AsiVal(oObjeto,Valor){
    document.getElementById(oObjeto).value = Valor;
}
function GetObj(oObjeto){
    return document.getElementById(oObjeto);
}
function lCase(sCampo){AsiVal(sCampo,GetVal(sCampo).toLowerCase().replace(/([^0-9 a-z])/g,""));}
function uCase(sCampo){AsiVal(sCampo,GetVal(sCampo).toUpperCase().replace(/([^0-9 A-Z])/g,""));}
function msgElimina(sMsg){  
    Ext.MessageBox.show({
        title:'Eliminar',
        msg: sMsg,
        closable:false,
        width:240,
        buttons: Ext.MessageBox.YESNO,
        fn: function (btn){ 
            if (btn=='yes'){    
                Eliminar();                
            }
       }
    });
} 
function msgGuarda(sMsg){  
    Ext.MessageBox.show({
        title:'Guardar',
        msg: sMsg,
        closable:false,
        width:240,
        buttons: Ext.MessageBox.YESNO,
        fn: function (btn){ 
            if (btn=='yes'){  
                Guardar();                
            }
       }
    });
}
function msgAbandona(sMsg){  
    Ext.MessageBox.show({
        title:'Abandonar',
        msg: sMsg,
        closable:false,
        width:240,
        buttons: Ext.MessageBox.YESNO,
        fn: function (btn){ 
            if (btn=='yes'){    
                Abandona();                
            }
       }
    });
}
function msgbox(sTitulo,sMsg){
    Ext.MessageBox.alert(sTitulo,sMsg);
}
function keyEnter(siguiente,variable){
    var miEvento = window.event;
    var key = miEvento.keyCode;
    if (key!=0) {
        if (variable != undefined) {
            $("#"+variable).val(1);
        } else {
            $("#sBody").val(1);
        }
        if (key==13 || key==9){setfocus(siguiente)} 
    }
}
function Uletras(objeto){
    var miElemento = GI(objeto);
    if(/[^0-9A-Z .-]/.test(miElemento.value)){
        miElemento.value = miElemento.value.toUpperCase().replace(/([^0-9A-Z .-])/g,"");
    }
}
function uletras(objeto){
    var miElemento = GI(objeto);
    if(/[^0-9 a-z .-]/.test(miElemento.value)){
        miElemento.value = miElemento.value.toLowerCase().replace(/([^0-9a-z .-])/g,"");
    }
}
function eMailValida(objeto){
    var miElemento = GetObj(objeto);
    if(/[^A-Za-z][^A-Za-z0-9_-]*@[^a-z0-9_-]+\.[^a-z0-9_.]+[^a-z]/.test(miElemento.value))
        return true;
    else
        return false;
}
function letras(objeto){
    var miElemento = objeto;
    if(/[^A-Za-z][^A-Za-z0-9_-]*@[^a-z0-9_-]+\.[^a-z0-9_.]+[^a-z]/.test(miElemento.value)){
        miElemento.value = miElemento.value.replace(/([^A-Za-z][^A-Za-z0-9_-]*@[^a-z0-9_-]+\.[^a-z0-9_.]+[^a-z])/g,"");
    }
}
function SoloNumeros(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 
function SoloLetras(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;
    patron = /\w/;
    te = String.fromCharCode(tecla);
    return patron.test(te); 
} 
function numeros(objeto){
    var miElemento = document.getElementById(objeto);
    if(/[^0-9.$%,]/.test(miElemento.value)){
        miElemento.value = miElemento.value.replace(/([^0-9.$%,])/g,"");
    }
}
function setfocus(a_field_id) {
    document.getElementById(a_field_id).focus();
}
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;
    s = s.substring(j, i);
  }
  return s;
}
function RTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1;       // Get length of string
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
    s = s.substring(0, i+1);
  }
  return s;
}
function trim(str)
{
  return RTrim(LTrim(str));
} 
function getData(sParameters){
	var sUrl = "http://"+sServer+"/DIME/asp/vb/getDatos.asp?" + sParameters;
    var sResponse = $.ajax({url: sUrl, async: false}).responseText;
    if (sResponse=='') {oData = [];} else {eval("oData = " + sResponse);}
}
function putData(sParameters){
    var sUrl = "http://"+sServer+"/DIME/asp/vb/putData.asp?"+sParameters;
    var sResponse = $.ajax({url: sUrl, async: false}).responseText;
    eval("oData = "+ sResponse);
}
function LlenaCombo(sSelect,sTabla,sCampos,sFiltro,sInicial){
    if (sInicial!=false){sInicial = true;}
    if (trim(sSelect) == "") {alert("FALTA! Campo de datos");return false;}
    if (trim(sTabla) == "") {alert("FALTA! Tabla de datos");return false;}
    if (trim(sCampos) == "") {alert("FALTA! Campos de la tabla de datos");return false;}
    sParams = "tabla="+sTabla+"&campos="+sCampos+"&objeto=1";
    if (trim(sFiltro) != "") {
        sParams += "&filtro="+sFiltro;
    }
    getData(sParams);
    if (oData == false) {
        return false;  
    }
    else {
        oSelect = document.getElementById(sSelect);
        oSelect.options.length = 0;      
        if (sInicial) {oSelect.options[0] = new Option("-- Seleccione --",0);}
        for (i in oData){
            if (i!=0){
                oOpcion = oData[i];
                if (sInicial) {
                    oSelect.options[i] = new Option(oOpcion[0],oOpcion[1]);        
                } else {
                    oSelect.options[i-1] = new Option(oOpcion[0],oOpcion[1]);        
                }
            }
        }
        return true;
    }
}
function iif(condicion,verdadero,falso){
    if (condicion){return verdadero;}
    else {return  falso;}
}
function ConvertCombo(idCombo, nWidth){
    var converted = new Ext.form.ComboBox({
        typeAhead: true,
        triggerAction: 'all',
        transform: idCombo,
        width: nWidth,
        forceSelection:true
    });
    return converted;
}
