// 
// 

function clear_filter_form()
{
  $('watershed_id').value = ""	
  $('county_id').value = ""
  $('stream_id').value = ""
  $('site_id').value = ""
  document.getElementsByName('date_begin[day]')[0].value = ""
  document.getElementsByName('date_begin[month]')[0].value = ""
  document.getElementsByName('date_begin[year]')[0].value = ""
  document.getElementsByName('date_end[day]')[0].value = ""
  document.getElementsByName('date_end[month]')[0].value = ""
  document.getElementsByName('date_end[year]')[0].value = ""
}

function metriccalc(theForm)
{
   var total = 0;
   var metric1score = 0;
   var metric2score = 0;
   var metric3score = 0;
   var metric4score = 0;
   var metric5score = 0;
   var metric6score = 0;

   total = theForm.fields_17.value * 1 + //worms 
     theForm.fields_18.value * 1 + //flatworms
     theForm.fields_19.value * 1 + //leeches
     theForm.fields_20.value * 1 + //crayfish
     theForm.fields_21.value * 1 + //sowbugs
     theForm.fields_22.value * 1 + //scuds
     theForm.fields_23.value * 1 + //stoneflies
     theForm.fields_24.value * 1 + //mayflies
     theForm.fields_25.value * 1 + //dragonfliesanddamselflies 
     theForm.fields_26.value * 1 + //hellgrammitesfishfliesandalderflies
     theForm.fields_27.value * 1 + //commonnetspinners
     theForm.fields_28.value * 1 + //mostcaddisflies
     theForm.fields_29.value * 1 + //beetles
     theForm.fields_30.value * 1 + //midges
     theForm.fields_31.value * 1 + //blackflies
     theForm.fields_32.value * 1 + //mosttrueflies
     theForm.fields_33.value * 1 + //gilledsnails
     theForm.fields_34.value * 1 + //lungedsnails
     theForm.fields_35.value * 1 + // clams
     theForm.fields_36.value * 1; // other
   theForm.fields_38.value = total; //total

   theForm.fields_39.value =(theForm.fields_24.value * 1 + // metric 1
                           theForm.fields_23.value * 1 +
			   theForm.fields_28.value * 1) / total * 100;

   if (theForm.fields_39.value >  32.2 )
     { metric1score = 2; }
   else if (theForm.fields_39.value >= 16.1 &&
            theForm.fields_39.value <= 32.2 )
     { metric1score = 1; }
   else if (!isFinite(theForm.fields_39.value))
     { theForm.fields_39.value = 0; }


   theForm.fields_40.value = theForm.fields_27.value / total * 100; // metric 2
   if (theForm.fields_40.value < 19.7 )
     { metric2score = 2; } 
   else if (theForm.fields_40.value >= 19.7 &&
            theForm.fields_40.value <= 34.5 )
     { metric2score = 1; }
   else if (!isFinite(theForm.fields_40.value))
     { theForm.fields_40.value = 0; }

   theForm.fields_41.value = theForm.fields_34.value / total * 100; // metric 3
   if (theForm.fields_41.value < 0.3 )
     { metric3score = 2; } 
   else if (theForm.fields_41.value >=  0.3 &&
            theForm.fields_41.value <=  1.5 )
     { metric3score = 1; }
   else if (!isFinite(theForm.fields_41.value))
     { theForm.fields_41.value = 0; }


   theForm.fields_42.value = theForm.fields_29.value / total * 100; // metric 4
   if (theForm.fields_42.value >   6.4 )
     { metric4score = 2; }
   else if (theForm.fields_42.value >= 3.2 &&
            theForm.fields_42.value <= 6.4 )
     { metric4score = 1; }
   else if (!isFinite(theForm.fields_42.value))
     { theForm.fields_42.value = 0; }


   theForm.fields_43.value =(theForm.fields_17.value * 1 + // metric 5
                             theForm.fields_18.value * 1 +
                             theForm.fields_19.value * 1 +
                             theForm.fields_21.value * 1 +
                             theForm.fields_22.value * 1 +
                             theForm.fields_25.value * 1 +
                             theForm.fields_30.value * 1 +
                             theForm.fields_31.value * 1 +
                             theForm.fields_34.value * 1 +
                             theForm.fields_35.value * 1) / total * 100;
   if (theForm.fields_43.value < 46.7 )
     { metric5score = 2; } 
   else if (theForm.fields_43.value >= 46.7 &&
            theForm.fields_43.value <= 61.5 )
     { metric5score = 1; }
   else if (!isFinite(theForm.fields_43.value))
     { theForm.fields_43.value = 0; }
   

   theForm.fields_44.value =(theForm.fields_17.value * 1 + // metric 6
                             theForm.fields_18.value * 1 +
                             theForm.fields_19.value * 1 +
                             theForm.fields_20.value * 1 +
                             theForm.fields_21.value * 1 +
                             theForm.fields_22.value * 1 +
                             theForm.fields_33.value * 1 +
                             theForm.fields_34.value * 1 +
                             theForm.fields_35.value * 1) / total * 100;
   if (theForm.fields_44.value < 5.4 )
     { metric6score = 2; } 
   else if (theForm.fields_44.value >= 5.4 &&
            theForm.fields_44.value <= 20.8 )
     { metric6score = 1; }
   else if (!isFinite(theForm.fields_44.value))
     { theForm.fields_44.value = 0; }

   theForm.fields_45.value = metric1score + // multimetric
     metric2score +
     metric3score +
     metric4score +
     metric5score +
     metric6score;
   //alert(' 1: '+                     metric1score + 
    //     ' 2: '+                     metric2score + 
     //    ' 3: '+                     metric3score + 
      //   ' 4: '+                     metric4score + 
       //  ' 5: '+                     metric5score + 
        // ' 6: '+                     metric6score + 
         //' total: ' +                theForm.multimetricscore.value);
   //if (theForm.fields_44.value > 9){
   //theForm.ecologicalconditions[0].click();
   //}
   //else {if (theForm.multimetricscore.value = 8){theForm.ecologicalconditions[1].click();}
   //else{
   // theForm.ecologicalconditions[2].click();
   //};
   //}
}
