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 verifyCheckBoxes() {
	var formObj = document.UserForm;
	//var Cancer =     formObj.CancerBox.value;
	var list = formObj.CancerBox
	var index = list.selectedIndex;
	var Cancer = list.options[index].value;
	//var Geo =      formObj.StateBox.value;	
	var list = formObj.StateBox
	var index = list.selectedIndex;
	var Geo = list.options[index].value;
	
	//var Sex =      formObj.GenderBox.value;
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Sex = list.options[index].value;
	
	//Race
	var list = formObj.RaceBox
	var index = list.selectedIndex;
	var Race = list.options[index].value;
	
	//Age - not here yet
	//var list = formObj.AgeBox
	//var index = list.selectedIndex;
	//var Age = list.options[index].value;

	
	//var Sort = formObj.SortBox.value;
	var okToSubmit = 0;
	var listForError = "";
	
	if (Geo == "**") {
		listForError = listForError + "State\n";
	}
	if (Cancer == "***") {
		listForError = listForError + "Cancer\n";
	}
	if (Sex == "*") {
		listForError = listForError+ "Sex\n";
	}
	if (Race == "**") {
		listForError = listForError+ "Race\n";
	}
	//if (Age == "**") {
	//	listForError = listForError+ "Age\n";
	//}
	//if (Sort == "*") {
	//	listForError = listForError + "Sort By\n";
	//}
	
	//return okToSubmit;
	return listForError;
}


function UpdateSelectedHealthy()
{
        var VisibleForm = document.UserForm;
        paramArray = GetParams();
	
	var CurrentStateVisible = VisibleForm.StateBox;
	var CurrentCancerVisible = VisibleForm.CancerBox;
	var CurrentSexVisible = VisibleForm.GenderBox;
	var CurrentRaceVisible = VisibleForm.RaceBox;
	//var CurrentAgeVisible = VisibleForm.AgeBox;
//	var CurrentSortVisible = VisibleForm.SortBox;
	
	var CurrentStateHidden = paramArray[0];
	var CurrentCancerHidden = paramArray[1];
	var CurrentRaceHidden = paramArray[2];
	var CurrentSexHidden = paramArray[3];
	var CurrentAgeHidden = paramArray[4];
//	var CurrentSexHidden = paramArray[1];
//	var lastparam = paramArray[1];
//	var lastparamarray = lastparam.split('#');
//	var CurrentSexHidden = lastparamarray[0];
//	var CurrentSortHidden = paramArray[2];
	
	for (var i=0; i<CurrentStateVisible.length; i++) {
	  if (CurrentStateHidden == CurrentStateVisible.options[i].value)   {
	    CurrentStateVisible.selectedIndex=i;
	    break;
	  }
	}
	
	
	
	for (var i=0; i<CurrentCancerVisible.length; i++) {
	  if (CurrentCancerHidden == CurrentCancerVisible.options[i].value)   {
	    CurrentCancerVisible.selectedIndex=i;
	    break;
	  }
	}
	SwitchGendersHealthy() ;
	for (var i=0; i<CurrentSexVisible.length; i++) {
	  if (CurrentSexHidden == CurrentSexVisible.options[i].value)   {
	    CurrentSexVisible.selectedIndex=i;
	    break;
	  }
	}
	
	for (var i=0; i<CurrentRaceVisible.length; i++) {
	  if (CurrentRaceHidden == CurrentRaceVisible.options[i].value)   {
	    CurrentRaceVisible.selectedIndex=i;
	    break;
	  }
	}
	
//	for (var i=0; i<CurrentAgeVisible.length; i++) {
//	  if (CurrentAgeHidden == CurrentAgeVisible.options[i].value)   {
//	    CurrentAgeVisible.selectedIndex=i;
//	    break;
//	  }
//	}
	
}

//4 list boxes on this page
function submitHealthy() {
	//alert("in quickhealthy2_2");
	statesite="/cgi-bin/deathrates/deathrates.pl";	
	var formObj = document.UserForm;
	//var Cancer =     formObj.CancerBox.value;
	var list = formObj.CancerBox
	var index = list.selectedIndex;
	var Cancer = list.options[index].value;
	//var Geo =      formObj.StateBox.value;	
	var list = formObj.StateBox
	var index = list.selectedIndex;
	var Geo = list.options[index].value;
	
	
	var list = formObj.RaceBox
	var index = list.selectedIndex;
	var Race = list.options[index].value;
	
	//var Sex =      formObj.GenderBox.value;
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Sex = list.options[index].value;
	
	//var Age not here yet
	//var list = formObj.AgeBox
	//var index = list.selectedIndex;
	//var Age = list.options[index].value;
	var Age = "001";
	if (Cancer == '515') {
		Age = '015';
	}
	else if (Cancer == '516') {
		Age = '016';
	}
	
	
	
	//var Sort = VisibleForm.SortBox.value;
	var Sort = 1; //sort by rate
	var SortOrder = 1; // descending, so top is places that are in the worst shape
	
	var listForError = verifyCheckBoxes() ;
		
	if (listForError != "") {
		
		alert("Please make a selection for each category 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 {
   	str = Geo+"&"+Cancer + "&" + Race +"&"+Sex + "&" + Age + "&" + Sort + "&" + SortOrder +"&1";//the one is for the regular report with links, triangles, etc.
	if (str.indexOf("nodata")!=-1) 
		str="nodata";
		
	var destination = statesite + "?" + str;		
	window.location.href = destination;
	}//else no gender mixup
}


function submitHealthy2() {
	//alert("in quickhealthy2_2");
	statesite="/cgi-bin/deathrates/deathrates.pl";	
	var formObj = document.UserForm;
	//var Cancer =     formObj.CancerBox.value;
	var list = formObj.CancerBox
	var index = list.selectedIndex;
	var Cancer = list.options[index].value;
	//var Geo =      formObj.StateBox.value;	
	var list = formObj.StateBox
	var index = list.selectedIndex;
	var Geo = list.options[index].value;
	
	var list = formObj.RaceBox
	var index = list.selectedIndex;
	var Race = list.options[index].value;
	
	//var Sex =      formObj.GenderBox.value;
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Sex = list.options[index].value;
	
	//var Age not here yet
	//var list = formObj.AgeBox
	//var index = list.selectedIndex;
	//var Age = list.options[index].value;
	var Age = "001";
	if (Cancer == '515') {
		Age = '015';
	}
	else if (Cancer == '516') {
		Age = '016';
	}
	
	//var Sort = VisibleForm.SortBox.value;
	//var SortOrder = 0;
	var paramArray = GetParams();
	var Sort = paramArray[5];
	var SortOrder = paramArray[6];
	
	var listForError = verifyCheckBoxes() ;
		
	if (listForError != "") {
		alert("Please make a selection for each category 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 {
   	str = Geo+"&"+Cancer + "&" + Race+"&"+Sex + "&" + Age + "&" + Sort + "&" + SortOrder + "&1"; //the one is for regular report
	if (str.indexOf("nodata")!=-1) 
		str="nodata";
		
	var destination = statesite + "?" + str;		
	window.location.href = destination;
	}//else no gender mixup
}

function SwitchGendersHealthy() {
//	alert("in changeSex()");
//	var cancer = document.UserForm.CancerBox.value;
	var list = document.UserForm.CancerBox
	var index = list.selectedIndex;
	var cancer = list.options[index].value;
//	alert ("cancer is "+cancer);
	
	var genderBox = document.UserForm.GenderBox;
	var current=genderBox.selectedIndex;
	var currentGender = genderBox.options[current].value;
	if (  (cancer == '055') || (cancer == '057') || (cancer == '058') || (cancer == '061') )  {
		genderBox.length = 0;
		genderBox.options[0] = new Option("Females");
		genderBox.options[0].value = "2";
		genderBox.selectedIndex = 0; //female
		genderBox.disabled = true;
	}
	else if (cancer == '066') {
		genderBox.length = 0;
		genderBox.options[0] = new Option("Males");
		genderBox.options[0].value = "1";
		genderBox.selectedIndex = 0; //male
		genderBox.disabled = true;
	}
	else {
		genderBox.disabled = false;
		genderBox.length = 0;
		genderBox.options[0] = new Option(CHOOSE_BEGINNING + "choose sex" + CHOOSE_END);
		genderBox.options[0].value = "*";
		genderBox.options[1] = new Option("Both Sexes");
		genderBox.options[1].value = "0";
		genderBox.options[2] = new Option("Males");
		genderBox.options[2].value = "1";
		genderBox.options[3] = new Option("Females");
		genderBox.options[3].value = "2";
		
		genderBox.selectedIndex = 0; 
		for (i=0; i<genderBox.length; i++) {
			if (genderBox.options[i].value == currentGender) {
				genderBox.selectedIndex=i;
				break;
			}
		}
	}//else
		
}
