﻿// Javascript File
Faq = function(isBlueBox)
{
    this.isBlueBox = isBlueBox;
    this.data = eval(AJAX.API.GetFaqCategories().value);
    this.dataStore = new Ext.data.SimpleStore({'id': 0,fields: ['value', 'text', 'class', 'type'],data : this.data}); 
    //this.divHeights = new Array(this.dataStore.totalLength-1);
    this.faqCategories = new Ext.form.ComboBox({
        typeAhead: false,
        transform: "faqCategory",
        store:this.dataStore,
        width:230,
        forceSelection:true,
        editable: false,    
        mode: 'local',
        valueField: 'value',
        displayField: 'text', 
        tpl: '<div class="x-combo-list-item"><div class="{class}">{text}</div></div>',
        allowBlank:false
    });

    this.faqCategories.on('beforequery', this.onBeforeQuery, this);
    this.faqCategories.on('select', this.onFaqCategorySelect, this);
    this.faqCategories.setValue("ALL");
}
Ext.extend(Faq, Ext.util.Observable, {
    
   onBeforeQuery: function(combo, e)
   {
    combo.forceAll = true;
    combo.query="";
   },   
   onFaqCategorySelect: function(combo, record, index) {


       if (record.data.value=='ALL'){
           for(i=0;i<this.dataStore.totalLength;i++){
             // show all category divs
             if(this.dataStore.data.items[i].id != 'ALL'){
                divID = eval(this.dataStore.data.items[i].id);
                document.getElementById(divID).style.display = 'block';
             }
           }
       }else{
            var divID;
            for(i=0;i<this.dataStore.totalLength;i++){
                //first go and hide all the category divs
                if(this.dataStore.data.items[i].id != 'ALL'){ 
                    divID = eval(this.dataStore.data.items[i].id);
                    document.getElementById(divID).style.display = 'none';
                }
            }
            for(i=0;i<this.dataStore.totalLength;i++){
                // then show it if the div ID matches the drop-down selection
                if(this.dataStore.data.items[i].id != 'ALL'){
                    divID = this.dataStore.data.items[i].id;
                    if(divID == record.data.value){
                        document.getElementById(divID).style.display = 'block';
                    }else{
                        document.getElementById(divID).style.display = 'none';
                    }
                }
            }
        }
    }
});
