// From http://javascript.about.com/library/blqs1.htm ... And then I changed it
function GetURLQueryVars() 
{
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) 
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0) 
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
		else	// if it is set but not equal to anything
		{
			var key = parms[i];
			qsParm[key]=null;
		}
	}
	return qsParm;
} 

function BrowseFilmLibrary()
{
	// Get all of the values of all of the drop-downs
	var state=document.getElementById('state').value;
	var year=document.getElementById('year').value;
	var org_type=document.getElementById('org_type').value;
	var gender=document.getElementById('gender').value;
	var org=document.getElementById('org').value;
	var sport=document.getElementById('sport').value;
	var level=document.getElementById('level').value;
	var game_type=document.getElementById('game_type').value;
	var team=document.getElementById('team').value;

	// Generate the query string
	var q="";
//	if(state > 0)
//	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="st="+state;
//	}
	if(year > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="y="+year;
	}
	if(org_type > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="ot="+org_type;
	}
	if(gender > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="g="+gender;
	}
	if(org > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="o="+org;
	}
	if(sport > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="sp="+sport;
	}
	if(level > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="l="+level;
	}
	if(game_type > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="g_t="+game_type;
	}
	if(team > 0)
	{
		if(q.length > 0)
		{
			q+="&";
		}
		q+="t="+team;
	}
	
	// TODO - sort

	// Add the query to the location pathname
	document.location=window.location.pathname+"?"+q;
}
