diff --git a/modules/templates/js/functions.js b/modules/templates/js/functions.js
index c9522843c2ab3996482524159ff7214931915bff..fa4f4131d9a8553a5878a9121499fdea7a37a9d7 100755
--- a/modules/templates/js/functions.js
+++ b/modules/templates/js/functions.js
@@ -60,36 +60,31 @@ function changeStyle(style_id, path_to_script)
 
 function setradiobutton(target)
 {
-    $("html").style.display="inline";
-    $("office").style.display="inline";
-    $("txt").style.display="inline";
-    $("span_html").style.display="inline";
-    $("span_office").style.display="inline";
-    $("span_txt").style.display="inline";
-   	$("template_attachment_type_tr").style.display="none";
+    $j("#html,#office,#txt,#span_html,#span_office,#span_txt").css({"display":"inline"});
+    $j("#template_attachment_type_tr").hide();
 
-    if(target=="notes"|| target=="sendmail") {
-        $("html").style.display="none";
-        $("span_html").style.display="none";
-        $("txt").click();
-        $("txt").checked = true;
-        $("office").style.display="none";
-        $("span_office").style.display="none";
+    if(target=="notes") {
+        $j("#html,#span_html,#office,#span_office").hide();
+        $j("#txt").click();
+    }else if(target=="sendmail") {
+        $j("#office,#span_office").hide();
+        $j("#html").click();
+        console.log("office caché !");
     } else if(target=="notifications") {
-        $("txt").style.display="none";
-        $("span_txt").style.display="none";
-        $("html").click();
-        $("html").checked = true;
-        $("office").style.display="none";
-        $("span_office").style.display="none";
+        $j("#txt,#span_txt,#office,#span_office").hide();
+        $j("#html").click();
     } else if (target=="attachments"){
-    	$("template_attachment_type_tr").style.display="inline";
+        $j("#txt,#span_txt,#html,#span_html").hide();
+        $j("#office").click();
+        $j("#template_attachment_type_tr").css({"display":"inline"});
+    } else if(target=="doctypes") {
+        $j("#txt,#span_txt,#office,#span_office").hide();
+        $j("#html").click();
     }
 
     if (target != "attachments") {
-    	$("template_attachment_type").selectedIndex="0";
+    	$j("#template_attachment_type").selectedIndex="0";
     }
-
 }
 
 function select_template(path_to_script, attachment_type)
diff --git a/modules/templates/templates_management.php b/modules/templates/templates_management.php
index 0b1ed9d99e3cf720ea71804d52deae9118fa30c3..5c7b0fd0b70247daa8f9a505fbb23b45079ec36d 100644
--- a/modules/templates/templates_management.php
+++ b/modules/templates/templates_management.php
@@ -137,8 +137,7 @@ if ($mode == 'list') {
                         ?>
                             <option value="<?php functions::xecho($_SESSION['m_admin']['templatesTargets'][$cptTarget]['id']);?>" <?php
                             if (isset($_SESSION['m_admin']['templates']['template_target'])
-                                && $_SESSION['m_admin']['templates']['template_target']
-                                    == $_SESSION['m_admin']['templatesTargets'][$cptTarget]['id']
+                                && $_SESSION['m_admin']['templates']['template_target'] == $_SESSION['m_admin']['templatesTargets'][$cptTarget]['id']
                             ) {
                                 echo 'selected="selected"';
                             }
@@ -184,6 +183,7 @@ if ($mode == 'list') {
                         onClick="javascript:show_special_form_3_elements('txt_div', 'html_div', 'office_div');" <?php
                         echo $checkedTXT;?>/> <span id="span_txt"><?php echo _TXT;?></span>
                 </p>
+                <script>setradiobutton($j("#template_target").val());</script>
                 <p>
                     <label for="template_datasource"><?php echo _TEMPLATE_DATASOURCE;?> : </label>
                     <select name="template_datasource" id="template_datasource">
@@ -197,8 +197,7 @@ if ($mode == 'list') {
                         ?>
                             <option value="<?php functions::xecho($_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['id']);?>" <?php
                             if (isset($_SESSION['m_admin']['templates']['template_datasource'])
-                                && $_SESSION['m_admin']['templates']['template_datasource']
-                                    == $_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['id']
+                                && $_SESSION['m_admin']['templates']['template_datasource'] == $_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['id']
                             ) {
                                 echo 'selected="selected"';
                             }
@@ -257,9 +256,8 @@ if ($mode == 'list') {
                                         functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileExt']); echo ': ';
                                         functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']);
                                     ?>" <?php
-                                    if (isset($_SESSION['m_admin']['templates']['template_style'])
-                                        && $_SESSION['m_admin']['templates']['template_style']
-                                            == $_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']
+                                    if(isset($_SESSION['m_admin']['templates']['template_style'])
+                                        && $_SESSION['m_admin']['templates']['template_style'] == $_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']
                                     ) {
                                         echo 'selected="selected"';
                                     }
@@ -445,35 +443,6 @@ if ($mode == 'list') {
                 </script>
                 <?php
             }
-
-            if (isset($_SESSION['m_admin']['templates']['template_target'])
-                && $_SESSION['m_admin']['templates']['template_target']
-                    == "notes"
-            ) {
-                ?>
-                <script>
-                    setradiobutton("notes");
-                </script>
-                <?php                
-            } else if (isset($_SESSION['m_admin']['templates']['template_target'])
-                && $_SESSION['m_admin']['templates']['template_target']
-                    == "notifications"
-            ) {
-                ?>
-                <script>
-                    setradiobutton("notifications");
-                </script>
-                <?php                
-            } else if (isset($_SESSION['m_admin']['templates']['template_target'])
-                && $_SESSION['m_admin']['templates']['template_target']
-                    == "attachments"
-            ) {
-                ?>
-                <script>
-                    setradiobutton("attachments");
-                </script>
-                <?php                
-            }
         }
         ?>
     </div>