var optionsPluginObjectId = 0;
var optionsPluginObjectCollection = [];

function optionsPlugIn (selectBoxSelector, valueFields) {
   this.selectBoxSelector = selectBoxSelector;
   this.valueFields = valueFields;
   this.selectBox = null;
   this.OID = optionsPluginObjectId;
   optionsPluginObjectCollection[this.OID] = this;

   this.init = function() {
      this.selectBox = $(this.selectBoxSelector);
      if (this.selectBox.length > 0) {
         this.selectBox.attr('optionspluginobjectid',this.OID);
         for (i in this.valueFields) {
            for (j in this.valueFields[i]) {
               $(this.valueFields[i][j]).addClass('optionspluginshowable_'+this.OID);
               $(this.valueFields[i][j]).hide();
            }
         }
         this.selectBox.change(function(){
            if (typeof(optionsPluginObjectCollection[$(this).attr('optionspluginobjectid')]) != 'undefined') {
               try {
                  optionsPluginObjectCollection[$(this).attr('optionspluginobjectid')].showFields($(this).val());
               } catch (e) {}
            }
         });
      }
   };

   this.showFields = function(theVal) {
      $('.optionspluginshowable_'+this.OID).hide();
      if (typeof(this.valueFields[theVal]) != 'undefined') {
         for (i in this.valueFields[theVal]) {
            if (i.match(/^[0-9]*$/)) {
               $(this.valueFields[theVal][i]).show();
            }
         }
      }
   };

   this.init();
   optionsPluginObjectId++;

}

