// main scripts for SCOPE system

// Accordion set up for the panel chooser page

function panelChooserInit() {
  $("#panel_list").accordion({
			autoHeight: false
  });
}

// support functions

function runApplet(url) {
  var appletWidth = Math.min(screen.availWidth - 100, 1140);
  var appletHeight = screen.availHeight - 150;

  // add the display size parameters for the applet and run it

  var link = url + "&w=" + appletWidth + "&h=" + appletHeight;

  window.location = link;

  return true;
}

// jQuery UI dialog managers

function showWhatsNew() {
  var msg = "<div id=\"bannerpopup\"><br/>" +
            "Added an image comparison tool to aid in star classifications.<br />&nbsp;<br />" +
            "Expanded the interface functionality with an instant star information popup to make finding specific stars easier.<br />&nbsp;<br />" +
            "The <I>My SCOPE/My Stars</I> page now provides additional info about the stars you've classified (such as the number of times each star has been classified and its officially determined star type, if available).<br />&nbsp;<br />" +
            "Print functionality has been added to the <I>My SCOPE/My Stars</I> page.<br />&nbsp;<br />" +
            "The date that each plate was taken is now included in the <I>Panel Chooser</I> page under \"Classify\".<br />&nbsp;<br />" +
            "Information on what's new to the site, general announcements, and scheduled maintenance is now available under <I>My SCOPE</I>.<br />&nbsp;<br />" +
            "The NEW PHP Platform (Java-Free) loads faster and is more compatible than the Java Applet." +
            "</div>";

  doDialog("What's New in SCOPE 2.1", msg, 700, 590, false);
}

function showDialog(titleText, messageText) {
  doDialog(titleText, messageText, 600, 200, false);
}

function showUpdated(titleText, messageText) {
  doDialog(titleText, messageText, 600, 180, true);
}

function showFormError(errorText, height) {
  doDialog("Page Error", errorText, 600, height, true);
}

function showRecorded(titleText, messageText) {
  doDialog(titleText, messageText, 600, 350, false);
}

function doDialog(titleText, messageText, width, height, errorPopupType) {
  // this approach does not need a DIV sction pre-defined in the HTML document
  var dlg = $("<div></div>").html(messageText).dialog({
    autoOpen: false,
    resizable: false,
    width: width,
    height: height,
    modal: true,
    title: titleText,
    buttons: {
      Ok: function() {
        $(this).dialog('close');
      }
    },
    open: function () {
      if (errorPopupType) {
        $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").addClass("ui-state-error");
      }
    }
  });

  dlg.dialog('open');

  return false;
}

