
<!--
function NG(data,UnitChange,CurrentDate)
  {
    //***********************************************************************
    //*
    //* Function NG calculates the gradient using coordinates directly scaled from
    //*          from a map or entered directly
    //*
    //* Language:  JavaScript1.1
    //*
    //* Inputs: 
    //*  data                  string signal for type of processing values:
    //*                        noexample--perform calculation using user data
    //*                        example--paste example data and calculate
    //*                        example2--paste second example data set and calculate
    //*                        clear--clear all data and exit
    //*                        save--save data to cookie file
    //*                        restore--read data from cookie file
    //*  UnitChage             signal to change units
    //*                        if none no unit change
    //*                        if head change head unit
    //*                        if map change map unit
    //*                        if field change field unit
    //*  CurrentDate           boolean signal to paste current date in the date field
    //*
    //* Returns:
    //*  nothing
    //*
    //* Limitations: Only for use with newgradient.htm
    //*
    //* 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: 9-21-1999
    //*          11-30-1999 units output with calculated values
    //*          12-16-1999 change to one variable to signal unit changes
    //*          01-17-2001 input error corrected for numerator of measured coordinates
    //*          02-04-2001 removal of cookies
    //*          02-09-2001 change from 1 to 2 decimal places for the heads
    //*          02-10-2001 inclusion of tenths in the map scales
    //*
    //* Required functions: clearAll, Input, ShortDate, save, restore, Num2String, Gradient
    //*
    //* Required scripts: input.js, gradient.js, digits.js, sdate.js, cookie.js, back.js, clear.js
    //*
    //***********************************************************************
   var f=document.Gradient;
   var unithead = "";
   var unitdist0 = "";
   var unitdist1 = "";
   var ucf1 = 1; 
   var ucf2 = 1;
   var ucf3 = 1;
   var ucf4 = 1;
   var ucfdist = 1;
   var ucfhead = 1;
   var SiteDate = "";
   var SiteName = "";
   var date = new Date();
   var Ent = new Array();

   var grad = 0;
   var gradstring = "";

   var x1 = 0;
   var y1 = 0;
   var x2 = 0;
   var y2 = 0;
   var h1 = 0;
   var h2 = 0;
   var fn = 0;
   var fd = 1;
   var fn1 = 0;
   var fd1 = 1;
   var ScaleIn = 1;
   var ScaleOut = 1;
    
//results
if (data=="noexample"  || data=="save")
   {
      //distances and heads
      x1 = 0;
      y1 = 0;
      x2 = Input(f.x2.value);
      y2 = 0;
      h1 = Input(f.h1.value);
      h2 = Input(f.h2.value);
      fn = Input(f.InNum.value);
      fd = parseInt(f.InDen.options[f.InDen.selectedIndex].value);
      //error in input corrected 1-17-2001
      fn1 = Input(f.InNum1.value);
      fd1 = parseInt(f.InDen1.options[f.InDen1.selectedIndex].value);

      ScaleIn = Input(f.ScaleIn.value);
      ScaleOut = Input(f.ScaleOut.value);
     
      SiteName = f.site.value;
      if (CurrentDate==true) {SiteDate=ShortDate(date); f.date.value = SiteDate;}
      else {SiteDate = f.date.value;}
    
        
     unithead = f.HeadUnit.options[f.HeadUnit.selectedIndex].value
     unitdist0 = f.DistUnit0.options[f.DistUnit0.selectedIndex].value    
     unitdist1 = f.DistUnit1.options[f.DistUnit1.selectedIndex].value  

     if (data=="save") 
       {
        //display the cookie message
        window.open('../../home/storage.html','storage','width=620,height=400,resizable');
        return;

         /*
         //store the data in an array for saving to a cookie
         Ent[0] = SiteDate;
         Ent[1] = SiteName;

         //create the id cookie
         save("id",Ent);
   
        //save the "new gradient" data
        Ent[0] = ScaleIn;
        Ent[1] = f.DistUnit0.selectedIndex;
        Ent[2] = x1;
        Ent[3] = y1;
        Ent[4] = x2;
        Ent[5] = y2;
        Ent[6] = ScaleOut;
        Ent[7] = f.DistUnit1.selectedIndex;
        Ent[8] = f.HeadUnit.selectedIndex;
        Ent[9] = h1;
        Ent[10] = h2;
        Ent[11] = fn;
        Ent[12] = f.InDen.selectedIndex;
        Ent[13] = fn1;
        Ent[14] = f.InDen1.selectedIndex;
       
        //create the "ng" cookie
        save("ng",Ent);
        */
       }  

   }
if (data=="example" || data=="example2" || data=="example3")
   {

     //example data set
     ScaleIn = 1;
     ScaleOut = 1;
     fn = 0;
     x1 = 0;
     y1 = 0;
     x2 = 200;
     y2 = 0;
     h1 = 20;
     h2 = 19;

     unithead = "ft";
     f.HeadUnit.selectedIndex = 0;
     unitdist0 = "ft";
     unitdist1 = "ft";
     f.DistUnit0.selectedIndex = 1;
     f.DistUnit1.selectedIndex = 0;
     f.InDen.selectedIndex = 0;
     f.InDen1.selectedIndex = 0;
       
     SiteName = "Map Gradient Ex 1";
     SiteDate = ShortDate(date);
    
     //change to a map scale example
     if (data=="example2" || data=="example3")
       {
         ScaleOut = 100;
         x1 = 0;
         x2 = 20;
         unitdist0 = "in"
         f.DistUnit0.selectedIndex = 0;
         SiteName = "Map Gradient Ex 2";
         //change to a fractional example
        if (data=="example3")
         {
           x2 = 20
           fn = 3;
           f.InDen.selectedIndex = 3;
           SiteName = "Map Gradient Ex 3"
           fn1 = 7;
           f.InDen1.selectedIndex = 3;
         }

       }
    }


if (data=="restore")
     {
      //display the cookie message
      window.open('../../home/storage.html','storage','width=620,height=400,resizable');
      return;

      /*
      //recover each value from the cookie
      SiteDate = restore("id","date");
      SiteName = restore("id","site");


      ScaleIn = restore("ng","ScaleIn");
      f.DistUnit0.selectedIndex = restore("ng","UnitIn");
      x1 = restore("ng","x1");
      y1 = restore("ng","y1");
      x2 = restore("ng","x2");
      y2 = restore("ng","y2");
      ScaleOut = restore("ng","ScaleOut");
      f.DistUnit1.selectedIndex = restore("ng","UnitOut");
      f.HeadUnit.selectedIndex = restore("ng","UnitHead");  
      h1 = restore("ng","h1");
      h2 = restore("ng","h2");
      fn = restore('ng','fn');
      f.InDen.selectedIndex = restore('ng','fd');
      fn1 = restore('ng','fn1');
      f.InDen1.selectedIndex = restore('ng','fd1');

      unithead = f.HeadUnit.options[f.HeadUnit.selectedIndex].value
      unitdist0 = f.DistUnit0.options[f.DistUnit0.selectedIndex].value    
      unitdist1 = f.DistUnit1.options[f.DistUnit1.selectedIndex].value  
      */
     }

if ( data=="restore" || data=="example" || data=="example2" || data=="example3")
  {
    f.date.value = SiteDate; 
    f.site.value = SiteName;  
    f.x2.value = x2;
    f.h1.value = h1;
    f.h2.value = h2;
    f.ScaleIn.value = ScaleIn;
    f.ScaleOut.value = ScaleOut;
    f.InNum.value = fn;
    fd = parseInt(f.InDen.options[f.InDen.selectedIndex].value);
    f.InNum1.value = fn1;
    fd1 = parseInt(f.InDen1.options[f.InDen1.selectedIndex].value);

  }

if (data=="clear") {clearAll(f); return;}



  
  

  //Head unit conversions;
  ucf1 = 1;
  if (UnitChange=="head")
    {
     if (f.HeadUnit.options[f.HeadUnit.selectedIndex].value=="ft") {ucf1=1/0.3048; unithead="ft";}
     if (f.HeadUnit.options[f.HeadUnit.selectedIndex].value=="m") {ucf1=0.3048; unithead="m";}
    }
 
  h1 = h1*ucf1;
  h2 = h2*ucf1;     
  f.h1.value = Num2String(h1,4,-10,10,-6,6);
  f.h2.value = Num2String(h2,4,-10,10,-6,6);

 
  unitdist0 = f.DistUnit0.options[f.DistUnit0.selectedIndex].value
  unitdist1 = f.DistUnit1.options[f.DistUnit1.selectedIndex].value 

  
  ucf4 = ScaleOut/(ScaleIn + fn/fd);
  f.testOne.value = fd;

  //add fractional part to distance between the wells
  x2 = x2 + fn1/fd1;


  x1 = x1*ucf4;
  y1 = y1*ucf4;
  x2 = x2*ucf4;
  y2 = y2*ucf4;
 
  f.x2Out.value = Num2String(x2,3,-10,10,-7,7) + " " + unitdist1;
 


  //do all calculation in meters
  ucfdist = 1;
  if (unitdist1=="ft") {ucfdist=0.3048;}
  ucfhead = 1;
  if (unithead=="ft") {ucfhead=0.3048;} 

  //apply the scale factor to the distances


  //convert quantities before performing gradient calculation
  x1 = x1*ucfdist;
  y1 = y1*ucfdist;
  x2 = x2*ucfdist;
  y2 = y2*ucfdist;

  h1 = h1*ucfhead;
  h2 = h2*ucfhead;



  //calculate the gradient
  grad = Gradient (x1,y1,x2,y2,h1,h2);      
  gradstring = Num2String(grad,3,-10,10,-4,4); 

  f.grad.value = gradstring;

  if (data == "save") 
   {
     /*
     //save the gradient result
     Ent[0] = gradstring;
     save ("gr",Ent);
     */
   }

}
//-->
<!-- end newgradient_1.js -->