/* Ext JS Library 2.0.1 Copyright(c) 2006-2008, Ext JS, LLC.*/
var identify;
var win;
var nav, setTab = 0; 
var windowOpen = 0;
var identData = [['No plants selected','','']];
var theStore;
function showWindow(theWeedData,features,identify){      
	/* set idHTML to display all the identify info, then set the identify tab html variable = idHTML */
	var idHTML = "No weeds selected";
	var gridData = "";  
	if (identify != null) //if there is an array
	{
		var counties = identify[0];
		var weeds = identify[1];
		/*idHTML = "<b>County</b><br>" + counties[0].name + "<br>";
		idHTML += "<table class='identifyTable'><tr><th>Species Name</th><th>Scientific Name</th><th>County</th>";*/
		for(var i =0; i < weeds.length; i++) 
		{  
			//idHTML +=  "<tr><td>" + weeds[i].common_nam + "</td><td>" + weeds[i].species_na + "</td><td>" + weeds[i].county + "</td></tr>";
			if(i == 0)
				gridData += "[\"" + eval("weeds[i]." + comname) + "\",'" + eval("weeds[i]." + sciname) + "','" + weeds[i].county + "']";
			if(i > 0)
				gridData += ",[\"" + eval("weeds[i]." + comname) + "\",'" + eval("weeds[i]." + sciname) + "','" + weeds[i].county + "']";
		}
		idHTML += "</table>";
		gridData = "var gridData = [" + gridData + "]";
		eval(gridData);
		identData = gridData;
		theStore.loadData(identData);
 		//store.load({params:{start:0, limit:25}});
	}

	//If the window was closed, show it, set the windowOpen variable value to 1 (open) and change the window icon in the toolbar
	    /*	win.show();
	    	windowOpen = 1; //set a variable
	    	document.getElementById('querymindiv').className = "querymindivOn"; //change the image on the panel div */
			toggleWin();
	

}

Ext.onReady(function(){
	Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	// create the data store
	theStore = new Ext.data.SimpleStore({
		fields: [
		   {name: 'CommonName'},
		   {name: 'ScientificName'},
		   {name: 'County'}
		]
	});
	theStore.loadData(identData);
  
	/*PAGINATION HOLDER*/
	nav = new Ext.Panel({
            title: 'Pagination',
            region: 'south',
            split: true,
            width: 200,
            collapsible: true,
            margins:'3 0 3 3',
            cmargins:'3 3 3 3'
        });

	/*GRID*/
	grid = new Ext.grid.GridPanel({
			store: theStore,
			columns: [
				{id:'CommonName',header: "Common Name",sortable: true, dataIndex: 'CommonName'},
				{header: "Scientific Name",sortable: true, dataIndex: 'ScientificName'},
				{header: "County",sortable: true,  dataIndex: 'County'}
			],
			stripeRows: true,
			autoExpandColumn: 'CommonName',
			title:'Identify Information'
    			});

	/*CREATE THE WINDOW*/
	win = new Ext.Window({
		el:'ident-win',
		layout:'fit',
		width:400,
		height:300,
		closeAction:'hide',
		plain: true,
		draggable: true,
		items: [ grid],

                buttons: [{
                    text: 'Close',
                    handler: function(){
                        win.hide();
                    }
                }]
            });

	//store.load({params:{start:0, limit:5}});
	//Animate when opening / closing
	win.animateTarget = document.getElementById('querymindiv');
	//Attach an event the identify icon
	var button = Ext.get('querymindiv');

	button.on('click', function(){
		toggleWin()
	});

});

function toggleWin()
{
	if(windowOpen == 1)
	{       
	//If the window was open, hide it, set the windowOpen variable value to 0 (closed) and change the window icon in the toolbar
		win.hide(); //close the open window
	    	windowOpen = 0; //set a variable
	    	document.getElementById('querymindiv').className = "querymindivOff"; //change the image on the panel div

	}
	else if(windowOpen == 0)
	{    
	//If the window was closed, show it, set the windowOpen variable value to 1 (open) and change the window icon in the toolbar
	    	win.show();
	    	windowOpen = 1; //set a variable
	    	document.getElementById('querymindiv').className = "querymindivOn"; //change the image on the panel div
	}
}


/*Change the style of some elements for IE*/
function resizeElements()
{
	document.getElementById('map').style.height = '85%';
    	var browser=navigator.appName;
    	window.onresize = dynamicallyResizeWindow;
    	document.getElementById('map').style.height= document.body.offsetHeight - 150;   /*so the map doesn't extend past the screen*/
	document.getElementById('leftOutter').style.height=document.body.offsetHeight - 170;
    	if ( browser == "Microsoft Internet Explorer" || browser == "Windows Internet Explorer"  )
     	{    
      		//document.getElementById('paneldivContainer').style.width='153px';
      		//document.getElementById('OpenLayers.Control.ScaleBar_55').style.position='absolute';
      		//document.getElementById('OpenLayers.Control.ScaleBar_55').style.left='-195px';
      		//document.getElementById('OpenLayers.Control.ScaleBar_55').style.bottom='10px';
      		//document.getElementById('map').style.left='0px';
      		//document.getElementById('l_4').style.left='-8px';
    	}
}
function dynamicallyResizeWindow() {
	document.getElementById('map').style.height= document.body.offsetHeight - 150;   /*so the map doesn't extend past the screen*/
	document.getElementById('leftOutter').style.height=document.body.offsetHeight - 170;
}
