/* *********************************************************
** JSDATA.JS - JS Client-Side Database Library
** ===========================================
** This library contains JS code and data to power the
** JS Client-Side Database demo presented in the 4/2000 
** JS ScriptHead column. It is loaded into the demo HTML
** document, jsdata.html, with the line:
**
** <script src="xjsdata.js" language="javascript"></script>
**
** Author      Ver  Date      Comments
** ======      ===  ====      ========
** Rick Scott  1.0  4/1/2000  First release
**
** Copyright 2000, Rick Scott, all rights reserved.
********************************************************* */


/* ********************************************************* 
** Script() - Script object constructor function
** ========
** Script() creates a Script object (database record) for 
** each ScriptHead script in the demo. Here's its syntax:
**
** var scriptObj = new Script(name,url, type, description)
**  name - the script name (string)
**   url - the absolute or relative script URL (string)
**   type -  the script subject (string)
**     this demo supports topics: "image archive",
**       "historical data", "global warming",
**       "ozone depletion",  "severe weather", "El nino-La nina"
**   description - brief summary of the website (string)
********************************************************* */

function Script(name,url,type,description)
  {
  this.name = name;      // script name property (string)
  this.url =url;        // script URL property (string)
  this.type = type;      // script type property (string)
  this.description = description;    // script description property (string)
   }


/* *********************************************************
** scripts - array of Script objects for this demo
** =======
** count automates indexing of scripts[], enabling
** you to safely insert new scripts between existing ones
** ****************************************************** */

var scripts = new Array();
var count = -1;

// ScriptHead Script objects

scripts[++count] = new Script(
  "Climate Change and Amphibian Population",
  "http://www.nature.com/cgi-taf/DynaPage.taf?file=/nature/journal/v410/n6829/full/410639a0_fs.html",
  "global_warming",
  "Climate-induced reduction in water depth and amphibian embryo mortality"
     );

scripts[++count] = new Script(
   "Climate Change 2001: Impacts, Adaptation and Vulnerability",
   "http://www.ipcc.ch/pub/spm19-02.pdf",
   "global_warming",
   "Summary of IPCC report on the effect of global warming on different countries and regions (February 2001)" 
     );

scripts[++count] = new Script(
  "Preparing for a Changing Climate",
  "http://www.essc.psu.edu/mara/results/foundations_report/index.html#report",
  "global_warming",
  "Potential consequences of climate change in the Mid-Atlantic region (January 2001)"
      );

scripts[++count] = new Script(
  "Climate Change in the Himalyas",
  "http://www.eurekalert.org/pub_releases/2000-09/OSU-Hicr-1409100.php",
  "global_warming",
  "Himalyan ice cores reveal last 50 years were the warmest in the last 1,000 years (September 2000)"
      );

scripts[++count] = new Script(
  "Global Warming and Terrestrial Biodiversity Decline",
  "http://panda.org/resources/publications/climate/speedkills/",
  "global_warming",
  "A World Wildlife Fund study of the effect of global warming on species distribution (August 2000)"
      );

scripts[++count] = new Script(
  "IPCC Publications",
  "http://www.ipcc.ch/pub/reports.htm",
  "global_warming",
  "Full summaries of reports of the Intergovernmental Panel on Climate Change"
      );

scripts[++count] = new Script(
  "Global Climate Change",
  "http://www.med.harvard.edu/chge/globalcc-v2n1.htm",
  "global_warming",
  "Summaries and full reviews of evidence of global warming and its observed consequences (October 30, 2000)"
      );

scripts[++count] = new Script(
  "Greenland's Thinning Coastal Ice",
  "ftp://ftp.hq.nasa.gov/pub/pao/pressrel/2000/00-112.txt",
  "global_warming",
  "A NASA study shows thinning in some places exceeding 3 feet a year(July 2000)"
	);

scripts[++count] = new Script(
  "Global Warming:It's Happening",
  "http://www.naturalscience.com/ns/articles/01-09/ns_ket.html",
  "global_warming",
  "Climate change researcher answers the skeptics  (December 1997)"
	);

scripts[++count] = new Script(
  "Adequacy of Climate Observing Systems",
  "http://www.nap.edu/books/0309063906/html/",
  "global_warming",
  "Online book evaluates systems for observing climate change (1999)"
	);
scripts[++count] = new Script(
  "Hot Nights in the City",
  "http://www.edf.org/pubs/Reports/HotNY/index.html",
  "global_warming",
  "Global warming, sea-level rise, and the New York metropolitan region (June 1999)"
	);
scripts[++count] = new Script(
  "Climate Change and Weather Extremes",
  "http://www.ncdc.noaa.gov/ol/climate/climateextremes.html",
  "global_warming",
  "Events, Reports, Publications; Data, Images, Climatology; from NOAA"
	);
scripts[++count] = new Script(
  "Climate of 1997",
  "http://www.ncdc.noaa.gov/ol/climate/research/1997/climate97.html",
  "global_warming",
  "1997--warmest year of century according to both land and ocean surface readings"
	);

scripts[++count] = new Script(
  "Climate of 1998",
  "http://www.wmo.ch/",
  "global_warming",
  "1998 warmest year since 1860 when record collecting started, according to the World Meteorological Organization. Click on Public Info, WMO Statements & Announcements and on December 17, 1998 Press Release"
	);

scripts[++count] = new Script(
  "Climate of 1999",
  "http://www.ncdc.noaa.gov/ol/climate/research/1999/ann/ann99.html",
  "global_warming",
  "Annual review from the National Climatic Data Center"
	);

scripts[++count] = new Script(
  "The Science of Global Warming",
  "http://www.ucsusa.org/environment/gw.science.html",
  "global_warming",
  "Fact sheet from the Union of Concerned Scientists"
	);

scripts[++count] = new Script(
  "Statement Concerning Global Warming",
  "http://www.senate.gov/~epw/105th/lind0710.htm",
  "global_warming",
  "Presented by MIT professor Richard S. Lindzen to the US Senate Committee on Environment and Public Works (1997)"

	);
scripts[++count] = new Script(
  "Severe Weather and Global Warming",
  "http://www.nationalcenter.org/NPA206.html",
  "global_warming",
  "	Incidents of severe weather  unrelated to global warming, according to David Ridenour of the National Center for Public Policy Research (1998)"
	);

scripts[++count] = new Script(
  "Climate Change--Canada",
  "http://climatechange.gc.ca/english/index.shtml",
  "global_warming",
  "	Links to information from Canadian sources"
	);

scripts[++count] = new Script(
  "EPA's Global Warming Website",
  "http://www.epa.gov/globalwarming/publications/index.html",
  "global_warming",
  "Environmental Protection Agency's publications, reports, position papers, reference material, information sheets, EPA Conference Reports"
	);

scripts[++count] = new Script(
  "Impact of Climate Change",
  "http://www.gcrio.org/NationalAssessment/",
  "global_warming",
  "Foundation Document details the likely consequences of climate change for each section of the United States"
	);

scripts[++count] = new Script(
  "Record Low Ozone Level",
  "http://www.niwa.cri.nz/mr/oct2%5F00.htm",
  "ozone_depletion",
  "Record low value of 124 Dobson Units recorded in stratosphere above Scott Base in Antarctica (Oct. 2000)"
	);
scripts[++count] = new Script(
  "Antarctic Ozone Bulletin /2000",
  "http://www.wmo.ch/web/arep/00/ozbull3.html",
  "ozone_depletion",
  "Issued by the World Meteorological Organization, bulletin describes unusually large ozone hole for early September (Sept. 2000)"
	);

scripts[++count] = new Script(
  "Understanding Ozone Depletion",
  "http://www.ucsusa.org/resources/index.html",
  "ozone_depletion",
  "Scientific overview, detailed explanation, and policy considerations; updates. Click on Environmental Connections"
	);

scripts[++count] = new Script(
  "Stratospheric Ozone: Winter Bulletins",
  "http://www.cpc.ncep.noaa.gov/products/stratosphere/winter_bulletins/index.html",
  "ozone_depletion",
  "Summaries of ozone levels for the northern and southern hemispheres"
	);
scripts[++count] = new Script(
  "Daily Ozone Readings",
  "http://jwocky.gsfc.nasa.gov/index.html",
  "ozone_depletion",
  "Data  from the stratosphere above almost any spot on earth; history of  changes in the ozone hole over Antarctica"
	);
scripts[++count] = new Script(
  "Stratospheric Ozone over the Arctic",
  "http://www.alaska.net/~nwsar/html/sat/ozone.html",
  "ozone_depletion",
  "Recent ozone readings from Earth Probe TOMS"
	);
scripts[++count] = new Script(
  "Ozone Levels over Europe",
  "http://auc.dfd.dlr.de/GOME/latest_europa.html",
  "ozone_depletion",
  "Color-coded map of ozone content of column section of  the atmosphere"
	);

scripts[++count] = new Script(
  "Pacific Decadal Oscillation",
  "http://tao.atmos.washington.edu/pdo/",
  "El_niņo-La_niņa",
  "Discussion, data and key references about another pattern found in long-term Pacific climate variability"
	);

scripts[++count] = new Script(
  "El Niņo Preparedness",
  "http://www.esig.ucar.edu/un/enFinal.pdf",
  "El_niņo-La_niņa",
  "Lessons learned from the 1997-98 El Niņo, according to a panel of United Nations scientists"
	);
scripts[++count] = new Script(
  "Climate Variability and El Niņo",
  "http://www.bom.gov.au/climate/glossary/elnino/elnino.shtml",
  "El_niņo-La_niņa",
  "The El Niņo phenomenon from an Australian perspective"
	);
scripts[++count] = new Script(
  "El Niņo-Southern Oscillation",
  "http://www.ogp.noaa.gov/enso/#Status",
  "El_niņo-La_niņa",
  "NOAA's rich compilation of data, including the current status of El Niņo/La Niņa and its long-term impact on the US climate"
	);
scripts[++count] = new Script(
  "Impact of El Niņo",
  "http://www.pmel.noaa.gov/toga-tao/el-nino/impacts.html#part5b",
  "El_niņo-La_niņa",
  "Links to studies of El Niņo's climatological and biological effects"
	);
scripts[++count] = new Script(
  "El Niņo Facts",
  "http://www.usc.edu/go/seagrant/elnino/",
  "El_niņo-La_niņa",
  "Brief, clear description"
	);

scripts[++count] = new Script(
  "Lightning Occurrence",
  "http://www.nwstc.noaa.gov/d.MET/Lightning/climo.htm",
  "severe_weather",
  "Lightning flash density in North America for years 1992-1995"
	);

scripts[++count] = new Script(
  "Nature's Greatest Storms",
  "http://hurricanes.noaa.gov/",
  "severe_weather",
  "NOAA's hurricane page: latest news, resources, background, links"
	);
scripts[++count] = new Script(
  "FAQ's about Tropical Storms",
  "http://www.aoml.noaa.gov/hrd/tcfaq/tcfaqHED.html",
  "severe_weather",
  "Answers to frequently asked questions about hurricanes, typhoons, and tropical cyclones"
	);
scripts[++count] = new Script(
  "Tornadoes--Nature's Most Violent Storms",
  "http://www.nws.noaa.gov/om/tornado.htm",
  "severe_weather",
  "From NOAA, a preparedness guide including safety information for schools"
	);
scripts[++count] = new Script(
  "Tornado Records",
  "http://www.theforge.com/tornado/states/",
  "severe_weather",
  "Tornado occurrences state by state, 1950--1998"
	);

scripts[++count] = new Script(
  "Miami Tornado",
  "http://www.srh.noaa.gov/MIA/vortex.html",
  "severe_weather",
  "Analysis and photographs of a Florida tornado"
	);

scripts[++count] = new Script(
  "Lightning Detection from Space",
  "http://ghrc.msfc.nasa.gov/lightning/primertext.html#LIS",
  "severe_weather",
  "From NASA, a lightning primer"
	);

scripts[++count] = new Script(
  "Weather Photography",
  "http://australiasevereweather.com/photography/",
  "severe_weather",
  "Cloud Features and phenomena"
	);

scripts[++count] = new Script(
  "Solar Image Index",
  "http://solar.sec.noaa.gov/current_images.html",
  "image_archive",
  "Archive of solar images revealing disturbances on the sun's surface"
	);
scripts[++count] = new Script(
  "Northern Lights over Finland",
  "http://virtual.finland.fi/finfo/english/aurora_borealis2.html",
  "image_archive",
  "Six vivid photos taken in southwest Finland in April 2000"
	);
scripts[++count] = new Script(
  "Martian Cloud Movie",
  "http://mars.jpl.nasa.gov/mgs/msss/camera/images/5_21_99_np_clouds/index.htm",
  "image_archive",
  ""
	);
scripts[++count] = new Script(
  "The Ozone Hole Tour",
  "http://www.atm.ch.cam.ac.uk/tour/",
  "ozone_depletion",
  "Data, scientific background, and current research; from the University of Cambridge Center for Atmospheric Research"
	);
scripts[++count] = new Script(
  "NOAA's Tsunami Program",
  "http://www.pmel.noaa.gov/tsunami/",
  "related_phenomena",
  " Mitigating tsunami hazards to the U.S. Pacific coast and to the Hawaiian Islands"
	);
scripts[++count] = new Script(
  "Martian Weather Observations",
  "http://nova.stanford.edu/projects/mgs/late.html",
  "historical_data",
  "Readings of surface temperature and pressure during one Martian year"
	);

scripts[++count] = new Script(
  "Pathfinder Weather Observations",
  "http://mars.sdsc.edu/ops/asimet.html",
  "historical_data",
  "Surface weather reports from July 9 through August 7,1997; also Martian meteorological data presented in graphic form"
	);
scripts[++count] = new Script(
  "Pathfinder Mast Temperatures",
  "http://www-k12.atmos.washington.edu/k12/mars/LOPS_Pathfinder_temperatures.cgi",
  "historical_data",
  "Animated graphs of temperatures recorded by the three sensors on Pathfinder's meteorology mast"
	);
scripts[++count] = new Script(
  "Lightning Occurrence",
  "http://www.nwstc.noaa.gov/d.MET/Lightning/climo.htm",
  "historical_data",
  "Lightning flash density for years 1992-1995"
	);

scripts[++count] = new Script(
  "Confronting Climate Change in California",
  "http://www.ucsusa.org/warming/calclimate.pdf",
  "global_warming",
  "Answers to frequently asked questions about hurricanes, typhoons, and tropical cyclones"
	);
scripts[++count] = new Script(
  "A Lightning Primer",
  "http://ghrc.msfc.nasa.gov/lightning/primertext.html#LIS",
  "severe_weather",
  "Causes and types of lightning as well as methods of detection and current research"
	);
scripts[++count] = new Script(
  "Snowstorm",
  "LB161317.jpg",
  "image_archive",
  "Snow falling on the Finnish countryside"
	);
scripts[++count] = new Script(
  "Finnish Autumn",
  "lb301534.jpg",
  "image_archive",
  "Late September in Finnish Lapland"
	);
scripts[++count] = new Script(
  "Spring Rain",
  "cam.jpg",
  "image_archive",
  "A rainy afternoon in Vyborg, Republic of Karelia, Russian Federation"
	);
scripts[++count] = new Script(
  "Winter Light",
  "tervola3.jpg",
  "image_archive",
  "Midday in January in northern Finland"
	);

scripts[++count] = new Script(
  "Earthquake Bulletin",
  "http://wwwneic.cr.usgs.gov/neis/bulletin/bulletin.html",
  "related_phenomena",
  "Near real-time list of the 21 most recent earthquakes"
	);
scripts[++count] = new Script(
  "Earth Observatory",
  "http://earthobservatory.nasa.gov/Library/GlobalFire/",
  "related_phenomena",
  "Environmental effects of biomass burning"
	);

scripts[++count] = new Script(
  "Seismic Activity",
  "http://camcic.unicam.it/discite/speciale/reale.htm",
  "related_phenomena",
  "Seismic monitoring in real time from the University of Camerino (in Italian)"
	);

scripts[++count] = new Script(
  "Exloring the Aurora",
  "http://www.pfrr.alaska.edu/~ddr/ASGP/ELEMPART/AURORA/INDEX.HTM",
  "related_phenomena",
  "Answers questions about the northern lights"
	);
scripts[++count] = new Script(
  "Climate Action Projects",
  "http://nature.org/international/specialinitiatives/climate/links/",
  "global_warming",
  "The Nature Conservancy's projects for sequestering carbon dioxide through reforestation"
	);
scripts[++count] = new Script(
  "Global Climate Coalition",
  "http://www.globalclimate.org/climlinks.htm",
  "global_warming",
  "A voice for business in the global warming debate"
	);

scripts[++count] = new Script(
  "Satellite Vegetation Data",
  "http://www.gsfc.nasa.gov/topstory/20010904greenhouse.html",
  "global_warming",
  "Data covering more than 2 decades shows a greening trend that is strongly correlated with temperature"
	);

scripts[++count] = new Script(
  "Mean Annual Precipitation",
  "http://www.climatesource.com/ppt_ann.gif",
  "historical_data",
  "Color-coded map of North America giving average annual precipitation for the years 1961-1990"
	);

scripts[++count] = new Script(
  "State Precipitation Maps",
  "http://www.ftw.nrcs.usda.gov/prism/prismmaps.html",
  "historical_data",
  "Color-coded maps of the United States giving average annual precipitation for the years 1961-1990"
	);

scripts[++count] = new Script(
  "2001 Ozone Hole Report",
  "http://www.noaanews.noaa.gov/stories/s792.htm",
  "ozone_depletion",
  "NASA reports ozone hole similar in size to holes of last 3 years"
	);
scripts[++count] = new Script(
  "Climate Change and Solar Cycle",
  "http://www.washingtonpost.com/wp-dyn/articles/A36652-2001Nov15.html",
  "global_warming",
  "Study shows possible link between the solar temperature cycle and North Atlantic climate"
	);

scripts[++count] = new Script(
  "Abrupt Climate Change",
  "http://www.nap.edu/books/0309074347/html/",
  "global_warming",
  "Rapid and large changes in the earth's climate possible, though unpredictable, according to a new National Academies of Science report"
	);



scripts[++count] = new Script(
  "Aerosols in the Atmosphere",
  "http://www.sciam.com/explorations/2002/010702aerosols/",
  "global_warming",
  "New date on possible role of aerosols in climate change "
	);


scripts[++count] = new Script(
  "Antarctic ice sheet growing",
  "http://dailynews.yahoo.com/h/nm/20020117/sc/environment_antarctica_dc_1.html",
  "global_warming",
  "WAIS ice sheet adding 26 billion tons of ice yearly"
	);


scripts[++count] = new Script(
  "El Niņo Home Page",
  "http://www.ogp.noaa.gov/enso/#Status",
  "El_niņo-La_niņa",
  "NOAA's one-stop source for information on El Niņo, La Niņa, and the Southern Oscillation "
	);

scripts[++count] = new Script(
  "Mixed Signals from Antarctica",
  "http://www.npr.org/programs/morning/features/2002/jan/antarctica/020118.antarctica.html",
  "global_warming",
  "New studies suggest rising temperatures; photogallery accompanies text"
	);
scripts[++count] = new Script(
  "Tornado Project Online",
  "http://tornadoproject.com/",
  "severe_weather",
  "A wide-ranging compilation of information about tornadoes"
	);

scripts[++count] = new Script(
  "Climate change projections",
  "http://www.met-office.gov.uk/research/hadleycentre/models/modeldata.html",
  "global_warming",
  "Hadley Centre for Climate Prediction and Research graphs climate change"
	);

scripts[++count] = new Script(
  "Confronting Climate Change in the Gulf Coast Region",
  "http://www.ucsusa.org/publications/gulfcoast_execsum.pdf",
  "global_warming",
  "executive summary and full UCS report (2002)"
	);

scripts[++count] = new Script(
  "Warmer Climate Fooling Flowers",
  "http://story.news.yahoo.com/news?tmpl=story&ncid=716&e=6&cid=514&u=/ap/20020530/ap_on_sc/climate___flowers_2",
  "global_warming",
  "As the climate warms, flowers are blooming earlier"
	);

scripts[++count] = new Script(
  "Global Warming and California's Climate",
  "http://unisci.com/stories/20022/0605024.htm",
  "global_warming",
  "Researchers at the University of California, Santa Cruz, predict warmer winters with more rain and a smaller snow pack"
	);

scripts[++count] = new Script(
  "Climate Action Report 2002",
  "http://www.epa.gov/globalwarming/publications/car/",
  "global_warming",
  "The Environmental Protection Agency's politically controversial report"
	);

scripts[++count] = new Script(
  "Global Warming: Early Warning Signs",
  "http://www.climatehotmap.org",
  "global_warming",
  "clickable map of local consequences of global warning"
	);

scripts[++count] = new Script(
  "Urban heat islands",
  "http://www.gsfc.nasa.gov/topstory/20020613urbanrain.html",
  "global_warming",
  "urban heat islands increase rainfall around cities"
	);


scripts[++count] = new Script(
  "Climate of 2001",
  "http://lwf.ncdc.noaa.gov/oa/climate/research/2001/ann/ann.html",
  "historical_data",
  "Annual review by the National Climatic Data Center"
	);

scripts[++count] = new Script(
  "Climate of 2000--Annual Review",
  "http://www.ncdc.noaa.gov/ol/climate/research/2000/ann/ann.html",
  "historical_data",
  "Separate world and US summaries"
	);

scripts[++count] = new Script(
  "Alaska's melting glaciers",
  "http://www.uaf.edu/seagrant/NewsMedia/02ASJ/07.19.02melting-glaciers.html",
  "global_warming",
  "Melting proceeding at an alarming rate"
	);

scripts[++count] = new Script(
  "Global Warming and Forest Fire Danger",
  "http://oregonstate.edu/dept/ncs/newsarch/2002/Sep02/fire1.htm",
  "global_warming",
  "In the American West global warming with accompanying enhanced precipitation will probably increase forest fire danger"
	);

scripts[++count] = new Script(
  "Average Snowfall",
  "http://www.met.utah.edu/jhorel/html/wx/climate/normsnow.html",
  "historical_data",
  "Monthly figures for US cities"
	);


scripts[++count] = new Script(
  "2002 Atlantic Hurricane Season ",
  "http://www.nhc.noaa.gov/2002atlan_summary.shtml",
  "historical_data",
  "Analysis of 14 2002 tropical cyclone reports"
	);

scripts[++count] = new Script(
  "Report on extreme weather",
  "http://www.waterandclimate.org/report.htm",
  "severe_weather",
  "Number of killer storms and droughts increasing worldwide, according to the World Water Council "
	);

/*********************************************************
** process query string of URL that loaded this page to get:
**   sortVal, typeVal 
** ****************************************************** */

var i, j;  // all-purpose vars
var query   = location.search;  // URL query string
var queries = new Array();      // array to hold parsed query data
var sortVal   = "nameAsc";  // default sort setting
var typeVal   = "any";      // default type setting

if (query.length > 1)  // query string there, parse it!
  queries = query.substring(1,query.length).split("&");

for (i=0; i<queries.length; i++)  // set sort/type/level/rating vals
  {
  if (queries[i].indexOf("sort") > -1)
    sortVal = queries[i].substring(5, queries[i].length);
  else if (queries[i].indexOf("type") > -1)
    typeVal = queries[i].substring(5, queries[i].length);
   }


/* *********************************************************
** filter table - i.e., build scriptsInList array per
** Type/Level/Rating settings (typeVal, levelVal, ratingVal)
**
** when creating your own database script, modify this code
** to build an array based on your data-filter settings
** ****************************************************** */

var scriptsInList = new Array();


for (i=0,j=0; i<scripts.length; i++)
  {
  if (typeVal == "any" || scripts[i].type.indexOf(typeVal) != -1)  
    scriptsInList[j++] = scripts[i];
  }

function applyFilters(form)
  {
  // get current Type, Level, Rating settings
  typeVal = form.typeSel.options[form.typeSel.selectedIndex].text;
   var queryStr = "";
  queryStr += "sort=" + sortVal;
  queryStr += ((typeVal == "any") ? "" : "&type="+typeVal);
    if (queryStr != "")
    queryStr = "?" + queryStr;
  location = "xjsdata.html" + queryStr;
  }

function clearFilters()
  {
  var queryStr = "";
  queryStr += "sort=" + sortVal;
  if (queryStr != "")
    queryStr = "?" + queryStr;
  location = "xjsdata.html" + queryStr;
  }


/* *********************************************************
** here are the various and sundry sort functions that are
** sent (as arguments) to scriptsInList.sort() as in:
**   scriptsInList.sort(sortByNameAscending)
**   scriptsInList.sort(sortByTypeDescending)
**   etc.
** ****************************************************** */

function sortByNameAscending(a, b)
  {
  if (a.name < b.name)
    return -1;
  else if (a.name > b.name)
    return 1;
  return 0;
  }

function sortByNameDescending(a, b)
  {
  if (a.name < b.name)
    return 1;
  else if (a.name > b.name)
    return -1;
  return 0;
  }

function sortByTypeAscending(a, b)
  {
  if (a.type < b.type)
    return -1;
  else if (a.type > b.type)
    return 1;
  return 0;
  }

function sortByTypeDescending(a, b)
  {
  if (a.type < b.type)
    return 1;
  else if (a.type > b.type)
    return -1;
  return 0;
  }


/* *********************************************************
** sort scripts array by name or type
** and assign values to name/typeSortArrow
* ****************************************************** */

var nameSortArrow = "";
var typeSortArrow = "";

if (sortVal == "nameAsc") {
  scriptsInList.sort(sortByNameAscending)
  nameSortArrow = "&nbsp;<img src=sort_up.gif>";
  }
else if (sortVal == "nameDesc") { 
  scriptsInList.sort(sortByNameDescending)
  nameSortArrow = "&nbsp;<img src=sort_down.gif>";
  }
else if (sortVal == "typeAsc") { 
  scriptsInList.sort(sortByTypeAscending)
  typeSortArrow = "&nbsp;<img src=sort_up.gif>";
  }
else if (sortVal == "typeDesc") { 
  scriptsInList.sort(sortByTypeDescending)
  typeSortArrow = "&nbsp;<img src=sort_down.gif>";
  }


/* *********************************************************
** updateTable(sortBy)
** ===================
** update table by reloading jsdata.html with query string
** ****************************************************** */

function updateTable(sortBy)
  {
  var queryStr = "";
  var sortType;

  if ((sortBy == "name" && sortVal == "nameAsc") ||
      (sortBy == "type" && sortVal == "typeAsc"))
         sortType = "Desc";
  else
        sortType = "Asc";

  queryStr += "sort=" + sortBy + sortType;
  queryStr += ((typeVal == "any") ? "" : "&type="+typeVal);
   if (queryStr != "")
    queryStr = "?" + queryStr;
  location = "xjsdata.html" + queryStr;
  }


/* *********************************************************
** create HTML table in which specified scripts are listed
** ****************************************************** */

var tableBegin = '<table align="center" width="98%">';
var tableEnd   = '</table>';

var rowHeaders = '<tr bgColor=#ffffcc><td width="35%"><a href="javascript:updateTable(\'name\')" onMouseOver="return showStatusMsg(\'Click once to sort by NAME ascending, click again to sort descending.\')"><B><BIG>Title</BIG></B></a>' + nameSortArrow + '</td><td width="25%"><a href="javascript:updateTable(\'type\')" onMouseOver="return showStatusMsg(\'Click once to sort by TYPE ascending, click again to sort descending.\')"><B><BIG>Topic</BIG></B></a>' + typeSortArrow + '</td><td> <B><BIG>Description</BIG></B>'  + '</td></tr>';

var rowBegin  = '<tr valign="top">';
var rowEnd    = '</tr>';

var tableBody = "";  // this will hold all the currently listed script data


for (i=0; i<scriptsInList.length; i++)
  {
  tableBody += rowBegin;
  tableBody += "<td width='35%'><a href='" + scriptsInList[i].url + "' target=newWin>";
  tableBody += scriptsInList[i].name + "</a></td>";
  tableBody += "<td width='25%'>" + scriptsInList[i].type + "</td>";
  tableBody += "<td>" + scriptsInList[i].description + "</td>";
  tableBody += rowEnd;  
  }


/* *********************************************************
** init()
** ======
** set initial values of Type select boxes
** ****************************************************** */

function init()
  {
  if (typeVal == "any")
    document.dbForm.typeSel.selectedIndex = 0; 
  else if (typeVal == "image_archive")
    document.dbForm.typeSel.selectedIndex = 1; 
  else if (typeVal == "historical_data")
    document.dbForm.typeSel.selectedIndex = 2; 
   else if (typeVal == "global_warming")
    document.dbForm.typeSel.selectedIndex = 3; 
  else if (typeVal == "ozone_depletion")
    document.dbForm.typeSel.selectedIndex = 4; 
  else if (typeVal == "severe_weather")
    document.dbForm.typeSel.selectedIndex = 5; 
  else if (typeVal == "El_niņo-La_niņa")
    document.dbForm.typeSel.selectedIndex = 6; 
else if (typeVal == "related_phenomena")
    document.dbForm.typeSel.selectedIndex = 7; 
  

   }


/* *********************************************************
** showStatusMsg()
** ===============
** zee humble little status-bar message changer ... 
**   usage: onMouseOver="return showStatusMsg('message')"
** ****************************************************** */

function showStatusMsg(msg)  // display status-bar message
  {
  status = msg;
  return true;
  }

