<!-- hide javascript from really old browsers.
// *****************************************************************************
// *****************************************************************************
// emenu.js
// ----------------------------------------------------------------------------
// This file, emenu.js, houses all JavaScript employed by the eMenu web
// application.  It is contained in a single repository for maintainability and
// to be able to reuse the code amongst the various ASP.NET pages.  In addition,
// by putting the JavaScript in an external file, the code is hidden from the
// curious user.  Many of the functions contained here are reused while some
// are specific to a single page.
// *****************************************************************************
// *****************************************************************************
var ForceKioskMode = 0 ; // set to 1 for CHURCHILL DOWNS; zero for everywhere else.  @ 1 this will force all operations to be kiosk-like.

// **************************************************************************
// showReceiptWindow
// -------------------------------------------------------------------------
// Shows the specified receipt URL in a new window.
// **************************************************************************
function showReceiptWindow( url )
{
    window.open( url,
   	             "receipt",
   		         "height=800,width=500,resizable,status,menubar,toolbar" ) ;
   	return;
}

// *************************************************************************
// getCookieValue()
// ------------------------------------------------------------------------
// Returns value of installed cookie identified in the parameter.  If not
// found, returns 0.  Assumes integer name/value pairs in cookies.
// Used by many, many of the pages for finding values of cookies.
// This is likely the most-used JavaScript function, so we put it at the
// top of the file.
// *************************************************************************
function getCookieValue ( cookieName )
{
   var cookieInfo, counter;
   cookieInfo = document.cookie.split("; ");

   // Iterate through the name/value pairs looking for a match on the name, 
   // element 0. If a match is found, return the value, element 1
   for (counter=0; counter<cookieInfo.length; counter++)
   {
      if (cookieInfo[counter].split("=")[0] == cookieName)
         return cookieInfo[counter].split("=")[1];
   }

   // If we get to here, the name wasn't found
   return 0 ;
} // end getCookieValue()


// *****************************************************************************
// SetTimer
// ----------------------------------------------------------------------------
// Function sets a timer for checking against user abandonment.
// Note: this method specifically sets a TIME-OUT (TO1) timer and not just any
// timer.  All pages with UI the user will see except for UserPrompt use
// this function to start the abandonment timer (in Kiosk mode).
// *****************************************************************************
function SetTimer()
{
   var TimerValue = 0 ;
   var KioskID    = 0 ;
   KioskID    = getCookieValue ( "eMenuKiosk" ) ;
   TimerValue = getCookieValue ( "TO1" ) ;


   //alert ( "Timer Value: " + TimerValue + ", KioskID: " + KioskID + ", ForcedKioskMode: " + ForceKioskMode ) ;
   
   if ( TimerValue > 0 && (KioskID > 0 || ForceKioskMode == 1) )
   {
      TimerValue = TimerValue * 1000 ;
      //alert ( "KioskID: " + KioskID + ", abandonment timer value to be set: " + TimerValue ) ;
      window.setTimeout( 'redirect()', TimerValue ) ;
   } // end setting a timer value if there is a valid value.
   //else
       //alert ( "Not a kiosk, so no timer to be installed." ) ;
} // end SetTimer().

// *****************************************************************************
// SetStandbyTimer
// ----------------------------------------------------------------------------
// Function sets a timer for checking against user abandonment.
// Note: this method specifically sets a TIME-OUT (TO1) timer and not just any
// timer.  All pages with UI the user will see except for UserPrompt use
// this function to start the abandonment timer (in Kiosk mode).
// *****************************************************************************
function SetStandbyTimer()
{
   var Url = document.Standby.Url.value ;
   var TimerValue = 10 ;
   
   TimerValue = TimerValue * 1000 ;

   window.setTimeout( 'retry()', TimerValue ) ;
} // end SetStandbyTimer()
// *****************************************************************************
// retry
// ----------------------------------------------------------------------------
// Unused method...
// *****************************************************************************
function retry()
{
   var url = document.Standby.Url.value ;
   //alert ( "url in 'retry()': " + url ) ;

   window.location = url ;
}


// *****************************************************************************
// redirect
// ----------------------------------------------------------------------------
// Function is called when a window's timer event (TO1) fires.  Depending upon 
// the situation, the site will be redirected to ask the user if he/she is 
// still shopping.
// *****************************************************************************
function redirect()
{
   // First we search the query string to extract name value pairs so we can 
   // preserve them upon our redirect.
   //alert ( "Redirect timer expired." ) ;
   var qs = location.search.substring(1) ;

   var m = "" ;
   var s = "" ;
   var c = "" ;
   var pairs = qs.split("&") ;
   for ( var i=0; i < pairs.length; i++ )
   {
      var pos = pairs[i].indexOf('=') ;
      if ( pos == -1 )
         continue ;

      var arg = pairs[i].substring(0,pos) ;
      var val = pairs[i].substring(pos+1) ;

      if ( arg == 'm' )
      {
         m = val ;
      } else if ( arg == 's' )
      {
         s = val ;
      } else if ( arg == 'c' )
      {
         c = val ;
      }
   } // end for loop for extracting name/value pairs from the query string.
   
   //var KioskEndSession = document.forms[0].KioskEndSession.value ;
   //alert ( "KioskEndSession: " + KioskEndSession ) ;
   
   // We always redirect the user to the "UserPrompt" page to ask them if they
   // are still there and shopping.
   // Set up the URL accordingly.
   var url = "UserPrompt.aspx" ;
   if ( m == "" )
      m = -1 ;
   if ( s == "" )
      s = -1 ;
   if ( c == "" )
      c = -1 ;
   url += "?m=" + m ; 
   url += "&s=" + s ;
   url += "&c=" + c ;   
   
   url += "&o=ato" ;

   if ( s != -1 || c != -1 )
   {
      window.location =  url ;
   }

   return ;
} // end redirect()
// ******************************************************************************
// formFocus_Transaction()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field.  Which field to use as the first focus depends on
// our mode of operation: kiosk v. web.  In kiosk mode, we set the focus to the
// magnetic stripe or swipe field.  In web mode, we set the focus to the first
// name field.
// 
// This method is used only by the Transaction form.
// ******************************************************************************
function formFocus_Transaction()
{
   var KioskID = getCookieValue ( "eMenuKiosk" ) ;

   if ( KioskID > 0 || ForceKioskMode == 1 )
   {
      document.all('SwipeData').focus() ;
   } // end setting focus for a kiosk
   else
   {
      document.all('CreditCardType:').focus() ;
   } // end setting focus for a web client.
} // end formFocus_Transaction()

// ******************************************************************************
// formFocus_ForgotPassword()
// -----------------------------------------------------------------------------
// Sets focus to the only control: email address.
// This method is used only by the ForgotPassword form.
// ******************************************************************************
function formFocus_ForgotPassword()
{
   if ( document.getElementById('Email') != null ) 
   {
      if ( document.getElementById('Email').disabled == false )
         document.getElementById('Email').focus() ;
   }
      // document.all('Email').focus() ;
} // end formFocus_ForgotPassword()

// ********************************************************************************
// formFocus_CG()
// -------------------------------------------------------------------------------
// CG => Choice Groups; this is used by wizard.aspx.cs.
// Sets input focus to the Next or Finish button...whichever is present in the
// form (ONE of them must always be in the form).
// ********************************************************************************
function formFocus_CG()
{ 
   if ( document.getElementById('Next') != null ) 
   {
      if ( document.all('Next').disabled == false ) 
         document.all('Next').focus() ;   
   }
   else if ( document.getElementById('Finish') != null ) 
   {

      if ( document.all('Finish').disabled == false ) 
        document.all('Finish').focus() ; 
   }
} // end formFocus_CG

// *******************************************************************************
// validateMinMaxChoiceGroup
// ------------------------------------------------------------------------------
// Inovked by wizard.aspx.cs.
// Method enables or disables navigation buttons as appropriate based upon
// combination of the user's choices and minimum and maximum choice criteria.
// *******************************************************************************
function validateMinMaxChoiceGroup()
{
    var disableNavigation = true ;
    var numchecked = 0 ;
    var numCheckBoxes = 0 ;
    var MinChoices = document.Form1.MinChoices.value ;
    var MaxChoices = document.Form1.MaxChoices.value ;

   for ( var i=0; i< document.forms[0].length; i++ )
   {
      var e = document.forms[0].elements[i] ;
      if ( e.type == "checkbox" )
      {
         numCheckBoxes = numCheckBoxes + 1 ;
	 if ( e.checked == true )
	 {
            numchecked = numchecked + 1 ;
	 }
      } // end if
   } // end for

   if ( numCheckBoxes > 0 )
   {
   if ( numchecked >= MinChoices && numchecked <= MaxChoices )
      disableNavigation = false ;      
   else
      disableNavigation = true ;

   if ( document.getElementById('Previous') != null )
      document.Form1.Previous.disabled = disableNavigation ;
   if ( document.getElementById('Next') != null )
      document.Form1.Next.disabled = disableNavigation ;
   if ( document.getElementById('Finish') != null )
      document.Form1.Finish.disabled = disableNavigation ;
   }

   // Reset the form's focus with each checkbox click by a customer
   // to either the Next or Finish button, as appropriate.
   formFocus_CG() ;

   return ;
} // end validateMinMaxChoiceGroup

// ******************************************************************************
// formFocus_Pin()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field.  
// 
// This method is used only by the Pin form.
// ******************************************************************************
function formFocus_Pin()
{
   document.all('PIN').focus() ;
} // end formFocus_Pin()

// ******************************************************************************
// formFocus_SignIn()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field.  
// 
// This method is used only by the SignIn form.
// ******************************************************************************
function formFocus_SignIn()
{
   if ( document.getElementById('Username') != null ) 
      document.all('Username').focus() ;
} // end formFocus_SignIn()
// ******************************************************************************
// formFocus_PasswordChange()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field.  
// 
// This method is used only by the PasswordChange form.
// ******************************************************************************
function formFocus_PasswordChange()
{
   document.all('Password').focus() ;
} // end formFocus_PasswordChange()

// ******************************************************************************
// formFocus_Registration()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field.  
// 
// This method is used only by the 3-page Registration form.
// ******************************************************************************
function formFocus_Registration()
{
   if ( document.getElementById('Username') != null )
   {
       document.all('Username').focus() ;
   }
   else if ( document.getElementById('Firstname') != null ) 
   {
      document.all('Firstname').focus() ;
   }
   else if ( document.getElementById('SVAccountNum') != null )
   {
      document.all('SVAccountNum').focus() ;
   }
   else if ( document.getElementById('CreditCardType_') != null ) 
   {
      document.all('CreditCardType_').focus() ;
   }
   else if ( document.getElementById('Phone') != null ) 
   {
      document.all('Phone').focus() ;
   }
   else if ( document.getElementById('Terms') != null )
   {
      document.all('Terms').focus() ;
   }

//      alert ( "Not page one." ) ;
} // end formFocus_Pin()


// ******************************************************************************
// formFocus_PreOrder()
// -----------------------------------------------------------------------------
// formFocus() is a method that sets the focus to the appropriate
// "first" user input field. 
// 
// This method is used only by the PreOrder form.
// ******************************************************************************
function formFocus_PreOrder()
{
    //document.all('Now').focus() ;
} // end formFocus_PreOrder()

// *****************************************************************************
// formValidate_Transaction()
// ---------------------------------------------------------------------------
// formValidate_Transaction: client-side validation of values entered into the
// Transaction form.  We do client-side checking (of course) to avoid making a
// round trip to the server with a form with values we know to be "bad" or 
// incomplete.  Not only does this help avoid round-trip delay, but it also
// lessens server load and most importantly, presents quick feedback to the
// user.
// ****************************************************************************
function formValidate_Transaction()
{
   // declare our error tracking variables
   var fErrorLength = false ; // Erroroneous length of field (that is, zero length)
   var fErrorChar   = false ; // Bad character entered (specific to a field)
   var fErrorValue  = false ; // Bad value (specific to a field, e.g., month too early)
   var numErrors    = 0     ; // Total number of errors; used in formatting message.

   // declare our presentation string.
   var ErrorString = "One or more data errors exist.\n\n" ;

   // *******************************************************************************************************************
   // regular expression strings: indicating the list of acceptable characters (or, in the case of ^, the opposite list).
   // *******************************************************************************************************************
   var patternName    = /[^a-zA-Z\s'-]/g ;      // name check -- alphabetic characters only.
   var patternCCNum   = /[^0-9]/g ;             // credit number check - numbers only
   var patternZipCode = /[^a-zA-Z0-9]/g ;       // zip code pattern.  Numbers, letters (Canada), or dash

   // samples:
   // var patternGeneral = /[^a-zA-Z0-9\s\-\/]/g ; // generalized string.
   // var patternUser    = /[^a-zA-Z0-9]/g ;       // usernames: same as generalized except no white spaces
   // var patternEasy    = /["]/g ;                // easier pattern test to pass; just allow no quotes that'll screw up SQL!
   // var patternPhone   = /[^0-9\s-()]/g ;        // phone number pattern.  Numbers, spaces, parenthesis, period, dash
   // var patternEmail   = /["\s]/g ;              // email address pattern.  No spaces or quotation marks allowed.
   //

   // ******************************************************************************************************************
   // Conduct our client side testing.
   // 
   // We perform three kinds of tests (generally). 1) Test for the existence of any entered value, 2) Test for valid
   // characters, 3) Test for valid values.
   // ******************************************************************************************************************

   // *******************************************
   // First check for valid field value lengths.
   // *******************************************
   if ( document.Trans.Firstname.value  == "" ||
        document.Trans.Lastname.value   == "" )
   {
      fErrorLength = true ;
      ErrorString += "The following required field(s) were not completed: " ;

      // We know at least one error (field-length-wise) exists, now go and set up 
      // the error message to show what the user must do to correct the situation.

      // FIRSTNAME
      if ( document.Trans.Firstname.value == "" )
      {
         ErrorString += " Firstname" ;
         numErrors++ ;
         document.Trans.Firstname.focus() ;
      } // end error checking code: FIRSTNAME

      // LASTNAME
      if ( document.Trans.Lastname.value == "" )
      {
         if ( numErrors > 0 )
         {
            ErrorString += ", " ;
         } 
         else
            document.Trans.Lastname.focus() ;
         
         ErrorString += " Lastname" ;
         numErrors++ ;
      } // end error checking code: LASTNAME

      // CREDIT CARD NUMBER
      if ( document.Trans.AccountNum_.value== "" )
      {
         if ( numErrors > 0 )
            ErrorString += ", " ;
         else
            document.Trans.AccountNum_.focus() ;

         ErrorString += " Card Number" ;
         numErrors++ ;
      } // end CREDIT CARD NUMBER

      // Complete the formatting of our error string.
      ErrorString += "." ;
   } // end general checking.

   // **************************************************************************************
   // Check for valid character entry (not associated with field length) and not with
   // respect to data validation--just character type by field as appropriate.
   // **************************************************************************************
   numErrors = 0 ; // reset variable for tracking "errors so far" by type...formatting aid.
   var resultFirstname = true ;
   var resultLastname  = true ;
   var resultCCNumber  = true ;
   var resultPostalCode = true ;

   // test for valid characters in the FIRSTNAME field
   var str = document.Trans.Firstname.value.toString() ;
   if ( !str.match(patternName) )
      resultFirstname = false ;

   // test for valid characters in the LASTNAME field
   str = document.Trans.Lastname.value.toString() ;
   if ( !str.match(patternName) )
      resultLastname = false ;

   // test for valid characters in the CREDIT CARD NUMBER field
   str = document.Trans.AccountNum_.value.toString() ;
   if ( !str.match(patternCCNum) )
      resultCCNumber = false ;

   // Any error sets the character error flag to true.
   if ( resultFirstname == true || resultLastname == true || resultCCNumber == true )
      fErrorChar = true ;

   if ( fErrorChar == true )
   {
      var cErrorString = "" ;
      if ( fErrorLength == true )
      {
         // If there was a previous error, we want to separate 
         cErrorString += "\n\n" ;
      }
      cErrorString += "Invalid characters were entered in one or more fields." ;

      // FIRSTNAME
      if ( resultFirstname == true )
      {
         cErrorString += "\n-- Firstname: alphabetic characters only [a-z, A-Z]." ;
      } // end formatting FIRSTNAME message.

      // LASTNAME
      if ( resultLastname == true )
      {
         cErrorString += "\n-- Lastname: alphabetic characters only. [a-z, A-Z]" ;
      } // end formatting LASTNAME message.

      // CREDIT CARD NUMBER
      if ( resultCCNumber == true )
      {
         cErrorString += "\n-- Card Number: numeric characters only. [0-9]" ;
      } // end formatting CREDIT CARD NUMBER message.

      // append the character oriented suggestion to the general string.
      ErrorString += cErrorString ;
   } // end formatting the error string for an error code.

   numErrors = 0 ; // reset variable for tracking "errors so far" by type...formatting aid.

   // *******************************************************************************
   // If any error has been discovered, show an error message to the user and abort.
   // *******************************************************************************
   if ( fErrorLength == true || fErrorChar == true || fErrorValue == true )
   {
      ErrorString += "\n\nPlease correct all errors and press Continue." ;

      // If there is any error found in validating the form, present the error message
      // to the user and inhibit submitting the form to the server.
      alert ( ErrorString ) ;

      // Because this JavaScript function was installed as an attribute of the form
      // and we included a "return" prefix, returning false here will avoid submitting
      // the form to the server.

      return false ;
   } // end if there is an error.

   // ***********************************************************************
   // We reach here only if an "early return" was not executed.
   // No errors found during client-side validation; submit to the server.
   // ***********************************************************************
   return true ;
} // end formValidate_Transaction()

// ******************************************************************************
// formValidate_Preorder
// -----------------------------------------------------------------------------
function formValidate_Preorder()
{
   var fError  = false ;
   var fReturn = true ;

   // **************************************************************************************
   // For pre orders, check to see that an hour and minute have been selected.
   // **************************************************************************************
   var AllowImmediateOrders = (document.getElementById('AllowImmediateOrders')).value ;
   
   // var p ; 
   var now, future ;
   
   //if ( AllowImmediateOrders == "Y" )
      //p = (document.getElementById('PreOrderSetting')).value ;
      
   if ( AllowImmediateOrders == "Y" )
   {   
      now = (document.getElementById('Now')).checked ;
      future = (document.getElementById('Future')).checked ;
   }
   else
   {
      now = false ;
      future = true ;
   }
   
   
   var hmErrorString = "\nPlease make a valid choice for both pre-order time setting." ;

   if ( future == true )
   {
      var hour = (document.getElementById('Hour')).value ;
      //var minute = (document.getElementById('Minute')).value ;

      if ( hour == "Select hour" /*|| minute == "Select minute"*/ )
      {
         fError = true ;
      }
   }
   if ( fError == true )
   {
      alert ( hmErrorString ) ;
      fReturn = false ;
   }

   // **************************************************************************************
   // Check for valid actual data where we can (e.g., month too early).
   // **************************************************************************************
   
   return fReturn ;
} // end formValidate_Preorder
// ******************************************************************************
// formValidate_Registration
// -----------------------------------------------------------------------------
// Client side validation of values entered into the RegistrationPage form
// associated with the RegistrationPage class of the eMenu application.  Again,
// we do client side checking to avoid some round-trips for errors we can
// catch locally.  This validation method is different than those above in that
// it must consider that the underlying form has three different "pages", one
// each for different subsets of the information that is to be collected.
// ******************************************************************************
function formValidate_Registration()
{
   var fErrorLength = false ;
   var ErrorString  = "One or more data errors exist.\n\n" ;
   var numErrors    = 0 ;
   var fErrorChar   = false ; // Bad character entered (specific to a field)
   var fErrorValue  = false ; // Bad value (specific to a field, e.g., month too early)

   // retrieve hidden form value to determine how much enforcement we'll do.
   var AuthenticationScheme = document.getElementById('AuthenticationScheme') ;

   // *******************************************************************************************************************
   // regular expression strings: indicating the list of acceptable characters (or, in the case of ^, the opposite list).
   // *******************************************************************************************************************
   var patternName    = /[^a-zA-Z\s'-]/g ;      // name check -- alphabetic characters only.
   var patternCCNum   = /[^0-9]/g ;             // credit number check - numbers only
   var patternZipCode = /[^a-zA-Z0-9]/g ;       // zip code pattern.  Numbers, letters (Canada), or dash


   if ( document.getElementById('Username') != null && AuthenticationScheme != 'Windows' ) 
   {
      // ************************************************************************************
      // PAGE ONE
      // ************************************************************************************
      // check for valid fieldname lengths
      // 
      var fPhoneError = false ;
      if ( document.getElementById('Phone') )
      {
	 if ( document.RegistrationPage.Phone.value == '' )
	 {
            fPhoneError = true ;
	 }
      }

      var fAddressError = false ;
      if ( document.getElementById('Address') )
      {
         if ( document.RegistrationPage.Address.value == '' )
         {
            fAddressError = true ;
         }
      }

      var fCityError = false ;
      if ( document.getElementById('City') )
      {
         if ( document.RegistrationPage.City.value == '' )
         {
            fCityError = true ;
         }
      }

      var fZipcodeError = false ;
      if ( document.getElementById('Zipcode') )
      {
         if ( document.RegistrationPage.Zipcode.value == '' )
         {
            fZipcodeError = true ;
         }
      }
      var fPasswordError = false ;
      if ( document.getElementById('Password') )
      {
         if ( document.RegistrationPage.Password.value == '' )
         {
            fPasswordError = true ;
         }
      }
   
   
      // ************************************************************************************
      // PAGE ONE
      // ************************************************************************************
      // check for valid fieldname lengths
      if ( document.RegistrationPage.Firstname.value == "" ||
           document.RegistrationPage.Lastname.value  == "" ||
           fPhoneError == true                             ||
           document.RegistrationPage.Email.value     == "" ||
           fAddressError == true                           ||
	       fCityError == true                              ||
	       fZipcodeError == true                           ||
           document.RegistrationPage.Username.value  == "" ||
           fPasswordError == true )
      {
         fErrorLength = true ;
         ErrorString += "The following required field(s) were not completed: " ;

         // FIRSTNAME
         if ( document.RegistrationPage.Firstname.value == "" )
         {
            ErrorString += " Firstname" ;
            numErrors++ ;
         }// end checking firstname
         // LASTNAME
         if ( document.RegistrationPage.Lastname.value == "" )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Lastname" ;
            numErrors++ ;
         }// end checking lastname
         // PHONE
         if ( fPhoneError == true )
	 {
   	    if ( document.RegistrationPage.Phone.value == "" )
            {
               if ( numErrors > 0 )
                  ErrorString += ", " ;
               ErrorString += " Phone" ;
               numErrors++ ;
            }// end checking phone
         }
	     // EMAIL
         if ( document.RegistrationPage.Email.value == "" )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Email" ;
            numErrors++ ;
         }// end checking email

         // ADDRESS
         if ( fAddressError == true )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Address" ;
            numErrors++ ;
         }// end checking address
         // CITY
         if ( fCityError == true )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " City" ;
            numErrors++ ;
         }// end checking city
         // ZIPCODE
         if ( fZipcodeError == true )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Postal code" ;
            numErrors++ ;
         }// end checking zipcode
         // USERNAME
         if ( document.RegistrationPage.Username.value == "" )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Username" ;
            numErrors++ ;
         }// end checking username
         // PASSWORD
         if ( fPasswordError == true )
         {
            if ( numErrors > 0 )
               ErrorString += ", " ;
            ErrorString += " Password" ;
            numErrors++ ;
         }// end checking password
         ErrorString += "." ;
      } // end checking all strings for sufficient length.

      var fmtFirstname = true ;
      var fmtLastname  = true ;
      var fmtUsername  = true ;
      var fmtPassword  = true ;

      // test for valid characters in FIRSTNAME field: allow only alphabetic chars
      var str = document.RegistrationPage.Firstname.value.toString() ;
      if ( str.match(patternName) )
         fmtFirstname = false ;

      // test for valid characters in LASTNAME field: allow only alphabetic chars
      str = document.RegistrationPage.Lastname.value.toString() ;
      if ( str.match(patternName) )
         fmtLastname = false ;

      // test for valid characters in USERNAME field: allow only alphanumeric chars
      str = document.RegistrationPage.Username.value.toString() ;
      if ( str.match(patternZipCode) )
         fmtUsername = false ;

      // test for valid characters in PASSWORD field: allow only alphanumeric chars
      if ( document.getElementById('Password') )
      {
         str = document.RegistrationPage.Password.value.toString() ;
         if ( str.match(patternZipCode) )
            fmtPassword = false ;
      }

      // Any error set the character error flag to "true".
      if ( !fmtFirstname || !fmtLastname || !fmtUsername || !fmtPassword )
      {
         fErrorChar = true ;
         if ( fErrorLength == true )
         {
            // separate the two error sets by two line feeds.
            ErrorString += "\n\n" ;
         } // end dealing with stringing two error type message together.

         // append the generic error indication (at least one formatting error found).
         ErrorString += "Invalid characters were entered in one or more fields." ;

         if ( !fmtFirstname )
            ErrorString += "\n-- Firstname: alphabetic characters only [a-z, A-Z]." ;
         if ( !fmtLastname )
            ErrorString += "\n-- Lastname: alphabetic characters only [a-z, A-Z]." ;
         if ( !fmtUsername )
            ErrorString += "\n-- Username: alphanumeric characters only [0-9, a-z, A-Z]." ;
         if ( !fmtPassword )
            ErrorString += "\n-- Password: alphanumeric characters only [0-9, a-z, A-Z]." ;
      } // end handling at least one formatting error.

      // Test to enforce at least 4 digits in a password.
      if ( document.getElementById('Password') )
      {
         var length = document.RegistrationPage.Password.value.length ;
         if ( length < 4 )
         {
            numErrors++ ;
            if ( fErrorLength == true || fErrorChar == true )
               ErrorString += "\n\n" ;
            ErrorString += "Password length must be at least four characters." ;
         } // end enforcing minimum # characters in a password.

         // Now test to make sure that the two entered password fields match.
         if ( document.RegistrationPage.Password.value != document.RegistrationPage.Password2.value )
         {
            numErrors++ ;
            if ( fErrorLength == true || fErrorChar == true || numErrors > 0 )
               ErrorString += "\n\n" ;
            ErrorString += "Password mismatch: values entered for both fields must match." ;
         }
      }

      // Now test to make sure that the two entered email address fields match.
      /*
      if ( document.RegistrationPage.Email.value != document.RegistrationPage.Email2.value )
      {
         numErrors++ ;
         if ( fErrorLength == true || fErrorChar == true || numErrors > 0 )
            ErrorString += "\n\n" ;
         ErrorString += "Email address mismatch: values entered for both fields must match." ;
      }
      */
   }// end checking page one.
   else if ( document.getElementById('SVAccountNum') != null ) 
   {
      // **************************************************************************************
      // PAGE TWO
      // **************************************************************************************
      // no character length restrictions will be imposed.
      // this means, simply, that we do not require a delivery address.
      var IsSVAccountRequired = "" ;
      if ( document.getElementById('SVNR') != null )
         IsSVAccountRequired = document.RegistrationPage.SVNR.value ;
      
      if ( IsSVAccountRequired == "Y" )
      {
         if ( document.RegistrationPage.SVAccountNum.value == "" )
         {
	        fErrorLength = true ;
	        ErrorString += "The following required fields(s) were not completed: " ;
	        ErrorString += " Account Number." ;
         }
      }
   } // else placing restrictions on page two items.
   else if ( document.getElementById('CreditCardType_') != null ) 
   {
      // **************************************************************************************
      // PAGE THREE
      // **************************************************************************************

      // test for valid characters in CARDNUMBER field: allow only numeric chars
      var fmtAccountNum = true ;
      var str = document.RegistrationPage.AccountNum_.value.toString() ;
      if ( str.match(patternCCNum) )
         fmtAccountNum = false ;

      if ( !fmtAccountNum )
      {
         fErrorChar = true ;
         if ( fErrorLength == true)
            ErrorString += "\n\n" ;
         // append the generic error indication (at least one formatting error found).
         ErrorString += "Invalid characters were entered in one or more fields." ;
         ErrorString += "\n-- Card Number: numeric characters only [0-9]." ;
      }
   } // else placing restrictions on page 2 items.


   if ( fErrorLength == true || numErrors > 0 || fErrorChar == true )
   {
      alert ( ErrorString ) ;
      return false ;
   }
   // ***********************************************************************
   // We reach here only if an "early return" was not executed.
   // No errors found during client-side validation; submit to the server.
   // ***********************************************************************   
   return true ;
}


// ******************************************************************************
// formValidate_PasswordChange
// -----------------------------------------------------------------------------
// Client side validation of values entered into the PasswordChange form
// associated with the Registration class of the eMenu application.  Again,
// we do client side checking to avoid some round-trips for errors we can
// catch locally.  This validation only makes sure that the password value
// passed is at least 4 chars and the two entries match.
// ******************************************************************************
function formValidate_PasswordChange()
{
   var fErrorLength = false ;
   var fErrorMatch  = false ;
   var ErrorString  = "One or more data errors exist.\n\n" ;

   if ( document.PasswordChangeForm.Password.value == "" )
   {
      fErrorLength = true ;
      ErrorString += "The following required field(s) were not completed: Password." ;
   }// end checking password   } // end length check.

   // Now test to make sure that the two entered password fields match.
   if ( document.PasswordChangeForm.Password.value != document.PasswordChangeForm.Password2.value )
   {
      fErrorMatch = true ;
      if ( fErrorLength == true )
         ErrorString += "\n\n" ;
      ErrorString += "Password mismatch: values entered for both fields must match." ;
   } // end checking for value match.

   // Test to enforce at least 4 digits in a password.
   var length = document.PasswordChangeForm.Password.value.length ;
   if ( length < 4 )
   {
      if ( fErrorLength == true || fErrorMatch == true )
         ErrorString += "\n\n" ;
      fErrorLength = true ;
      ErrorString += "Password length must be at least four characters." ;
   } // end enforcing minimum # characters in a password.

   if ( fErrorLength || fErrorMatch )
   {
      alert ( ErrorString ) ;
      return false ;
   }

   return true ;
} // end formValidate_PasswordChange

// ***********************************************************************************
// formValidate_Delivery
// ----------------------------------------------------------------------------------
// Require a phone number too.
// ***********************************************************************************
function formValidate_Delivery()
{
   var fErrorLength = false ;
   var fErrorChar   = false ;
   var fErrorPhoneFmt = false ;
   var fErrorPhoneLength = false ;

   var ErrorString  = "One or more data errors exist.\n\n" ;
   var patternNum   = /[^0-9]/g ;             // street number check - numbers only
   var patternPhone = /^\+?[0-9 ()-.]+[0-9]$/ ;             // phone number check - numbers only

   // **********************************************************************************
   // Address: free form only
   // **********************************************************************************
   if ( document.getElementById('Address') != null )
   {
      if ( document.Delivery.Address.value == "" )
      {
	  if ( fErrorLength == false )
	     ErrorString += "The following required field(s) were not completed: Address" ;
	  else
	     ErrorString += ", Address" ;

         fErrorLength = true ;
      }
   } // end requiring address


   // **********************************************************************************
   // Street number (restricted delivery only)
   // **********************************************************************************
   if ( document.getElementById('Number') != null ) 
   {
      if ( document.Delivery.Number.value == "" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: Address (street #)" ;
         else
	        ErrorString += ", Address (street #)" ;
         fErrorLength = true ;
      }
   } // end validating presence of number field, if appropriate (restricted delivery only).
   
   // **********************************************************************************
   // Street Name: retricted delivery only
   // **********************************************************************************
   if ( document.getElementById('StreetName') != null )
   {
      if ( document.getElementById('StreetName').value == "[Choose Street]" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: Address (street name)" ;
         else
	        ErrorString += ", Address (street name)" ;

         fErrorLength = true ;
      } // end requiring selected street name other than [Choose Street]
   } // end validating restricted delivery street name selection
   
   // **********************************************************************************
   // City
   // **********************************************************************************
   if ( document.getElementById('City') != null )
   {
      if ( document.Delivery.City.value == "" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: City" ;
         else
	        ErrorString += ", City" ;

         fErrorLength = true ;
      }
   }

   // **********************************************************************************
   // State
   // **********************************************************************************
   if ( document.getElementById('[Choose State]') != null )
   {   
      if ( document.Delivery.State.value == "[Choose State]" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: State" ;
         else
	        ErrorString += ", State" ;

         fErrorLength = true ;
      }
   }

   // **********************************************************************************
   // Zip code
   // **********************************************************************************
   if ( document.getElementById('Zipcode]') != null )
   {     
      if ( document.Delivery.Zipcode.value == "" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: Postal code" ;
         else
            ErrorString += ", Postal code" ;
         fErrorLength = true ;
      }
   }
   
   // ************************************************************************************
   // Cross Street field value enforcement.
   // Field is enforced if and only if:
   //   a) The field is actually in the form.  If missing, obviously we do not enforce.
   //   b) If a is true, then we look to see what the value of a secondary (hidden) field
   //      is (IsCrossStreetRequired).  If that's Y then it is enforced.
   // ************************************************************************************
   if ( document.getElementById('CrossStreet') != null )
   {      
      if ( document.getElementById('IsCrossStreetRequired') != null )
      {
         if ( document.Delivery.IsCrossStreetRequired.value == 'Y' )
         {
            if ( document.Delivery.CrossStreet.value == "" )
            {
               if ( fErrorLength == false )
                  ErrorString += "The following required field(s) were not completed: Cross Street" ;
               else
   	           ErrorString += ", Cross Street" ;

               fErrorLength = true ;
            } // no value...
         } // is enforced...
      } // field is present...
   }
   
   // ************************************************************************************
   // Room Name or descriptor
   // ************************************************************************************
   if ( document.getElementById('RoomName') != null )
   {      
      if ( document.Delivery.RoomName.value == "" )
      {
         if ( fErrorLength == false )
            ErrorString += "The following required field(s) were not completed: Room Name" ;
         else
   	     ErrorString += ", Room Name" ;

         fErrorLength = true ;
      }
   }   

   // If necessary, stick a terminating punctuation mark on the sentence.
   if ( fErrorLength == true )
      ErrorString += "." ;

   // test for valid characters in Street Number field: allow only numeric chars
   if ( document.getElementById('Number') != null ) 
   {
      var fmtStreetNum = true ;
      var str = document.Delivery.Number.value.toString() ;
      if ( str.match(patternNum) )
         fmtStreetNum = false ;

      if ( !fmtStreetNum )
      {
         fErrorChar = true ;
         if ( fErrorLength == true)
            ErrorString += "\n\n" ;
         // append the generic error indication (at least one formatting error found).
         ErrorString += "Invalid characters were entered in one or more fields." ;
         ErrorString += "\n-- Street #: numeric characters only [0-9]." ;
      }
   } // end validating number value (if appropriate).


   // **********************************
   // test for valid phone number.
   // **********************************
   if ( document.getElementById('RequirePhoneNumber') != null )
   {
      // We only enforce this test if the form includes a variable indicating
      // that it must be enforced: RequirePhoneNumber
      if ( document.Delivery.RequirePhoneNumber.value == "Y" )
      {
         var fmtPhoneNum = true ;
         var phoneNum = document.Delivery.Phone.value.toString() ;
 
	     var plen = phoneNum.length ;
         if ( plen < 7 || plen > 20 )
         {
            fErrorPhoneLength = true ;
         }

         // Make sure we have at least ten actual numbers.
         /*var numdigits = 0;
         for (var j=0; j<phoneNum.length; j++)
            if (phoneNum.charAt(j)>='0' && phoneNum.charAt(j)<='9') 
               numdigits++ ;
         if ( numdigits < 10 || numdigits > 10 )
            fErrorPhoneLength = true ;

         // allow numbers, hyphen, space
         if ( !patternPhone.test(phoneNum) )
            fErrorPhoneFmt = true ;
         */
         if ( /*fErrorPhoneFmt ||*/ fErrorPhoneLength )
         {
            if ( fErrorLength == true /*|| fErrorChar == true*/ )
            {
      	       ErrorString += "\n\n" ;
            }
            /*if ( fErrorPhoneFmt )
            {
	           ErrorString += "Invalid characters entered in the phone number field." ;
   	           ErrorString += "\n-- Numerals (0-9), hyphen, period, or space only." ;
            }*/
            if ( fErrorPhoneLength )
            {
      	       if ( ErrorString.length > 0 )
   	              ErrorString += "\n" ;
               ErrorString += "Invalid phone number length--please provide at least a 7-digit phone number." ;
            } // end adding phone # format instruction.
         } // end if there is an error 
      } // end if the value of RequirePhoneNumber is Y.
   } // end if RequirePhoneNumber field is present

   // ***********************************************************************
   // Make sure that the special instructions field does not exceed the
   // maximum number of allowed characters (1000).
   // ***********************************************************************
   if ( document.getElementById('SpecialInstructions') != null )
   {
      var si = document.getElementById('SpecialInstructions') ;

      if ( si.value.length > 350 )
      {
         fErrorLength = true ;
	     ErrorString += "\n" ;
	     ErrorString += "Special instructions text length (" + si.value.length + ") exceeds maximum allowable length of 350 characters." ;
      } // end formatting error message.
   } // end testing for field max violation for special instructions.

   // **********************************************
   // If ANY error, showi it and halt the user
   // **********************************************
   if ( fErrorLength || fErrorChar || fErrorPhoneFmt || fErrorPhoneLength )
   {
      alert ( ErrorString ) ;
      return false ;
   }

   return true ;
} // end formValidate_Delivery

// *****************************************************************************
// SetTimer_UserPrompt
// ----------------------------------------------------------------------------
// Javascript routine tha sets a timer with a value based upon the context.
// Method is used ONLY by the UserPrompt page.  It is more special purpose than
// the SetTimer() method in that it needs to set a timer accordingly to a 
// context.  All other pages set only one timer: abandonment (TO1)...while the
// UserPrompt page needs to set one of three timers: abandonment (TO1), 
// abandonment (TO2) prompt timeout, and post-sale (TO3) timeout.
// As the name indicates, this function is used only by the UserPrompt page.
// *****************************************************************************
function SetTimer_UserPrompt()
{
   // First we extract our current context from the query string so that
   // we can preserve context when we redirect.
   var qs = location.search.substring(1) ;
   var cmd = "" ;
   //var mall = "" ;
   //var store = "" ;
   
   var pairs = qs.split("&") ;
   for ( var i=0; i < pairs.length; i++ )
   {
      var pos = pairs[i].indexOf('=') ;
      if ( pos == -1 )
         continue ;

      var arg = pairs[i].substring(0,pos) ;
      var val = pairs[i].substring(pos+1) ;
      
      if ( arg == 'o' )
      {
         cmd = val ;
      }
      /*
      else if ( arg == 'm' )
      {
         mall = val ;
      }
      else if ( arg == 's' )
      {
         store = val ;
      }*/
   } // end for loop on extracting query string context.
   
   // Retrieve our KioskID and timer values from installed cookies.
   // An ASP.NET page installs all of these cookie values.
   var KioskID     = getCookieValue ( "eMenuKiosk" ) ;
   var TOAbandoned = getCookieValue ( "TO1" ) * 1000 ;
   var TOPrompt    = getCookieValue ( "TO2" ) * 1000 ;
   var TOPostSale  = getCookieValue ( "TO3" ) * 1000 ;

   // alert ( "TO1: " + AbandonedTimer + ", TO2: " + GeneralTimer + ", TO3: " + PostPaymentTimer ) ;
   
   // Page context determines our current state and which of the timers
   // to install.
   var Timeout = 0 ;
   if ( cmd == 'os' ) // set timer to "post sale"
      Timeout = TOPostSale ;
   else if ( cmd == 'ato' ) // set timer to prompt the user
      Timeout = TOPrompt ;
   else // all else: looking for abandonments.
      Timeout = TOAbandoned ;
   
   // We only start the timer if we're in Kiosk mode and we determined a context that set a timeout value.
   if ( (KioskID > 0 || ForceKioskMode == 1) && Timeout > 0 )
   {  
      window.setTimeout( "redirect_UserPrompt()", Timeout ) ;
            //alert ( "KioskID: " + KioskID + ", abandonment timer value to be set: " + Timeout ) ;
   }
} // end SetTimer_UserPrompt()
// *******************************************************************************
// redirect_UserPrompt
// ------------------------------------------------------------------------------
// Routine pushes the user to a specifically chosen page based upon the context.
// As the name indicates, this redirect page is used only by the UserPrompt 
// ASP.NET page.
// *******************************************************************************
function redirect_UserPrompt()
{
   var qs = location.search.substring(1) ;

   var mall  = "" ;
   var store = "" ;
   var cmd   = "" ;
   var c     = "" ;
   
   var pairs = qs.split("&") ;
   for ( var i=0; i < pairs.length; i++ )
   {
      var pos = pairs[i].indexOf('=') ;
      if ( pos == -1 )
         continue ;

      var arg = pairs[i].substring(0,pos) ;
      var val = pairs[i].substring(pos+1) ;

      if ( arg == 'm' )
      {
         mall = val ;
      } else if ( arg == 's' )
      {
         store = val ;
      } else if ( arg == 'o' )
      {
         cmd = val ;
      } else if ( arg == 'c' )
      {
         c = val ;
      }
   } // end for loop
   
   var url = "Reset.aspx" ;
   if ( cmd != 'ato' && cmd != 'os' )
      url = "UserPrompt.aspx" ;
   url += "?m=" + mall ;
   url += "&s=" + store ;
   if ( cmd != 'os' && cmd != 'ato' )
      url += "&o=ato" ;

   var KioskEndSession = document.forms[0].KioskEndSession.value ;
   //alert ( "KioskEndSession: " + KioskEndSession ) ;
   
   if ( KioskEndSession == 'Y' )
      self.close() ;

   window.location = url ;
} // end redirect_UserPrompt()

// **************************************************************************
// SignOutEndSessionCheck
// -------------------------------------------------------------------------
// Method checks to see if EndSession form variable is set to "Y" ...
// if so, executes browser close command.
// **************************************************************************
function SignOutEndSessionCheck()
{
   var EndSession = document.forms[0].EndSession.value ;

   alert ( "EndSession: " + EndSession ) ;

   if ( EndSession == "Y" ) 
      self.clsose() ;

   return ;
} // end SignOutEndSessionCheck


// **************************************************************************
// HandleKeypadClick
// -------------------------------------------------------------------------
// Handle a numeric button click and insert the associated value into the
// edit box included in the form.
// **************************************************************************
function HandleKeypadClick(num)
{
   //var btnClicked = num ;

   var PIN = document.PinPad.PIN.value ;

   if ( num >= 0 && num <= 9 )
   {
      var length = PIN.length ;
      if ( length < 4 )
         document.PinForm.PIN.value += num ;
   }
   else
   { 
      var length = PIN.length ;
      var newPIN = PIN.substring(0, length-1) ;
      document.PinForm.PIN.value = newPIN ;
   }

   return false ;
} // end HandleKeypadClick

// **************************************************************************
// HandleQuantityKeypadClick
// -------------------------------------------------------------------------
// Handle a numeric button click and insert the associated value into the
// edit box included in the form.
// **************************************************************************
function HandleQuantityKeypadClick( num )
{
   //var btnClicked = num ;

   var QuantityValue = document.forms[0].Quantity.value ;
   var MaxLength     = document.forms[0].MaxLength.value ;

   // alert ( "num: " + num ) ;

   if ( num >= 0 && num <= 9 )
   {
      var length = QuantityValue.length ;
      
      if ( length < MaxLength )
         document.forms[0].Quantity.value += num ;
   }
   else if ( num == 10 )
   { 
      var length = QuantityValue.length ;
      var newQuantity = QuantityValue.substring(0, length-1) ;
      document.forms[0].Quantity.value = newQuantity ;
   }
   else if ( num == 11 )
   {
      document.forms[0].Quantity.value = '' ;
   }

   return false ;
} // end HandleKeypadClick
// **************************************************************************
// formKeypad_Validate
// -------------------------------------------------------------------------
// Checks the value in the edit field of the form for validity.
// **************************************************************************
function formKeypad_Validate()
{
   var PIN = document.PinForm.PIN.value ;
   var length = PIN.length ;
   var patternPIN   = /[^0-9]/g ;             // credit number check - numbers only

   if ( length != 4 )
   {
      alert ( "Error: PIN entered must be 4-digits in length." ) ;
      return false ;
   }

   /*
      // test for valid characters in the PIN field
   var str = document.PinForm.PIN.value.toString() ;
   var resultPIN = true ;
   if ( !str.match(patternPIN) )
      resultPIN = false ;

   if ( resultPIN == false )
   {
      alert ( "Error: a PIN may only contain a numeric (0-9) value." ) ;
      return false ;
   }
   */
   return true ;
} // end formKeypad_Validate

// **************************************************************************
// submitForm
// -------------------------------------------------------------------------
// Method is invoked via onclick method for a form.  Purpose is to allow
// form processing once and only once--to inhibit double clicking.
// The blockIt() function is a dummy function included to redirect the
// action event after the first click.
// **************************************************************************
function submitForm()
{
   // force ASP.NET to submit the form.
   document.forms[0].submit() ;

   // This statement "renames" the submitForm method to be the blockIt method.
   // In other words, after the first time the submitForm() function is called,
   // javascript will instead be calling the blockIt() function (which does
   // nothing).
   submitForm = blockIt ;

   return false ;
} // end submitForm
// **************************************************************************
// blockIt
// -------------------------------------------------------------------------
// blockIt does absolutely nothing...intentionally.  After the initial
// button click in a form, the submitForm() method accepts the first one
// and then changes the "action" of the form to the blockIt() function...
// thereby preventing double-submits.
// **************************************************************************
function blockIt()
{
   // blockIt() does nothing, intentionally.
   return false ;
} // end blockIt


// **************************************************************************
// useAddress
// -------------------------------------------------------------------------
// Used by DeliveryPage.aspx.cs
// 
// useAddress is an attempt at using javascript to create some DHTML.  When
// a user clicks on a certain checkbox within the delivery page form, the
// user's billing address is inserted into the form's fields for delivery
// address.
// **************************************************************************
function useAddress()
{
   if ( document.getElementById('UseDelivery') != null )
   {
      var cbox = (document.getElementById('UseDelivery')).value ;

      if ( cbox == "on" )
      {
         // Insert Phone value
         if ( document.getElementById('bPhone') != null )
         {
            var p = (document.getElementById('bPhone')).value ;
            document.forms[0].Phone.value = p ;
         } // end phone

         // Insert Phone2 value
         if ( document.getElementById('bPhone2') != null )
         {
            var p = (document.getElementById('bPhone2')).value ;
            document.forms[0].Phone2.value = p ;
         } // end phone2

         // Insert Fax value
         //if ( document.getElementById('bFax') != null )
         //{
         //   var p = (document.getElementById('bFax')).value ;
         //   document.forms[0].Fax.value = p ;
         //} // end fax
      
         // Insert Address value
         if ( document.getElementById('bAddress1') != null )
         {
            var p = (document.getElementById('bAddress1')).value ;
            document.forms[0].Address.value = p ;
         } // end address

         // Insert Address2 value
         if ( document.getElementById('bAddress2') != null )
         {
            var p = (document.getElementById('bAddress2')).value ;
            document.forms[0].Address2.value = p ;
         } // end address2

         // Insert City
         if ( document.getElementById('bCity') != null )
         {
            var p = (document.getElementById('bCity')).value ;
            document.forms[0].City.value = p ;
         }// end city

         // Insert Zipcode
         if ( document.getElementById('bZipcode') != null )
         {
            var p = (document.getElementById('bZipcode')).value ;
            document.forms[0].Zipcode.value = p ;
         } // end zipcode

         // Select State
         if ( document.getElementById('bState') != null )
         {
            var p = (document.getElementById('bState')).value ;
         
	        if ( p != "" )
            {
               document.forms[0].State.value = p ;
            }
         } // end state
         
         // Select Country
         if ( document.getElementById('bCountry') != null )
         {
            var p = (document.getElementById('bCountry')).value ;
         
	        if ( p != "" )
            {
               document.forms[0].Country.value = p ;
            }
         } // end state         
      } // end if 'UseDelivery' check box is checked "on".
   } // end if the control is present in the page.
   
   return ;
} // end useAddress

// *************************************************************************
// enableMailControls
// ------------------------------------------------------------------------
// *************************************************************************
function enableMailControls()
{
    if ( document.Trans.Sendmail.checked == true )
       document.Trans.ConfirmationEmailAddress.disabled = false ;
    else
       document.Trans.ConfirmationEmailAddress.disabled = true ;

    return true ;
}

// *************************************************************************
// enableRegistration
// ------------------------------------------------------------------------
// *************************************************************************
function enableRegistration()
{
    if ( document.RegistrationPage.Terms.checked == true )
       document.RegistrationPage.Finish.disabled = false ;
    else
       document.RegistrationPage.Finish.disabled = true ;
    return true ;
}


// **************************************************************************
// enablePreOrders
// -------------------------------------------------------------------------
// 
// **************************************************************************
function enablePreOrders ( choice )
{
   //alert ( "Radio button picked: " + choice ) ;

   if ( choice == "Now" )
   {
      document.PreOrderForm.DateOfOrder.disabled = true ;
      document.PreOrderForm.Hour.disabled = true ;
      //document.PreOrderForm.Minute.disabled = true ;
//      document.Trans.DateLabel.disabled = true ;
//      document.Trans.TimeLabel.disabled = true ;
   }
   else
   {
      document.PreOrderForm.DateOfOrder.disabled = false ;
      document.PreOrderForm.Hour.disabled = false ;
      //document.PreOrderForm.Minute.disabled = false ;
//      document.Trans.DateLabel.disabled = false ;
//      document.Trans.TimeLabel.disabled = false ;
   }

   return true ;
} // end enablePreOrders

// ******************************************************************************
// EnableLowBalanceControls
// -----------------------------------------------------------------------------
// ******************************************************************************
function EnableLowBalanceControls()
{
    //alert ( "EnableLowBalanceControls()" ) ;
    //if ( document.getElementById('AllowLowBalanceNotification') != null )
       document.RegistrationPage.LowBalanceAmount.disabled = false ;
    //if ( document.getElementById('AutoReplenishment' != null )
       document.RegistrationPage.ReplenishmentAmount.disabled = true ;

    return true ;
}
// ******************************************************************************
function EnableAutoReplenishmentControls()
{
    //alert ( "EnableAutoReplenishmentControls()" ) ;

    EnableLowBalanceControls() ;

    //if ( document.getElementById('AutoReplenishment' != null )
       document.RegistrationPage.ReplenishmentAmount.disabled = false ;

    return true ;
}
// ******************************************************************************
function DisableAutoReplenishmentControls()
{
    //if ( document.getElementById("BalanceNotification' != null )
       document.RegistrationPage.LowBalanceAmount.disabled    = true ;
    //if ( document.getElementById('ReplenishmentAmount' != null )
       document.RegistrationPage.ReplenishmentAmount.disabled = true ;

    return true ;
}

// *******************************************************************************************
// EnableTenderTypeControls
// ------------------------------------------------------------------------------------------
// 
// *******************************************************************************************
function EnableTenderTypeControls()
{

   var PaymentType = document.forms[0].CreditCardType_.value ;
   //alert ( "Got EnableTenderTypeControls() call: " + PaymentType + " charAt[0]: " + PaymentType.charAt(0) ) ;

   if ( PaymentType.charAt(0) == '1' )
   {

      document.forms[0].AccountNum_.disabled = false ;
      document.forms[0].ExpirationMonth_.disabled = false ;
      document.forms[0].ExpirationYear_.disabled = false ;

      document.forms[0].AccountNum_.style.visibility='visible' ;
      document.forms[0].ExpirationMonth_.style.visibility='visible' ;
      document.forms[0].ExpirationYear_.style.visibility='visible' ;

      document.getElementById( "lb1" ).style.visibility='visible' ;
      document.getElementById( "lb2" ).style.visibility='visible' ;
      document.getElementById( "lb3" ).style.visibility='visible' ;

      var RequireCVV  = document.getElementById( "RequireCVV" ) ; // document.forms[0].RequireCVV.value ;
      if ( RequireCVV == 'Y' )
      {
	 document.forms[0].CVV.disabled = false ;
	 document.getElementById( "CVV_Label" ).style.visibility='visible' ;
	 document.getElementById( "CVV" ).style.visibility='visible' ;
	 document.getElementById( "RequireCVV" ).style.visibility='visible' ;
	 document.getElementById( "WhatIsCVV" ).style.visibility='visible' ;
	 document.forms[0].CVV.style.visibility='visible' ;         
      }

   }
   else
   {
      document.forms[0].AccountNum_.disabled = true ;
      document.forms[0].ExpirationMonth_.disabled = true ;
      document.forms[0].ExpirationYear_.disabled = true ;

      document.forms[0].AccountNum_.style.visibility='hidden' ;
      document.forms[0].ExpirationMonth_.style.visibility='hidden' ;
      document.forms[0].ExpirationYear_.style.visibility='hidden' ;

      document.getElementById( "lb1" ).style.visibility='hidden' ;
      document.getElementById( "lb2" ).style.visibility='hidden' ;
      document.getElementById( "lb3" ).style.visibility='hidden' ;

      var RequireCVV  = document.getElementById( "RequireCVV" ) ; // document.forms[0].RequireCVV.value ;
      
      if ( RequireCVV != null )
      {
         if ( RequireCVV == 'Y' )
         {
	       document.forms[0].CVV.disabled = true ;
	       document.getElementById( "CVV_Label" ).style.visibility='hidden' ;
	       document.getElementById( "CVV" ).style.visibility='hidden' ;
	       document.getElementById( "RequireCVV" ).style.visibility='hidden' ;
	       document.getElementById( "WhatIsCVV" ).style.visibility='hidden' ;
	       document.forms[0].CVV.style.visibility='hidden' ;         
         } // end y to require cvv
      } // end require cvv
   } // end else


   return true ;
} // end EnableTenderTypeControls

// ****************************************************************************
// EnableOrderHistoryReceiptView
// ---------------------------------------------------------------------------
// Enables the View Receipt pushbutton -- triggered by an onclick event
// in the order history list box.
// ****************************************************************************
function EnableOrderHistoryReceiptViewButton()
{
   document.forms[0].ViewReceipt.disabled = false ;
//   document.getElementById( "ViewReceipt" ).disabled = false ;
   return ;
} // end EnableOrderHistoryReceiptView

// ****************************************************************************
// EnableCancelScheduledOrderButton
// ---------------------------------------------------------------------------
// Enables the View Receipt pushbutton -- triggered by an onclick event
// in the order history list box.
// ****************************************************************************
function EnableCancelScheduledOrderButton()
{
   document.forms[0].CancelOrder.disabled = false ;
   document.forms[0].ViewReceipt.disabled = false ;
   
   return ;
} // end EnableCancelScheduledOrderButton

// ***************************************************************************
// EnableRoomListControl
// --------------------------------------------------------------------------
// ***************************************************************************
function EnableRoomListControl()
{
   var idList = document.getElementById( "Room" ) ;
   var idTextInput = document.getElementById ( "RoomDescriptor" ) ;

   idList.disabled = false ;
   idTextInput.disabled = true ;

   return ;
} // end EnableRoomListControl

// ***************************************************************************
// EnableTextInputControl
// --------------------------------------------------------------------------
// ***************************************************************************
function EnableTextInputControl()
{
//   alert ( "Entered EnableTextInputContro()" ) ;

   var idList = document.getElementById( "Room" ) ;
   var idTextInput = document.getElementById ( "RoomDescriptor" ) ;

   idList.disabled = true ;
   idTextInput.disabled = false ;

   return ;
} // end EnableTextInputControl



// ****************************************************************************
// formEnable_TransactionDetail
// ---------------------------------------------------------------------------
// Function enables/disables the form's OK button based upon whether or not
// at least one order item is checked (on).  Prevents empty return attempts.
// ****************************************************************************
function formEnable_TransactionDetail ()
{
   var numtrue ;
   numtrue = 0 ;

   for ( i=0; i < document.TransactionDetail.length ; i++ )
   {
      if ( document.TransactionDetail.elements[i].value == 'on' && document.TransactionDetail.elements[i].type == 'checkbox' && document.TransactionDetail.elements[i].checked )
      {
         numtrue = numtrue + 1 ;
//         alert ( "control: " + document.TransactionDetail.elements[i].type + ", " + document.TransactionDetail.elements[i].value
//                 + ", " + document.TransactionDetail.elements[i].checked ) ;
      }
   }

//   alert ( "numtrue: " + numtrue ) ;

   if ( numtrue > 0 )
      document.TransactionDetail.OK.disabled = false ;
   else
      document.TransactionDetail.OK.disabled = true ;

   return ;
} // end formEnable_TransactionDetail




// **************************************************************************
// addHiddenField
// -------------------------------------------------------------------------
// Appends a hidden input field (name, value) to a form.
// **************************************************************************
function appendFieldText ( form, fieldName, fieldValue )
{
   //var text = document.forms[0].CLICK_COUNT.value ;
   //text += " CLICK" ;
   //document.forms[0].CLICK_COUNT.value = text ;


   // Two different ways to inject the hidden field...depending upon browser support.
   if ( form.insertAdjacentHTML )
   {
       var html = '' ;
       html += '<input type="hidden" name="' + fieldName + '" value="' + fieldValue + '"/>' ;
       form.insertAdjacentHTML( 'beforeEnd', html ) ;
   }

/*
   else if ( document.createElement )
   {
       var input = document.createElement( 'input' ) ;
       input.type = 'hidden' ;
       input.name = fieldName ;
       input.value = fieldValue ;
       form.appendChild( input ) ;
   }
*/
} // end addHiddenField

// ************************************************************************
// selectNewDay()
// -----------------------------------------------------------------------
// Function supports the PreOrder page and allows a user to select
// a different day and have the time drop-down populated with valid times
// for that day.  This is for when the pre order page is supporting
// time entries per day from the ePreOrderSchedule database table.
// The new times to populate in the list box come from hidden fields
// populated by the C# code.
// ************************************************************************
function selectNewDay()
{
   var form    = document.forms[0] ;
   var lb_time = form.Time ;

   // Retrieve the newly chosen Date value.
   var lb_date = form.DateOfOrder ;
   var curDate = lb_date.options[lb_date.selectedIndex].value ;
   
   var bFoundComma = false ;
   var length = curDate.length ;

   var whereisit = curDate.indexOf(',') ;

   if ( whereisit >= 0 )
   {
      var DayOfWeek = curDate.substring( 0, whereisit ) ;
   }

   // clear the time list box:
   lb_time.options.length = 0 ;

   // loop through and add the "day specific" time list items.
   var i = 1 ;

   do
   {
      var ID = DayOfWeek + "_" + i.toString() ;
      var IDvalue = form.elements[ID].value ;

      lb_time.options[i-1] = new Option( IDvalue ) ;

      i = i + 1 ;
   } while ( IDvalue != null ) ;

   return true ;
} // end selectNewDay()


// **************************************************************************
// addHiddenField
// -------------------------------------------------------------------------
// Appends a hidden input field (name, value) to a form.
// **************************************************************************
function addHiddenField ( form, fieldName, fieldValue )
{
   // Two different ways to inject the hidden field...depending upon browser support.
   if ( form.insertAdjacentHTML )
   {
       var html = '' ;
       html += '<input type="hidden" name="' + fieldName + '" value="' + fieldValue + '"/>' ;
       form.insertAdjacentHTML( 'beforeEnd', html ) ;
   }
   else if ( document.createElement )
   {
       var input = document.createElement( 'input' ) ;
       input.type = 'hidden' ;
       input.name = fieldName ;
       input.value = fieldValue ;
       form.appendChild( input ) ;
   }
} // end addHiddenField


// ***************************************************************************************
// submitOrderHistoryForm
// --------------------------------------------------------------------------------------
// Process a "view receipt" request.  With respect to the order history form, all 
// processing is perfomed on the client side because we need to imitate a hyperlink with
// a specific URL -- to the Receipt.aspx page -- with a specific set of arguments
// including o=[emenu order number] *OR* xo=[eXternal Order #].
//
// So the work of this method is to parse the list item selected to retrieve the 
// order number and understand if it's an internal or external number and cause a new
// window to be opened for the Receipt.aspx page with the appropriate arguments.
// ***************************************************************************************
function submitOrderHistoryForm()
{
   //alert ( "Got View Receipt button click." ) ;
   // ******************************************************************************
   // Grab the selected list item text and parse it to retrieve internal or external
   // order number, as revealed.
   // ******************************************************************************
   // addHiddenField ( document.forms[0], 'ItemText' + i,  itemList.options[i].text ) ;
   // addHiddenField ( document.forms[0], 'ItemValue' + i, itemList.options[i].value ) ;
   
   //alert ( "ID: " + document.activeElement.id ) ;

   //if ( document.activeElement.id == "ViewReceipt" )
   //{
      //alert ( "Got View Receipt button click." ) ;

   
      var itemdata = document.forms[0].OrderData.value ;
      var fExternalCheckNumber = true ;
      var CheckNumber = "" ;

      // alert ( itemdata + ", length: " + itemdata.length ) ;

      // Decide if this is an internal or external check number.
      // # => external check number
      // @ => internal check number
      // NEITHER => internal check number, but strip it differently.
      var sIndicator = itemdata.substring ( 0, 1 ) ;
      if ( sIndicator == '#' )
         fExternalCheckNumber = true ;
      else
         fExternalCheckNumber = false ;

      // Parse the check number (order id).    
      //var i = itemdata.indexOf( '.', 0 ) ;
      //i-- ;
      if ( sIndicator == '#' || sIndicator == '@' )
         CheckNumber = itemdata.substring( 1, itemdata.length ) ;
      else
         CheckNumber = itemdata ;
         
      //alert ( "Check #: " + CheckNumber ) ;

      // Prepare a url for the window invocation.
      var url = "Receipt.aspx" ;
      if ( fExternalCheckNumber == true )
         url += "?xo=" ;
      else
         url += "?o=" ;
  
      url += CheckNumber ;

      // Open the new window and we're done.
      window.open( url,
   		"receipt",
   		"height=800,width=500,resizable,status,menubar,toolbar" ) ;

      // ******************************************************************************
      // force ASP.NET to submit the form.
      // This method is commented out to help DOCUMENT the fact that we do *not* want 
      // any server side processing.
      // ******************************************************************************
      //document.forms[0].submit() ;

      // ******************************************************************************
      // This statement "renames" the submitForm method to be the blockIt method.
      // In other words, after the first time the submitForm() function is called,
      // javascript will instead be calling the blockIt() function (which does
      // nothing).
      // We comment this out because we do not actually EVER want to process anything
      // on the server side within this page/form.
      // ******************************************************************************
      // submitOrderHistoryForm = blockIt ;
      return false ;
   //}
   //else // process the form in the ASP page itself.
      //return true ;
} // end submitOrderHistoryForm

// ****************************************************************************
// function submitCancelScheduledOrder
// ---------------------------------------------------------------------------
// ****************************************************************************

function submitCancelScheduledOrder()
{
   var qs = location.search.substring(1) ;
   
   var itemdata = document.Form1.OrderData.value ;
   
   //if ( confirm ( "Are you sure you want to cancel the selected scheduled order?" ) )
   //{
      var m = "" ;
      var s = "" ;
      var c = "" ;
      var pairs = qs.split("&") ;
      for ( var i=0; i < pairs.length; i++ )
      {
         var pos = pairs[i].indexOf('=') ;
         if ( pos == -1 )
            continue ;

         var arg = pairs[i].substring(0,pos) ;
         var val = pairs[i].substring(pos+1) ;

         if ( arg == 'm' )
         {
            m = val ;
         } else if ( arg == 's' )
         {
            s = val ;
         } else if ( arg == 'c' )
         {
            c = val ;
         }
      } // end for loop for extracting name/value pairs from the query string.
   
   
      // We always redirect the user to the "UserPrompt" page to ask them if they
      // want to cancel the scheduled order.
      // Set up the URL accordingly.
      var url = "UserPrompt.aspx" ;
      if ( m == "" )
         m = -1 ;
      if ( s == "" )
         s = -1 ;
      if ( c == "" )
         c = -1 ;
      url += "?m=" + m ; 
      url += "&s=" + s ;
      url += "&c=" + c ;   
   
      url += "&o=cso&id=" + itemdata ;
      // alert ( url ) ;

      window.location =  url ;
      
      //document.forms[0].submit() ;
      //submitCancelScheduledOrder = blockIt ;
   //}
   //else  
      //return false ;
} // end submitCancelScheduledOrder

// ****************************************************************************
// function quantityHighlight
// ---------------------------------------------------------------------------
// ****************************************************************************
function quantityHighlight()
{
   alert ( 'onload executed' ) ;

   document.all('Quantity').Select ;

   return true ;
}




// ***************************************************************************
// ********************** EXPERIMENTAL ***************************************
// ***************************************************************************
// ********************** NOT IN USE *****************************************
// ***************************************************************************

function copyData()
{
    document.myCopy.passwordCopy.value = document.html40.password.value;
    for (var i=0;i < document.html40.radio.length;i++)
        if (document.html40.radio[i].checked)
            document.myCopy.radioCopy.value = i;
    document.myCopy.selectCopy.value = document.html40.select.selectedIndex;
    document.myCopy.textCopy.value = document.html40.text.value;
    document.myCopy.textareaCopy.value = document.html40.textarea.value;
} // end copyData

function mySuspend()
{
    if (document.layers && document.layers['myLayer'] != null)
        document.layers['myLayer'].visibility = 'hidden';
    else if (document.all) {
        document.html40.button.disabled=true;
        document.html40.checkbox.disabled=true;
        document.html40.file.disabled=true;
        document.html40.password.disabled=true;
        for (var i=0;i < document.html40.radio.length;i++)
            document.html40.radio[i].disabled=true;
        document.html40.reset.disabled=true;
        document.html40.select.disabled=true;
        document.html40.submit.disabled=true;
        document.html40.text.disabled=true;
        document.html40.textarea.disabled=true;
    }
    else if (!off) {
        off = !off;
        copyData();
    }
} // end mySuspend

// **************************************************************************
// **************************************************************************
// **************************************************************************
//                         end: emenu.js
// **************************************************************************
// **************************************************************************
// **************************************************************************
-->
