function GetParams()
{
    var sLocation = new String(window.location);     //property contains domain, directory, 
                                                     //filename of the document plus the params (and the "?" before the params).
    var sParamsList = new String(sLocation.substr(sLocation.lastIndexOf("?")+1));
    return sParamsList.split('&');
}

function submitQuickProfile() {	
	//alert("in submit()");
   var formObj = document.UserForm;

    var list = formObj.StateBox
	var index = list.selectedIndex;
	var Geo = list.options[index].value;
    var list = formObj.CancerBox
	var index = list.selectedIndex;
	var Cancer = list.options[index].value;
//	var Geo = formObj.StateBox.value;
	
	if (Geo == "**" || Cancer == "***") {
	//	listForError = "State\n";
		alert("Please make a selection before continuing.");
		//alert("All variables must have a selection to create this graph.\n\nPlease make a selection for the following variable(s): \n"+listForError);
	}
	else {
	//var County = formObj.CountyBox.value;
	var queryString = Geo+"&"+Cancer;//+"&"+County;
//alert ("geo = "+Geo);
	//var queryString = Report +"&"+Geo+"&"+County+"&"+YearGroup+"&"+Age+"&"+CancerSite+"&"+Race+"&"+Sex+"&"+Output+"&"+Explanation+"&"+Type+"&"+pointsVisible+"&"+numLines;//+"&"+Scales;
//	alert ("querystring is");
//	alert (queryString);
	formObj.target='_self';
   formObj.action = "/cgi-bin/quickprofiles/profile.pl?"+queryString;
   //alert (formObj.target);
  // alert (formObj.action);
   formObj.submit();
}
}



function submitState() {	
	//alert("in submit()");
   var formObj = document.UserForm;

    var list = formObj.StateBox
	var index = list.selectedIndex;
	var Geo = list.options[index].value;
//	var Geo = formObj.StateBox.value;
	
	if (Geo == "**") {
	//	listForError = "State\n";
		alert("Please make a selection before continuing.");
		//alert("All variables must have a selection to create this graph.\n\nPlease make a selection for the following variable(s): \n"+listForError);
	}
	else {
	//var County = formObj.CountyBox.value;
	var queryString = Geo;//+"&"+County;
//alert ("geo = "+Geo);
	//var queryString = Report +"&"+Geo+"&"+County+"&"+YearGroup+"&"+Age+"&"+CancerSite+"&"+Race+"&"+Sex+"&"+Output+"&"+Explanation+"&"+Type+"&"+pointsVisible+"&"+numLines;//+"&"+Scales;
//	alert ("querystring is");
//	alert (queryString);
	formObj.target='_self';
   formObj.action = "/cgi-bin/reports/state/report.by.state.pl?"+queryString;
   //alert (formObj.target);
  // alert (formObj.action);
   formObj.submit();
}
}

// Used for the Cancer QuickReport (/cgi-bin/reports/cancerReport.pl)
function CancerReportUpdateSelected() {
	//alert ("in CancerReportUpdateSelected()");
	var VisibleForm = document.UserForm;
	paramArray = GetParams();
	var CurrentCancerVisible = VisibleForm.CancerBox;
	//var CurrentCancerHidden = paramArray[0];
	var lastparam = paramArray[0];
	var lastparamarray = lastparam.split('#');
	var CurrentCancerHidden = lastparamarray[0];
	//var CurrentCancerHidden = CurrentCancerHiddenNumber + "";
	//alert ("current cancer hidden = "+CurrentCancerHidden);
	for (var i=0; i<CurrentCancerVisible.length; i++) {
			//alert ("i = "+i+", CurrentCancerVisible.options[i] = "+CurrentCancerVisible.options[i].value);
		if (CurrentCancerHidden == CurrentCancerVisible.options[i].value) {
			CurrentCancerVisible.selectedIndex = i;
			break;
		}
	}
}

function submitCancer() {	
	//alert("in submit()");
   var formObj = document.UserForm;
	//var Cancer = formObj.CancerBox.value;
	
    var list = formObj.CancerBox
	var index = list.selectedIndex;
	var Cancer = list.options[index].value;
	if (Cancer == "***") {
		//listForError = "Cancer\n";
		
		alert("Please make a selection before continuing.");
	//	alert("All variables must have a selection to create this graph.\n\nPlease make a selection for the following variable(s): \n"+listForError);
	}
	else {
	//var County = formObj.CountyBox.value;
	var queryString = Cancer;//+"&"+County;
//alert ("geo = "+Geo);
	//var queryString = Report +"&"+Geo+"&"+County+"&"+YearGroup+"&"+Age+"&"+CancerSite+"&"+Race+"&"+Sex+"&"+Output+"&"+Explanation+"&"+Type+"&"+pointsVisible+"&"+numLines;//+"&"+Scales;
//	alert ("querystring is");
//	alert (queryString);
	formObj.target='_self';
   formObj.action = "/cgi-bin/reports/cancer/cancer.report.pl?"+queryString;
   //alert (formObj.target);
  // alert (formObj.action);
   formObj.submit();
}
}



function UpdateSelected()
{
//	alert ("in updateselected()");
        var VisibleForm = document.UserForm;
	//var HiddenFormVar = document.hiddenForm;
	
	var CurrentState = VisibleForm.StateBox;
	var CurrentCancerVisible = VisibleForm.CancerBox;
	//var CurrentCounty = VisibleForm.CountyBox;
	//alert(CurrentRace);
	
	paramArray = GetParams();
//	alert (CurrentAgesHidden);
	var CurrentStateHidden = paramArray[0]; //named area - NOT geo
	var lastparam = paramArray[1];
	var lastparamarray = lastparam.split('#');
	var CurrentCancerHidden = lastparamarray[0];
	//var CurrentCountyHidden = paramArray[1];
//	alert(CurrentStateHidden+": "+CurrentCountyHidden);
	//var CurrentGenderHidden = paramArray[7];
	//var CurrentIncdMortHidden = paramArray[10];
	//alert(CurrentRaceHidden.value);
	
	//var CurrentHidden = HiddenForm.datatype;
	for (var i=0; i<CurrentState.length; i++)
	{
	  if (CurrentStateHidden == CurrentState.options[i].value) 
	  {
	    CurrentState.selectedIndex=i;
	    break;
	  }
	}
	
	for (var i=0; i<CurrentCancerVisible.length; i++) {
			//alert ("i = "+i+", CurrentCancerVisible.options[i] = "+CurrentCancerVisible.options[i].value);
		if (CurrentCancerHidden == CurrentCancerVisible.options[i].value) {
			CurrentCancerVisible.selectedIndex = i;
			break;
		}
	}
	
	/*
	WriteCountySelectBox();
	for (var i=0; i<CurrentCounty.length; i++)
	{
	  if (CurrentCountyHidden == CurrentCounty.options[i].value) 
	  {
	    CurrentCounty.selectedIndex=i;
	    break;
	  }
	}*/
	   		
}


function WriteCountySelectBox(){
	//alert("write county select box");
//Function : 	WriteCountySelectBox
//Purpose :	To assign the available options in the CountySelectBox based upon the Selected  State in the State List Box
	
   var formObj = document.UserForm;
	//Assign State List Box Object
	var stateForm = formObj.StateBox;
	//Assign County List Box Object
	var countyForm = formObj.CountyBox;
	//Obtain the value of the Selected Index in the State List Box 
	var selectedStateFips = stateForm.options[stateForm.selectedIndex].value;
	//Assign the Starting Index for the for loop that will be used to access the variables in the CountyName array
	//The County Name Array contains All of the US Counties indexed by their State/County Fips
	var forLoopStart = selectedStateFips + "000";
	//Assign the Ending Index for the for loop that will be used to access the variables in the CountyName array
	var forLoopEnd = selectedStateFips + "999";
	//alert("entering if loops");
	if (selectedStateFips == "00") {
		//alert("total us");
		countyForm.length = 0;
		countyForm.options[0] = new Option("U.S. (Total)");
		countyForm.options[0].value = "000";//&U.S. (Total)";
	}
	else if (selectedStateFips == "11") { //DC - don't add "Entire State"
		//alert ("dc");
		countyForm.length = 0;
		var j = 0; //Separate Counter for assigning the members of the list box
		//var j = 0; //Separate Counter for assigning the members of the list box
		//alert("Entering loop");
		for (var i=forLoopStart; i<=forLoopEnd; i++){
			//If the Array spot has an entry
			if (seerStatCountyName[i]){
				//alert(seerStatCountyName[i]);
				//Create a new option for the county
				countyForm.options[j] = new Option(seerStatCountyName[i]);
				//Value of the option equals the state/county Fips
				countyForm.options[j].value = i;//+"&"+seerStatCountyName[i];
				j++;
			}
		}
	}
	else {
		//Erase all Current options from the County List Box
		countyForm.length=0;
		countyForm.options[0] = new Option("Entire State");
		countyForm.options[0].value = "000";//&Entire State";
		
		
		//Read counties in and sort them BEFORE adding to options
		var countyNames = new Array();
		var arrayLength = 0;
		var j = 0; 
		for (var i=forLoopStart; i<=forLoopEnd; i++) {
			//If the Array spot has an entry
			if (seerStatCountyName[i]) {
				//countyNames.push(seerStatCountyName[i]+"***"+i);
				countyNames[j] = (seerStatCountyName[i]+"***"+i);
				j++;
			}
		}//for
		
		countyNames.sort();
		var j = 1; //Separate Counter for assigning the members of the list box
		for (var i=0; i<countyNames.length; i++){
			//alert("countyNames[i] = "+countyNames[i]);
			var name = countyNames[i].substring(0, countyNames[i].indexOf('*'));
			//alert("name = "+name);
			var longFips = countyNames[i].substring(countyNames[i].lastIndexOf('*')+1, countyNames[i].length);
			var longFipsLength = longFips.length;
			var fips = longFips.substring(longFipsLength-3, longFipsLength);
			countyForm.options[j] = new Option(name);
			countyForm.options[j].value = fips;//+"&"+name;
			j++;
			//}
			}//for
		}//else
	countyForm.selectedIndex = 0;	//Select First Record in List Box
}
