function getHTTPObject() {
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
  try {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
       xmlhttp = false;
      }
    }
 @else
 xmlhttp = false;
 @end @*/
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  try {
   xmlhttp = new XMLHttpRequest();
  } catch (e) {
    xmlhttp = false;
    }
 }
return xmlhttp;
}
var http1 = "";
var http2 = "";
var http3 = "";
var http4 = "";
var lc_http = "";
var prev_ptype = "molecule";
/*used to determine if user presses return key. *if so call calculate button on tool they are using.
 * from http://www.java-scripts.net/javascripts/Secret-Alert-Popup.phtml
  */
var nav=navigator.appName;
var ns=(nav.indexOf("Netscape")!=-1);

//determine action if user hits return/enter key
if(ns) {
 if(document.layers) {
  document.captureEvents(Event.KEYPRESS);
  document.onkeypress = getkey;
 }
}
else {
 document.onkeypress = getkey;
}

function getkey(keyStroke) {
 var eventChooser = (ns)?keyStroke.which: event.keyCode;
 if(eventChooser == '13') {
  getIntensityPlot();
 }
}

function updateIsotope() {
 var gas_list_number = "db_gaslist";
 var gasValue = document.getElementById(gas_list_number).value;
 var url = "getIsotope.php?param="+escape(gasValue);
 http4 = getHTTPObject();
 http4.open("GET", url, true);
 http4.onreadystatechange = handleHttpResponse;
 http4.send(null);
}

function handleHttpResponse() {
if (http4.readyState == 4)  {
  var xmlDocument = http4.responseXML;
  var total_num = xmlDocument.getElementsByTagName('total_num').item(0).firstChild.data;
  var new_isotopes_array = new Array(total_num);
  for (var i = 1; i <= total_num; i++)  {
   var which_one = "noi_" + i;
   var iso = xmlDocument.getElementsByTagName(which_one).item(0).firstChild.data;
   new_isotopes_array[i] = iso;
  }
  var update_list = "db_isotopelist";
  isWorking = false;
  var list_menu =document.getElementById(update_list);
  update_isotopes_list(list_menu, total_num ,new_isotopes_array);
 } //end if readystate = 4 
} //end handleHttpResponse function

function nullOptions(aMenu) {
 var menu_length = aMenu.length;
 for (var i = menu_length; 0 <= i; i--)
 {
   aMenu.options[i] = null;
 }
} //end nullOptions function

function update_isotopes_list(my_menu,total_num,new_isotopes_array) {
 nullOptions(my_menu);
 with (my_menu){
  options[0]=null;
  options[0]= new Option("All", "All");
  options[0].selected = true;
  for (var z = 1; z <=total_num; z++)  {
   var iso = new_isotopes_array[z];
   var iso_id = iso.substring(0,1);
   options[z] = new Option(iso,iso_id);
  }
 } //end with
} //end update_isotopes_list function

function getIntensityPlot() {
 document.getElementById("db_err_div").innerHTML = "";
 var db_ll =  db_ll = document.getElementById("db_ll").value;
 var db_ul = db_ul = document.getElementById("db_ul").value;
 var threshold = 0;
 var plot_type = document.getElementById("db_brws_plot_type").value;
 var log_lin = document.getElementById("log_or_linear").value;
 var gas = "";
 var db_table = document.getElementById("db_use_table").value;
 var isotope_number = "";
 var out = "<db_info><type>intensity</type><plot_type>" + plot_type + "</plot_type><scale>" + log_lin +
 "</scale>";
 var error_value = "false";
 var db_units = document.getElementById("db_units").value;
 var temp_ll = "";
 var temp_ul = "";
 var error_string = "";
 var all_cked = "false";
 var db_bp_range = 100;
  if(plot_type == "molecule"){  
   threshold = document.getElementById("db_threshold").value;
   var counter1 = 0;
   var listlen = document.getElementById("listlen").value;
   var box_str = "";
   var cb = "";
   for(var cbox=0; cbox<listlen; cbox++) {
   box_str = "db_molecules" + cbox;
   cb = document.getElementById(box_str).checked;
   if(cb == true) {
    counter1++;
   }
  } //end for
  if(counter1>0) {
    if(counter1 == listlen) {
     all_cked = "true";
    }
    for(var cv=0; cv <listlen ; cv++) {
     box_str = "db_molecules" + cv;
     cb = document.getElementById(box_str);
     if(cb.checked == true){
       out+= "<gas>" + cb.value + "</gas>"; 
     } //end if cb.checked = true;
    } //end for loop
   } //end if counter1 > 0
    if(isNaN(parseFloat(threshold))) {
     threshold = 0;
    }
   out+= "<threshold>" + threshold + "</threshold><numMol>" + counter1 + "</numMol><allCk>" + all_cked + "</allCk>";
  } //end plot_type = molecule
  else if(plot_type == "isotope") {
   threshold = document.getElementById("db_threshold").value;
    if(isNaN(parseFloat(threshold))) {
     threshold = 0;
    }
   gas = document.getElementById("db_gaslist").value;
   isotope_number = document.getElementById("db_isotopelist").value;
   out+= "<gas iso='" + isotope_number + "'>" + gas + "</gas><threshold>" + threshold + "</threshold>";
  }
  else if(plot_type == "cross_section") {
   gas = document.getElementById("db_gaslist").value;
   isotope_number = document.getElementById("db_isotopelist").value;
   out+= "<gas iso='" + isotope_number + "'>" + gas + "</gas>";
  }
   temp_ll = db_ll;
   temp_ul = db_ul;
  if(db_units == "microns") {
   if(parseFloat(db_ll) == 0) {
    db_ll = 0.16;
   }
   if(parseFloat(db_ul) == 0) {
    db_ul = 0.16;
   }
   if(plot_type == "cross_section") {
    if((isNaN(parseFloat(db_ul)))|| (isNaN(parseFloat(db_ll)))) {
     db_ll = "none";
     db_ul = "none";
     temp_ll = 0.16
     temp_ul = 1;
    }
   }
   if((parseFloat(temp_ll) < 0) || (isNaN(parseFloat(temp_ll)))) {
    error_string+= "Lower Limit must be greater than 0 &nbsp;&#181;m&nbsp;<br>";
    error_value = "true";
   }
   if((parseFloat(temp_ul) < 0) || (isNaN(parseFloat(temp_ul)))) {
    error_string+= "Upper Limit must be greater than 0 &nbsp;&#181;m&nbsp;<br>";
    error_value = "true";
   }
  } //end db_units = microns
  else  {
   if(db_table == "hitemp_2008")  {
    var up_min_low = parseFloat(temp_ul) - parseFloat(temp_ll);
    if(up_min_low > 100)    {
     error_string+= "Waveband intervals wider than 100 cm<sup>-1</sup> are not available for the HITEMP 2008 database.<br>";
     error_value = "true";
    }
   }
   if(plot_type == "cross_section") {
    if((isNaN(parseFloat(db_ul)))|| (isNaN(parseFloat(db_ll)))) {
     db_ll = "none";
     db_ul = "none";
     temp_ll = 1
     temp_ul = 2;
    }
   }
   if((parseFloat(temp_ll) < 0) || (isNaN(parseFloat(temp_ll))) || (parseFloat(temp_ll) > 60000)) {
    error_string+= "Lower Limit must be between 0 and 60000 cm<sup>-1</sup><br>";
    error_value = "true";
   }
   if((parseFloat(temp_ul) < 0) || (isNaN(parseFloat(temp_ul))) || (parseFloat(temp_ul) > 60000)) {
    error_string+= "Upper Limit must be between 0 and 60000 cm<sup>-1</sup><br>";
    error_value = "true";
   }
  } //end else (units = wavenumber)

  if((parseFloat(temp_ul) < parseFloat(temp_ll)) || (parseFloat(temp_ul) == parseFloat(temp_ll))) {
   error_string+= "Lower Limit must be less than the Upper Limit.<br>";
   error_value = "true";
  }

  if(parseFloat(threshold) < 0) {
   error_string+= "Threshold value must be greater than 0.<br>";
   error_value = "true";
  }
 if(error_value == "false") {
  var error_div = document.getElementById("error_div");
  error_div.innerHTML = "";
  error_div.style.visibility = "hidden";
  var div1 = document.getElementById("progress_div");
  var div_string = "<center><img src='../images/loading.gif'><br><font color='#004D8F' size='+1'><b>Calculating</b></font></center>";
  document.body.style.cursor = 'wait';
  document.getElementById("db_int_submit").disabled = true;
  div1.innerHTML = "";
  div1.innerHTML = div_string;
  var remote_addr = document.getElementById("calc_remote_addr").value;
  var remote_host = document.getElementById("calc_remote_host").value;
  var user_agent = document.getElementById("calc_user_agent").value;
  var dots = document.getElementById("db_dots").value;
  out+= "<LL>" + db_ll + "</LL><UL>" + db_ul +  "</UL><r_addr>" + remote_addr;
  out+= "</r_addr><r_host>" + remote_host + "</r_host><user_agent>" + user_agent + "</user_agent>";
  out+= "<db_table>" + db_table + "</db_table><dots>" + dots + "</dots><units>" + db_units + "</units>";
  out = "db_xml=" + out + "</db_info>";
  http1 = getHTTPObject();
  http1.open("POST", "exec_grace.php", true);
  http1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  http1.setRequestHeader("Content-length", out.length);
  http1.setRequestHeader("Connection", "close");
  http1.onreadystatechange = show_intensity_plot;
  http1.send(out);
 }
 else {
  var error_div = document.getElementById("error_div");
  error_div.style.visibility = "visible";
  var error_str2 = "<br><font color='red'><strong><u>ERRORS</u></strong><br>";
  error_div.innerHTML = error_str2 + error_string + "</font>";
 }
} //end getIntensityPlot() function

function show_intensity_plot() {
 if(http1.readyState == 4) {
  document.body.style.cursor = 'default';
  document.getElementById("db_int_submit").disabled = false;
  var div1= document.getElementById("progress_div");
  div1.innerHTML = "";
  var res1 = http1.responseText;
  var pos_res = res1.split(":");
  var file_name = pos_res[0];
  var rnum = pos_res[1];
  var remind = pos_res[2]; 
  if(rnum >= 50) {
   document.getElementById("db_int_submit").disabled = true;
   document.getElementById("db_int_clear").disabled = true;
   popUp2("daily_max", "db_brwIN");
  }  //end if rnum >=50 
  else {
   var plot_div = document.getElementById("plot_div");
   var png_file = file_name + ".png";
   var pdf_file = file_name + ".pdf";
   var ps_file = file_name + ".ps";
   var output_string = "<table><TR><TD width='700px;'>";
   output_string+= "<img src='plots/" + png_file + "'><br><center><a href='plots/" +  pdf_file;
   output_string+= "' target='_blank'>PDF</a>&nbsp;&nbsp;<a href='plots/" +  ps_file;
   output_string+= "' target='_blank'>Postscript</a></center></TD></TR></table><hr><br>";
   plot_div.innerHTML = output_string  + plot_div.innerHTML;
   if(remind == "yes") {
    popUp2("remind", "db_brwIN");
    document.getElementById("db_int_submit").disabled = true;
    document.getElementById("db_int_clear").disabled = true;
   } //end remind = yes  
  }
 }//end readystate = 4
} //end function show_intensity_plot

//clears plot area
function ClearPlot() {
 var plot_div = document.getElementById("plot_div");
 plot_div.innerHTML = "";
// window.frameElement.height = 900;
}

function get_data_list() {
 var plot_type = document.getElementById("db_brws_plot_type").value;
 var table_name = document.getElementById("db_use_table").value;
 var params = "num=1&table_name=" + table_name+ "&plot_type=" + plot_type;
 http2 = getHTTPObject();
 http2.open("POST","../getListOfGases.php",true);
 http2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 http2.setRequestHeader("Content-length", params.length);
 http2.setRequestHeader("Connection", "close");
 http2.onreadystatechange = handle_data_list_update;
 http2.send(params);
} //end get_data_list

function handle_data_list_update() {
 if(http2.readyState == 4) {
  var output_to_div = document.getElementById("gas_info");
  var xmlDocument = http2.responseXML;
  var plot_type = xmlDocument.getElementsByTagName("plot_type").item(0).firstChild.data;
  var molecules = xmlDocument.getElementsByTagName("molecules").item(0);
  var numMol = molecules.childNodes.length;
  var mol_str = "";
  var ll = document.getElementById("db_ll")
  var ul =  document.getElementById("db_ul");
  var thresh_div = document.getElementById("db_threshold_div");
  var sticks_span = document.getElementById("sticks_span");
  var dots_span = document.getElementById("dots_span");
  if(plot_type == "molecule") {
   thresh_div.className = "cell_show";
   sticks_span.className = "cell_show";
   dots_span.className = "cell_show";
   if(parseInt(numMol) > 0) {
    mol_str+="<table class='molecule' style=\"width:620px;\"><tr>\n";
    mol_str+= "";
    var this_mol = ""; 
    var this_mol_id = "";
    var counter = 0;
    for(var j=0; j < numMol; j++) {
     this_mol = molecules.getElementsByTagName("molecule").item(j).getAttribute("formula");
     this_mol_id = molecules.getElementsByTagName("molecule").item(j).getAttribute("id");
     if(j == 0)  {
      mol_str+= "<td><input type='checkbox' id='db_molecules" + j + "' name='db_molecules' value='" + this_mol_id + "' checked ><a class='mol_over' onmouseover=\"className='mol_out'\" onmouseout=\"className='mol_over'\" onClick='change_clicked(\"" + j + "\")'>" + this_mol + "</a></input></td>\n";
     } 
     else {
      mol_str+= "<td><input type='checkbox' id='db_molecules" + j + "' name='db_molecules' value='" + this_mol_id + "'><a class='mol_over' onmouseover=\"className='mol_out'\" onmouseout=\"className='mol_over'\" onClick='change_clicked(\"" + j + "\")'>" + this_mol + "</a></input></td>\n";
     }
     counter = counter + 1;
     if(counter == 6) {
      mol_str+= "</tr><tr>";
      counter = 0;
     }
    }
    mol_str+="<td><input type='hidden' name='listlen' id='listlen' value='" + numMol + "'></td></tr>";
    var cspan = 6; 
    if(numMol < 6) {
     cspan = numMol;
    }
    mol_str+="<tr align='center'><td colspan=" + cspan + "><br><input type='button' onClick='change_clicked(\"all\"); return false;' value='All' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
    mol_str+="<input type='button' onClick='change_clicked(\"clear\");' value='Clear'>&nbsp;</td>\n";
    mol_str+="</tr></table>\n";

   } //end if numMol > 0
   var output_string = "<table style=\"width:620px; margin:0px;\"><tr><td><table align='center'>";
   output_string+="<tr><th class='ll2' align='center'><div class='hdr' align='center'>\n";
   output_string+="Species</div></th></tr><tr><td>\n";
   output_string+= mol_str + "</td></tr></table></td></tr></table>\n";
   document.getElementById("gas_info").innerHTML = output_string;
  } //end if plot_type = molecule
  else if(plot_type == "isotope")  {
   thresh_div.className = "cell_show";
   sticks_span.className = "cell_show";
   dots_span.className = "cell_show";
   if(parseInt(numMol) > 0) {
    mol_str+="<SELECT id='db_gaslist' name='db_gaslist' STYLE='width:155px' onChange='updateIsotope();'>\n";
    var this_mol = ""; 
    var this_mol_id = "";
    for(var j=0; j < numMol; j++) {
     this_mol = molecules.getElementsByTagName("molecule").item(j).getAttribute("formula");
     this_mol_id = molecules.getElementsByTagName("molecule").item(j).getAttribute("id");
     mol_str+= "<OPTION value=" + this_mol_id + ">" + this_mol + "</OPTION>\n";
    }
    mol_str+= "</SELECT>\n";
   }
   var output_string = "<table align='center' class='ll2' style=\"width:275px;\">";
   output_string+="<tr><th align='center' colspan='2'><div class='hdr' align='center'>\n";
   output_string+="Species</div></th></tr><tr align='center'><td>Gas</td><td>\n";
   output_string+= mol_str + "</tr><tr align='center'><td>Isotopologue</td><td class='ll2'><SELECT STYLE='width:155px' id='db_isotopelist' name='db_isotopelist'><OPTION value='0'>All</OPTION>\n";
   var isotopes = xmlDocument.getElementsByTagName("isotope1").item(0);
   var this_iso =  "";
   var this_iso_id = "";
   for(var is=0 ; is < isotopes.childNodes.length; is++) {
    this_iso = isotopes.getElementsByTagName("isotope").item(is).firstChild.data;
    this_iso_id = isotopes.getElementsByTagName("isotope").item(is).getAttribute("number");
    output_string+="<OPTION value='" + this_iso_id + "'>" + this_iso + "</OPTION>\n";
   }
   output_string+="</SELECT></td></tr></table><br><br>";
   output_to_div.innerHTML = output_string;
  } //end else if plot_type = isotope
  else if(plot_type == "cross_section") {
  thresh_div.className = "cell_hide";
  sticks_span.className = "cell_hide";
  dots_span.className = "cell_hide";
   if(parseInt(numMol) > 0) {
    mol_str+="<SELECT id='db_gaslist' name='db_gaslist' STYLE='width:155px' onChange='updateSpectrum();'  >\n";
    var this_mol = ""; 
    var this_mol_id = "";
    for(var j=0; j < numMol; j++) {
     this_mol = molecules.getElementsByTagName("molecule").item(j).getAttribute("formula");
     this_mol_id = molecules.getElementsByTagName("molecule").item(j).getAttribute("id");
     mol_str+= "<OPTION value=" + this_mol_id + ">" + this_mol + "</OPTION>\n";
    }
    mol_str+= "</SELECT>\n";
   }
   var output_string = "<table align='center' class='ll2' style=\"width:275px;\">";
   output_string+="<tr><th align='center' colspan='2'><div class='hdr' align='center'>\n";
   output_string+="Species</div></th></tr><tr align='center' ><td class='ll2' style=\"padding:5px;\">Gas</td><td class='ll2'>\n";
   output_string+= mol_str + "</tr><tr align='center' ><td class='ll2'>Spectrum</td><td class='ll2'><SELECT STYLE='width:155px' id='db_isotopelist' name='db_isotopelist'>\n";
   var spectrum = xmlDocument.getElementsByTagName("spectrum").item(0);
   var this_spec = "";
   var this_spec_id = "";
   for(var sp=0 ; sp < spectrum.childNodes.length; sp++) {
    this_spec = spectrum.getElementsByTagName("spec").item(sp).firstChild.data;
    this_spec_id = spectrum.getElementsByTagName("spec").item(sp).getAttribute("id");
    output_string+="<OPTION value='" +  this_spec_id + "'>" + this_spec + "</OPTION>\n";
   }
   output_string+="</SELECT></td></tr></table>";
   output_to_div.innerHTML = output_string;
  } //end else if plot_type == cross_section
 }  //end if http.readyState = 4
} //end function handle_data_list_update


function check_db() {
 var plot_type = document.getElementById("db_brws_plot_type").value;
 var table_menu = document.getElementById("db_use_table");
 if(plot_type == "cross_section"){
  if(prev_ptype != "cross_section") {
   nullOptions(table_menu);
   with (table_menu){
    options[0] = new Option("HITRAN08 Cross Sections", "cross_sections08");
    options[1] = new Option("HITRAN04 Cross Sections", "cross_sections04");
   }  //end with
 } 
 } //end if plot_type = cross_section
 else {
 if(prev_ptype == "cross_section") {
 nullOptions(table_menu);
  with (table_menu){
    options[0] = new Option("HITRAN2008", "hitran2008");
    options[1] = new Option("HITRAN2004","hitran2004");
    options[2] = new Option("GEISA2003","geisa2003");
    options[3] = new Option("HITEMP", "hitemp");
    options[4] = new Option("HITEMP Supplemental", "hitemp_supplemental");
  }  //end with
  get_custom_linelist("db_use_table");
 }
}
  get_data_list();
 prev_ptype = plot_type;
}

//this function changes the units displayed beside the lower & upper limit bandpass based upon what unit the user chooses.
function change_db_units() {
 var span_txt = "";
 var calc_unit1 = document.getElementById("db_units");
 var calc_unit = calc_unit1.value;
 var ll = document.getElementById("db_ll");
 var ul = document.getElementById("db_ul");
 var ll_val = ll.value;
 var ul_val = ul.value;
// var plot_type = document.getElementById("db_brws_plot_type").value;
 var db_err_div = document.getElementById("db_err_div");
 db_err_div.innerHTML = "";
 ll.value = "";
 ul.value = "";
 var db_range_limits = document.getElementById("db_range_limits");
 if(calc_unit == "microns") {
   //span_txt = "<a onClick='popUp(event,\"micron\")' class='info_divs'>&#181;m*</a>";
   span_txt = "&nbsp;&#181;m&nbsp;";
  db_range_limits.innerHTML = "( > 0.16&nbsp;&#181;m&nbsp;)";
 }
  else {
 //  span_txt = "<a onClick='popUp(event,\"wavenumber\")' class='info_divs'>cm<sup><font size='-2'>-1</font></sup>*</a>";
   span_txt = "&nbsp;cm<sup>-1</sup>&nbsp;";
   db_range_limits.innerHTML = "(0-60,000 cm<sup>-1</sup>)";
  }
 document.getElementById("db_ll_div").innerHTML = span_txt;
 document.getElementById("db_ul_div").innerHTML = span_txt; 

} //end calc_unit_chg function


function change_clicked(click_action) {
var boxes_checked = document.forms['intensity_form'].elements['db_molecules'];
 var boxes_length = boxes_checked.length;
 if(click_action == "clear") {
  for(var c=0; c < boxes_length; c++) {
   boxes_checked[c].checked = false;
  }
 }
 else if(click_action == "all") {
  var boxes_length2 = boxes_length ;
  for(var a=0; a < boxes_length2; a++) { 
   boxes_checked[a].checked = true;
  }
 }
 else {
 if(document.getElementById("db_use_table").value != "hitemp_supplemental") {
  if(boxes_checked[click_action].checked == true) {
   boxes_checked[click_action].checked = false;
  }
  else {
   boxes_checked[click_action].checked = true;
  }
 }
 } //end if db table != hitemp_supplemental.
}

//this function is used to update the spectrum number menu 
function updateSpectrum() {
 var spec_list_number = "db_gaslist";
 var spec_Value="";
 var my_form = document.getElementById("intensity_form");
 spec_Value = document.getElementById(spec_list_number).value;
 var url = "getSpectrum.php";
 var us_param = "param="+escape(spec_Value);
 http3 = getHTTPObject();
 http3.open("POST", url, true);
 http3.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 http3.setRequestHeader("Content-length", us_param.length);
 http3.setRequestHeader("Connection", "close");
 http3.onreadystatechange = handle_spectrum_update;
 http3.send(us_param);
} //end updateSpectrum function

function handle_spectrum_update() {
 if(http3.readyState == 4)  {
  var xmlDocument = http3.responseXML;
  var total_num = xmlDocument.getElementsByTagName('total_num').item(0).firstChild.data;
  var new_spectrum_array = new Array(total_num);
  var new_spectrum_ids = new Array(total_num);
  var spectrum = xmlDocument.getElementsByTagName("spectrum").item(0);
  var this_spec = "";
  var this_spec_id = "";
  for(var sp=0 ; sp < spectrum.childNodes.length; sp++) {
   this_spec = spectrum.getElementsByTagName("spec").item(sp).firstChild.data;
   this_spec_id = spectrum.getElementsByTagName("spec").item(sp).getAttribute("id");
   new_spectrum_array[sp] = this_spec;
   new_spectrum_ids[sp] = this_spec_id;
  }
  var update_list = "db_isotopelist";
  var list_menu =document.getElementById(update_list);
  update_spectrum_list(list_menu, total_num ,new_spectrum_array, new_spectrum_ids);
 } //end ready state = 4
} //end handle_spectrum_update function

function update_spectrum_list(my_menu,total_num,new_spectrum_array, new_spectrum_ids) {
 nullOptions(my_menu);
 var spec_info = "";
 var spec_id = "";
 with (my_menu){
 for (var z = 0; z <total_num; z++) {
 spec_info = new_spectrum_array[z];
 spec_id = new_spectrum_ids[z];
   options[z] = new Option(spec_info,spec_id);
  }
 } //end with
} //end update_isotopes_list function

function close_popup() {
 document.getElementById("db_int_submit").disabled = false;
  document.getElementById("db_int_clear").disabled = false;
 popUp2("remind", "db_brwIN");
} //end close popup

function close_popup_go_home() {
  popUp2("daily_max", "db_brwIN");
  window.location = "../info/about.php";
} //end close popup go home


//this function will get the last calculation done during this session and load it on the page.
function load_last_calc() {
 var remote_addr = document.getElementById("calc_remote_addr").value; 
 var out = "tool=dbi&r_addr=" + remote_addr;
 lc_http = getHTTPObject();
 lc_http.open("POST", "../last_calc.php", true);
 lc_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 lc_http.setRequestHeader("Content-length", out.length);
 lc_http.setRequestHeader("Connection", "close");
 lc_http.onreadystatechange = load_calc;
 lc_http.send(out);
}


function load_calc() {
 if(lc_http.readyState == 4) {
  var xmlDocument = lc_http.responseXML;
  var ext = xmlDocument.getElementsByTagName("calc").item(0).firstChild.data;
  if(ext != "None") {
   var thresh_div = document.getElementById("db_threshold_div");
   var sticks_span = document.getElementById("sticks_span");
   var dots_span = document.getElementById("dots_span");
   var ptype = xmlDocument.getElementsByTagName("plot_type").item(0).firstChild.data;
   var type_menu = document.getElementById("db_brws_plot_type");
   var pscale = xmlDocument.getElementsByTagName("scale").item(0).firstChild.data;
   var scale_menu = document.getElementById("log_or_linear");
   if(pscale == "log") {
    scale_menu.selectedIndex = 0;
   }
   else {
    scale_menu.selectedIndex = 1;
   }
   var ll = xmlDocument.getElementsByTagName("LL").item(0).firstChild.data;
   document.getElementById("db_ll").value = ll;
   var ul = xmlDocument.getElementsByTagName("UL").item(0).firstChild.data;
   document.getElementById("db_ul").value = ul;
   var load_units = xmlDocument.getElementsByTagName("units").item(0).firstChild.data;
   var db_range_limits = document.getElementById("db_range_limits");
   if(load_units == "microns") {
    span_txt = "&nbsp;&#181;m&nbsp;";
    db_range_limits.innerHTML = "( > 0.16&nbsp;&#181;m&nbsp;)";
   }
   else {
    span_txt = "&nbsp;cm<sup>-1</sup>&nbsp;";
    db_range_limits.innerHTML = "(0-60,000 cm<sup>-1</sup>)";
   }
   document.getElementById("db_ll_div").innerHTML = span_txt;
   document.getElementById("db_ul_div").innerHTML = span_txt; 
   var db_table = xmlDocument.getElementsByTagName("db_table").item(0).firstChild.data;
   var db_list = document.getElementById("db_use_table");
   if(ptype == "cross_section"){
    nullOptions(db_list);
    with (db_list){
     options[0] = new Option("HITRAN08 Cross Sections", "cross_sections08");
     options[1] = new Option("HITRAN04 Cross Sections", "cross_sections04");
    }  //end with
   } //end if plot_type = cross_section
   else {
    nullOptions(db_list);
    with (db_list){
     options[0] = new Option("HITRAN2008", "hitran2008");
     options[1] = new Option("HITRAN2004","hitran2004");
     options[2] = new Option("GEISA2003","geisa2003");
     options[3] = new Option("HITEMP", "hitemp");
     options[4] = new Option("HITEMP Supplemental", "hitemp_supplemental");
    }  //end with
    get_custom_linelist("db_use_table");
   }
   prev_ptype = ptype;
   for(var d=0; d < db_list.length; d++) {
    if(db_list[d].value == db_table) {
     db_list.selectedIndex = d;
     break
    }
   }
   var dots = xmlDocument.getElementsByTagName("dots").item(0).firstChild.data;
  if(dots == "sticks") {
    document.getElementById("db_dots").selectedIndex = 0;
   }
   else if(dots == "dots"){
    document.getElementById("db_dots").selectedIndex = 1;
   }
   else if(dots == "both"){
    document.getElementById("db_dots").selectedIndex = 2;
   }
   var units = xmlDocument.getElementsByTagName("units").item(0).firstChild.data; 
   if(units == "wavenumber") { 
    document.getElementById("db_units").selectedIndex = 0;
   }
   else {
    document.getElementById("db_units").selectedIndex = 1;
   }
   var mol_tag = xmlDocument.getElementsByTagName('molecule');
   var mol_id = "";
   var mol_form = "";
   var mol_Iarray = new Array();
   var mol_Farray = new Array();
   for(var w=0; w < mol_tag.length; w++) {
    mol_id = mol_tag.item(w).getAttribute("id");
    mol_Iarray[w] = mol_id;
    mol_form = mol_tag.item(w).getAttribute("formula"); 
    mol_Farray[w] = mol_form;
   }
   var iso_tag = xmlDocument.getElementsByTagName("iso0");
   var iso_id = "";
   var iso_form = "";
   var iso_Iarray = new Array();
   var iso_Farray = new Array();
   for(var w=0; w < iso_tag.length; w++) {
    iso_id = iso_tag.item(w).firstChild.data;
    iso_Iarray[w] = iso_id;
    iso_form = iso_tag.item(w).getAttribute("formula"); 
    iso_Farray[w] = iso_form;
   }
   if(ptype == "molecule") {
    thresh_div.className = "cell_show";
    sticks_span.className = "cell_show";
    dots_span.className = "cell_show";
    type_menu.selectedIndex = 0;
    var threshold = xmlDocument.getElementsByTagName("threshold").item(0).firstChild.data;
    document.getElementById("db_threshold").value = threshold;
    var gas_array = new Array();
//gas_tag contains the list of gases that were checked during the last calculation.
    var gas_tag = xmlDocument.getElementsByTagName("gas");
    for(var gt=0; gt < gas_tag.length; gt++) {
     gas_array[gt] = gas_tag.item(gt).firstChild.data;
    }
    var mol_str ="<table class='molecule' style=\"width:635px;\"><tr>\n";
    var counter = 0;
    var indof = "-1";
//create list of molecules in database table. 2nd for loop goes through list of gases that were selected in last calculation
//and checks them.
    for(var j=0; j < mol_tag.length; j++) {
     indof = "-1";
     mol_str+= "<td><input type='checkbox' id='db_molecules" + j + "' name='db_molecules' value='" + mol_Iarray[j] + "' ";
     for(var idx=0; idx<gas_array.length; idx++){
     if(mol_Iarray[j]==gas_array[idx]){
       indof = idx;
       break;
      } //end if loop
     } //end for loop
     if(indof != "-1") {
      mol_str+= " checked";
     }
     mol_str+= "><a class='mol_over' onmouseover=\"className='mol_out'\" onmouseout=\"className='mol_over'\" onClick='change_clicked(\"" + j + "\")'>" + mol_Farray[j] + "</a></input></td>\n";
     counter = counter + 1;
     if(counter == 6) {
      mol_str+= "</tr><tr>";
      counter = 0;
     }
    }
    mol_str+="<td><input type='hidden' name='listlen' id='listlen' value='" + mol_tag.length + "'></td></tr>";
    var cspan = 6; 
    if(mol_tag.length < 6) {
     cspan = mol_tag.length;
    }
    mol_str+="<tr align='center'><td colspan=" + cspan + "><br><input type='button' onClick='change_clicked(\"all\"); return false;' value='All' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";
    mol_str+="<input type='button' onClick='change_clicked(\"clear\");' value='Clear'>&nbsp;</td>\n";
    mol_str+="</tr></table><br>\n";
    var output_string = "<table style=\"width:620px;\"><tr><td><table align='center'>";
    output_string+="<tr><th align='center'><div class='hdr' align='center'>\n";
    output_string+="Species</div></th></tr><tr><td>\n";
    output_string+= mol_str + "</td></tr></table></td></tr></table>\n";
    document.getElementById("gas_info").innerHTML = output_string;
   } //end if ptype == molecule
   else if (ptype == "isotope") {
    type_menu.selectedIndex = 1;
    thresh_div.className = "cell_show";
    sticks_span.className = "cell_show";
    dots_span.className = "cell_show";
    var threshold = xmlDocument.getElementsByTagName("threshold").item(0).firstChild.data;
    document.getElementById("db_threshold").value = threshold;
    var gas_tag = xmlDocument.getElementsByTagName("gas").item(0);
    var gas_val = gas_tag.firstChild.data;
    var iso_val = gas_tag.getAttribute("iso");
    var mol_str ="<SELECT id='db_gaslist' name='db_gaslist' STYLE='width:155px' onChange='updateIsotope();'>\n";
    for(var j=0; j < mol_tag.length; j++) {
     if(mol_Iarray[j] == gas_val) {
      mol_str+= "<OPTION value=" + mol_Iarray[j] + " selected>" + mol_Farray[j] + "</OPTION>\n";
     }
     else {
      mol_str+= "<OPTION value=" + mol_Iarray[j] + ">" + mol_Farray[j] + "</OPTION>\n";
     }
    }
    mol_str+= "</SELECT>\n";
    var output_string = "<table align='center'  class='ll2' style=\"width:275px;\">";
    output_string+="<tr><th align='center' colspan='2' class='ll2'><div class='hdr' align='center'>\n";
    output_string+="Species</div></th></tr><tr align='center'><td>Gas</td><td>\n";
    output_string+= mol_str + "</tr><tr align='center'><td>Isotopologue</td><td><SELECT STYLE='width:155px' id='db_isotopelist'  name='db_isotopelist'><OPTION value='0'>All</OPTION>\n";
    for(var is=0 ; is < iso_tag.length; is++) {
     if(iso_Iarray[is] == iso_val) {
     output_string+="<OPTION value='" + iso_Iarray[is] + "' selected>" + iso_Farray[is] + "</OPTION>\n";
     }
     else {
     output_string+="<OPTION value='" + iso_Iarray[is] + "'>" + iso_Farray[is] + "</OPTION>\n";
     }
    }
    output_string+="</SELECT></td></tr></table>";
    document.getElementById("gas_info").innerHTML = output_string;
   } //end ptype == isotope
   else if(ptype == "cross_section") {
    type_menu.selectedIndex = 2;
    thresh_div.className = "cell_hide"; 
    sticks_span.className = "cell_hide";
    dots_span.className = "cell_hide";
    var gas_tag = xmlDocument.getElementsByTagName("gas").item(0);
    var gas_val = gas_tag.firstChild.data;
    var iso_val = gas_tag.getAttribute("iso");
    var mol_str ="<SELECT id='db_gaslist' name='db_gaslist' STYLE='width:155px' onChange='updateSpectrum();'  >\n";
    for(var j=0; j < mol_tag.length; j++) {
     if(mol_Iarray[j] == gas_val) {
      mol_str+= "<OPTION value=" + mol_Iarray[j] + " selected>" + mol_Farray[j] + "</OPTION>\n";
     }
     else {
      mol_str+= "<OPTION value=" + mol_Iarray[j] + ">" + mol_Farray[j] + "</OPTION>\n";
     }
    }
    mol_str+= "</SELECT>\n";
    var output_string = "<table align='center'  class='ll2' style=\"width:275px;\">";
    output_string+="<tr><th align='center' colspan='2'><div class='hdr' align='center'>\n";
    output_string+="Species</div></th></tr><tr align='center'><td class='ll2' style=\"padding:5px;\">Gas</td><td class='ll2'>\n";
    output_string+= mol_str + "</tr><tr align='center'><td class='ll2'>Spectrum</td><td class='ll2'><SELECT STYLE='width:155px' id='db_isotopelist' name='db_isotopelist'>\n";
    for(var sp=0 ; sp < iso_tag.length; sp++) {
     if(iso_Iarray[is] == iso_val) {
     output_string+="<OPTION value='" + iso_Iarray[sp] + "' selected>" + iso_Farray[sp] + "</OPTION>\n";
     }
     else {
     output_string+="<OPTION value='" + iso_Iarray[sp] + "'>" + iso_Farray[sp] + "</OPTION>\n";
     }    }
    output_string+="</SELECT></td></tr></table>";
    document.getElementById("gas_info").innerHTML = output_string;
   } //end ptype == cross_section
  } //end if ext != None
  else {
   get_data_list();
  }
 }  //end lc_http.readyState = 4
} //end function load_calc
