<!--

function checkOrderRequirements( form )
{
   // We need to verify that each required field is provided and tha
   // any extra field is cleared (i.e. expiration for invoices).
var rc = 1;
var displayError = true;
   
   if ( rc )
   {
      rc = checkSubmit( form.firstName, 'First Name' );
   }
  
   if ( rc )
   {
      rc = checkSubmit( form.lastName, 'Last Name' );
   }
  
   if ( rc )
   {
      rc = checkSubmit( form.company, 'Company' );
   }
  
   if ( rc )
   {
      rc = checkSubmit( form.phoneNumber, 'Phone Number' );
   }
  
   if ( rc )
   {
      rc = checkSubmit( form.email, 'Email Address' );
   }
  
   if ( form.creditAmount == null ||
	( form.total.value - form.creditAmount.value ) > 0 )
   {
      if ( rc )
      {
	 rc = checkSubmit( form.paymentType, 'Payment Type' );
      }
     
      if ( rc )
      {
	 rc = checkSubmit( form.paymentNumber, 'Payment Number', form.paymentType );
      }
     
      if ( form.paymentType.value == 'Invoice' )
      {
	 form.paymentExpiration.value = '';
      }
      else if ( rc )
      {
	 rc = checkSubmit( form.expireMonth, 'Expiration Month' );

	 if ( rc )
	 {
	    rc = checkSubmit( form.expireYear, 'Expiration Year' );
	 }
      }
   }

   if ( !rc && displayError )
   {
      alert( status );
   }

   return rc;
}


function checkSubmit( field, itemType, extraField )
{
var value = 0;
var action = 'provide'

   if ( field.type == 'select-one' )
   {
   var idx = field.selectedIndex;

      value = field.options[ idx ].value;
      action = 'select';
   }
   else if ( field.value )
   {
      value = field.value;
   }

var rc = 0;

   if ( field.name == 'email' )
   {
      rc = validateEmail( field, true );
   }
   else if ( field.name == 'paymentNumber' )
   {
      rc = validatePayment( field, extraField.value );
   }
   else if ( field.name == 'paymentExpiration' )
   {
      rc = validateExpiration( field );
   }
   else
   {
      rc = value.length > 0 ? true : false;
   }

   if ( !rc )
   {
      status = 'You must ' + action + ' a valid ' + itemType + ' before proceeding.';
   }

   return rc;
}


function ECG_openPopup( theURL )
{
   return ECG_openWindow( theURL, 'Popup' );
}


function ECG_openWindow( theURL, name )
{
var win = window.open( theURL, name, 'scrollbars=yes, resizable=yes,' +
                                     'width=600, height=400' );

   if ( win )
   {
      win.focus();
   }

   return false;
}


function inRange( value, min, max )
{
var num = parseInt( value, 10 );

   return ( num >= min && num <= max ) ? true : false;
}


function tmt_regExpFieldValidator( f, re, eMsg, ru, r )
{
var fv = f.value;
var myErr = "";
var rex = new RegExp( re );
var t = eval( ru + rex.test( fv ) );

   // alert( "r = " + r + " fv.length =  " + fv.length + " t = " + t + " for re = " + re );
   if ( r )
   {
      if ( fv.length <= 0 || !t )
      {
          alert( eMsg );
         myErr += "eMsg";
      }
   }
   else if( fv.length > 0 && !t )
   {
      alert( eMsg );
      myErr += "eMsg";
   }

   document.MM_returnValue = ( myErr == "" );

   if ( !document.MM_returnValue )
   {
      f.focus();
   }

   return document.MM_returnValue;
}


function validateCreditCard( field )
{
   return validateCreditCard( field, false );
}


function validateCreditCard( field, required )
{
var msg = 'You must provide a valid credit card number.';
var result = tmt_regExpFieldValidator( field, '^\\d{13,16}$', msg, '', required );

   if ( result )
   {
   var detail = '';
   var value = field.value;
   var ccLead = value.substr( 0, 1 );
   var ccLen = value.length;

      if ( ( ccLead == 3 && ccLen != 15 ) ||
           ( ccLead == 4 && ( ccLen != 13 && ccLen !=16 )) ||
           ( ccLead == 5 && ccLen != 16 ) ||
           ( ccLead == 6 && ccLen != 16 ) )
      {
          detail = '   Credit Card Number has wrong length!';
      }
      else if ( value.search( '^(4|5|6|37)' ) < 0 )
      {
          detail = '   Credit Card Number not recognized';
      }
      else
      {
         // Now we check for checksum
      var digit = value.substr( ccLen - 1, 1 );
      var sum =0 ;

          for ( var i = 0; i < ccLen - 1; i++ )
          {
          var tmp = value.substr( ccLen - ( i + 2 ), 1 ) * ( 2 - ( i % 2 ) );

             sum += ( ( tmp < 10 ) ? tmp : ( tmp - 9 ) );
          }

      var checksum = ( ( 10 - sum % 10 ) % 10 );

         if ( digit != checksum )
         {
            detail = '   Credit Card Number Does Not Exist (failed checksum ' + digit + ' / ' + checksum + ')!\nPlease re-enter card number carefully.';
         }
      }

      result = ( detail == '' );

      if ( !result )
      {
         alert( msg + detail );
      }
   }

   return result;
}


function validateDate( field )
{
   return validateDate( field, false );
}


function validateDate( field, required )
{
var msg = 'You must provide a proper date as MM/DD/YYYY for this field.';
var result = tmt_regExpFieldValidator( field, '^\\d{1,2}[-/]\\d{1,2}[-/]\\d{4}$', msg, '', required );

   if ( result )
   {
   var detail = '';
   var values = field.value.match( /\d+/g );

      // we passed basic formatting, let's see if it is a real date
      // Note, Date.parse doesn't work here since it just converts the
      // invalid date to milliseconds which become something different
      if ( inRange( values[ 0 ], 1, 12 ) )
      {
      var days = new Array ( 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
      var maxDays = days[ values[ 0 ] ];

         if ( values[ 0 ] == 2 )
         {
            // February is an exception, so ...
            // First we have to check the year, if it is divisible by 4
            // but not by 100, unless it is also divisible by 400 then it
            // is a leap year and we have to adjust the feburary max.
            if ( ( !( values[ 2 ] % 4 ) && ( values[ 2 ] % 100 ) ) ||
                 !( values[ 2 ] % 400 ) )
            {
               maxDays++;
            }
         }

         if ( inRange( values[ 1 ], 1, maxDays ) )
         {
         var today = new Date();
         var date = new Date( field.value );
         
            // They must enter a date which is after today.
            if ( date < today )
            {
               detail = '  You must provide a valid year.  The date must be in the future.';
            }
         }
         else
         {
            detail = '  You must provide a valid day for the selected month.';
         }
      }
      else
      {
         detail = '  You must provide a valid month between 1 and 12.';
      }

      result = ( detail == '' );

      if ( !result )
      {
         alert( msg + detail );
      }
   }

   return result;
}


function validateEmail( field )
{
   return validateEmail( field, false );
}


function validateEmail( field, required )
{
   return tmt_regExpFieldValidator( field, '^[\\w\\.=-]+@[\\w\\.-]+\\.[a-z]{2,3}$', 'Invalid Email Address', '', required );
}


function validateExpiration( field )
{
   return validateExpiration( field, false );
}


function validateExpiration( field, required )
{
var msg = 'You must provide a proper date as MM/YYYY for this field.';
var result = tmt_regExpFieldValidator( field, '^\\d{1,2}[-/]\\d{4}$', msg, '', required );

   if ( result && field.value )
   {
   var detail = '';
   var values = field.value.match( /\d+/g );

      // we passed basic formatting, let's see if it is a real date
      // Note, Date.parse doesn't work here since it just converts the
      // invalid date to milliseconds which become something different
      if ( inRange( values[ 0 ], 1, 12 ) )
      {
      var today = new Date();
      var date = new Date( field.value );
      
         // They must enter a date which is this month or later.
         if ( values[ 1 ] < today.getFullYear() ||
              ( values[ 1 ] == today.getFullYear() &&
                values[ 0 ] < today.getMonth() + 1 ) )
         {
            detail = '  The date must be in the future.';
         }
      }
      else
      {
         detail = '  You must provide a valid month between 1 and 12.';
      }

      result = ( detail == '' );

      if ( !result )
      {
         alert( msg + detail );
      }
   }

   return result;
}


function validateNumber( field )
{
   return validateNumber( field, false );
}


function validateNumber( field, required )
{
   return tmt_regExpFieldValidator( field, '^\\d+$', 'You must provide a whole number for this field.', '', required );
}


function validatePayment( field, type )
{
   return validatePayment( field, type, false );
}


function validatePayment( field, type, required )
{
   return type == 'Invoice' ? validateText( field, required ) : validateCreditCard( field, required );
}


function validatePrice( field )
{
   return validatePrice( field, false );
}


function validatePrice( field, required )
{
   return tmt_regExpFieldValidator( field, '^\\$*\\d{1,3}(,*\\d{3})*\\.\\d{2}$', 'You must provide a valid price.', '', required );
}


function validateQty( field )
{
   return validateQty( field, false );
}


function validateQty( field, required )
{
   return tmt_regExpFieldValidator( field, '^[ 0-3]$', 'No more than 3 people from the same company may attend the same program on the same date.', '', required );
}


function validateText( field )
{
   return validateText( field, false );
}


function validateText( field, required )
{
   return tmt_regExpFieldValidator( field, '^..*', 'You must provide text for this field.', '', required );
}


-->

