Index: extensions/event_cats/admin/template/autolog_new.js
===================================================================
--- extensions/event_cats/admin/template/autolog_new.js	(revision 4116)
+++ extensions/event_cats/admin/template/autolog_new.js	(revision 4157)
@@ -4,7 +4,9 @@
 var ec_is_creation              = true;
 var ec_chk_nover_cat            = true;
+var ec_chk_over_grp             = true;
 var ec_flag1                    = false;
 var ec_flag2                    = false;
 var ec_dont_check               = false;
+var ec_selected_old_group       = false;
 var ec_err                      = '';
 var ec_selected_img             = '';
@@ -12,4 +14,5 @@
 var ec_new_user_text            = '';
 var ec_new_psd_text             = '';
+var ec_new_grp_text             = '';
 var ec_old_new_psd_text         = '';
 var ec_test_reg                 = '';
@@ -20,7 +23,7 @@
 var ec_selected_old_entry       = '-1';
 var ec_selected_old_code        = '-1';
-var ec_selected_old_code2       = '-1';
+// var ec_selected_old_code2       = '-1';
 var ec_selected_old_user        = '-1';
-var ec_selected_old_user2       = '-1';
+// var ec_selected_old_user2       = '-1';
 var ec_selected_AP              = '-1';
 var ec_selected_cat             = '-1';
@@ -30,6 +33,6 @@
 var ec_JS_message               = new Array();
 var ec_duplic_codes             = new Array();
+var ec_lists_temp               = new Array();
 var ec_lists                    = new Array();
-    ec_lists['code']            = new Array();
     ec_lists['user_id']         = new Array();
     ec_lists['action']          = new Array();
@@ -51,8 +54,17 @@
 }
 
+function ec_check_exist_innerHTML(ec_id, ec_val) {
+  var e = document.getElementById(ec_id);
+  for (var i = 0; i < e.length; i++) {
+    if (e.options[i].innerHTML == ec_val) return true;
+  }
+  return false;
+}
+
 function ec_mark_entry(ec_id) {
   var i = 0;
   if (ec_id == '-1') de('ec_in_up_entry_list_id').selectedIndex = '-1';
   else {
+    de('ec_in_up_entry_list_id').value = ec_id;
     de('ec_act2_id').value = ec_id;
     if (
@@ -116,9 +128,5 @@
     ) {
       var t1 = '';
-      /* if (ec_id == 'ec_sel_code_old' && ec_selected_old_code == '-1') {
-        ec_selected_code = 'ec_sel_code_new';
-        ec_selected_old_code = ec_selected_old_code2;
-      }
-      else */ ec_selected_code = ec_id;
+      ec_selected_code = ec_id;
       de(ec_selected_code).checked = 'checked';
       switch (ec_selected_code) {
@@ -127,14 +135,19 @@
           de('ec_in_up_code_list_id').selectedIndex = '-1';
           de('ec_in_up_code_id').value              = ec_new_code_text;
+          de('ec_in_up_grp_txt_id').value           = ec_new_grp_text;
+          de('ec_in_up_newgroup_id').checked        =
+           (ec_selected_old_group) ? 'checked' : '';
           de('ec_act2_id').value                    = '-1';
         break;
         case 'ec_sel_code_old':
-          de('ec_act1_id').value            = 'duplicate_entry_submit';
-          de('ec_act2_id').value            = ec_selected_old_code;
-          de('ec_in_up_code_list_id').value = ec_selected_old_code;
-          de('ec_in_up_code_id').value      = '';
-          t1                                = 'disabled';
-          ec_selected_user                  = 'ec_sel_user_old';
-          ec_selected_old_user              =
+          de('ec_act1_id').value             = 'duplicate_entry_submit';
+          de('ec_act2_id').value             = ec_selected_old_code;
+          de('ec_in_up_code_list_id').value  = ec_selected_old_code;
+          de('ec_in_up_grp_txt_id').value    = '';
+          de('ec_in_up_newgroup_id').checked = '';
+          de('ec_in_up_code_id').value       = '';
+          t1                                 = 'disabled';
+          ec_selected_user                   = 'ec_sel_user_old';
+          ec_selected_old_user               =
            ec_lists['user_id'][ec_selected_old_code];
           ec_flag1 = true;
@@ -147,4 +160,6 @@
       de('ec_in_up_usr_txt_id').disabled   = t1;
       de('ec_in_up_psd_txt_id').disabled   = t1;
+      de('ec_in_up_newgroup_id').disabled  = t1;
+      de('ec_in_up_grp_txt_id').disabled   = t1;
       de('ec_sel_user_old').disabled       = t1;
       de('ec_in_up_usr_list_id').disabled  = t1;
@@ -172,10 +187,5 @@
      de('ec_sel_user_old').disabled == true)
     ) {
-      /* if (ec_id == 'ec_sel_user_old' && ec_selected_old_user == '-1') {
-        ec_selected_user =
-         (ec_is_creation) ? 'ec_sel_user_new' : 'ec_sel_user_none';
-        ec_selected_old_user = ec_selected_old_user2;
-      }
-      else */ ec_selected_user = ec_id;
+      ec_selected_user = ec_id;
       de(ec_selected_user).checked = 'checked';
       switch (ec_selected_user) {
@@ -184,6 +194,8 @@
            (ec_ap_ok && (ec_selected_action != 'ec_input_action_refused')) ?
            'ec_input_action_add_p' : 'ec_input_action_refused';
-          de('ec_in_up_usr_txt_id').value = '';
-          de('ec_in_up_psd_txt_id').value = '';
+          de('ec_in_up_usr_txt_id').value          = '';
+          de('ec_in_up_psd_txt_id').value          = '';
+          de('ec_in_up_grp_txt_id').value          = '';
+          de('ec_in_up_newgroup_id').checked       = '';
           de('ec_in_up_usr_list_id').selectedIndex = '-1';
         break;
@@ -191,6 +203,10 @@
           if (ec_selected_action == 'ec_input_action_refused')
            ec_selected_action = 'ec_input_action_home';
-          de('ec_in_up_usr_txt_id').value = ec_new_user_text;
-          de('ec_in_up_psd_txt_id').value = ec_new_psd_text;
+          de('ec_in_up_usr_txt_id').value          = ec_new_user_text;
+          de('ec_in_up_psd_txt_id').value          = ec_new_psd_text;
+          de('ec_in_up_grp_txt_id').value          =
+           (ec_selected_old_group) ? ec_new_grp_text : '';
+          de('ec_in_up_newgroup_id').checked       =
+           (ec_selected_old_group) ? 'checked' : '';
           de('ec_in_up_usr_list_id').selectedIndex = '-1';
         break;
@@ -198,8 +214,9 @@
           if (ec_selected_action == 'ec_input_action_refused')
            ec_selected_action = 'ec_input_action_home';
-          de('ec_in_up_usr_txt_id').value = '';
-          de('ec_in_up_psd_txt_id').value = '';
-          de('ec_in_up_usr_list_id').value =
-           ec_selected_old_user;
+          de('ec_in_up_usr_txt_id').value    = '';
+          de('ec_in_up_psd_txt_id').value    = '';
+          de('ec_in_up_grp_txt_id').value    = '';
+          de('ec_in_up_newgroup_id').checked = '';
+          de('ec_in_up_usr_list_id').value   = ec_selected_old_user;
         break;
       }
@@ -364,5 +381,5 @@
     ec_new_code_text = t;
   }
-  ec_mark_code('ec_sel_code_new');
+  if (ec_check_code_text(ec_new_code_text)) ec_mark_code('ec_sel_code_new');
 }
 
@@ -394,42 +411,45 @@
       ec_new_psd_text = t;
       ec_old_new_psd_text = ec_new_psd_text;
-    }
-    switch (ec_selected_action) {
-      case 'ec_input_action_add_p': // Additional Page
-        ec_new_user_text = ec_reg_ap.exec(
-         d.ec_new_code.ec_in_up_aps.options[
-          d.ec_new_code.ec_in_up_aps.selectedIndex
-         ].label
-        );
-      break;
-      case 'ec_input_action_cat': // Category
-      case 'ec_input_action_img': // Image
-        ec_cat_sel = d.ec_new_code.ec_in_up_cat.options[
-          d.ec_new_code.ec_in_up_cat.selectedIndex
-         ].label;
-        ec_new_user_text = (ec_reg_cat2.test(ec_cat_sel)) ?
-         ec_reg_cat1.exec(ec_cat_sel)[1] : ec_cat_sel;
-      if (ec_selected_action == 'ec_input_action_img') {
-        ec_new_user_text +=  '_' + d.ec_new_code.ec_in_up_imgs_id.value;
-      }
-      break;
-      case 'ec_input_action_home': // Home
-        t = ec_gen_txt('3');
-        if (t == '') {
-          alert("Failed :\n" + ec_err);
-          ec_new_psd_text = 'Failed...';
-          return false;
+      switch (ec_selected_action) {
+        case 'ec_input_action_add_p': // Additional Page
+          ec_new_user_text = ec_reg_ap.exec(
+           d.ec_new_code.ec_in_up_aps.options[
+            d.ec_new_code.ec_in_up_aps.selectedIndex
+           ].label
+          );
+        break;
+        case 'ec_input_action_cat': // Category
+        case 'ec_input_action_img': // Image
+          ec_cat_sel = d.ec_new_code.ec_in_up_cat.options[
+            d.ec_new_code.ec_in_up_cat.selectedIndex
+           ].label;
+          ec_new_user_text = (ec_reg_cat2.test(ec_cat_sel)) ?
+           ec_reg_cat1.exec(ec_cat_sel)[1] : ec_cat_sel;
+          ec_new_user_text = ec_new_user_text.replace(/\s/, '_');
+        if (ec_selected_action == 'ec_input_action_img') {
+          ec_new_user_text +=  '_' + d.ec_new_code.ec_in_up_imgs_id.value;
         }
-        ec_new_user_text = ec_JS_message['ec_up_code_lbl_home'] + '_' + t;
-      break;
-    }
-    ec_flag1 = true;
-    ec_mark_user('ec_sel_user_new');
-    ec_flag1 = false;
-    return true;
+        break;
+        case 'ec_input_action_home': // Home
+          t = ec_gen_txt('3');
+          if (t == '') {
+            alert("Failed :\n" + ec_err);
+            ec_new_psd_text = 'Failed...';
+            return false;
+          }
+          ec_new_user_text = ec_JS_message['ec_up_code_lbl_home'] + '_' + t;
+        break;
+      }
+      if (ec_selected_old_group) ec_new_grp_text = 'EC_' + ec_new_user_text;
+      ec_flag1 = true;
+      ec_mark_user('ec_sel_user_new');
+      ec_flag1 = false;
+      return ec_check_user_text();
+    }
   }
 }
 
 function ec_gen_full_auto() {
+  ec_selected_old_group = true;
   if (ec_gen_user()) ec_gen_code();
 }
@@ -449,17 +469,48 @@
 }
 
+function ec_check_user_text() {
+  if (ec_check_exist_innerHTML('ec_in_up_usr_list_id', ec_new_user_text)) {
+    alert(ec_JS_message['ec_user_already_exists']);
+    ec_new_user_text = '';
+    ec_mark_user('ec_sel_user_new');
+    return false;
+  }
+}
+
 function ec_check_pwd_text() {
-  de('ec_in_up_pwd_warn').innerHTML = (
+  if (
    de('ec_in_up_psd_txt_id').value == ec_old_new_psd_text
    && ec_old_new_psd_text != ''
    && ec_selected_user == 'ec_sel_user_new'
-  ) ? ec_JS_message['ec_new_pwd_gen'] : '';
-}
-
-function ec_check_code_text() {
-  var t    = de('ec_in_up_code_id').value;
-  var treg = /^[a-zA-Z0-9_-]{4,32}$/
-  if (t == '' || treg.test(t) || t == NULL) {
+  ) {
+    de('ec_in_up_pwd_warn1').innerHTML = ec_JS_message['ec_new_pwd_gen1'];
+    de('ec_in_up_pwd_warn2').innerHTML = ec_JS_message['ec_new_pwd_gen2'];
+  }
+  else {
+    de('ec_in_up_pwd_warn1').innerHTML = '';
+    de('ec_in_up_pwd_warn2').innerHTML = '';
+  }
+}
+
+function ec_check_grp_text() {
+  if (ec_chk_over_grp) {
+    de('ec_in_up_newgroup_id').checked =
+     (de('ec_in_up_newgroup_id').checked == '') ? 'checked' : '';
+    ec_chk_over_grp = false;
+  }
+  ec_selected_old_group = (de('ec_in_up_newgroup_id').checked != '');
+}
+
+function ec_check_code_text(t) {
+  var treg = /^[a-zA-Z0-9_-]{4,32}$/;
+  if (ec_check_exist_innerHTML('ec_in_up_code_list_id', t)) {
+    alert(ec_JS_message['ec_code_already_exists']);
+    ec_new_code_text = '';
+    de('ec_in_up_code_id').value = '';
+    return false;
+  }
+  else if (t == '' || treg.test(t) || t == NULL) {
     ec_new_code_text = t;
+    return true;
   }
   else {
@@ -467,4 +518,5 @@
     ec_new_code_text = '';
     de('ec_in_up_code_id').value = '';
+    return false;
   }
 }
@@ -496,5 +548,5 @@
       !t1 && ((
           de('ec_input_action_add_p').checked != '' &&
-          d.ec_new_code.ec_in_up_aps.selectedIndex < 1
+          d.ec_new_code.ec_in_up_aps.selectedIndex == '-1'
         ) || (
         de('ec_input_action_add_p').checked == '' &&
@@ -506,5 +558,5 @@
       return false;
     }
-    if (de('ec_in_up_entry_list_id').selectedIndex ==0) {
+    if (de('ec_in_up_entry_list_id').selectedIndex == '-1') {
       alert(ec_JS_message['ec_act_entry_miss']);
       return false;
@@ -527,10 +579,10 @@
   }
   if (
-    d.ec_new_code.ec_in_up_aps.selectedIndex < 1 &&
-    d.ec_new_code.ec_in_up_cat.selectedIndex < 1 && (
+    d.ec_new_code.ec_in_up_aps.selectedIndex == '-1' &&
+    d.ec_new_code.ec_in_up_cat.selectedIndex == '-1' && (
       de('ec_in_up_imgs_id').value == '' || (
         de('ec_in_up_imgs_id').value != '' && (
           isNaN(de('ec_in_up_imgs_id').value) ||
-          d.ec_new_code.ec_in_up_cat.selectedIndex < 1
+          d.ec_new_code.ec_in_up_cat.selectedIndex == '-1'
         )
       )
@@ -549,5 +601,5 @@
 
 function ec_change_user_list(ec_id) {
-  ec_selected_old_user2 = ec_selected_old_user;
+  // ec_selected_old_user2 = ec_selected_old_user;
   ec_selected_old_user = ec_id;
   ec_mark_user('ec_sel_user_old');
@@ -555,5 +607,5 @@
 
 function ec_change_code_list(ec_id) {
-  ec_selected_old_code2 = ec_selected_old_code;
+  // ec_selected_old_code2 = ec_selected_old_code;
   ec_selected_old_code = ec_id;
   ec_mark_code('ec_sel_code_old');
@@ -571,26 +623,44 @@
 }
 
+function ec_build_ec_lists() {
+  var t = new Array();
+  for (var i = 0; i < ec_lists_temp.length; i++) {
+    t = ec_lists_temp[i].split(';');
+    ec_lists['user_id'][t[0]] = t[1];
+    ec_lists['action'][t[0]] = t[2];
+    ec_lists['arg1'][t[0]] = t[3];
+    ec_lists['arg2'][t[0]] = t[4];
+    ec_lists['forced'][t[0]] = t[5];
+  }
+}
+
 function ec_init() {
-  ec_err                = '';
-  ec_selected_action    = '';
-  ec_selected_img       = '';
-  ec_new_code_text      = '';
-  ec_new_user_text      = '';
-  ec_new_psd_text       = '';
-  ec_old_new_psd_text   = '';
-  ec_test_reg           = '';
-  ec_selected_old_user  = '-1';
-  ec_selected_old_code  = '-1';
-  ec_selected_old_code2 = '-1';
-  ec_selected_AP        = '-1';
-  ec_selected_cat       = '-1';
-  ec_selected_old_user2 = '-1';
-  ec_selected_user      = '-1';
-  ec_selected_code      = '-1';
+  ec_selected_old_group                           = false;
+  ec_new_grp_text                                 = '';
+  ec_err                                          = '';
+  ec_selected_action                              = '';
+  ec_selected_img                                 = '';
+  ec_new_code_text                                = '';
+  ec_new_user_text                                = '';
+  ec_new_psd_text                                 = '';
+  ec_old_new_psd_text                             = '';
+  ec_test_reg                                     = '';
+  ec_selected_old_user                            = '-1';
+  ec_selected_old_code                            = '-1';
+  // ec_selected_old_code2                           = '-1';
+  ec_selected_AP                                  = '-1';
+  ec_selected_cat                                 = '-1';
+  // ec_selected_old_user2                           = '-1';
+  ec_selected_user                                = '-1';
+  ec_selected_code                                = '-1';
   de('ec_style_forced_id').innerHTML              = ec_up_code_lbl_forced_txt;
   de('ec_act1_id').value                          = ec_default_action;
+  de('ec_act2_id').value                          = '';
   de('ec_in_up_usr_txt_id').value                 = '';
   de('ec_in_up_psd_txt_id').value                 = '';
-  de('ec_in_up_pwd_warn').innerHTML               = '';
+  de('ec_in_up_grp_txt_id').value                 = '';
+  de('ec_in_up_newgroup_id').checked              = '';
+  de('ec_in_up_pwd_warn1').innerHTML              = '';
+  de('ec_in_up_pwd_warn2').innerHTML              = '';
   de('ec_in_up_aps_id').selectedIndex             = '-1';
   de('ec_in_up_cats_id').selectedIndex            = '-1';
@@ -625,4 +695,6 @@
       de('ec_in_up_usr_txt_id').disabled          = '';
       de('ec_in_up_psd_txt_id').disabled          = '';
+      de('ec_in_up_newgroup_id').disabled         = '';
+      de('ec_in_up_grp_txt_id').disabled          = '';
       de('ec_sel_user_old').disabled              = '';
       de('ec_in_up_usr_list_id').disabled         = '';
@@ -642,4 +714,6 @@
       de('ec_in_up_usr_txt_id').disabled          = 'disabled';
       de('ec_in_up_psd_txt_id').disabled          = 'disabled';
+      de('ec_in_up_newgroup_id').disabled         = 'disabled';
+      de('ec_in_up_grp_txt_id').disabled          = 'disabled';
       de('ec_sel_user_old').disabled              = 'disabled';
       de('ec_in_up_usr_list_id').disabled         = 'disabled';
@@ -670,5 +744,6 @@
       de('ec_in_up_usr_txt_id').disabled          = '';
       de('ec_in_up_psd_txt_id').disabled          = '';
-      de('ec_in_up_psd_txt_id').disabled          = '';
+      de('ec_in_up_newgroup_id').disabled         = '';
+      de('ec_in_up_grp_txt_id').disabled          = '';
       de('ec_in_up_usr_list_id').disabled         = '';
       de('ec_in_up_forced_id').disabled           = '';
@@ -690,4 +765,6 @@
       de('ec_in_up_psd_txt_id').disabled          = 'disabled';
       de('ec_in_up_psd_txt_id').disabled          = 'disabled';
+      de('ec_in_up_newgroup_id').disabled         = 'disabled';
+      de('ec_in_up_grp_txt_id').disabled          = 'disabled';
       de('ec_in_up_usr_list_id').disabled         = 'disabled';
       de('ec_in_up_forced_id').disabled           = 'disabled';
@@ -699,4 +776,5 @@
       de('ec_in_up_usr_list_id').selectedIndex    = '-1';
       de('ec_in_up_entry_list_id').value          = ec_default_entry;
+      de('ec_act2_id').value                      = ec_default_entry;
     }
     ec_default_action                             = 'modify_entry_ask';
