
function submitSearch()
{
	if (preSubmissionCheck()){
	  document.forms[1].submit();
	  }
} // end submitSearch

function  preSubmissionCheck(){

	var facilityValue = document.forms[1].facilityName.value;
	var cityValue = document.forms[1].city.value;
	var stateSelectionIndex = document.forms[1].stateCode.selectedIndex;
	var regionSelectionIndex = document.forms[1].region.selectedIndex;
	var sectorSelectionIndex = document.forms[1].sector.selectedIndex;
	var allSectorsSelected = document.forms[1].allSectorsCheckbox.checked;
 var sectorsSelected = 0;


	// REMOVED BY RC 12/18/01 now that sfiparse.cgi queries the flat file data instead of IDEA
	//if (stateSelectionIndex == 0 && cityValue != "")  
	//	{
	//  alert('Please select a state in addition to a city.');
	//  document.forms[1].stateCode.focus();
	//  return false;
	//  }

	if (facilityValue == "" && cityValue == "" && stateSelectionIndex == 0 && regionSelectionIndex == 0 && allSectorsSelected == true){
	 alert('You have selected all sectors and have specified no search criteria. \nYour search may take a few minutes to peform.  \nPlease specify additional search criteria, if you \'d like to speed up your search.');
	 return true;
	}
	
  for (var i = 0; i < document.forms[1].sector.length; i++)
		{
    if (document.forms[1].sector.options[i].selected)
				  {
						  sectorsSelected = sectorsSelected + 1;
						}
  }

	if (facilityValue == "" && cityValue == "" && stateSelectionIndex == 0 && regionSelectionIndex == 0 && sectorsSelected == 0){
	 alert('You have selected no search criteria. \nPlease specify one or more search criteria before submitting your search.');
	 return false;
	}
	
 return true;
  
} //end preSubmissionCheck

function resetState()
{
  document.forms[1].stateCode.options[0].selected = true;
}

function resetEPARegion()
{
  document.forms[1].region.options[0].selected = true;
}

function toggleAllSectorsCheckBox()
{
document.forms[1].allSectorsCheckbox.checked = false;
if (document.forms[1].allSectorsCheckbox.checked)
{
  for (var i = 0; i < document.forms[1].sector.length; i++)
		{
    document.forms[1].sector.options[i].selected = false;
  }
}
} // end toggleAllSectorsCheckBox

function toggleSectorSelection()
{
if (document.forms[1].allSectorsCheckbox.checked)
{
  for (var i = 0; i < document.forms[1].sector.length; i++)
		{
    document.forms[1].sector.options[i].selected = true;
  }
}
} // end toggleSectorSelection

function getTRISpreadsheet1() {
  alert("hello");
}

function getTRISpreadsheet() {
  var triSectorSelected = 0;
		var triFileType = "";
		var triFileName = "";
		triSectorSelected = document.triSpreadsheetSelectionForm.triDownloadList.selectedIndex;
  //if (document.triSpreadsheetSelectionForm.triFileFormat[0].checked){
  //  triFileType = document.triSpreadsheetSelectionForm.triFileFormat[0].value;
  //		}
  //if (document.triSpreadsheetSelectionForm.triFileFormat[1].checked){
  //  triFileType = document.triSpreadsheetSelectionForm.triFileFormat[1].value;

  // RC:  as of Sept 2003, force to Excel only
  
  triFileType = "ex";

  //}
  if (triSectorSelected == 1) {
    triFileName = "aut";
  }
  if (triSectorSelected == 2) {
    triFileName = "fed";
  }
  if (triSectorSelected == 3) {
    triFileName = "int";
  }
  if (triSectorSelected == 4) {
    triFileName = "min";
  }
  if (triSectorSelected == 5) {
    triFileName = "al";
  }
  if (triSectorSelected == 6) {
    triFileName = "cu";
  }
  if (triSectorSelected == 7) {
    triFileName = "pb";
  }
  if (triSectorSelected == 8) {
    triFileName = "zn";
  }
  if (triSectorSelected == 9) {
    triFileName = "pet";
  }
  if (triSectorSelected == 10) {
    triFileName = "plp";
  }
  redirectedFileName =  "download/" + triFileName + "tab" + triFileType + ".zip";
  if (triSectorSelected == 0) {
    alert('Please select a sector.');
    document.triSpreadsheetSelectionForm.triDownloadList.focus();
				redirectedFileName = "access.htm#download_data";
  }
  window.location.href = redirectedFileName;
		return false;
}




