<!--
document.onkeydown = getkeypress;

function getIndex(aname)
{
  var cntr=0;
  for (cntr=0; cntr<document.frmWaterUse.elements.length; cntr++)
  {
    //alert(document.frmWaterUse.elements[cntr].name);
    if (document.frmWaterUse.elements[cntr].name == aname)
      break;
  }
  return cntr;
}
function getkeypress(e) {
//var charCode = (navigator.appName == "Netscape") ? sender.which : sender.keycode;
//status = charCode;
//if (charCode = 13) {
//alert(window.event.srcElement.name)
//alert(sender.which)
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    if (Key == 13)
      {
        //alert("Key pressed! ASCII-value: " + Key);
      //if (Key = 13) Key =9;
      var theIndex = getIndex(window.event.srcElement.name);
      if (theIndex < frmWaterUse.elements.length-1)
    {
          //document.frmWaterUse.elements[getIndex(window.event.srcElement.name)+1].focus()
          frmWaterUse.elements[theIndex+1].focus()
          if (frmWaterUse.elements[theIndex+1].type == "text")
            frmWaterUse.elements[theIndex+1].select()
          
    }
    }
    //return Key;
}
//}

function clearForm(sender) {
  if (sender==document.frmWaterUse.btnClear1) {
  with (document.frmWaterUse) {
    area1.value="";
    area2.value="";
    area3.value="";
    area4.value="";
    area5.value="";
    area6.value="";
    areaAC1.value="";
    areaAC2.value="";
    areaAC3.value="";
    areaAC4.value="";
    areaAC5.value="";
    areaAC6.value="";
    calcWater(null);
    }
  }
}
function calcArea(sender)
{
  if (sender == null) return(0);
  if (sender.value == 0) return(0);
  //use innertext if sender is grid, value if edit;
  with (document.frmWaterUse) {
    if (sender.name=="areaAC1") area1.value=sender.value*43560;
    if (sender.name=="areaAC2") area2.value=sender.value*43560;
    if (sender.name=="areaAC3") area3.value=sender.value*43560;
    if (sender.name=="areaAC4") area4.value=sender.value*43560;
    if (sender.name=="areaAC5") area5.value=sender.value*43560;
    if (sender.name=="areaAC6") area6.value=sender.value*43560;
  
    if (sender.name=="area1") areaAC1.value=Math.round(sender.value/435.60)/100;
    if (sender.name=="area2") areaAC2.value=Math.round(sender.value/435.60)/100;
    if (sender.name=="area3") areaAC3.value=Math.round(sender.value/435.60)/100;
    if (sender.name=="area4") areaAC4.value=Math.round(sender.value/435.60)/100;
    if (sender.name=="area5") areaAC5.value=Math.round(sender.value/435.60)/100;
    if (sender.name=="area6") areaAC6.value=Math.round(sender.value/435.60)/100;
  }
  calcWater(null);
}

function calcWater(sender)
{
  /*
  if (window.status <> "loaded") then {
    msgbox("Wait for form to finish loading",vbOKOnly)
    exit;
  }
  */
  document.frmWaterUse.LocName.value = document.frmWaterUse.ddstation.value
  //get the sqaure foot from acreage or visa verse:
  if (sender!=null) calcArea(sender);
  
  var statvalue =0.00 ;
  cropary1 = new Array(5);
  cropary2 = new Array(5);
  cropary3 = new Array(5);
  cropary4 = new Array(5);
  cropary5 = new Array(5);
  cropary6 = new Array(5);
  growthary1 = new Array(5);
  growthary2 = new Array(5);
  growthary3 = new Array(5);
  growthary4 = new Array(5);
  growthary5 = new Array(5);
  growthary6 = new Array(5);
  AcFtary = new Array(6);
  AcInary = new Array(6);
  galary = new Array(6);
  tGalary = new Array(6); // total gallons array
  
  //set up the original constants:
  //bluegrass
  cropary1[1]=16.44; cropary1[2]=19.91; cropary1[3]=12.75; cropary1[4]=26.74; cropary1[5]=19.54;
  growthary1[1] = 110; growthary1[2] = 122; growthary1[3] = 91; growthary1[4] = 140; growthary1[5] = 171;
  //Alfalfa
  cropary2[1]=15.94; cropary2[2]=19.67; cropary2[3]=16.24; cropary2[4]=33.80; cropary2[5]=18.83;
  growthary2[1] = 125; growthary2[2] = 107; growthary2[3] = 114; growthary2[4] = 182; growthary2[5] = 132;
  //Pasture  
  cropary3[1]=19.62; cropary3[2]=22.27; cropary3[3]=16.84; cropary3[4]=30.43; cropary3[5]=18.19;
  growthary3[1] = 173; growthary3[2] = 195; growthary3[3] = 165; growthary3[4] = 234; growthary3[5] = 141;
  //Potatoes
  cropary4[1]=18.36; cropary4[2]=20.77; cropary4[3]=15.11; cropary4[4]=26.33; cropary4[5]=17.67;
  growthary4[1] = 125; growthary4[2] = 129; growthary4[3] = 112; growthary4[4] = 130; growthary4[5] = 130;
  //Vegetables
  cropary5[1]=7.65; cropary5[2]=10.29; cropary5[3]=0; cropary5[4]=8.90; cropary5[5]=8.07;
  growthary5[1] = 92; growthary5[2] = 90; growthary5[3] = "*"; growthary5[4] = 90; growthary5[5] = 91;
  //orchard
  cropary6[1]=15.94; cropary6[2]=16.68; cropary6[3]=13.47; cropary6[4]=25.36; cropary6[5]=15.27;
  growthary6[1] = 133; growthary6[2] = 111; growthary6[3] = 119; growthary6[4] = 194; growthary6[5] = 147;
  
  // check to see if area is selected
  var statnum = document.frmWaterUse.ddstation.selectedIndex ;
  if (statnum == 0) 
    alert("You must select the Nearest Station");
  
  var irrType = document.frmWaterUse.irrType.selectedIndex;
  if (irrType == 0) irrType = 1;
    //alert("Select a valid Irrigation Type to get Total Gallon Values");
  
  var irrMult=0;
  if (irrType==1) irrMult = 0.70;
  if (irrType==2) irrMult = document.frmWaterUse.soilType.value;
  
  
  var multConst = ((325900 / 43560) /12);
  with (document.frmWaterUse) {
    AcInary[1]=cropary1[statnum];
    AcInary[2]=cropary2[statnum];
    AcInary[3]= cropary3[statnum]; 
    AcInary[4]= cropary4[statnum];
    AcInary[5]= cropary5[statnum]; 
    AcInary[6]= cropary6[statnum];
    
    AcFtary[1]= (area1.value) * AcInary[1] / 43560 / 12;
  AcFtary[2]= (area2.value) * AcInary[2] / 43560 / 12;
  AcFtary[3]= (area3.value) * AcInary[3] / 43560 / 12;
  AcFtary[4]= (area4.value) * AcInary[4] / 43560 / 12;
  AcFtary[5]= (area5.value) * AcInary[5] / 43560 / 12;
  AcFtary[6]= (area6.value) * AcInary[6] / 43560 / 12;

    galary[1]= AcFtary[1] * 325900;
    galary[2]= AcFtary[2] * 325900;
    galary[3]= AcFtary[3] * 325900;
    galary[4]= AcFtary[4] * 325900;
    galary[5]= AcFtary[5] * 325900;
    galary[6]= AcFtary[6] * 325900;
    
    //AcInary[1]=(area1.value)*cropary1[statnum]*multConst;
    //AcInary[2]=(area2.value)*cropary2[statnum]*multConst;
    //AcInary[3]= (area3.value)*cropary3[statnum]*multConst; 
    //AcInary[4]= (area4.value)*cropary4[statnum]*multConst;
    //AcInary[5]= (area5.value)*cropary5[statnum]*multConst; 
    //AcInary[6]= (area6.value)*cropary6[statnum]*multConst;
  
    consIY1.innerText=Math.round(AcInary[1]); 
    consIY2.innerText=Math.round(AcInary[2]); 
    consIY3.innerText=Math.round(AcInary[3]); 
    consIY4.innerText=Math.round(AcInary[4]); 
    consIY5.innerText=Math.round(AcInary[5]); 
    consIY6.innerText=Math.round(AcInary[6]); 

    consAF1.innerText= AcFtary[1];
    consAF2.innerText=(AcFtary[2]); 
    consAF3.innerText=(AcFtary[3]); 
    consAF4.innerText=(AcFtary[4]); 
    consAF5.innerText=(AcFtary[5]); 
    consAF6.innerText=(AcFtary[6]); 
    
    var re = /./;
    var loc=0;
    loc = consAF1.innerText.search(re)+5;
    if (consAF1.innerText>0) consAF1.innerText=(consAF1.innerText.substr(0,loc)); 
    loc = consAF2.innerText.search(re)+5;
    if (consAF2.innerText>0) consAF2.innerText=(consAF2.innerText.substr(0,loc)); 
    loc = consAF3.innerText.search(re)+5;
    if (consAF3.innerText>0) consAF3.innerText=(consAF3.innerText.substr(0,loc)); 
    loc = consAF4.innerText.search(re)+5;
    if (consAF4.innerText>0) consAF4.innerText=(consAF4.innerText.substr(0,loc)); 
    loc = consAF5.innerText.search(re)+5;
    if (consAF5.innerText>0) consAF5.innerText=(consAF5.innerText.substr(0,loc)); 
    loc = consAF6.innerText.search(re)+5;
    if (consAF6.innerText>0) consAF6.innerText=(consAF6.innerText.substr(0,loc)); 
    
    cons1.innerText=Math.round(galary[1]); 
    cons2.innerText=Math.round(galary[2]); 
    cons3.innerText=Math.round(galary[3]); 
    cons4.innerText=Math.round(galary[4]); 
    cons5.innerText=Math.round(galary[5]); 
    cons6.innerText=Math.round(galary[6]); 
  
    if (irrMult == 0) tGalary[1] = 0 
      else tGalary[1]=Math.round(galary[1]/irrMult); 
    if (irrMult == 0) tGalary[2] = 0 
      else tGalary[2]=Math.round(galary[2]/irrMult); 
    if (irrMult == 0) tGalary[3] = 0 
      else tGalary[3]=Math.round(galary[3]/irrMult); 
    if (irrMult == 0) tGalary[4] = 0 
      else tGalary[4]=Math.round(galary[4]/irrMult); 
    if (irrMult == 0) tGalary[5] = 0 
      else tGalary[5]=Math.round(galary[5]/irrMult); 
    if (irrMult == 0) tGalary[6] = 0 
      else tGalary[6]=Math.round(galary[6]/irrMult); 
  }
  
  with (document.frmWaterUse.areaTot){
    value=Math.round(document.frmWaterUse.area1.value)+
      Math.round(document.frmWaterUse.area2.value)+
      Math.round(document.frmWaterUse.area3.value)+
      Math.round(document.frmWaterUse.area4.value)+
      Math.round(document.frmWaterUse.area5.value)+
      Math.round(document.frmWaterUse.area6.value);
  }

  with (document.frmWaterUse.areaACTot){
    value=(Math.round(document.frmWaterUse.areaAC1.value*100)+
      Math.round(document.frmWaterUse.areaAC2.value*100)+
      Math.round(document.frmWaterUse.areaAC3.value*100)+
      Math.round(document.frmWaterUse.areaAC4.value*100)+
      Math.round(document.frmWaterUse.areaAC5.value*100)+
      Math.round(document.frmWaterUse.areaAC6.value*100))/100;
  }
  with (document.frmWaterUse){
    consTot.innerText=(Math.round(galary[1])+
      Math.round(galary[2])+
      Math.round(galary[3])+
      Math.round(galary[4])+
      Math.round(galary[5])+
      Math.round(galary[6]));
  }
  consAFTot.innerText=(Math.round(consAF1.innerText*1000)+
      Math.round(consAF2.innerText*1000)+
      Math.round(consAF3.innerText*1000)+
      Math.round(consAF4.innerText*1000)+
      Math.round(consAF5.innerText*1000)+
      Math.round(consAF6.innerText*1000))/1000;
  
  document.frmWaterUse.totGal.value=(tGalary[1])+
      (tGalary[2])+
      (tGalary[3])+
      (tGalary[4])+
      (tGalary[5])+
      (tGalary[6]);
/*
  totGal.value=Math.round(tGalary[1])+
      Math.round(tGalary[1])+
      Math.round(tGalary[1])+
      Math.round(tGalary[1])+
      Math.round(tGalary[1])+
      Math.round(tGalary[1]);
*/
  
  with (document.frmWaterUse) {
    growthdays1.value = growthary1[statnum];
    growthdays2.value = growthary2[statnum];
    growthdays3.value = growthary3[statnum];
    growthdays4.value = growthary4[statnum];
    growthdays5.value = growthary5[statnum];
    growthdays6.value = growthary6[statnum];
  }
}
-->