diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 2ee79ab04d725eae4dc9ec93b426130e5c0b0443..2ce29a0bdefd4fde3d78a5f8f8288ea7fd6b02f5 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -622,7 +622,7 @@ if ($action == 'create')
 
     print_fiche_titre($langs->trans("NewMember"));
 
-    dol_htmloutput_errors($errmsg,$errmsgs);
+    dol_htmloutput_mesg($errmsg,$errmsgs,'error');
     dol_htmloutput_mesg($mesg,$mesgs);
 
     if ($conf->use_javascript_ajax)
diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index e91b8b307c07d1a8c6b153f84f1fea7cf5f4d315..9cc8ee4191e74d510394e95688ddfea584ce351c 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -365,7 +365,7 @@ foreach ($conf->file->dol_document_root as $dirroot)
 
                             if ($conf->global->FACTURE_ADDON.'.php' == $file)  // If module is the one used, we show existing errors
                             {
-                                if (! empty($module->error)) dol_htmloutput_errors($module->error,'',1);
+                                if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
                             }
 
                             print '</td>';
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index 9c12415ac55c3c5676cb24c245c9d5564e405bf0..e00a44ab5d8ad31f13c82d170aae75e42cd20108 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -612,9 +612,8 @@ if ($_GET["action"] == 'create')
 
 	print_fiche_titre($langs->trans("NewMailing"));
 
-	if (preg_match('/class="error"/i',$message)) dol_htmloutput_errors($message);
-	else dol_htmloutput_mesg($message);
-	
+	dol_htmloutput_mesg($message);
+
 	print '<table class="border" width="100%">';
 	print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTitle").'</td><td><input class="flat" name="titre" size="40" value="'.$_POST['titre'].'"></td></tr>';
 	print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat" name="from" size="40" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 80664161455ea6ad9e3aa2f629a41798b88f84c9..9c6d71ead2f763a569a95d28d68547b15af55097 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -104,7 +104,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
         }
         else
         {
-            $mesg=$object->error;
+            $mesg='<div class="error">'.$object->error.'</div>';
             $action='';
         }
     }
@@ -124,7 +124,7 @@ if ($action == 'reopen' && $user->rights->commande->creer)
         }
         else
         {
-            $mesg='<div class="error">'.$fac->error.'</div>';
+            $mesg='<div class="error">'.$object->error.'</div>';
         }
     }
 }
@@ -143,7 +143,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes')
         }
         else
         {
-            $mesg=$object->error;
+            $mesg='<div class="error">'.$object->error.'</div>';
         }
     }
 }
@@ -173,7 +173,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes')
         }
         else
         {
-            print $object->error;
+            $mesg='<div class="error">'.$object->error.'</div>';
         }
     }
     Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
@@ -1124,7 +1124,7 @@ if ($action == 'create' && $user->rights->commande->creer)
 {
     print_fiche_titre($langs->trans('CreateOrder'));
 
-    dol_htmloutput_errors($mesg,$mesgs);
+    dol_htmloutput_mesg($mesg,$mesgs,'error');
 
     $soc = new Societe($db);
     if ($socid) $res=$soc->fetch($socid);
@@ -1424,7 +1424,7 @@ else
 
     if ($id > 0 || ! empty($ref))
     {
-        dol_htmloutput_errors($mesg,$mesgs);
+        dol_htmloutput_mesg($mesg,$mesgs);
 
         $product_static=new Product($db);
 
diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php
index 7f812bb2c1efa6cd2632972b443e92c6a91e69e4..a3f656eff3916011c76c22a95803048126d68a26 100644
--- a/htdocs/compta/bank/ligne.php
+++ b/htdocs/compta/bank/ligne.php
@@ -215,8 +215,7 @@ $h++;
 
 dol_fiche_head($head, $hselected, $langs->trans('LineRecord'),0,'account');
 
-if (! preg_match('/class="error"/i',$mesg)) dol_htmloutput_mesg($mesg);
-else dol_htmloutput_errors($mesg);
+dol_htmloutput_mesg($mesg);
 
 $sql = "SELECT b.rowid,b.dateo as do,b.datev as dv, b.amount, b.label, b.rappro,";
 $sql.= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,";
diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php
index 27d813d531c3735cf4a60a7b586c22ce28180ea1..4f7737c5f30c991281af78d68af8fcf552668d39 100644
--- a/htdocs/compta/deplacement/fiche.php
+++ b/htdocs/compta/deplacement/fiche.php
@@ -184,7 +184,7 @@ if ($_GET["action"] == 'create')
 {
 	print_fiche_titre($langs->trans("NewTrip"));
 
-	if ($mesg) dol_htmloutput_errors($mesg);
+	dol_htmloutput_errors($mesg);
 
 	$datec = dol_mktime(12, 0, 0,
 	$_POST["remonth"],
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 5e4cc1f59df8b99a9a2d0aeb5a238fc67b02119f..fe73e96e1dd8fb425f34dbb57ddeec6dc4d1dcaf 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1841,8 +1841,7 @@ else
      */
     if ($id > 0 || ! empty($ref))
     {
-        if (preg_match('/class="error"/',$mesg)) dol_htmloutput_errors($mesg);
-        else dol_htmloutput_mesg($mesg);
+        dol_htmloutput_mesg($mesg);
 
         $result=$object->fetch($id,$ref);
         if ($result > 0)
diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index 3e77bdfab700cdfb27bb892d441188c960e50d33..96203d9c39fed9fe35005af5a5f3d63eb32c1517 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -227,7 +227,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
         if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
         print_fiche_titre($title);
 
-        if ($errmsg) dol_htmloutput_errors($errmsg);
+        dol_htmloutput_errors($errmsg);
 
         // Bouchon
         if ($facture->type == 2)
diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php
index 06ba2ded7ee369e5a6969fad06924e094b99b3ce..5194ba5cc61a6300470df1833339d02e47da6dc9 100644
--- a/htdocs/compta/paiement/cheque/fiche.php
+++ b/htdocs/compta/paiement/cheque/fiche.php
@@ -286,7 +286,7 @@ else
 	}
 }
 
-//if ($mesg) print $mesg.'<br>';
+
 dol_htmloutput_errors($mesg);
 
 
diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index 3d050ec2b552a7246460ca64b6310dcde8d9fbfb..7a25b945269f2e35d5aa202c4f84af0fdccb0dd8 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -480,7 +480,7 @@ if ($action == 'create')
 {
     dol_fiche_head($head, $a, $langs->trans("AddContract"), 0, 'contract');
 
-    dol_htmloutput_errors($mesg);
+    dol_htmloutput_errors($mesg,'');
 
     $soc = new Societe($db);
     $soc->fetch($socid);
@@ -583,7 +583,7 @@ else
             exit;
         }
 
-        dol_htmloutput_errors($mesg);
+        dol_htmloutput_errors($mesg,'');
 
 		$nbofservices=sizeof($object->lines);
 
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 3d6ed3cf92b0e36067892ff34f2f221eade5baff..a4a7bd01900bfd781d768d4d35b088f5ee0af5a6 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -835,12 +835,7 @@ else
 
 		if ($object->id > 0)
 		{
-			if ($mesg)
-			{
-				print '<div class="error">'.$mesg.'</div>';
-			}
-			
-			dol_htmloutput_mesg();
+			dol_htmloutput_mesg($mesg);
 
 			if (!empty($object->origin))
 			{
@@ -1236,13 +1231,13 @@ else
 					print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
 				}
 			}
-			
+
 			// TODO add alternative status
 			/* if ($object->statut == 1 && $user->rights->expedition->valider)
 			{
 				print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
 			}*/
-			
+
 			// Send
 			if ($object->statut == 1)
 			{
@@ -1257,7 +1252,7 @@ else
                     else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
 				}
 			}
-			
+
 			// Create bill and Classify billed
 			if ($conf->facture->enabled && $object->statut > 0  && ! $object->billed)
 			{
@@ -1267,7 +1262,7 @@ else
 					//print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
 					print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->origin.'&amp;originid='.$object->origin_id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
 				}
-				
+
 				// TODO add alternative status
 				if ($user->rights->expedition->creer && $object->statut > 2)
 				{
@@ -1309,17 +1304,17 @@ else
 
 			$somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
 			if ($genallowed && ! $somethingshown) $somethingshown=1;
-			
+
 			print '</td><td valign="top" width="50%">';
-			
+
 			// List of actions on element
 			include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
 			$formactions=new FormActions($db);
 			$somethingshown=$formactions->showactions($object,'shipping',$socid);
-			
+
 			print '</td></tr></table>';
 		}
-		
+
 		/*
 		 * Action presend
 		 *
@@ -1328,10 +1323,10 @@ else
 		{
 			$ref = dol_sanitizeFileName($object->ref);
 			$file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
-			
+
 			print '<br>';
 			print_titre($langs->trans('SendShippingByEMail'));
-			
+
 			// Cree l'objet formulaire mail
 			include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
 			$formmail = new FormMail($db);
@@ -1358,17 +1353,17 @@ else
 			$formmail->param['models']='shipping_send';
 			$formmail->param['shippingid']=$object->id;
 			$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
-			
+
 			// Init list of files
 			if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
 			{
 				$formmail->clear_attached_files();
 				$formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf');
 			}
-			
+
 			// Show form
 			$formmail->show_form();
-			
+
 			print '<br>';
 		}
 
diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index 9e11f15fd91dbe30b589e40e4d1bad1c31e90f26..61ddcc6ba9da6f9affd60cdf43e3f79b9a095ac2 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -702,7 +702,9 @@ elseif ($fichinterid)
     $societe=new Societe($db);
     $societe->fetch($fichinter->socid);
 
-    if ($mesg) dol_htmloutput_errors($mesg)."<br>";
+
+    dol_htmloutput_errors($mesg);
+
 
     $head = fichinter_prepare_head($fichinter);
 
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index de7cd699f357d0251859dd6036982fa5e53f9090..bfb074c71af9fd1a6f8dc64a55de3a6984d152a7 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -102,7 +102,7 @@ function dol_getprefix()
  *  To link to a module file from a module file, use include('./mymodulefile');
  *  To link to a module file from a core file, then this function can be used.
  * 	@param			relpath		Relative path to file (Ie: mydir/myfile, ../myfile, ...)
- *  @return         int			Result
+ *  @return         int			false if include fails.
  */
 function dol_include_once($relpath)
 {
@@ -3711,11 +3711,11 @@ function monthArrayOrSelected($selected=0)
 
 /**
  *	Get formated messages to output (Used to show messages on html output)
- *	@param		mesgstring		Message
+ *	@param		mesgstring		Message string
  *	@param		mesgarray       Messages array
- *  @param      style           Style of message output
+ *  @param      style           Style of message output ('ok' or 'error')
+ *  @param      keepembedded    Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
  *	@return		string			Return html output
- *  @return     $keepembedded   Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
  *  @see        dol_print_error
  *  @see        dol_htmloutput_errors
  */
@@ -3727,12 +3727,12 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
     $out='';
     $divstart=$divend='';
 
+    // Use session mesg
     if (isset($_SESSION['mesg']))
     {
     	$mesgstring=$_SESSION['mesg'];
     	unset($_SESSION['mesg']);
     }
-
 	if (isset($_SESSION['mesgarray']))
     {
     	$mesgarray=$_SESSION['mesgarray'];
@@ -3790,7 +3790,7 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
  *  Get formated error messages to output (Used to show messages on html output)
  *  @param      mesgstring          Error message
  *  @param      mesgarray           Error messages array
- *  @return     keepembedded        Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
+ *  @param      keepembedded        Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
  *  @return     html                Return html output
  *  @see        dol_print_error
  *  @see        dol_htmloutput_mesg
@@ -3801,18 +3801,24 @@ function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
 }
 
 /**
- *	print formated messages to output (Used to show messages on html output)
+ *	Print formated messages to output (Used to show messages on html output)
  *	@param		mesgstring		Message
  *	@param		mesgarray       Messages array
- *  @param      style           Style of message output
- *	@return		string			Return html output
- *  @return     $keepembedded   Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
+ *  @param      style           Which style to use ('ok', 'error')
+ *  @param      keepembedded    Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
  *  @see        dol_print_error
  *  @see        dol_htmloutput_errors
  */
 function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
 {
-	print get_htmloutput_mesg($mesgstring,$mesgarray,$style,$keepembedded);
+    if (empty($mesgstring) && (! is_array($mesgarray) || sizeof($mesgarray) == 0)) return;
+
+    $iserror=0;
+    if (preg_match('/class="error"/i',$mesgstring)) $iserror++;
+    if ($style=='error') $iserror++;
+
+    if ($iserror) print get_htmloutput_mesg($mesgstring,$mesgarray,'error',$keepembedded);
+    else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
 }
 
 /**
@@ -3820,13 +3826,12 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
  *  @param      mesgstring          Error message
  *  @param      mesgarray           Error messages array
  *  @return     keepembedded        Set to 1 in error message must be kept embedded into its html place (this disable jnotify)
- *  @return     html                Return html output
  *  @see        dol_print_error
  *  @see        dol_htmloutput_mesg
  */
 function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
 {
-    print get_htmloutput_errors($mesgstring, $mesgarray,$keepembedded);
+    dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
 }
 
 /**
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index 1c5f7d93e7fdf67aa93d90091f9bfb2c28c41f37..110482c829ee4997578bd78d0394790a2bc591a9 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -235,8 +235,8 @@ if ($_GET["id"] || $_GET["ref"])
 
 			print "</div>\n";
 
-			if (preg_match('/class="error"/',$mesg)) dol_htmloutput_errors($mesg);
-			else dol_htmloutput_mesg($mesg);
+
+			dol_htmloutput_mesg($mesg);
 
 
 			// Form to add or update a price
diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php
index 55cdb0c025d32ffa5cff2eba10be6fba61ba35e8..908a9ee54859a8946be6237a45313cdd29949be7 100644
--- a/htdocs/user/fiche.php
+++ b/htdocs/user/fiche.php
@@ -894,8 +894,7 @@ else
 			if ($ret == 'html') print '<br>';
 		}
 
-		if (! preg_match('/class="error"/',$message)) dol_htmloutput_mesg($message);
-		else dol_htmloutput_errors($message);
+		dol_htmloutput_mesg($message);
 
 		/*
 		 * Fiche en mode visu