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.RiskBox
	var index = list.selectedIndex;
	var Risk = list.options[index].value;
	
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Gender = list.options[index].value;
	
	//var Sort = formObj.SortBox.value;
	var okToSubmit = 0;
	var listForError = "";
	
	if (Risk == "**") {
		listForError = listForError + "Risk\n";
	}
	if (Gender == "*") {
		listForError = listForError + "Gender\n";
	}
	//return okToSubmit;
	return listForError;
}

function setSex() { 
	var list = document.UserForm.RiskBox
	var index = list.selectedIndex;
	var risk = list.options[index].value;
//	alert ("cancer is "+cancer);
	
	var genderBox = document.UserForm.GenderBox;
	var current=genderBox.selectedIndex;
	var currentGender = genderBox.options[current].value;
	if ( (risk == '02') || (risk == '04') || (risk == '05') || (risk == '06') || (risk == '07') || (risk == '10') || (risk == '11') || (risk == '25')  ){
		genderBox.length = 0;
		genderBox.options[0] = new Option("Females");
		genderBox.options[0].value = "2";
		genderBox.selectedIndex = 0; //female
		genderBox.disabled = true;
	}
	//else if (risk == '04') {
	//	genderBox.length = 0;
	//	genderBox.options[0] = new Option("Females");
	//	genderBox.options[0].value = "2";
	//	genderBox.selectedIndex = 0; //female
	//}
	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
		
}



function UpdateSelectedRisk()
{
        var VisibleForm = document.UserForm;
        paramArray = GetParams();
	
	var CurrentRiskVisible = VisibleForm.RiskBox;
	var CurrentSexVisible = VisibleForm.GenderBox;
	
	var CurrentRiskHidden = paramArray[0];
	//var CurrentSexHidden = paramArray[1];
	var lastparam = paramArray[1];
	var lastparamarray = lastparam.split('#');
	var CurrentSexHidden = lastparamarray[0];
	
	for (var i=0; i<CurrentRiskVisible.length; i++) {
	  if (CurrentRiskHidden == CurrentRiskVisible.options[i].value)   {
	    CurrentRiskVisible.selectedIndex=i;
	    break;
	  }
	}
	setSex();
	for (var i=0; i<CurrentSexVisible.length; i++) {
	  if (CurrentSexHidden == CurrentSexVisible.options[i].value)   {
	    CurrentSexVisible.selectedIndex=i;
	    break;
	  }
	}
	
	
}

//4 list boxes on this page
function submitRisk() {
	//alert("in quickhealthy2_2");
	statesite="/cgi-bin/risk/risk.pl";	
	//countysite="/cgi-bin/quickreport.healthy.counties.pl";	
	var formObj = document.UserForm;
	//var Cancer =     formObj.CancerBox.value;
	var list = formObj.RiskBox
	var index = list.selectedIndex;
	var Risk = list.options[index].value;
	
	
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Sex = list.options[index].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 = Risk + "&" + Sex + "&" + 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 submitRisk2() {
	//alert("in quickhealthy2_2");
	statesite="/cgi-bin/risk/risk.pl";	
	//countysite="/cgi-bin/quickreport.healthy.counties.pl";	
	var formObj = document.UserForm;
	//var Cancer =     formObj.CancerBox.value;
	var list = formObj.RiskBox
	var index = list.selectedIndex;
	var Risk = list.options[index].value;
	
	var list = formObj.GenderBox
	var index = list.selectedIndex;
	var Sex = list.options[index].value;
	
	var paramArray = GetParams();
	var Sort = paramArray[2];
	var SortOrder = paramArray[3];
	
	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 = Risk + "&" + Sex + "&" + 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
}
