//------------------------------------------------------------------------
// nes.js
//
// Functions for interfacing with NeS - NESDIS e-Commerce System
//
// $Id: nes.js,v 1.4 2006/05/16 17:44:56 kmoore Exp $
// $Log: nes.js,v $
// Revision 1.4  2006/05/16 17:44:56  kmoore
// Enter PR: 2181
// Parameterize online_store URL and product_type.
//
// Revision 1.3  2006/04/20 18:22:13  adrew
// Enter PR: 2251
// prepend the text CLASS to the order number as required for Online Store.
//
// Revision 1.2  2006/04/19 13:18:56  kmoore
// Enter PR: 2215
// Change URL for online store from test to production link.
//
// Revision 1.1  2005/12/30 22:07:33  kmoore
// Enter PR: 1756
// For Nes (NESDIS eCommerce System):
// Javascript to connect to the OLS (Online Store).
//
//------------------------------------------------------------------------

var iversion = -1;

function version() {
   if (iversion != -1) return iversion;
   iversion = parseInt(navigator.appVersion);
   return iversion;
}

//------------------------------------------------------------------------
// Based on value of form.action_status.value:
// =  0 indicates user has not been sent to the Online Store (OLS) yet from
//      this page, so call function to connect to the OLS.  Then reset
//      values on the calling form to indicate OLS has been called, and
//      change the button text.
// <> 0 indicates the user has been to the OLS from this page, so simply
//      post the form, which will send the user to wherever the form says.
//------------------------------------------------------------------------
function determine_action(form) {
   if (form.action_status.value == 0) {
      if (OpenOLSWindow(form)) {
         form.action_status.value = 1;
         form.nesPayment.value=form.button_text.value;
         form.nesPayment.title=form.button_text.value;
      }
   }
   else {
         form.submit();
   }
   return 0;
}

//------------------------------------------------------------------------
// Opens a new window, writes a form to the new window, then posts that
// form in order to connect to the OLS (Online Store), also known as
// the NESDIS eCommerce System (NeS).
//------------------------------------------------------------------------
function OpenOLSWindow(form) {
try {
  if (version() >= 3) {
      DataWindow = window.open('', 'OnlineStore',
       'toolbar=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,width=750,height=600');

      DataWindow.focus();
      DataWindow.document.write('<html><head><title>Comprehensive Large-Array data Stewardship System </title></head> \n');
      DataWindow.document.write('<body>\n');
      DataWindow.document.write('Connecting to the NESDIS Online Store...\n')
      DataWindow.document.write(
         '<form action="http://' + form.online_store.value + '" '
          + 'name="goto_ols" id="goto_ols" method="post" >'
      );
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="PROD" VALUE="' + form.product_number.value + '"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="SUBARR" VALUE="000"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="VARNAME" VALUE="CLASSORDNUM"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="VARVALUE" VALUE="CLASS' + form.class_order_num.value + '"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="QUAN" VALUE="1"/>\n');

      DataWindow.document.write('<input TYPE="HIDDEN" NAME="PROD" VALUE="' + form.product_number.value + '"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="SUBARR" VALUE="000"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="VARNAME" VALUE="PRICE"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="VARVALUE" VALUE="' + form.nes_price.value + '"/>\n');
      DataWindow.document.write('<input TYPE="HIDDEN" NAME="QUAN" VALUE="' + form.nes_quantity.value + '"/>\n');
      DataWindow.document.write('</form>\n');
      DataWindow.document.write('</body>');
      DataWindow.document.write('</html>');
      DataWindow.document.close();

      DataWindow.document.goto_ols.submit();
      return true;
  }
  else {
     alert("We regret that your browser does not support the functionality needed to open a window to the NESDIS Online Store.");
      return false;
  }
}
catch(e) {
   alert("Please close any existing window to the NESDIS Online Store before trying to submit a new payment.");
return false;
  }
}
