	
	var OutputLevel;            
        var MaximumNumZipCtyHDists;
		var IsCountyHealthDistrictSelected;            
        var DefaultCountyIndex;
        var DefaultIndicatorIndex;
        
        var LastICD9Year = 1998;		
        
        var MaxIndicatorValue = 15;
        
        var TOP_TEN_CAUSES = "...Top Ten Causes of Death";
        
        var IsCountyHealthDistrictSelected = false;
            
        DefaultCountyIndex = 0;
        DefaultIndicatorIndex = 1;
			
		OutputLevel = 2; // County on loading  
        MaximumNumZipCtyHDists = 15
            
     // funtions for modifing select box options
	function deleteOption(object,index) 
	{
		object.options[index] = null;
	}

	function addOption(object,text,value) 
	{
		var defaultSelected = true;
		var selected = true;
		var optionName = new Option(text, value, defaultSelected, selected)
		object.options[object.length] = optionName;
	}
	
	function addOption2(object,text,value) 
	{
		var defaultSelected = false;
		var selected = false;
		var optionName = new Option(text, value, defaultSelected, selected)
		object.options[object.length] = optionName;
		
	}	
	
	function addSelected(fromObject,toObject) 
	{    
		var sel = getSelected(fromObject.options);
		var j = -1;
			
		outerLoop:
		for (var item in sel)
		{												
			for (j = 0, l = toObject.options.length; j < l; j++)
			{									
				if (sel[item].text == toObject.options[j].text)
				{
					continue outerLoop;
				}					
			}	
			
			if (sel[item].value == "grpheading")
			{
				alert (sel[item].text + " is a group name of available Infant Mortality Variables and it cannot be added")
				continue outerLoop;
			}
			
			addOption(toObject,sel[item].text,sel[item].value);							
		}	
						
		if (j < 0)
		{
		   //alert ("Please select one or more zipcodes/counties/healthdistricts that you want to add from the above List");
		   return -1;
		}
		else
		{
			fromObject.options.selectedIndex = -1;	
		}
			
		return 1;
				
	}
   
	function removeSelected(fromObject) 
	{
		var sel = getSelected(fromObject.options);
		var i = 0;
			
		   for (var item in sel)
		{
			deleteOption(fromObject,sel[item].index - i);
			++i;								
		}			
	}
		
	// Removes all items from selected zipcodes/counties/healthdists
	function removeAll(fromObject) 
	{
		if (fromObject.options.length == 0)
		{
			return;
		}
		
		for (var i = fromObject.options.length - 1; i > -1; i--)
		{
			deleteOption(fromObject,i);										
		}					
	}
		
	// Returns the multiple items selected in Select List Box
	// as an array		
	function getSelected(opt) 
	{
		var selected = new Array();
		var index = 0;
           
		for (var intLoop = 0; intLoop < opt.length; intLoop++) 
		{
			if ((opt[intLoop].selected)) 
			{
				index = selected.length;
				selected[index] = new Object;
				selected[index].value = opt[intLoop].value;
				selected[index].index = intLoop;                  
				selected[index].text = opt[intLoop].text;
			}
         }
		return selected;
     }
         
    // Returns all items in Select List Box
	//  as an array		
	function getAllItems(opt) 
	{
        var allItems = new Array();
        var index = 0;
           
        for (var intLoop = 0; intLoop < opt.length; intLoop++) 
        {
			index = allItems.length;
            allItems[index] = new Object;
            allItems[index].value = opt[intLoop].value;
            allItems[index].index = intLoop;                  
            allItems[index].text = opt[intLoop].text;               
        }
        return allItems;
   }
   
   function addAllItems (sel, toObject)
	{
		var j;
									
		outerLoop:
		for (var item in sel)
		{												
			for (j = 0, l = toObject.options.length; j < l; j++)
			{									
				if (sel[item].text == toObject.options[j].text)
				{
						continue outerLoop;
				}				
			}					
				
			addOption(toObject,sel[item].text,sel[item].value);							
		}							
						
	}	
		  	
	//
	//  Fills the select box with available counties  
	//	
	function setCounties()
	{
		if (OutputLevel == 2 && document.forms[0].levelcty.checked == true)
              return;
        
        OutputLevel = 2;
       // EnableStep6Options ();
       // DisableConfidentialityRules ();
           
        window.status = "Please wait while the regions listbox is filled"        
        removeAll (document.forms[0].CtyZipHDist);
        removeAll (document.forms[0].SelCtyZipHDist);
         
        CountyList = document.forms[0].TxtCountyList.value;
		Counties = CountyList.split (";");
				
		for (var i = 0; i < Counties.length - 1; i = i + 2)
		{
			addOption2(document.forms[0].CtyZipHDist, Counties[i], Counties[i+1]);
		}
		document.forms[0].CtyZipHDist[0].selected = true;	
		
		setDefaultLocation ();	
		
		window.status = "Done"
				
	}
	
	//
	//  Fills the select box with available Health Districts
	//		
    			
	function setHDistricts()
	{
	
		if (OutputLevel == 3 && document.forms[0].levelhdist.checked == true)
              return;
        
        OutputLevel = 3;
        //EnableStep6Options ();
        //DisableConfidentialityRules ();
           
        window.status = "Please wait while the regions listbox is filled"        
        removeAll (document.forms[0].CtyZipHDist);
        removeAll (document.forms[0].SelCtyZipHDist);
        
        HDistList = document.forms[0].TxtHDistList.value;
		HDists = HDistList.split (";");
				
		for (var i = 0; i < HDists.length - 1; i = i + 2)
		{
			addOption2(document.forms[0].CtyZipHDist, HDists[i], HDists[i+1]);
		}
		document.forms[0].CtyZipHDist[0].selected = true;
		
		setDefaultLocation ();
		
		window.status = "Done"
				
	}
	
	// Disable rates, conf intervals
	function EnableConfidentialityRules ()
	{
		if (document.forms[0].georates1.checked == true || document.forms[0].conf1.checked == true ||
				document.forms[0].georates.checked == true)
		{
			alert ("Percents, Rates and 95% Confidential Intervals in Step Nine are not available when Zip Codes is selected in Step Five");		
		}	
		//document.forms[0].georates.checked = false;		
		//document.forms[0].georates.disabled = true;
		//document.forms[0].georates1.checked = false;		
		//document.forms[0].georates1.disabled = true;
		//document.forms[0].conf1.checked = false;
		//document.forms[0].conf1.disabled = true;
	}
	
	function DisableConfidentialityRules ()
	{
		//document.forms[0].georates.disabled = false;
		//document.forms[0].georates1.disabled = false;		
		//DisableConfidenceIntervals ();	
		
	}		
	
	// Adds selected locations to the Selected List Box (ca)				
	function addCtyZipHDist ()
    {
		var i;		
		
		if (IsTopTenCausesAlreadySelected () == 1 && document.forms[0].SelCtyZipHDist.options.length >= 1)
		{
			alert ("Multiple regions of interest cannot be selected in Step Six is  when Top Ten Caues of Death is chosen Step Seven")
			return;
		}
		
		i = addSelected(document.forms[0].CtyZipHDist, document.forms[0].SelCtyZipHDist);		
		if (i == -1)
			alert ("Please select one or more Regions that you want to add from the above List");
		
	}
        
    // Removes selected locations from the Selected List Box (ca)      
	function removeCtyZipHDist ()
	{
		removeSelected(document.forms[0].SelCtyZipHDist);		
	}
	
	
		
	// returns 1 if TopTenCauses is selected
	function IsTopTenCausesSelectedToAdd ()
	{
		var opt;
		var index = 0;
		
		opt = document.forms[0].IMIndicators.options;
           
		for (var intLoop = 0; intLoop < opt.length; intLoop++) 
		{
			if ((opt[intLoop].selected)) 
			{
				if (opt[intLoop].text == TOP_TEN_CAUSES)
					return 1;				
			}
         }
		return -1;
	}
	
	// returns 1 if TopTenCauses is selected
	function IsTopTenCausesAlreadySelected ()
	{
		var opt;
		var index = 0;
		
		opt = document.forms[0].SelIMIndicators.options;
           
		for (var intLoop = 0; intLoop < opt.length; intLoop++) 
		{
			if (opt[intLoop].text == TOP_TEN_CAUSES)
				return 1;				
			
       }
                
		return -1;
	}
	
	// returns 1 if TopTenCauses is selected to remove
	function IsTopTenCausesSelectedToRemove ()
	{
		var opt;
		var index = 0;
		
		opt = document.forms[0].SelIMIndicators.options;        
           
		for (var intLoop = 0; intLoop < opt.length; intLoop++) 
		{			
			if ((opt[intLoop].selected)) 
			{
				if (opt[intLoop].text == TOP_TEN_CAUSES)
					return 1;				
			}
        }
         
		return -1;
	}
	
	
	// Adds selected locations to the Selected List Box (ca)				
	function addIMIndicators ()
    {
		var i;
		var j;
		
		i = IsTopTenCausesAlreadySelected ();
		
		if (i != 1)
		{
			i = IsTopTenCausesSelectedToAdd ();
			
			if (i != 1)
			{		
				i = addSelected(document.forms[0].IMIndicators, document.forms[0].SelIMIndicators)			
				
				if (i == -1)
					alert ("Please select one or more Available Infant Mortality Variables that you want to add from the above List");
			}
			else
			{
				// remove any existing selections
					if (document.forms[0].SelIMIndicators.options.length > 0)
					{
						alert ("Multiple Infant Mortality Variables cannot be selected with Top Ten Causes of Death");
						removeAll(document.forms[0].SelIMIndicators);
					}
				//  add only Top Ten Causes
					j = getIndicatorValueByName (TOP_TEN_CAUSES)
					if (j >= 0)
						addOption(document.forms[0].SelIMIndicators,document.forms[0].IMIndicators.options[j].text, document.forms[0].IMIndicators.options[j].value);								
			}	
			
	    }
	    else
			alert ("Multiple Infant Mortality Variables cannot be selected with Top Ten Causes of Death");
	   	
	}	
	        
    // Removes selected indicators from the Selected List Box (ca)      
	function removeIMIndicators ()
	{
		removeSelected(document.forms[0].SelIMIndicators);
	}
	
	// Set the default options in Step 4
	function SetDefaultRaceEthnicityMaritalStatusAges()
	{
		/*if (document.forms[0].rc.selectedIndex != 0 || document.forms[0].et.selectedIndex != 0 ||
			document.forms[0].ma.selectedIndex != 0 || document.forms[0].ag.selectedIndex != 0)
		{
			alert ("Fertility Rates are available for All Races, All Ethnicities, All Marital Status, All Ages only in Step Four");
			
			document.forms[0].rc.selectedIndex = 0;
			document.forms[0].et.selectedIndex = 0;
			document.forms[0].ma.selectedIndex = 0;
			document.forms[0].ag.selectedIndex = 0;
		}*/
	}
	
	// sets default health indicator
	function setDefaultIMIndicator ()
	{
		if (document.forms[0].SelIMIndicators.options.length != 0)
			removeAll (document.forms[0].SelIMIndicators);
		addOption(document.forms[0].SelIMIndicators, document.forms[0].IMIndicators.options[DefaultIndicatorIndex].text, document.forms[0].IMIndicators.options[DefaultIndicatorIndex].value);
	}
	
	// set default location	
	function setDefaultLocation ()
	{
		// if the page is loaded for first time then add default Zip Codes/Counties/Health Districts			
		if (document.forms[0].SelCtyZipHDist.options.length == 0 && document.forms[0].CtyZipHDist.options.length > 0)
		{
			addOption(document.forms[0].SelCtyZipHDist,document.forms[0].CtyZipHDist.options[DefaultCountyIndex].text, document.forms[0].CtyZipHDist.options[DefaultCountyIndex].value);		
		}
	}	
	
	function getIndicatorValueByName (val)
	{			
		var opt = document.forms[0].IMIndicators.options;			
			
		for (var i = 0; i < opt.length; ++i)	
		{
		   if (opt[i].text == val)
			   return i;				
		}
		
		return -1;			
	}	
	
	// Enables Confidence-Intervals
	function EnableConfidenceIntervals ()
	{
		if (document.forms[0].conf1.disabled == false)
			return;
		else
			document.forms[0].conf1.disabled = false;
	}
	
	// Disables Confidence-Intervals
	function DisableConfidenceIntervals ()
	{
		if (document.forms[0].conf1.disabled == true)
			return;
		else
		{
			if (document.forms[0].conf1.checked == true && document.forms[0].georates2.checked == false)
			{
				alert ("frequencies and rates must be selected in Step Eight for 95% Confidence Intervals")
				document.forms[0].conf1.checked = false;
			}
			document.forms[0].conf1.disabled = true;
		}
	}
	
	// returns the number of years selected by user
	function NumofYears ()
	{
		var numYears;
		var YearsArray;
		var j;
					
		numYears = document.forms[0].yr.length;
		YearsArray = new Array();
		j = 0;
						
		// copy all years selected to YearsArray
		for (i = 0; i < numYears; ++i)
		{
			if (document.forms[0].yr[i].checked == true)
			{	
				YearsArray[j] = i;					
				++j;
			}
		}
			
		return YearsArray.length;	
			
	}
	
	function CheckForValidBirthweight()
	{
		if (document.forms[0].bw[document.forms[0].bw.selectedIndex].value == "Empty")
		{
			alert ("Please select a valid Birthweight")
			document.forms[0].bw.selectedIndex = 0;
		}
			
	}
	
	// select or un select all years
	function SelectAllYears ()
	{
		var numYears;
        numYears = document.forms[0].yr.length;
                    
        if (document.forms[0].allyr.checked == true)
        {
			for (i = 0; i < numYears; i++)
			{
				document.forms[0].yr[i].checked = true;				
			}
        }
        else
        {
			for (i = 0; i < numYears; i++)
			{
				document.forms[0].yr[i].checked = false;				
			}	
        }
                  
       return -1;   
	
	}
    
	
	//   Validates Row, Column selections				
	function validateRowColVariables() 
	{
		var rowVal;
        var colVal;
        var numRows
        var numCols;    
                    
		numRows = document.forms[0].row.length;         
		numCols = document.forms[0].col.length;     
                                
        for (i = 0; i < numRows; i++)
        {
            if (document.forms[0].row[i].checked == true)
            {   
                rowVal = i;
            }
        }
                    
       for (i = 0; i < numCols; i++)
       {
            if (document.forms[0].col[i].checked == true)
            {   
                colVal = i;
            }
       }
                    
       if (rowVal == colVal)
       {
            return -1;          
       }                    
       
       return 1;
                    
     }
                
     // validates the year of interest selected by user
     // if user does not select any year returns -1
     // else returns 1
                
      function validateYear ()
      {
         var numYears;
         numYears = document.forms[0].yr.length;
                    
         for (i = 0; i < numYears; i++)
         {
             if (document.forms[0].yr[i].checked == true)
             {   
                  return 1;
             }
         }
                  
         return -1;                        
      }    
    
    // validates Zip Codes/Counties/Health Districts
	// if user selects one or more Zip Codes/Counties/Health Districts then returns 1
	// else returns -1	
		
	function validateZipCtyHDists ()
	{
		var allItems;
		
		if (IsCountyHealthDistrictSelected == true)
			return 1;		
		
		if (document.forms[0].SelCtyZipHDist.options.length == 0)
			return -1;
				
		// get all items in the selected Zip Codes/Counties/Health Districtss
		allItems = getAllItems (document.forms[0].SelCtyZipHDist)
		// remove all items
		removeAll (document.forms[0].SelCtyZipHDist);	
					
		// highlight all items 
		addAllItems (allItems, document.forms[0].SelCtyZipHDist);				
		
		// Check if Top Ten Causes is chosen and mulitple locations are selected
		if (IsTopTenCausesAlreadySelected () == 1 && document.forms[0].SelCtyZipHDist.options.length > 1)
		{
			return -4;
		}						
		
		// check if location is not row variable and user selected multiple locations
		if ((document.forms[0].row[6].checked == false && document.forms[0].col[6].checked == false) && 
					document.forms[0].SelCtyZipHDist.options.length > 1)
		{
			return -2;	
		}
											
		// check if location is row/col variable and user selected more than MaximumNumZip Codes/Counties/Health Districtss
		// with trend-line or bar charts
		if ((document.forms[0].row[6].checked == true || document.forms[0].col[6].checked == true) && 
				document.forms[0].SelCtyZipHDist.options.length > MaximumNumZipCtyHDists && 
				document.forms[0].tab1.checked == false)
		{
			return -3;	
		}	
					
		return 1;
	}
	
	function validateIMIndicators()
	{
		var allItems;		
		
		if (document.forms[0].SelIMIndicators.options.length == 0)
			return -1;
				
		// get all items in the selected Health and Life Style Indicators
		allItems = getAllItems (document.forms[0].SelIMIndicators)
		// remove all items
		removeAll (document.forms[0].SelIMIndicators);	
					
		// highlight all items 
		addAllItems (allItems, document.forms[0].SelIMIndicators);				
								
		// check if Indicators is not row/col variable and user selected multiple Indicators
		if (document.forms[0].row[7].checked == false && document.forms[0].col[7].checked == false && document.forms[0].SelIMIndicators.options.length > 1)
		{
			return -2;	
		}
											
		// check if Indicators is row/col variable and user selected more than MaximumNum  Indicators
		if ((document.forms[0].row[7].checked == true || document.forms[0].col[7].checked == true) && document.forms[0].SelIMIndicators.options.length > MaximumNumZipCtyHDists && document.forms[0].tab1.checked == false)
		{
			return -3;	
		}	
		
		// check if Indicators is row/col variable and user selected Top Ten Causes of Death
		if (document.forms[0].row[7].checked == false && document.forms[0].col[7].checked == false && IsTopTenCausesAlreadySelected() == 1)
		{
			return -4;	
		}
					
		return 1;	
	}
	
	
	function validateOutcomes()
	{
		var numOutComes;
		var j;
		j = 0;
		numOutcomes = document.forms[0].out.length;         
		
		for (i = 0; i < numOutcomes; i++)
        {
			if (document.forms[0].out[i].checked == true)
			{   
				j++;
			}
		}
				
		if (document.forms[0].row[6].checked == true && j > 0)
		{
			return 1;
		}
		else if (document.forms[0].row[6].checked == false && j > 1)
		{
			return -2;
		}
		else if (document.forms[0].row[6].checked == false && j == 1)
		{
			return 1;
		}		
		
		return -1;
		
	}
	
	function saveSelectedZipCtyHDists ()
	{
		var allItems;
		
		document.forms[0].selopt.value = "";
				
		// get all items in the selected Zip Codes/Counties/Health Districtss
		allItems = getAllItems (document.forms[0].SelCtyZipHDist);
		
		for (var item in allItems)
		{								
			document.forms[0].selopt.value =  document.forms[0].selopt.value + allItems[item].text +  ";" + allItems[item].value +  ";";	
		}					
		
	}
	
	function saveSelectedIndicators ()
	{
		var allItems;
		
		document.forms[0].selindicators.value = "";
				
		// get all items in the selected Health and Life Sytle Indicators
		allItems = getAllItems (document.forms[0].SelIMIndicators);
		
		for (var item in allItems)
		{								
			document.forms[0].selindicators.value =  document.forms[0].selindicators.value + allItems[item].text +  ";" + allItems[item].value +  ";";	
		}			
		
	}
    
    // retains the selected locations and selected indicators when the browser's back button is clicked
    // using the delimited selected indexes in hidden text fields   
    function retainSelectedVars()
    {
		var selOptions;
		//if (document.forms[0].selout.value == 1 || document.forms[0].levelzip.checked == true)
			//setZipCodes ();
		//else 
		if (document.forms[0].selout.value == 3 || document.forms[0].levelhdist.checked == true)
			setHDistricts();
		else
			document.forms[0].CtyZipHDist[0].selected = true;
		
		selOptions	= document.forms[0].selopt.value;
		// fill the selected locations
		if (selOptions.length > 0)
		{
			window.status = "Please wait while the regions listbox is filled"        
	               
			SelectedOptions = document.forms[0].selopt.value;
			
			Options = SelectedOptions.split (";");
					
			for (var i = 0; i < Options.length - 1; i = i + 2)
			{
				addOption2(document.forms[0].SelCtyZipHDist, Options[i], Options[i+1]);
			}		
					
			window.status = "Done"
		}		
		
		selOptions	= document.forms[0].selindicators.value;
		// fill the selected indicators
		if (selOptions.length > 0)
		{
			window.status = "Please wait while the Infant Mortality Indicators listbox is filled"        
	               
			SelectedOptions = document.forms[0].selindicators.value;
			
			Options = SelectedOptions.split (";");
					
			for (var i = 0; i < Options.length - 1; i = i + 2)
			{
				addOption2(document.forms[0].SelIMIndicators, Options[i], Options[i+1]);
			}		
					
			window.status = "Done"
		}	
		
		// Disable 95% Confidence Intervals if 
		// 1. page-back was clicked and user selected Frequencies 
		// 2. page-back was clicked and user selected Frequencies and Percentages
		
		if (document.forms[0].georates1.checked == true || document.forms[0].geofrequencies.checked == true)
		{
			document.forms[0].conf1.disabled = true;				
		}
		else
			document.forms[0].conf1.disabled = false;
			
		// if the page is loaded for first time then add default Zip Codes/Counties/Health Districts			
		if (document.forms[0].SelCtyZipHDist.options.length == 0 && document.forms[0].CtyZipHDist.options.length > 0)
		{
			addOption(document.forms[0].SelCtyZipHDist,document.forms[0].CtyZipHDist.options[DefaultCountyIndex].text, document.forms[0].CtyZipHDist.options[DefaultCountyIndex].value);		
		}	
		
		// if the page is loaded for first time then add default Health and Life Syle indicator			
		if (document.forms[0].SelIMIndicators.options.length == 0 && document.forms[0].IMIndicators.options.length > 0)
		{
			addOption(document.forms[0].SelIMIndicators,document.forms[0].IMIndicators.options[DefaultIndicatorIndex].text, document.forms[0].IMIndicators.options[DefaultIndicatorIndex].value);		
		}	
		
    }
    
    function CheckOutputPreference()
	{
		var numOptions;
		var i;
		numOptions = document.forms[0].geo.length;
			
		for (i = 0; i < numOptions; i++)
		{
			if (document.forms[0].geo[i].checked == true)
			{	
				return i;
			}
		}
			
		return -1;
	}
	
	function CheckYearsOverlapICDCodes()
	{
		var numYears;
		var i;
		var bICD9 = 0;
		var bICD10 = 0;
					
		numYears = document.forms[0].yr.length;		
	
		for (i = 0; i < numYears; ++i)
		{
			if (document.forms[0].yr[i].checked == true)
			{	
				if (document.forms[0].yr[i].value <= LastICD9Year)
				    bICD9 = 1;
				else
					bICD10 = 1;					
			}			
			
		}
		
		if (bICD9 == 1 && bICD10 == 1)
			return 1;
					
		return -1;
	}	
	
	function CheckIfOnlyIndicatorsAreSelected ()
	{
		var opt;
		opt = document.forms[0].SelIMIndicators;
           
        for (var intLoop = 0; intLoop < opt.length; intLoop++) 
        {
		  // check if a cause of death is selected
		  if (opt[intLoop].value > MaxIndicatorValue)
			 return -1;    
        }
        		
		return 1;
	}
    
    function CheckForYearAsColVariable ()
	{
		if (document.forms[0].col[0].checked == true)
		{	
			return 1;
		}
		
		return -1;						
	}
	function CheckForYearAsRowVariable ()
	{
		if (document.forms[0].row[0].checked == true)
		{	
			return 1;
		}
		
		return -1;
						
	}
	
	function CheckForValidAge()
	{
		if (document.forms[0].ag[document.forms[0].ag.selectedIndex].value == "Empty")
		{
			alert ("Please select a valid age-group")
			document.forms[0].ag.selectedIndex = 0;
		}
			
	}
    
    function CheckForConsecutiveYearSelection ()
	{
		var numYears;
		var YearsArray;
		var j;
					
		numYears = document.forms[0].yr.length;
		YearsArray = new Array();
		j = 0;
						
		// copy all years selected to YearsArray
		for (i = 0; i < numYears; ++i)
		{
			if (document.forms[0].yr[i].checked == true)
			{	
				YearsArray[j] = i;					
				++j;
			}
		}
			
		if (YearsArray.length < 2)
			return -2;				
						
		for (i = 0; i < YearsArray.length - 1; ++i)
		{
			if (YearsArray[i + 1] - YearsArray[i] == 1)
			{
			}						
			else
				return -1;
		}			
			
		return 1;	
	}
	
	function validateOutputPresentation ()
	{
		var numOptions;
		var i;
		var j;
		var optionSelected;
		var notified;
				
		notified = 0;
		optionSelected = 0;
						
		numOptions = document.forms[0].tab.length;		
			
		for (i = 0; i < numOptions; i++)
		{
			if (document.forms[0].tab[i].checked == true)
			{						
				optionSelected = 1;				
							
				if (i == 1 || i == 3)
				{
					if (CheckForYearAsColVariable() == -1)
					{
						return -2;						
					}
						 
					j = CheckForConsecutiveYearSelection ();
					if (j == -2)
					{						
						return -3;
				 	}
						 
					if (j == -1)
					{
						return -4;
					}	
					
					if(CheckOutputPreference() == 3 && NumofYears() <= 3 )
					{
						return -6;
					}
					if(CheckOutputPreference() == 4 && NumofYears() <= 5 )
					{
						return -7;
					}
					if (CheckYearsOverlapICDCodes() == 1)
					{
						if (CheckIfOnlyIndicatorsAreSelected() == -1)
							return -8;
					}													
						
				}	
								
				if (i == 2)
				{
					if (CheckForYearAsColVariable () == -1 && CheckForYearAsRowVariable () == -1 && 
						CheckYearsOverlapICDCodes() == 1 )
					{
						return -9;
					}
				}	
								
				if (i == 1 || i == 2 || i == 3)
				{
					j = CheckOutputPreference();
					if (j == 0) //|| j == 1
						return -5;
				}			
					
			}					
				
		}
			
		// one of the options has been selected
		if (optionSelected == 1)
		    return 1;		
			
		return -1;
	}
	
	function validate3And5YearFrequencyRates ()
	{
				
		if (CheckOutputPreference() == 3)
		{
			if (CheckForYearAsColVariable() == -1 && CheckForYearAsRowVariable() == -1)
			{
				return -1;						
			}
			if (CheckForConsecutiveYearSelection() == -1)
			{
					return -2;
			}
			
			if (NumofYears() % 3 != 0)
			{
					return -3;
			} 
			
		}
		else if (CheckOutputPreference() == 4)
		{
			if (CheckForYearAsColVariable() == -1 && CheckForYearAsRowVariable() == -1)
			{
				return -4;						
			}
			if (CheckForConsecutiveYearSelection() == -1)
			{
				return -5;
			}
			
			if (NumofYears() % 5 != 0)
			{
				return -6;
			} 
			
		}		
		
		return 1;
	} 
                
	function validate ()
	{                       
		var i;              

		if (validateRowColVariables() == -1) 
		{
             alert ("Please select different row and column variables in Steps One and Two")
             return;
		}       
		if (validateYear () == -1)
		{
			alert ("Please select one or more years of interest in Step Three");
			return;
		}       		
                    
		i = validateZipCtyHDists ();
			
		if (i == -1)
		{
			alert ("Please select atleast one region of interest in Step Six")
			return;
		}
		else if (i == -2)
		{
			alert ("Please select Region as row/column variable in Step One/Step Two to select multiple regions in Step Six")
				return;
		}
		else if (i == -3)
		{
			alert ("Maximum number of regions of interest that you can select in Step Six is " + MaximumNumZipCtyHDists +  " only when Trend-line or Bar Chart are selected in Step Nine")
			return;
		}	
		else if (i == -4)
		{
			alert ("Multiple regions of interest cannot be selected in Step Six is  when Top Ten Caues of Death is chosen Step Seven")
			return;
		}
		
		
		i = validateIMIndicators ();
		
		if (i == -1)
		{
			alert ("Please select atleast one Infant Mortality Variable in Step Seven")
			return;
		}
		else if (i == -2)
		{
			alert ("Please select Infant Mortality Variables as row/column variable in Step One/Step Two to select multiple Infant Mortality Variables in Step Seven")
			return;
		}
		else if (i == -3)
		{
			alert ("Maximum number of Infant Mortality Variables that you can select in Step Seven is " + MaximumNumZipCtyHDists +  " only when Trend-line or Bar Chart are selected in Step Nine")
			return;
		}
		else if (i == -4)
		{
			alert ("Please select Infant Mortality Variables as row/column variable in Step One/Step Two to select Top Ten Causes of Death in Step Seven")
			return;
		}	
		
		//i = IsFertilityRateAlreadySelected ();		
		//if (i == 1)
		//	SetDefaultRaceEthnicityMaritalStatusAges();
		
			
		i = validateOutputPresentation ();	
		
		if (i == -1)
		{
			alert ("Please select one or more output presentation formats in Step Seven")
			return;
		}
		else if (i == -2)
		{
			alert ("Please select year as column variable in Step Two for Trend-line");
			return;
		}	
		else if (i == -3)
		{
			alert ("Please select more than one year in Step Three for Trend-line");
			return;
		}		
		else if (i == -4)
		{
			alert ("Please select consecutive years in Step Three for Trend-line");
			return;
		}	
		else if (i == -5)
		{
			alert("Please select an option other than Frequencies in Step Eight for Trend-line and Bar Charts");
			return;
		}	
		else if (i == -6)
		{
			alert ("Please select more than 3 years in Step Three for Trendline");
			return;
		}	
		else if (i == -7)
		{
			alert ("Please select more than 5 years in Step Three for Trendline");
			return;
		}
		else if (i == -8)
		{
			alert ("Trend-lines can only be generated when all the selected years are prior to 1988 (ICD9 Codes) or greater than 1988 (ICD10 Codes)");
			return;
		}
		else if (i == -9)
		{
			alert ("The selected years of interest overlap ICD9(prior to 1988) and ICD10(after 1988) Codes. Please select Year as row/col variable in Step One or select years of interest which are either prior to 1988 (ICD9 Codes) or greater than 1988 (ICD10 Codes)");
			return;
		}
		
		i = validate3And5YearFrequencyRates ();
			
		if (i == -1)
		{
			alert ("Please select year as row/column variable for 3 year frequency and rates")
			return;
		}
		else if (i == -2)
		{
			alert ("Please select multiples of 3 consecutive years in Step Three for 3 year frequency and rates");
			return;
		}	
		else if (i == -3)
		{
			alert ("Please select multiples of 3 consecutive years in Step Three for 3 year frequency and rates");
			return;
		}
		else if (i == -4)
		{
			alert ("Please select year as row/column variable for 5 year frequency and rates")
			return;
		}
		else if (i == -5)
		{
			alert ("Please select multiples of 5 consecutive years in Step Three for 5 year frequency and rates");
			return;
		}	
		else if (i == -6)
		{
			alert ("Please select multiples of 5 consecutive years in Step Three for 5 year frequency and rates");
			return;
		}					
		
		// now add selected locations to hidden text field
		saveSelectedZipCtyHDists ();
		// now add selected indicators to hidden text field
		saveSelectedIndicators ();
		document.forms[0].selout.value = OutputLevel;	
		
        document.forms[0].submit ();        
                    
	}	
