

$().ajaxSend(function(a,v){
	//$('#loadingAjax').html('Esperando respuesta...<br>Espere por favor.');
	$.fn.modal({cover:false, timer:0, tipo:'loading', contenido:'Esperando respuesta, aguarde.', claseCss:'infomsg'});
	//loadingAjax();
});

$().ajaxStop(function(a,v){
	//$('#loadingAjax').slideUp();
	$.fn.modalKillLoader();
});
/**
* Funcion que retorna un objeto html seleccionado por su ID
* @param id string
*/
function gId(id){
	if(typeof(id)=='string') {
		if(document.getElementById) id=document.getElementById(id);
		else if(document.all) id=document.all[id];
		else id=null;
	}
	return id;
}
function gvId(id){
	return gId(id).value;
}

function mostrar(id){
	gId(id).style.display='block';
}

function ocultar(id){
	gId(id).style.display='none';
}

function mostrarOcultar(id){
	var elem = gId(id).style;
	if (elem.display == 'none')
		elem.display = 'block';
	else
		elem.display = 'none';
}























		function uploadButton(id){
//alert('cargo upload a: '+id);
			$(id).upload({
				name: 'file',
				method: 'post',
				enctype: 'multipart/form-data',
				action: '?mod=Contenido&ac=upload&a='+Math.random()+'&',
				onSubmit: function() {
					$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/loading_icon.gif" border="0" align="absmiddle"> Carga en progreso...');
					$('#progress1').attr('class','infomsg');
				},
				onComplete: function(data) {
					//data contains the response from the action url
					//alert(data)
					if (data == -1 || data == ''){
						$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> Error de carga. Intente nuevamente.[3 0]');
						$('#progress1').attr('class','errormsg');
						throw new Error('Error de carga de archivos.');
	
					}else if (data == '0'){
						$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> Error de carga. Intente nuevamente.[301]');
						$('#progress1').attr('class','errormsg');
						throw new Error('Error de carga de archivos.');
					}
	
					else{
						if(guacamaya(data, '', '')){
							$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/thumb_up.gif" border="0" align="absmiddle"> Archivo cargado correctamente.');
							$('#progress1').attr('class','confirmmsg');
						}
					}
				}
			});
		}



		function addImage(src, id, clase, alt ){
			var newImg = document.createElement("img");
			newImg.setAttribute("alt", alt);
			newImg.setAttribute("class", clase);
			newImg.setAttribute("id", id);

			$("#cont-thumb-"+id ).prepend(newImg);

			newImg.style.margin = "15px";
			newImg.style.position = "absolute";

			newImg.onload = function () {
				fadeIn(newImg, 0);
			};
			newImg.src = src;
		}

		function addInput(id, clase, alt){
			//borrarrrr
		}

		function addItem(src, id, clase, alt ) {
			addImage(src, id, clase, alt );

			return;
		}

		function fadeIn(element, opacity) {
			var reduceOpacityBy = 5;
			var rate = 30;	// 15 fps


			if (opacity < 100) {
				opacity += reduceOpacityBy;
				if (opacity > 100) {
					opacity = 100;
				}

				if (element.filters) {
					try {
						element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
					} catch (e) {
						// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
						element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
					}
				} else {
					element.style.opacity = opacity / 100;
				}
			}

			if (opacity < 100) {
				setTimeout(function () {
					fadeIn(element, opacity);
				}, rate);
			}
		}



		function buttonOnClick(editorId, url, extension, fid) {
				$("#thumb-"+fid).css({display:'block'});
				var ed = tinyMCE.get(editorId);
				//var s = ed.controlManager.get(editorId + "_" + btn).settings;

				var clase = '';
				var h = '';
				var w = '';
				var comando='mceInsertContent';
				switch (extension){
					case 'pdf': case 'html': case 'doc': case 'rar': case 'zip': case 'xls': case 'xml': case 'rtf': case 'ppt': case 'psd': case 'txt': case 'tar': case 'gz': case 'deb': case 'bz':
						comando='mceInsertContent';//mceInsertRawHTML';
						objetoRaw = '<a href="'+url+'">'+url+'</a>';

					break;
					case 'jpeg': case 'jpg': case 'png': case 'gif':
						comando='mceInsertContent';//mceInsertRawHTML';
						objetoRaw = '<img src="'+url+'">';

					break;

					case 'swf': case 'flv':
						comando='mceInsertContent';
						clase = 'mceItemFlash';
						h='200';
						w='200';
						objetoRaw = '<img src="http://www.imagenesencostarica.com/js/tiny_mce/plugins/media/img/trans.gif" mce_src="jscripts/tiny_mce/plugins/media/img/trans.gif" class="'+clase+'" title="src:\''+url+'\',width:\''+w+'\',height:\''+h+'\'" align="" height="'+h+'" width="'+w+'">';
					break;

					case 'mov': case 'mpeg': case 'mpg': case 'mpeg': case 'mp4': case 'mp3': case 'ogg': case 'avi':
						comando='mceInsertContent';
						clase = 'mceItemQuickTime';
						h='280';
						w='321';
						objetoRaw = '<img src="http://www.imagenesencostarica.com/js/tiny_mce/plugins/media/img/trans.gif" mce_src="jscripts/tiny_mce/plugins/media/img/trans.gif" class="'+clase+'" title="src:\''+url+'\',width:\''+w+'\',height:\''+h+'\'" align="" height="'+h+'" width="'+w+'">';
					case 'wmv': case 'wma':
						comando='mceInsertContent';
						clase = 'mceItemWindowsMedia';
						h='280';
						w='321';
						objetoRaw = '<img src="http://www.imagenesencostarica.com/js/tiny_mce/plugins/media/img/trans.gif" mce_src="jscripts/tiny_mce/plugins/media/img/trans.gif" class="'+clase+'" title="src:\''+url+'\',width:\''+w+'\',height:\''+h+'\'" align="" height="'+h+'" width="'+w+'">';
				}
//alert(comando+' '+false+' '+objetoRaw);
				ed.execCommand(comando, false, objetoRaw);
		}


		function guacamaya(file, caption, star) {
			var caption = caption=='undefined'?'':caption;
			var star = star=='1'?'1':'0';
			var alt;
			var id;
			var nombreArchivo = file;
			var extension = nombreArchivo.substr(nombreArchivo.lastIndexOf('.')+1, nombreArchivo.length).toLowerCase();;
			var randomS = ''+Math.random();
			var fid = randomS.substr(2, randomS.length);
			var clase = 'icono';
			var thumb = '<img src="http://www.imagenesencostarica.com/img/iconos/filetypes/undefined.png" >';

			// medios permitidos
			var perm = 'gif|avi|jpg|jpeg|png|doc|odt|html|pdf|swf|flv|mpg|mov|mpeg|psd|mp3|wav|wma|wmv|xls|xml|ogg|ppt|txt|tiff|rar|zip';
			// medios de imagen
			var preview = 'jpg|jpeg|png|gif';
			// medios reproducibles
			var media = 'avi|mov|swf|wmv|wma|wav|flv|mpg|mpeg|ogg|mp3';
			// medios enlazables
			var links = 'html|xls|xml|rar|zip|html|pdf|psd|ppt|txt|doc';

			if(perm.lastIndexOf(extension) > -1){
				thumb = 'http://www.imagenesencostarica.com/img/iconos/filetypes/'+extension+'.png';//'<img src="iconos/filetypes/'+extension+'.png" class="'+clase+'" id="thumb-'+file.id+'" alt="'+file+'">';
				id = 'thumb-'+fid;
				alt = nombreArchivo;
			}
			else{
				$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> Tipo de archivo no v&aacute;lido.');
				$('#progress1').attr('class','errormsg');
				return false;
			}

			if(preview.lastIndexOf(extension) > -1){
				//thumb = 'http://www.imagenesencostarica.com/img/iconos/filetypes/'+extension+'.png';
				thumb = 'http://www.imagenesencostarica.com/download/thumbnail.php?i='+nombreArchivo;
				id = 'thumb-'+fid;
				alt = nombreArchivo;

			}
			else if(media.lastIndexOf(extension) > -1){
				thumb = 'http://www.imagenesencostarica.com/img/iconos/filetypes/'+extension+'.png';
				id = 'thumb-'+fid;
				alt = nombreArchivo;

			}
			else if(links.lastIndexOf(extension) > -1){
				thumb = 'http://www.imagenesencostarica.com/img/iconos/filetypes/'+extension+'.png';
				id = 'thumb-'+fid;
				alt = nombreArchivo;

			}
			
			$("#galeria #galeria-items").prepend("\n"+'<li class="item" id="cont-'+id+'">\
					<div class="botonera2 botonera-'+fid+'">\n\
						<img src="http://www.imagenesencostarica.com/img/iconos/textfield.gif" alt="'+alt+'" class="botones caption-'+fid+'" title="Ver Ep&iacute;grafe" />\n\
					</div>\n\
					<div class="botonera botonera-'+fid+'">\n\
						<img src="http://www.imagenesencostarica.com/img/iconos/add.gif" alt="'+alt+'" title="Agregar al Cuerpo" class="botones add-'+fid+'" >&nbsp;\n\
						<a href="'+alt+'" title="'+alt+'" target="_blank" class="zoom-'+fid+'">\n\
							<img src="http://www.imagenesencostarica.com/img/iconos/zoom.gif" class="botones" title="Ver el archivo">\n\
						</a>&nbsp;\n\
						<img src="http://www.imagenesencostarica.com/img/iconos/cancel.gif" class="botones del-'+fid+'" title="Borrar Archivo"><br>\n\
						<img src="http://www.imagenesencostarica.com/img/iconos//star'+(star=='0'?'_off':'')+'_48.png" alt="'+star+'" class="botones48 star-'+fid+'" title="Destacar archivo">\n\
						<input type="hidden" name="archivoStar[]" class="F_" id="starInput-'+fid+'" value="'+star+'">\n\
						<input type="hidden" name="archivoAlta[]" class="F_" id="archivoAlta-'+fid+'" value="'+alt+'">\n\
					</div>\n\
					<div id="inputCaption-'+fid+'" class="warningmsg ac-div">\n\
						<input type="text" id="ac-'+fid+'" class="ac-input F_" name="archivoCaption[]" value="'+caption+'">\n\
					</div>\n\
					</li>\n');


			addItem(thumb, fid, clase, alt);

			$("#cont-"+id).hover(
				function(){
					$(".botonera-"+fid).fadeIn(100);
				},
				function(){

					if($('#inputCaption-'+fid).css('display')=='none'){
						$(".botonera-"+fid).fadeOut(100);
					}
				}
			);
/*
				if(preview.lastIndexOf(extension) > -1){
					$('.zoom-'+fid).lightBox({fixedNavigation:true});
				}
*/
			
			$(".add-"+fid).click(function(){
//alert(".add-"+fid +'  '+$(".add-"+fid).attr('alt'));
			buttonOnClick('CONTENIDO', $(".add-"+fid).attr('alt'), extension, fid);
			});


			$(".caption-"+fid).toggle(

				function(){
					$('#inputCaption-'+fid).fadeIn(5);
					$('#inputCaption-'+fid).focus();
					$(this).attr('src','http://www.imagenesencostarica.com/img/iconos/accept.gif');
				}
				,
				function(){
					$('#inputCaption-'+fid).fadeOut(5);
					$(this).attr('src','http://www.imagenesencostarica.com/img/iconos//textfield.gif');

//						$('#archivoCaption-'+fid).attr('value',$('#ac-'+fid).attr('value'));
					//$('#archivoCaption-'+fid).val($('#ac-'+fid).val());
					//alert($('#ac-'+fid).val());
				}
			);

			$(".star-"+fid).click(
				function(){
					if($('#starInput-'+fid).val()=='0'){
						$('.star-'+fid).attr('src','http://www.imagenesencostarica.com/img/iconos//star_48.png');
						$('#starInput-'+fid).val('1');
					}else{
						$('.star-'+fid).attr('src','http://www.imagenesencostarica.com/img/iconos//star_off_48.png');
						$('#starInput-'+fid).val('0');
					}
				}

			);

			$(".del-"+fid).click(function(){
				$.ajax({
					url: "?mod=Contenido&ac=upload&",
					data: "borrar="+alt,
					cache: false,
					success: function(html){
						if(html == '1'){
							$('#archivosBaja').append('<input type="hidden" name="archivoBaja[]" value="'+alt+'">');
							$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/accept.gif" border="0" align="absmiddle"> Ha eliminado un archivo.');
							$('#progress1').attr('class','confirmmsg');
							$("#cont-"+id).fadeOut(100, function(){ $(this).remove();});
						}
						else if(html == '-2'){
							$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> El archivo no pudo eliminarse.');
							$('#progress1').attr('class', 'errormsg');
							if (confirma('El archivo no pudo borrarse.<br>Desea forzar el borrado del archivo?')){
								$("#cont-"+id).fadeOut(100, function(){ $(this).remove();});
								$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/accept.gif" border="0" align="absmiddle"> Ha eliminado un archivo.');
								$('#progress1').attr('class','confirmmsg');
							}
						}
						else if(html == '-1'){
							$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> El archivo no pudo eliminarse.');
							$('#progress1').attr('class', 'errormsg');
							if (confirma('El archivo no se encontr&oacute;.<br>Desea forzar el borrado del archivo?')){
								$("#cont-"+id).fadeOut(100, function(){ $(this).remove();});
								$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/accept.gif" border="0" align="absmiddle"> Ha eliminado un archivo.');
								$('#progress1').attr('class','confirmmsg');
							}
						} else {
							$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/error.gif" border="0" align="absmiddle"> El archivo no pudo eliminarse.');
							$('#progress1').attr('class', 'errormsg');

// 								$('#archivosBaja').append('<input type="hidden" name="archivoBaja[]" value="'+alt+'">');
// 								$('#progress1').html('<img src="http://www.imagenesencostarica.com/img/iconos/accept.gif" border="0" align="absmiddle"> Ha eliminado un archivo.');
// 								$('#progress1').attr('class','confirmmsg');
// 								$("#cont-"+id).fadeOut(100, function(){ $(this).remove();});
						}
					}
				})
			});
			return true;
		}






function initTinyMce(ide){
	tinyMCE.execCommand('mceAddFrameControl',false,{
		element_id:ide,
		window:window,
		other_init_option:'xyz',
		theme : 'advanced',
		plugins : "safari,pagebreak,style,layer,save,advhr,advimage,advlink,inlinepopups,media,contextmenu,paste,nonbreaking,xhtmlxtras",
		// Theme options
		theme_advanced_buttons1 : "save,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,undo,redo,|,link,unlink,anchor,image,code,forecolor,backcolor,hr,sub,sup,charmap,media,nonbreaking",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});

}
















/**
* Funcion para enviar alertas con acentos
* @param str string
*/
function alerta(str){
	alert (acentos(str));
}

/**
* Funcion para enviar alertas con acentos
* @param str string
*/
function confirma(str){
	return confirm(acentos(str));
}


/**
 Funcion popUp()
@param url
@param nombreVentana
@param width
@param height
*/
function popUp(url, nombreVentana, width_, height_){
	if (!width_) width_ = 700;
	if (!height_) height_ = 500;
	if (!nombreVentana) nombreVentana = "unique"+Math.random();
	
	window.open(url, nombreVentana, "menubar=0, resizable=1, width="+ width_ +", height="+ height_ +", location = 0, scrollbars=0, status=1");
}


/** 
* Function borrarNodoPorObjeto()
* @param: objeto a eliminar
* @descr: sube un nivel en el DOM para borrar el objeto enviado
* 
*/
function borrarNodoPorObjeto(objeto){
	objeto.parentNode.removeChild(objeto);
}

function getInputsByClass(classForm){
	var parametrosBusqueda = '';
	for(i=0; i < $(classForm).length; i++){
		campo = $(classForm)[i];
		if($(classForm)[i].type =='checkbox' && !$(classForm)[i].checked==true)continue
		if(campo.type =='textarea'){
			
			parametrosBusqueda = parametrosBusqueda+"&"+$(classForm)[i].name+"="+$(classForm)[i].innerHTML;
			continue;
		}
			
		
		parametrosBusqueda = parametrosBusqueda+"&"+$(classForm)[i].name+"="+$(classForm)[i].value;
	}
	//alert(parametrosBusqueda);
	return parametrosBusqueda;
}

function avisar(){
	$('#aviso').slideDown();
	setTimeout("$('#aviso').slideUp()",3500);
}

function loadingAjax(){
	$('#loadingAjax').slideDown();
}
								
function URLEncode (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;
}

//# Function: Acentos => Convierte acentos y entidades html (ASCII/ANSI) por los hexadecimales correctos
function acentos(x) {
	x = x.replace(/�/g,"\xA1");	x = x.replace(/&iexcl;/g,"\xA1")
//	x = x.replace(/�/g,"\xBF");	x = x.replace(/&iquest;/g,"\xBF")
	x = x.replace(/�/g,"\xC0");	x = x.replace(/&Agrave;/g,"\xC0")
	x = x.replace(/�/g,"\xE0");	x = x.replace(/&agrave;/g,"\xE0")
	x = x.replace(/�/g,"\xC1");	x = x.replace(/&Aacute;/g,"\xC1")
	x = x.replace(/�/g,"\xE1");	x = x.replace(/&aacute;/g,"\xE1")
	x = x.replace(/�/g,"\xC2");	x = x.replace(/&Acirc;/g,"\xC2")
	x = x.replace(/�/g,"\xE2");	x = x.replace(/&acirc;/g,"\xE2")
	x = x.replace(/�/g,"\xC3");	x = x.replace(/&Atilde;/g,"\xC3")
	x = x.replace(/�/g,"\xE3");	x = x.replace(/&atilde;/g,"\xE3")
	x = x.replace(/�/g,"\xC4");	x = x.replace(/&Auml;/g,"\xC4")
	x = x.replace(/�/g,"\xE4");	x = x.replace(/&auml;/g,"\xE4")
	x = x.replace(/�/g,"\xC5");	x = x.replace(/&Aring;/g,"\xC5")
	x = x.replace(/�/g,"\xE5");	x = x.replace(/&aring;/g,"\xE5")
	x = x.replace(/�/g,"\xC6");	x = x.replace(/&AElig;/g,"\xC6")
	x = x.replace(/�/g,"\xE6");	x = x.replace(/&aelig;/g,"\xE6")
	x = x.replace(/�/g,"\xC7");	x = x.replace(/&Ccedil;/g,"\xC7")
	x = x.replace(/�/g,"\xE7");	x = x.replace(/&ccedil;/g,"\xE7")
	x = x.replace(/�/g,"\xC8");	x = x.replace(/&Egrave;/g,"\xC8")
	x = x.replace(/�/g,"\xE8");	x = x.replace(/&egrave;/g,"\xE8")
	x = x.replace(/�/g,"\xC9");	x = x.replace(/&Eacute;/g,"\xC9")
	x = x.replace(/�/g,"\xE9");	x = x.replace(/&eacute;/g,"\xE9")
	x = x.replace(/�/g,"\xCA");	x = x.replace(/&Ecirc;/g,"\xCA")
	x = x.replace(/�/g,"\xEA");	x = x.replace(/&ecirc;/g,"\xEA")
	x = x.replace(/�/g,"\xCB");	x = x.replace(/&Euml;/g,"\xCB")
	x = x.replace(/�/g,"\xEB");	x = x.replace(/&euml;/g,"\xEB")
	x = x.replace(/�/g,"\xCC");	x = x.replace(/&Igrave;/g,"\xCC")
	x = x.replace(/�/g,"\xEC");	x = x.replace(/&igrave;/g,"\xEC")
	x = x.replace(/�/g,"\xCD");	x = x.replace(/&Iacute;/g,"\xCD")
	x = x.replace(/�/g,"\xED");	x = x.replace(/&iacute;/g,"\xED")
	x = x.replace(/�/g,"\xCE");	x = x.replace(/&Icirc;/g,"\xCE")
	x = x.replace(/�/g,"\xEE");	x = x.replace(/&icirc;/g,"\xEE")
	x = x.replace(/�/g,"\xCF");	x = x.replace(/&Iuml;/g,"\xCF")
	x = x.replace(/�/g,"\xEF");	x = x.replace(/&iuml;/g,"\xEF")
	x = x.replace(/�/g,"\xD1");	x = x.replace(/&Ntilde;/g,"\xD1")
	x = x.replace(/�/g,"\xF1");	x = x.replace(/&ntilde;/g,"\xF1")
	x = x.replace(/�/g,"\xD2");	x = x.replace(/&Ograve;/g,"\xD2")
	x = x.replace(/�/g,"\xF2");	x = x.replace(/&ograve;/g,"\xF2")
	x = x.replace(/�/g,"\xD3");	x = x.replace(/&Oacute;/g,"\xD3")
	x = x.replace(/�/g,"\xF3");	x = x.replace(/&oacute;/g,"\xF3")
	x = x.replace(/�/g,"\xD4");	x = x.replace(/&Ocirc;/g,"\xD4")
	x = x.replace(/�/g,"\xF4");	x = x.replace(/&ocirc;/g,"\xF4")
	x = x.replace(/�/g,"\xD5");	x = x.replace(/&Otilde;/g,"\xD5")
	x = x.replace(/�/g,"\xF5");	x = x.replace(/&otilde;/g,"\xF5")
	x = x.replace(/�/g,"\xD6");	x = x.replace(/&Ouml;/g,"\xD6")
	x = x.replace(/�/g,"\xF6");	x = x.replace(/&ouml;/g,"\xF6")
	x = x.replace(/�/g,"\xD8");	x = x.replace(/&Oslash;/g,"\xD8")
	x = x.replace(/�/g,"\xF8");	x = x.replace(/&oslash;/g,"\xF8")
	x = x.replace(/�/g,"\xD9");	x = x.replace(/&Ugrave;/g,"\xD9")
	x = x.replace(/�/g,"\xF9");	x = x.replace(/&ugrave;/g,"\xF9")
	x = x.replace(/�/g,"\xDA");	x = x.replace(/&Uacute;/g,"\xDA")
	x = x.replace(/�/g,"\xFA");	x = x.replace(/&uacute;/g,"\xFA")
	x = x.replace(/�/g,"\xDB");	x = x.replace(/&Ucirc;/g,"\xDB")
	x = x.replace(/�/g,"\xFB");	x = x.replace(/&ucirc;/g,"\xFB")
	x = x.replace(/�/g,"\xDC");	x = x.replace(/&Uuml;/g,"\xDC")
	x = x.replace(/�/g,"\xFC");	x = x.replace(/&uuml;/g,"\xFC")
	
	x = x.replace(/<br>/g,"\n")
	x = x.replace(/<BR>/g,"\n")
	
	x = x.replace(/\"/g,"\x22")
	x = x.replace(/\'/g,"\x27")
	x = x.replace(/\</g,"\x3C")
	x = x.replace(/\>/g,"\x3E")
	x = x.replace(/\[/g,"\x5B")
	x = x.replace(/\]/g,"\x5D")

	x = x.replace(/�/g,"\xA2");	x = x.replace(/&cent;/g,"\xA2") 
	x = x.replace(/�/g,"\xA3");	x = x.replace(/&pound;/g,"\xA3")
	//x = x.replace(/?/g,"\u20AC");	x = x.replace(/&euro;/g,"\u20AC") 
	x = x.replace(/�/g,"\xA9");	x = x.replace(/&copy;/g,"\xA9") 
	x = x.replace(/�/g,"\xAE");	x = x.replace(/&reg;/g,"\xAE") 
	x = x.replace(/�/g,"\xAA");	x = x.replace(/&ordf;/g,"\xAA") 
	x = x.replace(/�/g,"\xBA");	x = x.replace(/&ordm;/g,"\xBA") 
	x = x.replace(/�/g,"\xB0");	x = x.replace(/&deg;/g,"\xB0") 
	x = x.replace(/�/g,"\xB1");	x = x.replace(/&plusmn;/g,"\xB1")
	x = x.replace(/�/g,"\xD7");	x = x.replace(/&times;/g,"\xD7") 

	return x
}
