1   /* CheckArray - used to enable or disable toolbar images if items are checked or unchecked*/
  2   function CheckArray()
  3   { /* class properties */
  4   //alert('test');
  5     this.paste_ = false;
  6     this.ImageList = new Array(); // 2D array to hold image information
  7                                   //[x][0] = image ID
  8                                   //[x][1] = 'on' URL
  9                                   //[x][2] = 'off' URL
  10                                   //[x][3] = min. # of items required for 'on' state
  11     this.CheckList = new Array(); // 1D array that contains document IDs for checkboxes
  12     this.CheckValues = new Array();//1D array that contains values for each checkbox
  13     this.itemschecked=0;          // number of checked items
  14     this.formname = null;         // name of form containing checkboxes
  15     this.envar = null;            // envar of the document (from the query_string)
  16     this.uncheckClassName = new Array();   //class to set element class to when unchecking item
  17     /* class methods */
  18     this.addImage = addImage;         //adds an image to the image array
  19     this.selectAll = selectAll;       //set all check boxes to a value (true/false)
  20     this.invertItems = invertItems;   //invert all checkboxes
  21     this.addCheck = addCheck;         //called when an item is checked
  22     this.removeCheck = removeCheck;   //called when an item is unchecked
  23     this.setImages = setImages;       //used to set images to their on or off state 
  24     this.check_submit = check_submit; //called to submit the form
  25     this.itemChecked=itemChecked;     //returns true if at least 1 item is checked
  26     this.countChecks=countChecks;     //returns the # of checked items
  27     this.getItemList=getItemList;     //returns an array of the IDs currently checked
  28   }
  29  
  30   function addImage(Id,onURL,offURL,count)
  31   {
  32       img = new Array(Id,onURL,offURL,count);
  33       this.ImageList[this.ImageList.length] = img;
  34   }
  35  
  36   function itemChecked()
  37   {
  38       if(this.itemschecked>0)
  39       {
  40           return true;
  41       }
  42       else
  43       {
  44           return false;
  45       }
  46   }
  47  
  48   function selectAll(value)
  49   {
  50           checkcount = this.CheckList.length;
  51           for(var i=0; i<checkcount; i++)
  52           {    
  53                   var ob = document.getElementById(this.CheckList[i]);   
  54           var inputs = ob.getElementsByTagName("INPUT");
  55  
  56           for (var j = 0; j < inputs.length; j++)
  57           {         
  58               if (inputs[j].type == "checkbox")
  59               {
  60                 if(inputs[j].checked != value)
  61                 {
  62                   inputs[j].checked = value;
  63                   if(value==true)
  64                   { 
  65                            this.addCheck(ob.id);
  66                   }
  67                   else
  68                   {       
  69                    this.removeCheck(ob.id);
  70                   }
  71                 }
  72               }
  73           }       
  74        }
  75   }
  76  
  77   function invertItems()
  78   {
  79           checkcount = this.CheckList.length;
  80           for(var i=0; i<checkcount; i++)
  81           {       
  82                   ob = document.getElementById(this.CheckList[i]);   
  83           var inputs = ob.getElementsByTagName("INPUT");
  84           for (var j = 0; j < inputs.length; j++)
  85           {         
  86             if (inputs[j].type == "checkbox")
  87             {
  88                 value = inputs[j].checked;
  89                 if(value == false)
  90                 { 
  91                     inputs[j].checked = true;
  92                     this.addCheck(ob.id);
  93                 }
  94                 else
  95                 {  
  96                    inputs[j].checked = false;
  97                    this.removeCheck(ob.id);
  98                 }             
  99             }
  100           }       
  101        }
  102   }
  103  
  104   function addCheck(el_id)
  105   {
  106       el = document.getElementById(el_id);
  107           this.itemschecked++;   
  108           this.setImages();
  109       this.uncheckClassName[el.id] = el.className;
  110           el.className = 'selection';   
  111       idval = parseInt(el.id);
  112       //alert(el_id+'='+idval);
  113       this.CheckValues[el_id]=1;
  114   }
  115  
  116   function removeCheck(el_id)
  117   {
  118       el = document.getElementById(el_id);
  119           this.itemschecked--;
  120           this.setImages();
  121           el.className = this.uncheckClassName[el.id];   
  122       idval = parseInt(el.id);
  123       //alert(el_id+'='+idval);
  124       this.CheckValues[el_id]=0;
  125  
  126   }
  127  
  128   function countChecks()
  129   {
  130       return this.itemschecked;
  131   }
  132  
  133   function setImages()
  134   {
  135       for(var i=0; i<this.ImageList.length; i++)
  136       {
  137           id = this.ImageList[i][0];
  138           img = document.getElementById(id);
  139           if(img)
  140           {       
  141             if(this.itemschecked < this.ImageList[i][3])
  142             {              
  143               img.src=this.ImageList[i][2];
  144             }
  145             else
  146             {
  147               img.src=this.ImageList[i][1];
  148             }
  149           }
  150           else
  151               alert('An Image [' +id+ '] not found');
  152       }
  153   }
  154  
  155   function getItemList()
  156   {
  157       var res = new Array();
  158  
  159           for(var i=0; i<this.CheckList.length; i++)
  160           {
  161           if(this.CheckValues[this.CheckList[i]]>0)
  162           {
  163                 res[res.length] = this.CheckList[i];
  164           }
  165       }
  166       return res;
  167   }
  168  
  169   function check_submit(location, ActionValue, EnvVar)
  170   {   
  171           if( ActionValue.match(/_del/) || ActionValue.match(/del_/) )
  172                   if (!theMainScript.Confirm(lang_DeleteConfirm)) return
  173           
  174       f = document.getElementById(this.formname);
  175       if(f)
  176       {   
  177         f.Action.value = ActionValue;
  178         f.action = location + '.php?' + this.envar;
  179         if(EnvVar != null) f.action += EnvVar;
  180         //alert(f.name+ ' is submitting to '+ f.action + ' action=' + f.Action.value);
  181                   f.submit();
  182       }
  183       else
  184           alert('Form ' + this.formname + ' was not found.');
  185   }