// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    Global Declarations
// #   Function:  Global Declarations
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Nov 6, 1999
// #
// #**********************************************************************************
// #

// #*************************  End: Global Declarations  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    DetectBrowser
// #   Function:  Detect browser version and settings.
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Nov 11, 1999
// #
// #**********************************************************************************
// #

function DetectBrowser()
{
   var userAgent;
   var userAgentVersion;
   var userAgentVersionNum;
   var MinumumVersion     = 4;
   var AlertMessage       = "";


   userAgent        = navigator.userAgent.split(' ');
   userAgent        = userAgent[0].split('/');
   userAgentVersion = userAgent[1];
   userAgent        = userAgent[0];
   userAgentVersionNum = parseFloat(userAgentVersion);

   if (isNaN(userAgentVersionNum)) {
      userAgentVersionNum = 0;
   }

   if ((userAgent != 'Mozilla') || (userAgentVersionNum < MinumumVersion)) {
      AlertMessage = AlertMessage + 
         "It appears that your browser is an older version or non-compliant. \n" +
         "User Agent: " + navigator.userAgent + "\n";

      location.href = "../html/older_browser.html";
   }

   if (AlertMessage != "") {
      AlertMessage = 
            "An Error was Detected! \n" + 
            "\n" + 
            AlertMessage + 
            "\n" + 
            "To use this system you must: \n" +
            "    - use a Mozilla-type (1) browser (Mozilla/" + MinumumVersion + " or higher); \n" +
            "    - enable JavaScript support (JavaScript 1.0 or higher); and \n" +
            "    - enable cookie support. \n" +
            "\n" +
            "(1) Some Mozilla-type browsers are Internet Explorer, Netscape, Opera, Mozilla, and Mozilla Firefox. " +
            "\n" +
            "      Lynx is not a Mozilla-type browser. \n" +
            "\n" +
            "This system works best with Internet Explorer 6.x or Netscape 7.x. \n";

      alert(AlertMessage);
   }

   return false;
}

// #******************************  End Function: DetectBrowser  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GetBrowserEnv
// #   Function:  Get browser environment.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 15, 2002
// #
// #**********************************************************************************
// #

function GetBrowserEnv(form)
{
   var browserName;
   var browserVersion;
   var browserLanguage;
   var browserOS;
   var string;
   var index;
   var start;
   var end;
   var extra;


   if (navigator.appName == 'Netscape') {
      browserLanguage = navigator.language;
   }
   else {
      browserLanguage = navigator.browserLanguage;
   }

   browserName    = navigator.appName;
   browserVersion = navigator.appVersion;

   switch (browserName) {
      case "Microsoft Internet Explorer" :
         index          = browserVersion.indexOf('MSIE');
         browserVersion = navigator.appVersion.substring(index + 5);
         index          = browserVersion.indexOf(';');
         browserVersion = browserVersion.substring(0, index);	
         start          = (navigator.appVersion.indexOf(';') + 1);
         end            = navigator.appVersion.indexOf(')');
         string         = navigator.appVersion.substring(start, end);
         start          = string.indexOf(';') + 2;
         browserOS      = string.substring(start);
         extra          = browserOS.indexOf(';');

         if (extra > 0) {
            browserOS = browserOS.substring(0, extra);		
         }
         break;

      case "Netscape" :
         if (navigator.userAgent.indexOf('Netscape/') > -1) {
            index          = navigator.userAgent.indexOf('Netscape/');
            browserVersion = navigator.userAgent.substring(index + 9);
            browserOS      = navigator.appVersion;
            start          = browserOS.indexOf('(') + 1;
            stop           = browserOS.indexOf(';');
            browserOS      = browserOS.substring(start, stop);
         }
         else {
         if (navigator.userAgent.indexOf('Netscape6/') > -1) {
            index          = navigator.userAgent.indexOf('Netscape6/');
            browserVersion = navigator.userAgent.substring(index + 10);
            browserOS      = navigator.appVersion;
            start          = browserOS.indexOf('(') + 1;
            stop           = browserOS.indexOf(';');
            browserOS      = browserOS.substring(start, stop);
         }
         else {
            index          = browserVersion.indexOf('[');
            browserVersion = browserVersion.substring(0, index);
            browserOS      = navigator.appVersion;
            start          = browserOS.indexOf('(') + 1;
            stop           = browserOS.indexOf(';');
            browserOS      = browserOS.substring(start, stop);
         }
         }
         break;

      default :
         break;
   }

// Raw attributes.
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_appname" VALUE="' + navigator.appName + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_appcodename" VALUE="' + navigator.appCodeName + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_appversion" VALUE="' + navigator.appVersion + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_useragent" VALUE="' + navigator.userAgent + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_platform" VALUE="' + navigator.platform + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_navigator_javaenabled" VALUE="' + navigator.javaEnabled() + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_screen_width" VALUE="' + screen.width + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_screen_height" VALUE="' + screen.height + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_screen_colordepth" VALUE="' + screen.colorDepth + '">');

// Cooked attributes.

   document.write('<INPUT TYPE="hidden" NAME="browser_name" VALUE="' + navigator.appName + ' ' + browserVersion + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_version" VALUE="' + browserVersion + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_platform" VALUE="' + navigator.platform + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_os" VALUE="' + browserOS +'">');
   document.write('<INPUT TYPE="hidden" NAME="browser_screen_resolution" VALUE="' + screen.width + 'x' + screen.height + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_color_depth" VALUE="' + screen.colorDepth + ' bit">');
   document.write('<INPUT TYPE="hidden" NAME="browser_num_colors" VALUE="' + Math.pow(2, screen.colorDepth) + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_language" VALUE="' + browserLanguage + '">');
   document.write('<INPUT TYPE="hidden" NAME="browser_java_enabled" VALUE="' + navigator.javaEnabled() + '">');

   return true;
}

// #***************************  End Function: GetBrowserEnv  ************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    Dummy
// #   Function:  Dummy test routine.
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 21, 1999
// #
// #**********************************************************************************
// #

function Dummy(form)
{
   alert("Dummy");

   return false;
}

// #******************************  End Function: Dummy  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    Format
// #   Function:  Format a number.
// #
// #   Input:     A number or string.
// #   Output:    The formatted number.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  May 28, 1999
// #
// #**********************************************************************************
// #

function Format(UnformattedNumber, NumberFormat)
{
   var FormattedNumber = Number(UnformattedNumber);
   var DecimalIndex;


   switch (NumberFormat) {
      case "currency" :
         FormattedNumber = Math.round(FormattedNumber * 100) / 100;
         FormattedNumber = String(FormattedNumber);

         DecimalIndex = FormattedNumber.lastIndexOf(".");

         if (DecimalIndex < 0) {
            FormattedNumber += ".00";
         }
         if (DecimalIndex == (FormattedNumber.length - 2)) {
            FormattedNumber += "0";
         }

         DecimalIndex = FormattedNumber.lastIndexOf(".");

         if (DecimalIndex == 0) {
            FormattedNumber = "0" + FormattedNumber;
         }
         break;

      default :
         break;
   }

   return FormattedNumber;
}

// #*************************  End Function: Format  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    CalculatePaymentAmounts
// #   Function:  Calculates the amounts on the payment page.
// #
// #   Input:     The form object and field the event was triggered from/
// #   Output:    Recomputes the amounts on the page.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  May 28, 1999
// #
// #**********************************************************************************
// #

function CalculatePaymentAmounts(form, ChangedField)
{
   var PaymentTxnCode = new Array(
                                  "",
                                  "A",
                                  "B",
                                  "E",
                                  "C",
                                  "D"
                                 );
   var Telco, TaxableAmount, DiscountableAmount, DiscountUnits;


   if (typeof(form.telco) == 'undefined') {
      Telco = '';
   }
   else {
      if (form.telco.selectedIndex < 0) {
         Telco = '';
      }
      else {
         Telco = form.telco.options[form.telco.selectedIndex].value;
      }
   }

   if ((ChangedField == "txn_description") || (ChangedField == "txn_quantity") ||
       (ChangedField == "txn_unit_price")) {
      form.txn_extended_price.value = form.txn_quantity.value * form.txn_unit_price.value;

      if (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'A') {
         form.txn_extended_price.value = Number(form.txn_extended_price.value)  +
                                         Number(form.dial_plan_setup_fee.value) +
                                         Number(form.web_plan_setup_fee.value);
      }

      ChangedField = "txn_extended_price";
   }

   if (ChangedField == "txn_extended_price") {

      DiscountableAmount = form.txn_unit_price.value * 12;

      if ((PaymentTxnCode[form.txn_description_list.selectedIndex] == 'A') ||
          (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'B')) {

         // Discounts: Informatica

         if (Telco == "I") {

            // JavaScript doesn't have a integer division operator '\' so do it by longhand.

            DiscountUnits = ((form.txn_quantity.value - (form.txn_quantity.value % 12)) / 12);

            switch (form.dial_plan.value) {
               case "DID1" :
                  form.txn_discount.value = DiscountableAmount * DiscountUnits * .15;
                  break;
   
               case "DID2" :
                  form.txn_discount.value = DiscountableAmount * DiscountUnits * .15;
                  break;

               case "DIUL" :
                  form.txn_discount.value = DiscountableAmount * DiscountUnits * .20;
                  break;

               default :
                  form.txn_discount.value = 0;
                  break;
            }
         }
         else {
            form.txn_discount.value = 0;
         }
      }
      else {
         form.txn_discount.value = 0;
      }

      ChangedField = "txn_discount";
   }

   if (ChangedField == "txn_discount") {
      TaxableAmount = form.txn_extended_price.value - form.txn_discount.value;
      form.txn_gst.value = 0;
      form.txn_pst.value = 0;
      form.txn_hst.value = 0;

      if (form.gst_charged.value == 1) {
         form.txn_gst.value = TaxableAmount * form.gst_rate.value;
      }

      if (form.pst_charged.value == 1) {
         if (form.pst_compounded.value == 1) {
            form.txn_pst.value = (Number(TaxableAmount) + Number(form.txn_gst.value)) * 
                                 form.pst_rate.value;
         }
         else {
            form.txn_pst.value = TaxableAmount * form.pst_rate.value;
         }
      }

      if (form.hst_charged.value == 1) {
         form.txn_hst.value = TaxableAmount * form.hst_rate.value;
      }

      ChangedField = "txn_hst";
   }

   if ((ChangedField == "txn_gst") || (ChangedField == "txn_pst") || 
       (ChangedField == "txn_hst")) {
      form.txn_total.value = form.txn_extended_price.value - Number(form.txn_discount.value) + 
                             Number(form.txn_gst.value) + Number(form.txn_pst.value) + 
                             Number(form.txn_hst.value);
      ChangedField = "txn_total";
   }

   if (ChangedField == "txn_total") {
      form.txn_amount_tendered.value = 0;
      ChangedField = "txn_amount_tendered";
   }

   if (ChangedField == "txn_amount_tendered") {
      form.closing_balance.value = Number(form.opening_balance.value) + 
                                   Number(form.txn_amount_tendered.value);
      ChangedField = "";
   }

   form.txn_unit_price.value      = Format(form.txn_unit_price.value, "currency");
   form.txn_extended_price.value  = Format(form.txn_extended_price.value, "currency");
   form.txn_discount.value        = Format(form.txn_discount.value, "currency");
   form.txn_gst.value             = Format(form.txn_gst.value, "currency");
   form.txn_pst.value             = Format(form.txn_pst.value, "currency");
   form.txn_hst.value             = Format(form.txn_hst.value, "currency");
   form.txn_total.value           = Format(form.txn_total.value, "currency");
   form.txn_amount_tendered.value = Format(form.txn_amount_tendered.value, "currency");
   form.opening_balance.value     = Format(form.opening_balance.value, "currency");
   form.closing_balance.value     = Format(form.closing_balance.value, "currency");

   return true;
}

// #*************************  End Function: CalculatePaymentAmounts  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    CalculateHoursPaymentAmounts
// #   Function:  Calculates the houts amounts on the payment page.
// #
// #   Input:     The form object and field the event was triggered from/
// #   Output:    Recomputes the amounts on the page.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jun 1, 1999
// #
// #**********************************************************************************
// #

function CalculateHoursPaymentAmounts(form, ChangedField)
{
   var PaymentTxnCode = new Array(
                                  "",
                                  "A",
                                  "C",
                                  "D"
                                 );

   if (ChangedField == "txn_description") {
      if (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'A') {
         form.txn_hours.value = form.dial_plan_service_hours.value;
      }

      ChangedField = "txn_hours";
   }

   if (ChangedField == "txn_hours") {
      form.closing_balance.value = Number(form.opening_balance.value) + 
                                   Number(form.txn_hours.value);
      ChangedField = "";
   }

   form.txn_hours.value       = Format(form.txn_hours.value, "currency");
   form.opening_balance.value = Format(form.opening_balance.value, "currency");
   form.closing_balance.value = Format(form.closing_balance.value, "currency");

   return true;
}

// #*************************  End Function: CalculateHoursPaymentAmounts  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    PickMoneyTxnDescription
// #   Function:  Pick a payment transction description from the list.
// #
// #   Input:     The form object and field to send the result to.
// #   Output:    Returns the txn description selected from the list. 
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  May 27, 1999
// #
// #**********************************************************************************
// #

function PickMoneyTxnDescription(form, TxnDescriptionField)
{
   var PaymentTxnCode        = new Array(
                                         "",
                                         "A",
                                         "B",
                                         "E",
                                         "C",
                                         "D"
                                        );

   var PaymentTxnDescription = new Array(
                                         "",
                                         "Initial Payment",
                                         "Prepayment",
                                         "Manual Monthly Charge",
                                         "One-Time Charge",
                                         "Adjustment"
                                        );
   var PaymentTxnQuantity    = new Array(
                                         "",
                                         3,
                                         3,
                                         1,
                                         1,
                                         1
                                        );


   switch (TxnDescriptionField) {
      case "txn_description" :
         form.txn_description.value = 
            PaymentTxnDescription[form.txn_description_list.selectedIndex];
         form.txn_quantity.value = 
            PaymentTxnQuantity[form.txn_description_list.selectedIndex];

         if ((PaymentTxnCode[form.txn_description_list.selectedIndex] == 'A') ||
             (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'B')) {
            form.txn_unit_price.value = Number(form.dial_plan_unit_price.value) +
                                        Number(form.web_plan_unit_price.value);
         }
         else {
            if (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'E') {
               form.txn_unit_price.value = (Number(form.dial_plan_unit_price.value) +
                                            Number(form.web_plan_unit_price.value)) * -1;
            }
            else {
               form.txn_unit_price.value = 0;
            }
         }

         CalculatePaymentAmounts(form, "txn_description");
         break;

      default :
         break;
   }

   return true;
}

// #*************************  End Function: PickMoneyTxnDescription  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    PickHoursTxnDescription
// #   Function:  Pick an hours transction description from the list.
// #
// #   Input:     The form object and field to send the result to.
// #   Output:    Returns the txn description selected from the list. 
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jun 1, 1999
// #
// #**********************************************************************************
// #

function PickHoursTxnDescription(form, TxnDescriptionField)
{
   var PaymentTxnCode        = new Array(
                                         "",
                                         "A",
                                         "C",
                                         "D"
                                        );

   var PaymentTxnDescription = new Array(
                                         "",
                                         "Initial Setup",
                                         "Bonus",
                                         "Adjustment"
                                        );


   switch (TxnDescriptionField) {
      case "txn_description" :
         form.txn_description.value = 
            PaymentTxnDescription[form.txn_description_list.selectedIndex];

         if (PaymentTxnCode[form.txn_description_list.selectedIndex] == 'A') {
            form.txn_hours.value = form.dial_plan_service_hours.value;
         }
         else {
            form.txn_hours.value = 0;
         }

         CalculateHoursPaymentAmounts(form, "txn_description");
         break;

      default :
         break;
   }

   return true;
}

// #*************************  End Function: PickHoursTxnDescription  ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    PickFromList
// #   Function:  Pick the selected item from a list.
// #
// #   Syntax:    PickFromList(form, List, Field);
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Aug 31, 2003
// #
// #**********************************************************************************
// #

function PickFromList(form, List, Field)
{
   var ListIndex, Index;

   ListIndex = GetFormElementIndex(form, List);
   Index     = GetFormElementIndex(form, Field);

   if (Index > -1) {
      form.elements[Index].value = 
         form.elements[ListIndex].options[form.elements[ListIndex].selectedIndex].value;
   }

   return true;
}

// #******************************  End Function: PickFromList  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GenerateUsername
// #   Function:  Generate a username.
// #
// #   Input:     The form object and field to send the result to.
// #   Output:    Returns a randomly generated username.
// #              Format is:
// #                 PPAAAANNSS where 
// #                    - PP is a 2 character prefix
// #                    - AAAA is a 4 letter string
// #                    - NN is a 2 numeral string
// #                    - SS is a 2 character suffix
// #
// #   NOTE:      To cut down on confusion don't use letters l and 0, or numerals 1 or 0.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  May 4, 2004
// #
// #**********************************************************************************
// #

function GenerateUsername(form, UsernameField, UsernamePrefix, UsernameSuffix)
{
   var i;
   var Index;
   var RandSize1;
   var RandSize2;
   var SetLength1 = 4;
   var SetLength2 = 2;
   var SeedSet1 = "abcdefghijkmnpqrstuvwxyz";
   var SeedSet2 = "23456789";
   var Username = "";

   // Note: There is no random number seed function in JavaScript.  
   //       Random() is seeded from the current time.

   RandSize1 = SeedSet1.length;
   RandSize2 = SeedSet2.length;

   for (i=0; i<SetLength1; i++) {
      Username = Username + SeedSet1.substr((Math.floor(Math.random() * RandSize1)), 1);
   }

   for (i=0; i<SetLength2; i++) {
      Username = Username + SeedSet2.substr((Math.floor(Math.random() * RandSize2)), 1);
   }

   Username = UsernamePrefix + Username + UsernameSuffix;

   Index = GetFormElementIndex(form, UsernameField);

   if (Index > -1) {
      form.elements[Index].value = Username;
   }

   return true;
}

// #******************************  End Function: GenerateUsername  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GeneratePassword
// #   Function:  Generate a password.
// #
// #   Input:     The form object and field to send the result to.
// #   Output:    Returns a randomly generated password.
// #
// #   NOTE:      To cut down on confusion don't use letters l and 0, or numerals 1 or 0.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 14, 1999
// #
// #**********************************************************************************
// #

function GeneratePassword(form, PasswordField)
{
   var i;
   var Index;
   var Password = "";
   var PasswordLength = 8;
   var RandSize;
   var SeedSet = "abcdefghijkmnpqrstuvwxyz23456789";

   // Note: There is no random number seed function in JavaScript.  
   //       Random() is seeded from the current time.

   RandSize = SeedSet.length;

   for (i=0; i<PasswordLength; i++) {
      Password = Password + SeedSet.substr((Math.floor(Math.random() * RandSize)), 1);
   }

   Index = GetFormElementIndex(form, PasswordField);

   if (Index > -1) {
      form.elements[Index].value = Password;
   }

   return true;
}

// #******************************  End Function: GeneratePassword  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GetNow
// #   Function:  Get the current date and time.
// #
// #   Input:     The form object, DateType and field to send the result to.
// #              DateType: date    - returns date only
// #                        time    - returns time only
// #                        default - returns datetime
// #   Output:    Returns current date and time.
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jan 7, 2003
// #
// #**********************************************************************************
// #

function GetNow(form, DateField, DateType)
{
   var Year, Month, Day, Hour, Minute, Second, Now, NowDate, NowTime;
   var Index;

   Now = new Date();

   Year    = Now.getFullYear();
   Month   = "00" + (Now.getMonth() + 1);
   Month   = Month.substr(Month.length - 2, 2);
   Day     = "00" + Now.getDate();
   Day     = Day.substr(Day.length - 2, 2);
   Hour    = "00" + Now.getHours();
   Hour    = Hour.substr(Hour.length - 2, 2);
   Minute  = "00" + Now.getMinutes();
   Minute  = Minute.substr(Minute.length - 2, 2);
   Second  = "00" + Now.getSeconds();
   Second  = Second.substr(Second.length - 2, 2);

   NowDate = Year + "-" + Month + "-" + Day;
   NowTime = Hour + ":" + Minute + ":" + Second;
   Now     = NowDate + " " + NowTime;

   Index = GetFormElementIndex(form, DateField);

   if (Index > -1) {
      switch (DateType) {
         case "date" :
            form.elements[Index].value = NowDate;
            break;

         case "time" :
            form.elements[Index].value = NowTime;
            break;

         default :
            form.elements[Index].value = Now;
            break;
      }
   }

   return true;
}

// #******************************  End Function: GetNow  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GoToURL
// #   Function:  Go to URL.
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 21, 1999
// #
// #**********************************************************************************
// #

function GoToURL(form, URL)
{
   var i;
   var SearchText, SearchScope;
   var SearchString;
   var Letter;
   var Telco, NewTelco;
   var MasterNo, Username, BillingNo, GlobalBillingNo, LastName, Phone;
   var UsageType, FormatType, AccountType;
   var IPAddress, IPAddressType;
   var StartDate, EndDate;
   var BillDate, BillTable, BillGroup;
   var QuotaType;
   var Title, SubTitle;
   var ReportName, GroupReportBy, SortReportBy;
   var RegenerateData;
   var EmptyTables;
   var CouponNo;
   var DomainName;
   var MailList;
   var MACAddress;
   var DormantPeriod;
   var EStylesheet;
   var Database, Table, Column, Where, Having;
   var Menu, Group;
   var SystemLogFile, SystemLogScope, SystemLogNumLines;
   var FSecureKey, FSecureTxnLog, FSecureTxnType;
   var ReturnTo, Index;
   var IP_Pool, Status_Type;


   // Clean up parameters for CGI.
   // The logic is ass-first here because of the different ways NN and IE indicate
   // if a field is defined and is blank.

   if ((typeof(form.search_text) == 'undefined') || (form.search_text.value == "")) {
      SearchText = '';
   }
   else {
      SearchText = form.search_text.value;
   }

   if (typeof(form.search_scope) == 'undefined') {
      SearchScope = '';
   }
   else {
      for (i=0; i<form.search_scope.length; i++) {
         if (form.search_scope[i].checked) {
            SearchScope = form.search_scope[i].value;
            break;
         }
      }
   }

   if ((typeof(form.search_string) == 'undefined') || (form.search_string.value == "")) {
      SearchString = '';
   }
   else {
      SearchString = form.search_string.value;
   }

   if (typeof(form.telco) == 'undefined') {
      Telco = '';
   }
   else {
      if (form.telco.selectedIndex < 0) {
         Telco = '';
      }
      else {
         Telco = form.telco.options[form.telco.selectedIndex].value;
      }
   }

   if (typeof(form.new_telco) == 'undefined') {
      NewTelco = '';
   }
   else {
      if (form.new_telco.selectedIndex < 0) {
         NewTelco = '';
      }
      else {
         NewTelco = form.new_telco.options[form.new_telco.selectedIndex].value;
      }
   }

   if ((typeof(form.title) == 'undefined') || (form.title.value == "")) {
      Title = '';
   }
   else {
      Title = form.title.value;
   }

   if ((typeof(form.subtitle) == 'undefined') || (form.subtitle.value == "")) {
      SubTitle = '';
   }
   else {
      SubTitle = form.subtitle.value;
   }

   if (typeof(form.report) == 'undefined') {
      ReportName = '';
   }
   else {
      if (form.report.selectedIndex < 0) {
         ReportName = '';
      }
      else {
         ReportName = form.report.options[form.report.selectedIndex].value;
      }
   }

   if (typeof(form.group_report_by) == 'undefined') {
      GroupReportBy = '';
   }
   else {
      if (form.group_report_by.selectedIndex < 0) {
         GroupReportBy = '';
      }
      else {
         GroupReportBy =
            form.group_report_by.options[form.group_report_by.selectedIndex].value;
      }
   }

   if ((typeof(form.sort_report_by) == 'undefined') || (form.sort_report_by.value == "")) {
      SortReportBy = '';
   }
   else {
      SortReportBy = form.sort_report_by.value;
   }

   if (typeof(form.empty_tables) == 'undefined') {
      EmptyTables = '';
   }
   else {
      if (form.empty_tables.selectedIndex < 0) {
         EmptyTables = '';
      }
      else {
         EmptyTables = form.empty_tables.options[form.empty_tables.selectedIndex].value;
      }
   }

   if ((typeof(form.master_no) == 'undefined') || (form.master_no.value == "")) {
      MasterNo = '';
   }
   else {
      MasterNo = form.master_no.value;
   }

   if ((typeof(form.dial_username) != 'undefined') && (form.dial_username.value != "")) {
      Username = form.dial_username.value;
   }
   else {
      if ((typeof(form.username) != 'undefined') && (form.username.value != "")) {
         Username = form.username.value;
      }
      else {
         if ((typeof(form.web_username) != 'undefined') && (form.web_username.value != "")) {
            Username = form.web_username.value;
         }
         else {
            Username = '';
         }
      }
   }

   Letter = '';

   if ((typeof(form.billing_no) == 'undefined') || (form.billing_no.value == "")) {
      BillingNo = '';
   }
   else {
      BillingNo = form.billing_no.value;
   }

   if ((typeof(form.global_billing_no) == 'undefined') || (form.global_billing_no.value == "")) {
      GlobalBillingNo = '';
   }
   else {
      GlobalBillingNo = form.global_billing_no.value;
   }

   if ((typeof(form.last_name) == 'undefined') || (form.last_name.value == "")) {
      LastName = '';
   }
   else {
      LastName = form.last_name.value;
   }

   if ((typeof(form.phone) == 'undefined') || (form.phone.value == "")) {
      Phone = '';
   }
   else {
      Phone = form.phone.value;
   }

   if ((typeof(form.start_date) == 'undefined') || (form.start_date.value == "")) {
      StartDate = '';
   }
   else {
      StartDate = form.start_date.value;
   }

   if ((typeof(form.end_date) == 'undefined') || (form.end_date.value == "")) {
      EndDate = '';
   }
   else {
      EndDate = form.end_date.value;
   }

   if ((typeof(form.bill_date) == 'undefined') || (form.bill_date.value == "")) {
      BillDate = '';
   }
   else {
      BillDate = form.bill_date.value;
   }

   if (typeof(form.menu_start_date) == 'undefined') {
      MenuStartDate = '';
   }
   else {
      if (form.menu_start_date.selectedIndex < 0) {
         MenuStartDate = '';
      }
      else {
         MenuStartDate = form.menu_start_date.options[form.menu_start_date.selectedIndex].value;
      }
   }

   if (typeof(form.menu_end_date) == 'undefined') {
      MenuEndDate = '';
   }
   else {
      if (form.menu_end_date.selectedIndex < 0) {
         MenuEndDate = '';
      }
      else {
         MenuEndDate = form.menu_end_date.options[form.menu_end_date.selectedIndex].value;
      }
   }

   if (typeof(form.usage_type) == 'undefined') {
      UsageType = '';
   }
   else {
      if (form.usage_type.selectedIndex < 0) {
         UsageType = '';
      }
      else {
         UsageType = form.usage_type.options[form.usage_type.selectedIndex].value;
      }
   }

   if (typeof(form.format_type) == 'undefined') {
      FormatType = '';
   }
   else {
      if (form.format_type.selectedIndex < 0) {
         FormatType = '';
      }
      else {
         FormatType = form.format_type.options[form.format_type.selectedIndex].value;
      }
   }

   if (typeof(form.account_type) == 'undefined') {
      AccountType = '';
   }
   else {
      if (form.account_type.selectedIndex < 0) {
         AccountType = '';
      }
      else {
         AccountType = form.account_type.options[form.account_type.selectedIndex].value;
      }
   }

   if (typeof(form.ip_address_type) == 'undefined') {
      IPAddressType = '';
   }
   else {
      if (form.ip_address_type.selectedIndex < 0) {
         IPAddressType = '';
      }
      else {
         IPAddressType = form.ip_address_type.options[form.ip_address_type.selectedIndex].value;
      }
   }

   if ((typeof(form.ip_address) == 'undefined') || (form.ip_address.value == "")) {
      IPAddress = '';
   }
   else {
      IPAddress = form.ip_address.value;
   }

   if ((typeof(form.coupon_no) == 'undefined') || (form.coupon_no.value == "")) {
      CouponNo = '';
   }
   else {
      CouponNo = form.coupon_no.value;
   }

   if ((typeof(form.domain_name) == 'undefined') || (form.domain_name.value == "")) {
      DomainName = '';
   }
   else {
      DomainName = form.domain_name.value;
   }

   if ((typeof(form.mail_list) == 'undefined') || (form.mail_list.value == "")) {
      MailList = '';
   }
   else {
      MailList = form.mail_list.value;
   }

   if ((typeof(form.mac_address) == 'undefined') || (form.mac_address.value == "")) {
      MACAddress = '';
   }
   else {
      MACAddress = form.mac_address.value;
   }

   if ((typeof(form.dormant_period) == 'undefined') || (form.dormant_period.value == "")) {
      DormantPeriod = '';
   }
   else {
      DormantPeriod = form.dormant_period.value;
   }

   if ((typeof(form.estylesheet) == 'undefined') || (form.estylesheet.value == "")) {
      EStylesheet = '';
   }
   else {
      EStylesheet = form.estylesheet.value;
   }

   if (typeof(form.database) == 'undefined') {
      Database = '';
   }
   else {
      if (form.database.selectedIndex < 0) {
         Database = '';
      }
      else {
         Database = form.database.options[form.database.selectedIndex].value;
      }
   }

   if (typeof(form.table) == 'undefined') {
      Table = '';
   }
   else {
      if (form.table.selectedIndex < 0) {
         Table = '';
      }
      else {
         Table = form.table.options[form.table.selectedIndex].value;
      }
   }

   if (typeof(form.column) == 'undefined') {
      Column = '';
   }
   else {
      if (form.column.selectedIndex < 0) {
         Column = '';
      }
      else {
         Column = form.column.options[form.column.selectedIndex].value;
      }
   }

   if ((typeof(form.where) == 'undefined') || (form.where.value == "")) {
      Where = '';
   }
   else {
      Where = form.where.value;
   }

   if ((typeof(form.having) == 'undefined') || (form.having.value == "")) {
      Having = '';
   }
   else {
      Having = form.having.value;
   }

   if (typeof(form.menu) == 'undefined') {
      Menu = '';
   }
   else {
      if (form.menu.selectedIndex < 0) {
         Menu = '';
      }
      else {
         Menu = form.menu.options[form.menu.selectedIndex].value;
      }
   }

   if (typeof(form.group) == 'undefined') {
      Group = '';
   }
   else {
      if (form.group.selectedIndex < 0) {
         Group = '';
      }
      else {
         Group = form.group.options[form.group.selectedIndex].value;
      }
   }

   if (typeof(form.bill_table) == 'undefined') {
      BillTable = '';
   }
   else {
      if (form.bill_table.selectedIndex < 0) {
         BillTable = '';
      }
      else {
         BillTable = form.bill_table.options[form.bill_table.selectedIndex].value;
      }
   }

   if (typeof(form.bill_group) == 'undefined') {
      BillGroup = '';
   }
   else {
      if (form.bill_group.selectedIndex < 0) {
         BillGroup = '';
      }
      else {
         BillGroup = form.bill_group.options[form.bill_group.selectedIndex].value;
      }
   }

   if (typeof(form.quota_type) == 'undefined') {
     QuotaType = '';
   } else {
     QuotaType = form.quota_type.options[form.quota_type.selectedIndex].value;
   }

   if (typeof(form.ip_pool) == 'undefined') {
      IP_Pool = '';
   } else {
      if (form.ip_pool.selectedIndex < 0) {
         IP_Pool = '';
      } else {
         IP_Pool = form.ip_pool.options[form.ip_pool.selectedIndex].value;
      }
   }

   if (typeof(form.status_type) == 'undefined') {
      Status_Type = '';
   } else {
      if (form.status_type.selectedIndex < 0) {
         Status_Type = '';
      } else {
         Status_Type = form.status_type.options[form.status_type.selectedIndex].value;
      }
   }

   if (typeof(form.system_log_file) == 'undefined') {
      SystemLogFile = '';
   }
   else {
      if (form.system_log_file.selectedIndex < 0) {
         SystemLogFile = '';
      }
      else {
         SystemLogFile = form.system_log_file.options[form.system_log_file.selectedIndex].value;
      }
   }

   if (typeof(form.system_log_scope) == 'undefined') {
      SystemLogScope = '';
   }
   else {
      if (form.system_log_scope.selectedIndex < 0) {
         SystemLogScope = '';
      }
      else {
         SystemLogScope = form.system_log_scope.options[form.system_log_scope.selectedIndex].value;
      }
   }

   if ((typeof(form.system_log_num_lines) == 'undefined') || (form.system_log_num_lines.value == "")) {
      SystemLogNumLines = '';
   }
   else {
      SystemLogNumLines = form.system_log_num_lines.value;
   }

   if ((typeof(form.fsecure_key) == 'undefined') || (form.fsecure_key.value == "")) {
      FSecureKey = '';
   }
   else {
      FSecureKey = form.fsecure_key.value;
   }

   if (typeof(form.fsecure_txn_log) == 'undefined') {
      FSecureTxnLog = '';
   }
   else {
      if (form.fsecure_txn_log.selectedIndex < 0) {
         FSecureTxnLog = '';
      }
      else {
         FSecureTxnLog = form.fsecure_txn_log.options[form.fsecure_txn_log.selectedIndex].value;
      }
   }

   if (typeof(form.fsecure_txn_type) == 'undefined') {
      FSecureTxnType = '';
   }
   else {
      if (form.fsecure_txn_type.selectedIndex < 0) {
         FSecureTxnType = '';
      }
      else {
         FSecureTxnType = form.fsecure_txn_type.options[form.fsecure_txn_type.selectedIndex].value;
      }
   }

   if (typeof(form.regenerate_data) == 'undefined') {
      RegenerateData = '';
   }
   else {
      if (form.regenerate_data.checked) {
         RegenerateData = 1;
      }
      else {
         RegenerateData = 0;
      }
   } 

   ReturnTo = location.pathname;
   Index    = ReturnTo.lastIndexOf("/");

   if (Index > -1) {
      ReturnTo = ReturnTo.substring(Index + 1, ReturnTo.length + 1);
   }


   switch (URL) {
      case "active_dsl_connections_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&regenerate_data\=" + RegenerateData; 
         break;

      case "activity_log_report.cgi" :
         URL = URL + "\?search_string\=" + SearchString; 
         break;

      case "ad_hoc_report.cgi" :
         URL = URL + "\?database\=" + Database + "\&table\=" + Table + "\&column\=" + Column +
                     "\&where\=" + Where + 
                     "\&having\=" + Having + 
                     "\&title\=" + Title + "\&subtitle\=" + SubTitle;
         break;

      case "bill_viewing_log_report.cgi" :
         URL = URL + "\?search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username +
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone +
                     "\&telco\=" + Telco +
                     "\&bill_date\=" + BillDate;
         break;

      case "browse.cgi" :
         switch (SearchScope) {
            case 'B' :
               BillingNo = SearchText;
               break;

            case 'G' :
               GlobalBillingNo = SearchText;
               break;

            case 'H' :
               Phone = SearchText;
               break;

            case 'L' :
               LastName = SearchText;
               break;

            case 'U' :
               Username = SearchText;

               if (Letter == '') {
                  Letter = Username.substr(0, 1);
               }
               break;

            default :
               break;
         }

         URL = URL + "?letter\=" + Letter +
                     "\&username\=" + Username +
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone +
                     "\&return_to\=" + ReturnTo; 
         break;

      case "bulk_email_log_report.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;

      case "cable_modems_report.cgi" :
         URL = URL + "\?report\=" + ReportName + "\&telco\=" + Telco; 
         break;

      case "check_my_usage.cgi" :
         URL = URL + "\?usage_type\=" + UsageType + 
                     "\&menu_start_date\=" + MenuStartDate + "\&menu_end_date\=" + MenuEndDate; 
         break;

      case "delete_customer.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName;
         break;

      case "deleted_customers_report.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;

      case "dormant_customers_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&dormant_period\=" + DormantPeriod; 
         break;

      case "dsl_routers_report.cgi" :
         URL = URL + "\?report\=" + ReportName + "\&telco\=" + Telco; 
         break;

      case "edit_admin.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&last_name\=" + LastName;
         break;

      case "edit_cable_modem.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "edit_customer.cgi?action=find" :
         URL = URL + "\&search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone;
         break;

      case "edit_customer_password.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&last_name\=" + LastName;
         break;

      case "edit_dsl_router.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "edit_fsecure_plans.cgi?action=find" :
         URL = URL + "\&search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&fsecure_key\=" + FSecureKey + 
                     "\&username\=" + Username;
         break;

      case "edit_mail_domains.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "edit_mailboxes.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "edit_mail_lists.cgi" :
         URL = URL + "\?mail_list\=" + MailList;
         break;

      case "edit_password.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone;
         break;

      case "edit_profile.cgi?action=find" :
         URL = URL + "\&search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone;
         break;

      case "edit_stylesheet.cgi" :
         URL = URL + "\?estylesheet\=" + EStylesheet;
         break;

      case "edit_web_domains.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "edit_wireless_radio.cgi?action=find" :
         URL = URL + "\&username\=" + Username;
         break;

      case "extra_mailboxes_report.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;

      case "fsecure_customers_report.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;

      case "fsecure_log_report.cgi" :
         URL = URL + "\?fsecure_txn_log\=" + FSecureTxnLog + 
                     "\&fsecure_txn_type\=" + FSecureTxnType;
         break;

      case "fsecure_plans_summary_report.cgi" :
         URL = URL + "\?group_report_by\=" + GroupReportBy;
         break;

      case "help_lookup_mac_description.cgi?action=find" :
         URL = URL + "\&mac_address\=" + MACAddress;
         break;

      case "history_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&start_date\=" + StartDate + "\&end_date\=" + EndDate; 
         break;

      case "mail_aliases_having_domains_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&domain_name\=" + DomainName; 
         break;

      case "mail_domains_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&sort_report_by\=" + SortReportBy; 
         break;

      case "menu_configure.cgi" :
         URL = URL + "\?menu\=" + Menu + "\&telco\=" + Telco + "\&group\=" + Group;
         break;

      case "new_customer.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;

      case "new_hours_payment.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&last_name\=" + LastName;
         break;

      case "new_payment.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&last_name\=" + LastName;
         break;

      case "no_bill_sent_report.cgi" :
         URL = URL + "\?bill_table\=" + BillTable +
                     "\&bill_group\=" + BillGroup;
         break;

      case "over_mailbox_quotas_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&quota_type\=" + QuotaType; 
         break;

      case "promote_mailbox.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName;
         break;

      case "recover_customer.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&start_date\=" + StartDate + "\&end_date\=" + EndDate; 
         break;

      case "referral_coupons_report.cgi" :
         URL = URL + "\?coupon_no\=" + CouponNo; 
         break;

      case "report.cgi" :
         URL = URL + "\?report\=" + ReportName + "\&telco\=" + Telco; 
         break;

      case "reports_menu.cgi" :
         URL = "report.cgi" + "\?report\=" + ReportName;
         break;

      case "show_all_data.cgi?action=find" :
         URL = URL + "\&search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&empty_tables\=" + EmptyTables +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone;
         break;

      case "split_customer.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName;
         break;

      case "static_ip_report.cgi" :
         URL = URL + "\?telco\=" + Telco; 
         break;
 
      case "static_ip_availability_report.cgi" : 
         URL = URL + "\?ip_pool\=" + IP_Pool + 
                     "\&status_type\=" + Status_Type;
         break;

      case "system_log_viewer.cgi" :
         URL = URL + "\?system_log_file\=" + SystemLogFile + 
                     "\&system_log_scope\=" + SystemLogScope + 
                     "\&system_log_num_lines\=" + SystemLogNumLines;
         break;

      case "transfer_customer.cgi?action=find" :
         URL = URL + "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username + 
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName + 
                     "\&new_telco\=" + NewTelco;
         break;

      case "usage_by_ip_address_report.cgi" :
         URL = URL + "\?ip_address\=" + IPAddress + "\&ip_address_type\=" + IPAddressType + 
                     "\&menu_start_date\=" + MenuStartDate + "\&menu_end_date\=" + MenuEndDate; 
         break;

      case "usage_by_telco_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&account_type\=" + AccountType + 
                     "\&format_type\=" + FormatType + 
                     "\&menu_start_date\=" + MenuStartDate + "\&menu_end_date\=" + MenuEndDate; 
         break;

      case "usage_report.cgi" :
         URL = URL + "\?username\=" + Username + 
                     "\&usage_type\=" + UsageType + 
                     "\&menu_start_date\=" + MenuStartDate + "\&menu_end_date\=" + MenuEndDate; 
         break;

      case "view_bill.cgi" :
         URL = URL + "\?search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username +
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone +
                     "\&bill_date\=" + BillDate;
         break;

      case "view_my_bill.cgi" :
         URL = URL + "\?bill_date\=" + BillDate;
         break;

      case "view_traffic_analysis.cgi" :
         URL = URL + "\?search_text\=" + SearchText + "\&search_scope\=" + SearchScope +
                     "\&master_no\=" + MasterNo + 
                     "\&username\=" + Username +
                     "\&billing_no\=" + BillingNo + 
                     "\&global_billing_no\=" + GlobalBillingNo +
                     "\&last_name\=" + LastName +
                     "\&phone\=" + Phone;
         break;

      case "web_domain_aliases_report.cgi" :
         URL = URL + "\?telco\=" + Telco + 
                     "\&sort_report_by\=" + SortReportBy; 
         break;

      case "wireless_radios_report.cgi" :
         URL = URL + "\?report\=" + ReportName + "\&telco\=" + Telco; 
         break;

      default :
         break;
   }

   location.href = EscapeURL(URL);

   return false;
}

// #******************************  End Function: GoToURL  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    onChangePopupMenu
// #   Function:  Refresh the page when the list selection is changed.
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jan 13, 2004
// #
// #**********************************************************************************
// #

function onChangePopupMenu(form, List)
{
   var ListIndex,NewParamPair, OldParamPair, Selection, URLQuery;

   ListIndex = GetFormElementIndex(form, List);

   if (typeof(form.elements[ListIndex]) == 'undefined') {
      Selection = '*';
   }
   else {
      if (form.elements[ListIndex].selectedIndex < 0) {
         Selection = '*';
      }
      else {
         Selection = form.elements[ListIndex].options[form.elements[ListIndex].selectedIndex].value;
      }
   }

   OldParamPair = List + "=" + GetParam(List);
   NewParamPair = List + "=" + Selection;
   URLQuery     = location.search.substring(1);

   if (URLQuery == "") {
      URLQuery = NewParamPair;
   }
   else {
      if (URLQuery.indexOf(OldParamPair) > -1) {
         URLQuery = URLQuery.replace(OldParamPair, NewParamPair);
      }
      else {
         URLQuery = URLQuery + "&" + NewParamPair;
      }
   }

   location.href = EscapeURL(location.pathname + "?" + URLQuery);

   return false;
}

// #*************************  End Function: onChangePopupMenu ***********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    PrintScreen
// #   Function:  Print current browser window.
// #
// #   Input:     
// #   Output:    
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 22, 1999
// #
// #**********************************************************************************
// #

function PrintScreen() 
{
   if (window.print) {
      window.print();
   }
   else {
      alert("Sorry, this function is not supported by your browser.  " +
            "You'll need version 6 or higher to use it.");
   }

   return false;
}

// #******************************  End Function: PrintScreen  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    PrintPrep
// #   Function:  Prepares the screen for printing by changing
// #              to a plain stylesheet.
// #
// #   Input:
// #   Output:
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Apr 26, 1999
// #
// #**********************************************************************************
// #

function PrintPrep()
{
   if (location.href.indexOf("?") > -1) {
      location.href = EscapeURL(location.href + "&stylesheet=print.css");
   }
   else {
      location.href = EscapeURL(location.href + "?stylesheet=print.css");
   }
}

// #******************************  End Function: PrintPrep  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    EscapeURL
// #   Function:  Escape a URL using standard URL encoding.
// #              This function is similar to the JavaScript escape() function
// #              but this is more selective.
// #
// #   Syntax:    EscapeURL(URL)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jul 21, 2000
// #
// #**********************************************************************************
// #

function EscapeURL(URL) 
{

// NOTE: This is not a complete list of characters to escape.
//       Add characters as needed.

   var EscapedURL;

   EscapedURL = URL.replace(/ /g, "%20");

   return EscapedURL;
}

// #******************************  End Function: EscapeURL  ****************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    VirusScanningClicked
// #   Function:  Take action when the Virus Scanning checkbox is changed.
// #
// #   Syntax:    VirusScanningClicked(form, VirusScanningField)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Mar 20, 2001
// #
// #**********************************************************************************
// #

function VirusScanningClicked(form, VirusScanningField) 
{
   var Field;
   var Index;

   // Virus Scanning is included with Spam Filtering, so it cannot be unchecked if 
   // 'spam_filtering' is checked.

   if (!eval("form." + VirusScanningField + ".checked")) {
      Field = VirusScanningField.replace(/virus_scanning/g, "spam_filtering");

      if (eval("form." + Field + ".checked")) {
         alert("Virus Scanning is included with Spam Filtering.");

         Index = GetFormElementIndex(form, VirusScanningField);

         if (Index > -1) {
            form.elements[Index].checked = true;
         }
      }
   }

   return true;
}

// #***********************  End Function: VirusScanningClicked  *********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    SpamFilteringClicked
// #   Function:  Take action when the Spam Filtering checkbox is changed.
// #
// #   Syntax:    SpamFilteringClicked(form, SpamFilteringField)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Mar 20, 2001
// #
// #**********************************************************************************
// #

function SpamFilteringClicked(form, SpamFilteringField) 
{
   var Field;
   var Index;

   // If 'spam_filtering' is checked then check 'virus_scanning' and 
   // 'spam_filtering_actvd'.
   // If 'spam_filtering' is unchecked then uncheck 'spam_filtering_actvd'.

   if (eval("form." + SpamFilteringField + ".checked")) {
      Field = SpamFilteringField.replace(/spam_filtering/g, "virus_scanning");
      Index = GetFormElementIndex(form, Field);

      if (Index > -1) {
         form.elements[Index].checked = true;
      }

      Field = SpamFilteringField.replace(/spam_filtering/g, "spam_filtering_actvd");
      Index = GetFormElementIndex(form, Field);

      if (Index > -1) {
         form.elements[Index].checked = true;
      }
   }
   else {
      Field = SpamFilteringField.replace(/spam_filtering/g, "spam_filtering_actvd");
      Index = GetFormElementIndex(form, Field);

      if (Index > -1) {
         form.elements[Index].checked = false;
      }
   }

   return true;
}

// #***********************  End Function: SpamFilteringClicked  *********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    SpamFilteringActivatedClicked
// #   Function:  Take action when the Spam Filtering checkbox is changed.
// #
// #   Syntax:    SpamFilteringActivatedClicked(form, SpamFilteringActivatedField)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Mar 20, 2001
// #
// #**********************************************************************************
// #

function SpamFilteringActivatedClicked(form, SpamFilteringActivatedField) 
{
   var Field;
   var Index;

   // If 'spam_filtering_actvd' is checked then check 'spam_filtering' and
   // 'virus_scanning'.

   if (eval("form." + SpamFilteringActivatedField + ".checked")) {
      Field = SpamFilteringActivatedField.replace(/spam_filtering_actvd/g, "virus_scanning");
      Index = GetFormElementIndex(form, Field);

      if (Index > -1) {
         form.elements[Index].checked = true;
      }

      Field = SpamFilteringActivatedField.replace(/spam_filtering_actvd/g, "spam_filtering");
      Index = GetFormElementIndex(form, Field);

      if (Index > -1) {
         form.elements[Index].checked = true;
      }
   }

   return true;
}

// #******************* End Function: SpamFilteringActivatedClicked  ****************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GetFormElementIndex
// #   Function:  Returns the index of form.elements[] where NAME=FormElement.
// #
// #   Syntax:    GetFormElementIndex(form, FormElement)
// #
// #              This function is used to allow literal strings to be used on the
// #              left-hand side of an equation, as in:
// #
// #                FormElementName = "username";
// #
// #                Doesn't Work:
// #                  "form." . FormElementName . ".value" = "smith";
// #
// #                Works:
// #                  form.elements[GetFormElementIndex(form, FormElementName)].value 
// #                     = "smith";
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Mar 21, 2001
// #
// #**********************************************************************************
// #

function GetFormElementIndex(form, FormElementName) 
{
   var FormElementIndex = -1;

   for (i=0; i<form.elements.length; i++) {
      if (form.elements[i].name == FormElementName) {
         FormElementIndex = i;
         break;
      }
   }

   return FormElementIndex;
}

// #************************ End Function: GetFormElementIndex  *********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    HelpLookupMACDescription
// #   Function:  Lookup the MAC address' description.
// #
// #   Syntax:    HelpLookupMACDescription(form, MACAddressField)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  May 3, 2002
// #
// #**********************************************************************************
// #

function HelpLookupMACDescription(form, MACAddressField)
{
   var Width       = 600;
   var Height      = 200;
   var Top         = 20;
   var Left        = screen.width - Width - 20;
   var Scrollbars  = 'no';
   var Location    = 'no';
   var Directories = 'no';
   var Status      = 'no';
   var Menubar     = 'no';
   var Toolbar     = 'no';
   var Resizeable  = 'no';
   var MACLookup;
   var MACAddress;
   var Index;

   Index = GetFormElementIndex(form, MACAddressField);

   if (Index > -1) {
      MACAddress = form.elements[Index].value;
   }

   MACLookup = window.open('help_lookup_mac_description.cgi?mac_address=' + MACAddress, 
                           'MACLookup', 
                           'width=' + Width + 
                           ',height=' + Height + 
                           ',top=' + Top + 
                           ',left=' + Left + 
                           ',scrollbars=' + Scrollbars + 
                           ',location=' + Location + 
                           ',directories=' + Directories + 
                           ',status=' + Status + 
                           ',menubar=' + Menubar + 
                           ',toolbar=' + Toolbar + 
                           ',resizable=' + Resizeable
                          );
   MACLookup.focus();
}

// #************************ End Function: HelpLookupMACDescription  *********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    SubmitFormOnce
// #   Function:  Prohibit a form from being submitted more than once
// #              as a result of double- or multiple-clicking the submit button.
// #
// #   Syntax:    SubmitFormOnce(form)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Oct 16, 2002
// #
// #**********************************************************************************
// #

function SubmitFormOnce(form)
{

   var WaitMessage = "Wait...";


   // The accepted method of prohibitting a double- or multiple-click
   // of a submit button is to add something like
   //    ONCLICK="form.submit.disabled=true; return false;"
   // to the submit button, which would stop any submissions after the first button click.
   // However, CGI.pm implements the onSubmit event on the form, not the individual buttons
   // so you are left with adding the button.disabled code to either the button's onClick event
   // of the form's onSubmit event.  Unfortunately, this does not seem to work.  What appears to
   // happen is once the button is disabled then the submit is terminated regardless of
   // whether true or false is returned -- the submit is aborted.
   //
   // So, what we are left with is a two pass code that allows the first submit to proceed,
   // changes the button label to a WaitMessage, and leaves the button state alone.
   // On the second click (if there is one) the button is disabled, resulting in the submit
   // aborting, which is what we want.
   //  
   // A submit() button may not always be labeled "Submit"
   // but it should be changed to the wait message after it
   // is submitted for the first time.
 

//   if (form.submit.value != WaitMessage) {
      form.submit.value = "Wait...";
      return true;
//   }
//   else {
//      form.submit.disabled = true;
//      return false;
//   }
}

// #***************************** End Function: SubmitFormOnce  **************************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    BounceEmail
// #   Function:  Set appropriate fields to bounce email.
// #
// #   Syntax:    BounceEmail(form, BounceEmailField, BounceEmailToAddress)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Dec 16, 2002
// #
// #**********************************************************************************
// #

function BounceEmail(form, BounceEmailField, BounceEmailToAddress) 
{
   var Field;
   var Index;


   Index = GetFormElementIndex(form, BounceEmailField);

   if (Index > -1) {
      form.elements[Index].value = BounceEmailToAddress;
   }

   return true;
}

// #***********************  End Function: BounceEmail  *********************


// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    GetParam
// #   Function:  Get the value of the named paramater from the query string.
// #
// #   Syntax:    GetParam(Name)
// #
// #              CyberMill Canada Limited
// #              Jim.Saunders@cybermill.ca
// #
// #   History:   Initial Code  Jan 14, 2004
// #
// #**********************************************************************************
// #

function GetParam(Name) 
{
   var Index;
   var Params     = new Array();
   var ParamName;
   var URLQuery;
   var Value      = "";

   // Trash the '?' at the front of the query.
   // See parse_params() in CGI.pm for split delimiters.

   URLQuery = location.search.substring(1);
   Params   = URLQuery.split(/[&;]/);

   for (var i=0; i<Params.length; i++) {
      Index = Params[i].indexOf("=");

      if (Index > -1) {
         ParamName = Params[i].substring(0, Index);
         Value     = Params[i].substring(Index + 1);

         if (ParamName == Name) {
            break;
         }
      }
   }

   return Value;
}

// #****************************  End Function: GetParam  ****************************

// #
// #**********************************************************************************
// #   Program:   Customer Management System
// #   Module:    default_vacation_message
// #   Function:  sets the default vacation message in vacation_message.
// #
// #              CyberMill Canada Limited
// #              jamie@cybermill.ca
// #
// #   History:   Initial Code  Oct 19, 2002
// #
// #**********************************************************************************
// #

function default_vacation_message(form)
{
  form.vacation_subject.value = "Vacation Alert.";
  form.vacation_message.value = 
     "I will not be reading my mail for a while.\n" +
     "Your email message will be read when I return.";
}
