/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

// register xtype

Ext.onReady(function(){

    if(Ext.get('past_issues')) {

      var options = document.forms.issueForm.issueNo.options;
      var size = options.length;
      var myStore = new Array(size);
      var selected = options[document.forms.issueForm.issueNo.selectedIndex].text;
      for (var i = 0; i < size; i++) {
        myStore[i] = [options[i].text, options[i].value, options[i].className];
      }

      delete options; 

      // simple array store
      var store = new Ext.data.SimpleStore({
          fields: ['label', 'value','class'],
          data : myStore 
      });

      var issuesConverted = new Ext.ux.HasAccessCombo({
          store: store,
          displayField:'label',
          valueField:'value',
          fieldClass:'class',
          typeAhead: true,
          mode: 'local',
          editable: false, 
          triggerAction: 'all',
          width:195,
          listClass : 'small',
          forceSelection:true,
          transform: 'past_issues',
          emptyText: (selected == "") ? "Select an issue..." : selected,
          triggerAction: 'all',
          selectOnFocus:true,
          listeners: {
            'select': function() {
                         document.forms.issueForm.submit();
                       }
          }
      });

    }

    if(Ext.get('past_pages')) {

      var options = document.forms.pageForm.page.options;
      var size = options.length;
      var myStore = new Array(size);
      var selected = options[document.forms.pageForm.page.selectedIndex].text;

      for (var i = 0; i < size; i++) {
        myStore[i] = [options[i].text, options[i].value, options[i].className];
      }

      delete options; 

      // simple array store
      var store = new Ext.data.SimpleStore({
          fields: ['label', 'value','class'],
          data : myStore 
      });

      var pagesConverted = new Ext.ux.HasAccessCombo({
          store: store,
          displayField:'label',
          valueField:'value',
          fieldClass:'class',
          typeAhead: true,
          mode: 'local',
          editable: false, 
          triggerAction: 'all',
          width:195,
          listClass : 'small',
          forceSelection:true,
          selectOnFocus:true,
          transform: 'past_pages',
          triggerAction: 'all',
          emptyText:(selected == "") ? "Select a page..." : selected,
          selectOnFocus:true,
          listeners: {
            'select': function() {
                         document.forms.pageForm.submit();
                       }
          }
      });

    }

    if(Ext.get('magazines')) {

      var options = document.forms.magazines_form.magazine.options;
      var size = options.length;
      var myStore = new Array(size);

      for (var i = 0; i < size; i++) {
        myStore[i] = [options[i].text, options[i].value, options[i].className];
      }

      delete options; 

      // simple array store
      var store = new Ext.data.SimpleStore({
          fields: ['label', 'value','class'],
          data : myStore 
      });

      var magazinesConverted = new Ext.ux.HasAccessCombo({
          store: store,
          displayField:'label',
          valueField:'value',
          fieldClass:'class',
          typeAhead: true,
          mode: 'local',
          editable: false, 
          triggerAction: 'all',
          width:195,
          listClass : 'small',
          forceSelection:true,
          selectOnFocus:true,
          transform: 'magazines',
          triggerAction: 'all',
          emptyText:'Select a magazine...',
          selectOnFocus:true,
          listeners: {
            'select': function() {
                         window.location = document.magazines_form.magazine.value;
                       }
          }
      });

    }


    if(Ext.get('supplements')) {

      var options = document.forms.supplements_form.supplement.options;
      var size = options.length;
      var myStore = new Array(size);

      for (var i = 0; i < size; i++) {
        myStore[i] = [options[i].text, options[i].value, options[i].className];
      }

      delete options; 

      // simple array store
      var store = new Ext.data.SimpleStore({
          fields: ['label', 'value','class'],
          data : myStore 
      });

      var supplementsConverted = new Ext.ux.HasAccessCombo({
          store: store,
          displayField:'label',
          valueField:'value',
          fieldClass:'class',
          typeAhead: true,
          mode: 'local',
          editable: false, 
          triggerAction: 'all',
          width:195,
          listWidth: 300,
          listClass : 'small',
          forceSelection:true,
          selectOnFocus:true,
          transform: 'supplements',
          triggerAction: 'all',
          emptyText:'Select a special report...',
          selectOnFocus:true,
          listeners: {
            'select': function() {
                         window.location = document.supplements_form.supplement.value;
                       }
          }
      });

    }

});

