var
getArchivo = function(tamano, descargar)
{
	if (descargar != true) descargar = false;
	//if (tamano == 96) descargar = false;

	var retorna;

	if (this.fondo < 0)
		retorna = '~2'+(-this.fondo)+'-';
	else
		retorna = this.fondo+'-';

	var tmp;
	tmp = String(this.texto);
	if (tmp == '||||') tmp = '';
	tmp = tmp.replace(/~/g, '~1');
	tmp = tmp.replace(/-/g, '~2');
	tmp = tmp.replace(/_/g, '~3');
	retorna += tmp;

	retorna += '-'+this.fuente;
	retorna += '-'+this.color;
	retorna += '-'+this.color_borde;
	retorna += '-'+this.color_sombra;
	retorna += '-'+this.brillo;
	retorna += '-0';	//deprecated
	retorna += this.lang;
	if (descargar === true)	retorna += '1';
	else					retorna += '0';
	if (tamano == 96)
	{
		retorna += '--';
	} else {
		retorna += '-'+this.tamano;
		retorna += '-'+this.key;
	}

	//codifico el nombre del archivo
	if (this.isChino)
		retorna = urlencode(retorna);
	else
		retorna = URLEncode2(retorna);
	retorna = retorna.replace(/%/g, '_');

	return retorna;
},

setArchivo = function(valor)
{
	//convierto y separo las variables
	valor = valor.replace(/_/g, '%');

	var g = valor;

	valor = urldecode(valor);

	g = g + valor;
	//alert(g);

	tmp = valor.split('-');

	//paso cada variable a su correspondiente atributo
	this.fondo = tmp[0].replace(/~2/g, '-');

	tmp[1] = tmp[1].replace(/~3/g, '_');
	tmp[1] = tmp[1].replace(/~2/g, '-');
	tmp[1] = tmp[1].replace(/~1/g, '~');
	this.texto = tmp[1];


	this.fuente = tmp[2];
	this.color = tmp[3];
	this.color_borde = tmp[4];
	this.color_sombra = tmp[5];
	this.brillo = tmp[6];
	//this.tamano = tmp[7].substr(0,1);
	this.lang = tmp[7].substr(1,1);
	this.tamano = tmp[8];
	this.key = tmp[9];
	if (tmp[7].substr(2,1) == '1') 	this.descargar = true;
	else							this.descargar = false;
},

setArchivoDecoded = function(valor)
{
	//convierto y separo las variables
	//valor = valor.replace(/_/g, '%');

	var g = valor;

	//valor = urldecode(valor);

	g = g + valor;
	//alert(g);

	tmp = valor.split('-');

	//paso cada variable a su correspondiente atributo
	this.fondo = tmp[0].replace(/~2/g, '-');

	tmp[1] = tmp[1].replace(/~3/g, '_');
	tmp[1] = tmp[1].replace(/~2/g, '-');
	tmp[1] = tmp[1].replace(/~1/g, '~');
	this.texto = tmp[1];

	this.fuente = tmp[2];
	this.color = tmp[3];
	this.color_borde = tmp[4];
	this.color_sombra = tmp[5];
	this.brillo = tmp[6];
	//this.tamano = tmp[7].substr(0,1);
	this.lang = tmp[7].substr(1,1);
	this.tamano = tmp[8];
	this.key = tmp[9];
	if (tmp[7].substr(2,1) == '1') 	this.descargar = true;
	else							this.descargar = false;
},

class_display = function()
{
	this.fondo = 0;
	this.texto = '';
	this.fuente = 1;
	this.color = 'fff';
	this.color_borde = '333';
	this.color_sombra = '';
	this.brillo = 0;
	this.tamano = 96;
	this.key = '';
	this.lang = 0;
	this.descargar = false;
	this.isChino = chino;	// varible fuera del script

	this.getArchivo = getArchivo;
	this.setArchivo = setArchivo;
	this.setArchivoDecoded = setArchivoDecoded;
};

// http://cass-hacks.com/articles/code/js_url_encode_decode/
function URLEncode2 (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that
// (a) you leave this copyright notice intact, and
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
// function urlencode() for this


function urlencode( str ) {

    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
	//var agrr = ret;
    ret = encodeURIComponent(ret);
	//alert(agrr+"\n"+ret);

    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });

    return ret;
}


function urldecode(texto)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var encoded = texto;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2)
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};
