// JavaScript Document

var j;
var a;

function makearray(n) {

  this.length = n;

  for (var i = 1; i <=n; ++i)

    this[i] = 0;

}

function Isotope(name, thalf, tunit, SQ1) {

  this.name = name;

  this.thalf = thalf;

  this.tunit = tunit;

  this.SQ1 = SQ1;

}

function getSelectedIndex() {
return document.isoform2.isolist.selectedIndex
}

var topelist = new makearray(119);
topelist[1] = new Isotope("Ac-227", "21.77", "y", "0.1");
topelist[2] = new Isotope("Al-26", "720000", "y", "1");
topelist[3] = new Isotope("Al-29", "0.11", "h", "1");
topelist[4] = new Isotope("Am-241", "432", "y", "0.1");
topelist[5] = new Isotope("Sb-124", "60.20", "d", "10");
topelist[6] = new Isotope("As-74", "17.9", "d", "10");
topelist[7] = new Isotope("Ba-128", "2.43", "d", "1");
topelist[8] = new Isotope("Ba-133", "7.2", "y", "1");
topelist[9] = new Isotope("Ba-140", "12.8", "d", "10");
topelist[10] = new Isotope("Be-7", "53.3", "d", "100");
topelist[11] = new Isotope("Bi-207", "38", "y", "10");
topelist[12] = new Isotope("Bi-210", "5.01", "d", "1");
topelist[13] = new Isotope("Br-77", "57", "h", "1");
topelist[14] = new Isotope("Br-82", "35.34", "h", "10");
topelist[15] = new Isotope("Cd-109", "453", "d", "10");
topelist[16] = new Isotope("Ca-45", "165", "d", "10");
topelist[17] = new Isotope("C-11", "0.34", "h", "1");
topelist[18] = new Isotope("C-14", "5730", "y", "100");
topelist[19] = new Isotope("Ce-141", "32.5", "d", "1");
topelist[20] = new Isotope("Ce-144", "284", "d", "1");
topelist[21] = new Isotope("Cs-134", "2.06", "y", "10");
topelist[22] = new Isotope("Cs-137", "30.17", "y", "10");
topelist[23] = new Isotope("Cl-36", "301000", "y", "10");
topelist[24] = new Isotope("Cr-51", "27.70", "d", "100");
topelist[25] = new Isotope("Co-57", "270", "d", "10");
topelist[26] = new Isotope("Co-58", "71.3", "d", "10");
topelist[27] = new Isotope("Co-60", "5.272", "y", "10");
topelist[28] = new Isotope("Cu-61", "3.32", "h", "1");
topelist[29] = new Isotope("Cu-62", "0.163", "h", "1");
topelist[30] = new Isotope("Cu-64", "12.70", "h", "100");
topelist[31] = new Isotope("Cu-67", "61.88", "h", "100");
topelist[32] = new Isotope("Cm-244", "18.12", "y", "0.1");
topelist[33] = new Isotope("Eu-152", "13", "y", "1");
topelist[34] = new Isotope("F-18", "1.83", "h", "1");
topelist[35] = new Isotope("Gd-153", "242", "d", "1");
topelist[36] = new Isotope("Ga-67", "78.2", "h", "1");
topelist[37] = new Isotope("Ge-68", "275", "d", "1");
topelist[38] = new Isotope("Au-198", "2.696", "d", "10");
topelist[39] = new Isotope("Hf-181", "42.5", "d", "1");
topelist[40] = new Isotope("H-3", "12.26", "y", "1000");
topelist[41] = new Isotope("In-111", "2.81", "d", "1");
topelist[42] = new Isotope("In-113m", "1.66", "h", "100");
topelist[43] = new Isotope("In-114m", "49.51", "d", "10");
topelist[44] = new Isotope("I-123", "13.3", "h", "100");
topelist[45] = new Isotope("I-125", "60.2", "d", "1");
topelist[46] = new Isotope("I-131", "8.04", "d", "1");
topelist[47] = new Isotope("I-132", "2.26", "h", "10");
topelist[48] = new Isotope("Ir-192", "74.2", "d", "10");
topelist[49] = new Isotope("Fe-52", "8.2", "h", "1");
topelist[50] = new Isotope("Fe-55", "2.6", "y", "100");
topelist[51] = new Isotope("Fe-59", "44.6", "d", "10");
topelist[52] = new Isotope("Kr-85", "10.72", "y", "100");
topelist[53] = new Isotope("La-140", "40.3", "h", "10");
topelist[54] = new Isotope("Pb-210", "22.3", "y", "0.1");
topelist[55] = new Isotope("Mn-52m", "0.352", "h", "1");
topelist[56] = new Isotope("Mn-54", "313", "d", "10");
topelist[57] = new Isotope("Mn-56", "2.578", "h", "10");
topelist[58] = new Isotope("Hg-197", "65", "h", "100");
topelist[59] = new Isotope("Hg-203", "46.8", "d", "10");
topelist[60] = new Isotope("Mo-99", "66.02", "h", "10");
topelist[61] = new Isotope("Nd-147", "11.1", "d", "1");
topelist[62] = new Isotope("Np-237", "2140000", "y", "0.1");
topelist[63] = new Isotope("Ni-63", "92", "y", "10");
topelist[64] = new Isotope("Nb-94", "20000", "y", "1");
topelist[65] = new Isotope("Nb-95", "35.15", "d", "1");
topelist[66] = new Isotope("N-13", "0.166", "h", "1");
topelist[67] = new Isotope("O-15", "0.03417", "h", "1");
topelist[68] = new Isotope("P-32", "14.26", "d", "10");
topelist[69] = new Isotope("P-33", "24.4", "d", "1");
topelist[70] = new Isotope("Po-208", "2.9", "y", "1");
topelist[71] = new Isotope("Po-210", "5.01", "d", "0.1");
topelist[72] = new Isotope("K-38", "0.1285", "h", "1");
topelist[73] = new Isotope("K-42", "12.36", "h", "10");
topelist[74] = new Isotope("Pm-147", "2.62", "y", "10");
topelist[75] = new Isotope("Pu-238", "87.75", "y", "0.1");
topelist[76] = new Isotope("Pu-239", "24100", "y", "0.1");
topelist[77] = new Isotope("Pu-240", "6540", "y", "0.1");
topelist[78] = new Isotope("Pu-242", "380000", "y", "0.1");
topelist[79] = new Isotope("Ra-226", "1600", "y", "0.1");
topelist[80] = new Isotope("Rb-82", "0.0208", "h", "1");
topelist[81] = new Isotope("Rb-86", "18.7", "d", "10");
topelist[82] = new Isotope("Ru-103", "39.5", "d", "1");
topelist[83] = new Isotope("Ru-106", "367", "d", "1");
topelist[84] = new Isotope("Sc-46", "83.80", "d", "10");
topelist[85] = new Isotope("Se-75", "118.5", "d", "10");
topelist[86] = new Isotope("Ag-110", "252", "d", "10");
topelist[87] = new Isotope("Ag-111", "7.45", "d", "1");
topelist[88] = new Isotope("Na-22", "2.602", "y", "10");
topelist[89] = new Isotope("Na-24", "15.02", "h", "10");
topelist[90] = new Isotope("Sr-82", "25.0", "d", "1");
topelist[91] = new Isotope("Sr-85", "64.0", "d", "10");
topelist[92] = new Isotope("Sr-89", "52.7", "d", "10");
topelist[93] = new Isotope("Sr-90", "28.8", "y", "0.1");
topelist[94] = new Isotope("S-35", "87.2", "d", "10");
topelist[95] = new Isotope("Tc-99m", "6.05", "h", "100");
topelist[96] = new Isotope("Tc-99", "213000", "y", "10");
topelist[97] = new Isotope("Tl-204", "3.77", "y", "10");
topelist[98] = new Isotope("Th-228", "1.913", "y", "0.1");
topelist[99] = new Isotope("Th-229", "7340", "y", "0.1");
topelist[100] = new Isotope("Th-230", "77000", "y", "0.1");
topelist[101] = new Isotope("Th-232", "14000000000", "y", "0.1");
topelist[102] = new Isotope("Sn-113", "115", "d", "10");
topelist[103] = new Isotope("Sn-119m", "250", "d", "1");
topelist[104] = new Isotope("U-233", "159000", "y", "0.1");
topelist[105] = new Isotope("U-234", "244000", "y", "0.1");
topelist[106] = new Isotope("U-235", "704000000", "y", "0.1");
topelist[107] = new Isotope("U-236", "23400000", "y", "0.1");
topelist[108] = new Isotope("U-238", "4470000000", "y", "0.1");
topelist[109] = new Isotope("V-48", "16", "d", "1");
topelist[110] = new Isotope("Xe-133", "5.25", "d", "100");
topelist[111] = new Isotope("Xe-135", "9.10", "h", "100");
topelist[112] = new Isotope("Y-87", "80", "h", "10");
topelist[113] = new Isotope("Y-90", "64", "h", "10");
topelist[114] = new Isotope("Zn-62", "9.13", "h", "1");
topelist[115] = new Isotope("Zn-65", "244.1", "d", "10");
topelist[116] = new Isotope("Tl-201", "73.5", "h", "10");
topelist[117] = new Isotope("Re-188", "16.9", "h", "10");
topelist[118] = new Isotope("Re-186", "90.6", "h", "10");
topelist[119] = new Isotope("Er-169", "230.4", "h", "10");


function topechoose() {
  var a;
  a= getSelectedIndex()+1;
  document.isoform2.topename.value = topelist[a].name;
  document.isoform2.halflife.value = topelist[a].thalf;
  document.isoform2.timeunit.value = topelist[a].tunit;
  document.isoform.solid.value = 3.7 * topelist[a].SQ1;
  document.isoform.liquid.value = 0.37 * topelist[a].SQ1;
  document.isoform.gas.value = (3.7 * topelist[a].SQ1)/100;
  clearinput();
}

function clearinput() {
  document.isoform.solid.value = "";
  document.isoform.liquid.value = "";
  document.isoform.gas.value = "";
  document.isoform.initact.value = "";
  document.isoform.decayt.value = "";
  document.isoform.decayu[0].checked = false;
  document.isoform.decayu[1].checked = false;
  document.isoform.decayu[2].checked = false;
  document.isoform.decayu[3].checked = false;
  document.isoform.finact.value = "";
  document.isoform.initact2.value = "";
  document.isoform.finact2.value = "";
  document.isoform.decayt2.value = "";
  document.isoform.initact3.value = "";
  document.isoform.mass.value = "";
  document.isoform.decayt3.value = "";
  document.isoform.Tunit3.value = "";
  document.isoform.Tunit.value = "";

}


function calcdecay(form){
  var act = form.initact.value;
  var act2;
  var t = form.decayt.value;
  if (form.decayu[0].checked) {
    if (document.isoform2.timeunit.value == "d")
      t=t*(1/24/60)
    else if (document.isoform2.timeunit.value == "y")
      t=t*(1/8766/60)
     else if (document.isoform2.timeunit.value == "h")
      t=t*(1/60)
  } else if (form.decayu[1].checked) {
    if (document.isoform2.timeunit.value == "d")
      t=t*(1/24)
    else if (document.isoform2.timeunit.value == "y")
      t=t*(1/8766)
  } else if (form.decayu[2].checked){
    if (document.isoform2.timeunit.value == "h")
      t=t*24
    else if (document.isoform2.timeunit.value == "y")
      t=t*(1/365.25)
  } else if (form.decayu[3].checked) {
    if (document.isoform2.timeunit.value == "h")
      t=(t*8766)
    else if (document.isoform2.timeunit.value == "d")
      t=(t*365.25)
  }
  act2 = act*(Math.exp(-0.693147*t/document.isoform2.halflife.value));
  if (act2 <= 0.000001)
    act2 = 0
  form.finact.value = act2;
}

function calcTdecay(form){
  var temp;
  temp = (document.isoform2.halflife.value/-0.693147)*Math.log(document.isoform.finact2.value/document.isoform.initact2.value)
  if (temp <= 0.00001)
    temp = 0;
  form.decayt2.value = temp;
  form.Tunit.value = document.isoform2.timeunit.value
}

function calcTdisposal(form){
  var temp;
  temp = (document.isoform2.halflife.value/-0.693147)*Math.log(document.isoform.solid.value/(document.isoform.initact3.value/document.isoform.mass.value))
  if (temp <= 0.00001)
    temp = 0;
  form.decayt3.value = temp;
  form.Tunit3.value = document.isoform2.timeunit.value
}


function convertUnit(form){
  activity1 = form.activity1.value
  if (form.unit1[0].checked) {
    if (form.unit2[0].checked)
      form.activity2.value = activity1
    else if (form.unit2[1].checked)
      form.activity2.value = activity1/1000
    else if (form.unit2[2].checked)
      form.activity2.value = activity1/37
    else
      form.activity2.value = activity1/37000
   }else if (form.unit1[1].checked){
      if (form.unit2[0].checked)
        form.activity2.value = activity1*1000
      else if (form.unit2[1].checked)
        form.activity2.value = activity1
      else if (form.unit2[2].checked)
        form.activity2.value = activity1/0.037
      else
        form.activity2.value = activity1/37
   }else if (form.unit1[2].checked) {
      if (form.unit2[0].checked)
        form.activity2.value = activity1*37
      else if (form.unit2[1].checked)
        form.activity2.value = activity1*0.037
      else if (form.unit2[2].checked)
        form.activity2.value = activity1
      else
        form.activity2.value = activity1/1000
    }else if (form.unit1[3].checked) {
        if (form.unit2[0].checked)
          form.activity2.value = activity1*37000
        else if (form.unit2[1].checked)
          form.activity2.value = activity1*37
        else if (form.unit2[2].checked)
          form.activity2.value = activity1*1000
        else
          form.activity2.value = activity1
    }
}

function deldate(form){
  var date1;
  var date2;
  var diff;
  date1 = Date.parse(form.date1.value);
  date2 = Date.parse(form.date2.value);
  diff = Math.abs(date2 - date1);
  form.days1.value = diff/86400000;
} 

function adddays(form){
  var date3 = Date.parse(form.date3.value);
  var days2 = form.days2.value * 86400000;
  var added = date3 + days2;
  date4 = new Date();
  date4.setTime(added);
  var timestring = "";
  timestring += date4.getMonth()+1;
  if (timestring == "1")
     timestring = "Ene"
  if (timestring == "2")
     timestring = "Feb"
  if (timestring == "3")
     timestring = "Mar"
  if (timestring == "4")
     timestring = "Abr"
  if (timestring == "5")
     timestring = "May"
  if (timestring == "6")
     timestring = "Jun"
  if (timestring == "7")
     timestring = "Jul"
  if (timestring == "8")
     timestring = "Ago"
  if (timestring == "9")
     timestring = "Sep"
  if (timestring == "10")
     timestring = "Oct"
  if (timestring == "11")
     timestring = "Nov"
  if (timestring == "12")
     timestring = "Dic";
  timestring += " ";
  timestring += date4.getDate();
  timestring += ", ";
  timestring += date4.getFullYear();
  document.convertU.date4.value = timestring;

}
