// TRI Explorer - Set up parameter string for chemical reports
// W.Smith 21-jan-2000
//
//

function setParms(form) {
// This function sets the parameters to make the proper call to SAS.
// If USA is selected, it calls the top 100 USA facility report,
// else it calls the facilities in your state report
var NS4 = (document.layers) ? 1 : 0;
//    var s="";
//    for (var i=0; i < form.chemical.length; i++ ) {
//        if (form.chemical[i].selected) {
//           alert(form.chemical[i].value);
//           s += ("&fld=" + form.chemical[i].value);
//        }
//    }
//    alert(s);

var triDATASET = "";
var pdr = true;
  for (var i=0 ; i < form.length; i++){
    if (form.elements[i].name == "dataset") {
         pdr = false;
    }
  }
if (pdr == true)
    triDATASET = "TRIQ0";
else {
     if (form.dataset.checked == true)
          triDATASET = "TRIQ0";
     else
          triDATASET = "TRIQ1";
     }

//var statename = (NS4) ? form.state.options[form.state.selectedIndex].text : form.state.text;
//var pickstate = (NS4) ? //form.stateloc.options[form.stateloc.selectedIndex].value : form.stateloc.value;

//if (pickstate == "USA") {
//var statecode = "USA";
// }
//else {
// var statecode = (NS4) ? form.state.options[form.state.selectedIndex].value : form.state.value;
//}

if (form.stateloc.value == null) {
     var pickstate = (NS4) ? document.forms['form1'].stateloc.options[document.forms['form1'].stateloc.selectedIndex].value : document.forms['form1'].stateloc.value;
   }
   else {
     var pickstate = form.stateloc.value;
   }
if (pickstate.substr(0,3) == "USA") {
    statecode = "USA";
 }
else {
   var statecode = (NS4) ? form.state.options[form.state.selectedIndex].value : form.state.value;
 }

var chemicalcode = (NS4) ? form.chemical.options[form.chemical.selectedIndex].value : form.chemical.value;

cwords = form.chemselected.value.split(",");
chem_selected  = "";
for (var i=0; i < cwords.length -1; i++) {
	chem_selected += "&chemical="+cwords[i];
}
if (chemicalcode == "PICKCHEM" && chem_selected == "") {
  alert("You have not selected a chemical \n Please click on the 'Go To New Report' button \n Located to the right of the screen ");
  return false;
}

if (chemicalcode == "" || chemicalcode == null) {
  alert("You have not selected a chemical \n Please click on the 'Go To New Report' button \n Located to the right of the screen ");
  return false;
}
if (chemicalcode != "_ALL_" && chem_selected == "") {
  chem_selected = "&chemical="+chemicalcode;
}
if (chemicalcode == "_ALL_") {
  chem_selected = "&chemical=All+chemicals";
} 


//chemicalname = form.chemical.options[form.chemical.selectedIndex].text;
//if (chemicalname.substring(chemicalname.length-1) == '*') return false;
var industrycode = (NS4) ? form.industry.options[form.industry.selectedIndex].value : form.industry.value;

if (industrycode == "" || industrycode == null) {
  alert("You have not selected an industry \n Please click on the 'Go To New Report' button \n Located to the right of the screen ");
   return false;
}

iwords = form.indselected.value.split(",");
ind_selected  = "";
for (var i=0; i < iwords.length -1; i++) {
	ind_selected += "&industry="+iwords[i];
}

if (industrycode == "SIC" && ind_selected == "") {
  alert("You have not selected an industry \n Please click on the 'Go To New Report' button \n Located to the right of the screen ");
  return false;
}
if (industrycode == "OLD" && ind_selected == "") {
  ind_selected = "&industry=OLD";
}
if (industrycode == "ALL" && ind_selected == "") {
  ind_selected = "&industry=ALL";
}
if (industrycode == "NEW" && ind_selected == "") {
  ind_selected = "&industry=NEW";
}

var yearcode = (NS4) ? form.year.options[form.year.selectedIndex].value : form.year.value;

//alert("chemicalcode = "+chemicalcode+" chem_selected= "+chem_selected+"\n industrycode = "+industrycode +" ind_selected= "+ind_selected);
//return false;

if(chemicalcode == "PBT_IND" && yearcode < "2000") {
   selectchemical(form);
   return false;
}
  var strPageName = form.report.value;

  var strReportNum;
  if (strPageName == "chemical" || strPageName == "chemical01"  )
	strReportNum = "&tab_rpt=1";

  else if (strPageName == "chemicaltransfer")
 	strReportNum = "&tab_rpt=2";

  else if (strPageName.substr(0,16)  == "chemicalquantity")
 	strReportNum = "&tab_rpt=3";

   if (chemicalcode == "_ALL_") {
       if (statecode == "USA") {
        location = sBroker
              + "?view=USCH"
              + "&trilib="+triDATASET
              + "&sort=_VIEW_"
              + "&sort_fmt=1"
              + "&state=All+states"
              + "&county=All+counties"
              + "&chemical=All+chemicals"
              + ind_selected
              + "&year=" + yearcode
//	      + "&_linespp=" + linespp
	      + strReportNum 
              + setreportfields(form)
              + getService();
        }
        else {
        location = sBroker
              + "?view=STCH"
              + "&trilib="+triDATASET
              + "&sort=_VIEW_"
              + "&sort_fmt=1"
              + "&state=" + statefips(statecode)
              + "&county=All+counties"
              + "&chemical=All+chemicals"
              + ind_selected
              + "&year=" + yearcode
// 	      + "&_linespp=" + linespp
	      + strReportNum
              + setreportfields(form)
              + getService();
        }
     }
   else 
        if (statecode == "USA") {
          location = sBroker
              + "?view=USCH"
              + "&trilib="+triDATASET
              + "&sort=_VIEW_"
              + "&sort_fmt=1"
              + "&state=All+states"
              + "&county=All+counties"
              + chem_selected
              + ind_selected
              + "&year=" + yearcode
//	      + "&_linespp=" + linespp
	      + strReportNum 
              + setreportfields(form)
              + getService();
          }
       else {
            location = sBroker
              + "?view=STCH"
              + "&trilib="+triDATASET
              + "&sort=_VIEW_"
              + "&sort_fmt=1"
              + "&state=" + statefips(statecode)
              + "&county=All+counties"
              + chem_selected
              + ind_selected
              + "&year=" + yearcode
	      + strReportNum
              + setreportfields(form)
              + getService();
             }
}



