<!--
// --------------------------------------------------------------------
// $Id: 
//
//      file:   generatePlot.js
//      Author: Willa Zhu
//      Date:   January 1999
//
//      Function generatePlot() opens a new browser window and displays
//      a result page that is generated on-the-fly.
//
//      Argument:
//       theForm -- The name of the form that contains hidden parameters
//                  that will be used by CGI scripts.
//       win_name - Optional. Name of the window you will open.  If only  
//                  argument is given, the default name, "displayWin",
//                  will be used.
//       option   - Optional. The option for windoeFeatures Attributes.
//                  If this argument is given, you must also specify the
//                  window name.   The default option is "toolbar=1,
//                  scrollbars=1,resizable=1' and it will be overwritten
//                  by specified value.
// -------------------------------------------------------------------
//

var title_str;
function generatePlot(theForm, win_name, option) {
  //set the parameters
  getParameters(theForm);

  //if no error then make the plot
  if(validate()) {
    //get URL
    url_query_str = getURLQueryStr(theForm);
    //alert(url_query_str);
    
    // Avaible option:
    // option = "toolbar=1,scrollbars=1,resizable=1,width=pixels,height=pixels,status=1,directories=1,location=1";

    //Default option
    opt = 'toolbar=1,scrollbars=1,resizable=1';
    //default window name
    winname='displayWin';
    if(generatePlot.arguments.length >= 2)
       winname=win_name;
    if(generatePlot.arguments.length == 3)
       opt = option;
    openWindow(url_query_str, winname, opt);
  }
  return;
}

function getURLQueryStr(theForm) {
  len = theForm.numP.value;
  var url_str="";
  url_str += theForm.cover.value +"?";
 
  for(var i = 0; i < len; i++) {
    if(i > 0) url_str += "&";
    url_str += "P" + (i+1) + "=" + eval("theForm.P" + (i+1) + ".value");
  }
  url_str += "&script=" + theForm.script.value;

  title_str = theForm.titlestr.value;
  return(url_str);
}

function openWindow(new_url,winname,option) {
  // create the window
  displayWin = window.open("", winname, option);
  displayWin.document.writeln("<HTML>\n<HEAD></HEAD>\n<BODY>");
  displayWin.document.writeln("<BR><FONT SIZE=4><B>Generating " + title_str +" please wait ... </B></FONT>");
  displayWin.document.writeln("</BODY>\n</HTML>");
  displayWin.document.close();
 
  displayWin = window.open(new_url, winname, option);
  displayWin.focus();
  if (displayWin == null) {
    // couldn't create the window, exit
    return false;
  }
  return true;
}
