//
//definition of the GetKh object begins here
//******************************************
function GetKh(c,t)
{
    this.chemical=c;
    this.temp=t;
}


//data
GetKh.prototype.chThermo = new Array;
GetKh.prototype.chEnthalpy = new Array;
GetKh.prototype.chEntropy = new Array;
GetKh.prototype.chNoteThermo = new Array;
GetKh.prototype.chMaxTemp = new Array;

//chemicals with thermodynamic data
ii=-1;
ii=ii+1;
GetKh.prototype.chThermo[ii] = 'bromodichloromethane';
GetKh.prototype.chEnthalpy[ii] = 34980;
GetKh.prototype.chEntropy[ii] = 65.8;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'tribromomethane';
GetKh.prototype.chEnthalpy[ii] = 44260;
GetKh.prototype.chEntropy[ii] = 85.0;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 50;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'tetrachloromethane';
GetKh.prototype.chEnthalpy[ii] = 37910;
GetKh.prototype.chEntropy[ii] = 98.3;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'chloroethane';
GetKh.prototype.chEnthalpy[ii] = 25980;
GetKh.prototype.chEntropy[ii] = 49.75;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 34.6;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'chloroethene';
GetKh.prototype.chEnthalpy[ii] = 27280;
GetKh.prototype.chEntropy[ii] = 61.2;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 34.6;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'trichloromethane';
GetKh.prototype.chEnthalpy[ii] = 35660;
GetKh.prototype.chEntropy[ii] = 72.8;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 50;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'chloromethane';
GetKh.prototype.chEnthalpy[ii] = 35540;
GetKh.prototype.chEntropy[ii] = 79.6;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 34.6;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'dibromochloromethane';
GetKh.prototype.chEnthalpy[ii] = 38640;
GetKh.prototype.chEntropy[ii] = 72.6;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,2-dichlorobenzene';
GetKh.prototype.chEnthalpy[ii] = 36130;
GetKh.prototype.chEntropy[ii] = 68.0;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 37;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,3-dichlorobenzene';
GetKh.prototype.chEnthalpy[ii] = 36170;
GetKh.prototype.chEntropy[ii] = 71.9;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 37;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1-dichloroethane';
GetKh.prototype.chEnthalpy[ii] = 33180;
GetKh.prototype.chEntropy[ii] = 68.2;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 45;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,2-dichloroethane';
GetKh.prototype.chEnthalpy[ii] = 32220;
GetKh.prototype.chEntropy[ii] = 51.9;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 50;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1-dichloroethene';
GetKh.prototype.chEnthalpy[ii] = 31190;
GetKh.prototype.chEntropy[ii] = 74.4;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'cis-1,2-dichloroethene';
GetKh.prototype.chEnthalpy[ii] = 34220;
GetKh.prototype.chEntropy[ii] = 68.6;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'trans-1,2-dichloroethene';
GetKh.prototype.chEnthalpy[ii] = 34350;
GetKh.prototype.chEntropy[ii] = 76.4;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,2-dichloropropane';
GetKh.prototype.chEnthalpy[ii] = 31680;
GetKh.prototype.chEntropy[ii] = 56.9;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,3-dichloropropane';
GetKh.prototype.chEnthalpy[ii] = 39990;
GetKh.prototype.chEntropy[ii] = 80.4;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'dichloromethane';
GetKh.prototype.chEnthalpy[ii] = 31140;
GetKh.prototype.chEntropy[ii] = 54.4;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1,1,2-tetrachloroethane';
GetKh.prototype.chEnthalpy[ii] = 38320;
GetKh.prototype.chEntropy[ii] = 78.1;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1,2,2-tetrachloroethane';
GetKh.prototype.chEnthalpy[ii] = 39770;
GetKh.prototype.chEntropy[ii] = 69.0;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'tetrachloroethene';
GetKh.prototype.chEnthalpy[ii] = 40990;
GetKh.prototype.chEntropy[ii] = 103.8;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 34.6;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1,1-trichloroethane';
GetKh.prototype.chEnthalpy[ii] = 31200;
GetKh.prototype.chEntropy[ii] = 70.3;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = '1,1,2-trichloroethane';
GetKh.prototype.chEnthalpy[ii] = 32730;
GetKh.prototype.chEntropy[ii] = 51.1;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 50;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'trichloroethene';
GetKh.prototype.chEnthalpy[ii] = 36870;
GetKh.prototype.chEntropy[ii] = 84.6;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 40;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'benzene';
GetKh.prototype.chEnthalpy[ii] = 26750;
GetKh.prototype.chEntropy[ii] = 46.06;
GetKh.prototype.chNoteThermo[ii] = "Data from Peng and Wan, 1997, ES&T 31, 2998-3003.";
GetKh.prototype.chMaxTemp[ii] = 25;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'chlorobenzene';
GetKh.prototype.chEnthalpy[ii] = 33010;
GetKh.prototype.chEntropy[ii] = 64.2;
GetKh.prototype.chNoteThermo[ii] = "";
GetKh.prototype.chMaxTemp[ii] = 37;


ii=ii+1;
GetKh.prototype.chThermo[ii] = 'toluene';
GetKh.prototype.chEnthalpy[ii] = 31030;
GetKh.prototype.chEntropy[ii] = 61.18;
GetKh.prototype.chNoteThermo[ii] = "Data from Peng and Wan, 1997, ES&T 31, 2998-3003.";
GetKh.prototype.chMaxTemp[ii] = 30;

ii=ii+1;
GetKh.prototype.chThermo[ii] = 'mtbe';
//coefficients from linear regression of kh vs i/temp (k)
// for the kh values in units of atm m3/mol
// temp, kh (dimensionless), kh (atm m3/mol)
// 3C,  0.0091, 0.000204
// 5C,  0.0112, 0.000251
// 10C, 0.0117, 0.000262
// 15C, 0.0177, 0.000397
// 20C, 0.0224, 0.000502
// 25C, 0.0292, 0.000654
// kh (in atm m3/mol) = -4257.2/(Temp in K) + 6.927
//with adjustement for the multiplication by 1/R (from John's Method) below:
// kh = (-4257.2*8.31441/(Temp in K) + 6.927*8.31441)/8.31441
// kh = (-35396/(Temp in K) + 57.6)/8.31411
GetKh.prototype.chEnthalpy[ii] = 35396;
GetKh.prototype.chEntropy[ii] = 57.6;
GetKh.prototype.chNoteThermo[ii] = "Data from Fischer et al., 2004, Chemosphere 54, 689-694.";
GetKh.prototype.chMaxTemp[ii] = 25;




GetKh.prototype.entriesThermo = ii+1;

GetKh.prototype.chConstant = new Array;
GetKh.prototype.chLnKh = new Array;
GetKh.prototype.chTemp = new Array;
GetKh.prototype.chNote = new Array;

//chemicals without thermodynamic data
ii=-1;

ii=ii+1;
GetKh.prototype.chConstant[ii] = 'ethylbenzene';
GetKh.prototype.chLnKh[ii] = -4.775958507;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu, R.P. Sutherland. 1979. ES&T. Vol. 13. pp. 333-337.';


ii=ii+1;
GetKh.prototype.chConstant[ii] = 'ortho-xylene';
GetKh.prototype.chLnKh[ii] = -5.245724916;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., P.J. Leinonen. 1975. ES&T. Vol. 9. pp. 1178-1180.';

ii=ii+1;
GetKh.prototype.chConstant[ii] = 'meta-xylene';
GetKh.prototype.chLnKh[ii] = -4.974785641;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu. 1981. J. Phys. Chem. Ref. Data. Vol. 10. pp. 1175-1190.';

ii=ii+1;
GetKh.prototype.chConstant[ii] = 'para-xylene';
GetKh.prototype.chLnKh[ii] = -4.960417578;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu. 1981. J. Phys. Chem. Ref. Data. Vol. 10. pp. 1175-1190.';

ii=ii+1;
GetKh.prototype.chConstant[ii] = '2-chloroethylvinyl ether';
GetKh.prototype.chLnKh[ii] = -8.294049640;
GetKh.prototype.chTemp[ii] = 22.5;
GetKh.prototype.chNote[ii] = 'Data reported in Pankow, J.F., M.E. Rosen. 1988. ES&T. Vol. 22. pp. 398-405.  Reference temperature given as range 20 to 25 C';

ii=ii+1;
GetKh.prototype.chConstant[ii] = '1,4-dichlorobenzene';
GetKh.prototype.chLnKh[ii] = -6.450330432;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu. 1981. J. Phys. Chem. Ref. Data. Vol. 10. pp. 1175-1190.';

ii=ii+1;
GetKh.prototype.chConstant[ii] = 'dichlorodifluoromethane';
GetKh.prototype.chLnKh[ii] = -0.913793852;
GetKh.prototype.chTemp[ii] = 25;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu. 1981. J. Phys. Chem. Ref. Data. Vol. 10. pp. 1175-1190.';

ii=ii+1;
GetKh.prototype.chConstant[ii] = 'trichlorofluoromethane';
GetKh.prototype.chLnKh[ii] = -0.220646671;
GetKh.prototype.chTemp[ii] = 20;
GetKh.prototype.chNote[ii] = 'Data reported in Mackay, D., W.Y. Shiu. 1981. J. Phys. Chem. Ref. Data. Vol. 10. pp. 1175-1190.';

GetKh.prototype.entriesConstant = ii+1;
//prevents display of results with no temperature data
//(this is used because the constant values interfere with the temperature dependent values of the OSWER approach)
GetKh.prototype.entriesConstant = -1;

//define functions
//determine if chemical is in the data set
function GetKh_cPresent()
{
  var boolChemical = false;

  for (i=0 ; i<this.entriesThermo ; i=i+1) 
    {   
     if (this.chemical==this.chThermo[i]) {boolChemical=true;}
    }
  for (i=0 ; i<this.entriesConstant ; i=i+1)
    {
     if (this.chemical==this.chConstant[i]) {boolChemical=true;}
    }
  
  return boolChemical;
}


function GetKh_type() 
{
   var chType = 'nodata';
   for (i=0 ; i<this.entriesThermo ; i=i+1) 
    {   
     if (this.chemical==this.chThermo[i]) {chType='thermo'; return chType;}
    }
   for (i=0 ; i<this.entriesConstant ; i=i+1)
    {
     if (this.chemical==this.chConstant[i]) {chType='constant'; return chType;}
    }
   return chType;
}


function GetKh_note() 
{
   var chNote = '';
   var foundValue = false;

   //check chemicals with thermodynamic data
   for (i=0 ; i<this.entriesThermo ; i=i+1) 
    {
     if (this.chemical==this.chThermo[i])
     {
      if (this.chNoteThermo[i]!="")
      {
        chNote = this.chNoteThermo[i];
        foundValue = true;
        break;
      }
      else
      {
       chNote = 'Value calculated using thermodynamic data reported in Washington, J.W. 1996. Ground Water. Vol. 34. pp. 709-718.';
       foundValue = true;  
       break;   
      }
     }   
    }

   //check chemicals without thermodynamic data
   for (i=0 ; i<this.entriesConstant ; i=i+1)
    {
     if (this.chemical==this.chConstant[i]) 
     {
        chNote = this.chNote[i]; 
        foundValue=true; 
        break;
     }    
    }

   if (foundValue==false) {chNote = 'No peer-reviewed data has been identified for this chemical.';}
   return chNote;
}

function GetKh_thermo()
{
   var kh = 0;
   var lnKh = 0;
   var RI = 1/8.31441
   var chKTemp = this.temp + 273.15

   //estimate Henry's constant for chemicals with thermodynamic data
   for(i=0 ; i<this.entriesThermo ; i=i+1)
   {
     if (this.chemical==this.chThermo[i]) 
     {
      lnKh = (this.chEntropy[i] - this.chEnthalpy[i]/chKTemp)*RI;
      kh = Math.exp(lnKh);
      return kh;
     }
   }
}

function GetKh_checkTemp()
{
   var tempOK = false;

   //check temperature range for chemicals with thermodynamic data
   for(i=0 ; i<this.entriesThermo ; i=i+1)
   {
     if (this.chemical==this.chThermo[i]) 
     {
       //trial temperature must be greater than zero
       if (this.temp>0)
       {
         if (this.temp<=this.chMaxTemp[i])
         {
           //trial temperature must be less than the max allowable
           tempOK = true;
         }
       }
       break;
     }
   }

   return tempOK;
}

function GetKh_maxTemp()
{
   var maxTemp = 0;

   //check temperature range for chemicals with thermodynamic data
   for(i=0 ; i<this.entriesThermo ; i=i+1)
   {
     if (this.chemical==this.chThermo[i]) 
     {
       maxTemp = this.chMaxTemp[i];
       break;       
     }
   }

   return maxTemp;
}

function GetKh_constant()
{
    var kh = 0;
    var lnKh = 0;

    //estimate Henry's constant for chemicals without thermodynamic data
    for(i=0; i<this.entriesConstant; i=i+1)
    {
       if (this.chemical==this.chConstant[i]) 
       {
        lnKh=this.chLnKh[i]; 
        kh = Math.exp(lnKh);
        return kh;
       }
    }
}

function GetKh_temperature()
{
    var te = 0;

    //temperature associated with Henry's constant (no thermodynamic data)
    for(i=0; i<this.entriesConstant; i=i+1)
    {
        if (this.chemical==this.chConstant[i]) 
        {
         te=this.chTemp[i]; 
         return te;
        }
    }
    
}

GetKh.prototype.cPresent = GetKh_cPresent;
GetKh.prototype.type = GetKh_type;
GetKh.prototype.thermo = GetKh_thermo;
GetKh.prototype.checkTemp = GetKh_checkTemp;
GetKh.prototype.maxTemp = GetKh_maxTemp;
GetKh.prototype.constant = GetKh_constant;
GetKh.prototype.temperature = GetKh_temperature;
GetKh.prototype.note = GetKh_note;

//******************************************
//Definition of the GetKh object ends here
//

