Index: /trunk/services/class.ldap.php
===================================================================
--- /trunk/services/class.ldap.php	(revision 4445)
+++ /trunk/services/class.ldap.php	(revision 4828)
@@ -3,5 +3,5 @@
 class LdapService
 {
-    var $limit = 10;
+    var $limit = 11;
 
     var $allTargetTypes = array( 'i', 'g', 'l', 'u', 's' );
Index: /trunk/preferences/preferences.php
===================================================================
--- /trunk/preferences/preferences.php	(revision 3018)
+++ /trunk/preferences/preferences.php	(revision 4828)
@@ -22,5 +22,5 @@
 	if ($_POST['cancel'])
 	{
-		$GLOBALS['phpgw']->redirect_link('/preferences/index.php');
+	    $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
 	}
 	
@@ -29,8 +29,17 @@
 	$default = get_var('default',Array('POST'));
 
+        if(!@is_object($GLOBALS['phpgw']->js))
+        {
+                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
+        }
+        $GLOBALS['phpgw']->js->validate_file('jscode','validate','preferences');
+       
 	$t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
 	$t->set_file(array(
 		'preferences' => 'preferences.tpl'
 	));
+
+
+
 	$t->set_block('preferences','list','lists');
 	$t->set_block('preferences','row','rowhandle');
@@ -43,4 +52,6 @@
 		$GLOBALS['phpgw']->translation->add_app('preferences');	// we need the prefs translations too
 	}
+	
+	$GLOBALS['phpgw']->preferences->default['expressoMail']['show_name_print_messages'] = "0";
 
 	/* Make things a little easier to follow */
@@ -205,5 +216,5 @@
 	{
 		global $t,$prefs;
-        $t->set_var('row_id', "${GLOBALS[type]}[$name]");
+                $t->set_var('row_id', "${GLOBALS[type]}[$name]");
 		$t->set_var('row_value',$code.$prefs[$name].$appendcode);
 		$t->set_var('row_name',lang("signature"));
@@ -240,4 +251,5 @@
 		}
 		$s .= create_option_string($default,$values);
+		
 		if ($GLOBALS['type'] == 'user')
 		{
@@ -346,5 +358,4 @@
 	{
 		$_appname = check_app();
-
 		$prefs = &$repository[$_appname];
 
@@ -487,5 +498,5 @@
 		if (!is_admin() || $error)
 		{
-			$GLOBALS['phpgw']->redirect_link('/'.$_GET['appname'].'/'); 
+ 			$GLOBALS['phpgw']->redirect_link('/'.$_GET['appname'].'/');
 		}
 		
@@ -513,5 +524,9 @@
 	$t->set_var('messages',$error);
 	$t->set_var('action_url',$GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $_GET['appname']));
-	$t->set_var('th_bg',  $GLOBALS['phpgw_info']['theme']['th_bg']);
+
+        if($_GET['appname'] == 'expressoMail1_2')
+            $t->set_var('validateForm','onSubmit="return validateSignature();"');
+
+        $t->set_var('th_bg',  $GLOBALS['phpgw_info']['theme']['th_bg']);
 	$t->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']);
 	$t->set_var('row_on', $GLOBALS['phpgw_info']['theme']['row_on']);
Index: /trunk/preferences/templates/default/preferences.tpl
===================================================================
--- /trunk/preferences/templates/default/preferences.tpl	(revision 1405)
+++ /trunk/preferences/templates/default/preferences.tpl	(revision 4828)
@@ -1,5 +1,5 @@
 <center><b>{messages}</b></center>
 <!-- BEGIN form -->
-<form method="POST" action="{action_url}">
+<form method="POST" action="{action_url}" {validateForm}>
 <table width="75%" cellpadding=0 cellspacing=0  class="prefTable"> 
 <tr><td colspan="3">{tabs}</td></tr>  
Index: /trunk/expressoMail1_2/inc/fckeditor.php
===================================================================
--- /trunk/expressoMail1_2/inc/fckeditor.php	(revision 1059)
+++ /trunk/expressoMail1_2/inc/fckeditor.php	(revision 4828)
@@ -72,5 +72,5 @@
 			
 			if ( $this->ToolbarSet != '' )
-				$Link .= "&amp;Toolbar={$this->ToolbarSet}" ;
+				$Link .= "&Toolbar={$this->ToolbarSet}" ;
 
 			// Render the linked hidden field.
@@ -105,23 +105,24 @@
 	function IsCompatible()
 	{
-		global $HTTP_USER_AGENT ;
-
-		if ( isset( $HTTP_USER_AGENT ) )
-			$sAgent = $HTTP_USER_AGENT ;
-		else
-			$sAgent = $_SERVER['HTTP_USER_AGENT'] ;
-
-		if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false )
-		{
-			$iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ;
-			return ($iVersion >= 5.5) ;
-		}
-		else if ( strpos($sAgent, 'Gecko/') !== false )
-		{
-			$iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;
-			return ($iVersion >= 20030210) ;
-		}
-		else
-			return false ;
+		//             global $HTTP_USER_AGENT ; 
+ 		//  
+ 		//              if ( isset( $HTTP_USER_AGENT ) ) 
+ 		//                      $sAgent = $HTTP_USER_AGENT ; 
+ 		//              else 
+ 		//                      $sAgent = $_SERVER['HTTP_USER_AGENT'] ; 
+ 		//  
+ 		//              if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) 
+ 		//              { 
+ 		//                      $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3) ; 
+ 		//                      return ($iVersion >= 5.5) ; 
+ 		//              } 
+ 		//              else if ( strpos($sAgent, 'Gecko/') !== false ) 
+ 		//              { 
+ 		//                      $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ; 
+ 		//                      return ($iVersion >= 20030210) ; 
+ 		//              } 
+ 		//              else 
+ 		//                      return false ; 
+ 		            return( true ); 
 	}
 
@@ -149,4 +150,15 @@
 	}
 
+		//      function getConfigFieldString() 
+ 		//      { 
+ 		//          $sParams = array(); 
+ 		//       
+ 		//          foreach( $this->Config as $sKey => $sValue ) 
+ 		//              $sParams[] = $this->EncodeConfig( $sKey ).'='.$this->EncodeConfig( $sValue ); 
+ 		//  
+ 		//          return implode( '&amp;', $sParams ); 
+ 		//      }
+	
+	
 	function EncodeConfig( $valueToEncode )
 	{
Index: /trunk/expressoMail1_2/inc/hook_settings.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 4726)
+++ /trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 4828)
@@ -19,7 +19,6 @@
 	*  option) any later version.                                              *
 	\**************************************************************************/
-include_once("fckeditor.php");
-include_once("class.functions.inc.php");
-$type = isset($_GET['type']) ? $_GET['type']:$GLOBALS['type']; // FIX ME
+
+$type = isset($_GET['type']) ? $_GET['type']:$GLOBALS['type']; // FIX ME 
 
 //if ($type == 'user' || $type == ''){
@@ -27,17 +26,5 @@
 {
     var type = ("'.$type.'" == "") ? "user" : "'.$type.'";
-    var use_signature_digital_cripto = null;
-
-    if (document.all)
-    {
-        // is_ie
-        use_signature_digital_cripto = document.getElementsByName(type+"[use_signature_digital_cripto]")[1];
-    }
-    else
-    {
-        // not_ie
-        use_signature_digital_cripto = document.getElementsByName(type+"[use_signature_digital_cripto]")[0];
-    }
-
+    var use_signature_digital_cripto = document.getElementsByName(type+"[use_signature_digital_cripto]")[0];
     var default_signature_digital_cripto = "'.$GLOBALS['phpgw_info']['default']['preferences']['expressoMail']['use_signature_digital_cripto'].'";
 
@@ -72,10 +59,235 @@
     }
 
+}
+function validateSignature()
+{
+    var sigs_len = parseInt( document.getElementById("counter").value );
+
+    var signatures = {}, types = {}, noSig = true;
+
+    var default_signature = "", errors = false;
+
+    for( var i = 0; i < sigs_len; i++ )
+    {
+	if( !document.getElementById( "_signature" + i ) ) continue;
+
+	var key = document.getElementById( "title_signature" + i ).value;
+	var edit = !!document.getElementById( "edit_signature" + i ).checked;
+
+	var value =  edit ? tinyMCE.get( "user_signature" + i ).getContent() :
+		            document.getElementById( "user_signature" + i ).value;
+	
+	if( !value )
+	    continue;
+
+	if( !key )
+	{
+		alert( "Titulo da assinatura nao pode ser em branco." );
+		return( false );
+	}
+
+	var openTags = value.match(/<[a-z][^&>]*>/g);
+	var closedTags = value.match(/<[/][^&>]*>/g);
+	var oclosedTags = value.match(/[a-z]*[^&<>]* [/]>/g);
+
+	if( ( openTags || [] ).length !== (( closedTags || [] ).length + ( oclosedTags || [] ).length ))
+	{
+	    errors = errors || [];
+	    errors.push( key );
+	}
+
+	if( errors )
+	    continue;
+
+	if( document.getElementById( "default_signature" + i ).checked )
+	    default_signature = key;
+
+	signatures[key] = value;
+
+	if( edit )
+	    types[key] = edit;
+
+	if( noSig )
+	    noSig = false;
+    }
+
+    if( errors ){
+
+	alert( "Há erros de html na(s) assinatura(s) \'" + errors.join("\',\'") + "\'.\\nRevise a informação inserida (somente no modo Texto Simples ou visulização do Código-Fonte, no modo Texto Rico).\\nPossivelmente você copiou e colou sua assinatura de outro software. Para evitar erros, recomendamos utilizar apenas o editor Texto Rico do Expresso." );
+	return( false );
+    }
+
+    if( !default_signature ){
+	
+	if( !noSig )
+	{
+	    alert( "Favor selecionar uma assinatura padrao." );
+	    return( false );
+	}
+
+	document.getElementById( "signature_default" ).value =  "";
+	document.getElementById( "signature" ).value = "";
+    }
+    else
+    {
+	document.getElementById( "signature_default" ).value =  default_signature;
+	document.getElementById( "signature" ).value = types[key] ? signatures[default_signature] :
+								    signatures[default_signature].replace( /\\n/g, "<br>" );
+    }
+
+    document.getElementById( "signatures" ).value = toJSON( signatures );
+    document.getElementById( "signature_types" ).value = toJSON( types );
+
+    return( true );
+}
+function fromJSON( value )
+{
+    return (new Function( "return " + decode64( value )))();
+}
+
+function toJSON( value )
+{
+    var json = [];
+
+    for( var key in value )
+	json.push(  \'"\' + key + \'":"\' + escape( value[key] ) + \'"\' );
+
+    return encode64( "{" + json.join( "," ) + "}" );
+}
+
+// This code was written by Tyler Akins and has been placed in the
+// public domain.  It would be nice if you left this header intact.
+// Base64 code from Tyler Akins -- http://rumkin.com
+
+var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+
+function encode64(input) {
+	var output = new StringMaker();
+	var chr1, chr2, chr3;
+	var enc1, enc2, enc3, enc4;
+	var i = 0;
+
+	while (i < input.length) {
+		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.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
+   }
+   
+   return output.toString();
+}
+var ua = navigator.userAgent.toLowerCase();
+if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(" gecko/") >= 0) {
+    var StringMaker = function () {
+        this.str = "";
+        this.length = 0;
+        this.append = function (s) {
+            this.str += s;
+            this.length += s.length;
+        }
+        this.prepend = function (s) {
+            this.str = s + this.str;
+            this.length += s.length;
+        }
+        this.toString = function () {
+            return this.str;
+        }
+    }
+} else {
+    var StringMaker = function () {
+        this.parts = [];
+        this.length = 0;
+        this.append = function (s) {
+            this.parts.push(s);
+            this.length += s.length;
+        }
+        this.prepend = function (s) {
+            this.parts.unshift(s);
+            this.length += s.length;
+        }
+        this.toString = function () {
+            return this.parts.join("");
+        }
+    }
+}
+function decode64(input) {
+	var output = new StringMaker();
+	var chr1, chr2, chr3;
+	var enc1, enc2, enc3, enc4;
+	var i = 0;
+
+	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
+	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
+
+	while (i < input.length) {
+		enc1 = keyStr.indexOf(input.charAt(i++));
+		enc2 = keyStr.indexOf(input.charAt(i++));
+		enc3 = keyStr.indexOf(input.charAt(i++));
+		enc4 = keyStr.indexOf(input.charAt(i++));
+
+		chr1 = (enc1 << 2) | (enc2 >> 4);
+		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+		chr3 = ((enc3 & 3) << 6) | enc4;
+
+		output.append(String.fromCharCode(chr1));
+
+		if (enc3 != 64) {
+			output.append(String.fromCharCode(chr2));
+		}
+		if (enc4 != 64) {
+			output.append(String.fromCharCode(chr3));
+		}
+	}
+
+	return output.toString();
+}
+function loadSignature()
+{
+    var types = fromJSON( document.getElementById( "signature_types" ).value );
+    var signatures = fromJSON( document.getElementById( "signatures" ).value );
+    var old_signature = document.getElementById( "signature" ).value; 
+    var def = document.getElementById( "signature_default" ).value;
+
+    var counter = 0, ids = [], def_signature = "", noSig = true;
+
+    for( key in signatures )
+    {
+    	addSignature( !types || !types[key] );
+
+	var value = unescape( signatures[key] );
+
+	document.getElementById( "title_signature" + counter ).value = key;
+	document.getElementById( "user_signature" + counter ).value = value;
+
+	if( def === key )
+	    def_signature = counter;
+
+	if( noSig ) noSig = false;
+
+	counter++;
+    }
+
+    if( def_signature !== "" )
+	document.getElementById( "default_signature" + def_signature ).checked = true;
+    else if( noSig && old_signature )
+    {
+	addSignature( document.getElementById("type_signature").value !== "html" );
+	document.getElementById( "user_signature" + counter ).value = old_signature;
+    }
 }');
 //}
-$default = false;
-create_check_box('Do you want to show common name instead of UID?','uid2cn',$default,
-	'Do you want to show common name instead of UID?');
-create_check_box('Do you want to automatically display the message header?','show_head_msg_full',$default,'');
+
 $default = array(
 	'25'	=> '25',
@@ -85,16 +297,8 @@
 );
 
+// Cria nova opÃ§Ã£o nas preferÃªncias do ExpressoMail 
+create_check_box('View the user name in the header of the messages printed?', 'show_name_print_messages', 'Displays the user name in the header print email');
+
 create_select_box('What is the maximum number of messages per page?','max_email_per_page',$default,'This is the number of messages shown in your mailbox per page');
-
-create_check_box('View the user name in the header of the messages printed?', 'show_name_print_messages', 'Displays the user name in the header print email');
-
-//$default = 0;
-create_check_box('Preview message text within subject column','preview_msg_subject','this exhibits a sample of message within the message subject column');
-
-//$default = 0;
-create_check_box('Preview message text within a tool-tip box','preview_msg_tip','this exhibits a sample of message within a tool-tip box');
-
-create_check_box('View extended information about users','extended_info','This exhibits employeenumber and ou from LDAP in searchs');
-
 create_check_box('Save deleted messages in trash folder?','save_deleted_msg','When delete message, send it automatically to trash folder');
 $default = array(
@@ -106,10 +310,7 @@
 );
 
-$arquived_messages = array(true => lang("Copy"), false => lang("Move"));
-
 create_select_box('Delete trash messages after how many days?','delete_trash_messages_after_n_days',$default,'Delete automatically the messages in trash folder in how many days');
 create_check_box('Would you like to use local messages?','use_local_messages','Enabling this options you will be able to store messages in your local computer');
-create_select_box('Desired action to archive messages to local folders','keep_archived_messages',$arquived_messages,'After store email in your local computer delete it from server');
-create_check_box('Automaticaly create Default local folders?','auto_create_local','Enable this option if you want to automaticaly create the Inbox, Draft, Trash and Sent folders');
+create_check_box('Would you like to keep archived messages?','keep_archived_messages','After store email in your local computer delete it from server');
 create_check_box('Show previous message, after delete actual message?','delete_and_show_previous_message','Enable this option if you want to read the next message everytime you delete a message');
 create_check_box('Do you wanna receive an alert for new messages?','alert_new_msg','Everytime you receive new messages you will be informed');
@@ -117,7 +318,22 @@
 create_check_box('Do you want to use remove attachments function?','remove_attachments_function','It allow you to remove attachments from messages');
 create_check_box('Do you want to use important flag in email editor?','use_important_flag','It allow you to send emails with important flag, but you can receive unwanted messages with important flag');
-create_check_box('Do you want to use SpellChecker in email editor?','use_SpellChecker','It allow you to check the spelling of your emails');
+
 //Use user folders from email
-
+if ($type != "" && $type != "user"){
+	$trash = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];
+	$drafts = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
+	$spam = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'];
+	$sent = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'];
+	$delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'];
+	$default = Array(
+		'INBOX' =>      lang('INBOX'), 
+		'INBOX'.$delimiter.$trash => $trash,  
+		'INBOX'.$delimiter.$drafts => $drafts,
+		'INBOX'.$delimiter.$spam => $spam,
+		'INBOX'.$delimiter.$sent => $sent
+	);
+}
+else
+{
 require_once('class.imap_functions.inc.php');
 $boemailadmin = CreateObject('emailadmin.bo');
@@ -127,22 +343,4 @@
 $e_server = $_SESSION['phpgw_info']['expressomail']['email_server'];
 $imap = CreateObject('expressoMail1_2.imap_functions');
-
-if ($type != "" && $type != "user"){
-	
-	$trash     = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];
-	$drafts    = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
-	$spam      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'];
-	$sent      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'];
-	$delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'];
-	$default = Array(
-		'INBOX' =>      lang('INBOX'), 
-		'INBOX' . $imap->imap_delimiter . $drafts => lang($drafts),
-		'INBOX' . $imap->imap_delimiter . $spam => lang($spam),
-		'INBOX' . $imap->imap_delimiter . $trash => lang($trash),  
-		'INBOX' . $imap->imap_delimiter . $sent => lang($sent)
-	);
-}
-else
-{
 $save_in_folder_selected = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
 
@@ -180,59 +378,16 @@
 }
 create_select_box('Save sent messages in folder','save_in_folder',$default,'Save automatically sent messages in selected folder');
-create_check_box('Show TO: in place of FROM: only in Automatic SEND folder','from_to_sent','Show TO: in place of FROM: only in Automatic SEND folder');
-
-
 create_check_box('Hide menu folders?','hide_folders','You can use it if your screen does not have good resolution');
 
-
-$default =  array(
-    '50'    => '50',
-    '100'   => '100',
-    '150'   => '150',
-    '200'   => '200',
-    '300'   => '300',
-    '400'   => '400',
-    '65536' => lang('unlimited')
+$default = array(
+	'20' => lang('normal'),
+	'30' => lang('medium'),
+	'40' => lang('big')
 );
 
-create_select_box('What is the maximum number of results in an e-mail search?','search_result_number',$default,'');
-
-$default =  array(
-    '1' => lang('unlimited'),
-    '2'     => '2',
-    '3'     => '3',
-    '4'     => '4',
-    '5'     => '5'
-);
-
-create_select_box('What is the minimum number of characters in searching contacts?','search_characters_number',$default,'what is the minimum number of characters in searching contacts');
-
-	$default = array( 
-		'20' => lang('normal'), 
-		'30' => lang('medium'), 
-		'40' => lang('big') 
-	);
-
-
 create_select_box('What is the height of the lines in the list of messages?','line_height',$default,'');
-create_check_box('Increases th maximum size of show messages?','max_msg_size','Increases the maximum size of show emails from 100kb to 1mb');
 create_check_box('Use dynamic contacts?','use_dynamic_contacts','Store your\'s most used contacts');
-create_check_box('Use shortcuts?','use_shortcuts','n key (Open new message)<br>ESC key (Close tab)<br>i key (print)<br>e key (forward)<br>r key (reply)<br>DELETE key (delete the current message)<br>Ctrl + up (go to previous message)<br>Ctrl + down (go to next message)<br>Shift + up or down (select multiple messages)<br>F9  key (search at catalog)<br>');
+create_check_box('Use shortcuts?','use_shortcuts','');
 create_check_box('Auto save draft','auto_save_draft','When you are away from computer it saves automatically the message you are writing');
-create_check_box('Send messages with return recipient option by default','return_recipient_deafault','With this option every new email will get the return recipient option marked');
-
-unset($default);
-$functions = new functions();
-$zones = $functions->getTimezones();
-$default = array(sprintf("%s", array_search('America/Sao_Paulo', $zones)) => 'America/Sao_Paulo');
-create_select_box('What is your timezone?', 'timezone', $zones, 'The Timezone you\'re in.', $default);
-
-$default =  array(
-    '1' => lang('contacts'),
-    '2' => lang('email')
-);
-
-create_select_box('Where should the quick search be performed by default?','quick_search_default',$default,'It is where the keyword should be searched when the user executes a quick search.');
-
 $default = array(
 	'65536' => lang('unlimited'),
@@ -265,223 +420,87 @@
 	'html' => lang('rich text')
 );
-create_check_box('Auto close the first tab on reaching the maximum number of tabs?','auto_close_first_tab','');
 create_check_box('Insert signature automatically in new messages?','use_signature','');
-create_select_box('Signature Type','type_signature',$default,'','','','onchange="javascript:changeType(this.value);" onload="javascript:alert(this.value);"');
 
 if ($type == 'user' || $type == ''){
-	$oFCKeditor = new FCKeditor('html_signature');
-	$oFCKeditor->BasePath   = '../expressoMail1_2/js/fckeditor/';
-	$oFCKeditor->ToolbarSet = 'ExpressoLivre';
-
-	$vars = $GLOBALS['phpgw']->preferences->user[$appname];
-
-	create_html_code("signature","<div id='text_signature'>
-		<textarea rows='5' cols='50' id='user_signature' name='user[signature]'>","</textarea></div>
-		<div style='display:none;' id='html_signature'>".$oFCKeditor->Create()."</div>
-		<script language='javascript'>
-//document.getElementById('user_signature').value  = '".$vars['signature']."';
-function changeType(value){
-	var html_signature = FCKeditorAPI.GetInstance(\"html_signature\");
-        value=value.replace('d','');
-	if(value == 'text'){
-		document.getElementById('user_signature').value = html_signature.GetHTML();
-		document.getElementById(\"text_signature\").style.display = '';
-		document.getElementById(\"html_signature\").style.display = 'none';
+
+	global $prefs;
+// 	create_select_box('Signature Type','type_signature',$default,'','','','onchange="javascript:changeType(this.value);"');
+
+	$vars = $GLOBALS['phpgw']->preferences->user['expressoMail'];
+
+	create_html_code("signature","<script src='../library/jquery/jquery-1.6.1.min.js' language='javascript'></script><script src='../library/tiny_mce/jquery.tinymce.js' language='javascript'></script><script src='../library/tiny_mce/tiny_mce.js' language='javascript'></script>
+	<input type='hidden' id='counter' value='0'>
+	<input type='hidden' id='signatures' name='user[signatures]' value='". $vars['signatures']."'>
+	<input type='hidden' id='signature_default' name='user[signature_default]' value='".$vars['signature_default']."'>
+	<input type='hidden' id='type_signature' name='user[type_signature]' value='".$vars['type_signature']."'>
+	<input type='hidden' id='signature' name='user[signature]' value='","' >
+	<input type='hidden' id='signature_types' name='user[signature_types]' value='".$vars['signature_types']."'>
+
+	<div id='_signature' name='signature' style='display: none;'>
+	<div id='options_signature'>
+	<input id='edit_signature' type='checkbox' name='isEditor' onclick='changeType( \"\", this.id.replace( /[^0-9]*/gi, \"\" ) );' checked='checked'><label for='isEditor'>Editor de texto</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; titulo da assinatura&nbsp;<input type='text' id='title_signature'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' id='default_signature' name='signature_default'><label>Usar como padrao</label><a href='#' onclick='javascript: return removeSignature( this );' id='remove_signature'> remover</a>
+	</div><br/>
+	<div id='text_signature'>
+	<textarea rows='5' cols='50' id='user_signature' class='editor'></textarea></div>
+	</div>
+
+	<script language='javascript'>
+
+	$(document).ready(function(){
+
+	    loadSignature();
+
+	});
+
+	function changeType(value, target){
+
+	    tinyMCE.execCommand( 'mceToggleEditor', false, 'user_signature' + target );
 	}
-	else if(value == 'html'){
-		html_signature.SetHTML(document.getElementById('user_signature').value);
-		document.getElementById(\"text_signature\").style.display = 'none';
-		document.getElementById(\"html_signature\").style.display  = '';
-	}
-}
-function get_html_translation_table(table, quote_style) {
-    // http://kevin.vanzonneveld.net 
-    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
-    var constMappingTable = {}, constMappingQuoteStyle = {};
-    var useTable = {}, useQuoteStyle = {};
-    // Translate arguments
-    constMappingTable[0]      = 'HTML_SPECIALCHARS';
-    constMappingTable[1]      = 'HTML_ENTITIES';
-    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
-    constMappingQuoteStyle[2] = 'ENT_COMPAT';
-    constMappingQuoteStyle[3] = 'ENT_QUOTES';
- 
-    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
-    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
- 
-    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
-        throw new Error(\"Table: \"+useTable+' not supported');
-        // return false;
-    }
- 
-    entities['38'] = '&amp;';
-    if (useTable === 'HTML_ENTITIES') {
-        entities['160'] = '&nbsp;';
-        entities['161'] = '&iexcl;';
-        entities['162'] = '&cent;';
-        entities['163'] = '&pound;';
-        entities['164'] = '&curren;';
-        entities['165'] = '&yen;';
-        entities['166'] = '&brvbar;';
-        entities['167'] = '&sect;';
-        entities['168'] = '&uml;';
-        entities['169'] = '&copy;';
-        entities['170'] = '&ordf;';
-        entities['171'] = '&laquo;';
-        entities['172'] = '&not;';
-        entities['173'] = '&shy;';
-        entities['174'] = '&reg;';
-        entities['175'] = '&macr;';
-        entities['176'] = '&deg;';
-        entities['177'] = '&plusmn;';
-        entities['178'] = '&sup2;';
-        entities['179'] = '&sup3;';
-        entities['180'] = '&acute;';
-        entities['181'] = '&micro;';
-        entities['182'] = '&para;';
-        entities['183'] = '&middot;';
-        entities['184'] = '&cedil;';
-        entities['185'] = '&sup1;';
-        entities['186'] = '&ordm;';
-        entities['187'] = '&raquo;';
-        entities['188'] = '&frac14;';
-        entities['189'] = '&frac12;';
-        entities['190'] = '&frac34;';
-        entities['191'] = '&iquest;';
-        entities['192'] = '&Agrave;';
-        entities['193'] = '&Aacute;';
-        entities['194'] = '&Acirc;';
-        entities['195'] = '&Atilde;';
-        entities['196'] = '&Auml;';
-        entities['197'] = '&Aring;';
-        entities['198'] = '&AElig;';
-        entities['199'] = '&Ccedil;';
-        entities['200'] = '&Egrave;';
-        entities['201'] = '&Eacute;';
-        entities['202'] = '&Ecirc;';
-        entities['203'] = '&Euml;';
-        entities['204'] = '&Igrave;';
-        entities['205'] = '&Iacute;';
-        entities['206'] = '&Icirc;';
-        entities['207'] = '&Iuml;';
-        entities['208'] = '&ETH;';
-        entities['209'] = '&Ntilde;';
-        entities['210'] = '&Ograve;';
-        entities['211'] = '&Oacute;';
-        entities['212'] = '&Ocirc;';
-        entities['213'] = '&Otilde;';
-        entities['214'] = '&Ouml;';
-        entities['215'] = '&times;';
-        entities['216'] = '&Oslash;';
-        entities['217'] = '&Ugrave;';
-        entities['218'] = '&Uacute;';
-        entities['219'] = '&Ucirc;';
-        entities['220'] = '&Uuml;';
-        entities['221'] = '&Yacute;';
-        entities['222'] = '&THORN;';
-        entities['223'] = '&szlig;';
-        entities['224'] = '&agrave;';
-        entities['225'] = '&aacute;';
-        entities['226'] = '&acirc;';
-        entities['227'] = '&atilde;';
-        entities['228'] = '&auml;';
-        entities['229'] = '&aring;';
-        entities['230'] = '&aelig;';
-        entities['231'] = '&ccedil;';
-        entities['232'] = '&egrave;';
-        entities['233'] = '&eacute;';
-        entities['234'] = '&ecirc;';
-        entities['235'] = '&euml;';
-        entities['236'] = '&igrave;';
-        entities['237'] = '&iacute;';
-        entities['238'] = '&icirc;';
-        entities['239'] = '&iuml;';
-        entities['240'] = '&eth;';
-        entities['241'] = '&ntilde;';
-        entities['242'] = '&ograve;';
-        entities['243'] = '&oacute;';
-        entities['244'] = '&ocirc;';
-        entities['245'] = '&otilde;';
-        entities['246'] = '&ouml;';
-        entities['247'] = '&divide;';
-        entities['248'] = '&oslash;';
-        entities['249'] = '&ugrave;';
-        entities['250'] = '&uacute;';
-        entities['251'] = '&ucirc;';
-        entities['252'] = '&uuml;';
-        entities['253'] = '&yacute;';
-        entities['254'] = '&thorn;';
-        entities['255'] = '&yuml;';
-    }
-    if (useQuoteStyle !== 'ENT_NOQUOTES') {
-        entities['34'] = '&quot;';
-    }
-    if (useQuoteStyle === 'ENT_QUOTES') {
-        entities['39'] = '&#39;';
-    }
-    entities['60'] = '&lt;';
-    entities['62'] = '&gt;';
-  
-    // ascii decimals to real symbols
-    for (decimal in entities) {
-        symbol = String.fromCharCode(decimal);
-        hash_map[symbol] = entities[decimal];
-    }
-    return hash_map;
-}
-function html_entity_decode( string, quote_style ) {
-    // http://kevin.vanzonneveld.net
-    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
-    tmp_str = string.toString();
-    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
-        return false;
-    }
-    for (symbol in hash_map) {
-        entity = hash_map[symbol];
-        tmp_str = tmp_str.split(entity).join(symbol);
-    }
-    tmp_str = tmp_str.split('&#039;').join(\"'\");
-    return tmp_str;
-}
-
-function getTypeSignature() {
-   var elementoSelects  = document.getElementsByTagName('select');
-
-   if ( elementoSelects[18].name == \"user[type_signature]\" ) {
-	return elementoSelects[18];
-   }
-   
-   for(i=0;i<elementoSelects.length;i++){
-	if( elementoSelects[i].name == \"user[type_signature]\" ){
-	         return elementoSelects[i];
-	}
-    }
-    return null;
-}
-
-function config_form(pObj,pHandler)
-{
-	pObj.onclick=function () {
-		if (getTypeSignature().value == \"html\" || getTypeSignature().value == \"htmld\") {
-			return pHandler(\"text\");
-		}
-	};
-
-}
-document.getElementById('user_signature').value=html_entity_decode(document.getElementById('user_signature').innerHTML);
-
-function setDefaultTypeSignature() {
-	if(getTypeSignature()){
-		getTypeSignature().options[0].value = '".$GLOBALS['phpgw']->preferences->default['expressoMail']['type_signature']."d';
-		if(getTypeSignature().value.indexOf('html')!=-1){
-		   changeType(getTypeSignature().value);
-	    }
-	}else{
-		 changeType('".$GLOBALS['phpgw']->preferences->forced['expressoMail']['type_signature']."');
-	}
-}
-
-setTimeout('setDefaultTypeSignature();config_form(document.getElementsByName(\'submit\')[0],changeType);',2000);
-</script>");
+
+// var counter = 0;
+
+function addSignature( simple )
+{
+	var sig = document.getElementById('_signature').cloneNode( true );
+	var counter = document.getElementById( 'counter' ).value;
+
+	sig.innerHTML = sig.innerHTML.replace( /_signature/g, '_signature' + counter );
+
+	sig.id = '_signature' + counter;
+	sig.style.display = '';
+
+	$( '#add_signature' ).before( sig );
+
+	if( !simple )
+	    $( '#user_signature' + counter ).tinymce({
+		plugins : 'paste',
+		theme_advanced_toolbar_location : 'top',
+		theme_advanced_toolbar_align : 'center',
+		entities: '',
+		entity_encoding: 'raw',
+		theme: 'advanced',
+		add_form_submit_trigger : false
+	    });
+	else
+	    document.getElementById('edit_signature' + counter ).checked = '';
+
+	document.getElementById( 'counter' ).value = ++counter;
+}
+
+function removeSignature( el )
+{
+    counter = el.id.replace( /[^0-9]*/gi, \"\" );
+
+    el = document.getElementById( '_signature' + counter );
+    el.parentNode.removeChild( el );
+
+    return( false );
+}
+</script>
+<input id='add_signature' type='button' onclick='addSignature();' value='Adicionar Assinatura'>
+");
+}else{
+	create_select_box('Signature Type','type_signature',$default,'','','','');
+
 }
 ?>
Index: /trunk/expressoMail1_2/js/rich_text_editor.js
===================================================================
--- /trunk/expressoMail1_2/js/rich_text_editor.js	(revision 4801)
+++ /trunk/expressoMail1_2/js/rich_text_editor.js	(revision 4828)
@@ -6,4 +6,88 @@
 	this.buildEditor();
 	this.saveFlag = 0;
+	} 
+ 		 
+ 		// This code was written by Tyler Akins and has been placed in the 
+ 		// public domain.  It would be nice if you left this header intact. 
+ 		// Base64 code from Tyler Akins -- http://rumkin.com 
+ 		 
+ 		var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 
+ 	 
+ 		var ua = navigator.userAgent.toLowerCase(); 
+ 		if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(' gecko/') >= 0) { 
+ 		    var StringMaker = function () { 
+ 		        this.str = ""; 
+ 		        this.length = 0; 
+ 		        this.append = function (s) { 
+ 		            this.str += s; 
+ 		            this.length += s.length; 
+ 		        } 
+ 		        this.prepend = function (s) { 
+ 		            this.str = s + this.str; 
+ 		            this.length += s.length; 
+ 		        } 
+ 		        this.toString = function () { 
+ 		            return this.str; 
+ 		        } 
+ 		    } 
+ 		} else { 
+ 		    var StringMaker = function () { 
+				this.parts = []; 
+ 		        this.length = 0; 
+ 		        this.append = function (s) { 
+ 		            this.parts.push(s); 
+ 		            this.length += s.length; 
+ 		        } 
+ 		        this.prepend = function (s) { 
+ 		            this.parts.unshift(s); 
+ 		            this.length += s.length; 
+ 		        } 
+ 		        this.toString = function () { 
+ 		            return this.parts.join(''); 
+ 		        } 
+ 		    } 
+ 		} 
+ 		
+		function fromJSON( value ) 
+ 		{ 
+ 		    return (new Function( "return " + decode64( value )))(); 
+ 		}
+
+		
+ 		function decode64(input) { 
+ 		 
+ 		        if( typeof input === "undefined" ) return; 
+ 		 
+ 		        var output = new StringMaker(); 
+ 		        var chr1, chr2, chr3; 
+ 		        var enc1, enc2, enc3, enc4; 
+				var i = 0; 
+ 		 
+ 		        // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 
+ 		        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 
+ 		 
+ 		        while (i < input.length) { 
+ 		                enc1 = keyStr.indexOf(input.charAt(i++)); 
+ 		                enc2 = keyStr.indexOf(input.charAt(i++)); 
+ 		                enc3 = keyStr.indexOf(input.charAt(i++)); 
+ 		                enc4 = keyStr.indexOf(input.charAt(i++)); 
+ 		 
+						chr1 = (enc1 << 2) | (enc2 >> 4); 
+ 		                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 
+ 		                chr3 = ((enc3 & 3) << 6) | enc4; 
+ 		 
+ 		                output.append(String.fromCharCode(chr1)); 
+ 		 
+ 		                if (enc3 != 64) { 
+ 		                        output.append(String.fromCharCode(chr2)); 
+ 		                } 
+ 		                if (enc4 != 64) { 
+ 		                        output.append(String.fromCharCode(chr3)); 
+ 		                } 
+ 		        } 
+ 		 
+ 		        return output.toString();
+	
+	
 }
 
@@ -220,5 +304,20 @@
 
 
-
+cRichTextEditor.prototype.buildSelect = function( selectId, label, options, decode ) {  
+ 		 
+ 		    var selectBox = document.createElement("SELECT"); 
+ 		    selectBox.id = selectId; 
+ 		    selectBox.setAttribute("tabIndex","-1"); 
+ 		    selectBox.onchange = function () {RichTextEditor.Select( selectId );}; 
+ 		    selectBox.className = 'select_richtext'; 
+ 		    selectBox.length = 0; 
+ 		 
+ 		    selectBox.options[0] = new Option( get_lang(label), label ); 
+ 		 
+ 		    for( var key in options ) 
+ 		        selectBox.options[ selectBox.length ] = new Option( key, unescape( options[key] ) ); 
+ 		 
+ 		    return selectBox; 
+ 		}
 
 cRichTextEditor.prototype.buildEditor = function() {
@@ -232,62 +331,20 @@
 	var div_button_rt = document.createElement("DIV");
 	
-	selectBox=document.createElement("SELECT");
-	selectBox.id="fontname";
-	selectBox.setAttribute("tabIndex","-1");
-	selectBox.onchange = function () {RichTextEditor.Select("fontname");};
-	selectBox.className = 'select_richtext';
-	var option1 = new Option(get_lang('Font'), 'Font');
-	var option2 = new Option('Arial', 'Arial');
-	var option3 = new Option('Courier', 'Courier');
-	var option4 = new Option('Times New Roman', 'Times');
-	if (is_ie){
-		selectBox.add(option1);
-		selectBox.add(option2);
-		selectBox.add(option3);
-		selectBox.add(option4);
-	}
-	else{
-		selectBox.add(option1, null);
-		selectBox.add(option2, null);
-		selectBox.add(option3, null);
-		selectBox.add(option4, null);
-	}
-	div_button_rt.appendChild(selectBox);
-
-	selectBox=document.createElement("SELECT");
-	selectBox.id="fontsize";
-	selectBox.setAttribute("tabIndex","-1");
-	selectBox.setAttribute("unselectable","on");
-	selectBox.className = 'select_richtext';
-	selectBox.onchange = function () {RichTextEditor.Select("fontsize");};
-	var option1 = new Option(get_lang('Size'), 'Size');
-	var option2 = new Option('1 (8 pt)','1' );
-	var option3 = new Option('2 (10 pt)','2');
-	var option4 = new Option('3 (12 pt)','3');
-	var option5 = new Option('4 (14 pt)','4');
-	var option6 = new Option('5 (18 pt)','5');
-	var option7 = new Option('6 (24 pt)','6');
-	var option8 = new Option('7 (36 pt)','7');
-	if (is_ie){
-		selectBox.add(option1);
-		selectBox.add(option2);
-		selectBox.add(option3);
-		selectBox.add(option4);
-		selectBox.add(option5);
-		selectBox.add(option6);
-		selectBox.add(option7);
-		selectBox.add(option8);
-	}
-	else{
-		selectBox.add(option1, null);
-		selectBox.add(option2, null);
-		selectBox.add(option3, null);
-		selectBox.add(option4, null);
-		selectBox.add(option5, null);
-		selectBox.add(option6, null);
-		selectBox.add(option7, null);
-		selectBox.add(option8, null);	
-	}
-	div_button_rt.appendChild(selectBox);
+	
+	selectBox = this.buildSelect( "fontname", 'Font', { 'Arial' : 'Arial', 
+ 		                                                            'Courier' : 'Courier', 
+ 		                                                            'Times New Roman' : 'Times' }); 
+ 		 
+ 		        div_button_rt.appendChild( selectBox ); 
+ 		 
+ 		        selectBox = this.buildSelect( "fontsize", 'Size', { '1 (8 pt)': '1', 
+ 		                                                            '2 (10 pt)': '2', 
+ 		                                                            '3 (12 pt)': '3', 
+ 		                                                            '4 (14 pt)': '4', 
+ 		                                                            '5 (18 pt)': '5', 
+ 		                                                            '6 (24 pt)': '6', 
+ 		                                                            '7 (36 pt)': '7' }); 
+ 		 
+ 		        div_button_rt.appendChild( selectBox );
 	
 	var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
@@ -355,4 +412,13 @@
 	}
 
+	preferences.signatures = fromJSON( preferences.signatures ); 
+ 		        preferences.signature_types = fromJSON( preferences.signature_types ); 
+ 		 
+ 		        for( key in preferences.signatures ) 
+ 		            if( !preferences.signature_types[key] ) 
+						preferences.signatures[key] = preferences.signatures[key].replace( /\n/g, "<br>" );
+ 		 
+ 	        selectBox = this.buildSelect( "inserthtml", 'Signature', preferences.signatures ); 
+ 	        div_button_rt.appendChild( selectBox );
 
 	td.appendChild(div_button_rt);
@@ -366,5 +432,7 @@
 		var mainField = document.getElementById(this.editor).contentWindow;
 		mainField.focus();
-		var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
+		var signature = preferences.signature; 
+ 	    if( !preferences.signatures ) 
+			signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
 		if (command == 'signature'){
 			if (is_ie){
