-- Generation Time: Jun 12, 2007
-- Last update: Oct 16, 2007
-- Database: `flib`
--
-- BY JULIO RAFFO (EPFL/CEMI)
--
-- --------------------------------------------------------

DELIMITER $$

DROP FUNCTION IF EXISTS flib.decorrupt $$
CREATE FUNCTION flib.decorrupt(dirtystring VARCHAR(500)) RETURNS VARchar(500) charset utf8
BEGIN

	DECLARE tempstring varchar(500);

set tempstring=dirtystring;

set tempstring=replace(tempstring,'Ç','"');
set tempstring=replace(tempstring,'ì','°');
set tempstring=replace(tempstring,'º','°');
set tempstring=replace(tempstring,'Ã','Á');
set tempstring=replace(tempstring,'á','á');
set tempstring=replace(tempstring,'à','à');
set tempstring=replace(tempstring,'â','â');
set tempstring=replace(tempstring,'Ä','Ä');
set tempstring=replace(tempstring,'«','Ä');
set tempstring=replace(tempstring,'ä','ä');
set tempstring=replace(tempstring,'ã','ã');
set tempstring=replace(tempstring,'å','å');
set tempstring=replace(tempstring,'Õ','å');
set tempstring=replace(tempstring,'Å','Å');
set tempstring=replace(tempstring,'æ','æ');
set tempstring=replace(tempstring,'µ','æ');
set tempstring=replace(tempstring,'×','Ç');
set tempstring=replace(tempstring,'ç','ç');
set tempstring=replace(tempstring,'?','É');
set tempstring=replace(tempstring,'ñ','É');
set tempstring=replace(tempstring,'é','é');
set tempstring=replace(tempstring,'è','è');
set tempstring=replace(tempstring,'ê','ê');
set tempstring=replace(tempstring,'Ë','Ë');
set tempstring=replace(tempstring,'ë','ë');
set tempstring=replace(tempstring,'¢','ë');
set tempstring=replace(tempstring,'í','í');
set tempstring=replace(tempstring,'î','î');
set tempstring=replace(tempstring,'ï','ï');
set tempstring=replace(tempstring,'¾','ó');
set tempstring=replace(tempstring,'ó','ó');
set tempstring=replace(tempstring,'ò','ò');
set tempstring=replace(tempstring,'ô','ô');
set tempstring=replace(tempstring,'Ã','Ö');
set tempstring=replace(tempstring,'Ö','Ö');
set tempstring=replace(tempstring,'ö','ö');
set tempstring=replace(tempstring,'÷','ö');
set tempstring=replace(tempstring,'Ô','Õ');
set tempstring=replace(tempstring,'ø','ø');
set tempstring=replace(tempstring,'Ø','Ø');
set tempstring=replace(tempstring,'Ó','Ø');
set tempstring=replace(tempstring,'ß','ß');
set tempstring=replace(tempstring,'·','ú');
set tempstring=replace(tempstring,'ú','ú');
set tempstring=replace(tempstring,'û','û');
set tempstring=replace(tempstring,'¨','Ü');
set tempstring=replace(tempstring,'©','Ü');
set tempstring=replace(tempstring,'ü','ü');
set tempstring=replace(tempstring,'³','ü');
set tempstring=replace(tempstring,'Ü','Ü');
set tempstring=replace(tempstring,'ÿ','ÿ');
set tempstring=replace(tempstring,',¹',' ');
set tempstring=replace(tempstring,',¹',' ');
set tempstring=replace(tempstring,'­','È');
set tempstring=replace(tempstring,'Ã','');
set tempstring=replace(tempstring,' ','');
set tempstring=replace(tempstring,'¿','');
set tempstring=replace(tempstring,'Ñ','Ñ');
set tempstring=replace(tempstring,'Â','Â');
set tempstring=replace(tempstring,'±','');
set tempstring=replace(tempstring,'¤','');
set tempstring=replace(tempstring,'§','/');
set tempstring=replace(tempstring,'¬','');
set tempstring=replace(tempstring,'ð','');
set tempstring=replace(tempstring,'õ','õ ');
set tempstring=replace(tempstring,'É','');
set tempstring=replace(tempstring,'¼','');
set tempstring=replace(tempstring,'½','Ã');
set tempstring=replace(tempstring,'ý','.');
set tempstring=replace(tempstring,'¹',' ');
set tempstring=replace(tempstring,'Þ','');
set tempstring=replace(tempstring,'Ã','o');
set tempstring=replace(tempstring,'´','');
set tempstring=replace(tempstring,'®','o');
set tempstring=replace(tempstring,'°','o');
set tempstring=replace(tempstring,'ù','');
set tempstring=replace(tempstring,'²','O');
set tempstring=replace(tempstring,'Ú','e');

RETURN tempstring;

END


 $$

DELIMITER ;