home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / TextBox / TextBox.js < prev    next >
Encoding:
JavaScript  |  1998-10-05  |  37.9 KB  |  1,058 lines

  1. /* ======================================================================
  2. OBJECT:        com_netobjects_TextBox
  3.  
  4. PLATFORMS:    Netscape Navigator 4.01 or higher, 
  5.                 Microsoft Internet Explorer 4.02 or higher
  6.  
  7. DESC:            This object allows developers to create TextBoxes with common built
  8.                 in behaviors such as formating and validation.
  9.  
  10.                 Validation:
  11.                 ----------
  12.                 Validation will only occur when the validate property is true.  See the
  13.                 headers of functions below with the same name as the desired 
  14.                 valueType to find the validation rules for each valueType.
  15.  
  16.                 Formatting:
  17.                 ---------- 
  18.                 none:            The value will be displayed as entered.
  19.                 yes/no:         values of 0, false or "no" will be formatted as "no"
  20.                             values of 1, -1, true or "yes" will be formatted as "yes"
  21.                 true/false: values of 0, false or "no" will be formatted as "false"
  22.                             values of 1, -1, true or "yes" will be formatted as "true"
  23.                 percent:     numeric value will be multiplied by 100 and have a trailing "%"
  24.                 fixed:         numeric value will be rounded to the number of decimal places specified
  25.                                  in the object's decPlaces property.
  26.                 currency:     numeric value will be rounded to the number of decimal places specified
  27.                                  in the object's decPlaces property, and preceeded by a "$"
  28.  
  29. ====================================================================== */
  30. function com_netobjects_TextBox(params) {
  31.  // Public Properties    
  32.     this.name                 = (params.name != null) ? params.name : "";
  33.     this.textBoxName        = (params.textBoxName != null) ? params.textBoxName : "";
  34.     this.formName            = (params.formName != null) ? params.formName : "";
  35.     this.value                = (params.value != null) ? params.value : "";
  36.     this.size                 = (params.size != null) ? params.size : "";
  37.     this.isPassword         = ((params.isPassword != null) && (params.isPassword == true)) ? params.isPassword : false;
  38.     this.maxLength         = (params.maxLength != null) ? params.maxLength : "";
  39. //  none, 0/1, 0/-1, Yes/No, True/False, Percent, Currency, Fixed 
  40.     this.format             = (params.format != null) ? params.format : "";
  41.     this.decPlaces         = ((params.decPlaces != null) && (params.decPlaces != "")) ? params.decPlaces : "0";
  42.     this.validate             = ((params.validate != null) && (params.validate == true)) ? params.validate : "";
  43.     this.isRequired        = (params.isRequired     != null) ? params.isRequired : "";
  44. // none, IsAlpha, IsAlphaNum, IsAlphaNumOrUnderscore, IsInt, IsNum, IsValid5DigitZip, IsValid5Plus4DigitZip, IsValidEmail, IsValidPhone, IsValidSSN
  45.     this.valueType         = (params.valueType != null) ? params.valueType : "";
  46.     this.state                 = (params.state != null) ? params.state : "";
  47.  
  48.     this.testMode            = (params.testMode != null) ? params.testMode : "none"
  49.     
  50.     // Private Properties
  51.     this.isValid             = true;
  52.     this.errType             = null;
  53.     this.textBoxIndex     = 0
  54.  
  55.     // Public Methods
  56.     this.validateValue     = _TextBox_validateValue;
  57.     this.render             = _TextBox_render;
  58.  
  59.     // Private Methods
  60.     this.validateProperties = _TextBox_validateProperties;
  61.     this.getFormattedValue = _TextBox_GetFormattedValue;
  62.     this.isValidFormatType = _TextBox_isValidFormatType
  63.  
  64.     // Public Events
  65.     this.onBlur              = _TextBox_onBlur;
  66.     this.onChange             = _TextBox_onChange;
  67.     this.onFocus           = _TextBox_onFocus;
  68.     this.onSelect             = _TextBox_onSelect;
  69.     this.onValidate          = _TextBox_onValidate;
  70.     this.onInvalid           = _TextBox_onInvalid;
  71.     this.onValid           = _TextBox_onValid;
  72.     this.onRender         = _TextBox_onRender;
  73.  
  74.     // Private Events (internal event driven functionality)
  75.     this.eOnChange         = _TextBox_eOnChange;
  76.  
  77.     // Validate object properties
  78.     this.validateProperties();
  79.  
  80.     // Public Methods ----------------------------------------
  81.     function _TextBox_render() {
  82.         // Initialize Variables
  83.         var sTextBoxName = "";
  84.         var svalue = "";
  85.         var smaxLength = "";
  86.         var sisPassword = "";
  87.         var ssize = "";
  88.  
  89.         var sonBlur  = "";
  90.         var sonChange   = "";
  91.         var sonFocus    = "";
  92.         var sonSelect  = "";
  93.     
  94.         // Set Variables
  95.         sTextBoxName     = " Name = \"" + this.textBoxName + "\"";
  96.         var fmtedVal     = this.getFormattedValue();
  97.         // Only format if it's not a password value
  98.         if (!this.isPassword) {
  99.             this.value = fmtedVal;
  100.             svalue             = " Value = \"" + fmtedVal     + "\"";
  101.         } else
  102.             svalue= " Value = \"" + this.value     + "\"";
  103.         smaxLength         = " MaxLength = \"" + this.maxLength + "\"";
  104.         ssize             = " Size = \"" + this.size + "\"";
  105.  
  106.         if (this.isPassword) { 
  107.             sisPassword = " Type = \"Password\""
  108.         } else {
  109.             sisPassword = " Type = \"Text\""
  110.         }
  111.  
  112.         // Build Nav & IE shared link events
  113.         sonBlur  = " onBlur=\"" + this.name + ".onBlur();\""
  114.         sonChange   = " onchange=\"return " + this.name + ".eOnChange();\""
  115.         sonFocus    = " onFocus=\"" + this.name + ".onFocus();\""
  116.         sonSelect  = " onSelect=\"" + this.name + ".onSelect();\""
  117.         eEvents  = sonBlur + sonChange + sonFocus + sonSelect;
  118.  
  119.         // Write HTML
  120.         if (this.state == "hidden") {
  121.            document.write( "<Input Type=hidden" + sTextBoxName + svalue + eEvents + ">\n");
  122.         } else if (this.state == "read-only") {
  123.            document.write( fmtedVal + "\n");
  124.         } else {
  125.            document.write( "<Input" + sisPassword  +sTextBoxName + svalue + ssize + smaxLength + eEvents + ">\n");
  126.         }
  127.         
  128.         // Set control index:
  129.         // The control index is used by the object to identify its respective form element
  130.         // in the event that there is more than one form element with the same name.
  131.         if (this.state != "read-only") {
  132.             // Set control index if multiple controls exist
  133.             this.textBoxIndex = eval("window.document." + this.formName + "." + this.textBoxName + ".length")-1
  134.             if (isNaN(this.textBoxIndex)) {this.textBoxIndex=0}
  135.         }
  136.  
  137.         // Fire public events
  138.         this.onRender(); 
  139.     
  140.     } // END _TextBox_render
  141.  
  142.  
  143.         /* ======================================================================
  144.     
  145.    METHOD: _TextBox_validateProperties.  If the test mode is set,
  146.     generate error and/or warning messages if required or recommended properties
  147.     are set with invalid property values or are not set at all.
  148.  
  149.     ====================================================================== */
  150.     function _TextBox_validateProperties() {
  151.         if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
  152.             var errors = new Array()
  153.           iIndex = 0;  
  154.          
  155.             // Check for errors
  156.             if (this.name == "") 
  157.                 errors[iIndex++] = "Name is a required property.";  
  158.             if (this.textBoxName == "") 
  159.                 errors[iIndex++] = "Textbox name is a required property.";  
  160.             if (this.textBoxName == this.name) 
  161.                 errors[iIndex++] = "Textbox name and object name may not be the same.";  
  162.         if (!this.isValidFormatType(this.format, this.valueType))
  163.                 if (this.format == "Fixed" && this.valueType == "IsInt")
  164.                     errors[iIndex++] = "The format " + this.format + " is not valid with value type " + this.valueType + " unless decPlaces is set to 0."; 
  165.                 else
  166.                     errors[iIndex++] = "The format " + this.format + " is not valid with value type " + this.valueType + "."; 
  167.         if ((this.isPassword) && !((this.valueType == "") || (this.valueType == "none")))
  168.                 errors[iIndex++] = "You cannot have a value type on password values."; 
  169.         if ((this.isPassword) && !((this.format == "") || (this.format == "none")))
  170.                 errors[iIndex++] = "You cannot format a password value."; 
  171.  
  172.             // Display errors
  173.             for (var i=0; i<errors.length; i++)  {
  174.                 if (this.testMode.toLowerCase()    == "text") 
  175.                     document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_Button, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
  176.                 else
  177.                       alert("TEST MODE, com_netobjects_TextBox, '" + this.name + "' : " + errors[i]);
  178.  
  179.             }            
  180.         } 
  181.     } // END _TextBox_validateProperties
  182.  
  183.     /* ======================================================================
  184.     
  185.    METHOD: _TextBox_validateValue.  Validates the value entered in the text 
  186.     box according to the valueType property.  Validation will only occur when 
  187.     the validate property is true.  See the headers of functions below with 
  188.     the same name as the desired valueType to find the validation rules for 
  189.     each valueType.   This function will also make sure the value has not
  190.     been left blank if the isRequired property is true.
  191.  
  192.     ====================================================================== */
  193.     function _TextBox_validateValue() {
  194.         this.isValid = true;
  195.         this.errType = ""
  196.  
  197.         // Check for required value
  198.         if ((this.isRequired) && ((this.value == null) || (this.value == ""))) {
  199.             this.errType = "NoValue"
  200.             this.isValid = false;
  201.             // exit function
  202.         }
  203.     
  204.         // Check for value type
  205.         if (this.isValid) {
  206.             if ((this.valueType == "IsAlpha") && (!IsAlpha(this.value))) {
  207.                 this.errType = "NotAlpha"
  208.                 this.isValid = false;
  209.             } else if ((this.valueType == "IsAlphaNum") && (!IsAlphaNum(this.value))) {
  210.                 this.errType = "NotAlphaNum"
  211.                 this.isValid = false;
  212.             } else if ((this.valueType == "IsAlphaNumOrUnderscore") && (!IsAlphaNumOrUnderscore(this.value))) {
  213.                 this.errType = "NotAlphaNumOrUnderscore"
  214.                 this.isValid = false;
  215.             } else if ((this.valueType == "IsInt") && (!IsInt(this.value))) {
  216.                 this.errType = "NotInt"
  217.                 this.isValid = false;
  218.             } else if ((this.valueType == "IsNum") && (!IsNum(this.value))) {
  219.                 this.errType = "NotNum"
  220.                 this.isValid = false;
  221.             } else if ((this.valueType == "IsValid5DigitZip") && (!IsValid5DigitZip(this.value))) {
  222.                 this.errType = "NotValid5DigitZip"
  223.                 this.isValid = false;
  224.             } else if ((this.valueType == "IsValid5Plus4DigitZip") && (!IsValid5Plus4DigitZip(this.value))) {
  225.                 this.errType = "NotValid5Plus4DigitZip"
  226.                 this.isValid = false;
  227.             } else if ((this.valueType == "IsValidEmail") && (!IsValidEmail(this.value))) {
  228.                 this.errType = "NotValidEmail"
  229.                 this.isValid = false;
  230.             } else if ((this.valueType == "IsValidPhone") && (!IsValidPhone(this.value))) {
  231.                 this.errType = "NotValidPhone"
  232.                 this.isValid = false;
  233.             } else if ((this.valueType == "IsValidSSN") && (!IsValidSSN(this.value))) {
  234.                 this.errType = "NotValidSSN"
  235.                 this.isValid = false;
  236.             } 
  237.  
  238.         }    
  239.     
  240.  
  241.         // Fire public events
  242.         if (this.isValid) {this.onValid()} else {this.onInvalid()};
  243.         this.onValidate()
  244.  
  245.         return this.isValid;
  246.  
  247.     } // END _TextBox_validate
  248.  
  249.     
  250.     
  251.     // Private Event Handlers ----------------------------------------
  252.     /* ======================================================================
  253.     
  254.    METHOD: _TextBox_isValidFormatType.  Determines whether combination of 
  255.                 format and valueType are valid together.
  256.  
  257.     ====================================================================== */
  258.     function _TextBox_isValidFormatType(valFormat, valType) {
  259.         var result = false
  260.         if ((valFormat == null) || (valType ==  null)||
  261.              (valFormat == "none") || (valType == "none") ||
  262.              (valFormat == "") || (valType == "")) {
  263.             result = true
  264.         }     else if (((valFormat == "Yes/No") || (valFormat == "True/False"))
  265.                     && ((valType == "IsAlpha") || (valType == "IsAlphaNum") 
  266.                         ||(valType == "IsAlphaNumOrUnderscore"))) {
  267.             result = true    
  268.         }     else if ((valFormat == "Fixed")
  269.                     && ((valType == "IsInt" && this.decPlaces == 0) || (valType == "IsNum"))) {
  270.             result = true    
  271.         }
  272.     
  273.         return result
  274.     
  275.     } // END _TextBox_isValidFormatType
  276.  
  277.     /* ======================================================================
  278.     
  279.    METHOD: _TextBox_eOnChange.  Internal on change event.  Updates the value 
  280.               from the textbox.
  281.  
  282.     ====================================================================== */
  283.     function _TextBox_eOnChange() {
  284.         // use control index if more than one control exists
  285.         var index = ""
  286.         if (!isNaN(eval("window.document." + this.formName + "." + this.textBoxName + ".length"))) {
  287.             index = "[" + this.textBoxIndex + "]"
  288.         }
  289.  
  290.         // update value
  291.         this.value = eval("window.document." + this.formName + "." + this.textBoxName + index + ".value")
  292.         var fmtedVal = this.getFormattedValue();
  293.         if ((this.value != fmtedVal) && !this.isPassword) {
  294.             this.value =  fmtedVal
  295.             eval("window.document." + this.formName + "." + this.textBoxName + index + ".value=\"" + fmtedVal+"\"")
  296.         }
  297.  
  298.         var result = true
  299.         if (this.validate) {
  300.             result = this.validateValue()
  301.         }
  302.  
  303.         // Fire public events 
  304.         this.onChange()
  305.  
  306.         return result
  307.  
  308.     } // END _TextBox_eOnChange
  309.     
  310.     /* ======================================================================
  311.     
  312.    METHOD: _TextBox_GetFormattedValue.  Formats textbox value according to
  313.      the value of the format property.
  314.  
  315.     none:            The value will be displayed as entered.
  316.     yes/no:         values of 0, false or "no" will be formatted as "no"
  317.                          values of 1, -1, true or "yes" will be formatted as "yes"
  318.     true/false: values of 0, false or "no" will be formatted as "false"
  319.                          values of 1, -1, true or "yes" will be formatted as "true"
  320.     percent:     numeric value will be multiplied by 100 and have a trailing "%"
  321.     fixed:         numeric value will be rounded to the number of decimal places specified
  322.                      in the object's decPlaces property.
  323.     currency:     numeric value will be rounded to the number of decimal places specified
  324.                      in the object's decPlaces property, and preceeded by a "$"
  325.  
  326.     ====================================================================== */
  327.     function _TextBox_GetFormattedValue() {
  328.         if ((this.format == "Yes/No") || (this.format == "True/False")) {
  329.             return FormatBoolean(this.value, this.format)
  330.         } else if ((this.format != "")) {  // Format number    
  331.             return FormatNumber(this.value, this.format, this.decPlaces)
  332.         }    else {
  333.             return this.value
  334.         }
  335.     
  336.     } // END _TextBox_GetFormattedValue
  337.  
  338.     // Public Event Handlers ----------------------------------------
  339.     function _TextBox_onBlur() {
  340.     }
  341.     function _TextBox_onChange() {
  342.     }
  343.     function _TextBox_onFocus() {
  344.     }
  345.     function _TextBox_onSelect() {
  346.     }
  347.     function _TextBox_onValidate() {
  348.     }
  349.     function _TextBox_onInvalid() {
  350.             // Error messages are put here so that they may be overridden
  351.             if (this.errType == "NoValue") {
  352.                 alert("An entry in this field is REQUIRED.")    
  353.             } else if (this.errType == "NotAlpha") {
  354.                 alert("An entry in this field may only contain alpha characters.")    
  355.             } else if (this.errType == "NotAlphaNum") {
  356.                 alert("An entry in this field may only contain alpha-numeric characters.")    
  357.             } else if (this.errType == "NotAlphaNumOrUnderscore") {
  358.                 alert("An entry in this field may only contain alpha-numeric characters and underscores.")    
  359.             } else if (this.errType == "NotInt") {
  360.                 alert("An entry in this field must be an integer.")    
  361.             } else if (this.errType == "NotNum") {
  362.                 alert("An entry in this field must be an number.")    
  363.             } else if (this.errType == "NotValid5DigitZip") {
  364.                 alert("An entry in this field must be a valid 5 digit zipcode.")    
  365.             } else if (this.errType == "NotValid5Plus4DigitZip") {
  366.                 alert("An entry in this field must be a valid 5 plus 4 digit zipcode.")    
  367.             } else if (this.errType == "NotValidEmail") {
  368.                 alert("An entry in this field must be a valid email.")    
  369.             } else if (this.errType == "NotValidPhone") {
  370.                 alert("An entry in this field must be a valid phone.")    
  371.             } else if (this.errType == "NotValidSSN") {
  372.                 alert("An entry in this field must be a valid social security number.")    
  373.             } else {
  374.                 alert("Unknown Error.")    
  375.             } 
  376.     }
  377.     function _TextBox_onValid() {
  378.     }
  379.     function _TextBox_onRender() {
  380.     }
  381.     
  382.  
  383.     
  384. } // END CONSTRUCTOR com_netobjects_TextBox
  385.  
  386. // Shared Functions ---------------------------------------------------------------
  387. /* ======================================================================
  388.  
  389.   FUNCTION: FormatBoolean.  Formats boolean values "Yes/No", "True/False", "-1/0" & "1/0"
  390.             Fails silently, returning original value
  391.  
  392. ====================================================================== */
  393. function FormatBoolean(myVal, FmtName) {
  394.     var newVal = myVal
  395.     var ValIsTrue = false
  396.     var ValIsFalse = false
  397.     
  398.     if ((myVal.toString() == 0) || 
  399.          (myVal.toString().toLowerCase() == "false") ||
  400.          (myVal.toString().toLowerCase() == "no")){    
  401.          ValIsFalse = true
  402.     } else if ((myVal.toString() == "-1") || (myVal.toString() == "1") || 
  403.          (myVal.toString().toLowerCase() == "true") ||
  404.          (myVal.toString().toLowerCase() == "yes")) {    
  405.          ValIsTrue = true
  406.     }
  407.     
  408.     if (FmtName == "Yes/No") {
  409.         if (ValIsTrue){ newVal = "Yes" }    else if (ValIsFalse){ newVal = "No" }
  410.     } else if (FmtName == "True/False") {
  411.         if (ValIsTrue){ newVal = "True" }    else if (ValIsFalse){ newVal = "False" }
  412.     } else if (FmtName == "-1/0") {
  413.         if (ValIsTrue){ newVal = -1 }    else if (ValIsFalse){ newVal = 0 }
  414.     } else if (FmtName == "1/0") {
  415.         if (ValIsTrue){ newVal = 1 }    else if (ValIsFalse){ newVal = 0 }
  416.     }
  417.  
  418.     return newVal
  419. } // END FormatBoolean
  420.  
  421.  
  422. /* ======================================================================
  423.  
  424.   FUNCTION: FormatNumber.  Formats numeric values "Percent", "Currency" & "Fixed"
  425.             Fails silently, returning original value
  426.  
  427. ====================================================================== */
  428. function FormatNumber(myVal, FmtName, decPlaces) {
  429.     var newVal = myVal
  430.  
  431.     // Strip out spaces...
  432.  
  433.     // if Percent strip off '%'
  434.     if ((FmtName == "Percent") && (myVal.substring(myVal.length-1,myVal.length) == "%")) {
  435.         myVal = myVal.substring(0,myVal.length-1)
  436.         if (IsNum(myVal)) {myVal = myVal/100}
  437.     }
  438.     // if Currency strip off '$'
  439.     if ((FmtName == "Currency") && (myVal.substring(0,1) == "$")) {
  440.         myVal = myVal.substring(1,myVal.length)
  441.     }
  442.  
  443.     if (IsNum(myVal)) { 
  444.          
  445. //  Percent, Currency, Fixed0Places, Fixed2Places, Fixed3Places, Fixed4Places, Fixed5Places
  446.         if (FmtName == "Percent") {
  447.         //    var newDec = (parseInt(decPlaces,10)+2)
  448.             newVal = (Fix(myVal*100, decPlaces))+"%"
  449.         } else if (FmtName == "Currency") {
  450.             newVal = "$"+Fix(myVal, decPlaces)
  451.         } else if (FmtName == "Fixed") {
  452.             newVal = Fix(myVal, decPlaces)
  453.         }
  454.         
  455.     }    
  456.  
  457.     return newVal
  458. } // END FormatNumber
  459.  
  460. /* ======================================================================
  461.  
  462.   FUNCTION: Fix.  Rounds to specified decimal point.
  463.              Assumes a number is passed.
  464.  
  465. ====================================================================== */
  466. function Fix(myVal, decPlaces) {
  467.     var newVal = myVal
  468.     var returnVal = 0;
  469.  
  470.     var test = (Math.round(myVal*Math.pow(10,decPlaces))).toString() //Math.round(myVal*Math.pow(10,decPlaces))/Math.pow(10,decPlaces)
  471.     if (decPlaces > 0)
  472.         returnVal = test.substring(0,test.length-decPlaces) + "." + test.substring(test.length-decPlaces,test.length);
  473.     else if (decPlaces == 0)
  474.         returnVal = test.substring(0,test.length-decPlaces);
  475.     else
  476.         returnVal = myVal;
  477.  
  478.     return returnVal;
  479. } // END Fix
  480.  
  481. /* ======================================================================
  482. FUNCTION:      IsAlpha
  483.  
  484. INPUT:        str (string) - the string to be tested
  485.  
  486. RETURN:      true, if the string contains only alphabetic characters 
  487.                 false, otherwise.
  488.  
  489. PLATFORMS:    Netscape Navigator 3.01 and higher,
  490.                   Microsoft Internet Explorer 3.02 and higher,
  491.                   Netscape Enterprise Server 3.0,
  492.                   Microsoft IIS/ASP 3.0.
  493. ====================================================================== */
  494. function IsAlpha( str ) {
  495.     // Return immediately if an invalid value was passed in
  496.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  497.         return false;
  498.  
  499.     var isValid = true;
  500.  
  501.     str += "";    // convert to a string for performing string comparisons.
  502.  
  503.     // Loop through string one character at time,  breaking out of for
  504.     // loop when an non Alpha character is found.
  505.       for (i = 0; i < str.length; i++) {
  506.         // Alpha must be between "A"-"Z", or "a"-"z"
  507.         if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
  508.                   ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) ) {
  509.                          isValid = false;
  510.                          break;
  511.                   }
  512.    } // end for loop
  513.    
  514.     return isValid;
  515. }  // end IsAlpha 
  516.  
  517. /* ======================================================================
  518. FUNCTION:    IsAlphaNum
  519.  
  520. INPUT:        str (string) - a string that will be tested to ensure that
  521.                                       each character is a digit or a letter.
  522.  
  523. RETURN:      true, if all characters in the string are a character from 0-9
  524.                  or a-z or A-Z;  
  525.                 false, otherwise
  526.  
  527. PLATFORMS:    Netscape Navigator 3.01 and higher,
  528.                   Microsoft Internet Explorer 3.02 and higher,
  529.                   Netscape Enterprise Server 3.0,
  530.                   Microsoft IIS/ASP 3.0.
  531. ====================================================================== */
  532. function IsAlphaNum( str ) {
  533.     // Return immediately if an invalid value was passed in
  534.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  535.         return false;
  536.  
  537.     var isValid = true;
  538.     
  539.     // convert to a string for performing string comparisons.
  540.        str += "";    
  541.  
  542.     // Loop through length of string and test for any alpha numeric 
  543.     // characters
  544.        for (i = 0; i < str.length; i++)
  545.        {
  546.             // Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
  547.           if (!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
  548.                   ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
  549.                   ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
  550.             {
  551.                 isValid = false;
  552.                 break;
  553.             }    
  554.        } // END for   
  555.    
  556.        return isValid;
  557. }  // end IsAlphaNum
  558.  
  559. /* ======================================================================
  560. FUNCTION:    IsAlphaNumOrUnderscore
  561.  
  562. INPUT:        str (string) - the string to be tested
  563.  
  564. RETURN:      true, if the string contains only alphanumeric characters or underscores.
  565.                 false, otherwise.
  566.  
  567. PLATFORMS:    Netscape Navigator 3.01 and higher,
  568.                   Microsoft Internet Explorer 3.02 and higher,
  569.                   Netscape Enterprise Server 3.0,
  570.                   Microsoft IIS/ASP 3.0.
  571. ====================================================================== */
  572. function IsAlphaNumOrUnderscore( str ) {
  573.     // Return immediately if an invalid value was passed in
  574.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  575.         return false;
  576.  
  577.     var isValid = true;
  578.  
  579.     str += "";    // convert to a string for performing string comparisons.
  580.     // Loop through string one character at a time. If non-alpha numeric
  581.     // is found then, break out of loop and return a false result
  582.  
  583.     for (i = 0; i < str.length; i++)
  584.        {
  585.         // Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
  586.               if ( !( ((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
  587.                   ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
  588.                   ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ||
  589.                   (str.charAt(i) == "_") ) )
  590.               {
  591.                    isValid = false;
  592.                  break;
  593.               }
  594.  
  595.     } // END for   
  596.    
  597.     return isValid;
  598.  
  599. }  // end IsAlphaNumOrUnderscore
  600.  
  601. /* ======================================================================
  602. FUNCTION:      IsInt
  603.  
  604. INPUT:          numstr (string/number)      - the string that will be tested to ensure 
  605.                                                  that each character is a digit
  606.                 allowNegatives (boolean) - (optional) when true, allows numstr to be
  607.                                                     negative (contain a '-').  When false,
  608.                                                   any negative number or a string starting
  609.                                                     with a '-' will be considered invalid.
  610.  
  611. RETURN:      true, if all characters in the string are a character from 0-9,
  612.                 regardless of value for allowNegatives
  613.                 true, if allowNegatives is true and the string starts with a '-', and all other
  614.                 characters are 0-9.
  615.                  false, otherwise.
  616.  
  617. PLATFORMS:    Netscape Navigator 3.01 and higher,
  618.                   Microsoft Internet Explorer 3.02 and higher,
  619.                   Netscape Enterprise Server 3.0,
  620.                   Microsoft IIS/ASP 3.0.
  621. ====================================================================== */
  622. function IsInt( numstr, allowNegatives ) {
  623.     // Return immediately if an invalid value was passed in
  624.     if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")    
  625.         return false;
  626.  
  627.     // Default allowNegatives to true when undefined or null
  628.     if (allowNegatives+"" == "undefined" || allowNegatives+"" == "null")    
  629.         allowNegatives = true;
  630.  
  631.     var isValid = true;
  632.  
  633.     // convert to a string for performing string comparisons.
  634.     numstr += "";    
  635.  
  636.     // Loop through string and test each character. If any
  637.     // character is not a number, return a false result.
  638.      // Include special case for negative numbers (first char == '-').   
  639.     for (i = 0; i < numstr.length; i++) {
  640.         if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == "-"))) {
  641.            isValid = false;
  642.            break;
  643.         } else if ((numstr.charAt(i) == "-" && i != 0) || 
  644.                 (numstr.charAt(i) == "-" && !allowNegatives)) {
  645.            isValid = false;
  646.            break;
  647.       }
  648.                                  
  649.    } // END for   
  650.    
  651.        return isValid;
  652. }  // end IsInt
  653.  
  654. /* ======================================================================
  655. FUNCTION:      IsNum
  656.  
  657. INPUT:          numstr (string/number) - the string that will be tested to ensure 
  658.                                                that the value is a number (int or float)
  659.  
  660. RETURN:      true, if all characters represent a valid integer or float
  661.                  false, otherwise.
  662.  
  663. PLATFORMS:    Netscape Navigator 3.01 and higher,
  664.                   Microsoft Internet Explorer 3.02 and higher,
  665.                   Netscape Enterprise Server 3.0,
  666.                   Microsoft IIS/ASP 3.0.
  667. ====================================================================== */
  668. function IsNum( numstr ) {
  669.     // Return immediately if an invalid value was passed in
  670.     if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")    
  671.         return false;
  672.  
  673.     var isValid = true;
  674.     var decCount = 0;        // number of decimal points in the string
  675.  
  676.     // convert to a string for performing string comparisons.
  677.     numstr += "";    
  678.  
  679.     // Loop through string and test each character. If any
  680.     // character is not a number, return a false result.
  681.      // Include special cases for negative numbers (first char == '-')
  682.     // and a single decimal point (any one char in string == '.').   
  683.     for (i = 0; i < numstr.length; i++) {
  684.         // track number of decimal points
  685.         if (numstr.charAt(i) == ".")
  686.             decCount++;
  687.  
  688.         if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
  689.                 (numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
  690.            isValid = false;
  691.            break;
  692.         } else if ((numstr.charAt(i) == "-" && i != 0) ||
  693.                 (numstr.charAt(i) == "." && numstr.length == 1) ||
  694.               (numstr.charAt(i) == "." && decCount > 1)) {
  695.            isValid = false;
  696.            break;
  697.       }                                 
  698. //if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9")) || 
  699.    } // END for   
  700.    
  701.        return isValid;
  702. }  // end IsNum
  703. /* ======================================================================
  704. FUNCTION:      IsValid5DigitZip
  705.  
  706. INPUT:        str (string) - a 5-digit zip code to be tested
  707.  
  708. RETURN:      true, if the string is 5-digits long
  709.                 false, otherwise
  710.  
  711. CALLS:        IsBlank(), IsInt() which are defined elsewhere in the Script Library
  712.  
  713. PLATFORMS:    Netscape Navigator 3.01 and higher,
  714.                   Microsoft Internet Explorer 3.02 and higher,
  715.                   Netscape Enterprise Server 3.0,
  716.                   Microsoft IIS/ASP 3.0.
  717. ====================================================================== */
  718. function IsValid5DigitZip( str ) {
  719.     // Return immediately if an invalid value was passed in
  720.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  721.         return false;
  722.     
  723.     var isValid = true;
  724.  
  725.     str += "";
  726.  
  727.     // Rules: zipstr must be 5 characters long, and can only contain numbers from
  728.    // 0 through 9
  729.    if (IsBlank(str) || (str.length != 5) || !IsInt(str, false))
  730.         isValid = false;
  731.    
  732.    return isValid;
  733. } // end IsValid5DigitZip
  734. /* ======================================================================
  735. FUNCTION:      IsValid5Plus4DigitZip
  736.  
  737. INPUT:        str (string) - a 5+4 digit zip code to be tested
  738.  
  739. RETURN:      true, if the string contains 5-digits followed by a dash followed by 4 digits
  740.                 false, otherwise
  741.  
  742. CALLS:        IsBlank(), IsInt() which are defined elsewhere in the Script Library
  743.  
  744. PLATFORMS:    Netscape Navigator 3.01 and higher,
  745.                   Microsoft Internet Explorer 3.02 and higher,
  746.                   Netscape Enterprise Server 3.0,
  747.                   Microsoft IIS/ASP 3.0.
  748. ====================================================================== */
  749. function IsValid5Plus4DigitZip( str ) {
  750.     // Return immediately if an invalid value was passed in
  751.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  752.         return false;
  753.  
  754.     var isValid = true;
  755.  
  756.     str += "";
  757.  
  758.     // Rules: The first five characters may contain only digits 0-9,
  759.     // the 6th character must be a dash, '-', and 
  760.     // the last four characters may contain only digits 0-9.
  761.     // The total string length must be 10 characters.
  762.        if (IsBlank(str) || (str.length != 10) || 
  763.             !IsInt(str.substring(0,5), false) || str.charAt(5) != '-' ||
  764.             !IsInt(str.substring(6,10), false))
  765.         isValid = false;
  766.    
  767.        return isValid;
  768. } // end IsValid5Plus4DigitZip
  769. /* ======================================================================
  770. FUNCTION:      IsValidEmail
  771.  
  772. INPUT:        str (string) - an e-mail address to be tested
  773.  
  774. RETURN:      true, if the string contains a valid e-mail address which is a string
  775.                 plus an '@' character followed by another string containing at least 
  776.                 one '.' and ending in an alpha (non-punctuation) character.
  777.                 false, otherwise
  778.  
  779. CALLS:        IsBlank(), IsAlpha() which are defined elsewhere in the Script Library
  780.  
  781. PLATFORMS:    Netscape Navigator 3.01 and higher,
  782.                   Microsoft Internet Explorer 3.02 and higher,
  783.                   Netscape Enterprise Server 3.0,
  784.                   Microsoft IIS/ASP 3.0.
  785. ====================================================================== */
  786. function IsValidEmail( str ) {
  787.     // Return immediately if an invalid value was passed in
  788.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  789.         return false;
  790.  
  791.     var isValid = true;
  792.  
  793.     str += "";
  794.  
  795.     namestr = str.substring(0, str.indexOf("@"));  // everything before the '@'
  796.     domainstr = str.substring(str.indexOf("@")+1, str.length); // everything after the '@'
  797.  
  798.     // Rules: namestr cannot be empty, or that would indicate no characters before the '@',
  799.     // domainstr must contain a period that is not the first character (i.e. right after
  800.     // the '@').  The last character must be an alpha.
  801.        if (IsBlank(str) || (namestr.length == 0) || 
  802.             (domainstr.indexOf(".") <= 0) ||
  803.             (domainstr.indexOf("@") != -1) ||
  804.             !IsAlpha(str.charAt(str.length-1)))
  805.         isValid = false;
  806.    
  807.        return isValid;
  808. } // end IsValidEmail
  809. /* ======================================================================
  810. FUNCTION:      IsValidPhone
  811.  
  812. INPUT:        str (string) - an phone number to be tested
  813.                 incAreaCode (boolean) - if true, area code is included (10-digits);
  814.                                                 if false or undefined, area code not included
  815.  
  816. RETURN:      true, if the string contains a 7-digit phone number and incAreaCode == false
  817.                 or is undefined
  818.                 true, if the string contains a 10-digit phone number and incAreaCode == true
  819.                 false, otherwise
  820.  
  821. CALLS:        StripNonNumeric(), which is defined elsewhere in the Script Library
  822.  
  823. PLATFORMS:    Netscape Navigator 3.01 and higher,
  824.                   Microsoft Internet Explorer 3.02 and higher,
  825.                   Netscape Enterprise Server 3.0,
  826.                   Microsoft IIS/ASP 3.0.
  827. ====================================================================== */
  828. function IsValidPhone( str, incAreaCode ) {
  829.     // Return immediately if an invalid value was passed in
  830.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  831.         return false;
  832.  
  833.     // Set default value for incAreaCode to false, if undefined or null
  834.     if (incAreaCode+"" == "undefined" || incAreaCode+"" == "null")    
  835.         incAreaCode = false;
  836.  
  837.     var isValid = true;
  838.  
  839.     str += "";
  840.  
  841.     // After stripping out non-numeric characters, such as dashes, the
  842.     // phone number should contain 7 digits (no area code) or 10 digits (area code)
  843.     str = StripNonNumeric(str+"");
  844.     if (incAreaCode && str.length != 10)
  845.         isValid = false;
  846.    if (!incAreaCode && str.length != 7)
  847.         isValid = false;
  848.  
  849.        return isValid;
  850. } // end IsValidPhone
  851. /* ======================================================================
  852. FUNCTION:      IsValidSSN
  853.  
  854. INPUT:        str (string) - an phone number to be tested
  855.                 incDashes (boolean) - if true, str includes dashes (e.g. 111-12-3456);
  856.                                              if false, str contains only digits
  857.                 
  858. RETURN:      true, if the string contains digits and dashes in the form 111-12-3456;
  859.                 true, if the string contains a 9-digit number and incDashes is false;
  860.                 false, otherwise
  861.  
  862. CALLS:        IsInt(), which is defined elsewhere in the Script Library
  863.  
  864. PLATFORMS:    Netscape Navigator 3.01 and higher,
  865.                   Microsoft Internet Explorer 3.02 and higher,
  866.                   Netscape Enterprise Server 3.0,
  867.                   Microsoft IIS/ASP 3.0.
  868. ====================================================================== */
  869. function IsValidSSN( str, incDashes ) {
  870.     // Return immediately if an invalid value was passed in
  871.     if (str+"" == "undefined" || str+"" == "null" || str+"" == "")    
  872.         return false;
  873.  
  874.     var isValid = true;
  875.  
  876.     // Set default value for incDashes to true, if undefined or null
  877.     if (incDashes+"" == "undefined" || incDashes+"" == "null")    
  878.         incDashes = true;
  879.  
  880.     str += "";    // make sure it's a string
  881.  
  882.     if (!incDashes && (!IsNum(str) || str.length != 9))
  883.         isValid = false;
  884.  
  885.     var part1 = str.substring(0,3);
  886.     var part2 = str.substring(4,6);
  887.     var part3 = str.substring(7,str.length);
  888.  
  889.     // Ensure that the first part is a number and 3 digits long,
  890.     // the second part is a number and 2 digits long,
  891.     // the third part is a number and 4 digits long, e.g. 111-22-3333
  892.     if (incDashes && ((!IsInt(part1, false) || part1.length != 3) ||
  893.             (!IsInt(part2, false) || part2.length != 2) || 
  894.             (!IsInt(part3, false) || part3.length != 4)) )
  895.         isValid = false;
  896.  
  897.        return isValid;
  898. } // end IsValidSSN
  899.  
  900.  
  901. /* ======================================================================
  902. FUNCTION:    IsBlank
  903.  
  904. INPUT:        val - the value to be tested
  905.  
  906. RETURN:      true, if the string is null, undefined or an empty string, ""
  907.               false, otherwise.
  908.  
  909. CALLS:        IsNull(), IsUndef() which are defined elsewhere in the Script Library
  910.  
  911. PLATFORMS:    Netscape Navigator 3.01 and higher,
  912.                   Microsoft Internet Explorer 3.02 and higher,
  913.                   Netscape Enterprise Server 3.0,
  914.                   Microsoft IIS/ASP 3.0.
  915. ====================================================================== */
  916. function IsBlank( str ) {
  917.     var isValid = false;
  918.  
  919.      if ( IsNull(str) || IsUndef(str) || (str+"" == "") )
  920.          isValid = true;
  921.         
  922.     return isValid;
  923. }  // end IsBlank
  924. /* ======================================================================
  925. FUNCTION:    IsNull
  926.  
  927. INPUT:        val - the value to be tested
  928.  
  929. RETURN:      true, if the value is null;
  930.               false, otherwise.
  931.  
  932. PLATFORMS:    Netscape Navigator 3.01 and higher,
  933.                   Microsoft Internet Explorer 3.02 and higher,
  934.                   Netscape Enterprise Server 3.0,
  935.                   Microsoft IIS/ASP 3.0.
  936. ====================================================================== */
  937. function IsNull( val ) {
  938.     var isValid = false;
  939.  
  940.      if (val+"" == "null")
  941.          isValid = true;
  942.         
  943.     return isValid;
  944. }  // end IsNull
  945. /* ======================================================================
  946. FUNCTION:    IsUndef
  947.  
  948. INPUT:        val - the value to be tested
  949.  
  950. RETURN:      true, if the value is undefined
  951.               false, otherwise.
  952.  
  953. PLATFORMS:    Netscape Navigator 3.01 and higher,
  954.                   Microsoft Internet Explorer 3.02 and higher,
  955.                   Netscape Enterprise Server 3.0,
  956.                   Microsoft IIS/ASP 3.0.
  957. ====================================================================== */
  958. function IsUndef( val ) {
  959.     var isValid = false;
  960.  
  961.      if (val+"" == "undefined")
  962.          isValid = true;
  963.         
  964.     return isValid;
  965. }  // end IsUndef
  966.  
  967. /* ======================================================================
  968. FUNCTION:    StripNonNumeric
  969.  
  970. INPUT:          str (string) - a string to be altered
  971.  
  972. RETURN:         a string containing only numeric characters 0-9;
  973.                 returns null if invalid arguments were passed
  974.  
  975. DESC:            This function removes all non-numeric characters from a given
  976.                 string.  It is useful for removing dashes, parentheses, etc. from input 
  977.                 strings such as credit card numbers or phone nubmers.
  978. ====================================================================== */
  979. function StripNonNumeric( str ) {
  980.     var     resultStr = "";
  981.  
  982.     // Return immediately if an invalid value was passed in
  983.     if (str+"" == "undefined" || str == null)    
  984.         return null;
  985.  
  986.     // Make sure the argument is a string
  987.     str += "";
  988.  
  989.     // Loop through entire string, adding each character from the original
  990.     // string if it is a number
  991.     for (var i=0; i < str.length; i++)
  992.     {
  993.        if ( (str.charAt(i) >= "0") && (str.charAt(i) <= "9") )
  994.                   resultStr = resultStr + str.charAt(i);
  995.  
  996.    } // end for loop      
  997.  
  998.    return resultStr;
  999. }  // end StripNonNumeric
  1000.  
  1001.  
  1002. // Shared Array Parsing function
  1003.  function unEncodeJS(input) {  
  1004.      if (null == input)  
  1005.          return null;  
  1006.      if (input == "null" )  
  1007.          return null;  
  1008.      output = "";  
  1009.      i=0;  
  1010.      while (i<input.length) {  
  1011.          ch = input.charAt(i++);  
  1012.          if ('\\' == ch) {  
  1013.              ch = input.charAt(i++);  
  1014.              if ('n' == ch) {  
  1015.                  output += '\n';  
  1016.              } else if (';' == ch) {  
  1017.                  output += ';';  
  1018.              } else if ('r' == ch) {  
  1019.                  //supress this character  
  1020.              } else if ('t' == ch) {  
  1021.                  output += '\t';  
  1022.              } else {  
  1023.                  output += ch;  
  1024.              }  
  1025.          } else {  
  1026.              output += ch;  
  1027.          }  
  1028.      }  
  1029.      return output;  
  1030.  } // END unEncodeList  
  1031.  
  1032.  function unEncodeList( sList ) {  
  1033.      aRes = null;  
  1034.      if ( null != sList && ""!=sList ) {  
  1035.          aRes = new Array();  
  1036.          iStart = 0;  
  1037.          iIndex = 0;  
  1038.          j=0;  
  1039.          while (j<sList.length) {  
  1040.              ch = sList.charAt(j++);  
  1041.              if ('\\' == ch) {  
  1042.                  ch = sList.charAt(j++);  
  1043.              } else {  
  1044.                  if ( ';' == ch ) {  
  1045.                      sRaw = sList.substring( iStart, j-1 );  
  1046.                      aRes[iIndex++] = unEncodeJS( sRaw );  
  1047.                      iStart = j;  
  1048.                  }  
  1049.              }  
  1050.          }  
  1051.          if ( iStart != j ) {  
  1052.              sRaw = sList.substring( iStart, j );  
  1053.              aRes[iIndex++] = unEncodeJS( sRaw );  
  1054.          }  
  1055.      }  
  1056.      return aRes;  
  1057. } // END unEncodeList
  1058.