/**
* Explorer for FirefoxOS v0.1
*
* Copyright Sebastián Rajo 2013.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* References:
* 
* - https://wiki.mozilla.org/WebAPI/DeviceStorageAPI
*/

(function () {

  isPicking = false;
  activityRequest = "";


var tam="";
var dir="";
var nombredelista="";
var rootdenombredelista="";
var temnombredelistaparacopiar="";
var roottemnombredelistaparacopiar="";
var nombre="";
var tama="";
var fecha="";
var tipo="";
var tipe="";
var dircrea="";
var nomtexto="";
var nametosavetxt="";
var deleteempty="";
var showiconplay="";
var acceso="";
var direccionpropiedades="";
var direccionpropiedades1="";
var typedeextencion="";
try {
                  (window.localStorage.getItem) // will throw in Firefox under some settings
                } catch(e){
                  return; // quit because dom.storage.enabled is false
                }


    
function color(){

      
    //document.getElementById( 'select1' ).style="#"+localStorage.getItem('select1');
    //document.getElementById( 'select2' ).style="#"+localStorage.getItem('select2');
    //document.getElementById( 'select3' ).style="#"+localStorage.getItem('select3');
    //document.getElementById( 'select4' ).style="#"+localStorage.getItem('select4');
    //document.getElementById( 'select5' ).style="#"+localStorage.getItem('select5');
    //document.getElementById( 'select6' ).style="#"+localStorage.getItem('select6');
    //document.getElementById( 'select7' ).style="#"+localStorage.getItem('select7');
    //document.getElementById( 'select8' ).style="#"+localStorage.getItem('select8');
    //document.getElementById( 'select9' ).style="#"+localStorage.getItem('select9');
    //document.getElementById( 'select10' ).style="#"+localStorage.getItem('select10');
    //document.getElementById( 'select11' ).style="#"+localStorage.getItem('select11');
    //document.getElementById( 'select12' ).style="#"+localStorage.getItem('select12');
    //document.getElementById( 'select13' ).style="#"+localStorage.getItem('select13');
      
    var valuetextencabezado = window.localStorage.getItem('textencabezado');
    var valuetextboton = window.localStorage.getItem('textboton');
    var valuetextfondo = window.localStorage.getItem('textfondo');
      
    //alert(valuetextencabezado);
    //alert(valuetextboton);
    //alert(valuetextfondo);
    //localStorage.removeItem('textencabezado');
    //localStorage.removeItem('textboton');
    //localStorage.removeItem('textfondo');
   
      
    function aplicarestilosheader(elemento, listaestilos){
        for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
            document.getElementById( 'creacarpeta' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'crea' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'renombrar' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'playmp3Btn' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'pausemp3Btn' ).style[estilo]=listaestilos[estilo];
        }
    }
    function aplicarestilosboton(elementoboton, listaestilosboton){
        for (var estiloboton in listaestilosboton){
            elementoboton.style[estiloboton]=listaestilosboton[estiloboton];
        }
    }
    function aplicarestilosfondo(elementofondo){
        //for (var estilofondo in listaestilosfondo){
            document.body.style.background=elementofondo;
        
        //}
    }
      
      
    // -----------fondo------------------------------------    
if(valuetextfondo=="amarillo"){
var stylefondoamarillo='-moz-linear-gradient(#FFFFFF, #FCFDC4)';
aplicarestilosfondo(stylefondoamarillo);
}
if(valuetextfondo=="azul"){
var stylefondoazul='-moz-linear-gradient(#FFFFFF, #B7E1FF)';
aplicarestilosfondo(stylefondoazul);
}
if(valuetextfondo=="rojo"){
var stylefondorosado='-moz-linear-gradient(#FFFFFF, #FFC1C1)';
aplicarestilosfondo(stylefondorosado);
}
if(valuetextfondo=="verde"){
var stylefondoverde='-moz-linear-gradient(#FFFFFF, #C1FFB3)';
aplicarestilosfondo(stylefondoverde);
}
if(valuetextfondo=="blanco"){
var stylefondoblanco='-moz-linear-gradient(#FFFFFF, #FFFFFF)';
aplicarestilosfondo(stylefondoblanco);
} 
    
      
    // -----------boton------------------------------------                         
if(valuetextboton=="amarillo"){
var stylebotonamarillo={'background': '-moz-linear-gradient(#DCDA35, #BEBB14)','margin': 'auto'};
var elemento=document.getElementById( 'menuredondo' );
aplicarestilosboton(elemento,stylebotonamarillo);
}
if(valuetextboton=="azul"){
var stylebotonazul={'background': '-moz-linear-gradient(#30A1FC, #2161C9)','margin': 'auto'};
var elemento=document.getElementById( 'menuredondo' );
aplicarestilosboton(elemento,stylebotonazul);
}
if(valuetextboton=="rojo"){
var stylebotonrojo={'background': '-moz-linear-gradient(#F72229, #9A1014)','margin': 'auto'};
var elementoboton=document.getElementById( 'menuredondo' );
aplicarestilosboton(elementoboton,stylebotonrojo);
}
if(valuetextboton=="verde"){    
var stylebotonverde={'background': '-moz-linear-gradient(#48DD23, #2DA60E)','margin': 'auto'};
var elemento=document.getElementById( 'menuredondo' );
aplicarestilosboton(elemento,stylebotonverde);
}
      

                         
   // -------------header----------------------------------    
if(valuetextencabezado=="amarillo"){
var styleheadamarillo={'background': '-moz-linear-gradient(#DCDA35, #BEBB14)','margin': 'auto'};
var elemento=document.getElementById( 'header' );
aplicarestilosheader(elemento,styleheadamarillo);
}
if(valuetextencabezado=="azul"){
var styleheadazul={'background': '-moz-linear-gradient(#30A1FC, #2161C9)','margin': 'auto'};
var elementohead=document.getElementById( 'header' );
aplicarestilosheader(elementohead,styleheadazul);
}
if(valuetextencabezado=="rojo"){
var styleheadrojo={'background': '-moz-linear-gradient(#F72229, #9A1014)','margin': 'auto'};
var elemento=document.getElementById( 'header' );
aplicarestilosheader(elemento,styleheadrojo);
}
if(valuetextencabezado=="verde"){
var styleheadverde={'background': '-moz-linear-gradient(#48DD23, #2DA60E)','margin': 'auto'};
var elemento=document.getElementById( 'header' );
aplicarestilosheader(elemento,styleheadverde);
}

}
    
  function runApp() {

    SDCARD = "sdcard";
    filesToImport = [];
    folders = [];
    root = "";
    isBacking = false;
    foldersAdded = [];

//Paginas principales
//document.getElementById( 'main' ).style.display = 'none';
//document.getElementById( 'opentext' ).style.display = 'none';
//document.getElementById( 'viewpropiedadesfile' ).style.display = 'none';
//document.getElementById( 'alert11' ).style.display = 'none';
//document.getElementById( 'alert22' ).style.display = 'none';
//document.getElementById( 'configalphaexplorer' ).style.display = 'none';
//document.getElementById( 'dropbox' ).style.display = 'none';
//document.getElementById( '' ).style.display = 'none';
//document.getElementById( '' ).style.display = 'none';
      
//document.getElementById('header').style="#FFFFFF";
    //  document.body.style.background="#000000";
if (window.localStorage.getItem('select1')=="") {
      var elemento=document.getElementById('header');
      var listaestilos={'background': '-moz-linear-gradient(#DCDA35, #BEBB14)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
            document.getElementById( 'creacarpeta' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'crea' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'renombrar' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'playmp3Btn' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'pausemp3Btn' ).style[estilo]=listaestilos[estilo];
          
        }
}
if (window.localStorage.getItem('select2')=="") {
      var elemento=document.getElementById('header');
      var listaestilos={'background': '-moz-linear-gradient(#30A1FC, #2161C9)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
            document.getElementById( 'creacarpeta' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'crea' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'renombrar' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'playmp3Btn' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'pausemp3Btn' ).style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select3')=="") {
      var elemento=document.getElementById('header');
      var listaestilos={'background': '-moz-linear-gradient(#F72229, #9A1014)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
            document.getElementById( 'creacarpeta' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'crea' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'renombrar' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'playmp3Btn' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'pausemp3Btn' ).style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select4')=="") {
      var elemento=document.getElementById('header');
      var listaestilos={'background': '-moz-linear-gradient(#48DD23, #2DA60E)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
            document.getElementById( 'creacarpeta' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'crea' ).style[estilo]=listaestilos[estilo];
            document.getElementById( 'renombrar' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'playmp3Btn' ).style[estilo]=listaestilos[estilo];
          document.getElementById( 'pausemp3Btn' ).style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select5')=="") {
      var elemento=document.getElementById('menuredondo');
      var listaestilos={'background': '-moz-linear-gradient(#DCDA35, #BEBB14)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select6')=="") {
      var elemento=document.getElementById('menuredondo');
      var listaestilos={'background': '-moz-linear-gradient(#30A1FC, #2161C9)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select7')=="") {
      var elemento=document.getElementById('menuredondo');
      var listaestilos={'background': '-moz-linear-gradient(#F72229, #9A1014)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select8')=="") {
      var elemento=document.getElementById('menuredondo');
      var listaestilos={'background': '-moz-linear-gradient(#48DD23, #2DA60E)','margin': 'auto'};
      for (var estilo in listaestilos){
            elemento.style[estilo]=listaestilos[estilo];
        }
}
if (window.localStorage.getItem('select9')=="") {
    var fondobody='-moz-linear-gradient(#FFFFFF, #FCFDC4)';
    document.body.style.background=fondobody;
}
if (window.localStorage.getItem('select10')=="") {
    var fondobody='-moz-linear-gradient(#FFFFFF, #B7E1FF)';
    document.body.style.background=fondobody;
}
if (window.localStorage.getItem('select11')=="") {
    var fondobody='-moz-linear-gradient(#FFFFFF, #FFC1C1)';
    document.body.style.background=fondobody;
}
if (window.localStorage.getItem('select12')=="") {
    var fondobody='-moz-linear-gradient(#FFFFFF, #C1FFB3)';
    document.body.style.background=fondobody;
}
if (window.localStorage.getItem('select13')=="") {
    var fondobody='-moz-linear-gradient(#FFFFFF, #FFFFFF)';
    document.body.style.background=fondobody;
}

      
      
      
      
      
      document.getElementById( 'select1' ).style.display = window.localStorage.getItem('select1');
      document.getElementById( 'select2' ).style.display = window.localStorage.getItem('select2');
      document.getElementById( 'select3' ).style.display = window.localStorage.getItem('select3');
      document.getElementById( 'select4' ).style.display = window.localStorage.getItem('select4');
      document.getElementById( 'select5' ).style.display = window.localStorage.getItem('select5');
      document.getElementById( 'select6' ).style.display = window.localStorage.getItem('select6');
      document.getElementById( 'select7' ).style.display = window.localStorage.getItem('select7');
      document.getElementById( 'select8' ).style.display = window.localStorage.getItem('select8');
      document.getElementById( 'select9' ).style.display = window.localStorage.getItem('select9');
      document.getElementById( 'select10' ).style.display = window.localStorage.getItem('select10');
      document.getElementById( 'select11' ).style.display = window.localStorage.getItem('select11');
      document.getElementById( 'select12' ).style.display = window.localStorage.getItem('select12');
      document.getElementById( 'select13' ).style.display = window.localStorage.getItem('select13');
      
      
    btncerraralert11 = document.querySelector("#btncerraralert11");
    btncerraralert11.addEventListener ('click', function () {  
        document.getElementById( 'alert11' ).style.display = 'none';
        load();
    });
      
    btncerraralert22 = document.querySelector("#btncerraralert22");
    btncerraralert22.addEventListener ('click', function () {  
        document.getElementById( 'alert22' ).style.display = 'none';
        load();
    });
      
    btncerraralert33 = document.querySelector("#btncerraralert33");
    btncerraralert33.addEventListener ('click', function () {  
        document.getElementById( 'alert33' ).style.display = 'none';
        load();
    });
      
    btncerraralert44 = document.querySelector("#btncerraralert44");
    btncerraralert44.addEventListener ('click', function () {  
        document.getElementById( 'alert44' ).style.display = 'none';
        load();
    });
      
    btncerraralert55 = document.querySelector("#btncerraralert55");
    btncerraralert55.addEventListener ('click', function () {  
        document.getElementById( 'alert55' ).style.display = 'none';
        load();
    });
      
    btncerraralert66 = document.querySelector("#btncerraralert66");
    btncerraralert66.addEventListener ('click', function () {  
        document.getElementById( 'alert66' ).style.display = 'none';
        load();
    });
      
    btncerraralert77 = document.querySelector("#btncerraralert77");
    btncerraralert77.addEventListener ('click', function () {  
        document.getElementById( 'alert77' ).style.display = 'none';
        load();
    });
      
    btncerraralert88 = document.querySelector("#btncerraralert88");
    btncerraralert88.addEventListener ('click', function () {  
        document.getElementById( 'alert88' ).style.display = 'none';
        load();
    });
      
    btncerraralert99 = document.querySelector("#btncerraralert99");
    btncerraralert99.addEventListener ('click', function () {  
        document.getElementById( 'alert99' ).style.display = 'none';
        load();
    });

    btncerraralert1010 = document.querySelector("#btncerraralert1010");
    btncerraralert1010.addEventListener ('click', function () {  
        document.getElementById( 'alert1010' ).style.display = 'none';
        load();
    });

    btncerraralert1111 = document.querySelector("#btncerraralert1111");
    btncerraralert1111.addEventListener ('click', function () {  
        document.getElementById( 'alert1111' ).style.display = 'none';
        load();
    });

    btncerraralert1212 = document.querySelector("#btncerraralert1212");
    btncerraralert1212.addEventListener ('click', function () {  
        document.getElementById( 'alert1212' ).style.display = 'none';
        load();
    });

    btncerraralert1313 = document.querySelector("#btncerraralert1313");
    btncerraralert1313.addEventListener ('click', function () {  
        document.getElementById( 'alert1313' ).style.display = 'none';
        load();
    });
      
    encaamarillo = document.querySelector("#encaamarillo");
    encaamarillo.addEventListener ('click', function () {    
        document.getElementById( 'textencabezado' ).value="amarillo";
        window.localStorage.setItem('textencabezado', 'amarillo');
        window.localStorage.setItem('select1', '');
        window.localStorage.setItem('select2', 'none');
        window.localStorage.setItem('select3', 'none');
        window.localStorage.setItem('select4', 'none');
        document.getElementById( 'select1' ).style.display = '';
        document.getElementById( 'select2' ).style.display = 'none';
        document.getElementById( 'select3' ).style.display = 'none';
        document.getElementById( 'select4' ).style.display = 'none';
    });
    encaazul = document.querySelector("#encaazul");
    encaazul.addEventListener ('click', function () {    
        document.getElementById( 'textencabezado' ).value="azul";
        window.localStorage.setItem('textencabezado', 'azul');
        window.localStorage.setItem('select1', 'none');
        window.localStorage.setItem('select2', '');
        window.localStorage.setItem('select3', 'none');
        window.localStorage.setItem('select4', 'none');
        document.getElementById( 'select1' ).style.display = 'none';
        document.getElementById( 'select2' ).style.display = '';
        document.getElementById( 'select3' ).style.display = 'none';
        document.getElementById( 'select4' ).style.display = 'none';
    });
    encarojo = document.querySelector("#encarojo");
    encarojo.addEventListener ('click', function () {    
        document.getElementById( 'textencabezado' ).value="rojo";
        window.localStorage.setItem('textencabezado', 'rojo');
        window.localStorage.setItem('select1', 'none');
        window.localStorage.setItem('select2', 'none');
        window.localStorage.setItem('select3', '');
        window.localStorage.setItem('select4', 'none');
        document.getElementById( 'select1' ).style.display = 'none';
        document.getElementById( 'select2' ).style.display = 'none';
        document.getElementById( 'select3' ).style.display = '';
        document.getElementById( 'select4' ).style.display = 'none';
    });
    encaverde = document.querySelector("#encaverde");
    encaverde.addEventListener ('click', function () {    
        document.getElementById( 'textencabezado' ).value="verde";
        window.localStorage.setItem('textencabezado', 'verde');
        window.localStorage.setItem('select1', 'none');
        window.localStorage.setItem('select2', 'none');
        window.localStorage.setItem('select3', 'none');
        window.localStorage.setItem('select4', '');
        document.getElementById( 'select1' ).style.display = 'none';
        document.getElementById( 'select2' ).style.display = 'none';
        document.getElementById( 'select3' ).style.display = 'none';
        document.getElementById( 'select4' ).style.display = '';
    });
    
    botonamarillo = document.querySelector("#botonamarillo");
    botonamarillo.addEventListener ('click', function () {    
        document.getElementById( 'textboton' ).value="amarillo";
        window.localStorage.setItem('textboton', 'amarillo');
        window.localStorage.setItem('select5', '');
        window.localStorage.setItem('select6', 'none');
        window.localStorage.setItem('select7', 'none');
        window.localStorage.setItem('select8', 'none');
        document.getElementById( 'select5' ).style.display = '';
        document.getElementById( 'select6' ).style.display = 'none';
        document.getElementById( 'select7' ).style.display = 'none';
        document.getElementById( 'select8' ).style.display = 'none';
    });
    botonazul = document.querySelector("#botonazul");
    botonazul.addEventListener ('click', function () {    
        document.getElementById( 'textboton' ).value="azul";
        window.localStorage.setItem('textboton', 'azul');
        window.localStorage.setItem('select5', 'none');
        window.localStorage.setItem('select6', '');
        window.localStorage.setItem('select7', 'none');
        window.localStorage.setItem('select8', 'none');
        document.getElementById( 'select5' ).style.display = 'none';
        document.getElementById( 'select6' ).style.display = '';
        document.getElementById( 'select7' ).style.display = 'none';
        document.getElementById( 'select8' ).style.display = 'none';
    });
    botonrojo = document.querySelector("#botonrojo");
    botonrojo.addEventListener ('click', function () {    
        document.getElementById( 'textboton' ).value="rojo";
        window.localStorage.setItem('textboton', 'rojo');
        window.localStorage.setItem('select5', 'none');
        window.localStorage.setItem('select6', 'none');
        window.localStorage.setItem('select7', '');
        window.localStorage.setItem('select8', 'none');
        document.getElementById( 'select5' ).style.display = 'none';
        document.getElementById( 'select6' ).style.display = 'none';
        document.getElementById( 'select7' ).style.display = '';
        document.getElementById( 'select8' ).style.display = 'none';
    });
    botonverde = document.querySelector("#botonverde");
    botonverde.addEventListener ('click', function () {    
        document.getElementById( 'textboton' ).value="verde";
        window.localStorage.setItem('textboton', 'verde');
        window.localStorage.setItem('select5', 'none');
        window.localStorage.setItem('select6', 'none');
        window.localStorage.setItem('select7', 'none');
        window.localStorage.setItem('select8', '');
        document.getElementById( 'select5' ).style.display = 'none';
        document.getElementById( 'select6' ).style.display = 'none';
        document.getElementById( 'select7' ).style.display = 'none';
        document.getElementById( 'select8' ).style.display = '';
    });
      
    fondoamarillo = document.querySelector("#fondoamarillo");
    fondoamarillo.addEventListener ('click', function () {    
        document.getElementById( 'textfondo' ).value="amarillo";
        window.localStorage.setItem('textfondo', 'amarillo');
        window.localStorage.setItem('select9', '');
        window.localStorage.setItem('select10', 'none');
        window.localStorage.setItem('select11', 'none');
        window.localStorage.setItem('select12', 'none');
        window.localStorage.setItem('select13', 'none');
        document.getElementById( 'select9' ).style.display = '';
        document.getElementById( 'select10' ).style.display = 'none';
        document.getElementById( 'select11' ).style.display = 'none';
        document.getElementById( 'select12' ).style.display = 'none';
        document.getElementById( 'select13' ).style.display = 'none';
    });
    fondoazul = document.querySelector("#fondoazul");
    fondoazul.addEventListener ('click', function () {    
        document.getElementById( 'textfondo' ).value="azul";
        window.localStorage.setItem('textfondo', 'azul');
        window.localStorage.setItem('select9', 'none');
        window.localStorage.setItem('select10', '');
        window.localStorage.setItem('select11', 'none');
        window.localStorage.setItem('select12', 'none');
        window.localStorage.setItem('select13', 'none');
        document.getElementById( 'select9' ).style.display = 'none';
        document.getElementById( 'select10' ).style.display = '';
        document.getElementById( 'select11' ).style.display = 'none';
        document.getElementById( 'select12' ).style.display = 'none';
        document.getElementById( 'select13' ).style.display = 'none';
    });
    fondonrojo = document.querySelector("#fondorojo");
    fondorojo.addEventListener ('click', function () {    
        document.getElementById( 'textfondo' ).value="rojo";
        window.localStorage.setItem('textfondo', 'rojo');
        window.localStorage.setItem('select9', 'none');
        window.localStorage.setItem('select10', 'none');
        window.localStorage.setItem('select11', '');
        window.localStorage.setItem('select12', 'none');
        window.localStorage.setItem('select13', 'none');
        document.getElementById( 'select9' ).style.display = 'none';
        document.getElementById( 'select10' ).style.display = 'none';
        document.getElementById( 'select11' ).style.display = '';
        document.getElementById( 'select12' ).style.display = 'none';
        document.getElementById( 'select13' ).style.display = 'none';
    });
    fondoverde = document.querySelector("#fondoverde");
    fondoverde.addEventListener ('click', function () {    
        document.getElementById( 'textfondo' ).value="verde";
        window.localStorage.setItem('textfondo', 'verde');
        window.localStorage.setItem('select9', 'none');
        window.localStorage.setItem('select10', 'none');
        window.localStorage.setItem('select11', 'none');
        window.localStorage.setItem('select12', '');
        window.localStorage.setItem('select13', 'none');
        document.getElementById( 'select9' ).style.display = 'none';
        document.getElementById( 'select10' ).style.display = 'none';
        document.getElementById( 'select11' ).style.display = 'none';
        document.getElementById( 'select12' ).style.display = '';
        document.getElementById( 'select13' ).style.display = 'none';
    });
    fondoblanco = document.querySelector("#fondoblanco");
    fondoblanco.addEventListener ('click', function () {    
        document.getElementById( 'textfondo' ).value="blanco";
        window.localStorage.setItem('textfondo', 'blanco');
        window.localStorage.setItem('select9', 'none');
        window.localStorage.setItem('select10', 'none');
        window.localStorage.setItem('select11', 'none');
        window.localStorage.setItem('select12', 'none');
        window.localStorage.setItem('select13', '');
        document.getElementById( 'select9' ).style.display = 'none';
        document.getElementById( 'select10' ).style.display = 'none';
        document.getElementById( 'select11' ).style.display = 'none';
        document.getElementById( 'select12' ).style.display = 'none';
        document.getElementById( 'select13' ).style.display = '';
    });


      
      
    menudernubeselecticondrop = document.querySelector("#menudernubeselecticondrop");
    menudernubeselecticondrop.addEventListener ('click', function () {    
        
        var openURL = new MozActivity({
        name: "view",
        data: {
            type: "url", // Possibly text/html in future versions
            url: "https://dl.dropboxusercontent.com/u/3663454/alphasync/prueba/index.html"
            }
        });
    });
        
    
    menuderselectface = document.querySelector("#menuderselectface");
    menuderselectface.addEventListener ('click', function () {
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'menudernubeselect' ).style.display = 'none';
    document.getElementById( 'menuderselect' ).style.display = 'none';
    document.getElementById( 'menuderselectface' ).style.display = 'none';
    });
      
    menuderselectdeletefile = document.querySelector("#menuderselectdeletefile");
    menuderselectdeletefile.addEventListener ('click', function () {
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'menudernubeselect' ).style.display = 'none';
    document.getElementById( 'menuderselect' ).style.display = 'none';
    document.getElementById( 'menuderselectface' ).style.display = 'none';
    deletefolder();
    });
    
    //menuderselectnube = document.querySelector("#menuderselectnube");
    //menuderselectnube.addEventListener ('click', function () {  
    //document.getElementById( 'articulocorrecion' ).style.display = 'none';
    //document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    //document.getElementById( 'articulocorrecion2' ).style.display = '';
    //document.getElementById( 'opcionesselect' ).style.display = 'none';
    //document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    //document.getElementById( 'menudernubeselect' ).style.display = '';
    //});
    
    menuopcionesselectpropi = document.querySelector("#menuopcionesselectpropi");
    menuopcionesselectpropi.addEventListener ('click', function () {  
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'main' ).style.display = 'none';
    document.getElementById( 'opentext' ).style.display = 'none';
    document.getElementById( 'viewpropiedadesfile' ).style.display = '';
    viewpropiedades();
    });
    
      
    menuderselectconfig = document.querySelector("#menuderselectconfig");
    menuderselectconfig.addEventListener ('click', function () {  
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'main' ).style.display = 'none';
    document.getElementById( 'opentext' ).style.display = 'none';
    document.getElementById( 'configalphaexplorer' ).style.display = '';
    });
      
      
    btncerrarpropiedades = document.querySelector("#btncerrarpropiedades");
    btncerrarpropiedades.addEventListener ('click', function () {  
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'main' ).style.display = '';
    document.getElementById( 'opentext' ).style.display = 'none';
    document.getElementById( 'viewpropiedadesfile' ).style.display = 'none';
    document.getElementById( 'propieadesnombre' ).innerHTML = '';
    document.getElementById( 'propieadestamano' ).innerHTML = '';
    document.getElementById( 'propieadesum' ).innerHTML = '';
    document.getElementById( 'propieadestipo' ).innerHTML = '';
    document.getElementById( 'propieadesdireccion' ).innerHTML = '';
    });
    
    btncerrarconfig = document.querySelector("#btncerrarconfig");
    btncerrarconfig.addEventListener ('click', function () {  
    var mdercerrarconfig = document.getElementById( 'menuderselect' );
    mdercerrarconfig.style.display = (mdercerrarconfig.style.display == 'none') ? 'block' : 'none';
    var mderselectfacecerrarconfig = document.getElementById( 'menuderselectface' );
    mderselectfacecerrarconfig.style.display = (mderselectfacecerrarconfig.style.display == 'none') ? 'block' : 'none';
        
    document.getElementById( 'menudernubeselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'main' ).style.display = '';
    document.getElementById( 'opentext' ).style.display = 'none';
    document.getElementById( 'configalphaexplorer' ).style.display = 'none';
        color();
    });
      
    cerrarviewtxt = document.querySelector("#cerrarviewtxt");
    cerrarviewtxt.addEventListener ('click', function () {  
document.getElementById( 'main' ).style.display = '';
document.getElementById( 'opentext' ).style.display = 'none';
document.getElementById( 'viewpropiedadesfile' ).style.display = 'none';
    });
    
    menuder = document.querySelector("#menuder");
    menuder.addEventListener ('click', function () {
    var mder = document.getElementById( 'menuderselect' );
    mder.style.display = (mder.style.display == 'none') ? 'block' : 'none';
    var mderselectface = document.getElementById( 'menuderselectface' );
    mderselectface.style.display = (mderselectface.style.display == 'none') ? 'block' : 'none';
    $(document).ready(function(){
    if ($('#backBtn').is(':visible'))
        {document.getElementById( 'menuderselectdeletefile' ).style.display = '';}
    else
        {document.getElementById( 'menuderselectdeletefile' ).style.display = 'none';}
    });       
document.getElementById( 'articulocorrecion' ).style.display = 'none';
document.getElementById( 'articulocorrecion1' ).style.display = 'none';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
document.getElementById( 'menudernubeselect' ).style.display = 'none';
    });
      
    menuopcionesselectrenom = document.querySelector("#menuopcionesselectrenom");
    menuopcionesselectrenom.addEventListener ('click', function () {
document.getElementById( 'renombrar' ).style.display = '';
document.getElementById( 'articulocorrecion' ).style.display = '';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    });

    menuredondo = document.querySelector("#menuredondo");
    menuredondo.addEventListener ('click', function () {
        var mra = document.getElementById( 'menuredondoarchivo' );
        var mrc = document.getElementById( 'menuredondocarpeta' );
    mra.style.display = (mra.style.display == 'none') ? 'block' : 'none';
    mrc.style.display = (mrc.style.display == 'none') ? 'block' : 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
        
        var mrhijo = document.getElementById( 'hijo3' );
        var mrhijocierra = document.getElementById( 'hijo3cierra' );
    mrhijo.style.display = (mrhijo.style.display == 'none') ? 'block' : 'none';
    mrhijocierra.style.display = (mrhijocierra.style.display == 'none') ? 'block' : 'none';
    });
      
    menuredondocarpeta = document.querySelector("#menuredondocarpeta");
    menuredondocarpeta.addEventListener ('click', function () {
document.getElementById( 'creacarpeta' ).style.display = '';
document.getElementById( 'articulocorrecion' ).style.display = '';
document.getElementById( 'articulocorrecion1' ).style.display = '';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'menuredondoarchivo' ).style.display = 'none';
document.getElementById( 'menuredondocarpeta' ).style.display = 'none';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
document.getElementById( 'crea' ).style.display = 'none';
document.getElementById( 'renombrar' ).style.display = 'none';
        var mrhijo = document.getElementById( 'hijo3' );
        var mrhijocierra = document.getElementById( 'hijo3cierra' );
    mrhijo.style.display = (mrhijo.style.display == 'none') ? 'block' : 'none';
    mrhijocierra.style.display = (mrhijocierra.style.display == 'none') ? 'block' : 'none';
    });
      
    menuredondoarchivo = document.querySelector("#menuredondoarchivo");
    menuredondoarchivo.addEventListener ('click', function () {
document.getElementById( 'crea' ).style.display = '';
document.getElementById( 'articulocorrecion' ).style.display = '';
document.getElementById( 'articulocorrecion1' ).style.display = '';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'menuredondoarchivo' ).style.display = 'none';
document.getElementById( 'menuredondocarpeta' ).style.display = 'none';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
document.getElementById( 'creacarpeta' ).style.display = 'none';
document.getElementById( 'renombrar' ).style.display = 'none';
        var mrhijo = document.getElementById( 'hijo3' );
        var mrhijocierra = document.getElementById( 'hijo3cierra' );
    mrhijo.style.display = (mrhijo.style.display == 'none') ? 'block' : 'none';
    mrhijocierra.style.display = (mrhijocierra.style.display == 'none') ? 'block' : 'none';
    });  
      
    pausemp3Btn = document.querySelector("#pausemp3Btn");
    pausemp3Btn.addEventListener ('click', function () {
document.getElementById( 'playmp3Btn' ).style.display = '';
document.getElementById( 'pausemp3Btn' ).style.display = 'none';
pauseaudimp3();
    });

    playmp3Btn = document.querySelector("#playmp3Btn");
    playmp3Btn.addEventListener ('click', function () {
document.getElementById( 'playmp3Btn' ).style.display = 'none';
document.getElementById( 'pausemp3Btn' ).style.display = '';
openmp3();
    });

    menuopcionesselectopen = document.querySelector("#menuopcionesselectopen");
    menuopcionesselectopen.addEventListener ('click', function () {
    open();
        
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    
    //document.getElementById( 'main' ).style.display = 'none';
    //document.getElementById( 'opentext' ).style.display = '';
    });

    menuarchivoBtn = document.querySelector("#menuarchivoBtn");
    menuarchivoBtn.addEventListener ('click', function () {
    var ma = document.getElementById( 'menuopcionesselect' );
    ma.style.display = (ma.style.display == 'none') ? 'block' : 'none';
    });
      
    hiddenfileBtn = document.querySelector("#hiddenfileBtn");
    hiddenfileBtn.addEventListener ('click', function () {
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'pegardeshabiliBtn' ).style.display = '';
    document.getElementById( 'pegarBtn' ).style.display = 'none';
    document.getElementById( 'pegarcutBtn' ).style.display = 'none';
    });

    menuderselectrefresh = document.querySelector("#menuderselectrefresh");
    menuderselectrefresh.addEventListener ('click', function () {
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'menuderselect' ).style.display = 'none';
    document.getElementById( 'menuderselectface' ).style.display = 'none';
      load();
    });

    renombrarBtn = document.querySelector("#renombrarBtn");
    renombrarBtn.addEventListener ('click', function () {
    document.getElementById( 'renombrar' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
      renombrarfile();
    });
    
    btncancelrenombrar = document.querySelector("#btncancelrenombrar");
    btncancelrenombrar.addEventListener ('click', function () {
document.getElementById( 'renombrar' ).style.display = 'none';
document.getElementById( 'renombre' ).value = '';
document.getElementById( 'articulocorrecion' ).style.display = 'none';
document.getElementById( 'articulocorrecion1' ).style.display = 'none';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    });
      
    btncrear = document.querySelector("#btncrear");
    btncrear.addEventListener ('click', function () {
    document.getElementById( 'crea' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
      creatxt();
    });
    
    btncancelcreararchivo = document.querySelector("#btncancelcreararchivo");
    btncancelcreararchivo.addEventListener ('click', function () {
document.getElementById( 'crea' ).style.display = 'none';
document.getElementById( 'nombre' ).value = '';
document.getElementById( 'articulocorrecion' ).style.display = 'none';
document.getElementById( 'articulocorrecion1' ).style.display = 'none';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    });

    btncrearcarpeta = document.querySelector("#btncrearcarpeta");
    btncrearcarpeta.addEventListener ('click', function () {
document.getElementById( 'creacarpeta' ).style.display = 'none';
document.getElementById( 'articulocorrecion' ).style.display = 'none';
document.getElementById( 'articulocorrecion1' ).style.display = 'none';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
        creacarpetatxt();
    });

    btncancelcrearcarpeta = document.querySelector("#btncancelcrearcarpeta");
    btncancelcrearcarpeta.addEventListener ('click', function () {
document.getElementById( 'creacarpeta' ).style.display = 'none';
document.getElementById( 'nombrecarpeta' ).value = '';
document.getElementById( 'articulocorrecion' ).style.display = 'none';
document.getElementById( 'articulocorrecion1' ).style.display = 'none';
document.getElementById( 'articulocorrecion2' ).style.display = '';
document.getElementById( 'opcionesselect' ).style.display = 'none';
document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    });
      
	btnsaver = document.querySelector("#btnsaver");
    btnsaver.addEventListener ('click', function () {
var dirsinsaver=dircrea+nametosavetxt;
var dirconsaver=dircrea+"/"+nametosavetxt;
				if (dircrea==""){
				    var request = storage.delete(dirsinsaver);
				}
				else{
					var request = storage.delete(dirconsaver);
				}

      savertxtwithdelete();
        //var theContent = document.getElementById('editores').innerHTML;
        //alert(theContent);
    });

    eliminarBtn = document.querySelector("#eliminarBtn");
    eliminarBtn.addEventListener ('click', function () {
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    eliminartxt();
    });
      
    pegarBtn = document.querySelector("#pegarBtn");
    pegarBtn.addEventListener ('click', function () {
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'pegardeshabiliBtn' ).style.display = '';
    document.getElementById( 'pegarBtn' ).style.display = 'none';
    document.getElementById( 'pegarcutBtn' ).style.display = 'none';
      pegar();
    });

    copyBtn = document.querySelector("#copyBtn");
    copyBtn.addEventListener ('click', function () {
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'pegardeshabiliBtn' ).style.display = 'none';
    document.getElementById( 'pegarBtn' ).style.display = '';
    document.getElementById( 'pegarcutBtn' ).style.display = 'none';
      copy();
    });

    cutBtn = document.querySelector("#cutBtn");
    cutBtn.addEventListener ('click', function () {
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'pegarBtn' ).style.display = 'none';
    document.getElementById( 'pegarcutBtn' ).style.display = '';
    document.getElementById( 'pegardeshabiliBtn' ).style.display = 'none';
      cut();
    });

	pegarcutBtn = document.querySelector("#pegarcutBtn");
    pegarcutBtn.addEventListener ('click', function () {
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
    document.getElementById( 'articulocorrecion2' ).style.display = '';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'pegardeshabiliBtn' ).style.display = '';
    document.getElementById( 'pegarBtn' ).style.display = 'none';
    document.getElementById( 'pegarcutBtn' ).style.display = 'none';
      pegarcut();
    });

    menuopcionesselectcompar = document.querySelector("#menuopcionesselectcompar");
    menuopcionesselectcompar.addEventListener ('click', function () {
    document.getElementById( 'opcionesselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion' ).style.display = 'none';
    document.getElementById( 'menuopcionesselect' ).style.display = 'none';
    document.getElementById( 'articulocorrecion1' ).style.display = 'none';
      compartir();
    });

    menuderselectsalir = document.querySelector("#menuderselectsalir");
    menuderselectsalir.addEventListener ('click', function () {
      salir();
    });

    backhBtn = document.querySelector("#backBtn");
    backhBtn.addEventListener ('click', function () {
      back();
    });

    // Open the default device storage
    storage = navigator.getDeviceStorage(SDCARD);
    storages = [];
    
    deviceStoragesList = document.querySelector("#deviceStoragesList");
    // Check that getDeviceStorages is available (only for FxOS >=1.1)
    if (navigator.getDeviceStorages) {
        storages = navigator.getDeviceStorages(SDCARD);
        if (storages.length > 1) {
            // Display the dropdown list only if there are more than one device storage available
            deviceStoragesList.style.display = "block";
            for (var i = 0; i < storages.length; i++) {
                var storageName = storages[i].storageName;
                deviceStoragesList.options[i] = new Option(storageName, storageName);
                if (storages[i].default === true) {
                        deviceStoragesList.options[i].selected = true;
                }
            }
        }
        deviceStoragesList.addEventListener("change", function() {
            changeDeviceStorage(this.options[this.selectedIndex].value);
        });
    }
   



function creacarpetatxt(){
var nombrecarpeta=document.getElementById('nombrecarpeta').value;


	var file   = new Blob([""]);
if (dircrea==""){
	var fmname = dircrea+nombrecarpeta+"/.empty";
	var request = storage.addNamed(file,fmname);
deleteempty=fmname;
}else{
	var fmname = dircrea+"/"+nombrecarpeta+"/.empty";
	var request = storage.addNamed(file,fmname);
deleteempty=fmname;
}


	request.onsuccess = function () {
	  var name = this.result;
    document.getElementById( 'alert11' ).style.display = '';
	  load();
	}

	// An error typically occur if a file with the same name already exist
	request.onerror = function () {
        document.getElementById( 'alert44' ).style.display = '';
	  //alert("No es posible crear la carpeta debido a la existencia de esta o los permisos de la aplicación");
	  load();
	}
    document.getElementById( 'nombrecarpeta' ).value = '';
    }

function eliminaempty(){
var nomtemelimi="/sdcard/"+deleteempty;
var request = storage.delete(nomtemelimi);
deleteempty="";
}




    function creatxt(){
var nombre=document.getElementById('nombre').value;


	var file   = new Blob([""], {type: "text/plain"});
if (dircrea==""){
	var fmname = dircrea+nombre;
	var request = storage.addNamed(file,fmname);
}else{
	var fmname = dircrea+"/"+nombre;
	var request = storage.addNamed(file,fmname);
}

	request.onsuccess = function () {
	  var name = this.result;
        document.getElementById( 'alert22' ).style.display = '';
	  //alert("El archivo " + name + " ha sido creado.");
	  load();
	}

	// An error typically occur if a file with the same name already exist
	request.onerror = function () {
        document.getElementById( 'alert33' ).style.display = '';
	  //alert("No es posible crear el archivo debido a la existencia de este o los permisos de la aplicacion");
	  load();
	}

document.getElementById( 'nombre' ).value = '';
    }


function savertxtwithdelete(){
var dirsin=dircrea+nametosavetxt;
var dircon=dircrea+"/"+nametosavetxt;
//if(!confirm("Desea remplazar el archivo existente?")) {return false;} 
//			else {
//				if (dircrea==""){
//				    var request = storage.delete(dirsin);
                    savertxt();
//				}
//				else{
//					var request = storage.delete(dircon);
//            	    savertxt();
//				}
//			}
//    
//    
}

function savertxt(){
load();
//var nombre=document.getElementById('nombre').value;
//var ext=document.getElementById('ext').value;
var nametosave=nametosavetxt;
var contenidoeditor=document.getElementById('editor').value;

	var file   = new Blob([contenidoeditor], {type: "text/plain"});

//alert(nametosavetxt);
//alert(dircrea);

if (dircrea==""){
//alert("El archivo ha sido creado");
	var fmname = dircrea+nametosavetxt;
	var request = storage.addNamed(file,fmname);
load();
}else{
//alert("El archivo ha sido creado");
	var fmname = dircrea+"/"+nametosavetxt;
	var request = storage.addNamed(file,fmname);
load();
}


	request.onsuccess = function () {
	  var name = this.result;
        document.getElementById( 'alert88' ).style.display = '';
	  //alert("El archivo " + name + " ha sido creado.");
	  load();
	}

	// An error typically occur if a file with the same name already exist
	request.onerror = function () {
        //document.getElementById( 'alert33' ).style.display = '';
	  //alert("No es posible crear el archivo debido a la existencia de este o los permisos de la aplicacion");
	  var name = this.result;
        //document.getElementById( 'alert22' ).style.display = '';
	  //alert("El archivo " + name + " ha sido creado.");
    }
}




    function eliminartxt(){
       	var sdcard = navigator.getDeviceStorage('sdcard');
	var deletename = "/sdcard/" + nomtexto;
	var deletenamedir = "/sdcard/" + dircrea + "/" + nomtexto;
	
    document.getElementById( 'confirm22' ).style.display = '';

    btnaceptarconfirm22 = document.querySelector("#btnaceptarconfirm22");
    btnaceptarconfirm22.addEventListener ('click', function () {  
        document.getElementById( 'confirm22' ).style.display = 'none';
        
//if(!confirm("Esta seguro de borrar el archivo \n " + nomtexto + "?")) {return false;} 

//else {
    if (dircrea==""){
    
		var requestelimarachivo = storage.delete(deletename);
    
        document.getElementById( 'alert77' ).style.display = '';
        //alert("El archivo " + nomtexto + " ha sido eliminado");
        $('#item-list li').remove();
	   load();
       return false;
    }
    else{
    
		var requestelimarachivodentrofolder = storage.delete(deletenamedir);
        document.getElementById( 'alert77' ).style.display = '';
        //alert("El archivo " + nomtexto + " ha sido eliminado");
        $('#item-list li').remove();
	   load();
       return false;
    }
//} 
        
        
        load();
    });
    btncancelarconfirm22 = document.querySelector("#btncancelarconfirm22");
    btncancelarconfirm22.addEventListener ('click', function () {  
        document.getElementById( 'confirm22' ).style.display = 'none';
        load();
    });


	requestelimarachivo.onsuccess = function () {
	  var namedelete = this.result;
        load();
	}

	requestelimarachivo.onerror = function () {
	  var namedeleteerror = this.result;
        document.getElementById( 'alert33' ).style.display = '';
	  //alert("Nos es posible eliminar el archivo " + nomtexto + " debido a la inexistencia de este o los permisos de la aplicacion.");
	  load();
	}
    
    requestelimarachivodentrofolder.onsuccess = function () {
	  var namedelete = this.result;
        load();
	}
	requestelimarachivodentrofolder.onerror = function () {
	  var namedeleteerror = this.result;
        document.getElementById( 'alert33' ).style.display = '';
	  //alert("Nos es posible eliminar el archivo " + nomtexto + " debido a la inexistencia de este o los permisos de la aplicacion.");
        
	  load();
	}
    

     }

    function music(){
       	var sdcardw = navigator.getDeviceStorage('sdcard');
		var deletenameurlq = "sdcard/" + dircrea + "/" + nomtexto;
		var openurl = "pastas.txt";
	var asd = "/sdcard/datos.txt";
var midir = window.URL.createObjectURL(asd);
      		roottexto_ = document.querySelector("#texto");
      		roottexto_.innerHTML = '<form>hola<object type="text/plain" data="' + midir + '" id="textos" name="textos" width="94%" height="400"></object> <iframe src="' + midir + '"></iframe> </form>';



    }

    function salir(){
	window.close();
     }


    function back(){
      isBacking = true;
      folders = root.split("/");
      folders.splice(folders.length - 1, 1)
      root = folders.join("/");
      load();
    }
    
    /**
     * Switches to another device storage, based on the given name
     * @param {String} deviceStorageName Name of the device storage to switch to
     */
    function changeDeviceStorage(deviceStorageName) {
        for (var i=0; i< storages.length; i++) {
            if (deviceStorageName === storages[i].storageName) {
                storage = storages[i];
                // Go back to the root of the device storage, and load its content
                root = "";
                load();
                return;
            }
        }
    }

      
function deletefolder(){
    acceso = dircrea;

            var storagenameran ="sdcard"
            var filesd = navigator.getDeviceStorage(storagenameran);

			var cursor = filesd.enumerate();

			cursor.onsuccess = function () {
			  //alert("Got something");
			  var filed = this.result;
                
			  if (filed != null) {
			    
                 
                  var strdeletefile = filed.name;
                  var cantnumfile = strdeletefile.indexOf(dircrea); 
                  
                  if(cantnumfile!="-1"){
                    
                      var deletename = strdeletefile;
                      
                      var requestdelete = filesd.delete(deletename);
                      
                      requestdelete.onsuccess = function () {
                          //var namedelete = this.result;
                      }

                      requestdelete.onerror = function () {
                          //var namedeleteerror = this.result;
                      }
                  }
                  
			  }
			  else {
			    this.done = true;
                  //alert(this.done);
			  }

			  if (!this.done) {
				this.continue();
			  }
              if (this.done!="false"){
                  rootmenosuno = acceso.split("/");
    //alert(rootmenosuno);
        rootmenosuno.splice(rootmenosuno.length - 1, 1)
        root = rootmenosuno.join("/");
    //alert(root);
        $('#item-list li').remove();
                  
              }
			}
           cuarteto(); 
    
   
}

function cuarteto(){
    document.getElementById( 'alert55' ).style.display = '';
	  //alert("Carpeta eliminada");
    load();
}
    
      
      function cargaload(){
          

      foldersToSort = [];
      filesToSort = [];
      pathsToSort = [];
      sizes = [];

      alreadyAdded = [];
      if(root == ""){
        backhBtn.style.display = 'none';
      } else {
        backhBtn.style.display = 'block';
      }

      root_ = document.querySelector("#path_root");
      //root_.innerHTML = '<label><span class="home"></span></label>SDCard/' + root;
dircrea=root;
      //$('#item-list li').remove();
      var cursor = storage.enumerate(root); 
      cursor.onsuccess = function() {
        if (!cursor.result)  {
          execute();
          return; 
        }
         var file = cursor.result;          
        var prefix = "/" + storage.storageName + "/";
        if (root != "") {
           prefix += root + "/";
        }
        var fname = file.name.replace(prefix, "");

        if(fname.split("/").length > 1) {
          pathsToSort.push(fname);
            
        } else {
            var mio = file.size;
                    
        var quantity1;
        var unit1;
		
		if (mio < Math.pow(1024, 2)) {
			quantity1 = mio / 1024;
			unit1 = "KB";
		} else if (mio < Math.pow(1024, 3)) {
			quantity1 = mio / Math.pow(1024, 2);
			unit1 = "MB";
		} else {
			quantity1 = mio / Math.pow(1024, 3);
			unit1 = "GB";
		}
            
          //filesToSort.push("<table><tr style='font-size: 13pt;font-family: arial;color:#202020'><td width='250px'>" + fname + " <td>" + quantity1.toFixed(2) + unit1);
          
//fecha=file.lastModifiedDate;
//tipo=file.type;

        }
        cursor.continue(); 

      }

      function execute() {


        filesWithImage = ['doc', 'xls', 'ppt', 'psd', 'ai', 'pdf', 'html', 'xml', 'txt', 'mp3', 'jpg', 'png', 'zip'];

        pathsToSort.sort(
          function(a, b) {
            if (a.toLowerCase() < b.toLowerCase()) return -1;
            if (a.toLowerCase() > b.toLowerCase()) return 1;
            return 0;
          }
          );


        for (var s = 0; s < pathsToSort.length; s++)  {
          n = pathsToSort[s].split("/");
          if(n.length == 1) {
            filesToSort.push(n[0]);
          } else {
            foldersToSort.push(n[0]);
          }
        }

        for (var g = 0; g < foldersToSort.length; g++)  {
          path = foldersToSort[g].split("/");
          if(alreadyAdded.lastIndexOf(path[0] + "/") == -1) {
            alreadyAdded.push(path[0] + "/");
              //$("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="folder"></span></label></td><td width="450px"><label style="font-size: 13pt;font-family: arial;color:#202020"><div style="width:270px">' + path[0] + "/</div></label>" + '</tr></table></li>');
          }
        }
        for (var f = 0; f < filesToSort.length; f++)  {

          path = filesToSort[f].split("/");


//fileType = path.toString().substring(0, path.toString().lastIndexOf(' ')).split(".")[1];
var extension = path.toString().substring(0, path.toString().lastIndexOf(' '));
var ggfile = extension.slice(extension.indexOf("\\") + 1); 
var ext = ggfile.slice(ggfile.indexOf(".")).toLowerCase(); 
var comprueba = ext.charAt(0);
if(ext!=".empty"){
if(comprueba != "."){
fileType = 'unk';

          //$("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="' + fileType + '"></span>' + '</label></td><td>' + path + '</td></tr></table></li>');

}else{
var fileType = (extension.substring(extension.lastIndexOf(".")).split(".")[1]).toLowerCase();
          if(filesWithImage.indexOf(fileType) == -1){
            fileType = 'unk';
          }
//tipe=fileType;

          //$("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="' + fileType + '"></span>' + '</label></td><td>' + path + '</td></tr></table></li>');
}
}

	}

        
      };
      //isBacking = false;
        
        
    }
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

    function load(){
window.addEventListener('deviceorientation', function(event) {
var v2 = event.gamma;
var v3 = parseInt(event.gamma);

if(v3>"50" || v3<"-50"){
  //alert(event.alpha + ' : ' + event.beta + ' : ' + v3);
}

});

      foldersToSort = [];
      filesToSort = [];
      pathsToSort = [];
      sizes = [];

      alreadyAdded = [];
      if(root == ""){
        backhBtn.style.display = 'none';
      } else {
        backhBtn.style.display = 'block';
      }

      root_ = document.querySelector("#path_root");
      root_.innerHTML = '<label><span class="home"></span></label>SDCard/' + root;
dircrea=root;
      $('#item-list li').remove();
      var cursor = storage.enumerate(root); 
      cursor.onsuccess = function() {
        if (!cursor.result)  {
          execute();
          return; 
        }
         var file = cursor.result;          
        var prefix = "/" + storage.storageName + "/";
        if (root != "") {
           prefix += root + "/";
        }
        var fname = file.name.replace(prefix, "");

        if(fname.split("/").length > 1) {
          pathsToSort.push(fname);
            
        } else {
            var mio = file.size;
                    
        var quantity1;
        var unit1;
		
		if (mio < Math.pow(1024, 2)) {
			quantity1 = mio / 1024;
			unit1 = "KB";
		} else if (mio < Math.pow(1024, 3)) {
			quantity1 = mio / Math.pow(1024, 2);
			unit1 = "MB";
		} else {
			quantity1 = mio / Math.pow(1024, 3);
			unit1 = "GB";
		}
            
          filesToSort.push("<table><tr style='font-size: 13pt;font-family: arial;color:#202020'><td width='250px'>" + fname + " <td>" + quantity1.toFixed(2) + unit1);
          
//fecha=file.lastModifiedDate;
//tipo=file.type;

        }
        cursor.continue(); 

      }

      function execute() {


        filesWithImage = ['doc', 'xls', 'ppt', 'psd', 'ai', 'pdf', 'html', 'xml', 'txt', 'mp3', 'jpg', 'png', 'zip'];

        pathsToSort.sort(
          function(a, b) {
            if (a.toLowerCase() < b.toLowerCase()) return -1;
            if (a.toLowerCase() > b.toLowerCase()) return 1;
            return 0;
          }
          );


        for (var s = 0; s < pathsToSort.length; s++)  {
          n = pathsToSort[s].split("/");
          if(n.length == 1) {
            filesToSort.push(n[0]);
          } else {
            foldersToSort.push(n[0]);
          }
        }

        for (var g = 0; g < foldersToSort.length; g++)  {
          path = foldersToSort[g].split("/");
          if(alreadyAdded.lastIndexOf(path[0] + "/") == -1) {
            alreadyAdded.push(path[0] + "/");
              $("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="folder"></span></label></td><td width="450px"><label style="font-size: 13pt;font-family: arial;color:#202020"><div style="width:270px">' + path[0] + "/</div></label>" + '</tr></table></li>');
          }
        }
        for (var f = 0; f < filesToSort.length; f++)  {

          path = filesToSort[f].split("/");


//fileType = path.toString().substring(0, path.toString().lastIndexOf(' ')).split(".")[1];
var extension = path.toString().substring(0, path.toString().lastIndexOf(' '));
var ggfile = extension.slice(extension.indexOf("\\") + 1); 
var ext = ggfile.slice(ggfile.indexOf(".")).toLowerCase(); 
var comprueba = ext.charAt(0);
if(ext!=".empty"){
if(comprueba != "."){
fileType = 'unk';

          $("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="' + fileType + '"></span>'
            + '</label></td><td>' + path + '</td></tr></table></li>');

}else{
var fileType = (extension.substring(extension.lastIndexOf(".")).split(".")[1]).toLowerCase();
          if(filesWithImage.indexOf(fileType) == -1){
            fileType = 'unk';
          }
//tipe=fileType;

          $("#item-list").append('<li><br><table><tr><td width="15px"><label><input type="checkbox"><span class="' + fileType + '"></span>'
            + '</label></td><td>' + path + '</td></tr></table></li>');
}
}

	}


        flagOk = true;


        $('#item-list li').click(function(event) {
            
          var target = $(event.target);
          if(flagOk && target.text() != ""){
            if(target.text().split("/").length > 1){
              if(!isBacking){
                if(root == ""){
                  root = target.text().substring(0, target.text().lastIndexOf('/'));
//AQUI alert(root);
                } else {
                  root = root + "/" + target.text().substring(0, target.text().lastIndexOf('/'));
//alert(root);
                }
              }
              load();
            } else {
              var fname = target.text();

               
if(root==""){
direccionpropiedades="SDCard/"+fname;
}else{
direccionpropiedades="SDCard/"+root+"/"+fname;
}

       
             //alert("aaaa" + direccionpropiedades);   
                
                
var extensionclick = direccionpropiedades.toString().substring(0, direccionpropiedades.toString().lastIndexOf(' '));
var ggfileclick = extensionclick.slice(extensionclick.indexOf("\\") + 1); 
var extclick = ggfileclick.slice(ggfileclick.indexOf(".")).toLowerCase(); 
var compruebaclick = extclick.charAt(0);                
typedeextencion=extclick;
//alert(direccionpropiedades);
var namefilemb = direccionpropiedades.indexOf('MB'); 
var namefilekb = direccionpropiedades.indexOf('KB');
var namefilegb = direccionpropiedades.indexOf('GB'); 

if(namefilemb != "-1"){
    direccionpropiedades1=direccionpropiedades.slice(0,direccionpropiedades.length-7);    
}
if(namefilekb != "-1"){
    direccionpropiedades1=direccionpropiedades.slice(0,direccionpropiedades.length-7);
}
if(namefilegb != "-1"){
    direccionpropiedades1=direccionpropiedades.slice(0,direccionpropiedades.length-7);
}
if(direccionpropiedades1 == ""){
    direccionpropiedades1=direccionpropiedades;
}
                
//alert(direccionpropiedades1);
//alert(root);
//alert(fname);


              if (fname.lastIndexOf(' ') >= 0) {
                fname = fname.substring(0, fname.lastIndexOf(' '))

//tipe=fname.type;


showiconplay = fname.slice(fname.indexOf(".")).toLowerCase();                 
//alert(showiconplay);
nombredelista=fname;
rootdenombredelista=root;
nomtexto=fname;


              }
              console.log("File to share: " + fname);
              //importFiles(fname); 
if(showiconplay==".mp3"){
document.getElementById( 'playmp3Btn' ).style.display = '';
document.getElementById( 'pausemp3Btn' ).style.display = 'none';
}
else{
document.getElementById( 'playmp3Btn' ).style.display = 'none';
}
document.getElementById( 'opcionesselect' ).style.display = '';
document.getElementById( 'articulocorrecion1' ).style.display = '';
document.getElementById( 'crea' ).style.display = 'none';
document.getElementById( 'creacarpeta' ).style.display = 'none';
document.getElementById( 'renombrar' ).style.display = 'none';
		load();

            }
            flagOk = false;
          }
        });
      };
      isBacking = false;
        
        
    }

    load();


function renombrarfile(){
temnombredelistaparacopiar=nombredelista;
roottemnombredelistaparacopiar=rootdenombredelista;

var tempo=temnombredelistaparacopiar;
renameFiles(tempo);
//alert(tempo);
load();
}

function viewpropiedades(){
//alert(nombredelista);
nametosavetxt=nombredelista;
propiedades(nombredelista);
}
      
function open(){
//alert(nombredelista);
nametosavetxt=nombredelista;
openFiles(nombredelista);
}

function openmp3(){
//alert(nombredelista);
nametosavetxt=nombredelista;
openFilesmp3(nombredelista);
}
      
function copy(){
temnombredelistaparacopiar=nombredelista;
roottemnombredelistaparacopiar=rootdenombredelista;
}

function pegar(){
var tempo=temnombredelistaparacopiar;
copyFiles(tempo);
//alert(tempo);
load();
}

function cut(){
temnombredelistaparacopiar=nombredelista;
roottemnombredelistaparacopiar=rootdenombredelista;
}

function pegarcut(){
var tempo=temnombredelistaparacopiar;
cutFiles(tempo);
//alert(tempo);
load();
}

function compartir(){
importFiles(nombredelista);
}


//desde aqui es pauseaudimp3

function pauseaudimp3(){
      $('.abremp3').remove();
}




//desde aqui es copiar

    function copyFiles(filesToImport) {
//alert(filesToImport);

root=roottemnombredelistaparacopiar;
//alert(root);
//alert(dircrea);
var dircreaconfirm=dircrea;
//alert(dircreaconfirm);

        
      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
          load();
        };
        //alert(a_file.error.name);
      };

      a_file.onsuccess = function() { 

        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
            //alert(item.filename);
            //alert(type);
            

//var nombre=document.getElementById('nombre').value;
//var ext=document.getElementById('ext').value;


	//var file   = new Blob(["este es el contenido de este archivo."], {type: "text/plain"});
if (dircreaconfirm==""){
	var fmname = dircreaconfirm+temnombredelistaparacopiar;
    //alert(fmname);
	var request = storage.addNamed(item.blob,fmname);
}else{
	var fmname = dircreaconfirm+"/"+temnombredelistaparacopiar;
    //alert(fmname);
	var request = storage.addNamed(item.blob,fmname);
}


	request.onsuccess = function () {

	  var name = this.result;
    document.getElementById( 'alert1111' ).style.display = '';

temnombredelistaparacopiar="";
rootdenombredelista="";
root=dircreaconfirm;
	  load();
	}


	// An error typically occur if a file with the same name already exist

	request.onerror = function () {
	  //alert("No es posible crear el archivo debido a la existencia de este o los permisos de la aplicacion");
	  var name = this.result;

	  //alert("error en" + name);
	  load();
	}





		}
		}
}




//desde aqui es renombrar

    function renameFiles(filesToImport) {
//alert(filesToImport);

root=roottemnombredelistaparacopiar;
//alert(root);
      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 

        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
//alert("entro");

var renombre=document.getElementById('renombre').value;

	//var file   = new Blob(["este es el contenido de este archivo."], {type: "text/plain"});
if (dircrea==""){
	var fmname = dircrea+renombre;
	var request = storage.addNamed(item.blob,fmname);
}else{
	var fmname = dircrea+"/"+renombre;
	var request = storage.addNamed(item.blob,fmname);
}

	request.onsuccess = function () {
	  var name = this.result;
        document.getElementById( 'alert99' ).style.display = '';
	  //alert("El archivo " + name + " ha sido creado.");








	var deletename = "/sdcard/" + filesToImport;
	var deletenamedir = "/sdcard/" + root + "/" + filesToImport;
	//alert(root);
	
if (root==""){
		var request = storage.delete(deletename);
                return false;
}
else{
		var request = storage.delete(deletenamedir);

                return false;
}
    

	request.onsuccess = function () {
	  var namedelete = this.result;
	}

	request.onerror = function () {
	  var namedeleteerror = this.result;
	}




	}
//alert(dircrea);
temnombredelistaparacopiar="";
rootdenombredelista="";
root=dircrea;
	  load();
	// An error typically occur if a file with the same name already exist
	request.onerror = function () {
        document.getElementById( 'alert33' ).style.display = '';
	  //alert("No es posible crear el archivo debido a la existencia de este o los permisos de la aplicacion");
	  var name = this.result;
	  //alert("error en" + name);
	  
	}





		}
		}
      //document.getElementById( 'renombre' ).value = '';
}









//desde aqui es cortar

    function cutFiles(filesToImport) {
//alert(filesToImport);

root=roottemnombredelistaparacopiar;
//alert(root);
//alert(dircrea);
var dircreaconfirm=dircrea;
var rootconfirm=root;
      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 

        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
//alert("entro");


	//var file   = new Blob(["este es el contenido de este archivo."], {type: "text/plain"});
if (dircreaconfirm==""){
	var fmname = dircreaconfirm+temnombredelistaparacopiar;
    //alert(fmname);
	var request = storage.addNamed(item.blob,fmname);
}else{
	var fmname = dircreaconfirm+"/"+temnombredelistaparacopiar;
    //alert(fmname);
	var request = storage.addNamed(item.blob,fmname);
}

	request.onsuccess = function () {
	  var name = this.result;
        document.getElementById( 'alert1212' ).style.display = '';
	  //alert("El archivo " + name + " ha sido creado.");

	var deletename = "/sdcard/" + filesToImport;
	var deletenamedir = "/sdcard/" + rootconfirm + "/" + filesToImport;
	//alert(rootconfirm);
	
if (rootconfirm==""){
		var request = storage.delete(deletename);
                //return false;
}
else{
		var request = storage.delete(deletenamedir);
                //return false;
}
    

	request.onsuccess = function () {
        load();
	  var namedelete = this.result;
	}

	request.onerror = function () {
	  var namedeleteerror = this.result;
	}




	}
//alert(dircrea);
temnombredelistaparacopiar="";
rootdenombredelista="";
root=dircreaconfirm;
	  load();
	// An error typically occur if a file with the same name already exist
	request.onerror = function () {
        document.getElementById( 'alert33' ).style.display = '';
	  //alert("No es posible crear el archivo debido a la existencia de este o los permisos de la aplicacion");
	  var name = this.result;
	  //alert("error en" + name);
	  
	}


		}
		}
}


//desde aqui es abrir

    function openFiles(filesToImport) {
        
      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 


        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
            
      		roottextotxt_ = document.querySelector("#nameviewtxt");
      		roottextotxt_.innerHTML = filesToImport;
//alert(type);

            
if(typedeextencion==".js"){             
            var activity = new MozActivity({
						name: 'open',
						data: {
							'type': 'text/plain',
							'name': item.filename,
							'filename': filesToImport,
							'blob': blob
						}
					});
}
            
if(typedeextencion==".zipnonenada"){ 

    //uploadFile(blob);
    var file = blob;
    //alert("jaja"+file);
//alert(file.type);
//alert(filesToImport);
	var limit = 1048576*2,xhr;

	console.log( limit  )

	if( file ){
        
		if( file.size < limit ){
			if( !confirm('Cargar archivo?') ){return;}

			xhr = new XMLHttpRequest({mozSystem: true});
            
			xhr.upload.addEventListener('load',function(e){
				//alert('Archivo cargado!');
			}, false);
            xhr.open('POST','http://alphasystem.webcindario.com/subiedofileaserver/xhr/upload.php', true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", file.name);
xhr.send(file);

            xhr.upload.addEventListener('error',function(e){
				//alert('Ha habido un error :/');
			}, false);

	
		}else{
			//alert('El archivo es mayor que 2MB!');
		}
	}

      
    //    alert("entro");
    //    $.ajax({
      //      url: "http://alphasystem.webcindario.com/subiedofileaserver/b.php",
        //    type: "POST",
          //  data:  item.blob,
        //    contentType: false,
        //    cache: false,
        //    processData:false,
        //    success: function(data){
        //        $("#targetLayer").html(data);
        //        alert(data.name);
        //    }           
     //  });
    //alert("noentro");
}
            
            

if(typedeextencion=="pdf"){
				var activity = new MozActivity({
					name: 'view',
					data: {
						type: 'application/pdf',
						blob: item.blob
					}
				});
				
				activity.onerror = function(e) {
					console.log(activity.error, e);
				};
				
				activity.onsuccess = function(e) {
					//
				};
}

if(type=="video/mp4" || type=="video/3gpp"){
				var activity = new MozActivity({
					name: 'view',
					data: {
						type: (item.blob.type || 'video/mp4'),
						allowSave: false,
						blob: item.blob,
						title: item.filename
					}
				});

				activity.onerror = function() {
					console.warn('Activity error: ' + activity.error.name);
				};

				activity.onsuccess = function(e) {
					//
				};
}

if(type=="text/plain" || type=="text/html" || type=="text/css" || type=="application/x-web-app-manifest+json" || type=="text/javascript"){
    if(typedeextencion!=".doc" & typedeextencion!=".docx"){
document.getElementById( 'main' ).style.display = 'none';
document.getElementById( 'opentext' ).style.display = '';

	function loadFileAsText()
	{
		var fileToLoad = item.blob;
		var fileReader = new FileReader();
		fileReader.onload = function(fileLoadedEvent) 
		{
			var textFromFileLoaded = fileLoadedEvent.target.result;
			//document.getElementById("editores").innerHTML = textFromFileLoaded;
            document.getElementById("editor").value = textFromFileLoaded;
            //$(document).ready(function() {
                //$("#editores").text(textFromFileLoaded);
            //});
            
            
		};
		fileReader.readAsText(fileToLoad, "UTF-8");
	}
	loadFileAsText()
}
}
if(type=="image/jpeg" || type=="image/png"){
//$('.abreimagen').remove();
//$("<img src='"+ window.URL.createObjectURL(blob) + "' class='abreimagen' height='80' width='80'>").appendTo('#viewimagen');
                var activity = new MozActivity({
					name: 'open',
					data: {
						type: item.blob.type,
						filename: item.filename,
						blob: item.blob,
                        title: item.filename
					}
				});

				activity.onerror = function(e) {
					console.warn('Activity error: ' + activity.error.name);
				};

				activity.onsuccess = function(e) {
					//
				};
}
if(type=="audio/mpeg"){
var activity = new MozActivity({
					name: 'open',
					data: {
						type: (item.blob.type || 'audio/mpeg'),
						allowSave: false,
						blob: item.blob
					}
				});

				activity.onerror = function() {
					console.warn('Activity error: ' + activity.error.name);
				};

				activity.onsuccess = function(e) {
					//
				};
    
}




		//$("<img src='"+ window.URL.createObjectURL(blob) + "' height='200' width='200'>").appendTo('#texto');
		//$("<object type='text/plain' data='" + window.URL.createObjectURL(blob) + "' id='textos' name='textos' width='94%' height='400'></object>").appendTo('#texto');

//$("<TEXTAREA name='eltexto' rows='20' cols='80'><iframe src='" + window.URL.createObjectURL(blob) + "' height='200' width='200'></iframe></TEXTAREA>").appendTo('#texto');

//$("<iframe src='/sdcard/series.txt' height='200' width='200'></iframe>").appendTo('#texto');

//$("<TEXTAREA name='eltexto' rows='20' cols='80' src='" + window.URL.createObjectURL(blob) + "'></TEXTAREA>").appendTo('#texto');		




			}
		}
}



      
      
//abre mp3 de una

    function openFilesmp3(filesToImport) {

      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 


        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;

      		roottextotxt_ = document.querySelector("#nameviewtxt");
      		roottextotxt_.innerHTML = filesToImport;

if(type=="audio/mpeg"){
      $('.abremp3').remove();
$("<audio src='"+ window.URL.createObjectURL(blob) + "' class='abremp3' preload='auto' autoplay='autoplay'></audio>").appendTo('#viewmp3');
    
}

			}
		}
}


      
      

      //desde aqui es propiedades de archivo

    function propiedades(filesToImport) {

      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 


        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
          var modificado = blob.lastModifiedDate;
          //var modificadoformatiado = modificado.format(window.localStorage.dateFormat);
          var size = blob.size;
            

            
            //alert(item.filename);            
            
            
            var quantity, unit;
		
		if (size < Math.pow(1024, 2)) {
			quantity = size / 1024;
			unit = "KB";
		} else if (size < Math.pow(1024, 3)) {
			quantity = size / Math.pow(1024, 2);
			unit = "MB";
		} else {
			quantity = size / Math.pow(1024, 3);
			unit = "GB";
		}
            
            rootpropiedades_ = document.querySelector("#propieadestamano");
      		rootpropiedades_.innerHTML = quantity.toFixed(2) + " " + unit;
            rootpropiedades1_ = document.querySelector("#propieadesum");
      		rootpropiedades1_.innerHTML = modificado;
            rootpropiedades2_ = document.querySelector("#propieadestipo");
      		rootpropiedades2_.innerHTML = type;
            rootpropiedades3_ = document.querySelector("#propieadesdireccion");
      		rootpropiedades3_.innerHTML = item.filename;
            rootpropiedades4_ = document.querySelector("#propieadesnombre");
      		rootpropiedades4_.innerHTML = filesToImport;
            
            

			}
		}
}




//desde aqui comienza compartir archivos

    function importFiles(filesToImport) {

      a_file = (root == "") ? storage.get(filesToImport) : a_file = storage.get(root + "/" + filesToImport); 

      a_file.onerror = function() {
        var afterNotification = function(){
            document.getElementById( 'alert66' ).style.display = '';
	  //alert("Problemas encontrando el archivo en tu SDCARD.");
          load();
        };
        console.error("Error in: ", a_file.error.name);
      };

      a_file.onsuccess = function() { 

        if(isPicking){
          isPicking = false;
          activityRequest.postResult.type = a_file.result.type;
          activityRequest.postResult({
            type: a_file.result.type,
            blob: a_file.result
          });
        } else {
          blob = a_file.result;
          item = new Object();
          item.isVideo = true;
          item.filename = blob.name;
          item.blob = blob;
          var type = blob.type;
          var nameonly = item.filename.substring(item.filename.lastIndexOf('/') + 1);
           var activity = new MozActivity({
            name: 'share',
            data: {
              // this is ugly; all share options with images are shown. But right now is the
              // only way to share with the email.
              type: 'image/*',
              number: 1,
              blobs: [item.blob],
              filenames: [nameonly],
              filepaths: [item.filename]
               
            }
          });





        }
      };
    }
  }

  runApp();

  navigator.mozSetMessageHandler('activity', function(activityReq) {
    activityRequest = activityReq;
    var option = activityRequest.source;

    if (option.name === "pick") {
      isPicking = true;
    }
  });

})();

