<!--
//created by Joseph Roland
//www.cytographica.com
function weight(form)
{
var cunit = form.cunit.value;
var conc = (form.conc.value)/cunit;
var volunit = (form.volunit.value);
var vol = (form.vol.value)/volunit;
var pH = form.pH.value;
var hclmol = form.hclmol.value;
var tunit = form.tunit.value;
var vunit = form.vunit.value;
var lls = (pH)-(8.12);
var acidcon = Math.pow(10, lls);
var acid = (conc)/((acidcon)+(1));
var grams = ((121.14)*(conc))*(vol);
var dilute = (hclmol)/(acid);
var hcl = (vol)/(dilute);
if (grams < 1)
{
 if (grams > 0.001)
 {
	form.grams.value = Math.round(100000.000*(grams))/100.000;
	form.tunit.value = "mg";
 }
else
{
	form.grams.value = Math.round(1000000.000*(grams))/1.000;
	form.tunit.value = "ug";
}
}
else
{
	form.grams.value = Math.round(1000.000*(grams))/1000.000;
	form.tunit.value = "g";
}

if (hcl < 1)
{
 if (hcl > 0.001)
 {
	form.hcl.value = Math.round(100000.000*(hcl))/100.000;
	form.vunit.value = "mL";
 }
else
{
	form.hcl.value = Math.round(1000000.000*(hcl))/1.000;
	form.vunit.value = "uL";
}
}
else
{
	form.hcl.value = Math.round(1000.000*(hcl))/1000.000;
	form.vunit.value = "L";
}
}

function showOut(form)
{
var cunit = form.cunit.value;
var conc = form.conc.value;
var volunit = form.volunit.value;
var vol = form.vol.value;
var pH = form.pH.value;
var hclmol = form.hclmol.value;
var tunit = form.tunit.value;
var vunit = form.vunit.value;
var grams = form.grams.value;
var hcl = form.hcl.value;
var lls = (pH)-(8.12);
var acidcon = Math.pow(10, lls);
var acid = (conc)/((acidcon)+(1));
var dilute = (hclmol)/(acid);
var zza = lls.toFixed(3);
var zzb = acidcon.toFixed(3);
var zzc = dilute.toFixed(3);
var zzd = acid.toFixed(2);
var zze = form.conc.value/form.cunit.value;
if (cunit == 1)
{
	var munit = "M";
}
if (cunit == 1000)
{
	var munit = "mM";
}
if (cunit == 1000000)
{
	var munit = "&micro;M";
}
if (volunit == 1)
{
	var nunit = "L";
}
if (volunit == 1000)
{
	var nunit = "ml";
}
if (volunit == 1000000)
{
	var nunit = "&micro;l";
}
if (form.conc.value > 0)
{
	if (form.vol.value > 0)
	{
		if (form.pH.value > 0)
		{
newwindow = window.open();
newdoc = newwindow.document;
newdoc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Henderson-Hasselbalch Calculator for Tris Buffers</title></head><body><blockquote><blockquote><table width="700" border="0" align="center" cellpadding="2" cellspacing="0"><tr><td><div align="center"><p><font face="Arial, Helvetica, sans-serif" size="4"><strong>Henderson-Hasselbalch Calculations<br> <font size="3">for '+vol+' '+nunit+' of '+conc+' '+munit+' Tris-Cl, pH '+pH+'</font></strong></font> </p></div></td></tr><tr><td><div align="center"><font size="3" face="Times New Roman, Times, serif"><em><strong>- Mathematical Proof -</strong></em></font></div></td></tr></table><HR WIDTH="70%" SIZE="1" ALIGN="CENTER"><table width="700" border="1" align="center" cellpadding="2"><tr><td><div align="center"><strong><font size="3" face="Times New Roman, Times, serif">HA &hArr; H<sup>+</sup> + A<sup>-</sup></font> </strong></div></td><td><div align="center"><font size="3" face="Times New Roman, Times, serif">HA = Undissociated Acid</font></div></td><td><div align="center"><font size="3" face="Times New Roman, Times, serif">A<sup>-</sup> = Conjugate Base of HA</font></div></td><td><div align="center"><font size="3" face="Times New Roman, Times, serif">H<sup>+</sup> = Hydrogen Ion</font></div></td></tr></table><table width="700" border="1" align="center" cellpadding="4"><tr><td><div align="center"><font size="3">K<sub>a</sub> = [H<sup>+</sup>][A<sup>-</sup>]/[HA]</font></div></td><td><div align="center"><em><font size="3">Therefore:</font></em><font size="3"> -log[H<sup>+</sup>] = -log[K<sub>a</sub>] + log[A<sup>-</sup>] - log[HA]</font></div></td></tr></table><table width="700" border="1" align="center" cellpadding="4"><tr><td><div align="center"><font size="3">pK<sub>a</sub> = -log[K<sub>a</sub>]</font></div></td><td><div align="center"><font size="3">pH = -log[H<sup>+</sup>]</font></div></td><td><div align="center"><font size="3">log[A<sup>-</sup>] - log[HA] = log[A<sup>-</sup>/HA]</font></div></td></tr></table><table width="700" border="1" align="center" cellpadding="4" cellspacing="4"><tr><td><div align="center"><font size="4"><em><font size="3">Henderson-Hasselbalch Equation</font></em>:<strong> pH = pK<sub>a</sub> + log[A<sup>-</sup>/HA] </strong></font></div></td></tr><tr><td><div align="center"><font size="3">Tris-base : MW = 121.14 ; pK<sub>a</sub> = 8.12 at 25&deg;C</font></div></td></tr></table><table width="700" border="0" align="center" cellpadding="4" cellspacing="4"><tr><td><div align="justify"><p align="left">Since the desired pH is '+pH+', then '+pH+' = 8.12 + log[A<sup>-</sup>/HA]</p><p align="left">Therefore, &nbsp;&nbsp;log[A-/HA] = '+zza+' &nbsp;&there4;&nbsp; [A<sup>-</sup>/HA] = 10<sup>('+zza+')</sup> = '+zzb+'</p></div></td></tr><tr><td><div align="justify">The concentration of conjugate base [A<sup>-</sup>] is equal to the concentration of base (in this case '+conc+' '+munit+') minus the concentration of H<sup>+</sup> (which is what we are solving for). Similarly, the concentration of the undissociated acid is equal to the concentration of H<sup>+</sup>. Thus, [A-/HA] = ([Base] - [Acid] ) / [Acid] = '+zzb+' &nbsp;</div></td></tr></table><table width="700" align="center" cellpadding="4"><tr><td><div align="left">Multiply both sides of the equation by [Acid] to get : [Base] - [Acid] = ('+zzb+') * [Acid]</div></td></tr><tr><td> <div align="left">Add [Acid] to both sides of the equation to get : [Base] = (('+zzb+') * [Acid] )+ [Acid]</div></td></tr><tr><td>Divide both sides of the equation by [Acid] to get : [Base]/[Acid] = ('+zzb+') + 1 &nbsp;</td></tr><tr><td>Invert the equation and get : [Acid] = [Base] /  ('+zzb+' + 1)  &nbsp;&there4;&nbsp;[Acid] = ['+conc+' '+munit+'] / ('+zzb+' + 1)</td></tr><tr><td><div align="center"><strong>[Acid] = '+zzd+' '+munit+'</strong></div></td></tr></table><table width="700" align="center" cellpadding="4"><tr><td><div align="justify"><p>If '+hclmol+' M Hydrochloric Acid is used then ['+hclmol+'] / ['+zzd+'] = '+zzc+' (dilution factor)</p><p>Divide the desired volume ('+vol+' '+nunit+') by the dilution factor to get the required volume of HCl to add:</p><p align="center"> '+vol+' '+nunit+' / '+zzc+' =<strong> '+hcl+' '+vunit+' of '+hclmol+' M HCl needed</strong></p></div></td></tr></table><table width="700" align="center" cellpadding="4"><tr><td><div align="justify"><p>To determine the amount of Tris-base needed, multiply the desired volume ('+vol+' '+nunit+'), by the desired concentration ('+conc+' '+munit+'), by the molecular weight (121.14) : </p><p align="center">('+vol+' '+nunit+') x ('+zze+' M) x (121.14) =<strong> '+grams+' '+tunit+'</strong></p></div></td></tr></table><table width="400" border="0" align="center"><tr><td><p align="center"><font color="#DDDDDD" size="2" face="Times New Roman, Times, serif">&copy; 2008 Joseph T.E. Roland <br />www.Cytographica.com</font></p></td></tr></table></blockquote></blockquote></body></html>');
		}
		else
		{
		alert ("YOU MUST ENTER THE DESIRED pH");
		}
	}
	else
	{
	alert ("YOU MUST ENTER THE DESIRED VOLUME");
	}
}
else
{
	alert ("YOU MUST ENTER THE DESIRED MOLARITY");
}
newdoc.close();
}
// JavaScript Document
