/*
  Will open a window containing the given url 
  with the given name.  If args is not specified,
  it will default to turning on all available
  options.

  It is designed to work like this:
    <a href="link.html"
       onclick="windowOpener(this, "winname"); return false;">
      Link</a>
  That way, the link can still be opened of javascript is
  whacked on the client computer.
  Need to test to be sure this works with other browsers.

  Note: the default 'args' turning everything on
  works with Linux Firefox 1.5, need to test with
  other stuff.

  Additional Note: In Firefox, if you have the
  "Force links that open new widows to open in:"
  option set, it will always open a new tab.
  This is the same as the "target=" behaviour.
*/
function windowOpener(link, window_name, args) {

  // "default" argument for args,
  // all window possibilites ON
  myargs = (typeof(args) != 'undefined') ? args : "directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,toolbar=yes";

  // get the HREF section of the link
  url = retrieveHREF(link);

  // find the window if it is alread open
  windowHandle = window.open(url, window_name, myargs);
  windowHandle.focus();
  return;

}

function BugInstructorAboutFeedback(feedback_link, window_name, args) {
  // "default" argument for args,
  // all window possibilites ON
  myargs = (typeof(args) != 'undefined') ? args : "directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes,toolbar=yes";

  var response = confirm("When you have finished capturing your students’ scores, please take a moment to fill out a brief questionnaire so that we know how well this lesson is working and how to improve it.\n\nOpen survey in a new window?  (Either answer will proceed with downloading the scores.)");

  if (response) {
    // find the window if it is alread open
    windowHandle = window.open(feedback_link, window_name, myargs);
    windowHandle.focus();
  }

  return true;
}

/*
From: http://www.irt.org/script/988.htm
and modified slightly, if passed a link
handle, get the href.
*/
function retrieveHREF(what) {
  if (document.layers) {
    // NS4+?
    return url + '?' + escape(what.text);
  }
  else if (document.all) {
    // IE4?
    return url + '?' + escape(what.innerText);
  }
  else {
    // This is what my Linux Firefox 1.5 uses
    return what.href;
  }
}