/**
 * @author jonathan
 */
var advancedSearch = function(){

    var forms = {
        member: new Ext.form.FormPanel({
            id: 'memberSearch',
            frame: true,
            layout: 'column',
            url: '/user/browse',
            standardSubmit:true,
			method:'POST',
            labelAlign: 'top',
            defaults: {
                columnWidth: '.5',
                layout: 'form'
            },
            items: [{
                items: [
				{
					xtype:'hidden',
					name:'advancedsearch',
					value:1
				},
				{
                    xtype: 'textfield',
                    fieldLabel: 'Member Name',
                    width: 225,
                    name: 'membername'
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Keywords',
                    emptyText: 'e.g. Dancing, Singer, Actor...',
                    width: 225,
                    name: 'keywords'
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Location',
                    emptyText: 'e.g. New York, NY',
                    width: 225,
                    name: 'location'
                }, {
                    layout: 'column',
                    items: [{
                        columnWidth: '.2',
                        layout: 'form',
                        items: [{
                            xtype: 'numberfield',
                            minValue: 18,
                            fieldLabel: 'Min Age',
                            name: 'agemin',
                            width: 50
                        }]
                    
                    }, {
                        columnWidth: '.5',
                        layout: 'form',
                        items: [{
                            xtype: 'numberfield',
                            minValue: 18,
                            fieldLabel: 'Max Age',
                            name: 'agemax',
                            width: 50
                        }]
                    }]
                }, {
                    xtype: 'combo',
                    fieldLabel: 'Gender',
                    width: 225,
                    displayField: 'description',
                    valueField: 'gender',
                    hiddenName: 'gender',
                    triggerAction: 'all',
                    mode: 'local',
                    emptyText: 'Limit your search by gender',
                    store: new Ext.data.SimpleStore({
                        fields: ['gender', 'description'],
                        data: [['M', 'Male'], ['F', 'Female'], ['G', 'Group']]
                    })
                }, {
                    xtype: 'combo',
                    fieldLabel: 'Category',
                    width: 225,
                    displayField: 'description',
                    valueField: 'categoryid',
                    hiddenName: 'categoryid',
                    triggerAction: 'all',
                    mode: 'local',
                    emptyText: 'Limit your search by category',
                    store: new Ext.data.JsonStore({
                        fields: ['categoryid', 'description'],
                        data: dateCategory
                    })
                
                }]
            }, {
                items: [{
                    xtype: 'combo',
                    fieldLabel: "Date Type",
                    width: 225,
                    displayField: 'description',
                    valueField: 'target',
                    hiddenName: 'target',
                    triggerAction: 'all',
                    value: 'forsale',
                    mode: 'local',
                    store: new Ext.data.SimpleStore({
                        fields: ['target', 'description'],
                        data: [['forsale', 'Dates for Sale'], ['wanted', 'Dates Wanted']]
                    })
                
                }, {
                    layout: 'column',
                    items: [{
                        columnWidth: '.2',
                        layout: 'form',
                        items: [{
                            xtype: 'numberfield',
                            minValue: 18,
                            fieldLabel: 'Min Price',
                            name: 'pricemin',
                            width: 50
                        }]
                    
                    }, {
                        columnWidth: '.5',
                        layout: 'form',
                        items: [{
                            xtype: 'numberfield',
                            minValue: 18,
                            fieldLabel: 'Max Price',
                            name: 'pricemax',
                            width: 50
                        }]
                    }]
                }, {
                    xtype: 'datefield',
                    format: 'm-d-Y',
                    fieldLabel: 'Start Date Range',
                    emptyText: 'Start date range',
                    width: 200,
                    name: 'startdaterange'
                }, {
                    xtype: 'datefield',
                    format: 'm-d-Y',
                    fieldLabel: 'End Date Range',
                    emptyText: 'End date range',
                    width: 200,
                    name: 'enddaterange'
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Nonprofit Beneficiary',
                    emptyText: 'e.g. Cancer Research, National Wildlife, etc.',
                    width: 225,
                    name: 'hasnonprofit'
                }, {
                    xtype: 'checkbox',
                    fieldLabel: 'Show only members with photos.',
                    inputValue: 1,
                    checked: true,
                    name: 'hasphotos'
                }, {
                    xtype: 'checkbox',
                    fieldLabel: 'Show only members with dates available.',
                    inputValue: 1,
                    checked: true,
                    name: 'hasdates'
                }, {
                    xtype: 'checkbox',
                    fieldLabel: 'Show only members who are online.',
                    inputValue: 1,
                    checked: false,
                    name: 'online'
                }]
            }],
            buttons: [{
                iconCls: 'btn-reset',
                text: 'Reset Form',
                handler: function(){
                    this.ownerCt.form.reset();
                }
            }, {
                iconCls: 'btn-edit',
                text: 'Search',
                handler: function(){
					this.ownerCt.getForm().getEl().dom.action='/user/browse';
                    this.ownerCt.getForm().submit();

                }
            }]
        }),
        nonprofit: new Ext.form.FormPanel({
            id: 'nonprofitSearch',
            frame: true,
            layout: 'form',
            url: '/charity/browse',
            method: 'GET',
            labelAlign: 'top',
			standardSubmit:true,
            items: [
				{
					xtype:'hidden',
					name:'advancedsearch',
					value:1
				},
			
			{
                xtype: 'textfield',
                fieldLabel: 'Nonprofit Name or Keyword',
                emptyText: 'e.g. Cancer Research, National Wildlife',
                width: 225,
                name: 'name'
            }, {
                xtype: 'combo',
                fieldLabel: 'Category/ Cause',
                width: 225,
                displayField: 'description',
                valueField: 'categoryid',
                hiddenName: 'categoryid',
                triggerAction: 'all',
                mode: 'local',
                emptyText: 'Limit your search by category',
                store: new Ext.data.JsonStore({
                    fields: ['categoryid', 'description'],
                    data: charityCategory
                })
            }, {
                xtype: 'textfield',
                fieldLabel: 'City',
                width: 225,
                name: 'city'
            }, {
                xtype: 'combo',
                width: 225,
                fieldLabel: 'State',
                emptyText: 'Select One',
                triggerAction: 'all',
                mode: 'local',
                hiddenName: 'state',
                displayField: 'description',
                valueField: 'abbreviation',
                store: new Ext.data.SimpleStore({
                    fields: ['abbreviation', 'description'],
                    data: StateList
                })
            }],
            buttons: [{
                iconCls: 'btn-reset',
                text: 'Reset Form',
                handler: function(){
                    this.ownerCt.form.reset();
                }
            }, {
                iconCls: 'btn-edit',
                text: 'Search',
                handler: function(){
					this.ownerCt.form.getEl().dom.action='/charity/browse';
                    this.ownerCt.form.submit();
                }
            }]			
        })
    };
    return {
        init: function(){
            forms.member.render('memberSearchContainer');
            forms.nonprofit.render('nonprofitSearchContainer');
        }
    }
}

Ext.onReady(function(){
    var as = advancedSearch();
    as.init();
});
