function validarNombreCarpeta(nombre){
    if(nombre.length<1){
        new SatiraCaos.GUI.alert({
            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
            texto: SatiraCaos.i18n[indice_locale].error.debeEscribirNombre
        });
        return (false);
    }
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz_0123456789";
    var checkStr = nombre;
    var allValid = true;
    var i,ch,j;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++){
            if (ch == checkOK.charAt(j)){
                break;
            }
        }
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
    }
    if (!allValid) {
        new SatiraCaos.GUI.alert({
            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
            texto: SatiraCaos.i18n[indice_locale].error.letrasNumerosGuiones
        });
        return (false);
    }
    checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz";
    ch = checkStr.charAt(0);
    for (j = 0; j < checkOK.length; j++){
        if (ch == checkOK.charAt(j)){
            break;
        }
    }
    if (j == checkOK.length) {
        allValid = false;
    }
    if (!allValid) {
        new SatiraCaos.GUI.alert({
            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
            texto: SatiraCaos.i18n[indice_locale].error.debeComenzarLetra
        });
        return (false);
    }
    return (true);
}
if (typeof SatiraCaos === 'undefined') {
  var SatiraCaos = {};
}
if (typeof SatiraCaos.GUI === 'undefined') {
    SatiraCaos.GUI = {};
}
if (typeof SatiraCaos.GUI.alert === 'undefined') {
    SatiraCaos.GUI.alert=new Class({
        Implements: [Options],
        options: {
            titulo: 'aviso',
            texto: '',
            divFondo: null,
            divMensaje: null,
            tipo: 'alerta',

            resultado: null,

            input1: null,

            valorInput1: '',

            funcionAceptar: function(){}

        },

        initialize: function(options){

            this.setOptions(options);

            Object.append(this,this.options);

            this.options=null;

            this.crearDOM();

        },

        crearDOM: function(){

            var div,div2,div3,div4,div5,div6;

            var span;

            var yo=this;

            this.divFondo=new Element('div',{

            }).inject(document.body);

            this.divFondo.addClass('fondoAlert');

            if(this.tipo=='alerta'){

                this.divFondo.setStyle('z-index','20000');

            }else if(this.tipo=='input'){

                this.divFondo.setStyle('z-index','10000');

            }else if(this.tipo=='confirmar'){

                this.divFondo.setStyle('z-index','15000');

            }

            this.divFondo.innerHTML='&nbsp;';

            this.divFondo.fade(0.2);

            this.divMensaje=new Element('div',{

            }).inject(document.body);

            this.divMensaje.addClass('mensajeAlert');

            if(this.tipo=='alerta'){

                this.divMensaje.setStyle('z-index','20001');

            }else if(this.tipo=='input'){

                this.divMensaje.setStyle('z-index','10001');

            }else if(this.tipo=='confirmar'){

                this.divMensaje.setStyle('z-index','15001');

            }

            div=new Element('div',{

                styles: {

                    'height': '100%',

                    'margin': '0 auto',

                    'width': '50%',

                    'display': 'table'

                }

            }).inject(this.divMensaje);

            div2=new Element('div',{

                styles: {

                    'vertical-align': 'middle',

                    'display': 'table-cell'

                }

            }).inject(div);

            div3=new Element('div',{

                styles: {

                    'display': 'table',

                    'width': '100%'

                }

            }).inject(div2);

            div4=new Element('div',{

                styles: {

                    'display': 'table-row'

                }

            }).inject(div3);

            div4.addClass('tituloAlert');

            div5=new Element('div',{

                styles: {

                    'display': 'table-cell',

                    'text-align': 'left',

                    'width': '100%'

                }

            }).inject(div4);

            span=new Element('span',{

            }).inject(div5);

            span.innerHTML=SatiraCaos.i18n[indice_locale].titulo.satiraCaos+' - '+this.titulo;

            div5=new Element('div',{

                styles: {

                    'display': 'table-cell',

                    'text-align': 'center'

                }

            }).inject(div4);

            span=new Element('span',{

                html: 'X'

            }).inject(div5);

            span.addClass('cerrarAlert');

            span.addEvent('click', function(event){

                yo.cancelar();

            });

            div3=new Element('div',{

            }).inject(div2);

            div3.addClass('contenidoAlert');

            div4=new Element('div',{

            }).inject(div3);

            div4.innerHTML=this.texto;

            if(this.tipo=='input'){

                div4=new Element('div',{

                }).inject(div3);

                this.input1=new Element('input',{

                    type: 'text',

                    value: yo.valorInput1

                }).inject(div4);

                this.input1.focus();

                this.input1.addEvent('keypress', function(event){

                    if(event.key=='enter'){

                        yo.aceptar();

                    }

                });

            }

            div4=new Element('div',{

                styles: {

                    'display': 'table',

                    'width': '100%'

                }

            }).inject(div3);

            div5=new Element('div',{

                styles: {

                    'display': 'table-row'

                }

            }).inject(div4);

            if(this.tipo=='input'||this.tipo=='confirmar'){

                div6=new Element('div',{

                    styles: {

                        'display': 'table-cell',

                        'text-align': 'left'

                    }

                }).inject(div5);

                span=new Element('span',{

                    html: SatiraCaos.i18n[indice_locale].etiqueta.cancelar

                }).inject(div6);

                span.addClass('boton');

                span.addEvent('click', function(event){

                    yo.cancelar();

                });

            }

            div6=new Element('div',{

                styles: {

                    'display': 'table-cell',

                    'text-align': 'right'

                }

            }).inject(div5);

            span=new Element('span',{

                html: SatiraCaos.i18n[indice_locale].etiqueta.aceptar

            }).inject(div6);

            span.addClass('boton');

            span.addEvent('click', function(event){

                yo.aceptar();

            });

        },

        cancelar: function(){

            this.resultado=null;

            this.cerrar();

        },

        aceptar: function(){

            if(this.tipo=='alerta'){

                this.cerrar();

            }else if(this.tipo=='input'){

                this.resultado=this.input1.value;

                this.valorInput1=this.resultado;

                this.cerrar();

                this.funcionAceptar();

            }else if(this.tipo=='confirmar'){

                this.cerrar();

                this.funcionAceptar();

            }

        },

        cerrar: function(){

            this.divFondo.nix({duration: 0},true);

            this.divMensaje.nix({duration: 0},true);

        }

    });

}



if (typeof SatiraCaos.ExploradorArchivos === 'undefined') {

    SatiraCaos.ExploradorArchivos=new Class({

        Implements: [Options],

        options: {

            raiz: 0,

            nodos: [],

            contenedor: '',

            nivelActual: 0,

            nodoSeleccionado: -1,

            botonSubirNivel: null

        },

        initialize: function(options){

            this.setOptions(options);

            Object.append(this,this.options);

            this.options=null;

            var nodosT=this.nodos;

            var i,itop=nodosT.length;

            var boton,div_row,div_table,div_cell;

            this.nivelActual=0;

            this.nodoSeleccionado=-1;

            var yo=this;

            for(i=0;i<itop;i++){

                if(nodosT[i].padre==-1){

                    div_table=new Element('div',{

                        styles:{

                            'display': 'table'

                        }

                    }).inject(this.contenedor);

                    nodosT[i].div=div_table;

                    div_row=new Element('div',{

                        styles:{

                            'display': 'table-row'

                        }

                    }).inject(div_table);

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'left'

                        }

                    }).inject(div_row);

                    boton=new Element('span',{

                    }).inject(div_cell);

                    if(nodosT[i].esCarpeta){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/folder.png" /> '+nodosT[i].nombre;

                    }else if(nodosT[i].esPersonaje){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/attribution.png" /> '+nodosT[i].nombre;

                    }

                    boton.addClass('boton');

                    boton.set('idNodo',i);

                    if(nodosT[i].esCarpeta){

                        boton.addEvent('click', function(event){

                            yo.abrirCarpeta(this.get('idNodo'));

                        });

                    }else if(nodosT[i].esPersonaje){

                        boton.addEvent('click', function(event){

                            yo.cargarPersonaje(this.get('idNodo'));

                        });

                    }

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'right'

                        }

                    }).inject(div_row);
                    boton=new Element('img',{
                        src: 'http://satirarpg.com/img/iconos/16x16/delete.png',
                        alt: SatiraCaos.i18n[indice_locale].etiqueta.eliminar,
                        styles: {
                            'cursor': 'pointer'
                        }
                    }).inject(div_cell);
                    boton.set('idNodo',i);
                    if(nodosT[i].esCarpeta){
                        boton.addEvent('click', function(event){
                            var archivo=yo;
                            var elboton=this;
                            new SatiraCaos.GUI.alert({
                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarCarpeta,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }else if(nodosT[i].esPersonaje){

                        boton.addEvent('click', function(event){

                            var archivo=yo;

                            var elboton=this;

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarPersonaje,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }

                }

            }

        },

        cerrarCarpeta: function(){

            var nodosT=this.nodos;

            var i,itop=nodosT.length;

            var div_cell,div_table,div_row,boton;

            var yo=this;

            if(this.botonSubirNivel!=null){

                this.botonSubirNivel.nix({duration: 0},true);

                this.botonSubirNivel=null;

            }

            if(nodosT[this.nodoSeleccionado].padre!=-1){

                this.botonSubirNivel=new Element('img',{

                    src: 'http://satirarpg.com/img/iconos/16x16/arrow_up.png',

                    styles: {

                        'cursor': 'pointer'

                    }

                }).inject(this.contenedor);

                this.botonSubirNivel.addEvent('click', function(event){

                    yo.cerrarCarpeta();

                });

            }

            for(i=0;i<itop;i++){

                if(nodosT[i].div!=null){

                    nodosT[i].div.nix({duration: 0},true);

                    nodosT[i].div=null;

                }else if(nodosT[i].padre==nodosT[this.nodoSeleccionado].padre){

                    div_table=new Element('div',{

                        styles:{

                            'display': 'table'

                        }

                    }).inject(this.contenedor);

                    nodosT[i].div=div_table;

                    div_row=new Element('div',{

                        styles:{

                            'display': 'table-row'

                        }

                    }).inject(div_table);

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'left'

                        }

                    }).inject(div_row);

                    boton=new Element('span',{

                    }).inject(div_cell);

                    if(nodosT[i].esCarpeta){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/folder.png" /> '+nodosT[i].nombre;

                    }else if(nodosT[i].esPersonaje){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/attribution.png" /> '+nodosT[i].nombre;

                    }

                    boton.addClass('boton');

                    boton.set('idNodo',i);

                    if(nodosT[i].esCarpeta){

                        boton.addEvent('click', function(event){

                            yo.abrirCarpeta(this.get('idNodo'));

                        });

                    }else if(nodosT[i].esPersonaje){

                        boton.addEvent('click', function(event){

                            yo.cargarPersonaje(this.get('idNodo'));

                        });

                    }

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'right'

                        }

                    }).inject(div_row);

                    boton=new Element('img',{

                        src: 'http://satirarpg.com/img/iconos/16x16/delete.png',

                        alt: SatiraCaos.i18n[indice_locale].etiqueta.eliminar,

                        styles: {

                            'cursor': 'pointer'

                        }

                    }).inject(div_cell);

                    boton.set('idNodo',i);

                    if(nodosT[i].esCarpeta){

                        boton.addEvent('click', function(event){

                            var archivo=yo;

                            var elboton=this;

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarCarpeta,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }else if(nodosT[i].esPersonaje){

                        boton.addEvent('click', function(event){

                            var archivo=yo;

                            var elboton=this;

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarPersonaje,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }

                }

            }

            this.nivelActual--;

            this.nodoSeleccionado=nodosT[this.nodoSeleccionado].padre;

        },

        abrirCarpeta: function(idNodo){

            idNodo=parseInt(idNodo);

            var nodosT=this.nodos;

            var i,itop=nodosT.length;

            var div_cell,div_row,div_table,boton;

            var yo=this;

            if(this.botonSubirNivel!=null){

                this.botonSubirNivel.nix({duration: 0},true);

                this.botonSubirNivel=null;

            }

            this.botonSubirNivel=new Element('img',{

                src: 'http://satirarpg.com/img/iconos/16x16/arrow_up.png',

                alt: SatiraCaos.i18n[indice_locale].etiqueta.subir,

                styles: {

                    'cursor': 'pointer'

                }

            }).inject(this.contenedor);

            this.botonSubirNivel.addEvent('click', function(event){

                yo.cerrarCarpeta();

            });

            for(i=0;i<itop;i++){

                if(nodosT[i].div!=null){

                    nodosT[i].div.nix({duration: 0},true);

                    nodosT[i].div=null;

                }else if(nodosT[i].padre==idNodo){

                    div_table=new Element('div',{

                        styles:{

                            'display': 'table'

                        }

                    }).inject(this.contenedor);

                    nodosT[i].div=div_table;

                    div_row=new Element('div',{

                        styles:{

                            'display': 'table-row'

                        }

                    }).inject(div_table);

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'left'

                        }

                    }).inject(div_row);

                    boton=new Element('span',{

                    }).inject(div_cell);

                    if(nodosT[i].esCarpeta){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/folder.png" /> '+nodosT[i].nombre;

                    }else if(nodosT[i].esPersonaje){

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/attribution.png" /> '+nodosT[i].nombre;

                    }

                    boton.addClass('boton');

                    boton.set('idNodo',i);

                    if(nodosT[i].esCarpeta){

                        boton.addEvent('click', function(event){

                            yo.abrirCarpeta(this.get('idNodo'));

                        });

                    }else if(nodosT[i].esPersonaje){

                        boton.addEvent('click', function(event){

                            yo.cargarPersonaje(this.get('idNodo'));

                        });

                    }

                    div_cell=new Element('div',{

                        styles:{

                            'display': 'table-cell',

                            'text-align': 'right'

                        }

                    }).inject(div_row);

                    boton=new Element('img',{

                        src: 'http://satirarpg.com/img/iconos/16x16/delete.png',

                        alt: SatiraCaos.i18n[indice_locale].etiqueta.eliminar,

                        styles: {

                            'cursor': 'pointer'

                        }

                    }).inject(div_cell);

                    boton.set('idNodo',i);

                    if(nodosT[i].esCarpeta){

                        boton.addEvent('click', function(event){

                            var archivo=yo;

                            var elboton=this;

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarCarpeta,
                                tipo: 'confirmar',
                                funcionAceptar: function(){
                                    archivo.eliminar(elboton.get('idNodo'));
                                }
                            });
                        });
                    }else if(nodosT[i].esPersonaje){
                        boton.addEvent('click', function(event){
                            var archivo=yo;
                            var elboton=this;
                            new SatiraCaos.GUI.alert({
                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarPersonaje,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }

                }

            }

            this.nivelActual++;

            this.nodoSeleccionado=idNodo;

        },

        pedirCrearCarpeta: function(){

            var yo=this;

            new SatiraCaos.GUI.alert({

                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                texto: SatiraCaos.i18n[indice_locale].mensaje.escribirNombreCarpeta,

                tipo: 'input',

                funcionAceptar: function(){

                    if(!validarNombreCarpeta(this.resultado)){

                        this.crearDOM();

                    }else{

                        yo.crearCarpeta(this.resultado);

                    }

                }

            });

        },

        pedirGuardarPersonaje: function(){

            var yo=this;

            new SatiraCaos.GUI.alert({

                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                texto: SatiraCaos.i18n[indice_locale].mensaje.escribirNombreArchivo,

                tipo: 'input',

                funcionAceptar: function(){

                    if(!validarNombreCarpeta(this.resultado)){

                        this.crearDOM();

                    }else{

                        yo.guardarPersonaje(elPersonaje,this.resultado,false);

                    }

                }

            });

        },

        guardarPersonajeOk: function(elPersonaje,nombreArchivo,laCarpeta,sobreescribir){

            var variables='';

            var yo=this;

            var i,itop;

            var nodosT=this.nodos;

            var div_cell,div_row,div_table,boton;

            var posNuevoNodo=this.nodos.length;

            var contenedorT=this.contenedor;

            var iterador=this.nodoSeleccionado;

            variables='carpeta='+laCarpeta;

            if(sobreescribir){

                variables+="&sobreescribir_archivo=s";

            }else{

                variables+="&sobreescribir_archivo=n";

            }

            variables+='&nombre_archivo='+nombreArchivo;

            variables+='&tipo_personaje='+$('tipo_personaje').value;

            variables+='&raza='+elPersonaje.raza;

            variables+='&sub_raza='+elPersonaje.subRaza;

            variables+='&sub_sub_raza='+elPersonaje.subSubRaza;

            variables+='&clase_principal='+elPersonaje.clasePrincipal;

            variables+='&nivel_clase_principal='+elPersonaje.nivelClasePrincipal;

            variables+='&clase_afin='+elPersonaje.claseAfin;

            variables+='&nivel_clase_afin='+elPersonaje.nivelClaseAfin;

            variables+='&clase_entrenamiento='+elPersonaje.claseEntrenamiento;

            variables+='&nivel_clase_entrenamiento='+elPersonaje.nivelClaseEntrenamiento;

            variables+='&clase_opuesta='+elPersonaje.claseOpuesta;

            variables+='&nivel_clase_opuesta='+elPersonaje.nivelClaseOpuesta;

            variables+='&caracteristicas=';

            variables+='int:'+elPersonaje.caracteristicas.inteligencia+';';

            variables+='fue:'+elPersonaje.caracteristicas.fuerza+';';

            variables+='des:'+elPersonaje.caracteristicas.destreza+';';

            variables+='cons:'+elPersonaje.caracteristicas.constitucion+';';

            variables+='conc:'+elPersonaje.caracteristicas.concentracion+';';

            variables+='car:'+elPersonaje.caracteristicas.carisma+';';

            variables+='vol:'+elPersonaje.caracteristicas.voluntad+';';

            variables+='log:'+elPersonaje.caracteristicas.logica+';';

            variables+='esp:'+elPersonaje.caracteristicas.espiritu+';';

            variables+='sab:'+elPersonaje.caracteristicas.sabiduria+';';

            variables+='guardados:'+elPersonaje.caracteristicas.guardados;

            variables+='&cualidades=';

            variables+='vida:'+elPersonaje.cualidades.vida+';';

            variables+='mana:'+elPersonaje.cualidades.mana+';';

            variables+='resistencia:'+elPersonaje.cualidades.resistencia+';';

            variables+='reflejos_fisicos:'+elPersonaje.cualidades.reflejos_fisicos+';';

            variables+='reflejos_magicos:'+elPersonaje.cualidades.reflejos_magicos+';';

            variables+='posibilidad_resurreccion:'+elPersonaje.cualidades.posibilidad_resurreccion+';';
            variables+='curacion_resurreccion:'+elPersonaje.cualidades.curacion_resurreccion+';';
            variables+='regeneracion_vida:'+elPersonaje.cualidades.regeneracion_vida+';';
            variables+='regeneracion_mana:'+elPersonaje.cualidades.regeneracion_mana+';';
            variables+='regeneracion_resistencia:'+elPersonaje.cualidades.regeneracion_resistencia+';';
            variables+='guardados:'+elPersonaje.cualidades.guardados+'';
            itop=elPersonaje.habilidades.length;
            var primera_vez=true;
            for(i=0;i<itop;i++){
                if(elPersonaje.habilidades[i].habilidadNatural||elPersonaje.habilidades[i].gratis){
                    continue;

                }

                if(primera_vez){

                    primera_vez=false;

                    variables+="&habilidades=";

                }

                if(elPersonaje.habilidades[i].magia){

                    variables+='hechizo:'+elPersonaje.habilidades[i].indice+','+elPersonaje.habilidades[i].fuentes[0].indice+','+elPersonaje.habilidades[i].forma.indice+','+elPersonaje.habilidades[i].nivel;

                    if(i<(itop-1)){

                        variables+=';';

                    }

                }else if(elPersonaje.habilidades[i].escogeRaza){

                    variables+='habilidadConRaza:'+elPersonaje.habilidades[i].indice+','+elPersonaje.habilidades[i].raza+','+elPersonaje.habilidades[i].nivel;

                    if(i<(itop-1)){

                        variables+=';';

                    }

                }else if(elPersonaje.habilidades[i].especializacionEnArmas){

                    variables+='especializacionEnArmas:'+elPersonaje.habilidades[i].indice+','+elPersonaje.habilidades[i].tipoDeArma+','+elPersonaje.habilidades[i].nivel;

                    if(i<(itop-1)){

                        variables+=';';

                    }

                }else{

                    variables+='habilidad:'+elPersonaje.habilidades[i].indice+','+elPersonaje.habilidades[i].nivel;

                    if(i<(itop-1)){

                        variables+=';';

                    }

                }

            }

            var enviarOpciones=new Request({

                mehtod: 'post',

                url: 'http://satirarpg.com/guardar_personaje.php',

                encoding: 'utf-8',

                noCache: true,

                onRequest: function(){

                    $('estado_explorador_archivos').innerHTML='<img src="img/loading/loading2.gif" />';

                },

                onSuccess: function(responseText, responseXML){

                    if(responseText!='Ok'){

                        new SatiraCaos.GUI.alert({

                            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                            texto: responseText

                        });

                    }else{

                        elPersonaje.laCarpeta=laCarpeta;

                        elPersonaje.nombreArchivo=nombreArchivo;

                        if(!sobreescribir){

                            nodosT[posNuevoNodo]=new  SatiraCaos.ExploradorArchivos.Nodo({

                                nombre: nombreArchivo,

                                padre: iterador,

                                esCarpeta: false,

                                esPersonaje: true

                            });

                            div_table=new Element('div',{

                                styles:{

                                    'display': 'table'

                                }

                            }).inject(contenedorT);

                            nodosT[posNuevoNodo].div=div_table;

                            div_row=new Element('div',{

                                styles:{

                                    'display': 'table-row'

                                }

                            }).inject(div_table);

                            div_cell=new Element('div',{

                                styles:{

                                    'display': 'table-cell',

                                    'text-align': 'left'

                                }

                            }).inject(div_row);

                            boton=new Element('span',{

                            }).inject(div_cell);

                            boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/attribution.png" /> '+nombreArchivo;

                            boton.addClass('boton');

                            boton.set('idNodo',posNuevoNodo);

                            boton.addEvent('click', function(event){

                                yo.cargarPersonaje(this.get('idNodo'));

                            });

                            div_cell=new Element('div',{

                                styles:{

                                    'display': 'table-cell',

                                    'text-align': 'right'

                                }

                            }).inject(div_row);

                            boton=new Element('img',{

                                src: 'http://satirarpg.com/img/iconos/16x16/delete.png',

                                alt: SatiraCaos.i18n[indice_locale].etiqueta.eliminar,

                                styles: {

                                    'cursor': 'pointer'

                                }

                            }).inject(div_cell);

                            boton.set('idNodo',posNuevoNodo);

                            boton.addEvent('click', function(event){

                                var archivo=yo;

                                var elboton=this;

                                new SatiraCaos.GUI.alert({

                                    titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                    texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarPersonaje,

                                    tipo: 'confirmar',

                                    funcionAceptar: function(){

                                        archivo.eliminar(elboton.get('idNodo'));

                                    }

                                });

                            });

                        }

                        if($('btn_guardar_personaje_como')==null){

                            boton=new Element('img',{

                                id: 'btn_guardar_personaje_como',

                                src: 'http://satirarpg.com/img/iconos/16x16/disk_multiple.png',

                                alt: SatiraCaos.i18n[indice_locale].etiqueta.guardarComo,

                                styles: {

                                    'cursor': 'pointer'

                                }

                            }).inject('barra_herramientas');

                            boton.addEvent('click', function(event){

                                yo.pedirGuardarPersonaje();

                            });

                        }

                    }

                    $('estado_explorador_archivos').innerHTML='';

                }

            });

            enviarOpciones.send(variables);

        },

        guardarPersonaje: function(elPersonaje,nombreArchivo,sobreescribir){

            var variables='';

            var yo=this;

            var iterador=this.nodoSeleccionado;

            var nodosT=this.nodos;

            var i,itop=nodosT.length;

            if(!sobreescribir){

                for(i=0;i<itop;i++){

                    if(nodosT[i].padre==this.nodoSeleccionado){

                        if(!nodosT[i].esCarpeta&&nodosT[i].nombre==nombreArchivo){

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.archivoExisteSobreescribir,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    yo.guardarPersonaje(elPersonaje,nombreArchivo,true);

                                }

                            });

                            return;

                        }

                    }

                }

            }

            while(iterador!=-1){

                variables=this.nodos[iterador].nombre+'-'+variables;

                iterador=this.nodos[iterador].padre;

            }            

            var laCarpeta=variables;

            this.guardarPersonajeOk(elPersonaje,nombreArchivo,laCarpeta,sobreescribir);

            

        },

        cargarPersonaje: function(idNodo){

            idNodo=parseInt(idNodo);

            var variables='';

            var iterador=this.nodoSeleccionado;

            while(iterador!=-1){

                variables=this.nodos[iterador].nombre+'-'+variables;

                iterador=this.nodos[iterador].padre;

            }

            iterador=this.nodoSeleccionado;

            var form,input;
            form=new Element('form',{
                action: 'http://satirarpg.com/'+the_page,
                method: 'post'
            }).inject(document.body);
            input=new Element('input',{
                type: 'hidden',
                name: 'carpeta_personaje',
                value: variables
            }).inject(form);
            input=new Element('input',{
                type: 'hidden',
                name: 'cargar_personaje',
                value: this.nodos[idNodo].nombre
            }).inject(form);
            form.submit();
        },
        eliminar: function(idNodo){
            idNodo=parseInt(idNodo);
            var i,itop=this.nodos.length;
            for(i=0;i<itop;i++){
                if(this.nodos[i].padre==idNodo){
                    new SatiraCaos.GUI.alert({
                        titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,
                        texto: SatiraCaos.i18n[indice_locale].error.carpetaDebeEstarVacia
                    });
                    return;
                }
            }
            var variables='';
            var yo=this;
            var iterador=this.nodoSeleccionado;
            while(iterador!=-1){
                variables=this.nodos[iterador].nombre+'-'+variables;
                iterador=this.nodos[iterador].padre;
            }
            variables='carpeta='+variables;
            variables+='&nombre_archivo='+this.nodos[idNodo].nombre;
            if(this.nodos[idNodo].esCarpeta){
                variables+='&tipo=carpeta';
            }else if(this.nodos[idNodo].esPersonaje){
                variables+='&tipo=personaje';
            }
            var enviarOpciones=new Request({

                mehtod: 'post',

                url: 'http://satirarpg.com/borrar_datos_personaje.php',

                encoding: 'utf-8',

                noCache: true,

                onRequest: function(){

                    $('estado_explorador_archivos').innerHTML='<img src="img/loading/loading2.gif" />';

                },

                onSuccess: function(responseText, responseXML){

                    $('estado_explorador_archivos').innerHTML='';

                    if(responseText!='Ok'){

                        new SatiraCaos.GUI.alert({

                            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                            texto: responseText

                        });

                    }else{

                        limpiarCarpetasPersonaje();

                        cargarCarpetasPersonaje();

                    }

                }

            });

            enviarOpciones.send(variables);

        },

        crearCarpeta: function(nombreCarpeta){

            var variables='';

            var yo=this;

            var iterador=this.nodoSeleccionado;

            while(iterador!=-1){

                variables=this.nodos[iterador].nombre+'-'+variables;

                iterador=this.nodos[iterador].padre;

            }

            iterador=this.nodoSeleccionado;

            variables+=nombreCarpeta;

            var div_cell,div_row,div_table,boton;

            var posNuevoNodo=this.nodos.length;

            var nodosT=this.nodos;

            var contenedorT=this.contenedor;

            var enviarOpciones=new Request({

                mehtod: 'post',

                url: 'http://satirarpg.com/crear_carpeta_personaje.php',

                encoding: 'utf-8',

                noCache: true,

                onRequest: function(){

                    $('estado_explorador_archivos').innerHTML='<img src="img/loading/loading2.gif" />';

                },

                onSuccess: function(responseText, responseXML){

                    if(responseText!='Ok'){

                        new SatiraCaos.GUI.alert({

                            titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                            texto: responseText

                        });

                    }else{

                        nodosT[posNuevoNodo]=new  SatiraCaos.ExploradorArchivos.Nodo({

                            nombre: nombreCarpeta,

                            padre: iterador

                        });

                        div_table=new Element('div',{

                            styles:{

                                'display': 'table'

                            }

                        }).inject(contenedorT);

                        nodosT[posNuevoNodo].div=div_table;

                        div_row=new Element('div',{

                            styles:{

                                'display': 'table-row'

                            }

                        }).inject(div_table);

                        div_cell=new Element('div',{

                            styles:{

                                'display': 'table-cell',

                                'text-align': 'left'

                            }

                        }).inject(div_row);

                        boton=new Element('span',{

                        }).inject(div_cell);

                        boton.innerHTML='<img src="http://satirarpg.com/img/iconos/16x16/folder.png" /> '+nombreCarpeta;

                        boton.addClass('boton');

                        boton.set('idNodo',posNuevoNodo);

                        boton.addEvent('click', function(event){

                            yo.abrirCarpeta(this.get('idNodo'));

                        });

                        div_cell=new Element('div',{

                            styles:{

                                'display': 'table-cell',

                                'text-align': 'right'

                            }

                        }).inject(div_row);

                        boton=new Element('img',{

                            src: 'http://satirarpg.com/img/iconos/16x16/delete.png',

                            alt: SatiraCaos.i18n[indice_locale].etiqueta.eliminar,

                            styles: {

                                'cursor': 'pointer'

                            }

                        }).inject(div_cell);

                        boton.set('idNodo',posNuevoNodo);

                        boton.addEvent('click', function(event){

                            var archivo=yo;

                            var elboton=this;

                            new SatiraCaos.GUI.alert({

                                titulo: SatiraCaos.i18n[indice_locale].titulo.creadorPersonajes,

                                texto: SatiraCaos.i18n[indice_locale].pregunta.eliminarCarpeta,

                                tipo: 'confirmar',

                                funcionAceptar: function(){

                                    archivo.eliminar(elboton.get('idNodo'));

                                }

                            });

                        });

                    }

                    $('estado_explorador_archivos').innerHTML='';

                }

            });

            enviarOpciones.send('carpeta='+variables);

        }

    });

}



if (typeof SatiraCaos.ExploradorArchivos.Nodo === 'undefined') {

    SatiraCaos.ExploradorArchivos.Nodo=new Class({

        Implements: [Options],

        options: {

            nombre: '',

            esCarpeta: true,

            esPersonaje: false,

            padre: -1,

            div: null

        },

        initialize: function(options){

            this.setOptions(options);

            Object.append(this,this.options);

            this.options=null;

        }

    });

}



/*
Ejemplo de como se usa:
window.addEvent('load', function() {
    var boton=new SatiraCaos.GUI.Menu({
        contenedor: 'boton',
        titulo: 'Menu',
        muestraSubMenusCon: 'click',
        abreCon: '',
        despuesDeabrir: function(){
            $('estado').innerHTML='Menu abierto';
        }
    });
    var submenu=new SatiraCaos.GUI.Menu({
        contenedor: '',
        titulo: 'SubMenu_1',
        vertical: true,
        despuesDeabrir: function(){
            $('estado').innerHTML='SubMenu 1 abierto';
        }
    });
    boton.agregarSubMenu(submenu);
    var subsubmenu=new SatiraCaos.GUI.Menu({
        contenedor: '',
        titulo: 'SubSubMenu_1_1',
        vertical: true,
        despuesDeabrir: function(){
            $('estado').innerHTML='SubSubMenu 1 1 abierto';
        }
    });
    submenu.agregarSubMenu(subsubmenu);
    submenu=new SatiraCaos.GUI.Menu({
        contenedor: '',
        titulo: 'SubMenu_2',
        vertical: true,
        despuesDeabrir: function(){
            $('estado').innerHTML='SubMenu 2 abierto';
        }
    });
    boton.agregarSubMenu(submenu);
});
 */


SatiraCaos.GUI.zindexmenu=9999;
SatiraCaos.GUI.Menu=new Class({
    Implements: [Options],
    options: {
        contenedor: '',
        /* si se coloca - es un separador */
        titulo: '',
        ancho: 100,
        div_dom: null,
        contenedor_submenus: null,
        checkeable: false,
        checked: false,
        antesDeabrir: function(menu){},
        despuesDeabrir: function(menu){},
        muestraSubMenusCon: 'mouseenter',
        ocultaSubMenusCon: 'mouseleave',
        abreCon: 'click',
        vertical: false,
        submenus: [],
        principal: false,
        padre: null,
        span_txt: null,
        posicion: 0
    },
    initialize: function(options){
        this.setOptions(options);
        Object.append(this,this.options);
        this.options=null;
        this.crearDOM();
    },
    crearDOM: function(){
        var yo=this;
        this.div_dom=new Element('div',{
        });
        if(this.contenedor!=''){
            this.div_dom.inject(this.contenedor);
        }
        if(this.titulo!='-'){
            this.div_dom.addEvent(this.muestraSubMenusCon,function(event){
                yo.mostrarSubMenu();
                event.stopPropagation();
            });
            this.div_dom.addEvent(this.ocultaSubMenusCon,function(event){
                yo.ocultarSubMenu();
            });
            if(this.abreCon!=''){
                this.div_dom.addEvent(this.abreCon,function(event){
                    yo.abrir();
                    event.stopPropagation();
                });
            }
        }
        if(this.titulo!='-'){
            this.span_txt=new Element('span',{
            }).inject(this.div_dom);
            this.span_txt.innerHTML=this.titulo;
        }else{
            this.div_dom.innerHTML='<hr>';
        }
        this.div_dom.setStyle('width',this.ancho+'px');
        if(this.principal){
            this.div_dom.setStyle('z-index',SatiraCaos.GUI.zindexmenu--);
            this.div_dom.addClass('SatiraCaos_GUI_Menu');
        }
        if(this.checkeable){
            if(this.checked){
                this.div_dom.addClass('boton_menu_horizontal_checked');
            }else{
                this.div_dom.addClass('boton_menu_horizontal_unchecked');
            }
        }else{
            if(this.titulo!='-'){
                if(this.vertical){
                    this.div_dom.addClass('boton_menu_vertical_item');
                }else{
                    this.div_dom.addClass('boton_menu_horizontal');
                }
            }else{
                if(this.vertical){
                    this.div_dom.addClass('separador_menu_vertical');
                }else{
                    this.div_dom.addClass('separador_menu_horizontal');
                }
            }
        }
        this.contenedor_submenus=new Element('div',{
        }).inject(this.div_dom);
        if(this.vertical){
            this.contenedor_submenus.addClass('contenedor_menu_vertical_interno_oculto');
            this.contenedor_submenus.setStyle('left',(this.ancho+20)+'px');
        }else{
            this.contenedor_submenus.addClass('contenedor_menu_vertical_oculto');
        }
    },
    mostrarSubMenu: function(){
        if(this.vertical){
            this.contenedor_submenus.removeClass('contenedor_menu_vertical_interno_oculto');
            this.contenedor_submenus.addClass('contenedor_menu_vertical_interno');
        }else{
            this.contenedor_submenus.removeClass('contenedor_menu_vertical_oculto');
            this.contenedor_submenus.addClass('contenedor_menu_vertical');
        }
    },
    ocultarSubMenu: function(){
        if(this.vertical){
            this.contenedor_submenus.removeClass('contenedor_menu_vertical_interno');
            this.contenedor_submenus.addClass('contenedor_menu_vertical_interno_oculto');
        }else{
            this.contenedor_submenus.removeClass('contenedor_menu_vertical');
            this.contenedor_submenus.addClass('contenedor_menu_vertical_oculto');
        }
    },
    abrir: function(){
        this.antesDeabrir(this);
        if(this.checkeable){
            this.checked=!this.checked;
            if(this.checked){
                this.div_dom.removeClass('boton_menu_horizontal_unchecked');
                this.div_dom.addClass('boton_menu_horizontal_checked');
            }else{
                this.div_dom.removeClass('boton_menu_horizontal_checked');
                this.div_dom.addClass('boton_menu_horizontal_unchecked');
            }
        }
        this.ocultarSubMenu();
        this.despuesDeabrir(this);
    },
    agregarSubMenu: function(submenu){
        if(this.checkeable){
        }else{
            if(this.vertical){
                this.div_dom.removeClass('boton_menu_vertical_item');
                this.div_dom.addClass('boton_menu_vertical');
            }else{
            }
        }
        this.submenus[this.submenus.length]=submenu;
        submenu.posicion=this.submenus.length-1;
        submenu.div_dom.inject(this.contenedor_submenus);
        if(this.posicion>0&&!this.principal){
            this.contenedor_submenus.setStyle('top','-'+((this.posicion)*22)+'px');
        }
        submenu.padre=this;
    },
    cambiarEtiquetaSubMenu: function(etiqueta,nuevaEtiqueta){
        var i,itop=this.submenus.length;
        for(i=0;i<itop;i++){
            if(this.submenus[i].span_txt!=null&&this.submenus[i].span_txt.innerHTML==etiqueta){
                this.submenus[i].span_txt.innerHTML=nuevaEtiqueta;
                return;
            }
        }
    },
    getTitulo: function(){
        return this.span_txt.innerHTML;
    },
    setTitulo: function(nuevoTitulo){
        this.span_txt.innerHTML=nuevoTitulo;
    }
});

SatiraCaos.GUI.Menu.actualizarIndices=function(){
    SatiraCaos.GUI.zindexmenu=9999;
    var divs=$$('.SatiraCaos_GUI_Menu');
    var i,itop=divs.length;
    for(i=0;i<itop;i++){
        divs[i].setStyle('z-index',SatiraCaos.GUI.zindexmenu--);
    }
}

String.implement({

    startsWith: function(str){

        return (this.match("^"+str)==str)

    }

});

String.implement({

    endsWith: function(str){

        return (this.match(str+"$")==str)

    }

});

Element.implement({

    addSpan: function(texto){

        var span=new Element('span', {

            text: texto

        }).inject(this);

        return span;

    }

});

Element.implement({

    addBoldSpan: function(texto){

        var span=new Element('span').inject(this);

        new Element('strong', {

            text: texto

        }).inject(span);

        return span;

    }

});

Element.implement({

    addBr: function(){

        new Element('br').inject(this);

    }

});



if (typeof SatiraCaos.i18n === 'undefined') {

    SatiraCaos.i18n = [];

}



if (typeof SatiraCaos.i18n[0] === 'undefined') {//es

    SatiraCaos.i18n[0] = {};

}



if (typeof SatiraCaos.i18n[1] === 'undefined') {

    SatiraCaos.i18n[1] = {};

}



if (typeof SatiraCaos.i18n[0].titulo === 'undefined') {

    SatiraCaos.i18n[0].titulo = {};

}



if (typeof SatiraCaos.i18n[1].titulo === 'undefined') {

    SatiraCaos.i18n[1].titulo = {};

}



if (typeof SatiraCaos.i18n[0].error === 'undefined') {

    SatiraCaos.i18n[0].error = {};

}



if (typeof SatiraCaos.i18n[1].error === 'undefined') {

    SatiraCaos.i18n[1].error = {};

}



if (typeof SatiraCaos.i18n[0].etiqueta === 'undefined') {

    SatiraCaos.i18n[0].etiqueta = {};

}



if (typeof SatiraCaos.i18n[1].etiqueta === 'undefined') {

    SatiraCaos.i18n[1].etiqueta = {};

}



if (typeof SatiraCaos.i18n[0].pregunta === 'undefined') {

    SatiraCaos.i18n[0].pregunta = {};

}



if (typeof SatiraCaos.i18n[1].pregunta === 'undefined') {

    SatiraCaos.i18n[1].pregunta = {};

}



if (typeof SatiraCaos.i18n[0].mensaje === 'undefined') {

    SatiraCaos.i18n[0].mensaje = {};

}



if (typeof SatiraCaos.i18n[1].mensaje === 'undefined') {

    SatiraCaos.i18n[1].mensaje = {};

}



if (typeof SatiraCaos.i18n[0].comando === 'undefined') {

    SatiraCaos.i18n[0].comando = {};

}



if (typeof SatiraCaos.i18n[1].comando === 'undefined') {

    SatiraCaos.i18n[1].comando = {};

}



if (typeof SatiraCaos.i18n[0].comando.ladosdado === 'undefined') {

    SatiraCaos.i18n[0].comando.ladosdado = {};

}



if (typeof SatiraCaos.i18n[1].comando.ladosdado === 'undefined') {

    SatiraCaos.i18n[1].comando.ladosdado = {};

}


