/* $Header: /var/cvs/cvsroot/fry_2_mod_real_estate/javascript/real-estate-search.js,v 1.29 2010/05/31 14:49:28 waldo Exp $ */

Ext.BLANK_IMAGE_URL = '/modules/real_estate/javascript/ext-2.2/resources/images/default/s.gif'; 

Ext.onReady(function(){ 
	Ext.QuickTips.init(); 
	Ext.form.Field.prototype.msgTarget = 'side'; 
	var pp = Ext.urlDecode(window.location.search.substring(1));

	Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

	var state = Ext.state.Manager.getProvider();
	var start = state.get('startStoreAdmin',0);
	var limit = state.get('limitStoreAdmin',15);
	var q = state.get('qStoreAdmin','');
	var x = state.get('xStoreAdmin','B');

	var realEstateStore = new Ext.data.JsonStore({
		autoLoad : true,
		url : 'modules/real_estate/services/search.json.php',
		root: 'data',
		totalProperty: 'totalcount',
		idProperty: 'id',
		params: {'start':start,'limit':limit,'q':q, 'x': x},
		paramNames: {'start':'start','limit':'limit','q':'q','x':'x'},
		remoteSort: true,
		fields : ['id','propertyOverview','address','image','propertyType','municipality','zoning','price', 'lat', 'lng', 'title', 'listing_type', 'brokers', 'mls_number'],
	});
	
	realEstateStore.on('loadexception', function(event, options, response, error) { 
	    var data = Ext.decode(response.responseText);
	    if(data.error){
			Ext.Msg.alert('Error', data.error);
			realEstateStore.removeAll();
		}
	});


	function property_overview(val,x,realEstateStore) {
		newurl = (displayurl.indexOf('?') < 0)?displayurl+'?':displayurl+'&';
        if (realEstateStore.data.mls_number == 0) {
            var fromCTT = 'Provided by CTT Inc or its Partners - ';
        } else {
            var fromCTT = '';
        }
        if (realEstateStore.data.image != "") {
		    return '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="property-grid-img-td" valign="top"><a href="'+newurl+'reid='+realEstateStore.data.id+'" target="_BLANK"><img class="property-grid-img" src="'+realEstateStore.data.image+'" height="55" width="70" align="left" valign="top" /></a></td><td class="property-grid-td-description" valign="top">' + fromCTT + '<div class="property-grid-address"><a href="'+newurl+'reid='+realEstateStore.data.id+'" target="_BLANK">'+realEstateStore.data.address+'</a></div><div class="property-grid-brokers">'+realEstateStore.data.brokers+'</div><div class="property-grid-description"><a href="'+newurl+'reid='+realEstateStore.data.id+'" target="_BLANK">'+val+'</a></div></td></tr></table>';
        } else {
            return '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="property-grid-td-description" valign="top"><div class="property-grid-address">' + fromCTT + '<a href="'+newurl+'reid='+realEstateStore.data.id+'" target="_BLANK">'+realEstateStore.data.address+'</a></div><div class="property-grid-brokers">'+realEstateStore.data.brokers+'</div><div class="property-grid-description"><a href="'+newurl+'reid='+realEstateStore.data.id+'" target="_BLANK">'+val+'</a></div></td></tr></table>';
        }
	}
		
	var map = new Ext.ux.GMapPanel({
		title: 'Map Display',
		gmapType: 'map',
		iconCls: 'search_results_map_tab_icon',
		zoomLevel: 5,
		height: 500,
		dataStore: realEstateStore,
		addControl: new GSmallMapControl(),
		defaultCenter: {
			geoCodeAddr: '57 Erb Street West, Waterloo, Ontario, Canada N2L 6C2',
			marker: {title: 'Canada\'s Technology Triangle Inc'}
		}
	});

	var buildingSearchForm = new Ext.FormPanel({
		labelWidth: 150,
		width: 600,
		title:'Building',
		iconCls: 'search_form_building_tab_icon',
		frame: false,
		border:false,
		autoHeight:true,
		style:'padding:20px;',
		items:[
            {
                xtype: 'checkbox',
                fieldLabel: 'Property Type',
                name: 'sub_type_industrial',
                boxLabel: 'Industrial',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                name: 'sub_type_institutional',
                labelSeparator:'',
                boxLabel: 'Institutional',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_office',
                boxLabel: 'Office',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_retail',
                boxLabel: 'Retail',
                allowBlank: true
            },
			{
				xtype: 'checkbox',
				fieldLabel: 'Municipality',
				name: 'waterloo_region',
				boxLabel: 'Waterloo Region',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'cambridge',
				boxLabel: 'Cambridge',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'kitchener',
				boxLabel: 'Kitchener',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'waterloo',
				boxLabel: 'Waterloo',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'north_dumfries',
				boxLabel: 'Township of North Dumfries',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wellesley',
				boxLabel: 'Township of Wellesley',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wilmot',
				boxLabel: 'Township of Wilmot',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'woolwich',
				boxLabel: 'Township of Woolwich',
				allowBlank:true
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Town (if applicable)',
				name: 'town',
				allowBlank:true 
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Street',
				name: 'street',
				allowBlank:true 
			},
			{
				xtype: 'radiogroup',
				fieldLabel: 'Transaction Type',
				columns: 1,
				allowBlank: false,
				name: 'transaction_type',
				defaults: {name: 'transaction_type'},
				items: [
					{
						boxLabel: 'Sale',
						inputValue: 'S'
					},
					{
						boxLabel: 'Lease',
						inputValue: 'L'
					},
					{
						boxLabel: 'Any',
						inputValue: 'ANY'
					}
				]
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Min',
				name: 'sale_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Max',
				name: 'sale_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Sale Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['sale_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'sale_dimension',
				name: 'sale_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Min',
				name: 'lease_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Max',
				name: 'lease_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Lease Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['lease_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'lease_dimension',
				name: 'lease_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Min',
				name: 'size_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Max',
				name: 'size_max',
				allowBlank:true,
				width:175
			},{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Size Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['size_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'size_dimension',
				name: 'size_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			}
		],
		buttons: [
			{
				text: 'Search',
				handler: function() {
					var f = buildingSearchForm.getForm();
					var query = f.getValues(true).replace(/\=/g,':').replace(/\&/g,'|');
					state.set('qStoreAdmin',query);
					state.set('xStoreAdmin','C');
					realEstateStore.load({params: {
						q:query,start:0,limit:15,x:'C'
					}});
					tabs.activate('search_results');
				}
			}
		]
	});
	
	
	
	var allSearchForm = new Ext.FormPanel({
		labelWidth: 150,
		width: 600,
		title:'All',
		frame: false,
		border:false,
		autoHeight:true,
		style:'padding:20px;',
		iconCls: 'search_form_all_tab_icon',
		items:[
			{
				xtype: 'checkbox',
				fieldLabel: 'Municipality',
				name: 'waterloo_region',
				boxLabel: 'Waterloo Region',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'cambridge',
				boxLabel: 'Cambridge',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'kitchener',
				boxLabel: 'Kitchener',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'waterloo',
				boxLabel: 'Waterloo',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'north_dumfries',
				boxLabel: 'Township of North Dumfries',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wellesley',
				boxLabel: 'Township of Wellesley',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wilmot',
				boxLabel: 'Township of Wilmot',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'woolwich',
				boxLabel: 'Township of Woolwich',
				allowBlank:true
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Town (if applicable)',
				name: 'town',
				allowBlank:true 
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Street',
				name: 'street',
				allowBlank:true 
			},
			{
				xtype: 'radiogroup',
				fieldLabel: 'Transaction Type',
				columns: 1,
				allowBlank: false,
				name: 'transaction_type',
				defaults: {name: 'transaction_type'},
				items: [
					{
						boxLabel: 'Sale',
						inputValue: 'S'
					},
					{
						boxLabel: 'Lease',
						inputValue: 'L'
					},
					{
						boxLabel: 'Any',
						inputValue: 'ANY'
					}
				]
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Min',
				name: 'sale_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Max',
				name: 'sale_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Sale Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['sale_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'sale_dimension',
				name: 'sale_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Min',
				name: 'lease_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Max',
				name: 'lease_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Lease Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['lease_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'lease_dimension',
				name: 'lease_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Min',
				name: 'size_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Max',
				name: 'size_max',
				allowBlank:true,
				width:175
			},{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Size Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['size_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'size_dimension',
				name: 'size_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			}
		],
		buttons: [
			{
				text: 'Search',
				handler: function() {
					var f = allSearchForm.getForm();
					var query = f.getValues(true).replace(/\=/g,':').replace(/\&/g,'|');
					state.set('qStoreAdmin',query);
					state.set('xStoreAdmin','A');
					realEstateStore.load({params: {
						q:query,start:0,limit:15,x:'A'
					}});
					tabs.activate('search_results');
				}
			}
		]
	});
	
	var landSearchForm = new Ext.FormPanel({
		labelWidth: 150,
		width: 600,
		title:'Land',
		frame: false,
		border:false,
		autoHeight:true,
		iconCls: 'search_form_land_tab_icon',
		style:'padding:20px;',
		items:[
            {
                xtype: 'checkbox',
                fieldLabel: 'Property Type',
                name: 'sub_type_agricultural',
                boxLabel: 'Agricultural',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_commercial',
                boxLabel: 'Commercial',
                allowBlank: true
            },{
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_industrial',
                boxLabel: 'Industrial',
                allowBlank: true
            },{
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_institutional',
                boxLabel: 'Institutional',
                allowBlank: true
            },
			{
				xtype: 'checkbox',
				fieldLabel: 'Municipality',
				name: 'waterloo_region',
				boxLabel: 'Waterloo Region',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'cambridge',
				boxLabel: 'Cambridge',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'kitchener',
				boxLabel: 'Kitchener',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'waterloo',
				boxLabel: 'Waterloo',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'north_dumfries',
				boxLabel: 'Township of North Dumfries',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wellesley',
				boxLabel: 'Township of Wellesley',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wilmot',
				boxLabel: 'Township of Wilmot',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'woolwich',
				boxLabel: 'Township of Woolwich',
				allowBlank:true
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Town (if applicable)',
				name: 'town',
				allowBlank:true 
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Street',
				name: 'street',
				allowBlank:true 
			},
			{
				xtype: 'radiogroup',
				fieldLabel: 'Transaction Type',
				columns: 1,
				allowBlank: false,
				name: 'transaction_type',
				defaults: {name: 'transaction_type'},
				items: [
					{
						boxLabel: 'Sale',
						inputValue: 'S'
					},
					{
						boxLabel: 'Lease',
						inputValue: 'L'
					},
					{
						boxLabel: 'Any',
						inputValue: 'ANY'
					}
				]
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Min',
				name: 'sale_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Max',
				name: 'sale_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Sale Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['sale_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'sale_dimension',
				name: 'sale_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Min',
				name: 'lease_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Lease Price Max',
				name: 'lease_max',
				allowBlank:true,
				width:175
			},
			{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Lease Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['lease_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'lease_dimension',
				name: 'lease_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Min',
				name: 'size_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Size Max',
				name: 'size_max',
				allowBlank:true,
				width:175
			},{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Size Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['size_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'size_dimension',
				name: 'size_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			}
		],
		buttons: [
			{
				text: 'Search',
				handler: function() {
					var f = landSearchForm.getForm();
					var query = f.getValues(true).replace(/\=/g,':').replace(/\&/g,'|');
					state.set('qStoreAdmin',query);
					state.set('xStoreAdmin','L');
					realEstateStore.load({params: {
						q:query,start:0,limit:15,x:'L'
					}});
					tabs.activate('search_results');
				}
			}
		]
	});
	
	var businessSearchForm = new Ext.FormPanel({
		labelWidth: 150,
		width: 600,
		title:'Business',
		frame: false,
		border:false,
		autoHeight:true,
		style:'padding:20px;',
		iconCls: 'search_form_business_tab_icon',
		items:[
            {
                xtype: 'checkbox',
                fieldLabel: 'Property Type',
                name: 'sub_type_includes_property',
                boxLabel: 'Includes Property',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_in_leased_premises',
                boxLabel: 'In Leased Premises',
                allowBlank: true
            },
            {
                xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator:'',
                name: 'sub_type_business_only',
                boxLabel: 'Business Only',
                allowBlank: true
            },
			{
				xtype: 'checkbox',
				fieldLabel: 'Municipality',
				name: 'waterloo_region',
				boxLabel: 'Waterloo Region',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'cambridge',
				boxLabel: 'Cambridge',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'kitchener',
				boxLabel: 'Kitchener',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'waterloo',
				boxLabel: 'Waterloo',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'north_dumfries',
				boxLabel: 'Township of North Dumfries',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wellesley',
				boxLabel: 'Township of Wellesley',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'wilmot',
				boxLabel: 'Township of Wilmot',
				allowBlank:true
			},
			{
				xtype: 'checkbox',
				fieldLabel: '',
				labelSeparator:'',
				name: 'woolwich',
				boxLabel: 'Township of Woolwich',
				allowBlank:true
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Town (if applicable)',
				name: 'town',
				allowBlank:true 
			},
			{
				xtype: 'textfield',
				width:400,
				fieldLabel: 'Street',
				name: 'street',
				allowBlank:true 
			},
			{
				xtype: 'radiogroup',
				fieldLabel: 'Transaction Type',
				columns: 1,
				allowBlank: false,
				name: 'transaction_type',
				defaults: {name: 'transaction_type'},
				items: [
					{
						boxLabel: 'Sale',
						inputValue: 'S'
					},
					{
						boxLabel: 'Lease',
						inputValue: 'L'
					},
					{
						boxLabel: 'Any',
						inputValue: 'ANY'
					}
				]
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Min',
				name: 'sale_min',
				allowBlank:true,
				width:175
			},
			{
				xtype:'textfield',
				fieldLabel: 'Sale Price Max',
				name: 'sale_max',
				allowBlank:true,
				width:175
			},{
				xtype: 'combo',
				width: 175,
				fieldLabel: 'Size Dimension',
				store: new Ext.data.SimpleStore({
					fields: ['size_dimension'],
					data:[['sq ft'], ['sq m'], ['acres'], ['hectares'], ['total']]
				}),
				displayField: 'size_dimension',
				name: 'size_dimension',
				triggerAction: 'all',
				forceSelection: true,
				typeAhead: false,
				mode: 'local',
				selectOnFocus:true,
				allowBlank:false
			}
		],
		buttons: [
			{
				text: 'Search',
				handler: function() {
					var f = businessSearchForm.getForm();
					var query = f.getValues(true).replace(/\=/g,':').replace(/\&/g,'|');
					state.set('qStoreAdmin',query);
					state.set('xStoreAdmin', 'B');
					realEstateStore.load({params: {
						q:query,start:0,limit:15,x:'B'
					}});
					tabs.activate('search_results');
				}
			}
		]
	});
	
    Ext.ux.GridPrinter.stylesheetPath = '/templates/public_print.css';
    
    var grid = new Ext.grid.GridPanel({
        xtype:'grid',
        title:'Tabular Display',
        iconCls: 'search_results_tabular_tab_icon',
        collapsible: false,
        frame:false,
        header:false,
        name: 'REGrid',
        id: 'REGrid',
        store:realEstateStore,
        height:500,
        width:764,
        hideCollapseTool:true,
        stripeRows:true,
        bbar: new Ext.PagingToolbar ({
            pageSize: 15,
            store: realEstateStore,
            displayInfo: true,
            displayMsg: 'Displaying entries {0} - {1} of {2}',
            emptyMsg: "No entries to display",
            stateful:true
        }),
        columns: [
            {header:"Property Overview",dataIndex:'propertyOverview',id:'x-grid3-cell-inner',width:315, renderer:property_overview},
            {header:"Address",dataIndex:'address',hidden:true},
            {header:"Image",dataIndex:'image',hidden:true,hideable:false},
            {header:"Property Type",dataIndex:'propertyType',width:150},
            {header:"Municipality",dataIndex:'municipality',width:100},
            {header:"Price",dataIndex:'price',width:100},
            {header:"Brokers",dataIndex:'brokers',width:75}
        ]						
    });
   
    var printButton = new Ext.Toolbar.Button({
        text   : 'Print this page',
        iconCls: 'search_results_tabular_print_icon',
        handler: function() {
            Ext.ux.GridPrinter.print(grid);
        } 
    });
    
	var tabs = new Ext.TabPanel({
		renderTo: 'contentGrid',
		width: 764,
		activeTab:0,
        deferredRender: false,
		frame: false,
		border:true,
		autoHeight:false,
        height: 825,
		items:[
			{
				xtype:'tabpanel',
				width: 764,
				title:'Search Form',
				iconCls: 'search_form_tab_icon',
				activeTab:0,
                deferredRender: false,
				frame: false,
				border:false,
				items:[
						buildingSearchForm,
						landSearchForm,
						businessSearchForm,
						allSearchForm
				]
			},
			{
				xtype:'tabpanel',
				width: 764,
				title:'Search Results',
				iconCls: 'search_results_tab_icon',
				activeTab:0,
				frame: false,
				border:false,
				id:'search_results',
				items:[
					grid,
					map
						
				]

			}
			
		]
	});

	Ext.override(Ext.data.Store, {
		onMetaChange : function(meta, rtype, o){
			this.recordType = rtype;
			this.fields = rtype.prototype.fields;
			delete this.snapshot;
			if(meta.sortInfo){
				this.sortInfo = meta.sortInfo;
			}else if(this.sortInfo && !this.fields.get(this.sortInfo.field)){
				delete this.sortInfo;
			}
			this.modified = [];
			this.fireEvent('metachange', this, this.reader.meta);
		}
	});

    new Ext.LoadMask(Ext.getBody(), {msg: 'Please Wait...', store: realEstateStore});
    
	realEstateStore.on('beforeload', function() {
		var state = Ext.state.Manager.getProvider(); 
		
		this.baseParams['x'] = state.get('xStoreAdmin', 'B');
		this.baseParams['q'] = state.get('qStoreAdmin', '');
        
	});
	realEstateStore.on('load',function(){
		
		if (map.rendered) {
			map.clearMarkers();
			realEstateStore.each(function(rec){
				if (!(rec.data.lat == 0 && rec.data.lng == 0)) {
                    var marker = map.addMarker(new GLatLng(rec.data.lat, rec.data.lng), {title: rec.data.title});
                	GEvent.addListener(marker,'click', function() {
          	            window.open('display_listing?reid=' + rec.data.id, 'details');
        	        });
				}
			});

			map.setCenter(map.getCenter(), map.getBoundsZoomLevel());
		}
	});
	
    grid.render();
    grid.getBottomToolbar().add('-',printButton); 
	
});