// This file is for Javascript functions relating to OTIS 5
// Created by Matt Malachowski on September 9, 2004

function Browsercheck() {
  //Verifies that user is NOT using Netscape Version 4.  Resets hidden values  on loading of form if
  //user is using Netcape 4 or below (as the form cannot retain hidden values on "back" in these browsers)
    var browserName=navigator.appName;
    var browserVer=parseInt(navigator.appVersion);

	if (browserName=="Netscape" && browserVer<5) {
	alert("We have detected that you are using " + "\n" +
		      navigator.appName +  " version " + browserVer + " as your current browser." + "\n" +
		      " EPA strongly recommends using Mozilla Firefox, Microsoft Internet Explorer, or" + "\n" + 
		      "Netscape Version 5 or higher to run a query in OTIS.  If you choose to continue" + "\n" +
		      "using your current browser, please reset your form before running every query.");
	}
}

function BrowsercheckMM() {
  //resets value and hidden field used for SFIP search
	document.forms[0].otis_otm_sfi_universe.selectedIndex="0";
	document.forms[0].idea_linkage.value="LINKED NONLINKED";
	document.forms[0].idea_db_filter.value="INC FRS AFS DEM ICI NCD PCS RCR TRI";
}
  
function submitSearch(media) {
  //Submits the contents of the CAA, RCRA and CWA form
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }
}

function submitSearchmm() {
  //Submits the contents of the CAA, RCRA and CWA form
  if (preSubmissionCheck()){
    document.forms[0].submit();
  }
}

function  preSubmissionCheck() {
  //Verifies that a user also enters a State when a City is inputted
   var state = document.forms[0].idea_state.selectedIndex;
   var city = document.forms[0].idea_city_name_l.value;
 
    if ((state == 0) && (city != "")) {
       window.alert("Please select a state in addition to a city.");
       return false;
    }
    else {
  	return isValidFacLength(document.forms[0].idea_otis_name_l, 0);
      }
 }
  
function isValidFacLength(element, formIndex) {
  //verifying that facility name is no longer than 18 characters long
   var nameArray = element.value.split(" ");
   var nameCount = nameArray.length;  // checking to see how many words were entered
   for (var i = 0; i < nameCount; i++) {
     if (nameArray[i].length > 18) {
       alert('You may enter multiple words for a Facility Name, but each word must be at most 18 characters long. If you are manually inputting multiple facility names, please include a space after each comma.');
       eval("document.forms[" + formIndex + "]." + element.name + ".focus()");
       return false;
     }
   }
   return true;
} 

function remove_special_characters(field,position) {
  //Used to Remove Special Characters that users may input
  var documentName = field.value;
  var n = documentName.length;
  var j = position;
  for (var i = 1; i <= n; i++)
  {
    if ( documentName.charAt(i-1) == "~"
      ||   documentName.charAt(i-1) == "="
      ||   documentName.charAt(i-1) == "{"
      ||   documentName.charAt(i-1) == "}"
      ||   documentName.charAt(i-1) == "["
      ||   documentName.charAt(i-1) == "]"
      ||   documentName.charAt(i-1) == "@"
      ||   documentName.charAt(i-1) == "|"
      ||   documentName.charAt(i-1) == "\\")
    {
      alert ('You have entered one of the following special characters:\n\n ~ = {  } [ ] @ | \\ \n\n Please edit your entry before submitting the form.');
      document.forms[0].elements[j].focus();
      break;
    }
  }
return false;
}

function remove_apostophes(field) {
  //Used to Remove Special Characters that users may input
  var nameValue = field.value;
  nameValue = nameValue.replace(/'/g, "")  // getting rid of apostrophes
  field.value = nameValue;

}

function remove_fac_finder_fields(field) {
  //Used to Remove Special Characters that users may input
  var nameValue = field.value;
  nameValue = nameValue.replace(/'/g, "")  // getting rid of apostrophes
  nameValue = nameValue.replace(/echo/g, "ech")  // getting rid of the word "echo"
  nameValue = nameValue.replace(/Echo/g, "ech")  // getting rid of the word "echo"
  nameValue = nameValue.replace(/ECHO/g, "ech")  // getting rid of the word "echo"
  nameValue = nameValue.replace(/route/g, "rt")  // getting rid of the word "route"
  nameValue = nameValue.replace(/Route/g, "rt")  // getting rid of the word "route"
  nameValue = nameValue.replace(/ROUTE/g, "rt")  // getting rid of the word "route"
  nameValue = nameValue.replace(/services/g, "service")  // getting rid of the word "services"
  nameValue = nameValue.replace(/Services/g, "service")  // getting rid of the word "services"
  nameValue = nameValue.replace(/SERVICES/g, "service")  // getting rid of the word "services"
  nameValue = nameValue.replace(/control/g, "contro")  // getting rid of the word "control"
  nameValue = nameValue.replace(/Control/g, "contro")  // getting rid of the word "control"
  nameValue = nameValue.replace(/CONTROL/g, "contro")  // getting rid of the word "control"
  nameValue = nameValue.replace(/ cat/g, " ca")  // getting rid of the word "cat"
  nameValue = nameValue.replace(/ Cat/g, " ca")  // getting rid of the word "cat"
  nameValue = nameValue.replace(/ CAT/g, " ca")  // getting rid of the word "cat"  
  nameValue = nameValue.replace(/ sam/g, " sa")  // getting rid of the word "sam"
  nameValue = nameValue.replace(/ Sam/g, " sa")  // getting rid of the word "sam"
  nameValue = nameValue.replace(/ SAM/g, " sa")  // getting rid of the word "sam"  
  nameValue = nameValue.replace(/ rm/g, " r")  // getting rid of the word "rm"
  nameValue = nameValue.replace(/ Rm/g, " r")  // getting rid of the word "rm"
  nameValue = nameValue.replace(/ RM/g, " r")  // getting rid of the word "rm"   
  field.value = nameValue;

}




function check_for_numbers_and_length(field,position) {
  //Used to verify that only numbers are entered.
  var documentName = field.value;
  var n = documentName.length;  
  var j = position;

  for (var i = 1; i <= n; i++) {
    if ( documentName.charAt(i-1) != "0"
      &&   documentName.charAt(i-1) != "1"
      &&  documentName.charAt(i-1) != "2"
      &&   documentName.charAt(i-1) != "3"
      &&   documentName.charAt(i-1) != "4"
      &&   documentName.charAt(i-1) != "5"
      &&   documentName.charAt(i-1) != "6"
      &&   documentName.charAt(i-1) != "7"
      &&   documentName.charAt(i-1) != "8"
      &&   documentName.charAt(i-1) != "9"
      &&   documentName.charAt(i-1) != ",")
    {
      alert ('Please enter only numbers or numbers separated by commas.\n\nEdit your entry before submitting the form.');
      document.forms[0].elements[j].focus();
      break;
    }
  }
  return false;
}

function showCounties() {
  //Produces a list of Counties when State is selected on all OTIS query pages 

  var counter =0;
  var  varall_length= document.forms[0].idea_state.length;
    //alert('var_all length= ' +  varall_length);
    for (i = 0; i<varall_length;i++) {
    	if  (document.forms[0].idea_state[i].selected == true) {
		counter ++;
  	}
    }
    
  if (counter <2) { //run only if multiple states are not selected
  	var countyCodeIndex = document.forms[0].idea_state.selectedIndex; 
  }
  
  else { //run if multiple states are selected
    	var countyCodeIndex = 0;  
  }
  
  
  
  var countyCodeValue = "";
  var countyName = "";

  var countyIndexMin = 0;
  var countyIndexMax = 0;  
  document.forms[0].idea_county.options.length = 0;

	for (var j = 0; j <= countyCodeIndex; j++) {
  	  countyIndexMax = countyIndexMax + parseInt(countiesByStateArray[j].substring(3));
        }
		countyIndexMin = countyIndexMax - countiesByStateArray[countyCodeIndex].substring(3);

		numberOfCounties = countiesByStateArray[countyCodeIndex].substring(3);
		document.forms[0].idea_county.options.length = numberOfCounties;

        for (var i = countyIndexMin; i < countyIndexMax; i++) {
  	  countyCodeValue = countyCodesArray[i].substring(0,5);
  	  countyName = countyCodesArray[i].substring(8);
  	  document.forms[0].idea_county.options[i-countyIndexMin] = new Option(countyName, countyCodeValue);
  	}
}

function showLCON() {
  //Produces a list of LCON values when State is selected on CAA query page 
  var LCONCodeValue = "";
  var LCONName = "";
  var LCONCodeIndex = document.forms[0].idea_state.selectedIndex;
  var LCONIndexMin = 0;
  var LCONIndexMax = 0;

    document.forms[0].idea_afs_lcon.options.length = 0;

	for (var j = 0; j <= LCONCodeIndex; j++) {
  	  LCONIndexMax = LCONIndexMax + parseInt(countiesByLCONArray[j].substring(3));
        }
		LCONIndexMin = LCONIndexMax - countiesByLCONArray[LCONCodeIndex].substring(3);

		numberOfCounties = countiesByLCONArray[LCONCodeIndex].substring(3);
		document.forms[0].idea_afs_lcon.options.length = numberOfCounties;

        for (var i = LCONIndexMin; i < LCONIndexMax; i++) {
  	  LCONCodeValue = LCONCodesArray[i].substring(0,5);
  	  LCONName = LCONCodesArray[i].substring(8);
  	  document.forms[0].idea_afs_lcon.options[i-LCONIndexMin] = new Option(LCONName, LCONCodeValue);
  	}
}

function setRegion() {
  //Resets Region when State is selected on PCS, and MM pages
  document.forms[0].idea_region[0].selected = true;
  showCounties();
}

function setFederal() {
  //Fixes IDEA bug...when any Federal agency is selected, the "No Agency Selected" option must be deselected.  76 is the length of the field
  var fedi =1;
  var len = document.forms[0].otis_frsfed.length;
 // window.alert(len);
  for (fedi; fedi<len; fedi++) {
 // window.alert(fedi);
    if (document.forms[0].otis_frsfed[fedi].selected) {
      document.forms[0].otis_frsfed[0].selected = false; 
    }
  }
}

function setCAAtype() {
  //Fixes IDEA bug...when CAA type is selected, the "Any" option must be deselected.  11 is the length of the field
  var i =1;
  for (i; i<=10; i++) {
    if (document.forms[0].idea_afs_program[i].selected) {
      document.forms[0].idea_afs_program[0].selected = false; 
    }
  }
}


function setRegionAFS() {
  //Resets Region and calls the LCON function when State is selected on AFS page
  document.forms[0].idea_region[0].selected = true;
  showCounties();
  showLCON();
}

function setState() {
  //Resets State when Region is selected on PCS, and MM pages
  var n = document.forms[0].idea_state.options.length;
  var i =1;
  for (i; i<n; i++) {
      document.forms[0].idea_state[i].selected = false; 
  }  
  document.forms[0].idea_state[0].selected = true;
  showCounties();
}

function setStateAFS() {
  //Resets State and LCON when Region is selected on AFS page
  var n = document.forms[0].idea_state.options.length;
  var i =1;
  for (i; i<n; i++) {
      document.forms[0].idea_state[i].selected = false; 
  } 
  document.forms[0].idea_state[0].selected = true;
  showCounties();
  showLCON();
}

function setRegionRCR() {
  //Resets District and Region when State is selected on the RCRA page
  document.rcra_idea_query_form.idea_rcr_district[0].selected = true;
  document.rcra_idea_query_form.idea_region[0].selected = true;
  showCounties();
}

function setStateRCR() {
  //Resets District and State when Region is selected on the RCRA page
  var n = document.forms[0].idea_state.options.length;
  var i =1;
  for (i; i<n; i++) {
      document.forms[0].idea_state[i].selected = false; 
  } 
  document.rcra_idea_query_form.idea_rcr_district[0].selected = true;
  document.rcra_idea_query_form.idea_state[0].selected = true;
  showCounties();
}

function setDistrictRCR(){
  //Resets State, Region, City, and Zip when District is selected on the RCRA page
  document.forms[0].idea_region[0].selected = true;
  var n = document.forms[0].idea_state.options.length;
  var i =1;
  for (i; i<n; i++) {
      document.forms[0].idea_state[i].selected = false; 
  }
  document.forms[0].idea_state[0].selected = true;
  showCounties();
  document.forms[0].idea_city_name_l.value = "";
  document.forms[0].idea_zip_any.value = "";
}

function uncheckAll(field) {
  //unchecks individual designations on the RCRA page when "all" is checked
   for (i = 0; i < field.length; i++)
        field[i].checked = false;
}

function notAll() {
  //unchecks "All" on the RCRA page when Individual Designations are checked
    document.rcra_idea_query_form.idea_facility_designationAll.checked = false;
}



function uncheckAllCWA(field) {
  //checks individual designations on the ICIS/NPDES page when "all" is checked
  if (document.forms[0].idea_compliance_v3[0].checked == true) {
  	document.forms[0].idea_pcs_snc_dummy[1].checked = true;
  	document.forms[0].idea_pcs_snc_dummy[2].checked = true;
  	document.forms[0].idea_pcs_snc_dummy[3].checked = true;
  	document.forms[0].idea_pcs_snc_dummy[4].checked = true;
  	document.forms[0].idea_pcs_snc_dummy[0].checked = true;
  	document.forms[0].idea_pcs_snc.value = "";
 }
   else {
	document.forms[0].idea_pcs_snc_dummy[1].checked = false;
	document.forms[0].idea_pcs_snc_dummy[2].checked = false;
	document.forms[0].idea_pcs_snc_dummy[3].checked = false;
	document.forms[0].idea_pcs_snc_dummy[4].checked = false;
	document.forms[0].idea_pcs_snc_dummy[0].checked = false;
	document.forms[0].idea_pcs_snc.value = "";
   }
} 



function uncheckAllCWA2(field) {
  //unchecks individual designations on the ICIS/NPDES page when "all" is checked
   if (document.forms[0].idea_compliance_v3_dummy1.checked == true) {
     	document.forms[0].idea_pcs_snc1_dummy[1].checked = true;
     	document.forms[0].idea_pcs_snc1_dummy[2].checked = true;
     	document.forms[0].idea_pcs_snc1_dummy[3].checked = true;
     	document.forms[0].idea_pcs_snc1_dummy[0].checked = true;
     	document.forms[0].idea_pcs_snc1.value = "S,E,X,T";
    }
      else {
      document.forms[0].idea_pcs_snc1_dummy[1].checked = false;
      document.forms[0].idea_pcs_snc1_dummy[2].checked = false;
      document.forms[0].idea_pcs_snc1_dummy[3].checked = false;
      document.forms[0].idea_pcs_snc1_dummy[0].checked = false;
      document.forms[0].idea_pcs_snc1.value = "";
   }
}

function uncheckCWA() {
  //unchecks "SNC" on the ICIS-NPDES page when Individual Designations are checked
   if ((document.forms[0].idea_pcs_snc_dummy[0].checked == true) && (document.forms[0].idea_pcs_snc_dummy[1].checked == true) && (document.forms[0].idea_pcs_snc_dummy[2].checked == true) && (document.forms[0].idea_pcs_snc_dummy[3].checked == true) && (document.forms[0].idea_pcs_snc_dummy[4].checked == true)) {
  	document.forms[0].idea_pcs_snc.value = "";
  	document.forms[0].idea_compliance_v3[0].checked = true;
   
   }
   
   else {
   document.forms[0].idea_compliance_v3[0].checked = false;
   resethiddenSNC();
   }
   
   
    
}

function resethiddenSNC() {
var list = "";
var counter =0;
var  varall_length= document.forms[0].idea_pcs_snc_dummy.length;
  //alert('var_all length= ' +  varall_length);
  for (i = 0; i<varall_length;i++) {
  	if  (document.forms[0].idea_pcs_snc_dummy[i].checked == true) {
		if (counter == 0) {
			list = document.forms[0].idea_pcs_snc_dummy[i].value;
		}
		else {
			list = list + ',' + document.forms[0].idea_pcs_snc_dummy[i].value;
		}
		counter ++;
	}
   }
	//alert ('list = ' + list);
        document.forms[0].idea_pcs_snc.value=list;

}

function uncheckCWA2() {
  //unchecks "Minor SNC" on the ICIS-NPDES page when Individual Designations are checked
   if ((document.forms[0].idea_pcs_snc1_dummy[0].checked == true) && (document.forms[0].idea_pcs_snc1_dummy[1].checked == true) && (document.forms[0].idea_pcs_snc1_dummy[2].checked == true) && (document.forms[0].idea_pcs_snc1_dummy[3].checked == true)) {
       	document.forms[0].idea_compliance_v3_dummy1.checked = true;
       
       }
       
       else {
       document.forms[0].idea_compliance_v3_dummy1.checked = false;
   }
   
   resethiddenSNC2();
}

function resethiddenSNC2() {
var list = "";
var counter =0;
var  varall_length= document.forms[0].idea_pcs_snc1_dummy.length;
  //alert('var_all length= ' +  varall_length);
  for (i = 0; i<varall_length;i++) {
  	if  (document.forms[0].idea_pcs_snc1_dummy[i].checked == true) {
		if (counter == 0) {
			list = document.forms[0].idea_pcs_snc1_dummy[i].value;
		}
		else {
			list = list + ',' + document.forms[0].idea_pcs_snc1_dummy[i].value;
		}
		counter ++;
	}
   }
	//alert ('list = ' + list);
        document.forms[0].idea_pcs_snc1.value=list;

}


function ComplianceAFS() {
  //creates custom date range pop-up box when "Custom" is selected for AFS's Last Compliance Inspection 
  var dateRange = document.forms[0].idea_last_inspected.selectedIndex;

	if ( dateRange == 1) {
			window.open('/otis/caa_compliance.html','sub','height=270,width=475,left=120,top=200,resizable,scrollbars');
      }
   	else {
   	  document.forms[0].idea_last_inspected_custom.value = "";
   	  document.forms[0]._idea_insp_mm1.value="";
	  document.forms[0]._idea_insp_dd1.value="";
	  document.forms[0]._idea_insp_mm2.value="";
	  document.forms[0]._idea_insp_dd2.value="";
	  document.forms[0]._idea_insp_yyyy1.value="";
	  document.forms[0]._idea_insp_yyyy2.value="";
	  document.forms[0].idea_insp_detail.value="Any";
	  document.forms[0]._idea_insp_agency.value="Any";
  	  document.forms[0]._not_idea_insp_detail.value="";
      }
}

function CompliancePCS() {
  //creates custom date range pop-up box when "Custom" is selected for PCS's Last Compliance Inspection 
  var dateRange = document.forms[0].idea_last_inspected.selectedIndex;

	if ( dateRange == 1) {
	  window.open('/otis/cwa_compliance.html','sub','height=270,width=475,left=120,top=200,resizable,scrollbars');
      }
   	else {
   	  document.forms[0].idea_last_inspected_custom.value = "";
   	  document.forms[0]._idea_insp_mm1.value="";
	  document.forms[0]._idea_insp_dd1.value="";
	  document.forms[0]._idea_insp_mm2.value="";
	  document.forms[0]._idea_insp_dd2.value="";
	  document.forms[0]._idea_insp_yyyy1.value="";
	  document.forms[0]._idea_insp_yyyy2.value="";
	  document.forms[0].idea_insp_detail.value="Any";
	  document.forms[0]._idea_insp_agency.value="Any";
  	  document.forms[0]._not_idea_insp_detail.value="";
      }
}

function ComplianceICP() {
  //creates custom date range pop-up box when "Custom" is selected for PCS's Last Compliance Inspection 
  var dateRange = document.forms[0].idea_last_inspected.selectedIndex;

	if ( dateRange == 1) {
	  window.open('/otis/ici_compliance.html','sub','height=270,width=475,left=120,top=200,resizable,scrollbars');
      }
   	else {
   	  document.forms[0].idea_last_inspected_custom.value = "";
   	  document.forms[0]._idea_insp_mm1.value="";
	  document.forms[0]._idea_insp_dd1.value="";
	  document.forms[0]._idea_insp_mm2.value="";
	  document.forms[0]._idea_insp_dd2.value="";
	  document.forms[0]._idea_insp_yyyy1.value="";
	  document.forms[0]._idea_insp_yyyy2.value="";
	  document.forms[0].idea_insp_detail.value="Any";
	  document.forms[0]._idea_insp_agency.value="Any";
  	  document.forms[0]._not_idea_insp_detail.value="";
      }
}

function ComplianceRCR() {
  //creates custom date range pop-up box when "Custom" is selected for RCRA's Last Compliance Inspection 
  var dateRange = document.forms[0].idea_last_inspected.selectedIndex;

	if ( dateRange == 1) {
	  window.open('/otis/rcra_compliance.html','sub','height=270,width=475,left=120,top=200,resizable,scrollbars');
      }
   	else {
   	  document.forms[0].idea_last_inspected_custom.value = "";
   	  document.forms[0]._idea_insp_mm1.value="";
	  document.forms[0]._idea_insp_dd1.value="";
	  document.forms[0]._idea_insp_mm2.value="";
	  document.forms[0]._idea_insp_dd2.value="";
	  document.forms[0]._idea_insp_yyyy1.value="";
	  document.forms[0]._idea_insp_yyyy2.value="";
	  document.forms[0].idea_insp_detail.value="Any";
	  document.forms[0]._idea_insp_agency.value="Any";
  	  document.forms[0]._not_idea_insp_detail.value="";   	  
      }
}

function enforcementAFS() {
  //creates custom date range pop-up box when "Custom" is selected for AFS's Last Enforcement Action
  //otherwise, resets hidden values to default values
  var dateRange2 = document.forms[0].otis_formal_actions.selectedIndex;

	if ( dateRange2 == 1) {
	   window.open('/otis/caa_enforcement_actions.html','sub','height=250,width=475,left=120,top=200,resizable,scrollbars');
       }
        else {
           document.forms[0].otis_formal_actions_custom.value = "";
	   document.forms[0]._idea_act_mm1.value="";
	   document.forms[0]._idea_act_dd1.value="";
	   document.forms[0]._idea_act_mm2.value="";
	   document.forms[0]._idea_act_dd2.value="";
	   document.forms[0]._idea_act_yyyy1.value="";
	   document.forms[0]._idea_act_yyyy2.value="";
	   document.forms[0]._idea_act_agency.value="Any";
	   document.forms[0].idea_action_detail.value="Any";           
       }
}

function enforcementPCS() {
  //creates custom date range pop-up box when "Custom" is selected for PCS's Last Enforcement Action
  //otherwise, resets hidden values back to default.
  var dateRange2 = document.forms[0].otis_formal_actions.selectedIndex;

	if ( dateRange2 == 1) {
	   window.open('/otis/cwa_enforcement_actions.html','sub','height=250,width=475,left=120,top=200,resizable,scrollbars');
       }
        else {
           document.forms[0].otis_formal_actions_custom.value = "";
	   document.forms[0]._idea_act_mm1.value="";
	   document.forms[0]._idea_act_dd1.value="";
	   document.forms[0]._idea_act_mm2.value="";
	   document.forms[0]._idea_act_dd2.value="";
	   document.forms[0]._idea_act_yyyy1.value="";
	   document.forms[0]._idea_act_yyyy2.value="";
	   document.forms[0]._idea_act_agency.value="Any";
	   document.forms[0].idea_action_detail.value="Any";            
       }
}

function enforcementICP() {
  //creates custom date range pop-up box when "Custom" is selected for PCS's Last Enforcement Action
  //otherwise, resets hidden values back to default.
  var dateRange2 = document.forms[0].otis_formal_actions.selectedIndex;

	if ( dateRange2 == 1) {
	   window.open('/otis/ici_enforcement_actions.html','sub','height=250,width=475,left=120,top=200,resizable,scrollbars');
       }
        else {
           document.forms[0].otis_formal_actions_custom.value = "";
	   document.forms[0]._idea_act_mm1.value="";
	   document.forms[0]._idea_act_dd1.value="";
	   document.forms[0]._idea_act_mm2.value="";
	   document.forms[0]._idea_act_dd2.value="";
	   document.forms[0]._idea_act_yyyy1.value="";
	   document.forms[0]._idea_act_yyyy2.value="";
	   document.forms[0]._idea_act_agency.value="Any";
	   document.forms[0].idea_action_detail.value="Any";            
       }
}

function enforcementRCR() {
  //creates custom date range pop-up box when "Custom" is selected for RCR's Last Enforcement Action 
  //otherwise, resets hidden values back to default
  var dateRange2 = document.forms[0].otis_formal_actions.selectedIndex;

	if ( dateRange2 == 1) {
	   window.open('/otis/rcra_enforcement_actions.html','sub','height=250,width=475,left=120,top=200,resizable,scrollbars');
       }
        else {
           document.forms[0].otis_formal_actions_custom.value = "";
	   document.forms[0]._idea_act_mm1.value="";
	   document.forms[0]._idea_act_dd1.value="";
	   document.forms[0]._idea_act_mm2.value="";
	   document.forms[0]._idea_act_dd2.value="";
	   document.forms[0]._idea_act_yyyy1.value="";
	   document.forms[0]._idea_act_yyyy2.value="";
	   document.forms[0]._idea_act_agency.value="Any";
	   document.forms[0].idea_action_detail.value="Any"; 
       }
}

        

function HPVtypes() {
  //opens more AFS HPV types upon clicking the "more options" checkbox.  Resets other Compliance measures
        if (document.forms[0].idea_compliance_gray.checked == true) { 
	   	document.forms[0].idea_afs_hpv.value = "";
  		document.forms[0].idea_hpv.value = "";
  		document.forms[0].idea_compliance_v3[0].checked = false;
		window.open ('/otis/high_priority_violator2.html','sub','height=300,width=300,left=210,top=140,resizable,scrollbars');
	}
	else {
	 	document.forms[0].idea_afs_hpv.value = "";
 		document.forms[0].idea_hpv.value = "";
 	 	document.forms[0].idea_compliance_v3[0].checked = false;
 	 }
}

function SNCtypesPCS() {
  //opens more PCS SNC types upon clicking the "more options" checkbox.  Resets other Compliance measures
	if (document.forms[0].idea_compliance_gray.checked == true) { 
	  	document.forms[0].idea_compliance_v3[0].checked = false;
	  	document.forms[0].idea_pcs_snc.value = "";
 	  	document.forms[0].idea_pcs.value = "";
	  	window.open ('/otis/snc_types.html','sub','height=300,width=300,left=210,top=140,resizable,scrollbars');
	}
	else {
 		document.forms[0].idea_pcs_snc.value = "";
 		document.forms[0].idea_pcs.value = "";
 	 	document.forms[0].idea_compliance_v3[0].checked = false;
 	}
}

function SNCtypesRCR() {
  //opens more RCR SNC types upon clicking the "more options" checkbox.  Resets other Compliance measures
	if (document.forms[0].idea_compliance_gray.checked == true) { 
	  	document.forms[0].idea_compliance_v3[0].checked = false;
	  	document.forms[0].idea_pcs_snc.value = "";
 	  	document.forms[0].idea_pcs.value = "";
	  	window.open ('/otis/rcr_snc_types.html','sub','height=300,width=300,left=210,top=140,resizable,scrollbars');
	}
	else {
 		document.forms[0].idea_pcs_snc.value = "";
 		document.forms[0].idea_pcs.value = "";
 	 	document.forms[0].idea_compliance_v3[0].checked = false;
 	}
}

function resetHPV(value) {
  //adjusts AFS form settings to search for HPV depending on whether HPV is checked
 	if (document.forms[0].idea_compliance_v3[0].checked == false) {
 		document.forms[0].idea_afs_hpv.value = "";
  		document.forms[0].idea_hpv.value = "";
  		document.forms[0].idea_compliance_gray.checked = false;
 	   }
 	else {
 		document.forms[0].idea_afs_hpv.value = "";
 		document.forms[0].idea_hpv.value = "B, C, E, F, S, T, X";
 		document.forms[0].idea_compliance_gray.checked = false;

 	   }
}

function PCSresetSNC(value) {
  //adjusts PCS form settings to search for SNC depending on whether SNC is checked
 	if (document.forms[0].idea_compliance_v3[0].checked == false) {
 		document.forms[0].idea_pcs_snc.value = "";
  		document.forms[0].idea_pcs.value = "";
          }
 	else {
 		document.forms[0].idea_pcs_snc.value = "";
 		document.forms[0].idea_pcs.value = "D, E, S, T, X";
 	 	document.forms[0].idea_compliance_gray.checked = false;
	  }
}

function RCRresetSNC(value) {
  //adjusts RCR form settings to search for SNC depending on whether SNC is checked
 	if (document.forms[0].idea_compliance_v3[0].checked == false) {
 		document.forms[0].idea_pcs_snc.value = "";
  		document.forms[0].idea_pcs.value = "";
          }
 	else {
 		document.forms[0].idea_pcs_snc.value = "";
 		document.forms[0].idea_pcs.value = "1A, 1B, 2, 3, 4A, 4B, 5";
 	 	document.forms[0].idea_compliance_gray.checked = false;
	  }
}

function minorWarning() {
  //pops up a warning upon selection of "minor facility"
  if (document.forms[0].otis_facility_designation[3].checked)
  {
var win;
var features = "height=400,width=400,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
win = window.open("/otis/caa_minor_facilities_warning.html", "minor", features);
	   document.forms[0].otis_universe.value="";
  }
  else {
	   document.forms[0].otis_universe.value="Y";
  }
}

function Activate() {
  //In OTIS CAA, checks all of the "Active" types when the active checkbox is checked
    if (document.forms[0].idea_afs_opst1.checked) {
      	document.forms[0].idea_afs_opst[0].checked = true;
      	document.forms[0].idea_afs_opst[2].checked = true;
      	document.forms[0].idea_afs_opst[4].checked = true;
      }
    else {
      	document.forms[0].idea_afs_opst[0].checked = false;
      	document.forms[0].idea_afs_opst[2].checked = false;
      	document.forms[0].idea_afs_opst[4].checked = false;
      }
}

function ActivateAll() {
  //In OTIS CAA, checks the Active checkbox when all three active types are checked
    if ((document.forms[0].idea_afs_opst[0].checked) && (document.forms[0].idea_afs_opst[2].checked) && 
        (document.forms[0].idea_afs_opst[4].checked)) {
            document.forms[0].idea_afs_opst1.checked = true;
      }
    else {
            document.forms[0].idea_afs_opst1.checked = false;
      }
}
  
function Inactivate() {
  //In OTIS CAA, checks all of the "Inactive" types when the inactive checkbox is checked
    if (document.forms[0].idea_afs_opst2.checked) {
      document.forms[0].idea_afs_opst[1].checked = true;
      document.forms[0].idea_afs_opst[3].checked = true;
      document.forms[0].idea_afs_opst[5].checked = true;
    }
    else {
      document.forms[0].idea_afs_opst[1].checked = false;
      document.forms[0].idea_afs_opst[3].checked = false;
      document.forms[0].idea_afs_opst[5].checked = false;
      }
}

function InactivateAll() {
    //In OTIS CAA, checks the Inactive checkbox when all three inactive types are checked
    if ((document.forms[0].idea_afs_opst[1].checked) && (document.forms[0].idea_afs_opst[3].checked) && 
        (document.forms[0].idea_afs_opst[5].checked)) {
            document.forms[0].idea_afs_opst2.checked = true;
      }
    else {
            document.forms[0].idea_afs_opst2.checked = false;
      }
}

function adjustSFI() {
  //resets search parameters from LINKED NONLINKED to LINKED SFI when SFI is selected 
  var SFI = document.forms[0].otis_otm_sfi_universe.selectedIndex;
   if (SFI ==0) {
	document.forms[0].idea_linkage.value="LINKED NONLINKED";
	document.forms[0].idea_db_filter.value="INC FRS AFS DEM ICI NCD PCS RCR TRI";
	}
   else {
    window.open('/otis/sfi_explanation.html','','height=400,width=400,resizing=0,scrollbars=1,menubar=0');
    document.forms[0].idea_linkage.value="LINKED SFI";
    document.forms[0].idea_db_filter.value="INC SFI AFS DEM ICI NCD PCS RCR TRI";
 	 
    }
}

function resetDefaultValues(what) {
  //function for resetting the form
    for (var i=0, j=what.elements.length; i<j; i++) {
        myType = what.elements[i].type;
        if (myType == 'checkbox' || myType == 'radio')
            what.elements[i].checked = what.elements[i].defaultChecked;
        if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
            what.elements[i].value = what.elements[i].defaultValue;
        if (myType == 'select-one' || myType == 'select-multiple')
            for (var k=0, l=what.elements[i].options.length; k<l; k++)
                what.elements[i].options[k].selected = what.elements[i].options[k].defaultSelected;
        }
          
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  //used in MM query, search by permit ID
  window.open(theURL,winName,features);
}

function permitwarningAFS() {
  //used to give otis users a warning if they enter permit ids and do not have minor facilities checked
  //a hidden field of permit_warning determines whether it is the first time a pop-up is being displayed. 
  var warning = document.forms[0].permit_warning.value;
     if ((document.forms[0].otis_facility_designation[3].checked == false) && (warning == "0")) {
        window.open('/otis/permit_warning.html','','height=250,width=300,resizing=0,scrollbars=1,menubar=0');
       	document.forms[0].permit_warning.value="1";
   	
  }
  
}

function remove_carriage_returns(media) {
 //the value of media is equal to the number of characters that the permit id should be, AFS=10, PCS=9, RCRA=12
    var browserName=navigator.appName;
    var browserVer=parseInt(navigator.appVersion); 
if (browserName=="Microsoft Internet Explorer") {    
 
  var limit= media;
  nameValue = document.forms[0].otis_facility_id_l.value;
  nameValue = nameValue.replace(/\r\n/g, ",")  // getting rid of carriage returns
  nameValue = nameValue.replace(/\s/g, "")  // getting rid of spaces
  var length = nameValue.length;
  if ((length != "0") && (nameValue.charAt(length-1) != ",")) { //adding comma as last digit, of last permit
      nameValue = nameValue + ",";
    }
  document.forms[0].otis_facility_id_l.value = nameValue;
  var length2 = nameValue.length;
  var counter = 0; //setting up a counter value to determine the number of commas in the list

		 for (var i = 1; i <= length2; i++) { //for loop determines number of commas in list
			if ((nameValue.charAt(i-1) == ",")) {
				  counter = counter +1;
			}
			else {
				   counter = counter;
			}
		}
		a = nameValue.split(",");  //splitting the list at commas
		y = "";  //setting up an array for valid ids
		q = "";  //setting up an array for invalid ids
		var invalid = 0; //variable to denote whether the invalid array is ever accessed

		 for (var p = 0; p < counter; p++) {
			  var sublength = a[p].length;  //determining length of each id in array

			  if (sublength == limit) {  //if id is correct length, add to array of accepted ids
				if (y != "") {
					s = new Array (y, ",", a[p]);
					y = s.join("");
				}
				else {
					s = new Array (a[p]);
					y = s.join("");
				}
			 }
			  else if (sublength != limit) {  //if id is incorrect length, add to array of invalid ids
				if (q != "") {
					z = new Array (q, ",", a[p]);
					q = z.join("");
					invalid = 1;
				}
				else {
					z = new Array (a[p]);
					q = z.join("");
					invalid = 1;
				}
			 }
		  }

 if (invalid == 1) { //if there are ids in our invalid list

   if (confirm("The following invalid ids are not " + limit + " characters long:" + "\n" +  q + "\n" + "Would you like to remove these invalid ids, and proceeed with your search\?")){
	document.forms[0].otis_facility_id_l.value = y;
	return preSubmissionCheck();
   }
   else {  //user does not want to proceed, return false
			return false;
	}
}

 else {  //no ids we in our invalid list, allow user to proceed
     return preSubmissionCheck();
 }
}

 else {  //no ids we in our invalid list, allow user to proceed
     return preSubmissionCheck();
 }

}


function stackAFS() {
  //creates custom date range pop-up box when "Custom" is selected for AFS's Stack Test Results
  var dateRange = document.forms[0].idea_afs_stack_test.selectedIndex;

	if ( dateRange == 1) {
			window.open('/otis/caa_stack_test.html','sub','height=270,width=475,left=120,top=200,resizable,scrollbars');
      }
   	else {
   	  document.forms[0].otis_stack_custom.value = "";
   	  document.forms[0]._idea_stack_mm1.value="";
	  document.forms[0]._idea_stack_dd1.value="";
	  document.forms[0]._idea_stack_mm2.value="";
	  document.forms[0]._idea_stack_dd2.value="";
	  document.forms[0]._idea_stack_yyyy1.value="";
	  document.forms[0]._idea_stack_yyyy2.value="";
	  document.forms[0].idea_afs_stack_detail.value="Any";
	  document.forms[0]._idea_stack_type.value="Any";
	  document.forms[0]._idea_stack_agency.value="Any";
      }
}

function opencustomcwa() {
  //opens custom column pop-up
  var extra = document.forms[0].otis_custom_col.value;
  var link =  '/otis/cwa_customized_columns.html?vars=' + extra;
  window.open(link,'sub','height=500,width=500,left=120,top=200,resizable,scrollbars');

}

function opencustomici() {
  //opens custom column pop-up
  var extra = document.forms[0].otis_custom_col.value;
  var link =  '/otis/ici_customized_columns.html?vars=' + extra;
  window.open(link,'sub','height=500,width=500,left=120,top=200,resizable,scrollbars');

}


function opencustomcaa() {
  //opens custom column pop-up
  var extra = document.forms[0].otis_custom_col.value;
  var link =  '/otis/caa_customized_columns.html?vars=' + extra;
  window.open(link,'sub','height=500,width=500,left=120,top=200,resizable,scrollbars');

}


function opencustomrcra() {
  //opens custom column pop-up
  var extra = document.forms[0].otis_custom_col.value;
  var link =  '/otis/rcra_customized_columns.html?vars=' + extra;
  window.open(link,'sub','height=500,width=500,left=120,top=200,resizable,scrollbars');

}


function opencustommm() {
  //opens custom column pop-up
  var extra = document.forms[0].otis_custom_col.value;
  var link =  '/otis/mm_customized_columns.html?vars=' + extra;
  window.open(link,'sub','height=500,width=500,left=120,top=200,resizable,scrollbars');

}

function resethiddencaa() {
  //resets caa hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  document.forms[0]._idea_insp_mm1.value = "";
  document.forms[0]._idea_insp_mm2.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_yyyy1.value = "";
  document.forms[0]._idea_insp_yyyy2.value = "";
  document.forms[0].idea_insp_detail.value = "Any";
  document.forms[0]._idea_insp_agency.value = "Any";
  document.forms[0]._not_idea_insp_detail.value = "";
  document.forms[0]._idea_act_mm1.value = "";
  document.forms[0]._idea_act_mm2.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_yyyy1.value = "";
  document.forms[0]._idea_act_yyyy2.value = "";
  document.forms[0]._idea_act_agency.value = "Any";
  document.forms[0].idea_action_detail.value = "Any";
  document.forms[0].idea_afs_hpv.value = "";
  document.forms[0]._idea_stack_mm1.value = "";
  document.forms[0]._idea_stack_mm2.value = "";
  document.forms[0]._idea_stack_dd1.value = "";
  document.forms[0]._idea_stack_dd1.value = "";
  document.forms[0]._idea_stack_yyyy1.value = "";
  document.forms[0]._idea_stack_yyyy2.value = "";
  document.forms[0]._idea_stack_agency.value = "Any";
  document.forms[0]._idea_stack_type.value = "Any";
  document.forms[0].idea_afs_stack_detail.value = "Any";
  document.forms[0].idea_report.value="OTISECHO PARM airpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  document.forms[0].idea_db_filter.value="INC 1DBF AFS NEI ICI DEM TRI";
  document.forms[0].map_database.value="";
}

function resethiddenicp() {
  //resets cwa hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0]._idea_insp_mm1.value = "";
  document.forms[0]._idea_insp_mm2.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_yyyy1.value = "";
  document.forms[0]._idea_insp_yyyy2.value = "";
  document.forms[0].idea_insp_detail.value = "Any";
  document.forms[0].idea_insp_detail_l.value = "";  
  document.forms[0]._idea_insp_agency.value = "Any";
  document.forms[0]._not_idea_insp_detail.value = "";
  document.forms[0]._idea_act_mm1.value = "";
  document.forms[0]._idea_act_mm2.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_yyyy1.value = "";
  document.forms[0]._idea_act_yyyy2.value = "";
  document.forms[0]._idea_act_agency.value = "Any";
  document.forms[0].idea_action_detail.value = "Any";
  document.forms[0].idea_action_detail_l.value = "Any";
  document.forms[0].idea_pcs_snc.value = "S,E,X,T,D";
  document.forms[0].idea_pcs_snc1.value = "S,E,X,T";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  document.forms[0].idea_db_filter.value="INC 1DBF ICP ICI DEM TRI"; 
  document.forms[0].map_database.value="";
}

function resethiddencwa() {
  //resets cwa hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0]._idea_insp_mm1.value = "";
  document.forms[0]._idea_insp_mm2.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_yyyy1.value = "";
  document.forms[0]._idea_insp_yyyy2.value = "";
  document.forms[0].idea_insp_detail.value = "Any";
  document.forms[0].idea_insp_detail_l.value = "";  
  document.forms[0]._idea_insp_agency.value = "Any";
  document.forms[0]._not_idea_insp_detail.value = "";
  document.forms[0]._idea_act_mm1.value = "";
  document.forms[0]._idea_act_mm2.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_yyyy1.value = "";
  document.forms[0]._idea_act_yyyy2.value = "";
  document.forms[0]._idea_act_agency.value = "Any";
  document.forms[0].idea_action_detail.value = "Any";
  document.forms[0].idea_action_detail_l.value = "Any";
  document.forms[0].idea_pcs_snc.value = "";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  document.forms[0].idea_db_filter.value="INC 1DBF PCS ICI DEM TRI"; 
  document.forms[0].map_database.value="";
}



function resethiddenrcra() {
  //resets rcra hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  document.forms[0]._idea_insp_mm1.value = "";
  document.forms[0]._idea_insp_mm2.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_dd1.value = "";
  document.forms[0]._idea_insp_yyyy1.value = "";
  document.forms[0]._idea_insp_yyyy2.value = "";
  document.forms[0].idea_insp_detail.value = "Any";
  document.forms[0]._idea_insp_agency.value = "Any";
  document.forms[0]._not_idea_insp_detail.value = "";
  document.forms[0].idea_insp_detail_l.value = "";  
  document.forms[0]._idea_act_mm1.value = "";
  document.forms[0]._idea_act_mm2.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_dd1.value = "";
  document.forms[0]._idea_act_yyyy1.value = "";
  document.forms[0]._idea_act_yyyy2.value = "";
  document.forms[0]._idea_act_agency.value = "Any";
  document.forms[0].idea_action_detail.value = "Any";
  document.forms[0].idea_action_detail_l.value = "";  
  document.forms[0].idea_pcs_snc.value = "";
  document.forms[0].idea_report.value="OTISECHO PARM rcrapage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  document.forms[0].idea_db_filter.value="INC 1DBF RCR ICI DEM TRI";  
  document.forms[0].map_database.value="";
}

function resethiddenmm() {
  //resets mm hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0].idea_linkage.value = "LINKED NONLINKED";
  document.forms[0].idea_db_filter.value = "INC AFS DEM ICI FRS NCD PCS RCR TRI";
  document.forms[0].idea_report.value="OTISECHO PARM SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
}

function resethiddenicimm() {
  //resets mm hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  document.forms[0].idea_linkage.value = "LINKED NONLINKED";
  document.forms[0].idea_db_filter.value = "INC AFS DEM ICI FRS NCD PCS ICP RCR TRI";
  document.forms[0].map_database.value="";  

}

function resethiddenmact() {
  //resets mact hidden fields on reset-fixes firefox bug with customized columns
  document.forms[0].var_all.value = "1,2,3,4,5,6,7,11,26,31,35,36";

}

function submitStandardrcra(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="";
  document.forms[0].idea_db_filter.value="INC 1DBF RCR ICI DEM TRI";
  document.forms[0].idea_report.value="OTISECHO PARM rcrapage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";  
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitMappingrcra(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="MAPOTIS_RCR";
  document.forms[0].idea_db_filter.value="INC 1DBF RCR ICI DEM TRI FRS";
  document.forms[0].idea_report.value="OTISECHO PARM rcrapage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19 R XMLRPT PARM RCR_CHKLAT";  
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardcwa(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="";
  document.forms[0].idea_db_filter.value="INC 1DBF PCS ICI DEM TRI";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitMappingcwa(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="MAPOTIS_PCS";
  document.forms[0].idea_db_filter.value="INC 1DBF PCS ICI DEM TRI FRS";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19 R XMLRPT PARM PCS_CHKLAT";

  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardicp(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="";
  document.forms[0].idea_db_filter.value="INC 1DBF ICP ICI DEM TRI";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitMappingicp(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  document.forms[0].map_database.value="MAPOTIS_ICP";
  document.forms[0].idea_db_filter.value="INC 1DBF ICP ICI DEM TRI FRS";
  document.forms[0].idea_report.value="OTISECHO PARM waterpage_SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19 R XMLRPT PARM ICP_CHKLAT";

  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardmm() {
  document.forms[0].map_database.value="";
  document.forms[0].idea_report.value="OTISECHO PARM SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19";
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  if (preSubmissionCheck()){
    document.forms[0].submit();
  }  
}

function submitMappingmm() {
  document.forms[0].map_database.value="MAPOTIS_MM";
  document.forms[0].idea_report.value="OTISECHO PARM SORTNAME_tricommas_pencommas_DEMRADIUS=3_violqtrsmax=12 PARM actionstart2=#coqbd-19 R XMLRPT PARM CHKLAT";
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,29,30";
  if (preSubmissionCheck()){
    document.forms[0].submit();
  }  
}
function submitStandard(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,29,30";
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardej(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,33,29,30";
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardcwaej(media) {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,33,29,30";
  if (remove_carriage_returns(media)){
    document.forms[0].submit();
  }  
}

function submitStandardmmej() {
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,33,29,30";
  if (preSubmissionCheck()){
    document.forms[0].submit();
  }  
}


function resethiddenej() {
  //resets the reset for EJ seat, we have an additional custom field added.
  document.forms[0].otis_custom_col.value = "7,20,12,13,19,18,23,15,33,29,30";
} 

function resethiddenejcwa() {
  //resets the reset for EJ seat, we have an additional custom field added.
  document.forms[0].otis_custom_col.value = "7,20,12,24,13,19,18,23,15,33,29,30";
} 

function MediaSearch() {
  //resets google maps page (otismaps.html) media checkboxes when url string is passed-in
 if (location.search)
   {  // checks to see if URL has a search string e.g. test.html?searchstring
	 var formParameters = window.location.search.substr(1).split("&");  // splits search string into field=value pairs, returns to formParameters the pair but ignores the "&" (in position 0), populates the array formParameters
	 for (i=0; i < formParameters.length; i++) {
		 formParameters[i] = formParameters[i].split("=");  // for each entry in formParameters, splits field=value pair into mini array with field and value (formParameters [fieldvaluepair][field=0, value=1]
	  }
	 var qStr = new Array();
	 var reftype = "";
	 for (i=0; i < formParameters.length; i++)
	 {
		formParameters[i][0] = formParameters[i][0].replace(/\+/g," ");
 		formParameters[i][0] = unescape(formParameters[i][0]);
	 	formParameters[i][1] = formParameters[i][1].replace(/\+/g," ");
		formParameters[i][1] = unescape(formParameters[i][1]);
		qStr[formParameters[i][0]] = formParameters[i][1];  // formParameters[i][0] equals the field name and formParameters[i][1] equals its value

	 } // end for
	 var tool = qStr["tool"];
	  if (tool) {
	    if(tool == "rcr") {
		document.forms[0].idea_database[2].checked = true;
	       }
	    else if(tool == "caa") {
		document.forms[0].idea_database[1].checked = true;
	       }  
	    else if(tool == "cwa") {
		document.forms[0].idea_database[3].checked = true;
	       }	       
	    else {
		document.forms[0].idea_database[0].checked = true;
	       }       
	  }

 } // end if location.search
} // end function

function ucheckMajor() {
	if (document.forms[0].idea_facility_designation_nmajor.checked) {
	  document.forms[0].otis_facility_designation[0].checked=false;
	
	}

}

function ucheckMajor2() {
	if (document.forms[0].otis_facility_designation[0].checked) {
	  document.forms[0].idea_facility_designation_nmajor.checked=false;
	
	}

}

function resetFirst() {
  //The "Any" option cannot be selected if any other option is selected-> corrects IDEA bug
  var varall_length = document.forms[0].idea_state.length; 
  //alert('var_all length= ' +  varall_length);

    for (i = 1; i<varall_length;i++) {
    	if  (document.forms[0].idea_state[i].selected == true) {
		document.forms[0].idea_state[0].selected = false;
  	}
    }
}

function lengthtest(min,max,field) {
//function takes 3 parameters - minimum # of characters, maximum# of characters, and field propety
  var minimum = min;
  var maximum = max;
  strValue = field.value;
  strValue = strValue.replace(/"/g, "")  // getting rid of quotes
  strValue = strValue.replace(/\r\n/g, ",")  // getting rid of carriage returns
  strValue = strValue.replace(/\s/g, "")  // getting rid of spaces
  var length = strValue.length;
  if ((length != "0") && (strValue.charAt(length-1) != ",")) { //adding comma at last digit of last permit
      strValue = strValue + ",";
   } //end if length !=0

  var counter = 0; //setting up a counter value to determine the number of commas in the list

		 for (var r = 1; r <= length+1; r++) { //for loop determines number of commas in list
			if ((strValue.charAt(r-1) == ",")) {
				  counter = counter +1;
			}  //end if strValue.charAt(r-1)
			else {
				   counter = counter;
			}  //end else
		  }  //end for r=1
		a = strValue.split(",");  //splitting the list at commas
		y = "";  //setting up an array for valid ids
		q = "";  //setting up an array for invalid ids
		var invalid = 0; //variable to denote whether the invalid array is ever accessed

		 for (var k = 0; k < counter; k++) { //increment through each id
			  var sublength = a[k].length;  //determining length of each id in array

              for (var b=minimum;b<=maximum;b++) { //for number of characters in id, starting with minimum
				  if (sublength == b) {  //if id is correct length, add to array of accepted ids, break from loop
					if (y != "") {
					s = new Array (y, ",", a[k]);
						y = s.join("");
						break;
					} // end if (y != "")
					else {
						s = new Array (a[k]);
						y = s.join("");
						break;
					}  //end else
				  }  //end if sublength ==b
				  if ((sublength != b) && (b==maximum)) {  //if id is incorrect length, add to array of invalid ids
					if (q != "") {
					  z = new Array (q, ",", a[k]);
					  q = z.join("");
					  invalid = 1;
					 }  // end if (q != "")
					else {
					  z = new Array (a[k]);
					  q = z.join("");
					  invalid = 1;
					}  //end else
				  } //end if ((sublength != b)

			} // end for (var b=minimum;b<=maximum;b++)
		 }  // end for (var k = 0; k < counter; k++)

		 if (invalid == 1) { //if there are ids in our invalid list
		 	if (minimum == maximum) {
			window.alert("The following invalid values are not " + minimum + " characters long:" + "\n" +  q + "\n" + "These invalid values will be removed");
		 	}
		 	else {
			window.alert("The following invalid values are not between " + minimum + " and " + maximum + " characters long:" + "\n" +  q + "\n" + "These invalid values will be removed");
			}
			field.value = y;
		   }  //end if invalid

} //end lengthtest