	
	// JavaScript Document
	
	//
	//	funcString.js
	//	Fecha de creaci?n: 24 / 01 / 2009
	//	Descripci�n: Contiene funciones de tratamientos para strings
	//
	

	function nl2br ( str ) 
	{
	    breakTag = '<br />';

	    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
	}

	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
	    ret = encodeURIComponent(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( str ) 
	{
		var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
		var ret = str.toString();
		var search;
		
		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 urlencode.
		histogram['!']   = '%21';
		histogram['%20'] = '+';
		
		for ( replace in histogram ) 
		{
			// Switch order when decoding
			search = histogram[replace];
			
			// Custom replace. No regexing 
			ret = replacer (search, replace, ret);  
		}
		
		// End with decodeURIComponent, which most resembles PHP's encoding functions
		ret = decodeURIComponent(ret);
	
		return ret;
	}
	
	function htmlspecialchars (string, quote_style) 
	{
		var histogram = {}, symbol = '', tmp_str = '', i = 0;
		tmp_str = string.toString();
		
		if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) 
		{
			return false;
		}
		
		for ( symbol in histogram['first'] ) 
		{
			entity = histogram['first'][symbol];
			tmp_str = tmp_str.split(symbol).join(entity);
		}
		
		for ( symbol in histogram['quotes'] ) 
		{
			entity = histogram['quotes'][symbol];
			tmp_str = tmp_str.split(symbol).join(entity);
		}
		
		return tmp_str;
	}
	
	function htmlspecialchars_decode ( string , quote_style ) 
	{
		var histogram = {}, symbol = '', tmp_str = '', i = 0;
		tmp_str = string.toString();
		
		if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) 
		{
			return false;
		}
		
		for ( symbol in histogram['first'] ) 
		{
			entity = histogram['first'][symbol];
			tmp_str = tmp_str.split(entity).join(symbol);
		}
		
		for ( symbol in histogram['quotes'] ) 
		{
			entity = histogram['quotes'][symbol];
			tmp_str = tmp_str.split(entity).join(symbol);
		}
		
		return tmp_str;
	}
	
	function get_html_translation_table (table, quote_style) 
	{
		var entities = {}, histogram = {}, decimal = 0, symbol = '';
		var constMappingTable = {}, constMappingQuoteStyle = {};
		var useTable = {}, useQuoteStyle = {};
		
		useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
		useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
		
		// Translate arguments
		constMappingTable[0]      = 'HTML_SPECIALCHARS';
		constMappingTable[1]      = 'HTML_ENTITIES';
		constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
		constMappingQuoteStyle[2] = 'ENT_COMPAT';
		constMappingQuoteStyle[3] = 'ENT_QUOTES';
		
		// Map numbers to strings for compatibilty with PHP constants
		if (!isNaN(useTable)) {
			useTable = constMappingTable[useTable];
		}
		if (!isNaN(useQuoteStyle)) {
			useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
		}
		
		entities['first']	= {};
		entities['quotes']	= {};
		
		if (useTable == 'HTML_SPECIALCHARS') 
		{
			// ascii decimals for better compatibility
			entities['first']['38'] = '&amp;';
			entities['first']['60'] = '&lt;';
			entities['first']['62'] = '&gt;';
		} 
		else if (useTable == 'HTML_ENTITIES') 
		{
			// ascii decimals for better compatibility
			entities['first']['38'] = '&amp;';
			entities['first']['60'] = '&lt;';
			entities['first']['62'] = '&gt;';
			entities['first']['160'] = '&nbsp;';
			entities['first']['161'] = '&iexcl;';
			entities['first']['162'] = '&cent;';
			entities['first']['163'] = '&pound;';
			entities['first']['164'] = '&curren;';
			entities['first']['165'] = '&yen;';
			entities['first']['166'] = '&brvbar;';
			entities['first']['167'] = '&sect;';
			entities['first']['168'] = '&uml;';
			entities['first']['169'] = '&copy;';
			entities['first']['170'] = '&ordf;';
			entities['first']['171'] = '&laquo;';
			entities['first']['172'] = '&not;';
			entities['first']['173'] = '&shy;';
			entities['first']['174'] = '&reg;';
			entities['first']['175'] = '&macr;';
			entities['first']['176'] = '&deg;';
			entities['first']['177'] = '&plusmn;';
			entities['first']['178'] = '&sup2;';
			entities['first']['179'] = '&sup3;';
			entities['first']['180'] = '&acute;';
			entities['first']['181'] = '&micro;';
			entities['first']['182'] = '&para;';
			entities['first']['183'] = '&middot;';
			entities['first']['184'] = '&cedil;';
			entities['first']['185'] = '&sup1;';
			entities['first']['186'] = '&ordm;';
			entities['first']['187'] = '&raquo;';
			entities['first']['188'] = '&frac14;';
			entities['first']['189'] = '&frac12;';
			entities['first']['190'] = '&frac34;';
			entities['first']['191'] = '&iquest;';
			entities['first']['192'] = '&Agrave;';
			entities['first']['193'] = '&Aacute;';
			entities['first']['194'] = '&Acirc;';
			entities['first']['195'] = '&Atilde;';
			entities['first']['196'] = '&Auml;';
			entities['first']['197'] = '&Aring;';
			entities['first']['198'] = '&AElig;';
			entities['first']['199'] = '&Ccedil;';
			entities['first']['200'] = '&Egrave;';
			entities['first']['201'] = '&Eacute;';
			entities['first']['202'] = '&Ecirc;';
			entities['first']['203'] = '&Euml;';
			entities['first']['204'] = '&Igrave;';
			entities['first']['205'] = '&Iacute;';
			entities['first']['206'] = '&Icirc;';
			entities['first']['207'] = '&Iuml;';
			entities['first']['208'] = '&ETH;';
			entities['first']['209'] = '&Ntilde;';
			entities['first']['210'] = '&Ograve;';
			entities['first']['211'] = '&Oacute;';
			entities['first']['212'] = '&Ocirc;';
			entities['first']['213'] = '&Otilde;';
			entities['first']['214'] = '&Ouml;';
			entities['first']['215'] = '&times;';
			entities['first']['216'] = '&Oslash;';
			entities['first']['217'] = '&Ugrave;';
			entities['first']['218'] = '&Uacute;';
			entities['first']['219'] = '&Ucirc;';
			entities['first']['220'] = '&Uuml;';
			entities['first']['221'] = '&Yacute;';
			entities['first']['222'] = '&THORN;';
			entities['first']['223'] = '&szlig;';
			entities['first']['224'] = '&agrave;';
			entities['first']['225'] = '&aacute;';
			entities['first']['226'] = '&acirc;';
			entities['first']['227'] = '&atilde;';
			entities['first']['228'] = '&auml;';
			entities['first']['229'] = '&aring;';
			entities['first']['230'] = '&aelig;';
			entities['first']['231'] = '&ccedil;';
			entities['first']['232'] = '&egrave;';
			entities['first']['233'] = '&eacute;';
			entities['first']['234'] = '&ecirc;';
			entities['first']['235'] = '&euml;';
			entities['first']['236'] = '&igrave;';
			entities['first']['237'] = '&iacute;';
			entities['first']['238'] = '&icirc;';
			entities['first']['239'] = '&iuml;';
			entities['first']['240'] = '&eth;';
			entities['first']['241'] = '&ntilde;';
			entities['first']['242'] = '&ograve;';
			entities['first']['243'] = '&oacute;';
			entities['first']['244'] = '&ocirc;';
			entities['first']['245'] = '&otilde;';
			entities['first']['246'] = '&ouml;';
			entities['first']['247'] = '&divide;';
			entities['first']['248'] = '&oslash;';
			entities['first']['249'] = '&ugrave;';
			entities['first']['250'] = '&uacute;';
			entities['first']['251'] = '&ucirc;';
			entities['first']['252'] = '&uuml;';
			entities['first']['253'] = '&yacute;';
			entities['first']['254'] = '&thorn;';
			entities['first']['255'] = '&yuml;';
		} 
		else 
		{
			throw Error("Table: "+useTable+' not supported');
			return false;
		}
		
		if (useQuoteStyle != 'ENT_NOQUOTES') 
		{
			entities['quotes']['34'] = '&quot;';
		}
		
		if (useQuoteStyle == 'ENT_QUOTES') 
		{
			entities['quotes']['39'] = '&#039;';
		}
		
		histogram['first']	= {};
		histogram['quotes']	= {};
		
		// ascii decimals to real symbols
		for (decimal in entities['first']) 
		{
			symbol = String.fromCharCode(decimal)
			histogram['first'][symbol] = entities['first'][decimal];
		}
		
		for (decimal in entities['quotes']) 
		{
			symbol = String.fromCharCode(decimal)
			histogram['quotes'][symbol] = entities['quotes'][decimal];
		}
		
		return histogram;
	}
