// Trim white space from the beginning and from the end of the given string.
//
// Inputs: s - string to trim.
// Return: trimmed string.
//
function stringTrim(s)
{
    return s.replace(/^\s+|\s+$/, '');
} 

// Function uses a random number generator to arbitrarily display one of a
// collection of photos on the front page.
//
function displayPic()
{
  var numPics  = 4;
  var index    = (Math.floor(Math.random() * numPics)) + 1;
  var filename = "/images/newshead" + index + ".jpg";
  document.write("<img align=center src='" + filename + "' border=0>");
}

// Function uses a random number generator to arbitrarily display one of a
// collection of hotshots photos on the front page.
//
function displayHS()
{
  var numPics  = 5;
  var index    = (Math.floor(Math.random() * numPics)) + 1;
  var filename = "/instruments/hotshots/thumb" + index + ".jpg";
  document.write("<a href='/instruments/hotshots'>");
  document.write("<img align=center src='" + filename + "' border=0>");
  document.write("</a>");
}

// Function is used to add an email link to a page in such a way that the
// email address tracking bots can't see it.
//
// Inputs: name  - email recipient name.
//         place - the email recipient domain.
//
function mailto(name,place)
{
  document.write("<a href='mailto:" + name + "@" + place + "'>");
  document.write(name);
  document.write("<img src='/images/at.gif' border=0>");
  document.write(place);
  document.write("</a>\n");
}

// Function opens a popup window. The specified name serves as the caption
// and is also the name of the HTML file to open in the window.
//
// Inputs: name   - popup window caption and HTML filename.
//         width  - popup window width.
//         height - popup window height.
//         scroll - boolean scrollbar flag.
//
function openWindow(name,width,height,scroll)
{
  file = name + ".html";
  var options = "width=" + width + ",height=" + height +
                ",resizable=1,scrollbars=" + scroll;
  window.open(file,name,options);
}

// Function opens a popup window containing the specified HTML file. The
// window caption is left blank.
//
// Inputs: file   - HTML filename.
//         width  - popup window width.
//         height - popup window height.
//         scroll - boolean scrollbar flag.
//
function openWindow2(file,width,height,scroll)
{
  var options = "width=" + width + ",height=" + height +
                ",resizable=1,scrollbars=" + scroll;
  window.open(file,"",options);
}

// Function points the curent browser window to the specified URL.
//
// Inputs: url - URL to open in the current window.
//
function goTo(url)
{
  window.location.href = url;
}

// Function puts up a form with "next" and "previous" buttons for use in a
// slide show presentation.
//
// Inputs: prv - HTML file to link to "previous" button.
//         nxt - HTML file to link to "next" button.
//
function slideArrows(prv,nxt)
{
  var strPRV = "onclick=goTo('" + prv + "')> ";
  var strNXT = "onclick=goTo('" + nxt + "')> ";

  document.write("<form>");
  document.write("<input class=dinput type=button value=' << '");
  document.write(strPRV);
  document.write("<input class=dinput type=button value=' >> '");
  document.write(strNXT);
  document.write("</form>");
}

// Function displays one slide out of a collection of many in a slideshow
// presentation. The function assumes the HTML files for the slides are
// of the form "slide_x.html" where "x" is the slide number.
//
// Inputs: num - number of the slide to display ("slide_num.html").
//         tot - total number of slides in the collection.
//
function showSlide(num,tot)
{
  var prv = num - 1;
  var nxt = num + 1;

  if (num == 1)
    prv = tot;
  if (num == tot)
    nxt = 1;

  var strPRV = "onclick=goTo('slide_" + prv + ".html')> ";
  var strNXT = "onclick=goTo('slide_" + nxt + ".html')> ";

  document.write("<h4>(" + num + " of " + tot + ")</h4> ");
  document.write("<form>");
  document.write("<input class=buttontext type=button value=' << '");
  document.write(strPRV);
  document.write("<input class=buttontext type=button value=' >> '");
  document.write(strNXT);
  document.write("</form>");

  document.write("<img src='slide_" + num + ".jpg'><br> ");
}

