
<!--
function VerticalGradient(data,CurrentDate)
{
//***********************************************************************
//*
//* Function VerticalGradient (Calculator)
//*
//* Language:  JavaScript1.1
//*
//* Inputs:
//*     data           noexample -- process  input data and perform calculation
//*                    example   -- load example data and perform calculation
//*                    clear     -- clear all data fields and exit
//*                    save      -- save data in cookie
//*                    restore   -- restore data from cookie
//*     CurrentDate    if true   -- use current date on calculation
//*
//* Returns:
//*
//* Limitations:
//*
//* Author:
//*  Dr. Jim Weaver
//*  Hydrologist
//*  Regulatory Support Branch
//*  Ecosystems Research Division
//*  National Exposure Research Laboratory
//*  United States Environmental Protection Agency
//*  960 College Station Road
//*  Athens, Georgia 30605
//*  weaver.jim@epa.gov
//* 
//*
//* Reference:
//*  Flanagan, D., 1997, JavaScript: The Definitive Guide, 2ed, O'Reilly and Associates
//*
//* Created:  5-13-2003
//*
//* Required objects: None
//*
//* Required functions: Input, Num2String, CheckSelection, ShortDate, SelectIndex, clearAll, back
//*
//* Required scripts: input.js, digits.js, sdate.js, back.js, getkocprogram.js, index.js, cselect.js, clear.js
//*
//***********************************************************************



  
  var f = document.vgradient;
  var se1 = 0.;
  var se2 = 0.;
  var d1 = 0.;
  var d2 = 0.;
  var dh1 = 0.;
  var dh2 = 0.;
  var h1 = 0.;
  var h2 = 0.;
  var e1 = 0.;
  var e2 = 0.;
  var ebs1 = 0.;
  var ebs2 = 0.;
  var ets1 = 0.;
  var ets2 = 0.;
  var s1 = 0.;
  var s2 = 0.;
  var string01 = "";
  var string02 = "";
  var string03 = "";

  var grad = new Array();

  var date = new Date();
  

  if (data=="noexample" || data=="save")
    {
      se1 = Input(f.se1.value);
      se2 = Input(f.se2.value);
      d1 = Input(f.d1.value);
      d2 = Input(f.d2.value);
      s1 = Input(f.s1.value);
      s2 = Input(f.s2.value);
      dh1 = Input(f.dh1.value);
      dh2 = Input(f.dh2.value);

      if (data=="save")
       {

        //display the cookie message
        window.open('../../home/storage.html','storage','width=620,height=400,resizable');
        return;
        /*
        //save data for future use

      
        */

        }
     }
  if (data=="example")
     {
       se1 = 100.;
       se2 = 100.;
       d1 = 25.;
       d2 = 45.;
       s1 = 5.;
       s2 = 5.;
       dh1 = 15.0;
       dh2 = 14.9;
 
     }
  if (data=="restore")
     {

      //display the cookie message
      window.open('../../home/storage.html','storage','width=620,height=400,resizable,scrollbars');
      return;
      
      /*
      //recover each value from the cookie
     
      */
     }

  if (data=="restore" || data=="example")
     {
        f.se1.value = Num2String(se1,4,-10,10,-6,6); 
        f.se2.value = Num2String(se2,4,-10,10,-6,6); 
        f.s1.value = Num2String(s1,4,-10,10,-6,6); 
        f.s2.value = Num2String(s2,4,-10,10,-6,6); 
        f.dh1.value = Num2String(dh1,4,-10,10,-6,6); 
        f.dh2.value = Num2String(dh2,4,-10,10,-6,6); 
        f.d1.value = Num2String(d1,4,-10,10,-6,6); 
        f.d2.value = Num2String(d2,4,-10,10,-6,6); 
  }


  if (data=="clear") {clearAll(f);return;}
 
  //convert depths to elevations
  // e = elevation of mid point of screen
  // se = surface elevation
  // d = depth to top of screen
  // dh = depth to water
  // ebs = elevation of bottom of screen
  // ets = elevation of the top of screen
  e1 = se1 - (d1 + 0.5*s1);
  e2 = se2 - (d2 + 0.5*s2);
  ebs1 = se1 - (d1 + s1);
  ebs2 = se2 - (d2 + s2);
  ets1 = se1 - d1;
  ets2 = se2 - d2;
  h1 = se1 - dh1;
  h2 = se2 - dh2;

  
  string01 = "";
  string02 = "";
  string03 = "";


  //check to see if wells are not fully submerged 
  if (ets1 > h1 && h1 > ebs1)
  {
    //water table is in shallow well
    string01 = string01 + "Shallow well is a water table well.  ";
    //top of screen is the water table elevation
    ets1 = h1;
    //midpoint is the between the water level and the bottom of the screen
    e1 = 0.5*(ets1 + ebs1);
    //screen length for calculation is reset
    s1 = ets1 - ebs1;
  }
  if (ets2 > h2 && h2 > ebs2)
  {
    //water table is in deep well
    string01 = string01 + "Deep well is a water table well.  ";
    //top of screen is the water table elevation
    ets2 = h2;
    //midpoint is the between the water level and the bottom of the screen
    e2 = 0.5*(ets2 + ebs2);
    //screen length for calculation is reset
    s2 = ets2 - ebs2;
  } 

  if (string01!="") {string01 = string01 + "Only submerged length used in calculations.  ";}

  string02 = "";
  //check to make sure wells aren't dry
  //either well is dry no calculation can be done
  if (h1<=ebs1)
  {
    //shallow well is dry
    string02 = string02 + "Shallow well is dry.  ";
  }
  if (h2<=ebs2)
  {
    //deep well is dry
    string02 = string02 + "Deep well is dry.  ";
  }
 
  if (string02!="") {string02 = string02 + "No calculation is possible.  ";} 


  //assure that the shallow well is shallow and the deep well is deep
  if (ets1 < ets2) {string03 = "Shallow and deep wells are reversed.  Switch them and recalculate.  ";}


  //make comment and exit or proceed
  f.comment.value = string01 + string02 + string03;

  //exit if either well is dry or shallow and deep wells aren't right
  if (string02 != "" || string03 != "") {return;}
  f.comment.value = "Flow directions can be determined.  " + string01;

  //L:H gradient
  grad[3] = (h2-h1)/((e2 + 0.5*s2) - (e1 - 0.5*s1));

  //H:H gradient
  grad[1] = (h2-h1)/((e2 + 0.5*s2) - (e1 + 0.5*s1));

  //Mid:Mid gradient
  grad[0] = (h2-h1)/(e2-e1);

  //L:L gradient
  grad[4] = (h2-h1)/((e2 - 0.5*s2) - (e1 - 0.5*s1));
 
  //H:L gradient
  grad[2] = (h2-h1)/((e2 - 0.5*s2) - (e1 + 0.5*s1));
 
  //magnitudes
 
  f.grad0.value = Num2String(Math.abs(grad[0]),4,-10,10,-6,6); 
  f.grad1.value = Num2String(Math.abs(grad[1]),4,-10,10,-6,6); 
  f.grad2.value = Num2String(Math.abs(grad[2]),4,-10,10,-6,6); 
  f.grad3.value = Num2String(Math.abs(grad[3]),4,-10,10,-6,6);
  f.grad4.value = Num2String(Math.abs(grad[4]),4,-10,10,-6,6); 

  //directions
  if (grad[0]<0.) {f.grad0dir.value = "up";} else {f.grad0dir.value = "down";}
  if (grad[1]<0.) {f.grad1dir.value = "up";} else {f.grad1dir.value = "down";}
  if (grad[2]<0.) {f.grad2dir.value = "up";} else {f.grad2dir.value = "down";}
  if (grad[3]<0.) {f.grad3dir.value = "up";} else {f.grad3dir.value = "down";}
  if (grad[4]<0.) {f.grad4dir.value = "up";} else {f.grad4dir.value = "down";}





  //gradients with screen length of zero
  //calculation for piezometer
  s1 = 0.;
  s2 = 0.;

  //convert depths to elevations
  // e = elevation of mid point of screen
  // se = surface elevation
  // d = depth to top of screen
  // dh = depth to water
  e1 = se1 - (d1 + 0.5*s1);
  e2 = se2 - (d2 + 0.5*s2);
  h1 = se1 - dh1;
  h2 = se2 - dh2;

  

  //Mid:Mid gradient (piezometer with screen length = 0)
  grad[0] = (h2-h1)/(e2-e1);
  f.grad5.value = Num2String(Math.abs(grad[0]),4,-10,10,-6,6); 
  if (grad[0]<0.) {f.grad5dir.value = "up";} else {f.grad5dir.value = "down";}
 



}
//  -->
<!-- end vgradient02_1.js -->