/*
	summary:
		javascript functions that control majority of the atmospheric_paths main page. 
 		It will get the inputs from the page and send them to be processed. It will show the results on the page
		after a calculation completes.
	author: Kim Smith

	copyright:
		(&copy;) Copyright 2006 by GATS Inc.
		11864 Canon Blvd., Suite 101, Newport News, VA 23606

		All Rights Reserved. No part of this software or publication may be
		reproduced, stored in a retrieval system, or transmitted, in any form
		or by any means, electronic, mechanical, photocopying, recording, or
		otherwise without the prior written permission of GATS Inc.


*/

var get_gas_http = "";
var get_plot_http = "";
//show/hide the information in each tab based upon which tab is selected.
function show_tab(cell_number) {
 var div_id_num = "";
 var div_id = "";
 var cell_label = document.getElementById("cell_label");
 var tab_array = new Array("obsv_tab", "paths_tab", "source_tab", "options_tab", "saved_tab", "spectra_tab");
 var tab_desc = new Array("Observer", "Atmosphere", "Source", "Plot Options", "My Settings", "My Spectra");
 var tab_on = new Array();
 tab_on[0] = new Image(85,28);
 tab_on[0].src = "../images/active_tab_obsv.png";
 tab_on[1] = new Image(85,28);
 tab_on[1].src = "../images/active_tab_atmos.png";
 tab_on[2] = new Image(85,28);
 tab_on[2].src = "../images/active_tab_source.png";
 tab_on[3] = new Image(85,28);
 tab_on[3].src = "../images/active_tab_options.png";
 tab_on[4] = new Image(85,28);
 tab_on[4].src = "../images/active_tab_set.png";
 var tab_off = new Array();
 tab_off[0] = new Image(85,28);
 tab_off[0].src = "../images/inactive_tab_obsv.png";
 tab_off[1] = new Image(85,28);
 tab_off[1].src = "../images/inactive_tab_atmos.png";
 tab_off[2] = new Image(85,28);
 tab_off[2].src = "../images/inactive_tab_source.png";
 tab_off[3] = new Image(85,28);
 tab_off[3].src = "../images/inactive_tab_options.png";
 tab_off[4] = new Image(85,28);
 tab_off[4].src = "../images/inactive_tab_set.png";
 for(var c=0; c < 5; c++) {
  div_id_num = "cell" + c + "_div";
  div_id = document.getElementById(div_id_num);
  if(c == cell_number) {
   document.images[tab_array[c]].src = tab_on[c].src;
   div_id.className = "cell_show";
   cell_label.innerHTML = tab_desc[c];
   if(c == 2) {
    var src_sel = document.getElementById("source_select");
    var src_div_err = document.getElementById("source_div_err");
    var src_div = document.getElementById("source_div");
    var tran_rad = "";
    for(var a=0; a < 3; a++) {
     if(document.show_info_form.compute[a].checked) {
     tran_rad = document.show_info_form.compute[a].value;
     }
    }
    if(tran_rad == "radiance") {
     src_div_err.className="cell_hide";
     src_div.className="cell_show";
     src_sel.disabled = false;
     source_change();
    }
    else {
     src_div_err.className="cell_show";
     src_div.className="cell_hide";
     src_sel.selectedIndex=0;
     src_sel.disabled = true;
    }
  } //end if c == 2
  else if(c == 4) {
   var user_status = document.getElementById("user_status").value;
   if(user_status == "on") {
    get_saved_calculations();
   }
   else {
    document.getElementById("saved_calc_div").innerHTML = "<font color='red'>Saved settings are only available to active subscribers.  Please login above, or <a href='../info/plans.php' target='_blank'>Subscribe</a><br>";
   } 
  } //end if c == 4
 } //end if c = cell_number
 else {
  document.images[tab_array[c]].src = tab_off[c].src;
  div_id.className = "cell_hide";
 }
 } //end for loop
} //end show_tab

function show_image(scenario_name) {
 document.getElementById("horizontal").border = 0;
 var scen_array = new Array("horizontal", "up", "down", "limb");
 var user_plan = document.getElementById("user_plan").value;
 var user_name = document.getElementById("user_name").value;
 user_name = user_name.toLowerCase();
 user_plan = user_plan.toUpperCase();
//this changes the border around the image.
   for(var i=0; i < scen_array.length; i++) {
    if(scen_array[i] != scenario_name) {
     document.getElementById(scen_array[i]).className = "scenNobdr";
    } //end if.
   }//end for.
   document.getElementById(scenario_name).className = "scenbdr";
   document.getElementById("which_scenario").value = scenario_name;
//   } //end if

 var option1_span = document.getElementById("option1");
 var option1a_span = document.getElementById("option1a");
 var option2_span = document.getElementById("option2");
 var option2a_span = document.getElementById("option2a");
 var option3_span = document.getElementById("option3");
 var option3a_span = document.getElementById("option3a");
 var tempSpan = document.getElementById("temp_offsetOpt");
 var tempSpan2 = document.getElementById("tempInput");
//change what shows up on the atmosphere tab based upon which scenario is selected.
 if(scenario_name == "horizontal") {
  option1_span.innerHTML = "";
  option1a_span.innerHTML = "&nbsp;";
  option2_span.innerHTML = "Observer Height&nbsp;";
  option2a_span.innerHTML = "<input id='option2_val' name='option2_val' value='0' size='12'>&nbsp;km";
  option3_span.innerHTML = "Path Length&nbsp;";
  option3a_span.innerHTML = "<input id='option3_val' name='option3_val' value='1' size='12'>&nbsp;km";
  tempSpan.innerHTML = "<a class='activate' onmouseover=className='activate_over'; onmouseout=className='activate'; onClick='popUp(event,\"temp_offset\")'>Temperature Offset</a>&nbsp;";
  tempSpan2.innerHTML = "<input id='temp_offsetVal' name='temp_offsetVal' value='0' size='12'>&nbsp;K";
 }
 else if(scenario_name == "limb") {
  option1_span.innerHTML = "";
  option1a_span.innerHTML = "&nbsp;";
  option2_span.innerHTML = "";
  option2a_span.innerHTML = "";
  option3_span.innerHTML = "<a href='../info/help.php#32' target='_blank' class='activate' onmouseover=className='activate_over'; onmouseout=className='activate'>Tangent Height</a>&nbsp;";
  option3a_span.innerHTML = "<input id='option3_val' name='option3_val' value='30' size='12'>&nbsp;km";
  tempSpan.innerHTML = "";
  tempSpan2.innerHTML = "";
 }
 else if(scenario_name == "up"){
  option1_span.innerHTML = "Observer Height&nbsp;";
  option1a_span.innerHTML = "<input id='option1_val' name='option1_val' value='0' size='12'>&nbsp;km";
  option2_span.innerHTML = "Target Height&nbsp;";
  option2a_span.innerHTML = "<input id='option2_val' name='option2_val' value='600' size='12'>&nbsp;km";
  option3_span.innerHTML = "Zenith Angle&nbsp;";
  option3a_span.innerHTML = "<input id='option3_val' name='option3_val' value='0' size='12'>&nbsp;degrees";
  tempSpan.innerHTML = "";
  tempSpan2.innerHTML = "";
} //end scenario == up
 else if(scenario_name == "down"){
  option1_span.innerHTML = "Observer Height&nbsp;";
  option1a_span.innerHTML = "<input id='option1_val' name='option1_val' value='600' size='12'>&nbsp;km";
  option2_span.innerHTML = "Target Height&nbsp;";
  option2a_span.innerHTML = "<input id='option2_val' name='option2_val' value='0' size='12'>&nbsp;km";
  option3_span.innerHTML = "Nadir Angle&nbsp;";
  option3a_span.innerHTML = "<input id='option3_val' name='option3_val' value='0' size='12'>&nbsp;degrees";
  tempSpan.innerHTML = "";
  tempSpan2.innerHTML = "";
 } //end scenario == up
 document.getElementById("opt1_err").innerHTML = ""; 
 document.getElementById("opt2_err").innerHTML = ""; 
 document.getElementById("opt3_err").innerHTML = ""; 
 document.getElementById("tempOS_err").innerHTML = ""; 
 document.getElementById("error_div").innerHTML = "";

}//end show_image


//calls a php file to get a list of gases and isotopes to display in the gas/isotope menus.
 function populate_cell_gases() {
 var gas_db = document.getElementById("calc_gas_db").value;
 var atmos = document.getElementById("atmosphere_name").value;
 var params = "&table_name=" + gas_db + "&plot_type=path&atmos=" + atmos;
 get_gas_http = getHTTPObject();
 try {
 get_gas_http.open("POST","../getListOfGases.php",true);
 }
catch (err) {
 get_gas_http.close;
 get_gas_http.open("POST","../getListOfGases.php",true);
 }
 get_gas_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 get_gas_http.setRequestHeader("Content-length", params.length);
 get_gas_http.setRequestHeader("Connection", "close");
 get_gas_http.onreadystatechange = handlePathGasList;
 get_gas_http.send(params);
} //end populate_cell_gases() function

//put the gas & isotope results in a select menu and put them in the correct spot on the page.
function handlePathGasList() {
if (get_gas_http.readyState == 4)  {
  var GasXMLDocument = get_gas_http.responseXML;
  var counter = 0;
  var mol_tag = GasXMLDocument.getElementsByTagName('molecules').item(0);
  var numMol = mol_tag.childNodes.length;
  var num_gases = GasXMLDocument.getElementsByTagName('num_gases').item(0).firstChild.data;
  var gas_menu = "";
  var iso_menu = "";
  var iso_tag = "";
  var numIso = 0;
  var temp_gas_id = "";
  var temp_gas_name = "";
  var temp_gas_formula = "";
  var iso_num = "";
  var iso_formula = "";
  var iso_out = "";
  var total_iso = GasXMLDocument.getElementsByTagName('ttl_is').item(0).firstChild.data;
  //populate the list of gases in the gas menus.
  for(var i=1; i<=num_gases; i++) {
   gas_menu = document.getElementById("gaslist_" + i);
   nullOptions(gas_menu);
   temp_gas_id = "";
   temp_gas_name = "";
   temp_gas_formula = "";
   with (gas_menu){
   options[0] = new Option("None", "None");
    for(var x=0; x<numMol; x++) {
     temp_gas_formula = mol_tag.getElementsByTagName("molecule").item(x).getAttribute("formula");
     temp_gas_id = mol_tag.getElementsByTagName("molecule").item(x).getAttribute("id");
     temp_gas_name = mol_tag.getElementsByTagName("molecule").item(x).firstChild.data;
     options[x+1] = new Option(temp_gas_formula,temp_gas_id);
     if(counter == x) {
      options[x+1].selected = true; 
     }
    } //end for x < num_gases_in_db
   } //end with 
   iso_tag = GasXMLDocument.getElementsByTagName("isotope" + i).item(0);
   numIso = iso_tag.childNodes.length;
   iso_menu = document.getElementById("isotope" + i);
   iso_num = "";
   iso_formula = "";
   iso_out = "";
   nullOptions(iso_menu);
   with (iso_menu){
   options[0] = new Option("All", "0");
    for(var q=0; q < numIso; q++) {
     iso_num = iso_tag.getElementsByTagName("isotope").item(q).getAttribute("number");
     iso_formula = iso_tag.getElementsByTagName("isotope").item(q).firstChild.data;
     iso_out = iso_num + "   " + iso_formula;
     options[q+1] = new Option(iso_out, iso_out);
    }
   } //end with that updates isotope menu.
    counter = counter + 1;
   } //end for i < num_gases
  if(num_gases < 6) { 
   var endiso = 6;
   if(total_iso < 6) {
    endiso = total_iso;
   }
   var ngpo = parseInt(num_gases) + 1;
   for(var z =ngpo; z <= endiso; z++) {
    gas_menu = document.getElementById("gaslist_" + z);
    nullOptions(gas_menu);   
    with (gas_menu){
     options[0] = new Option("None", "None");
     for(var x=0; x<numMol; x++) {
      temp_gas_formula = mol_tag.getElementsByTagName("molecule").item(x).getAttribute("formula");
      temp_gas_id = mol_tag.getElementsByTagName("molecule").item(x).getAttribute("id");
      temp_gas_name = mol_tag.getElementsByTagName("molecule").item(x).firstChild.data;
      options[x+1] = new Option(temp_gas_formula,temp_gas_id);
     } //end for x < num_gases_in_db
    } //end with
    iso_menu = document.getElementById("isotope" + z);
    nullOptions(iso_menu);
    with (iso_menu){
     options[0] = new Option("None", "None");
    }  //end with iso_menu
   }  //end for var z
   var tipo = parseInt(total_iso) + 1;
   for(var b=tipo; b <=6; b++) {
    gas_menu = document.getElementById("gaslist_" + b);
    nullOptions(gas_menu);
    with (gas_menu){
     options[0] = new Option("None", "None");
    } //end with gas_menu
    iso_menu = document.getElementById("isotope" + b);
    nullOptions(iso_menu);
    with (iso_menu){
     options[0] = new Option("None", "None");
    } //end with iso_menu
   } //end for var b

 } //end num_gases < 6
 
 } //end if readystate = 4 
} //end function handleGasList


//this function will reset all values to their default values
function reset_all() {
 document.show_info_form.compute[0].checked;
 document.getElementById("log_lin_box").checked = false;
 document.getElementById("source_select").selectedIndex = 0;
 document.getElementById("source_select").disabled = true;
 document.getElementById("source_temp").value = "300";
 document.getElementById("source_emissivity").value = "1"; 
 document.getElementById("calc_units").selectedIndex=0; 
 var span_txt = "<a onClick='popUp(event,\"wavenumber\")'><font color='blue'>cm<sup>-1</sup></font></a>";
 document.getElementById("calc_ll_unit").innerHTML = span_txt;
 document.getElementById("calc_ul_unit").innerHTML = span_txt; 
 document.getElementById("calc_iw_units").innerHTML = span_txt;
 document.getElementById("lower_bandpass").value = "2000";
 document.getElementById("upper_bandpass").value = "2010";
 document.getElementById("instr_width").value = "0.1";
 document.getElementById("instr_sel").selectedIndex = 0;
 document.getElementById("path_annotate").checked = true;
 document.getElementById("path_timestamp").checked = true;
 document.getElementById("ticks_box").checked = true;
 document.getElementById("calc_gas_db").selectedIndex = 0;
 document.getElementById("atmosphere_name").selectedIndex = 0;
 for(var s=1; s <=6; s++) {
  document.getElementById("scale" + s).value = "1.0";
 }
 change_atmos_list("earth", "none", "no");
 populate_cell_gases();
 show_image("horizontal");

} //end function reset_all

//this function will check the input values for known possible errors.
function check_for_errors(chk_action) {
 var out = "path_xml=<path_info>";
 var error = false;
 var err_str = "";
 var user_name = document.getElementById("user_name").value;
 var user_status = document.getElementById("user_status").value;
 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 atmosphere = document.getElementById("atmosphere_name").value;
 var db_table = document.getElementById("calc_gas_db").value;
 var scenario = document.getElementById("which_scenario").value;
 var bandpass_range = 5000;
 var tran_or_rad = "";
 for(var a=0; a < 3; a++) {
  if(document.show_info_form.compute[a].checked) {
  tran_or_rad = document.show_info_form.compute[a].value;
  }
 } 
 var units = document.getElementById("calc_units").value;
 var lower_limit = 0;
 var upper_limit = 0;
 var llmt = document.getElementById("lower_bandpass").value
 var ulmt = document.getElementById("upper_bandpass").value;
 var instr_func = document.getElementById("instr_sel").value;
 var i_w = document.getElementById("instr_width").value;
 var instr_width = 0;
 if(i_w.indexOf('+') != -1) {
  i_w = i_w.replace('+', "");
 } 
 //create a string of arguments to send to a php file 
 out+="<user_status>" + user_status + "</user_status><action>" + chk_action + "</action>";
 out+= "<user_name>" + user_name + "</user_name><r_addr>" + remote_addr + "</r_addr><r_host>" + remote_host + "</r_host><user_agent>" + user_agent + "</user_agent>";
 out+="<atmosphere>" + atmosphere + "</atmosphere><db_table>" + db_table + "</db_table><compute>" + tran_or_rad + "</compute><instr>" + instr_func + "</instr><IW>" + i_w + "</IW>";

 if(units == "microns") {
  if(llmt == 0) {
   out+= "<units>microns</units><LL>1e-6</LL><UL>" + ulmt + "</UL>";
  }
  else {
   out+= "<units>microns</units><LL>" + llmt + "</LL><UL>" + ulmt + "</UL>";
  }
 //if microns is being used, convert them to wavenumbers.
  var m1 = 10000/parseFloat(ulmt);
  var m2 = 10000/parseFloat(llmt);
  lower_limit = m1;
  upper_limit = m2;
  var temp1 = (parseFloat(ulmt) + parseFloat(llmt))/2;
  var temp2 = (10000/Math.pow(parseFloat(temp1),2))*parseFloat(i_w);
  instr_width = parseFloat(temp2);
  out+= "<CLL>" + lower_limit + "</CLL><CUL>" + upper_limit + "</CUL><CIW>" + instr_width + "</CIW>"; 
 }
 else  {
  lower_limit = llmt;
  upper_limit = ulmt;
  instr_width = i_w;  
  if(lower_limit == 0) {
  lower_limit = 1e-6;
   out+= "<units>" + units + "</units><LL>1e-6</LL><UL>" + upper_limit + "</UL>";
  }
  else {
   out+= "<units>" + units + "</units><LL>" + lower_limit + "</LL><UL>" + upper_limit + "</UL>";
  }
 }
 var up_min_low = parseFloat(upper_limit) - parseFloat(lower_limit);
 var lower_err = "none";
 var upper_err = "none";
  if((parseFloat(lower_limit) < 0) || (parseFloat(lower_limit) > 60000)) {
  err_str+= "<br>Lower Limit has to be greater than/equal to 0 cm<sup>-1</sup> and less than/equal to 60000 cm<sup>-1</sup>";
  lower_err = "error";
  error = true;
 } //end error checking for lower limit.
 if((parseFloat(upper_limit) < 0) || (parseFloat(upper_limit) > 60000)) {
  err_str+= "<br>Upper Limit has to be greater than/equal to 0 cm<sup>-1</sup> and less than/equal to 60000 cm<sup>-1</sup>";
  upper_err = "error";
 } //end error checking for lower limit.
 if(isNaN(parseFloat(upper_limit))) {
  err_str+= "<br>Upper Limit has to be a numeric value";
  upper_err = "error";
  error = true;
 }
 if(isNaN(parseFloat(lower_limit))) {
  err_str+= "<br>Lower Limit has to be a numeric value";
  lower_err = "error";
  error = true;
 }
 var min_diff = parseFloat(lower_limit)/10000;

 if((parseFloat(up_min_low) > parseInt(bandpass_range)) || (up_min_low < min_diff)) {
  error = true;
  lower_err = "error";
  upper_err = "error";
  err_str+= "<br>(Upper Limit - Lower Limit) has to be greater than/equal to " + min_diff + " cm<sup>-1</sup> and less than/equal to " + bandpass_range + " cm<sup>-1</sup>";
  err_str+="<br>Click <a href='../info/help.php#12' target='_blank'>here</a> for more information. ";
 }
 if(lower_err == "error") {
  document.getElementById("lower_div").innerHTML = "<font color='red'>X</font> Lower Limit";
 }
 else {
  document.getElementById("lower_div").innerHTML = "Lower Limit";
 } 
 if(upper_err == "error") {
  document.getElementById("upper_div").innerHTML = "<font color='red'>X</font> Upper Limit";
 }
 else {
  document.getElementById("upper_div").innerHTML = "Upper Limit";
 } 
  if(instr_func != "none") { //if instrument function is selected check width value.
  if((parseFloat(instr_width) < 0) || (parseFloat(instr_width) > 250) || (parseFloat(instr_width) > (parseFloat(up_min_low)/2))) {
   err_str+= "<br>Instrument width too large. Must be:<br>";
   err_str+= "&nbsp;&nbsp;&nbsp;*between 0 and 250 cm<sup>-1</sup><br>";
   err_str+= "&nbsp;&nbsp;&nbsp;*no more than 1/2 the wave band.<br>";   
   document.getElementById("width_div").innerHTML = "<font color='red'>X</font>&nbsp;Width";
   error = true;
  }
  else {
   document.getElementById("width_div").innerHTML = "Width";
  }
 }
//do error checking based upon which scenario is selected.
 out+="<scenario>" + scenario + "</scenario>";
 if(scenario == "horizontal") {
  var horiz_height = document.getElementById("option2_val").value;
  if((parseFloat(horiz_height) < 0) || (parseFloat(horiz_height) > 120) || (isNaN(parseFloat(horiz_height)))) {
   error = true;
   err_str+="<br>Observer Height has to be greater than/equal to 0 km and less/equal to than 120 km";
   document.getElementById("opt2_err").innerHTML = "<font color='red'>X </font>";
  }
  else {
   document.getElementById("opt2_err").innerHTML = ""; 
  }
  var horiz_distance = document.getElementById("option3_val").value;
  if((parseFloat(horiz_distance) <= 1e-6) || (parseFloat(horiz_distance) > 1000) || (isNaN(parseFloat(horiz_distance)))) {
   error = true;
   err_str+="<br>Path Length has to be greater than 1e-6 km and less than/equal to 1000 km";
   document.getElementById("opt3_err").innerHTML = "<font color='red'>X </font>";
  }
  else {
   document.getElementById("opt3_err").innerHTML = ""; 
  }
   var temp_offset = document.getElementById("temp_offsetVal").value;
  if((parseFloat(temp_offset) < -50) || (parseFloat(temp_offset) > 50) || (isNaN(parseFloat(temp_offset)))) {
     error = true;
   err_str+="<br>Temperature offset has to be greater/equal to than -50 K and less/equal to than 50K";
   document.getElementById("tempOS_err").innerHTML = "<font color='red'>X </font>";
  }
  else {
   document.getElementById("tempOS_err").innerHTML = ""; 
  }
  out+="<temp_offset>" + temp_offset + "</temp_offset>";
   out+="<height>" + horiz_height + "</height><distance>" + horiz_distance + "</distance>";
 } //end scenario = horizontal
 else if(scenario == "limb") {
  var tan_height = document.getElementById("option3_val").value;
   if((parseFloat(tan_height) <= 0) || (parseFloat(tan_height) > 119.999) || (isNaN(parseFloat(tan_height)))) {
    error = true;
    err_str+="<br>Tangent Height has to be greater than 0 km and less than 120 km";
    document.getElementById("opt3_err").innerHTML = "<font color='red'>X </font>";
   }
   else {
    out+="<tan_height>" + tan_height + "</tan_height>";
    document.getElementById("opt3_err").innerHTML = ""; 
   }
 }
 else if(scenario == "up") {
  var obs_hgt = document.getElementById("option1_val").value;
  var tar_hgt = document.getElementById("option2_val").value;
  var zen_ang = document.getElementById("option3_val").value;
  var h1_err = false;
  var h2_err = false;
  if((parseFloat(obs_hgt) < 0) || (parseFloat(obs_hgt) > 119) || (isNaN(parseFloat(obs_hgt)))) {
   error = true;
   h1_err = true;
   err_str+= "<br>Observer Height has to be greater than/equal to 0 km and less than/equal to 119 km.";
  }
  else {
   out+="<obs_hgt>" + obs_hgt + "</obs_hgt>";
  }
  if((parseFloat(tar_hgt) < 1) || (parseFloat(tar_hgt) > 1e9) || (isNaN(parseFloat(tar_hgt)))) {
    error = true;
    h2_err = true;
    err_str+="<br>Target Height has to be greater than/equal to 1 km and less than/equal to 1e9 km ";
  }
  else {
   out+="<tar_hgt>" + tar_hgt + "</tar_hgt>";
  }
  if((tar_hgt - obs_hgt) < 1) {
   error = true;
   h1_err = true;
   h2_err = true; 
   err_str+="<br>Target Height minus Observer Height has to be greater than/equal to 1 km.";
  }
  if(h1_err == true) {
   document.getElementById("opt1_err").innerHTML = "<font color='red'>X </font>";
   }
  else {
   document.getElementById("opt1_err").innerHTML = "";
  }
  if(h2_err == true) {
    document.getElementById("opt2_err").innerHTML = "<font color='red'>X </font>"; 
  }
  else {
    document.getElementById("opt2_err").innerHTML = "";
  }
 if((parseFloat(zen_ang) < 0) || (parseFloat(zen_ang) > 89.99) || (isNaN(parseFloat(zen_ang)))) {
   error = true;
   err_str+="<br>Zenith Angle has to be greater than/equal to 0 degrees and less than/equal to 89.99 degrees."; 
   document.getElementById("opt3_err").innerHTML = "<font color='red'>X </font>";
  }
  else {
   out+="<angle>" + zen_ang + "</angle>";
   document.getElementById("opt3_err").innerHTML = "";
  }
 } //end if scenario =up.
 else if(scenario == "down") {
  var obs_hgt = document.getElementById("option1_val").value;
  var tar_hgt = document.getElementById("option2_val").value;
  var nadir_ang = document.getElementById("option3_val").value;
  var h1_err = false;
  var h2_err = false;
  if((parseFloat(obs_hgt) < 1) || (parseFloat(obs_hgt) > 1e9) || (isNaN(parseFloat(obs_hgt)))) {
    error = true;
    h1_err = true;
    err_str+="<br>Observer Height has to be greater than/equal to 1 km and less than/equal to 1e9 km.";
  } 
  else {
   out+="<obs_hgt>" + obs_hgt + "</obs_hgt>";
  } 
  if((obs_hgt - tar_hgt) < 1) {
    error = true;
    h1_err = true;
    h2_err = true; 
    err_str+="<br>Observer Height minus Target Height has to be greater than/equal to 1 km.";
  }
  if((parseFloat(tar_hgt) < 0) || (parseFloat(tar_hgt) > 119.99) || (isNaN(parseFloat(tar_hgt)))) {
    error = true;
    h2_err = true;
    err_str+="<br>Target Height has to be greater than/equal to 0 km and less than to 120 km";
  }
  else {
  // if(tar_hgt < 1e-9) {tar_hgt = 1e-9; }
   out+="<tar_hgt>" + tar_hgt + "</tar_hgt>";
  }
  if(h1_err == true) {
   document.getElementById("opt1_err").innerHTML = "<font color='red'>X </font>";
   }
  else {
   document.getElementById("opt1_err").innerHTML = "";  
  }
  if(h2_err == true) {
    document.getElementById("opt2_err").innerHTML = "<font color='red'>X </font>"; 
  }
  else {
    document.getElementById("opt2_err").innerHTML = "";
  }
  var radius = 6356.0
  if(atmosphere == "Martian_Standard") {
   radius = 3376.0;
  }
  var na0 = (parseFloat(radius) - 5.0)/(parseFloat(radius) + parseFloat(obs_hgt));
  na0 = Math.asin(na0) * (180/Math.PI);
  if((parseFloat(nadir_ang) < 0) || (isNaN(parseFloat(nadir_ang)))) {
   error = true;
   err_str+="<br>Nadir Angle can not be negative.";
 //  err_str+="<br>The path does not intersect Earth. Please select a ";
   document.getElementById("opt3_err").innerHTML = "<font color='red'>X </font>";
  }
  else if(parseFloat(nadir_ang) > na0) {
   error = true;
   err_str+="<br>Nadir Angle can not exceed " + na0.toFixed(3) + " degrees from " + obs_hgt;
   err_str+=" km (This ensures the refracted ray hits the ground).";
   document.getElementById("opt3_err").innerHTML = "<font color='red'>X </font>";
  }
  else {
   nadir_ang = 180 - nadir_ang;
   out+="<angle>" + nadir_ang + "</angle>";
   document.getElementById("opt3_err").innerHTML = "";
  }
 } //end scenario = down.

 var gas = "";
 var iso_sub = "";
 var iso = "";
 var selInd = "";
 var scale_fac = "";
 var scale_str = "";
 var scale_err = "none";
 var gas_array = new Array();
 gas_array[0]="-1";
 var iso_array = new Array();
 var gas_err_array = new Array();
 iso_array[0]="-1;"
 gas_err_array[0]= "none";
 var gas_err = "none";
 var gas_err_div = "";
 var num_gases = 0;
 for(var i=1; i <=6; i++) {
  gas = document.getElementById("gaslist_" + i).value;
  gas_array[i] = gas;
  if(gas != "None") {
   num_gases++;
   scale_fac = document.getElementById("scale" + i).value;
   iso_sub = document.getElementById("isotope" + i).value;
   iso = iso_sub.substring(0,1);
   iso_array[i] = iso;
   selInd = document.getElementById("gaslist_" + i).selectedIndex;
   for(var m=1; m < i; m++) {
    if((gas_array[m] == gas) && (iso_array[m] == iso))   {
     gas_err_array[i] = "error";
     gas_err = "error";
     error = true;
    } //end if
    else  {
    gas_err_array[i] = "none";
    }
   } //end for loop
   gas_err_div = document.getElementById("gas" + i + "err");
   if(gas_err_array[i] == "error") {
    gas_err_div.innerHTML = "<font color='red'>X</font>";
   }
   else {
    gas_err_div.innerHTML = "";
   }
   out+= "<gas iso='" + iso + "' selInd='" + selInd + "' scale_fac='" + scale_fac + "'>"+ gas + "</gas>";
   scale_str = "scale" + i + "err";
   if((parseFloat(scale_fac) < 0) || (parseFloat(scale_fac) > 1000) || (isNaN(parseFloat(scale_fac)))) {
    document.getElementById(scale_str).innerHTML = "<font color='red'>X</font>";
    if(scale_err == "none") {
     err_str+="<br>Scale factor values must be greater than/equal to 0 and less than/equal to 1000.";
     scale_err = "error";
     error = true;
    }
   } //end if that checks scale_fac ranges
   else {
    document.getElementById(scale_str).innerHTML = "";
   } //end else.
  } //end if gas!= none
  else {
   gas_err_div = document.getElementById("gas" + i + "err");
   gas_err_div.innerHTML = "";
   iso_array[i] = "None";
   gas_err_array[i] = "none";
   out+= "<gas iso='none' selInd='0' scale_fac='1.0'>None</gas>";
  }
}//end for.
if(gas_err == "error") {
  err_str+= "<br>Duplicate Gas/Isotopologue combinations are not allowed<br>";
 }
out+="<num_gases>" + num_gases + "</num_gases>";
 var annotate = document.getElementById("path_annotate").checked;
  if(annotate == true) {
   out+= "<annotate>annotate</annotate>";
  }
  else {
   out+= "<annotate>noannotate</annotate>";
  }
 var ts = document.getElementById("path_timestamp").checked;
  if(ts == true) {
    out+= "<ts>timestamp</ts>";
  }
  else {
    out+= "<ts>notimestamp</ts>";
  }
 var ticks = document.getElementById("ticks_box").checked;
 if(ticks == true) {
  out+= "<plot_lp>sticks</plot_lp>";
 }
 else {
  out+= "<plot_lp>nosticks</plot_lp>";
 }
 //if radiance check the source tab info.
 var src_sel = document.getElementById("source_select").value;

 if(tran_or_rad == "radiance") {
  if(src_sel == "user_blackbody") {
   out+= "<blackbody>user_blackbody</blackbody>";
   var source_temp = document.getElementById("source_temp").value;
   if(source_temp.indexOf('+') != -1) {
    source_temp = source_temp.replace('+', "");
   }
   if((parseFloat(source_temp) < 0.1 ) || (parseFloat(source_temp) >20000) || (isNaN(parseFloat(source_temp)))) {
    document.getElementById("src_temp").innerHTML = "<font color='red'>X </font>Temperature";
    err_str+= "<br>Source temperature must be between 0.1K and 20000K";
    error = true;
   }
   else {
    document.getElementById("src_temp").innerHTML = "Temperature";
   }
   var source_emiss = document.getElementById("source_emissivity").value;
   if(source_emiss.indexOf('+') != -1) {
    source_emiss = source_emiss.replace('+', "");
   }
   if((parseFloat(source_emiss) <  0) || (parseFloat(source_emiss) >1) || (isNaN(parseFloat(source_emiss)))) {
    document.getElementById("src_emiss").innerHTML = "<font color='red'>X </font>Emissivity";
    err_str+= "<br>Source emissivity must be between 0 and 1";
    error = true;
   }
   else {
    document.getElementById("src_emiss").innerHTML = "Emissivity";
   }
  out+= "<source_temp>" + source_temp + "</source_temp><source_dopp>0</source_dopp><source_emm>" + source_emiss + "</source_emm>";

  } //end if src_sel = user_blackbody
  else if(src_sel == "noblackbody") {
  out+= "<blackbody>noblackbody</blackbody>";
  }
  else {
  out+= "<blackbody>default</blackbody>";
  }
}//end if tran_or_rad = radiance.  
else{
 out+= "<blackbody>noblackbody</blackbody>";
 } //end else
 var log_lin = document.getElementById("log_lin_box").checked;
 if(log_lin == true) {
  out+= "<log_lin>log</log_lin>";
 }
 else {
  out+= "<log_lin>nolog</log_lin>";
 }
 var user_plan = document.getElementById("user_plan").value;
 out+="<which_exec>public</which_exec>";

 out+="</path_info>";
 if(error == true) {
  document.getElementById("error_div").innerHTML = "<font color='red'><b>ERRORS:</b> " + err_str + "</font><br>";
 }
 else {
  document.body.style.cursor = 'wait';
  document.getElementById("path_submit").disabled = true;
  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>";
  div1.innerHTML = "";
  div1.innerHTML = div_string;
  document.getElementById("error_div").innerHTML = "";
  var exec_src = "make_atmos_plot.php";
  if(scenario != "horizontal") {
   exec_src = "make_udl_plot.php";
  }
  get_plot_http = getHTTPObject();
  get_plot_http.open("POST", exec_src, true);
  get_plot_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  get_plot_http.setRequestHeader("Content-length", out.length);
  get_plot_http.setRequestHeader("Connection", "close");
  get_plot_http.onreadystatechange = handlePlotResults;
  get_plot_http.send(out);
 }
} //end function check_for_errors
//show the results.
function handlePlotResults() {
 if(get_plot_http.readyState == 4) {
 document.body.style.cursor = 'default';
 document.getElementById("path_submit").disabled = false;
 var div1= document.getElementById("progress_div");
 div1.innerHTML = "";
 var graph_div = document.getElementById("display_graph");
 var plot_xml = get_plot_http.responseXML;
 var plot_action = plot_xml.getElementsByTagName("which_action").item(0).firstChild.data;
  if(plot_action == "genXML") {
  var fn = plot_xml.getElementsByTagName('fn').item(0).firstChild.data;
  var fnstr = "xml_files/" + fn + ".xml";
  window.open(fnstr);
 }
 else {
  var calc_err = plot_xml.getElementsByTagName("ERROR").item(0).firstChild.data;
  var fn = plot_xml.getElementsByTagName("fn").item(0).firstChild.data;
  var plot_units = plot_xml.getElementsByTagName("plot_units").item(0).firstChild.data;
  var ptype = plot_xml.getElementsByTagName("ptype").item(0).firstChild.data;
  var ex_str = "";
  var scenr = plot_xml.getElementsByTagName("scenario").item(0).firstChild.data;
  var time_key = plot_xml.getElementsByTagName("L_ID").item(0).firstChild.data;
  var out_str = "";
  if(calc_err == "none") {
   ex_str = plot_xml.getElementsByTagName("ex").item(0).firstChild.data;
   out_str = "<br><img src='plots/" + fn + ".png'><br><br>";
   out_str+= "<font color='blue'><u><a onClick=\"generate_PsPdf_files('" + ex_str + "', '" + scenr + "', '" + fn + "', 'ps')\">Generate Postscript</a></u></font>&nbsp;&nbsp;&nbsp;&nbsp;";
   out_str+= "<font color='blue'><u><a onClick=\"generate_PsPdf_files('" + ex_str + "', '" + scenr + "', '" + fn + "', 'pdf')\">Generate PDF</a></u></font>\n";
   remain_days = plot_xml.getElementsByTagName('remain_days').item(0).firstChild.data;
   var txt_size = plot_xml.getElementsByTagName('fsz').item(0).firstChild.data;
   if(plot_units == "microns") { //if the calculation was done in microns, show the converted microns file.
    out_str+= "&nbsp;&nbsp;&nbsp;&nbsp;<a href='plots/" + fn + "_microns.txt' target='_blank' onmouseover=\"popUp(event,'ascii')\" onmouseout=\"popUp(event,'ascii')\">Text File (" + txt_size + ")</a>\n";
   } //end units = microns
   else {
   out_str+= "&nbsp;&nbsp;&nbsp;&nbsp;<a href='plots/" + fn + ".txt' target='_blank' onmouseover=\"popUp(event,'ascii')\" onmouseout=\"popUp(event,'ascii')\">Text File (" + txt_size + ")</a>\n";
   } //end else
   out_str+= "&nbsp;&nbsp;&nbsp;&nbsp;<font color='blue'><u><a onClick='window.open(\"../print.php?fn=" + fn + "&tool=atmospheric_paths&units=" + plot_units +"\")' onmouseover=\"popUp(event,'print')\" onmouseout=\"popUp(event,'print')\">Print</a></u></font>";
   out_str+= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='blue'><u><a onClick=\"save_profile('save', '" + time_key + "');\">Save setup</a></u></font>";
   out_str+= "&nbsp;&nbsp;&nbsp;&nbsp;<font color='blue'><u><a onClick=\"save_spectra('save', '" + fn + "', '" + time_key  + "', '" + ptype +  "', 'atmospheric_paths');\">Save Spectra</a></u></font>\n";
   out_str+="<br><div id='prof_info_" + time_key + "'></div>\n";
   out_str+="<br><span id='ps_pdf_file" + fn + "'></span>\n";
   if(remain_days < 0) {
    document.getElementById("user_status").value = "limited_reg";
    } //end if
   graph_div.innerHTML = out_str + "<BR><BR>" + graph_div.innerHTML ;
  } //end calc_err= none
  else if (calc_err == "no_lines") {
   out_str = "<br><br><font color='ff0000'>Error: No absorption lines were found in this spectral bandpass for these molecules.<br>Please choose different molecules or adjust your bandpass limits.<br><br></font>\n";
   graph_div.innerHTML = out_str + "<BR><BR>" + graph_div.innerHTML ;
  } //end else if calc_err = no_lines
  else if(calc_err == "ref_tang_alt") {
   out_str = "<br><br><font color='ff0000'>Error: The refracted tangent height is < 0.<br>Please click ";
   out_str+="<a href='../info/help.php#32' target='_blank'>here</a> for more information.<br><br></font>\n";
   graph_div.innerHTML = out_str + "<BR><BR>" + graph_div.innerHTML ;
  }
  else if (calc_err == "too_many_pts") {
   var req_pts = plot_xml.getElementsByTagName('req_pts').item(0).firstChild.data;
   var allow_pts = plot_xml.getElementsByTagName('allow_pts').item(0).firstChild.data;
   out_str = "<br><br><font color='ff0000'>Error: Spectrum requires " + req_pts + " points, exceeding " + allow_pts + " point limit.<br>";
   out_str+="Please adjust waveband, pressure, or other parameters to reduce the spectrum size.<br>Click <a href='../info/help.php#29' target='_blank'>here</a> for more details.";
   graph_div.innerHTML = out_str + "<BR><BR>" + graph_div.innerHTML ;
  }//end else too_many_pts
  else if(calc_err == "vmr_err") {
   var ttlVMRerr = plot_xml.getElementsByTagName('sumExceedsOne').item(0).firstChild.data;
   var indivVMRerr = plot_xml.getElementsByTagName('indivErr').item(0).firstChild.data;
   out_str = "<font color='ff0000'>Error: ";
   if(ttlVMRerr == "true") {
    out_str+="The sum of the VMR values exceeds one.<br> ";
   }
   if(indivVMRerr == "true") {
    var num_errs = plot_xml.getElementsByTagName('numErrs').item(0).firstChild.data;
    var this_err = "";
    out_str+="The following gases have a VMR value that exceed one: ";
    for(var v=0; v<num_errs; v++) { //for each error, show the forumla with the problem on the browser.
     this_err = plot_xml.getElementsByTagName('vmrErr').item(v).firstChild.data;
     out_str+="<BR>" + this_err;
    }
   } //end if indivVMRerr == true.
    out_str+="<BR>Click <a href='../info/paths_user_guide.html#scale_factor' target='_blank'>here</a> for more information.<br>";
   graph_div.innerHTML = out_str + "</font><BR><BR>" + graph_div.innerHTML ;
  } //end else if calc_err == vmr_exceeds one.
 } //end else.
} //end ready state = 4
} //end function.

//this function will change the number of gases that are not set to 'none'
function chg_num_gases() {
 var num_gases_in_ll = document.getElementById("gaslist_1").length;
 num_gases_in_ll = parseInt(num_gases_in_ll) - 1;
 var num_gases_sel = document.getElementById("num_path_gases").value;
 num_gases_sel++;
 for(var i=num_gases_sel; i <=6; i++) {
  document.getElementById("gaslist_" + i).selectedIndex = 0;  
 }
 for(var z = 1; z < num_gases_sel; z++) {
  if(z <= num_gases_in_ll) {
   document.getElementById("gaslist_" + z).selectedIndex = z;  
  }
  else {
   document.getElementById("gaslist_" + z).selectedIndex = 0;
 }
 }
}

//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=paths&r_addr=" + remote_addr;
 saved_http2 = getHTTPObject();
 saved_http2 = getHTTPObject();
 saved_http2.open("POST", "../last_calc.php", true);
 saved_http2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 saved_http2.setRequestHeader("Content-length", out.length);
 saved_http2.setRequestHeader("Connection", "close");
 saved_http2.onreadystatechange = load_prof_result;
 saved_http2.send(out);
}  //load_last_calc


function load_prof(num_prof) {
 var p2 = "";
 for(var i=0; i < num_prof; i++)
 {
  p2 = document.getElementById("prof_rad" + i);
  if(p2.checked == true)
  {
   document.getElementById("prof_load_" + i).innerHTML = "<font color='red'>Loading...</font>";
   var saved_params = "tool=paths&audId=" + p2.value + "&action=load&load_num=" + i; 
   saved_http2 = getHTTPObject();
   saved_http2.open("POST", "../saved_calcs.php", true); 
   saved_http2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   saved_http2.setRequestHeader("Content-length", saved_params.length);
   saved_http2.setRequestHeader("Connection", "close");
   saved_http2.onreadystatechange = load_prof_result;
   saved_http2.send(saved_params);
  }
  else {
     document.getElementById("prof_load_" + i).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;";
  }
 }
} //end function load_prof


//this function is used to load a saved calculation or the last calculation the user performed.
//it repopulates the page with the stored values.
function load_prof_result() {
 if(saved_http2.readyState == 4) {
  var prof_xml = saved_http2.responseXML;
  var prof_act = prof_xml.getElementsByTagName("cact").item(0).firstChild.data;
  var num_prof = 1;
  var load_num = 0;
  var scenario = "";
  if(prof_act == "loadprof") {
   num_prof = prof_xml.getElementsByTagName('num_prof').item(0).firstChild.data;
   load_num = prof_xml.getElementsByTagName('load_num').item(0).firstChild.data;
   scenario = prof_xml.getElementsByTagName('scenario').item(0).firstChild.data;
   show_image(scenario);
  }
  else if(prof_act == "lastload") {
   var calc_ext = prof_xml.getElementsByTagName('calc').item(0).firstChild.data;
   if(calc_ext == "None") {
    num_prof = 0;
    populate_cell_gases(); 
   }
   else {
    scenario = prof_xml.getElementsByTagName('scenario').item(0).firstChild.data;
    show_image(scenario);
   }
  }
  if(num_prof > 0) {
   var db_table = prof_xml.getElementsByTagName('db_table').item(0).firstChild.data;   
   var db_list = document.getElementById("calc_gas_db");
   for(var d=0; d < db_list.length; d++) {
   if(db_list[d].value == db_table) {
     db_list.selectedIndex = d;
     break;
    }
   }
   var saved_atmosphere =  prof_xml.getElementsByTagName('atmosphere').item(0).firstChild.data;
   if(saved_atmosphere == "Martian_Standard") {
   change_atmos_list("mars", "none", "no");
   }
   else {
   change_atmos_list("earth", saved_atmosphere, "no");
   }
   var mol_tag = prof_xml.getElementsByTagName('molecule');
   var mol_id = "";
   var mol_form = "";
   var ml = "";
   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;
   } //end for var = w
   var mstr = "";
   var z2 = 0;
   for(var z=0; z < 6; z++)
   {
    z2 = z +1;
    mstr = "gaslist_" + z2;
    ml = document.getElementById(mstr);
    nullOptions(ml);
    with (ml){
     options[0] = new Option("None", "None");
     for (var v = 0; v < mol_tag.length; v++) {
      options[v+1] = new Option(mol_Farray[v],mol_Iarray[v]);
     }
    } //end with
   } //end for var=z 
   var gas_tag = prof_xml.getElementsByTagName('gas');
   var gas_iso = "";
   var gas_scale_fac = "";
   var g2 = 0;
   var q2 = 0;
   var iso_tag = "";
   var iso_tag2 = "";
   var iso_form = "";
   var iso_id = "";
   for(var q=0; q < gas_tag.length; q++) {
    gas_iso = gas_tag.item(q).getAttribute("iso");
    gas_scale_fac = gas_tag.item(q).getAttribute("scale_fac");
    q2 = q +1;
    document.getElementById("scale" + q2).value = gas_scale_fac;
    g2 = gas_tag.item(q).getAttribute("selInd"); 
    isostr2 = "iso" + q;
    iso_tag = prof_xml.getElementsByTagName(isostr2);
    var list_menu = document.getElementById("isotope" + q2);
    nullOptions(list_menu);
    with (list_menu){    
    if(gas_iso == "none") {
     options[0] = new Option("None", "None");
    }
    else {
    var istr = "";
    options[0] = new Option("All", "0");
    for(var f=0; f < iso_tag.length; f++) {
     iso_form = iso_tag.item(f).getAttribute("formula");
     iso_id = iso_tag.item(f).firstChild.data;
     istr = iso_id + "    " + iso_form;
     options[f+1] = new Option(istr, iso_id);
     } //end for
    } //end else
   } //end with 
    if(q < mol_tag.length){
     document.getElementById("gaslist_" + q2).selectedIndex = g2;
     document.getElementById("isotope" + q2).selectedIndex = gas_iso;   
    }
   } //end for loop
   var compute = prof_xml.getElementsByTagName('compute').item(0).firstChild.data;
   var log_lin = prof_xml.getElementsByTagName('log_lin').item(0).firstChild.data;
   if(log_lin == "nolog") {
    document.getElementById("log_lin_box").checked = false;
   } 
   else {
    document.getElementById("log_lin_box").checked = true;
   }
   if(compute == "transmission") {
    document.show_info_form.compute[0].checked = true;
   }
   else if (compute == "absorption") {
    document.show_info_form.compute[1].checked = true;
   }
   else {
    document.show_info_form.compute[2].checked = true;
    var blackbody = prof_xml.getElementsByTagName('blackbody').item(0).firstChild.data;
    document.getElementById("source_select").disabled = false;
    if(blackbody == "default") {
     document.getElementById("source_select").selectedIndex = 0;
     source_change();
    }
    else if(blackbody == "noblackbody") {
     document.getElementById("source_select").selectedIndex = 2;
     source_change();
    }
    else {
     document.getElementById("source_select").selectedIndex = 1;
     source_change();
     var bb_temp = prof_xml.getElementsByTagName("source_temp").item(0).firstChild.data;
     var bb_ems = prof_xml.getElementsByTagName("source_emm").item(0).firstChild.data;
     document.getElementById("source_temp").value = bb_temp;
     document.getElementById("source_emissivity").value = bb_ems; 
    }
   } //end else compute != transmission
   var units = prof_xml.getElementsByTagName('units').item(0).firstChild.data;  
   var span_txt = "";
   if(units == "wavenumber") {
    document.getElementById("calc_units").selectedIndex=0; 
    span_txt = "<a onClick='popUp(event,\"wavenumber\")'><font color='blue'>cm<sup>-1</sup></font></a>";
   }
   else {
    document.getElementById("calc_units").selectedIndex=1;
    span_txt = "&#181;m";
   }
   document.getElementById("calc_ll_unit").innerHTML = span_txt;
   document.getElementById("calc_ul_unit").innerHTML = span_txt; 
   document.getElementById("calc_iw_units").innerHTML = span_txt;
   var ll = prof_xml.getElementsByTagName('LL').item(0).firstChild.data;
   document.getElementById("lower_bandpass").value = ll;
   var ul = prof_xml.getElementsByTagName('UL').item(0).firstChild.data;  
   document.getElementById("upper_bandpass").value = ul;
   var iw = prof_xml.getElementsByTagName('IW').item(0).firstChild.data; 
   document.getElementById("instr_width").value = iw;
   var instr_val = prof_xml.getElementsByTagName('instr').item(0).firstChild.data; 
   if(instr_val == "none") {
    document.getElementById("instr_sel").selectedIndex = 0;
   }
   else if(instr_val == "sinc") {
    document.getElementById("instr_sel").selectedIndex = 1;   
   }
   else if(instr_val == "triangle"){
    document.getElementById("instr_sel").selectedIndex = 2;   
   }
   else if(instr_val == "square"){
    document.getElementById("instr_sel").selectedIndex = 3;   
   }   
   else if(instr_val == "gaussian"){
    document.getElementById("instr_sel").selectedIndex = 4;   
   }   
   var num_gases = prof_xml.getElementsByTagName('num_gases').item(0).firstChild.data;  
   var annotate = prof_xml.getElementsByTagName('annotate').item(0).firstChild.data;  
   if(annotate == "annotate") {
    document.getElementById("path_annotate").checked = true;
   }
   else {
    document.getElementById("path_annotate").checked = false;
   }
   var ts = prof_xml.getElementsByTagName('ts').item(0).firstChild.data;  
   if(ts == "timestamp") {
    document.getElementById("path_timestamp").checked = true;
   }
   else {
    document.getElementById("path_timestamp").checked = false;
   }
   var plot_lp = prof_xml.getElementsByTagName('plot_lp').item(0).firstChild.data;  
   if(plot_lp == "sticks") {
    document.getElementById("ticks_box").checked = true;
   }
   else {
    document.getElementById("ticks_box").checked = false;
   }
   if(scenario == "horizontal") {
    var saved_height = prof_xml.getElementsByTagName('height').item(0).firstChild.data;
    document.getElementById("option2_val").value = saved_height;

    var saved_distance = prof_xml.getElementsByTagName('distance').item(0).firstChild.data;
    document.getElementById("option3_val").value = saved_distance;
    var saved_offset =prof_xml.getElementsByTagName('temp_offset').item(0).firstChild.data;
    document.getElementById("temp_offsetVal").value = saved_offset;
    } //end scenario = horizontal
    else if(scenario == "down") {
     var obs_hgt = prof_xml.getElementsByTagName('obs_hgt').item(0).firstChild.data;
     var tar_hgt = prof_xml.getElementsByTagName('tar_hgt').item(0).firstChild.data;
     var nadir = prof_xml.getElementsByTagName('angle').item(0).firstChild.data;
     nadir = 180 - nadir;
     document.getElementById("option1_val").value = obs_hgt;
     document.getElementById("option2_val").value = tar_hgt;
     document.getElementById("option3_val").value = nadir;
    }
    else if (scenario == "up") {
     var obs_hgt = prof_xml.getElementsByTagName('obs_hgt').item(0).firstChild.data;
     var tar_hgt = prof_xml.getElementsByTagName('tar_hgt').item(0).firstChild.data;
     var zen_ang = prof_xml.getElementsByTagName('angle').item(0).firstChild.data;
     document.getElementById("option1_val").value = obs_hgt;
     document.getElementById("option2_val").value = tar_hgt;
     document.getElementById("option3_val").value = zen_ang;

    }
    else if (scenario == "limb") {
     var tan_height = prof_xml.getElementsByTagName('tan_height').item(0).firstChild.data;
     document.getElementById("option3_val").value = tan_height;
    }
   if(prof_act == "loadprof") {
    document.getElementById("prof_load_" + load_num).innerHTML = "<font color='red'>Loaded</font>";
   }
  }
  else {
   if(prof_act == "loadprof") { 
    window.alert("An error has occurred, please load the setting again.");
   } //end if.
  } //end else.
 }
} //end function.

//this function will change the values in the drop down menu for the atmospheres based upon whether
//the user selects the Earth or Mars planet.
function change_atmos_list(planet, selected_atmos, populate_gases) {
 var atmos_menu = document.getElementById("atmosphere_name");
 nullOptions(atmos_menu);
 if(planet == "earth") {
  document.getElementById("Mars").className = "scenNobdr";
  document.getElementById("Earth").className = "scenbdr";
   with (atmos_menu){
    options[0] = new Option("US_Standard", "US_Standard");
    options[1] = new Option("Midlatitude_Summer", "Midlatitude_Summer");
    options[2] = new Option("Midlatitude_Winter", "Midlatitude_Winter");
    options[3] = new Option("Polar_Summer", "Polar_Summer");
    options[4] = new Option("Polar_Winter", "Polar_Winter");
    options[5] = new Option("Tropical", "Tropical");
  }
  if(selected_atmos != "none") {
   document.getElementById("atmosphere_name").value = selected_atmos;
 }
 }
 else if(planet == "mars"){
  document.getElementById("Mars").className = "scenbdr";
  document.getElementById("Earth").className = "scenNobdr";
   with (atmos_menu){
    options[0] = new Option("Martian_Standard", "Martian_Standard");
   }
 }
 if(populate_gases == "yes") {
  populate_cell_gases();
 }

//   } //end if
}