/* ---------------------------------------------------
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 "RegDetail":
					document.forms[0].Region.value = value;
					break;
				case "Region":
					document.forms[0].RegionList.value = value;
					break;
				case "ProjectType":
					document.forms[0].ProjectTypeList.value = value;
					break;
				case "ProjectSize":
					document.forms[0].ProjectSizeList.value = value;
					break;
				case "NewsReg":
					document.forms[0].NewsRegion.value = value;				
					break;
				case "NewsDate":
					document.forms[0].NewsDate.value = value;
					break;
				case "CareerLoc":
					document.forms[0].CareerLoc.value = value;
				case "CareerPath":
					document.forms[0].CareerPath.value = value;
			}
		}
	}
}

/* --------------------------------------------------------------
Checks to see that no more than six newsletters have been selected
-----------------------------------------------------------------*/
function checkNewslettersTotal (o, c)
{
	var i = 0;
	var totalOptIns = 0;
	
	for (i = 0; i < o.length; i++)
	{
		if (o[i].checked == true) { totalOptIns++; }
	}
	
	if (totalOptIns > 6)
	{
		c.checked = false;
		alert("You may subscribe to up to six newletters.");
	}
}
/* --------------------------------------------------------------
Description:	Validate Newsletters sign up page
-----------------------------------------------------------------*/
function validateNewslettersOptIn (form)
{
	var isValid = true;
	var errorText = "The fields listed below were either left blank or found to contain errors.\nPlease check them and try again.\n";
	
	if (form.firstName == null || !stringCheck(form.firstName.value)) {
		errorText = errorText + "\n" + "First Name";
		isValid = false;
	}
	
	if (form.lastName == null || !stringCheck(form.lastName.value)) {
		errorText = errorText + "\n" + "Last Name";
		isValid = false;
	}
	
	if (form.company == null || !stringCheck(form.company.value)) {
		errorText = errorText + "\n" + "Company";
		isValid = false;
	}
	
	if (form.title == null || !stringCheck(form.title.value)) {
		errorText = errorText + "\n" + "Title";
		isValid = false;
	}
	
	if (form.address == null || !stringCheck(form.address.value)) {
		errorText = errorText + "\n" + "Address";
		isValid = false;
	}
	
	if (form.city == null || !stringCheck(form.city.value)) {
		errorText = errorText + "\n" + "City";
		isValid = false;
	}
	
	if (form.state == null || !stringCheck(form.state.value)) {
		errorText = errorText + "\n" + "State";
		isValid = false;
	}
	
	if (form.zipCode == null || !stringCheck(form.zipCode.value)) {
		errorText = errorText + "\n" + "ZIP Code";
		isValid = false;
	}
	
	if (form.email == null || !emailCheck(form.email.value)) {
		errorText = errorText + "\n" + "E-mail";
		isValid = false;
	}
	
	if (!isValid) { alert(errorText); }
	
	return isValid;
}

/* --------------------------------------------------------------
Validates input from the Newsletters page.
-----------------------------------------------------------------*/
function validateNewslettersSelection (form)
{
	var i = 0;
	var optInList = form.optInList;
	var valid = false;
	
	for (i = 0; i < optInList.length; i++)
	{
		if (optInList[i].checked == true) { valid = true; }
	}
	
	if (!valid) { alert("Please choose at least one newsletter."); }
	
	return valid;
}
	/* Project Search Functions */
	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 "Region":
						document.forms[0].RegionList.value = value;
						ShowHideUdTab();
					case "ProjectType":
						document.forms[0].ProjectTypeList.value = value;
					case "ProjectSize":
						document.forms[0].ProjectSizeList.value = value;
				}
			}
			
		}
	}

	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;}
		}

		location = location.pathname + "?ProjectComplete=" + pc 
			+ "&Region=" + document.forms[0].RegionList.value 
			+ "&ProjectType=" + document.forms[0].ProjectTypeList.value 
			+ "&ProjectSize=" + document.forms[0].ProjectSizeList.value;
	}
	function ShowHideUdTab()
	{
		var selectedTab = document.forms[0].RegionList.value;
		if ((selectedTab  == 'South') || (selectedTab  == 'East') || (selectedTab  == 'West'))
		{
//			alert(document.getElementById("udttwo"));
			var tab1 = document.getElementById('udtone');
			var tab2 = document.getElementById('udttwo');
			if (tab1 != null)
				tab1.style.display = 'none';
			
			if (tab2 != null)
				tab2.style.display = 'none';
		}
	}

