// Lista comuni
var TownsStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'town',
        agency_id: User.agencyId
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Towns',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista zone
var ZonesStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'zone'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Zones',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista quartieri
var DistrictsStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'district'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Districts',
        id: 'id',
        fields: ['id', 'nome', 'zone_id']
    })
});

// Lista categorie
var CategoriesStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'category'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Categories',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista tipologie di immobile
var HouseTypesStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
		item: 'house_type',
		category_id: searchParams.category_id
	},
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'HouseTypes',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista tipologie di edificio
var BuildingTypesStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
	item: 'building_type'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'BuildingTypes',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista tipologie di contratto
var ContractsStore = new Ext.data.Store({
	autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
		item: 'contract'
	},
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Contracts',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista condizioni immobile
var HouseStatusesStore = new Ext.data.Store({
	autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
		item: 'status'
	},
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Statuses',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Lista posizione immobile
var FloorsStore = new Ext.data.Store({
	autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'floor'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Floors',
        id: 'id',
        fields: ['id', 'nome']
    })
});

// Referers di un'annuncio
var ReferersStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'referer'
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Referers',
        id: 'id',
        fields: ['id', 'nome']
    })
});

var DistancesStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: '/combos.php',
        method: 'POST'
    }),
    baseParams: {
        item: 'distance',
        min_distance: User.prefs.minDistanceOnSearchByAddress
    },
    reader:  new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Distances',
        id: 'id',
        fields: ['id', 'km']
    })
});

// Lista immobili
var bp = Ext.apply(searchParams, {
    action: 'read',
    limit: 25,
    site_id: User.siteId,
    agency_id: User.agencyId
});
var userListingsStore = new Ext.data.Store({
    id: 'user_listings_store',
    remoteSort: true,
    proxy: new Ext.data.HttpProxy({
        url: '/listings.php',
        method: 'POST'
    }),
    baseParams: bp,
    reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'Listings',
        id: 'id',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'zone_id', type: 'int'},
            {name: 'district_id', type: 'int'},
            {name: 'contract_id', type: 'int'},
            {name: 'customer_id', type: 'int'},
            {name: 'category_id', type: 'int'},
            {name: 'house_type_id', type: 'int'},
            {name: 'building_type_id', type: 'int'},
            {name: 'comunione_beni', type: 'int'},
            {name: 'mutuo_residuo', type: 'int'},
            {name: 'prezzo', type: 'int'},
            {name: 'active', type: 'int'},
            {name: 'enabled', type: 'int'},
            {name: 'prezzo_visibile', type: 'int'},
            'indirizzo',
            'comune',
            'cap',
            'customer',
            'categoria',
            'agency_agent',
            'titolo',
            'sef_title',
            'codice',
            'contratto',
            'tipologia',
            'edificio',
            'datainserimento',
            'zona',
            'quartiere',
            'descrizione',
            'latitudine',
            'longitudine',
            'fotografie',
            'proprietario'
        ]
    })
});

var listingPicturesStore = new Ext.data.JsonStore({
    url: '/pictures.php',
    root: 'images',
    baseParams: {
		action: 'read'
	},
    fields:[
        'id',
        'listing_id',
        'nomefile',
        'basepath',
        'fullpath',
        {
        	name: 'didascalia',
        	convert: function (val, rec) {
        		return Ext.util.Format.ellipsis(val, 15);
        	}
        }
    ]
});
