/* ---------------------------------------------------
Sets values in form controls from query strings.
------------------------------------------------------*/
function setFormVals(){
	var qs = location.search.substring(1, location.search.length);
	if (qs.length > 0){
		//parse through and retrieve values
		var args = qs.split('&');
		for (var i=0; i<args.length; i++) {
			var pair = args[i].split('=');
			var name = unescape(pair[0]);
			var value = unescape(pair[1]);
			
			switch(name) {
				case "State":
					document.forms[0].StateList.value = value;
					break;
				case "ProjectType":
					document.forms[0].ProjectTypeList.value = value;
					break;
				case "ProjectSize":
					document.forms[0].ProjectSizeList.value = value;
					break;
			}
		}
	}
}

function GetResults(obj){
	//if id of obj <> searchbutton, then assume it's a click on the tab
	//if it's a click on the tab, then get the opposite projectcomplete type (i.e., if complete, get under dev).

	//first look at the querystring and see what the existing filter is for "project complete".
	var qs = location.search.substring(1, location.search.length);
	var pc = 1; //assume that project complete is true as a default

	if (qs.length > 0){
		var io = qs.indexOf("ProjectComplete=") + ("ProjectComplete=").length;
		pc = qs.substring(io, io + 1);
	}

	if (obj.id != "SearchButton"){
		if (pc == 0){pc = 1;}
		else if (pc == 1){pc = 0;}
	}

	var url = "";

	if (window.location.toString().indexOf("/HistoricalProjects") == -1)
		url = "/Projects/Search?ProjectComplete=" + pc + "&State=" + document.forms[0].StateList.value + "&ProjectType=" + document.forms[0].ProjectTypeList.value + "&ProjectSize=" + document.forms[0].ProjectSizeList.value;
	else
		url = "/Projects/HistoricalProjects/Search?" + "State=" + document.forms[0].StateList.value + "&ProjectType=" + document.forms[0].ProjectTypeList.value + "&ProjectSize=" + document.forms[0].ProjectSizeList.value;

	window.location = url;
}

