
function el(id)
{ 
	return document.getElementById(id);
}

function showPopup(url)
{
	iWidth = 600;
	iHeight = 600;
	iLeft = (window.screen.width - iWidth ) / 2
	iTop = (window.screen.height - iHeight ) / 2
	window.open(url,"_blank","menubar=no, scrollbars=yes, statusbar=no, left="+iLeft+", top="+iTop+", width="+iWidth+", height="+iHeight+",");
}

/**
 * Clase que contiene utilidades 
 * varias
 */
function JUtil() {}
JUtil.IE  = 1001;
JUtil.MOZ = 1002;
JUtil.getNav = function() {
    var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1? true : false;
    var isMoz = document.implementation && document.implementation.createDocument;
    if ( isIE ) return this.IE;
    if ( isMoz) return this.MOZ;
}   
var isIE = JUtil.getNav()==JUtil.IE? true : false;

// Creación de nuevas funciones para Math
Math.genNumber = function(number) {
    exp = Math.pow(10,number);
    return Math.round(Math.random() * exp);
}

String.prototype.UXC = function () {
	cadena = this.replace(/#lt#/gi,"&lt;");
	cadena = cadena.replace(/#cm#/gi,"\"");
	cadena = cadena.replace(/#am#/gi,"&amp;");
	cadena = cadena.replace(/#ap#/gi,"'");
	return cadena;	
}	


String.prototype.getDir = function () {
	cadena = this.replace("http://","");
	cadena = cadena.replace(document.domain+"/","");
	
	partes = cadena.split("/");
	partes.pop();
	var i;
	dir = "";
	if ( partes.length == 1 ) return "";
	for(i=0;i<partes.length;i++) {
		
		dir += partes[i];
		dir+="/";
	}
	return dir;
}

String.prototype.urlEncode = function () {

	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = this;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "%20";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode <= 255) {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;

}




/**
 * Objeto que controla las pilas globales
 * @return (void)
 */
function JPile() {
    // Propiedades
    this.arrRefObjects = Array();
    this.arrRefDialogs = Array();
    
    // Métodos
    this.addRefObject  = JPileAddRefObject;
    this.getRefObject  = JPileGetRefObject;

}


/**
 * Funcion que controla los objetos asignados
 * a elementos HTML
 * @param  (Object) Objeto que se quiere añadir
 * @return (int) Identificador al objeto añadido
 */
function JPileAddRefObject( obj ) {
    id = this.arrRefObjects.length;
    this.arrRefObjects[id] = obj;
    return id;
}
 
/**
 * Recupera la referencia del objeto
 * @param (int) Identificador asignado del objeto
 * @return (Object) Objeto indicado o undefined si no se encuentra
 */
function JPileGetRefObject(id) {
    if ( this.arrRefObjects[id] ) return this.arrRefObjects[id];
    return undefined;
}

// Instancia del objeto para poder utilizar sus propiedades
jPile = new JPile();
   
function valida_fecha(dia,mes,ano)
		{
		
    if ( dia.length == 0 ) return false;
    if ( mes.length == 0 ) return false;
    if ( ano.length == 0 ) return false;
    
    
		dia=parseInt(limpiaCeros(dia));
		mes=parseInt(limpiaCeros(mes));
		ano=parseInt(limpiaCeros(ano));
	
		fecha = new Date();
	
	 
		if (mes<1 || mes>12)
			return false;
	
			meses = new Array(13)
			meses[1] = 31;
			if ( (ano%4) ==0) meses[2]=29;
			else meses[2]=28;
			meses[3] = 31;
			meses[4] = 30;
			meses[5] = 31;
			meses[6] = 30;
			meses[7] = 31;
			meses[8] = 31;
			meses[9] = 30;
			meses[10] = 31;
			meses[11] = 30;
			meses[12] = 31;


		if (dia<1 || dia>meses[mes]) return false;	
			
		return true;
		}

function seleccionar(form_select,seleccion)
		{
		for(i=0;i<(form_select.length);i++)
				{
					if (form_select.options[i].value==seleccion)
						{
						form_select.options[i].selected=true;
						}
				}	
		}

function anadir(form_select,valor,texto,marcado,clase)
			{

			form_select.length++;
				form_select.options[form_select.length-1].text=texto;
				form_select.options[form_select.length-1].value=valor;
				form_select.options[form_select.length-1].selected=marcado;	
				form_select.options[form_select.length-1].className = clase;
			}


digito="0123456789";
puntoDecimal=".,";
caracterMayuscula="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
caracterMinuscula="abcdefghijklmnopqrstuvwxyz";
caracer = caracterMayuscula + caracterMinuscula;
alfaNumerico=digito+caracterMayuscula+caracterMinuscula;
signos="_-.";
arroba="@";
cadenaValida= alfaNumerico+signos+arroba;



function validarCadena(mascara,cadena)
	{
	
		if (cadena.length==0) return false;
	
	
		for(i=0;i<cadena.length;i++)
			{
			if (mascara.indexOf(cadena.charAt(i))==-1) return false;
			}
		return true;
	}

function esEmail(cadena)
	{
	
		if(!validarCadena(cadena,arroba))
			{error='cadena sin arroba';return false;}
		
		parte = cadena.split("@");
	
		aaaa=parte[0];
		
			
		ultimoPunto = parte[1].lastIndexOf(".");	
		if (ultimoPunto==-1)
			{error='El email no tiene dominio';return false;}		
		
		bbbb=parte[1].slice(0,ultimoPunto);
		
		if (bbbb.length<2)
			{error='bbbb no puede ser menor que 2';return false;}
		
		if (!validarCadena(alfaNumerico+signos,aaaa+bbbb))
				{error='cadena sin arroba';return false;}
		

		cc=parte[1].slice(ultimoPunto+1);


		if (cc.length<2 || cc.length>4)
			{error='cadena sin arroba';return false;}
		if (!validarCadena(caracterMayuscula+caracterMinuscula,cc))
			{error='cadena sin arroba';return false;}	

		return true;
	
	}


function roundOff(value, precision)
	{
		
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));
        if ( precision == 0) return whole;
        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {

                result = whole.substring(0, decPoint);

				result += ",";
                result += whole.substring(decPoint, whole.length);

				if (result==",0") result="0,00";
        }
        else
        {

                result = "0,"+whole;
        }

        return result;
		}
    
function limpiaCeros( cadena ) 
{
    temp="";
    numeros=0;
    for(i=0;i<cadena.length;i++)
    {
        if ( cadena.charAt(i)!="0" || numeros>0)
        {  
           temp+=cadena.charAt(i);
           numeros++;
        } 
    }
return temp;
}

/**
 * Aplica una mascara a una cadena
 * @param (String) mask 	Máscara a aplicar
 * @param (String) cadena	Cadena
 * @param (String) align	Alineamiento de la cadena ('left', 'right')
 */
function mascara(  mask , cadena , align ) {
    var i;
    if ( !align  ) align="left";
    if ( !mask   ) return cadena;
	if ( !cadena ) return ""; 

	// Alineamiento del texto a la derecha
    if ( align == "right" ) {
        cad = "";
        for(i=0;i<mask.length-cadena.length;i++) {
            cad+=mask.charAt(i);
        } 
        cad += cadena; 
    }
    
    // Alineamiento del texto a la izquierda
    if ( align == "left" ) {
        cad = cadena;
        for(i=cadena.length;i<mask.length;i++) {
            cad+=mask.charAt(i);
        } 
    }
    
    return cad;
}

/*-------------------------------------------------------------------
    Objeto popup
--------------------------------------------------------------------*/

     function JPopup(window) {
         this.url    = "";
         this.width  = 780;
         this.height = 500;
         this.returnedValue = "";
         this.window = window;
         this.Show = JPopupShow;
         this.hide   = "no";
         this.title  = "";
     }    
     
     function JPopupShow() {
         
         argumentos = Array( this.url );
         valor = this.window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/funciones/popup.php?title="+this.title, argumentos ,  "dialogHeight:"+this.height+"px; dialogWidth:"+this.width+"px; dialogTop:150px; dialogLeft:150px;  edge:raised; scroll:yes; status:no; dialogHide="+this.hide+";");

         if ( valor == "undefined" ) valor = "";
         if ( !valor ) valor = "";
         return valor;
     }
    
/*-------------------------------------------------------------------
    Objeto Confirm
--------------------------------------------------------------------*/
     function JConfirm( texto ) {
        this.texto  = texto;
        this.width  = "400";
        this.height = "200";
        this.Show  = JConfirmShow;
     }

     function JConfirmShow() {
         argumentos = Array( this.texto );
         res = window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/plantillas/jmensaje.php", argumentos ,  "dialogHeight:"+this.height+"px; dialogWidth:"+this.width+"px center:yes; edge:raised; scroll:no; status:no;");
         if ( res == "undefined" ) res = false;
         if ( !res ) res = false;
         return res;
     }
   
/*------------------------------------------------------------------
     Objeto Formulario 
-------------------------------------------------------------------*/
    function JForm( form ) {
        this.form = form;
        this.arrInputs = Array();
           
           
        this.addInput  = JFormAddInput;
        this.validar   = JFormValidar;
        this.submit    = JFormSubmit;
    }
     
    function JFormAddInput( input ) {
        if ( !input ) return;
        this.arrInputs[ this.arrInputs.length ] = input;
 
    }
    
    function JFormSubmit() {

        if  (this.validar()) {
            this.form.submit();
        }
    }
    
    function JFormValidar() {
        
        for(iInp=0;iInp<this.arrInputs.length;iInp++) {
            
            
            //if ( iInp > 50 ) return;
            if ( !this.arrInputs[iInp].validar() ) return false;
        }   
        
        return true;
    }
    
    
    function numericCheckKey(event) {
    	evento = isIE? e : event;
    
		key = isIE ? event.keyCode : event.charCode;
        keyNom = String.fromCharCode(key);
        alert(event.ctrlKey);
        if ( event.ctrlKey) return true;
	    if ( key == 0 ||
	         key == 9 ||
	         key == 8 ||
	         key == 37 ||
	         key == 39 ||                  
	         key == 46 ||                  
	         key == 116 
	    ) {
	            return true;
	    }
        
        validos = "0123456789.,-";
        
        if ( key == 46 ) {
           if ( isIE ) event.keyCode = 44;
           else {
           	 event.target.value += ",";
           	 return false;
           }
        }
        if ( validos.search(keyNom)==-1 ) {
        	alert("Solo se pueden introducir carácteres numéricos");
            if ( isIE ) event.keyCode = null;
            return false;
        }
        
    }
    
    
    
    
    
/*----------------------------------------------------------------
    Objeto Input
-----------------------------------------------------------------*/    
    function JInput( input , alias , tipo , notNull ) {
        this.input   = input;
        this.alias   = alias;
        this.tipo    = (tipo) ? tipo : "texto";
        this.notNull = (notNull) ? notNull : false;
        this.mensaje = "";
        this.filtro  =  this.input.getAttribute("filtro")!=null? this.input.getAttribute("filtro") : "";
         
        this.validar = JInputValidar;
        if ( this.input.onchange == null ) {
            this.input.onchange = JInputModificado;
        }
       

        // Si el input es númerico
	    if ( this.tipo == "numerico" ) {
			
			// Añadido evento de pulsación de tecla
	        if ( this.input.addEventListener ) {
	        
	           this.input.setAttribute("onkeypress","return JInputNumericValidate(event);");
	        } else {
	           this.input.onkeypress = JInputNumericValidate; 
	        }
	        this.input.value = this.input.value.replace(/\./gi,",");
	        
	    }
            
    }
    function mesaje() {
        
    }
    
    /**
	 * Valida la pulsación de una tecla en un
	 * imput numérico
	 * @param   Event   e   Objeto Evento (solo en Netscape)
	 */
	function JInputNumericValidate(e) {
	
	    if ( e ) {
	        return JInputNumericValidateNS(e);
	    } else {
	        return JInputNumericValidateIE(event);
	    }
	}
	
	
/**
 * Valida la pulsación de una tecla en un
 * imput numérico
 * @param   Event   e   Objeto Evento (solo en Netscape)
 */
function JInputNumericValidateIE(event) {
    src    = event.srcElement;
    key    = event.keyCode;
    
    if ( event.ctrlKey) return;
    if ( key == 0 ||
         key == 9 ||
         key == 8 ||
         key == 37 ||
         key == 39 ||                  
         key == 27 ||
         key == 13 ||
         key == 116
    ) {
            return ;
    }

    
    keyNom = String.fromCharCode(key);
    validos = "0123456789.,-";
    if ( key == 46 ) {
       event.keyCode = 44;
    }
    
    if ( validos.search(keyNom)==-1 ) {
        msg = src.getAttribute("msgNum");
        
        if ( !msg ) alert("Este campo solo admite valores numéricos");
        else alert(msg);
        event.keyCode = null;
        return;
    }
    return;
}

/**
 * Valida la pulsación de una tecla en un
 * imput numérico
 * @param   Event   e   Objeto Evento (solo en Netscape)
 */
function JInputNumericValidateNS(event) {

    src = event.target;
    key = event.charCode? event.charCode : event.keyCode;
    
    if ( event.ctrlKey) return true;
    if ( key == 0 ||
         key == 9 ||
         key == 8 ||
         key == 37 ||
         key == 39 ||      
         key == 27 ||            
         key == 13 ||
         key == 116
    ) {
            return true;
    }
    
    keyNom = String.fromCharCode(key);

    validos = "0123456789.,-";
    
    if ( key == 46 ) {
   
        src.value += ",";
        return false;
    }
    
    if ( validos.search(keyNom)==-1 ) {
        msg = src.getAttribute("msgNum");
        if ( !msg ) alert("Este campo solo admite valores numéricos");
        else alert(msg);
        return false;
    }
    return true;
}
	
    
    function JInputModificado() {
        
        if ( this.type != "textarea") {
            this.className = "inputMod";
        } else {
            this.className = "inputModArea";
        }
    }
    function JInputValidar() {
       
        if ( this.notNull ) {
        	var className = this.input.className;
        	if ( className == 'input_html' )  {
        		var tiny = tinyMCE.get(this.input.name);
        		if ( !tiny ) return true;
        		var value = tiny.getContent();
        		if ( value.length == 0 || value == '<p>&nbsp;</p>' ) {
        		
        		 if ( !this.mensaje ) {
                      alert("El campo [" + this.alias + "] no puede quedar vacio");
                  } else {
                      alert(this.mensaje);
                  }
                  if ( this.input.type != "textarea") {
                      this.input.focus();
                  }
                  return false;
        		} else return true;
        		
        	}
              if ( this.input.value.length == 0 ) {
                   
                  if ( !this.mensaje ) {
                      alert("El campo [" + this.alias + "] no puede quedar vacio");
                  } else {
                      alert(this.mensaje);
                  }
                  if ( this.input.type != "textarea") {
                      this.input.focus();
                  }
                  return false;
              }
              if ( this.tipo == "numerico" && this.input.value == 0) {
              if ( !this.mensaje ) {
                      alert("El campo [" + this.alias + "] no puede ser 0");
                  } else {
                      alert(this.mensaje);
                  }
                  this.input.focus();
                  return false;
              }
           } 
    
        if ( this.tipo == "texto" ) {
            
        }

        if ( this.tipo == "numerico" ) {
            
            
            numcomas = 0;
            for(i=0;i<this.input.value.length;i++) {
                numcomas += (this.input.value.charAt(i) == ",") ? 1 : 0;
            }
            

            this.input.value = this.input.value.replace(/\./gi,"");
            this.input.value = this.input.value.replace(/,/gi,".");
            this.input.value = limpiaCeros( this.input.value );
            if ( this.input.value.length == 0 ) this.input.value = 0;
            if ( isNaN(this.input.value) ) {
                this.input.value = this.input.value.replace(/\./gi,",");
                if ( this.mensaje ) alert(this.mensaje);
                else alert("El campo " + this.alias + " debe contener valores númericos");
                this.input.focus();
                return false;
            }
        }
        
        if ( this.tipo == "email") {
            if ( !esEmail( this.input.value)) {
               if ( this.mensaje ) alert(this.mensaje);
               else alert("El campo "+ this.alias +" no contiene un formato de email válido");
               this.input.focus();
               return;
            } 
        }
        
        if ( this.filtro.length>0  ) {
        	if ( !validarCadena(this.filtro,this.input.value)) {
        		alert("El campo [" + this.alias + "] contiene carácteres no permitidos.\nEvite acentos, comillas, barras, espacios en blanco, etc.");
        		this.input.focus();
        		return;
        	}
        }
        
           
        return true;  
    }

/*--------------------------------------------------------------------
    Objeto select
-----------------------------------------------------------------------*/
function JSelect(select,textoInicial,valorInicial) {
    this.select = select;
    this.textoInicial = ((textoInicial+"").length>0) ? textoInicial : "";
    this.valorInicial = ((valorInicial+"").length>0) ? valorInicial : "";
    // Funciones
    this.addValue = JSelectAddValue;
    this.ini      = JSelectIni;
    this.seleccionar = JSelectSeleccionar;
    this.clear	  = JSelectClear;
    
    this.ini();
}    

function JSelectClear()
{
	this.select.length = 0;
}

function JSelectAddValue(codigo,valor,selected) {
    selected = (selected) ? true : false;
    anadir(this.select, codigo, valor, selected);
}
    
function JSelectIni() {
    this.select.length = 0;
    if ( this.textoInicial.length > 0 ) {
        this.addValue(this.valorInicial,this.textoInicial,true);
    }
}
function JSelectSeleccionar(value) {
    seleccionar(this.select,value);
}    
    
/*------------------------------------------------------------------------
     Objeto fecha
------------------------------------------------------------------------*/
    function JInputFecha( dia, mes , ano , alias , notNull ) {
        this.dia   = dia;
        this.mes   = mes;
        this.ano   = ano;
        this.alias = alias;
        this.notNull = (notNull) ? true : false;    
    
        this.validar = JInputFechaValidar;
    }
    
    
    function JInputFechaValidar() {

        if ( this.notNull ) {
            dia         = new JInput( this.dia );
            dia.alias   = this.alias + " (día)";
            dia.notNull = true;
            dia.tipo    = "numerico";
            
            
            mes = new JInput( this.mes );
            mes.alias   = this.alias  + " (mes)" ;
            mes.notNull = true;
            mes.tipo    = "numerico" ;

            ano = new JInput( this.ano );
            ano.alias   = this.alias   + " (año)";
            ano.notNull = true;
            ano.tipo    = "numerico";           
            
            if ( !dia.validar() ) return false;
            if ( !mes.validar() ) return false;
            if ( !ano.validar() ) return false;

            if ( dia.input.value==0 || mes.input.value==0 || ano.input.value == 0 ) {
                dia.input.value = "";
                mes.input.value = "";
                ano.input.value = "";
                alert("El campo [" + this.alias + "] no puede quedar vacío");
                this.dia.focus();
                return false;
            }
        }
        
        
        
        if ( this.dia.value.length > 0 || this.mes.value.length > 0 || this.ano.value.length > 0)  {
            
            if ( !valida_fecha( this.dia.value , this.mes.value , this.ano.value )) {
                alert("El campo [" + this.alias + "] no contiene una fecha válida");
                this.dia.focus();
                return false;
            }
        }
       
        return true;
    }
    

    
/*------------------------------------------------------------------
       Objeto para obtener una fecha
-------------------------------------------------------------------*/
    function JDialogFecha( dia , mes ,ano ) {
        this.dia = dia;
        this.mes = mes;
        this.ano = ano;
        this.ruta;    
        this.width  = 210;
        this.height = 200;
        this.value = "";
        this.setFecha = JDialogFechaSetFecha;   
        this.Show     = JDialogFechaShow;
    }    
    
    function JDialogFechaSetFecha() {
        if ( !this.value ) return;
        if ( this.value.length == 0 ) return;
        
        tokens = this.value.split("-");
        if ( tokens.length != 3 ) return;
        
        dia = parseInt(tokens[0],10);
        mes = parseInt(tokens[1],10);
        ano = parseInt(tokens[2],10);
        
        this.dia.value = dia;
        this.mes.value = mes;
        this.ano.value = ano;            
    }
    
    function JDialogFechaShow() {
        valor = window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/funciones/calendar.php", "" , "dialogHeight:"+this.height+"px; dialogWidth:"+this.width+"px center:yes; edge:raised; scroll:no; status:no;"); 

        if ( valor == "undefined" ) valor = "";
        this.value = valor;
        this.setFecha();
        return valor;        
    }
    
/*-----------------------------------------------------------
    Objeto para obtener una imagen
------------------------------------------------------------*/

   function JDialogImagen(tabla,campo) {
       this.rutaImg = "";
       this.tabla  = (tabla) ? tabla : "";
       this.campo  = (campo) ? campo : "";  
       this.width  = 780;
       this.height = 580;
       this.Show   = JDialogImagenShow;
       this.TextBox  = "";
       this.Imagen = "";
       this.UpLoad = JDialogImagenUpLoad;
       
   }
   
   function JDialogImagenShow() {
       var imagen = window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/funciones/mrk_imagenes.php?tabla="+this.tabla+"&campo="+this.campo+"&current="+this.TextBox.value,  "" , "dialogHeight:"+this.height+"px; dialogWidth:"+this.width+"px center:yes; edge:raised; scroll:no; status:no;");
       
       if ( imagen ) {
           this.TextBox.value = imagen;
           this.Imagen.src = this.rutaImg+imagen;
       }
       
       return imagen;
   }
   
   function JDialogImagenUpLoad() {
       var imagen = window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/funciones/subir.php?tabla="+this.tabla+"&campo="+this.campo,  "" , "dialogHeight:180px; dialogWidth:500px center:yes; edge:raised; scroll:no; status:no;");
       if ( imagen ) {
           this.TextBox.value = imagen;
           this.Imagen.src = this.rutaImg+imagen;
       }
       return imagen;
   }
   
/*------------------------------------------------------------------
       Objeto para seleccionar un color
-------------------------------------------------------------------*/
    function JDialogColor() {
        this.Show  = JDialogColorShow;
        this.width  = 300;
        this.height = 200;

    } 
    
    function JDialogColorShow() {
      
       var res = window.showModalDialog( "http://www.mcapitaleditorial.com/acceso_admin/funciones/select_color.html",  "" , "dialogHeight:"+this.height+"px; dialogWidth:"+this.width+"px center:yes; edge:raised; scroll:no; status:no;");
       return res;
    }

/*------------------------------------------------------------------
    Objeto para controlar una imagen
-------------------------------------------------------------------*/
    function JImagen( input , TextBox , Imagen, rutaImg, tabla, campo ) {
        this.input   = input;
        this.TextBox = TextBox;
	    this.Imagen  = Imagen;
	    this.rutaImg = rutaImg;
	    this.tabla = tabla;
	    this.campo = campo;
        this.validar  = JImagenValidar;
        this.setImg   = JImagenSetImg;
        this.getImage = JImagenGetImage;
        
    }
    
    function JImagenValidar() {
        return this.input.validar();
    }
    
    function JImagenSetImg(valor) {
        this.Imagen.src = this.rutaImg + valor;
    }
    
    function JImagenGetImage(tipo) {
	
       Img = new JDialogImagen(this.tabla,this.campo);
	   Img.TextBox = this.TextBox;
	   Img.Imagen  = this.Imagen;
	   Img.rutaImg = this.rutaImg;
	   if ( tipo=="listado" ) Img.Show();
	   if ( tipo=="nueva")    Img.UpLoad();
    }
    
/**
 * Objeto Imagen de un listado
 */
    function JLstImagen(imagen) {
        this.imagen = imagen;
        
        this.imagen.style.cursor = "hand";
        this.imagen.alt = "Ver imagen";
        this.imagen.onclick = JLstVerImagen;   
    }
    
    function JLstVerImagen() {
        imagen = event.srcElement;
        pop = new JPopup(window);
        pop.url = imagen.src;
        pop.width = 300;
        pop.height = 300;
        pop.Show();
    }
    
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



/**
 * Objeto para procesar xml's 
 */
function JXML(url) {
    this.url   = url;
    
    // Metodos
    this.load            = JXMLLoad;
    this.createXmlObject = JXMLCreateXmlObject
    this.setOwner        = JXMLSetOwner;
    this.setURL          = JXMLSetURL;
    this.loadXML		 = JXMLLoadXML;
    
    // Inicialización
    this.xml             = this.createXmlObject();
       
}

function JXMLLoadXML(xmlString)
{
	var myDocument; 
  
	if (document.implementation.createDocument){ 
		// Mozilla, create a new DOMParser 
		var parser = new DOMParser(); 
		myDocument = parser.parseFromString(xmlString, "text/xml"); 
	} else if (window.ActiveXObject){ 
		// Internet Explorer, create a new XML document using ActiveX 
		// and use loadXML as a DOM parser. 
		myDocument = new ActiveXObject("Microsoft.XMLDOM") 
		myDocument.async="false"; 
		myDocument.loadXML(xmlString);   
	} 
	return myDocument.documentElement;
}

function JXMLSetURL(url) {
    this.url = url;
    
}

function JXMLSetOwner(object ) {
    this.owner = object;
    
}

/**
 * Carga el xml en forma asincrona 
 */
function JXMLLoad() {
    CurrentXML = this;
    
    // Navegador Explorer y Mozilla
    if (document.implementation && document.implementation.createDocument
        || window.ActiveXObject ) {
    		this.xml.load(this.url);
    }		

    
    	
    	
    return;
}

function JXMLCreateXmlObject() {
    // Navegador Mozilla
    if (document.implementation && document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument("http://www.dataweb-online.com/", "", null);
        xmlDoc.async = true;
        xmlDoc.onload = JXMLOnLoad;
        return xmlDoc;
    } 
    
    // Navegador explorer
    if (window.ActiveXObject ) {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = this.async;
        xmlDoc.onreadystatechange = JXMLOnReadyStateChange;
        return xmlDoc;
    }
}

function JXMLOnReadyStateChange() {

    if ( xmlDoc.readyState == 4 ) {
        CurrentXML.owner.getXML(xmlDoc.documentElement);
    }
}


function JXMLOnLoad() {
    CurrentXML.owner.getXML(this.documentElement);
}

function getXMLFrame(iframe) {
	xmlDoc = isIE? iframe.contentWindow.document.XMLDocument : iframe.contentWindow.document;
	return xmlDoc;
}


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
   
}
