to avoid a little warning
[old-projects.git] / philter / philter / include / philter.js
index 834f07c..e574de5 100644 (file)
@@ -21,15 +21,12 @@ function cleanChilds(Node, nbChilds) {
         Node.removeChild(Node.childNodes[nbChilds]);
 }
 
-function getElement(obj) {
-    return getNthElement(obj,0);
-}
-
-function getNthElement(obj, index) {
-    if(document.getElementsByName)
-        return document.getElementsByName(obj)[index];
+function getElement(obj, index) {
+    if(document.getElementById)
+        return document.getElementById(obj);
     if(document.all)
-        return document.all[obj][index];
+        return document.all[obj];
+    return false;
 }
 
 /********** ORDER FORM FUNCTIONS **********/
@@ -103,16 +100,17 @@ var matches_i = 0;
 function createActionSelect(data,base) {
     var i,j;
     var select = document.createElement("select");
+    var sel = 0;
     select.name = base+'[0]';
 
-    for(i=0, j=0; i<actions_list.length; i++)
-        if(actions_list[i])
-            select.options[j++] = new Option(actions_list[i],i,false,(data==i));
-
-    select.setAttribute("onchange", "changeRow(this,actions_func)");
+    for(i=0, j=0; i<actions_list.length; i++) {
+        if(data==i) sel = j;
+        if(actions_list[i]) select.options[j++] = new Option(actions_list[i],i,false,(data==i));
+    }
 
-    if(select.selectedIndex<0)
-        select.selectedIndex = 0;
+    select.selectedIndex = sel;
+    select.onchange = function () { changeRow(this,actions_func); };
+    
     return select;
 }
 
@@ -126,7 +124,7 @@ function createActionRow(Node,data) {
     var del = document.createElement("input");
     del.setAttribute("type", "submit");
     del.setAttribute("value", "Del");
-    del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
+    del.onclick = function () { del.parentNode.parentNode.removeChild(del.parentNode); };
     div.appendChild(del);
 
     div.appendChild(document.createTextNode(" "));
@@ -138,7 +136,7 @@ function createActionRow(Node,data) {
 }
 
 function newAction() {
-    createActionRow(getElement('actions_row'), 0);
+    createActionRow(getElement('actionsRow'), [-1]);
 }
 
 /********** RULE.MATCH FORM FUNCTIONS **********/
@@ -146,16 +144,17 @@ function newAction() {
 function createMatchSelect(data,base) {
     var i,j;
     var select = document.createElement("select");
+    var sel = 0;
     select.name = base+'[0]';
 
-    for(i=0, j=0; i<matches_list.length; i++)
-        if(matches_list[i])
-            select.options[j++] = new Option(matches_list[i],i,false,(data==i));
+    for(i=0, j=0; i<matches_list.length; i++) {
+        if(data==i) sel = j;
+        if(matches_list[i]) select.options[j++] = new Option(matches_list[i],i,false,(data==i));
+    }
 
-    select.setAttribute("onchange", "changeRow(this,matches_func)");
+    select.selectedIndex = sel;
+    select.onchange = function () { changeRow(this,matches_func); };
 
-    if(select.selectedIndex<0)
-        select.selectedIndex = 0;
     return select;
 }
 
@@ -169,7 +168,7 @@ function createMatchRow(Node,data) {
     var del = document.createElement("input");
     del.setAttribute("type", "submit");
     del.setAttribute("value", "Del");
-    del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
+    del.onclick = function () { del.parentNode.parentNode.removeChild(del.parentNode); };
     div.appendChild(del);
 
     div.appendChild(document.createTextNode(" "));
@@ -181,7 +180,7 @@ function createMatchRow(Node,data) {
 }
 
 function newMatch() {
-    createMatchRow(getElement('matches_row'), 0);
+    createMatchRow(getElement('matchesRow'), [-1]);
 }
 
 /********** RULE FORM FUNCTIONS **********/
@@ -202,15 +201,16 @@ function createRuleForm() {
 
     getElement('rule[id]').value = index;
     getElement('rule[name]').value = current_rule.name;
-    getNthElement('rule[all]',[1-current_rule.all]).checked = true;
+    var c = (current_rule.all ? '1' : '0');
+    getElement('rule[all'+c+']').checked = true;
     getElement('rule[block]').checked = current_rule.block;
 
-    var mr = getElement('matches_row');
+    var mr = getElement('matchesRow');
     cleanChilds(mr,0);
     for(i=0; i<current_rule.matches.length; i++)
         createMatchRow(mr, current_rule.matches[i]);
     
-    var ar = getElement('actions_row');
+    var ar = getElement('actionsRow');
     cleanChilds(ar,0);
     for(i=0; i<current_rule.actions.length; i++)
         createActionRow(ar, current_rule.actions[i]);