/********************************************************
IPLAN Data System JavaScript
Illinois Department of Public Health
*********************************************************/

	

function selectRegionalCounties(Region){
	/**************
	 NN added May 7, 2003
	Code for auto selecting counties when requesting Regional data
	***************/

//	alert("here!");
	
	//clear all selected options	
		var nSelLength = 0;
		nSelLength = document.selForm.CntyCode.length; //get number of current selections and then clear
		for (i=0; i<nSelLength; i++) {
			document.selForm.CntyCode.options[i].selected = false;
		}
		// end clear values
	

	//Champaign Region
		if (Region == 'Champaign_Region'){
				// select option index number in list
				//Champaign, value 1
				document.selForm.CntyCode.options[10].selected = true;
				document.selForm.CntyCode.options[12].selected = true;
				document.selForm.CntyCode.options[15].selected = true;
				document.selForm.CntyCode.options[20].selected = true;
				document.selForm.CntyCode.options[22].selected = true;
				document.selForm.CntyCode.options[23].selected = true;
				document.selForm.CntyCode.options[26].selected = true;
				document.selForm.CntyCode.options[31].selected = true;
				document.selForm.CntyCode.options[42].selected = true;
				document.selForm.CntyCode.options[57].selected = true;
				document.selForm.CntyCode.options[79].selected = true;
				document.selForm.CntyCode.options[59].selected = true;
				document.selForm.CntyCode.options[68].selected = true;
				document.selForm.CntyCode.options[74].selected = true;
				document.selForm.CntyCode.options[91].selected = true;
				document.selForm.CntyCode.options[100].selected = true;
		}
		
		if (Region == 'Chicago_Region'){
				document.selForm.CntyCode.options[17].selected = true;
		}
		
		if (Region == 'Edwardsville_Region'){
				//Edwardsville Region, value 2
				document.selForm.CntyCode.options[2].selected = true;
				document.selForm.CntyCode.options[6].selected = true;
				document.selForm.CntyCode.options[11].selected = true;
				document.selForm.CntyCode.options[14].selected = true;
				document.selForm.CntyCode.options[35].selected = true;
				document.selForm.CntyCode.options[46].selected = true;
				document.selForm.CntyCode.options[60].selected = true;
				document.selForm.CntyCode.options[61].selected = true;
				document.selForm.CntyCode.options[71].selected = true;
				document.selForm.CntyCode.options[72].selected = true;
				document.selForm.CntyCode.options[73].selected = true;
				document.selForm.CntyCode.options[80].selected = true;
				document.selForm.CntyCode.options[94].selected = true;
				document.selForm.CntyCode.options[84].selected = true;
				document.selForm.CntyCode.options[88].selected = true;
				document.selForm.CntyCode.options[90].selected = true;
				document.selForm.CntyCode.options[103].selected = true;
		}
		
		// Marion region
		if (Region == 'Marion_Region'){
				document.selForm.CntyCode.options[1].selected = true;
				document.selForm.CntyCode.options[13].selected = true;
				document.selForm.CntyCode.options[19].selected = true;
				document.selForm.CntyCode.options[27].selected = true;
				document.selForm.CntyCode.options[28].selected = true;
				document.selForm.CntyCode.options[30].selected = true;
				document.selForm.CntyCode.options[32].selected = true;
				document.selForm.CntyCode.options[34].selected = true;
				document.selForm.CntyCode.options[37].selected = true;
				document.selForm.CntyCode.options[39].selected = true;
				document.selForm.CntyCode.options[43].selected = true;
				document.selForm.CntyCode.options[44].selected = true;
				document.selForm.CntyCode.options[45].selected = true;
				document.selForm.CntyCode.options[48].selected = true;
				document.selForm.CntyCode.options[55].selected = true;
				document.selForm.CntyCode.options[62].selected = true;
				document.selForm.CntyCode.options[65].selected = true;
				document.selForm.CntyCode.options[78].selected = true;
				document.selForm.CntyCode.options[81].selected = true;
				document.selForm.CntyCode.options[82].selected = true;
				document.selForm.CntyCode.options[85].selected = true;
				document.selForm.CntyCode.options[87].selected = true;
				document.selForm.CntyCode.options[99].selected = true;
				document.selForm.CntyCode.options[101].selected = true;
				document.selForm.CntyCode.options[104].selected = true;
				document.selForm.CntyCode.options[105].selected = true;
				document.selForm.CntyCode.options[108].selected = true;
				
		}
		
		//Peoria Region
		if (Region == 'Peoria_Region'){
				document.selForm.CntyCode.options[0].selected = true;
				document.selForm.CntyCode.options[4].selected = true;
				document.selForm.CntyCode.options[5].selected = true;
				document.selForm.CntyCode.options[8].selected = true;
				document.selForm.CntyCode.options[33].selected = true;
				document.selForm.CntyCode.options[38].selected = true;
				document.selForm.CntyCode.options[40].selected = true;
				document.selForm.CntyCode.options[41].selected = true;
				document.selForm.CntyCode.options[52].selected = true;
				document.selForm.CntyCode.options[53].selected = true;
				document.selForm.CntyCode.options[58].selected = true;
				document.selForm.CntyCode.options[63].selected = true;
				document.selForm.CntyCode.options[64].selected = true;
				document.selForm.CntyCode.options[66].selected = true;
				document.selForm.CntyCode.options[69].selected = true;
				document.selForm.CntyCode.options[70].selected = true;
				document.selForm.CntyCode.options[77].selected = true;
				document.selForm.CntyCode.options[83].selected = true;
				document.selForm.CntyCode.options[86].selected = true;
				document.selForm.CntyCode.options[89].selected = true;
				document.selForm.CntyCode.options[95].selected = true;
				document.selForm.CntyCode.options[98].selected = true;
				document.selForm.CntyCode.options[102].selected = true;
				document.selForm.CntyCode.options[110].selected = true;
		}
		
		//Rockford Region
		if (Region == 'Rockford_Region'){
				document.selForm.CntyCode.options[3].selected = true;
				document.selForm.CntyCode.options[7].selected = true;
				document.selForm.CntyCode.options[21].selected = true;
				document.selForm.CntyCode.options[47].selected = true;
				document.selForm.CntyCode.options[56].selected = true;
				document.selForm.CntyCode.options[76].selected = true;
				document.selForm.CntyCode.options[96].selected = true;
				document.selForm.CntyCode.options[106].selected = true;
				document.selForm.CntyCode.options[109].selected = true;
		}
		
		//West Chicago Region
		if (Region == 'WestChicago_Region'){
				document.selForm.CntyCode.options[24].selected = true;
				document.selForm.CntyCode.options[36].selected = true;
				document.selForm.CntyCode.options[49].selected = true;
				document.selForm.CntyCode.options[50].selected = true;
				document.selForm.CntyCode.options[51].selected = true;
				document.selForm.CntyCode.options[54].selected = true;
				document.selForm.CntyCode.options[67].selected = true;
				document.selForm.CntyCode.options[107].selected = true;
		}
		
		//Southern Seven HD
		if (Region == 'SouthernSevenHD'){
				document.selForm.CntyCode.options[1].selected = true;
				document.selForm.CntyCode.options[39].selected = true;
				document.selForm.CntyCode.options[48].selected = true;
				document.selForm.CntyCode.options[65].selected = true;
				document.selForm.CntyCode.options[81].selected = true;
				document.selForm.CntyCode.options[82].selected = true;
				document.selForm.CntyCode.options[99].selected = true;
		}
		
		//Egyptian HD
		if (Region == 'EgyptianHD'){
				document.selForm.CntyCode.options[34].selected = true;
				document.selForm.CntyCode.options[87].selected = true;
				document.selForm.CntyCode.options[105].selected = true;
		}
		
		//Champaign Urbana HD
		if (Region == 'ChampaignUrbanaHD'){
				document.selForm.CntyCode.options[9].selected = true;
		}
		
		//
		if (Region == 'EastsideHD'){
				document.selForm.CntyCode.options[25].selected = true;
		}
		
		//evanston
		if (Region == 'EvanstonHD'){
				document.selForm.CntyCode.options[29].selected = true;
		}
		
		//oak park
		if (Region == 'OakParkHD'){
				document.selForm.CntyCode.options[75].selected = true;
		}
		
		//skokie
		if (Region == 'SkokieHD'){
				document.selForm.CntyCode.options[92].selected = true;
		}
		
		//springfield
		if (Region == 'SpringfieldHD'){
				document.selForm.CntyCode.options[93].selected = true;
		}
		
		//STICKNEY
		if (Region == 'StickneyHD'){
				document.selForm.CntyCode.options[97].selected = true;
		}
		
		//All counties
		if (Region == 'AllCounties'){
				document.selForm.CntyCode.options[111].selected = true;
		}
		
		//all counties + 9 LHDs
		if (Region == 'AllCounties_9LHDs'){
				document.selForm.CntyCode.options[112].selected = true;
		}

		//collar counties
		if (Region == 'CollarCounties'){
				document.selForm.CntyCode.options[24].selected = true;	//DUPAGE
				document.selForm.CntyCode.options[49].selected = true;	//KANE
				document.selForm.CntyCode.options[54].selected = true;	//LAKE
				document.selForm.CntyCode.options[67].selected = true;	//MCHENRY
				document.selForm.CntyCode.options[107].selected = true;	//WILL	
		}

		//urban counties
		if (Region == 'UrbanCounties'){
				document.selForm.CntyCode.options[10].selected = true;	//CHAMPAIGN
				document.selForm.CntyCode.options[21].selected = true;	//DEKALB
				document.selForm.CntyCode.options[51].selected = true;	//KENDALL
				document.selForm.CntyCode.options[59].selected = true;	//MACON
				document.selForm.CntyCode.options[61].selected = true;	//MADISON
				document.selForm.CntyCode.options[86].selected = true;	//ROCK ISLAND
				document.selForm.CntyCode.options[68].selected = true;	//MCLEAN
				document.selForm.CntyCode.options[77].selected = true;	//PEORIA
				document.selForm.CntyCode.options[88].selected = true;	//SANGAMON
				document.selForm.CntyCode.options[94].selected = true;	//ST. CLAIR
				document.selForm.CntyCode.options[98].selected = true;	//TAZEWELL		
				document.selForm.CntyCode.options[109].selected = true;	//WINNEBAGO
		}

		//rural counties
		if (Region == 'RuralCounties'){
				document.selForm.CntyCode.options[113].selected = true;	//all 84 rural counties
/*
				document.selForm.CntyCode.options[0].selected = true;	//ADAMS
				document.selForm.CntyCode.options[1].selected = true;	//ALEXANDER
				document.selForm.CntyCode.options[2].selected = true;	//BOND
				document.selForm.CntyCode.options[3].selected = true;	//BOONE
				document.selForm.CntyCode.options[4].selected = true;	//BROWN
				document.selForm.CntyCode.options[5].selected = true;	//BUREAU
				document.selForm.CntyCode.options[6].selected = true;	//CALHOUN
				document.selForm.CntyCode.options[7].selected = true;	//CARROLL
				document.selForm.CntyCode.options[8].selected = true;	//CASS
//				document.selForm.CntyCode.options[9].selected = true;	//CHAMPAIGN-URBANA HD

				document.selForm.CntyCode.options[11].selected = true;	//CHRISTIAN
				document.selForm.CntyCode.options[12].selected = true;	//CLARK
				document.selForm.CntyCode.options[13].selected = true;	//CLAY
				document.selForm.CntyCode.options[14].selected = true;	//CLINTON
				document.selForm.CntyCode.options[15].selected = true;	//COLES
//				document.selForm.CntyCode.options[16].selected = true;	//COOK SUBURB
//				document.selForm.CntyCode.options[17].selected = true;	//COOK
//				document.selForm.CntyCode.options[18].selected = true;	//CHICAGO
				document.selForm.CntyCode.options[19].selected = true;	//CRAWFORD
				document.selForm.CntyCode.options[20].selected = true;	//CUMBERLAND

				document.selForm.CntyCode.options[22].selected = true;	//DEWITT
				document.selForm.CntyCode.options[23].selected = true;	//DOUGLAS

//				document.selForm.CntyCode.options[25].selected = true;	//EASTSIDE HD
				document.selForm.CntyCode.options[26].selected = true;	//EDGAR
				document.selForm.CntyCode.options[27].selected = true;	//EDWARDS
				document.selForm.CntyCode.options[28].selected = true;	//EFFINGHAM
//				document.selForm.CntyCode.options[29].selected = true;	//EVANSTON HD
				document.selForm.CntyCode.options[30].selected = true;	//FAYETTE
				document.selForm.CntyCode.options[31].selected = true;	//FORD
				document.selForm.CntyCode.options[32].selected = true;	//FRANKLIN
				document.selForm.CntyCode.options[33].selected = true;	//FULTON
				document.selForm.CntyCode.options[34].selected = true;	//GALLATIN
				document.selForm.CntyCode.options[35].selected = true;	//GREENE
				document.selForm.CntyCode.options[36].selected = true;	//GRUNDY
				document.selForm.CntyCode.options[37].selected = true;	//HAMILTON
				document.selForm.CntyCode.options[38].selected = true;	//HANCOCK
				document.selForm.CntyCode.options[39].selected = true;	//HARDIN
				document.selForm.CntyCode.options[40].selected = true;	//HENDERSON
				document.selForm.CntyCode.options[41].selected = true;	//HENRY
				document.selForm.CntyCode.options[42].selected = true;	//IROQUOIS
				document.selForm.CntyCode.options[43].selected = true;	//JACKSON
				document.selForm.CntyCode.options[44].selected = true;	//JASPER
				document.selForm.CntyCode.options[45].selected = true;	//JEFFERSON
				document.selForm.CntyCode.options[46].selected = true;	//JERSEY
				document.selForm.CntyCode.options[47].selected = true;	//JO DAVIESS
				document.selForm.CntyCode.options[48].selected = true;	//JOHNSON

				document.selForm.CntyCode.options[50].selected = true;	//KANKAKEE

				document.selForm.CntyCode.options[52].selected = true;	//KNOX
				document.selForm.CntyCode.options[53].selected = true;	//LASALLE

				document.selForm.CntyCode.options[55].selected = true;	//LAWRENCE
				document.selForm.CntyCode.options[56].selected = true;	//LEE
				document.selForm.CntyCode.options[57].selected = true;	//LIVINGSTON
				document.selForm.CntyCode.options[58].selected = true;	//LOGAN

				document.selForm.CntyCode.options[60].selected = true;	//MACOUPIN

				document.selForm.CntyCode.options[62].selected = true;	//MARION
				document.selForm.CntyCode.options[63].selected = true;	//MARSHALL
				document.selForm.CntyCode.options[64].selected = true;	//MASON
				document.selForm.CntyCode.options[65].selected = true;	//MASSAC
				document.selForm.CntyCode.options[66].selected = true;	//MCDONOUGH


				document.selForm.CntyCode.options[69].selected = true;	//MENARD
				document.selForm.CntyCode.options[70].selected = true;	//MERCER
				document.selForm.CntyCode.options[71].selected = true;	//MONROE
				document.selForm.CntyCode.options[72].selected = true;	//MONTGOMERY
				document.selForm.CntyCode.options[73].selected = true;	//MORGAN
				document.selForm.CntyCode.options[74].selected = true;	//MOULTRIE
//				document.selForm.CntyCode.options[75].selected = true;	//OAK PARK HD
				document.selForm.CntyCode.options[76].selected = true;	//OGLE

				document.selForm.CntyCode.options[78].selected = true;	//PERRY
				document.selForm.CntyCode.options[79].selected = true;	//PIATT
				document.selForm.CntyCode.options[80].selected = true;	//PIKE
				document.selForm.CntyCode.options[81].selected = true;	//POPE
				document.selForm.CntyCode.options[82].selected = true;	//PULASKI
				document.selForm.CntyCode.options[83].selected = true;	//PUTNAM
				document.selForm.CntyCode.options[84].selected = true;	//RANDOLPH
				document.selForm.CntyCode.options[85].selected = true;	//RICHLAND

				document.selForm.CntyCode.options[87].selected = true;	//SALINE

				document.selForm.CntyCode.options[89].selected = true;	//SCHUYLER
				document.selForm.CntyCode.options[90].selected = true;	//SCOTT
				document.selForm.CntyCode.options[91].selected = true;	//SHELBY
//				document.selForm.CntyCode.options[92].selected = true;	//SKOKIE HD
//				document.selForm.CntyCode.options[93].selected = true;	//SPRINGFIELD HD

				document.selForm.CntyCode.options[95].selected = true;	//STARK
				document.selForm.CntyCode.options[96].selected = true;	//STEPHENSON
//				document.selForm.CntyCode.options[97].selected = true;	//STICKNEY HD

				document.selForm.CntyCode.options[99].selected = true;	//UNION
				document.selForm.CntyCode.options[100].selected = true;	//VERMILION
				document.selForm.CntyCode.options[101].selected = true;	//WABASH
				document.selForm.CntyCode.options[102].selected = true;	//WARREN
				document.selForm.CntyCode.options[103].selected = true;	//WASHINGTON
				document.selForm.CntyCode.options[104].selected = true;	//WAYNE
				document.selForm.CntyCode.options[105].selected = true;	//WHITE
				document.selForm.CntyCode.options[106].selected = true;	//WHITESIDE

				document.selForm.CntyCode.options[108].selected = true;	//WILLIAMSON

				document.selForm.CntyCode.options[110].selected = true;	//WOODFORD
*/
		}
		
}


function checkVars(dataType) {

 var doSubmit=1;
 var msg="";
 var nSelLength = 0;
 if (dataType==1) {
 // called by iplanrpt.htm or cmtylist.htx
  var noYears=0;
  var noCnties=0;
  var noIndNo=0;
  var selected800=0;
  var nMaxNoOfCountiesAndYears=28;	//Marion has 27 counties.  the browser will timeout on more counties & years
  var nMaxNoOfYears=10;	//max number of years can be selected
  // count number of selected counties
//  for (i=0; i<document.selForm.CntyCode.options.length; i++) {
  nSelLength = document.selForm.CntyCode.length;
  for (i=0; i<nSelLength; i++) {
    if (document.selForm.CntyCode.options[i].selected == true) {
      noCnties++;
      // check if 800 or 810 or 700 is selected
//      if ((document.selForm.CntyCode.options[i].value == '800,') || (document.selForm.CntyCode.options[i].value == '810,')) {
      if ((document.selForm.CntyCode.options[i].value == '800,') || (document.selForm.CntyCode.options[i].value == '810,') || (document.selForm.CntyCode.options[i].value == '700,')) {
        selected800=1;
      }
    }
  }
  // count number of selected years
//  for (i=0; i<document.selForm.YEAR.options.length; i++) {
  nSelLength = document.selForm.YEAR.length;
  for (i=0; i<nSelLength; i++) {
    if (document.selForm.YEAR.options[i].selected == true) {
      noYears++;
    }
  }
  // count number of selected indicators
//  for (i=0; i<document.selForm.IndNo.options.length; i++) {
  if (document.selForm.IndNo.value == "8.99,") { //called by cmtysum.htm
	noIndNo = 1;
  }
  else {
    nSelLength = document.selForm.IndNo.length;
    for (i=0; i<nSelLength; i++) {
      if (document.selForm.IndNo.options[i].selected == true) {
        noIndNo++;
      }
    }
  }
  if (noYears==0) {
    msg="Please select a data year.";
    doSubmit=0;
  }
  if (noIndNo==0) {
    msg="Please select an indicator.";
    doSubmit=0;
  }
  if (noCnties==0) {
    msg="Please select a county/community.";
    doSubmit=0;
  }

  /* 
  	 an error occurs when more than 12 years are selected.
  	 display a message when more than 12 years are selected.
	 [ Nolan added February 2004] 
  */ 

  if (noYears > nMaxNoOfYears) {
    msg="You have selected "+noYears+" years.\nNo more than "+nMaxNoOfYears+" years can be selected.";
    doSubmit=0;
  }
/*
  if (noCnties>20) {
    msg="You have selected "+noCnties+" counties/communities.\nNo more than 20 counties/communities can be selected.";
    doSubmit=0;
  } else {
*/
  if ((noCnties + noYears)>nMaxNoOfCountiesAndYears) {
    msg="You have selected "+noCnties+" counties/communities and "+noYears+" years.\nNo more than a total of "+nMaxNoOfCountiesAndYears+" can be selected.";
    doSubmit=0;
  } else {
    if ((selected800==1) && (noYears>1)) {
      msg="You have selected "+noYears+" data years.\nWhen 700, 800, or 810 is selected in Step 1,\nonly one data year can be selected.";
      doSubmit=0;
    } else {
      if ((selected800==1) && (noCnties>1)) {
        msg="When 700, 800, or 810 is selected in Step 1,\nno other counties can be selected.";
        doSubmit=0;
      }
    }
  }        
  if (doSubmit==1) {
    document.selForm.submit();
    return true;
  } else {
    alert(msg);
    return false;

  }
 }

  if (dataType==2) {
    // called by rptdata.htx: - sort
    var noSortCategories=0;
    document.dataSort.rptType.value='rptdata';  //used by rptsort.idc
    // count number of selected data categories
//    for (i=0; i<document.dataSort.ExcCat.options.length; i++) {
    nSelLength = document.dataSort.ExcCat.length; 
    for (i=0; i<nSelLength; i++) {
      if (document.dataSort.ExcCat.options[i].selected == true) {
        noSortCategories++;
      }
    }

    if (document.dataSort.IndNo.value=='1.01') {
      document.dataSort.tempType.value='1';
    }
    if ((document.dataSort.IndNo.value=='2.02') ||
        (document.dataSort.IndNo.value=='2.06') ||
        (document.dataSort.IndNo.value=='3.09')) {
      document.dataSort.tempType.value='2';
    }

    if (noSortCategories==0) {
      msg="Please select a data category.";
      doSubmit=0;
    }
    if (doSubmit==1) {
	   document.dataSort.action="/data/rptsort.idc";
      document.dataSort.submit();
      return true;
    } else {
      alert(msg);
      return false;
    }
  } //sort

  if (dataType==3) {
    // called by rptdata.htx: - chart
    var noSortCategories=0;
    document.dataSort.rptType.value='rptchart';  //used by rptsort.idc

    // count number of selected chart categories
    var chartField1="Indno, indname, noyears, rptyear, nocnties, ctcode, county, category, ";
    var chartField="";
//    for (i=0; i<document.dataSort.ChartBy1.options.length; i++) {
    nSelLength = document.dataSort.ChartBy1.length;
    for (i=0; i<nSelLength; i++) {
      if (document.dataSort.ChartBy1.options[i].selected == true) {
        chartField=document.dataSort.ChartBy1.options[i].value;
      }
    }
    document.dataSort.selFields.value=chartField1 + chartField+" as chartField, "+chartField+" as barWidth";
//    alert(document.dataSort.selFields.value);

    if (document.dataSort.IndNo.value=='1.01') {
      document.dataSort.tempType.value='1';
    }
    if ((document.dataSort.IndNo.value=='2.02') ||
        (document.dataSort.IndNo.value=='2.06') ||
        (document.dataSort.IndNo.value=='3.09')) {
      document.dataSort.tempType.value='2';
    }

    // count number of selected data categories
//    for (i=0; i<document.dataSort.ExcCat.options.length; i++) {
	nSelLength = document.dataSort.ExcCat.options.length; 
	for (i=0; i<nSelLength; i++) {
      if (document.dataSort.ExcCat.options[i].selected == true) {
        noSortCategories++;
      }
    }
    if (noSortCategories==0) {
      msg="Please select a data category.";
      doSubmit=0;
    }
    if (doSubmit==1) {
 	   document.dataSort.action="/data/rptsort.idc";	 
      document.dataSort.submit();
      return true;
    } else {
      alert(msg);
      return false;
    }
  } //chart

  if (dataType==4) {
    // called by iplanrpt.htx: - data manipulation
    if (document.tableView.IndNo.value=='1.01') {
      document.tableView.tempType.value='1';
    }
    if ((document.tableView.IndNo.value=='2.02') ||
        (document.tableView.IndNo.value=='2.06') ||
        (document.tableView.IndNo.value=='3.09')) {
      document.tableView.tempType.value='2';
    }
    if (doSubmit==1) {
      document.tableView.submit();
      return true;
    } else {
      alert(msg);
      return false;
    }
  } //data manipulation

  if (dataType==5) {
    // called by rptsort.htx: - map
    // count number of selected data categories
//    for (i=0; i<document.dataSort.ExcCat.options.length; i++) {
	nSelLength = document.dataSort.ExcCat.options.length; 
	noSortCategories = 0;
	for (i=0; i<nSelLength; i++) {
      if (document.dataSort.ExcCat.options[i].selected == true) {
        noSortCategories++;
      }
    }
//	alert("Category length: " + nSelLength);
//	alert("Select category: " + noSortCategories);
//	alert("county code: " + getCntyCode());
    if (noSortCategories==0) {
      msg="Please select a data category.";
      doSubmit=0;
    }
	if (getCntyCode().length>3) {
//		alert("not county report");
      msg="Due to the lack of cartographic boundary files, the map \nfunction is not available for community-level reports.";
      doSubmit=0;
	}
    if (doSubmit==1) {
		if (noSortCategories==1) {
			document.dataSort.action="/cgi-bin/vfpcgi.exe?IDCFile=/data/rptmap.idc";
		}
		else {
			//multiple categories selected
			document.dataSort.action="/cgi-bin/vfpcgi.exe?IDCFile=/data/rptmap2.idc";	
		}
	    document.dataSort.submit();
		return true;
    } else {
		alert(msg);
		return false;
    }
  } //map

}

var nSelNoOfYears=0;
var nSelNoOfCnties=0;
function saveIndInfo(nNoYears,nNoCnties) {
  nSelNoOfYears=nNoYears;
  nSelNoOfCnties=nNoCnties;
}

function getIndInfo(nVar) {
  if (nVar==1) {  //return number of selected years
    return nSelNoOfYears;
  }
  if (nVar==2) {  //return number of selected counties
    return nSelNoOfCnties;
  }
}

var nCntyCode="";
function saveCntyCode(cntycode) {
	nCntyCode = cntycode;
}
function getCntyCode() {
	return nCntyCode;
}

var nMaxbarWidth = 0;
function saveBarWidth(nNum) {
    nMaxbarWidth = nNum;
}

var nCurrBarWidth=0;
function getBarWidth(nNum) {
  nCurrBarWidth=nNum;  //save current bar width
  var writeText="";
  var nPercent=0;
  var nFactor=2;  //magnifying factor for displaying the bar
  if (nMaxbarWidth > 0) {
    nPercent=Math.round((nNum/nMaxbarWidth)*1000)/10; //save one decimal point
  }
  writeText='<IMG SRC="c.gif" WIDTH='+nFactor+' HEIGHT=8>'
  for (i=0; i<nPercent-1; i++) {
    writeText=writeText+'<IMG SRC="c.gif" WIDTH='+nFactor+' HEIGHT=8>';
  }
  writeText=writeText+'&nbsp;<FONT SIZE=-3>'+nPercent+'%</FONT>';
  return writeText;
}


function getPctChange(nNum) {
  var nPctChange='n/a';
  if (nCurrBarWidth > 0) {
    nPctChange=Math.round(((nNum-nCurrBarWidth)/nCurrBarWidth)*1000)/10+'%';
  }
  return nPctChange;
}

//for map
var colorcode = new Array(6);
 colorcode[0] = "#ff0000";
 colorcode[1] = "#00ff00";
 colorcode[2] = "#0000ff";
 colorcode[3] = "#ffff00";
 colorcode[4] = "#ff00ff";
 colorcode[5] = "#00ffff";
//function to return a sequential number for Map group#
var nMapCounter1=0;
var nMapCounter2=0;
var nMapCounter3=0;
function getMapGroupID(MapCount) {
  if (MapCount == 1) {
    nMapCounter1++;
	return nMapCounter1;
  }
  if (MapCount == 2) {
    nMapCounter2++;
	return nMapCounter2;
  }
  if (MapCount == 3) {
    nMapCounter3++;
	return nMapCounter3;
  }
}
// function to return colorcode for map a group
function getColorCode(code) {
  return colorcode[code];
}

// function to save map groups
var mapGroupName = new Array();
function saveMapGroup(mapGroup) {
  mapGroupName[getNextID()] = mapGroup;
}

//print button
function displayPrintButton() {
  if ((navigator.appName.indexOf("Netscape") > -1 &&
    parseInt(navigator.appVersion) >= 4) ||
    (navigator.appName.indexOf("Microsoft") > -1 &&
    parseInt(navigator.appVersion) >= 4) ) {
    document.write
    ("<FORM><INPUT TYPE=button VALUE=' Print ' onClick='printCurrentPage();'></FORM>");
  }
}

function displayCloseButton() {
  if ((navigator.appName.indexOf("Netscape") > -1 &&
    parseInt(navigator.appVersion) >= 4) ||
    (navigator.appName.indexOf("Microsoft") > -1 &&
    parseInt(navigator.appVersion) >= 4) ) {
    document.write
    ("<FORM><INPUT TYPE=button VALUE='Close' onClick='window.close();'></FORM>");
  }
}

function printCurrentPage() {
  if (navigator.appName.indexOf("Microsoft") > -1 &&
   navigator.appVersion.indexOf("5.") == -1) {
   // IE4
   OLECMDID_PRINT = 6;
   OLECMDEXECOPT_DONTPROMPTUSER = 2;
   OLECMDEXECOPT_PROMPTUSER = 1;
   WebBrowser =
   '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
   document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
   WebBrowser1.ExecWB(OLECMDID_PRINT,   OLECMDEXECOPT_PROMPTUSER);
   WebBrowser1.outerHTML = "";
   }
   else {
   // N4 IE5
   window.print();
 }
}

//function to return a sequential number for Rec#
var nCounter=0;
function getNextID() {
  nCounter++;
  return nCounter;
}

//dynamic communities
function getCommunities(){
  var nSelLength;
//  for (i=0; i<document.selForm.CtyCode.options.length; i++) {
  nSelLength = document.selForm.CtyCode.length;
  for (i=0; i<nSelLength; i++) {
    if (document.selForm.CtyCode.options[i].selected == true) {
      var sSelected=document.selForm.CtyCode.options[i].value;
      var sIndSelected=sSelected.substring(0, sSelected.indexOf(","));
      break;
    }
  }
getCmtyList(sIndSelected);
}

function getCmtyList(sIndCode){
  clearcombo(document.selForm.CntyCode);
  if (sIndCode == 'NONE' || sIndCode == ''){
  // if they click on an empty area in the imagemap
       addopt(0, '&nbsp;[please select a county]');
     } else {
       // a non-empty area
       window.open("/data/popfetcmty.asp?sIndcode=" + sIndCode, "gofetch", 
       "toolbar=no,menubar=no,location=no,directories=no," +
        "resizeable=yes,width=100,height=100,left=0,top=0");
     }
}

function addcmty(nValue, sText){
  // this routine adds a new item to our listbox
  var nSelLength;
//  document.selForm.CntyCode.options[document.selForm.CntyCode.options.length] =
  nSelLength = document.selForm.CntyCode.length;
  document.selForm.CntyCode.options[nSelLength] =
    new Option(sText, nValue);
}

//dynamic years
function getIndYears(){

  var nSelLength;
//  for (i=0; i<document.selForm.IndNo.options.length; i++) {
  nSelLength = document.selForm.IndNo.length; 
  for (i=0; i<nSelLength; i++) {
    if (document.selForm.IndNo.options[i].selected == true) {
      var sSelected=document.selForm.IndNo.options[i].value;
      var sIndSelected=sSelected.substring(0, sSelected.indexOf(","));
      break;
    }
  }
	getYears(sIndSelected);
}

function getYears(sIndCode){
  clearcombo(document.selForm.YEAR);
  if (sIndCode == 'NONE' || sIndCode == ''){
  // if they click on an empty area in the imagemap
       addopt(0, 'Click on an indicator in Step 3 to get years');
     } else {
       // a non-empty area
       window.open("/data/popfetyears.asp?sIndcode=" + sIndCode, "gofetch", 
       "toolbar=no,menubar=no,location=no,directories=no," +
        "resizeable=yes,width=100,height=100,left=0,top=0");
     }
}



//function addopt(nValue, sText, grpcty, grpyear, ethnicity){
function addopt(nValue, sText){
  // this routine adds a new item to our listbox
  var nSelLength;
//  document.selForm.YEAR.options[document.selForm.YEAR.options.length] =
  nSelLength = document.selForm.YEAR.length;
  document.selForm.YEAR.options[nSelLength] =
    new Option(sText, nValue);
	 
}

// NN added April 2002 for having first item selected
function addopt_GetSelected(nValue, sText, grpcty, grpyear, ethnicity){
  var nSelLength;
  nSelLength = document.selForm.YEAR.length;
  document.selForm.YEAR.options[nSelLength] =
    new Option(sText, nValue, true, true);
	
	// set agg year, agg county, ethnicity to enabled first (disable in the IF statement)
 	 document.selForm.AgCnty[1].disabled = false;	//enable radio button Aggregate Counties YES 
	 document.selForm.AgYear[1].disabled = false;	//enable radio button Aggregate Years YES 
	 document.selForm.RACE[1].disabled = false;		//enable radio button ETHNICITY
	 
	 if (grpcty == 'N')
	 {
	 	document.selForm.AgCnty[0].checked = true;		// select NO for county aggregation
		document.selForm.AgCnty[1].disabled = true;		// disable YES radio on agg county
	 }
	 
	 if (grpyear == 'N')
	 {
		document.selForm.AgYear[0].checked = true;		// select NO on agg Years
		document.selForm.AgYear[1].disabled = true;		// disable YES radio on agg year
	 }
	 
	 if (ethnicity == 'N')
	 {
		document.selForm.RACE[0].checked = true;			// select RACE radio
		document.selForm.RACE[1].disabled = true;			// disable ETHNICITY radio
	 }
	 
}

function clearcombo(el){
  // this routine clears out a listbox or combo box
  var nSelLength;
//  for (var i = el.options.length; i >= 0; i--){
  nSelLength = el.length;
  for (var i = nSelLength; i >= 0; i--){
    el.options[i] = null;
  }
  el.selectedIndex = -1;
}

function displayBackButton(nNoPages) {
  var nBacktoPage;
  if (nNoPages==null) {
	nBacktoPage = -1;
  } else {
  	nBacktoPage = nNoPages;
  }
  document.write
    ("<FORM><INPUT TYPE=button VALUE='Back' onClick='parent.history.go(" + nBacktoPage + "); return false;'></FORM>");
}

function SelectAllOptions(pSelectionBox){
	// this will select all options in the combo/list box
		var nOptions;
		nOptions = pSelectionBox.options.length
		for (var i=0; i <= nOptions - 1; i++) 
		{
			pSelectionBox[i].selected=true;
		}
}

