var sql, searchgrid;
// BEGIN PARCEL OWNER SEARCH //
function ownerquery () {
document.getElementById("searchgrid").innerHTML = "";
var ownerinput = document.getElementById("ownerinput").value;
sql = 'http://www.opengeohost.com/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=stlawrence:parcels2010&CQL_FILTER=OWNER%20like%20%27%25' + ownerinput + '%25%27&outputformat=json';
}

function ownersearch(fname) {	
Ext.onReady(function(){
 
		var xg = Ext.grid;
	
		var store = new Ext.data.JsonStore({
        autoLoad: true,  //autoload the data
        url: sql,
        root: 'features',
        fields: [{name: "PRINTKEY", mapping:"properties.PRINTKEY"}, {name: "OWNER", mapping:"properties.OWNER"}, {name: "ADDRESS", mapping:"properties.ADDRESS"}, {name: "MUNI", mapping:"properties.MUNI"}, {name: "PROP_CLASS", mapping:"properties.PROP_CLASS"}, {name: "ACRES", mapping:"properties.ACRES"},{name: "SWIS", mapping:"properties.SWIS"}, {name: "PROP_INFO", mapping:"properties.PROP_INFO"}, {name: "BBOX", mapping:"properties.bbox"}],
		sortInfo: {
            field: 'OWNER',
            direction: 'ASC'
        },       
		listeners: {
            load: {
                fn: function(store, records, options){
                    // get the property grid component
                    var propGrid = Ext.getCmp('propGrid');
                    // make sure the property grid exists
                    if (propGrid) {
                        // populate the property grid with store data
                        propGrid.setSource(store.getAt(0).data);
                    }					
                }
            }
        }
    }); 
	
	    var filters = new Ext.ux.grid.GridFilters({
        // encode and local configuration options defined previously for easier reuse
        encode: false, // json encode the filter query
        local: true,
		filters: [{
            type: 'string',
            dataIndex: 'PRINTKEY'
        }, {
            type: 'string',
            dataIndex: 'OWNER'
        }, {
            type: 'string',
            dataIndex: 'ADDRESS'
        }, {
            type: 'string',
            dataIndex: 'MUNI'
        }, {
            type: 'numeric',
            dataIndex: 'PROP_CLASS'
        }, {
            type: 'numeric',
            dataIndex: 'ACRES'
        }, {
            type: 'numeric',
            dataIndex: 'SWIS'
        }]
    });
	
	var expander = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template(
            '<p><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody>' +
			'<tr><td style="width: 30%;"><tr><td><b>Parcel ID:</b></td><td>{PRINTKEY}</td></tr>' +
			'<tr><td><b>Owner:</b></td><td>{OWNER}</td></tr>' +
			'<tr><td><b>Address:</b></td><td>{ADDRESS}</td></tr>' +
			'<tr><td><b>Municpality:</b></td><td>{MUNI}</td></tr>' +
			'<tr><td><b>Property Class:</b></td><td>{PROP_CLASS}</td></tr>' +
			'<tr><td><b>Acres:</b></td><td>{ACRES}</td></tr>' +
			'<tr><td><b>Swis:</b></td><td>{SWIS}</td></tr>' +
			'<tr><td><b>Property Info:</b></td><td><a href="{PROP_INFO}">Property Info</a></td></tr>' +
			'<tr><td><b>Map:</b></td><td><a href="#" onClick="map.zoomToExtent(new OpenLayers.Bounds({BBOX}).transform(map.displayProjection, map.googleprojection));">Zoom</a></td></tr></tbody></table></p>'

        )
    });

	function renderMap(value, p, record, data) {
        return String.format('<a href="#" onClick="highlightWMS(&#34;{1}&#34;); map.zoomToExtent(new OpenLayers.Bounds({0}).transform(map.displayProjection, map.googleprojection));">Zoom</a>', value, record.data.PRINTKEY);
    }

    function renderPropInfo(value, p, record) {
        return String.format('<a href="{0}" target="_blank">PROPERTY INFO</a>', value);
    }

    searchgrid = new xg.GridPanel({
        store: store,
		plugins: [filters],
		stripeRows: true,
        cm: new xg.ColumnModel({
            defaults: {
                width: 20,
                sortable: true
            },
            columns: [
            //expander,
			{header: "MAP", width: 50, dataIndex: 'BBOX', renderer: renderMap, sortable: false},
            {header: "PARCEL ID", width: 100, dataIndex: 'PRINTKEY', filterable: true, sortable: true},
            {header: "OWNER", width: 100, dataIndex: 'OWNER', filterable: true, sortable: true},
			{header: "ADDRESS", width: 100, dataIndex: 'ADDRESS', filterable: true, sortable: true},
			{header: "MUNICIPALITY", width: 100, dataIndex: 'MUNI', filterable: true, sortable: true},
			{header: "PROPERTY CLASS", width: 100, dataIndex: 'PROP_CLASS', filterable: true, sortable: true},
			{header: "ACRES", width: 100, dataIndex: 'ACRES', filterable: true, sortable: true},
			{header: "SWIS", width: 100, dataIndex: 'SWIS', filterable: true, sortable: true},
			{header: "PROPERTY INFO", width: 100, dataIndex: 'PROP_INFO', renderer: renderPropInfo, filterable: false, sortable: false}
            ]
        }),
        viewConfig: {
            forceFit:true
        },
        columnLines: true,
        width: '100%',
        height: 175,
        //plugins: expander,
        collapsible: false,
        animCollapse: false,
		loadMask: true,
        //title: 'Expander Rows, Collapse and Force Fit',
        //iconCls: 'icon-grid',
        renderTo: 'searchgrid'
    });
});
}
// END PARCEL OWNER SEARCH //

// BEGIN PARCEL ID SEARCH //
function idquery () {
document.getElementById("searchgrid").innerHTML = "";
var idinput = document.getElementById("idinput").value;
sql = 'http://www.opengeohost.com/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=stlawrence:parcels2010&CQL_FILTER=PRINTKEY%20like%20%27%25' + idinput + '%25%27&outputformat=json';
}

function idsearch(fname) {	
Ext.onReady(function(){
 
		var xg = Ext.grid;
	
		var store = new Ext.data.JsonStore({
        autoLoad: true,  //autoload the data
        url: sql,
        root: 'features',
        fields: [{name: "PRINTKEY", mapping:"properties.PRINTKEY"}, {name: "OWNER", mapping:"properties.OWNER"}, {name: "ADDRESS", mapping:"properties.ADDRESS"}, {name: "MUNI", mapping:"properties.MUNI"}, {name: "PROP_CLASS", mapping:"properties.PROP_CLASS"}, {name: "ACRES", mapping:"properties.ACRES"},{name: "SWIS", mapping:"properties.SWIS"}, {name: "PROP_INFO", mapping:"properties.PROP_INFO"}, {name: "BBOX", mapping:"properties.bbox"}],
        sortInfo: {
            field: 'PRINTKEY',
            direction: 'ASC'
        },  
		listeners: {
            load: {
                fn: function(store, records, options){
                    // get the property grid component
                    var propGrid = Ext.getCmp('propGrid');
                    // make sure the property grid exists
                    if (propGrid) {
                        // populate the property grid with store data
                        propGrid.setSource(store.getAt(0).data);
                    }					
                }
            }
        }
    }); 
	
	var filters = new Ext.ux.grid.GridFilters({
        // encode and local configuration options defined previously for easier reuse
        encode: false, // json encode the filter query
        local: true,
				filters: [{
            type: 'string',
            dataIndex: 'PRINTKEY'
        }, {
            type: 'string',
            dataIndex: 'OWNER'
        }, {
            type: 'string',
            dataIndex: 'ADDRESS'
        }, {
            type: 'string',
            dataIndex: 'MUNI'
        }, {
            type: 'numeric',
            dataIndex: 'PROP_CLASS'
        }, {
            type: 'numeric',
            dataIndex: 'ACRES'
        }, {
            type: 'numeric',
            dataIndex: 'SWIS'
        }]
    });

    var expander = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template(
            '<p><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody>' +
			'<tr><td style="width: 30%;"><tr><td><b>Parcel ID:</b></td><td>{PRINTKEY}</td></tr>' +
			'<tr><td><b>Owner:</b></td><td>{OWNER}</td></tr>' +
			'<tr><td><b>Address:</b></td><td>{ADDRESS}</td></tr>' +
			'<tr><td><b>Municpality:</b></td><td>{MUNI}</td></tr>' +
			'<tr><td><b>Property Class:</b></td><td>{PROP_CLASS}</td></tr>' +
			'<tr><td><b>Acres:</b></td><td>{ACRES}</td></tr>' +
			'<tr><td><b>Swis:</b></td><td>{SWIS}</td></tr>' +
			'<tr><td><b>Property Info:</b></td><td><a href="{PROP_INFO}">Property Info</a></td></tr>' +
			'<tr><td><b>Map:</b></td><td><a href="#" onClick="map.zoomToExtent(new OpenLayers.Bounds({BBOX}).transform(map.displayProjection, map.googleprojection));">Zoom</a></td></tr></tbody></table></p>'

        )
    });
	
	function renderMap(value, p, record, data) {
        return String.format('<a href="#" onClick="highlightWMS(&#34;{1}&#34;); map.zoomToExtent(new OpenLayers.Bounds({0}).transform(map.displayProjection, map.googleprojection));">Zoom</a>', value, record.data.PRINTKEY);
    }

    function renderPropInfo(value, p, record) {
        return String.format('<a href="{0}" target="_blank">PROPERTY INFO</a>', value);
    }

    searchgrid = new xg.GridPanel({
        store: store,
		plugins: [filters],
		stripeRows: true,
        cm: new xg.ColumnModel({
            defaults: {
                width: 20,
                sortable: true
            },
            columns: [
            //expander,
			{header: "MAP", width: 50, dataIndex: 'BBOX', renderer: renderMap, sortable: false},
            {header: "PARCEL ID", width: 100, dataIndex: 'PRINTKEY', filterable: true, sortable: true},
            {header: "OWNER", width: 100, dataIndex: 'OWNER', filterable: true, sortable: true},
			{header: "ADDRESS", width: 100, dataIndex: 'ADDRESS', filterable: true, sortable: true},
			{header: "MUNICIPALITY", width: 100, dataIndex: 'MUNI', filterable: true, sortable: true},
			{header: "PROPERTY CLASS", width: 100, dataIndex: 'PROP_CLASS', filterable: true, sortable: true},
			{header: "ACRES", width: 100, dataIndex: 'ACRES', filterable: true, sortable: true},
			{header: "SWIS", width: 100, dataIndex: 'SWIS', filterable: true, sortable: true},
			{header: "PROPERTY INFO", width: 100, dataIndex: 'PROP_INFO', renderer: renderPropInfo, filterable: false, sortable: false}
            ]
        }),
        viewConfig: {
            forceFit:true
        },
        columnLines: true,
        width: '100%',
        height: 175,
        //plugins: expander,
        collapsible: false,
        animCollapse: false,
		loadMask: true,
        //title: 'Expander Rows, Collapse and Force Fit',
        //iconCls: 'icon-grid',
        renderTo: 'searchgrid'
    });
});
}
// END PARCEL ID SEARCH //

// BEGIN PARCEL ADDRESS SEARCH //
function addressquery () {
document.getElementById("searchgrid").innerHTML = "";
var addressinput = document.getElementById("addressinput").value;
sql = 'http://www.opengeohost.com/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=stlawrence:parcels2010&CQL_FILTER=ADDRESS%20like%20%27%25' + addressinput + '%25%27&outputformat=json';
}

function addresssearch(fname) {	
Ext.onReady(function(){
 
		var xg = Ext.grid;
	
		var store = new Ext.data.JsonStore({
        autoLoad: true,  //autoload the data
        url: sql,
        root: 'features',
        fields: [{name: "PRINTKEY", mapping:"properties.PRINTKEY"}, {name: "OWNER", mapping:"properties.OWNER"}, {name: "ADDRESS", mapping:"properties.ADDRESS"}, {name: "MUNI", mapping:"properties.MUNI"}, {name: "PROP_CLASS", mapping:"properties.PROP_CLASS"}, {name: "ACRES", mapping:"properties.ACRES"},{name: "SWIS", mapping:"properties.SWIS"}, {name: "PROP_INFO", mapping:"properties.PROP_INFO"}, {name: "BBOX", mapping:"properties.bbox"}],
        sortInfo: {
            field: 'ADDRESS',
            direction: 'ASC'
        },  
		listeners: {
            load: {
                fn: function(store, records, options){
                    // get the property grid component
                    var propGrid = Ext.getCmp('propGrid');
                    // make sure the property grid exists
                    if (propGrid) {
                        // populate the property grid with store data
                        propGrid.setSource(store.getAt(0).data);
                    }					
                }
            }
        }
    }); 
	
	var filters = new Ext.ux.grid.GridFilters({
        // encode and local configuration options defined previously for easier reuse
        encode: false, // json encode the filter query
        local: true,
				filters: [{
            type: 'string',
            dataIndex: 'PRINTKEY'
        }, {
            type: 'string',
            dataIndex: 'OWNER'
        }, {
            type: 'string',
            dataIndex: 'ADDRESS'
        }, {
            type: 'string',
            dataIndex: 'MUNI'
        }, {
            type: 'numeric',
            dataIndex: 'PROP_CLASS'
        }, {
            type: 'numeric',
            dataIndex: 'ACRES'
        }, {
            type: 'numeric',
            dataIndex: 'SWIS'
        },]
    });

    var expander = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template(
            '<p><table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"><tbody>' +
			'<tr><td style="width: 30%;"><tr><td><b>Parcel ID:</b></td><td>{PRINTKEY}</td></tr>' +
			'<tr><td><b>Owner:</b></td><td>{OWNER}</td></tr>' +
			'<tr><td><b>Address:</b></td><td>{ADDRESS}</td></tr>' +
			'<tr><td><b>Municpality:</b></td><td>{MUNI}</td></tr>' +
			'<tr><td><b>Property Class:</b></td><td>{PROP_CLASS}</td></tr>' +
			'<tr><td><b>Acres:</b></td><td>{ACRES}</td></tr>' +
			'<tr><td><b>Swis:</b></td><td>{SWIS}</td></tr>' +
			'<tr><td><b>Property Info:</b></td><td><a href="{PROP_INFO}">Property Info</a></td></tr>' +
			'<tr><td><b>Map:</b></td><td><a href="#" onClick="map.zoomToExtent(new OpenLayers.Bounds({BBOX}).transform(map.displayProjection, map.googleprojection));">Zoom</a></td></tr></tbody></table></p>'

        )
    });
	
	function renderMap(value, p, record, data) {
        return String.format('<a href="#" onClick="highlightWMS(&#34;{1}&#34;); map.zoomToExtent(new OpenLayers.Bounds({0}).transform(map.displayProjection, map.googleprojection));">Zoom</a>', value, record.data.PRINTKEY);
    }

    function renderPropInfo(value, p, record) {
        return String.format('<a href="{0}" target="_blank">PROPERTY INFO</a>', value);
    }

    searchgrid = new xg.GridPanel({
        store: store,
		plugins: [filters],
		stripeRows: true,
        cm: new xg.ColumnModel({
            defaults: {
                width: 20,
                sortable: true
            },
            columns: [
            //expander,
			{header: "MAP", width: 50, dataIndex: 'BBOX', renderer: renderMap, sortable: false},
            {header: "PARCEL ID", width: 100, dataIndex: 'PRINTKEY', filterable: true, sortable: true},
            {header: "OWNER", width: 100, dataIndex: 'OWNER', filterable: true, sortable: true},
			{header: "ADDRESS", width: 100, dataIndex: 'ADDRESS', filterable: true, sortable: true},
			{header: "MUNICIPALITY", width: 100, dataIndex: 'MUNI', filterable: true, sortable: true},
			{header: "PROPERTY CLASS", width: 100, dataIndex: 'PROP_CLASS', filterable: true, sortable: true},
			{header: "ACRES", width: 100, dataIndex: 'ACRES', filterable: true, sortable: true},
			{header: "SWIS", width: 100, dataIndex: 'SWIS', filterable: true, sortable: true},
			{header: "PROPERTY INFO", width: 100, dataIndex: 'PROP_INFO', renderer: renderPropInfo, filterable: false, sortable: false}
            ]
        }),
        viewConfig: {
            forceFit:true
        },
        columnLines: true,
        width: '100%',
        height: 175,
        //plugins: expander,
        collapsible: false,
        animCollapse: false,
		loadMask: true,
        //title: 'Expander Rows, Collapse and Force Fit',
        //iconCls: 'icon-grid',
        renderTo: 'searchgrid'
    });
});
}
// END PARCEL ADDRESS SEARCH //
