var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getuser() {
  var user = document.myform.username.value;
  var passw = document.myform.password.value;
  if (user=="" || passw=="") {
     alert('No username or password was entered, please enter one and try again.');
     return false;
  }
  document.myform.submit();
}

function averagetrans() {
  var trans1 = document.myform.trans1.value;
  var trans2 = document.myform.trans2.value;
  //alert(trans1);
  //alert(trans2);
  if (trans1=="" || trans2=="" || trans1=="0" || trans2=="0") {
     //do nothing
     return false;
  } else {
     if (trans1==">60")
       var trans1=60;
     if (trans1==">100")
       var trans1=100;       
     if (trans2==">60")
       var trans2=60;    
     if (trans2==">100")
       var trans2=100;           
     if (trans2==60 && trans1==60) {
       var avgtranscalc = ">60";
       document.myform.avgtrans.value=avgtranscalc;
       }
     else if (trans2==100 && trans1==100) {
       var avgtranscalc = ">100";
       document.myform.avgtrans.value=avgtranscalc;
     } else {
       var avgtranscalc = (parseFloat(trans1) + parseFloat(trans2))/2;
       document.myform.avgtrans.value=avgtranscalc;
     }
   }

}

function addstreamwq() {
  var sampledate = document.myform.sampledate.value;
  var sampletime = document.myform.sampletime.value;
  var appearance = document.myform.appearance.value;
  var recsuit = document.myform.recsuit.value;
  var trans1 = document.myform.trans1.value;
  var trans2 = document.myform.trans2.value;
  var avgtrans = document.myform.avgtrans.value;
  var rainfall = document.myform.rainfall.value;
  var streamstage = document.myform.streamstage.value;
  if (sampledate=="" || sampletime=="") {
     alert('Some of the required fields have not been filled in, please fill them in before pressing the add button.');
     return false;
  }
  document.myform.submit();
}

function addstreamdry() {
  var sampledate = document.myform.sampledate.value;
  var sampletime = document.myform.sampletime.value;
  var comments = document.myform.comments.value;  
  var userid = document.myform.userid.value;
  var siteid = document.myform.siteid.value;  
  if (sampledate=="" || sampletime=="") {
     alert('You must fill in the date and time to add a dry stream record to the sheet.');
     return false;
  }
     window.location="adddrystreamrecord.php?&userid=" + userid + "&siteid=" + siteid + "&sampledate=" + sampledate + "&sampletime=" + sampletime + "&comments=" + comments;
}

function addlakewq() {
  var sampledate = document.myform.sampledate.value;
  var sampletime = document.myform.sampletime.value;
  var pc = document.myform.pc.value;
  var rc = document.myform.rc.value;
  var secchi = document.myform.secchi.value;
  var color = document.myform.color.value;
  if (sampledate=="" || sampletime=="" || pc=="" || rc=="" || secchi=="" || color=="") {
     alert('Some of the required fields have not been filled in, please fill them in before pressing the add button.');
     return false;
  }
  document.myform.submit();
}

function addprecip() {
  var sampledate = document.myform.sampledate.value;
  var sampletime = document.myform.sampletime.value;
  var precip = document.myform.precip.value;
  if (sampledate=="" || sampletime=="" || precip=="") {
     alert('Some of the required fields have not been filled in, please fill them in before pressing the add button.');
     return false;
  }
  document.myform.submit();
}


function deletestreamwq(id) {
  var wqid = id;
  var userid = document.myform.userid.value;
  var siteid = document.myform.siteid.value;
    var r=confirm("Are you sure you would like to delete this monitoring record from the data sheet?");
    if (r==true)
      {
       window.location="deletestreamwqrecord.php?wqid=" + wqid + "&userid=" + userid + "&siteid=" + siteid;
      }
    else
      {
      //do nothing
    }
}

function deletelakewq(id) {
  var wqid = id;
  var userid = document.myform.userid.value;
  var siteid = document.myform.siteid.value;
    var r=confirm("Are you sure you would like to delete this monitoring record from the data sheet?");
    if (r==true)
      {
       window.location="deletelakewqrecord.php?wqid=" + wqid + "&userid=" + userid + "&siteid=" + siteid;
      }
    else
      {
      //do nothing
    }
}

function deleteprecip(id) {
  var precipid = id;
  var userid = document.myform.userid.value;
    var r=confirm("Are you sure you would like to delete this gauge reading from the data sheet?");
    if (r==true)
      {
       window.location="deletepreciprecord.php?precipid=" + precipid + "&userid=" + userid;
      }
    else
      {
      //do nothing
    }
}