var newWindow = null;


function openWindow(url, name, width, height) {
  if (!newWindow || newWindow.closed) {
    newWindow = window.open(url, name, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,width=" + width + ",height=" + height);
    newWindowURL = url;
  } else {
    if (newWindowURL != url) {
      newWindow.location.href = url;
      newWindowURL = url;
    }
  }

  newWindow.focus();
}


function startLoadingAnimation() {
  /* Call this function immediately before causing a request to be sent
     to the client. */
  loadingCaption = top.document.getElementById("loadingCaption");
  if(loadingCaption)
    loadingCaption.innerHTML = "CONNECTING TO PC";

  loadingAnimation = top.document.getElementById("loadingAnimation");
  if(loadingAnimation)
    loadingAnimation.src = "/images/loading_animation.gif";
}


function endLoadingAnimation() {
  loadingCaption = top.document.getElementById("loadingCaption");
  if(loadingCaption)
    loadingCaption.innerHTML = "&#160;";

  loadingAnimation = top.document.getElementById("loadingAnimation");
  if(loadingAnimation)
    loadingAnimation.src = "/images/idle_animation.gif";
}


/**
 * Prevents a page from being loaded outside of a frame set.  When the user
 * clicks a link after their session has expired, only the target of that link
 * will be opened after they have logged in again.  Thus, if the link was to a
 * frame, the containing frameset will be lost.  To correct this, each page
 * that can appear in a frame set should call this function when it is loaded.
 */
function forceInsideFrameset() {
    if (top.location == self.location)
        top.location = "/";
}

/**
 * Prevents a page from being loaded inside of a frameset.  If a fatal error
 * occurs, or the session times out and the login page appears, we don't want
 * to let the user login again from within a frame.
 */
function forceOutsideFrameset() {
    if (top.location != self.location)
        top.location = self.location;
}
