function ViscosityWater (temperatureC)
{
  //viscosity in centipoise from Tucker and Nelkom, page 17-21, table 17-7
  var visc = new Array();
  var temp = new Array();
  var viscosity = 0;

  //set up viscosity data arrays
  visc[0]=1.787;
  visc[1]=1.728;
  visc[2]=1.671;
  visc[3]=1.618;
  visc[4]=1.567;
  visc[5]=1.519;
  visc[6]=1.472;
  visc[7]=1.428;
  visc[8]=1.386;
  visc[9]=1.346;
  visc[10]=1.307;
  visc[11]=1.271;
  visc[12]=1.235;
  visc[13]=1.202;
  visc[14]=1.169;
  visc[15]=1.139;
  visc[16]=1.109;
  visc[17]=1.081;
  visc[18]=1.053;
  visc[19]=1.027;
  visc[20]=1.002;
  visc[21]=0.9779;
  visc[22]=0.9548;
  visc[23]=0.9325;
  visc[24]=0.9111;
  visc[25]=0.8904;
  visc[26]=0.8705
  visc[27]=0.8513;
  visc[28]=0.8327;
  visc[29]=0.8148;
  visc[30]=0.7975;
 

  for (i=0 ; i<31 ; i++)
  {
    temp[i] = i;
  }
  
  //set limits
  if (temperatureC<0) {return;}
  if (temperatureC>30) {return;}


  //search (however crudely)
  for (i=0 ; i<30 ; i++)
  {
    if (temp[i]<temperatureC && temperatureC<=temp[i+1])
    {
      sl = (visc[i+1]-visc[i])/(temp[i+1]-temp[i]);
      viscosity = visc[i] + sl*(temperatureC-temp[i]);
    }
  }

  return viscosity;
}
function MolecularWeight (elements,number)
{
  //determine the molecular weight of compounds containing
  //carbon, hydrogen, oxygen, nitrogen, cloride, and sulfur (only)
  //constants from  Mortimer, C.E., 1975, Chemistry, A Conceptual Approach, Van Nostrand, New York, 756pp.
  var mw = 0;

  for (i=0 ; i<10 ; i++ )
  {
    if (elements[i]=="carbon") {mw = mw + number[i]*12.011;} 
    if (elements[i]=="hydrogen") {mw = mw + number[i]*1.0079;} 
    if (elements[i]=="oxygen") {mw = mw + number[i]*15.9994;} 
    if (elements[i]=="nitrogen") {mw = mw + number[i]*14.0067;} 
    if (elements[i]=="chlorine") {mw = mw + number[i]*35.453;} 
    if (elements[i]=="sulfur") {mw = mw + number[i]*32.06;} 
    if (elements[i]=="bromium") {mw = mw + number[i]*79.904;} 
    if (elements[i]=="fluorine") {mw = mw + number[i]*18.99840;} 
    if (elements[i]=="iodine") {mw = mw + number[i]*126.9045;} 
  }

  return mw;
}
function VolumeIncrements (elements,condition,number)
{
  //determine the atomic and structural volume increments
  //  Tucker, W.A. and L.H. Nelken, 1982, "Diffusion Coefficients in Air and Water, in  
  //  Handbook of Chemical Property Estimation Methods, eds. W.J. Lyman, W.F. Reehl, 
  //    D.H. Rosenblatt, American Chemical Society, page 17-11, table 17-4

  var vol = 0;

  for (i=0 ; i<16 ; i++)
  {
    if (elements[i]=="carbon") {vol = vol + number[i]*16.5;} 
    if (elements[i]=="hydrogen") {vol = vol + number[i]*1.98;} 
    if (elements[i]=="oxygen") {vol = vol + number[i]*5.48;} 
    if (elements[i]=="nitrogen") {vol = vol + number[i]*5.69;} 
    if (elements[i]=="chlorine") {vol = vol + number[i]*19.5;} 
    if (elements[i]=="sulfur") {vol = vol + number[i]*17.0;} 
    if (elements[i]=="rings") {vol = vol + number[i]*(-20.2);}  
  }

  return vol;
}
function LaBasVolumeIncrements (elements,condition,number)
{
  var vol = 0;

  for (i=0 ; i<16 ;i++)
  {
    vol = vol + IndividualLaBasVolumeIncrement (elements[i],condition[i],number[i]);
  }
  
  return vol;
}
function IndividualLaBasVolumeIncrement (element,condition,number)
{
  //determine the LaBas Volume Elements 
  //  Tucker, W.A. and L.H. Nelken, 1982, "Diffusion Coefficients in Air and Water, in  
  //  Handbook of Chemical Property Estimation Methods, eds. W.J. Lyman, W.F. Reehl, 
  //    D.H. Rosenblatt, American Chemical Society, page 17-11, table 17-5

  
  var vol = 0;




  //if the atom is not present there are no special conditions
  //and no increments are added (i.e., vol=0)

  //there are three special conditions possible (oxygen, nitrogen and rings) all
  //other atoms do not have special conditions.

  if (number<=0) {return vol;}

  if (element=="carbon") { vol = number*14.8;}
  if (element=="hydrogen") { vol = number*3.7;}
  if (element=="oxygen")
  {
    if (condition=="None") { vol = number*7.4; }
    if (condition=="MethylEstersEthers") { vol = number*9.1; }
    if (condition=="EthylEstersEthers") { vol = number*9.9; }
    if (condition=="HigherEstersEthers") { vol = number*11.0; }
    if (condition=="Acids") { vol = number*12.0; }
    if (condition=="SPN") { vol = number*8.3; }
  }
  if (element=="nitrogen")
  {
    if (condition=="DoubleBonded") { vol = number*15.6;}
    if (condition=="PrimaryAmine") { vol = number*10.5;}
    if (condition=="SecondaryAmine") { vol = number*12.0;}
  }
  if (element=="bromium"){ vol = number*27.0;}
  if (element=="chlorine"){ vol = number*24.6;}
  if (element=="fluorine") { vol = number*8.7;}
  if (element=="iodine") { vol = number*37.0;}
  if (element=="sulfur") { vol = number*25.6;}

  //individual rings, treated separately used in fsg-LaBas Method
  if (element=="ring3") {vol = number*(-6.0);}
  if (element=="ring4") {vol = number*(-8.5);}
  if (element=="ring5") {vol = number*(-11.5);}
  if (element=="ring6") {vol = number*(-15.0);}
  if (element=="ring-naphthalene") {vol = number*(-30);}
  if (element=="ring-anthracene") {vol = number*(-47.5);}

  

  return vol;
}
function DetermineDiffusionCoefficientAirFSG(method,temperatureK,pressureATM,elements,condition,number)
{
//***********************************************************************
//*
//* Function  DetermineDiffusionCoefficient estimates the diffusion coefficient
//*           by the Fuller, Schettler and Giddings method using both FSG volume estimates
//*           and LeBas molar volume estimates
//*
//* Language:  JavaScript1.1
//*
//* Inputs:
//*   method = calculation method 
//*            fsg = Fuller, Schettler and Giddings 
//*            fsgLaBas = Fuller, Schettler and Giddings using LaBas Molar Volume Estimates
//*   temperatureK = temperature in K
//*   pressureATM = pressure in atm
//*   elements = array of element ids
//*   condition = array of special conditions for some elements
//*   number = array of number of elements
//*
//* Returns:
//*   edc = Estimated Diffusion Coefficient in cm2/s
//*
//* 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:
//*  Tucker, W.A. and L.H. Nelken, 1982, "Diffusion Coefficients in Air and Water, in  
//*  Handbook of Chemical Property Estimation Methods, eds. W.J. Lyman, W.F. Reehl, 
//*    D.H. Rosenblatt, American Chemical Society, page 17-11, table 17-4
//*  Mortimer, C.E., 1975, Chemistry, A Conceptual Approach, Van Nostrand, New York, 756pp.
//*  Flanagan, D., 1997, JavaScript: The Definitive Guide, 2ed, O'Reilly and Associates
//*
//* Created: 1-18-2002
//*
//* Required objects:
//*
//* Required functions:
//*
//* Required scripts: VolumeIncrements, MolecularWeights
//*
//***********************************************************************
  var edc = 0;
  var mr = 0;
  var mwGasB = 0;
  var va13 = 0;
  var v114 = 0;

  //molecular weight of air = 28.97 g/mol
  var mwAir = 28.97;
  //molar volume of air = 20.1 cm3/mol
  var volAir = 20.1;

  //determine the molecular weight of the compound of interest
  mwGasB = MolecularWeight (elements,number);  
  mr = (mwAir + mwGasB)/mwAir/mwGasB;

  if (method=="fsg")
  {
    //determine the volume increments for the compound of interest
    volGasB = VolumeIncrements (elements,condition,number);
  }
  if (method=="fsgLaBas")
  {
    //determine the LaBas volume increment for the compound of interest
    volGasB = 0.875 * LaBasVolumeIncrements (elements,condition,number);
  }

  //estimated diffusion coefficient in cm2/s from equation 17-12 of Tucker and Nelken
  va13 = Math.pow(volAir,1./3.);
  if (volGasB>0)
  {
    vb14 = Math.pow(volGasB,1./3.);
    edc = 0.001*Math.pow(temperatureK,1.75)*Math.sqrt(mr)/pressureATM/(va13 + vb14)/(va13 + vb14);
  }

  return edc;
}
function DetermineDiffusionCoefficientAirWL (method,temperatureK,pressureATM,boilingPointK,elements,condition,number)
{
//***********************************************************************
//*
//* Function  DetermineDiffusionCoefficient estimates the diffusion coefficient
//*           by the Wilke and Lee method
//*
//* Language:  JavaScript1.1
//*
//* Inputs:
//*   method = calculation method 
//*            fsgLaBas = Fuller, Schettler and Giddings using LaBas Molar Volume Estimates
//*            
//*
//*   temperatureK = temperature in K
//*   pressureATM = pressure in atm
//*   boilingPointK = boiling point in K
//*   elements = array of element ids
//*   condition = array of special conditions for some elements
//*   number = array of number of elements
//*
//* Returns:
//*   edc = Estimated Diffusion Coefficient in cm2/s
//*
//* 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:
//*  Tucker, W.A. and L.H. Nelken, 1982, "Diffusion Coefficients in Air and Water, in  
//*  Handbook of Chemical Property Estimation Methods, eds. W.J. Lyman, W.F. Reehl, 
//*    D.H. Rosenblatt, American Chemical Society, page 17-13, table 17-4
//*  Mortimer, C.E., 1975, Chemistry, A Conceptual Approach, Van Nostrand, New York, 756pp.
//*  Flanagan, D., 1997, JavaScript: The Definitive Guide, 2ed, O'Reilly and Associates
//*
//* Created: 1-18-2002
//*
//* Required objects:
//*
//* Required functions:
//*
//* Required scripts: VolumeIncrements, MolecularWeights
//*
//***********************************************************************
  var edc = 0;
  var mr = 0;
  var mwGasB = 0;
  var va13 = 0;
  var v114 = 0;

  //molecular weight of air = 28.97 g/mol
  var mwAir = 28.97;
  //molar volume of air = 20.1 cm3/mol
  var volAir = 20.1;
  //
  var sigmaA = 3.711;
  var sigmaB = 0;
  var sigmaAB = 0;
  var eKA = 78.6;
  var eKB = 0;
  var eKAB = 0;
  var tStar = 0;
  var omega = 0;
  var bPrime = 0;

  //determine the molecular weight of the compound of interest
  mwGasB = MolecularWeight (elements,number);  
  mr = (mwAir + mwGasB)/mwAir/mwGasB;

 
  //determine the LaBas volume increment for the compound of interest
  volGasB = LaBasVolumeIncrements (elements,condition,number);
 
  //equation 17-21, characteristic length
  sigmaB = 1.18*Math.pow(volGasB,1./3.);

  //equation 17-20
  sigmaAB = 0.5*(sigmaA + sigmaB);
  
  //equation 17-19, ratio of the Boltzmann constant k to the molecular energy of attraction
  eKB = 1.15 * boilingPointK;

  //equation 17-18
  eKAB = Math.sqrt(eKB*eKA);

  //equation 17-17
  tStar = temperatureK/eKAB;

  //equation 17-16 collision integral
  omega = 1.06036/Math.pow(tStar,0.15610);
  omega = omega + 0.19300/Math.pow(2.71828,0.47635*tStar);
  //omega = omega + Math.pow(1.03587,3.)/Math.pow(2.71828,1.52996*tStar);
  omega = omega + 1.03587/Math.pow(2.71828,1.52996*tStar);
  omega = omega + 1.76474/Math.pow(2.71828,3.89411*tStar);

  //equation 17-15
  bPrime = 0.00217 - 0.00050*Math.sqrt( 1./mwGasB + 1./mwAir );

  //estimated diffusion coefficient in cm2/s from equation 17-14 of Tucker and Nelken
  if (pressureATM>0 && sigmaAB >0 && omega>0 )
  {
    edc = bPrime*Math.pow(temperatureK,1.5)*Math.sqrt(mr)/pressureATM/sigmaAB/sigmaAB/omega; 
  }
  return edc;
}


function DetermineDiffusionCoefficientWater (temperatureC,elements,condition,number)
{
//***********************************************************************
//*
//* Function DetermineDiffusionCoefficientWater uses the Hayduk and Laudie
//*          method for estimating the diffusivity of a chemical in water 
//*
//* Language:  JavaScript1.1
//*
//* Inputs:
//*   temperatureC = temperature in C
//*   pressureATM = pressure in atm
//*   elements = array of element ids
//*   condition = array of special conditions for some elements
//*   number = array of number of elements
//*
//* Returns:
//*   edc = Estimated Diffusion Coefficient in cm2/s
//*
//* 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:
//*  Tucker, W.A. and L.H. Nelken, 1982, "Diffusion Coefficients in Air and Water, in  
//*  Handbook of Chemical Property Estimation Methods, eds. W.J. Lyman, W.F. Reehl, 
//*    D.H. Rosenblatt, American Chemical Society, page 17-20, table 17-4
//*  Mortimer, C.E., 1975, Chemistry, A Conceptual Approach, Van Nostrand, New York, 756pp.
//*  Flanagan, D., 1997, JavaScript: The Definitive Guide, 2ed, O'Reilly and Associates
//*
//* Created: 1-20-2002
//*
//* Required objects:
//*
//* Required functions:
//*
//* Required scripts: VolumeIncrements, MolecularWeights
//*
//***********************************************************************
  var edc = 0;
  var volB = 0;
  var viscosity = 0;
  

 

  //determine the viscosity of water
  viscosity = ViscosityWater(temperatureC);

  //determine the volume increments for the compound of interest
  volB = LaBasVolumeIncrements (elements,condition,number);

  //estimated diffusion coefficient in cm2/s from equation 17-24 of Tucker and Nelken
  if (volB>0)
  {
    edc = (13.26e-5)/Math.pow(viscosity,1.14)/Math.pow(volB,0.589);
  }

  return edc;
}

