// toolbox_javascript.js//// This contains all the common elements for DKA validation and other JavaScript function//// ARRAY FUNCTIONS// define_states();//// UTILITY FUNCTIONS// calendar($form_name, $field_name);// is_string($VAR);// openWin($URL);// openWin_with_menubar($URL)//// VALIDATION FUNCTIONS// validate_initialize();  <---  Always call this first!// validate_date($DATE, $FORMAT);// validate_date_MDY($DATE);// validate_date_YMD($DATE);// validate_day($DAY);// validate_digit($CHECK);// validate_digits_all($CHECK);// validate_element_as_date($ID, $FORMAT);// validate_element_as_email($ID);// validate_element_as_extention($ID);// validate_element_as_in_selection($ID, $LIST);// validate_element_as_not_empty($ID);// validate_element_as_phone($ID, $FORMAT, $EMPTY);// validate_element_as_ssn($ID);// validate_element_as_state($ID);// validate_element_as_zip($ID);// validate_email($MAIL);// validate_extention($extention);// validate_in_selection($ID, $LIST);// validate_integer_range($CHECK, $LOW, $HIGH);// validate_month($MONTH);// validate_not_empty($DATA);// validate_phone($PHONE, $FORMAT, $EMPTY);// validate_phone_LONG($PHONE);// validate_phone_SHORT($PHONE);// validate_selection($VALUE, $LIST);// validate_ssn($SSN);// validate_state($STATE);// validate_year($YEAR);// validate_zip($ZIP);////// PRIVATE FUNCTIONS:// toolbox_error($function, $location, $message)// toolbox_error_to_string($data)////// Define toolbox variables// Public vars (really for read only purposes)var $ERROR; // The global error message as a stringvar $ERROR_MESSAGE; // Boolean true = an error has occured, false = no error// Private varsvar $toolbox_year_low;  // The lowest valid yearvar $toolbox_year_high; // The highest valid year// Initialize toolbox variables$ERROR_MESSAGE='';  // Start with no error$ERROR=false;       // Start with no error$toolbox_year_low = 2000;  // The lowest valid year$toolbox_year_high = 2010; // The highest valid year///////////////////////////////////////function toolbox_error($FUNCTION, $LOCATION, $MESSAGE){//alert ("toolbox_error("+$FUNCTION+", "+$LOCATION+", "+$MESSAGE+")");  // Formats an error message  //  // YOU SHOULD NOT BE USING THIS FUNCTION OUTSIDE OF toolbox_javascript.js  // CONSIDER THIS A PRIVATE FUNCTION  //  // WARNING: GIGO IN EFFECT  //  // Parameters:  //  $FUNCTION = (string) the name, and parameters, of the function where the error was detected  //  $LOCATION = (string) the name (or number) of a location inside the function, these should all be unique  //  $MESSAGE = (string) the diagnostic information to return in the error message  //  //  $line = "ERROR IN "+$FUNCTION+" AT "+$LOCATION+" => ["+$MESSAGE+"]\n";  $ERROR_MESSAGE=$line+$ERROR_MESSAGE;  $ERROR=true;  //  // No return value} // function toolbox_error($function, $location, $message)function toolbox_error_to_string($DATA){//alert ("toolbox_error_to_string("+$DATA+")");  // Returns a string for any input  //  // YOU SHOULD NOT BE USING THIS FUNCTION OUTSIDE OF toolbox_javascript.js  // CONSIDER THIS A PRIVATE FUNCTION  //  // WARNING: GIGO IN EFFECT  //  // Parameters:  //  $DATA = the variable information to report as a string  //  //  // Is the data already a string?  if (is_string($DATA))  {    // Yes, already a string    $result=$DATA;  }  else  {    // No, not a string    $result=$DATA.toString();  } // if (is_string($DATA))  //  return $result;} // function toolbox_error_to_string($data)////////////////////////////////////////////////////////////////////////////// UTILITY FUNCTIONSfunction clean_dollar($dollar){  // Remove $ and comma and trim whitespace from a value  //  // $dollar (string)  //  // output  (string)  //  /////////////////  // Remove dollar signs  $dollar=$dollar.replace(/\$/gi, "");  // remove commas  $dollar=$dollar.replace(/,/gi, "");  // trim white space  $result=trim($dollar);  //
  // output  (string)  return $result;  //} // function date_convert_mdy_ymd($mdy)////function date_convert_mdy_ymd($mdy){//alert("date_convert_mdy_ymd("+$mdy+")");  // Converts a date from mm/dd/yyyy to yyyy-mm-dd format  //  // Divider can be / or -  //  // output is always -  //  $normalized=$mdy.replace("/", "-");  $pieces=split($mdy, '-');  $result=$pieces[2]+"-"+$pieces[0]+"-"+$pieces[1];  //  return $result;} // function date_convert_mdy_ymd($mdy)function define_states(){//alert("define_states()");  // Create at array with all legal US postal codes  //  //  $result=new Array("AA", "AE", "AK", "AL", "AP", "AR", "AS", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "FM", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MH", "MI", "MN", "MO", "MP", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "PR", "PW", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY");  //  return $result;} // function define_states()function is_string($VAR){//alert("is_string("+$VAR+")");  // Returns true if var is a string  //  //  // Parameters:  //  $VAR = (any) variable to test for string  //  //  if (typeof($VAR)!="string")  {    // Not a string    toolbox_error("is_string(" + $VAR + ")", "1", "VAR is not a string");    $result=false;  }  else  {    // Is a string    $result=true;  } // if (typeof($VAR)!="string")  //  return $result;} // function is_string($VAR)function openWin($URL){  // Description  //  Opens a window and displays the URL  //  // Parameters  //  $URL = full URL to open  //  // Returns  //  (void)  //  aWindow=window.open($URL, "thewindow", "toolbar=yes, directories=yes, location=yes, status=yes, scrollbars=yes, resizable=yes, width=800, height=420, left=20, top=20");  //} // function openWin($URL)function openWin_with_menubar($URL,$name){  // Description  //  Opens a window  with a menubar and displays the URL  //  // Parameters  //  $URL = full URL to open  //  // Returns  //  (void)  //  //alert($name);  aWindow=window.open($URL,$name,"toolbar=yes,directories=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,width=800,height=420,left=20,top=20");  //} // function openWin_with_menubar($URL,$name)function openWin_named($URL, $name){  // Description  //  Opens a window and displays the URL  //  // Parameters  //  $URL = full URL to open  //  // Returns  //  (void)  //  aWindow=window.open($URL, $name, "toolbar=yes, directories=yes, location=yes, status=yes, scrollbars=yes, resizable=yes, width=800, height=420, left=20, top=20");  //} // function openWin_named($URL)////////////////////////////////////////////////////////////////////////////// VALIDATION FUNCTIONSfunction validate_initialize(){  // Sets the error variables for another form validation  //  $ERROR=false;  $ERROR_MESSAGE="";  //  // No return} // function validate_initialize()function validate_date($DATE, $FORMAT){//alert("validate_date("+$DATE+", "+$FORMAT+")");  // Returns true if the date is in the proper given format  //  // Parameters:  //  $PHONE = (string) phone to be checked  //  $FORMAT = (string) format to use  YMD, MDY, BOTH  //                     YMD = YYYY-MM-DD  //                     MDY = MM-DD-YYYY  //                     BOTH  = either YMD or MDY  //                     Note: Will accept either - or / for dividers  //  //  // Is the format legal?  switch ($FORMAT)  {    case "YMD":      // Is the date good?      if (!validate_date_YMD($DATE))      {        // The date is bad        $error_DATE=toolbox_error_to_string($DATE);        $error_FORMAT=toolbox_error_to_string($FORMAT);        toolbox_error("validate_date(" + $error_DATE + ", " + $error_FORMAT + ")", "1", "Date is invalid YMD");        $result=false;      }      else      {        // The format is good        $result=true;      } // if (!validate_date_YMD($DATE))    break; // YMD    //    case "MDY":      // Is the date good?      if (!validate_date_MDY($DATE))      {        // The date is bad        $error_DATE=toolbox_error_to_string($DATE);        $error_FORMAT=toolbox_error_to_string($FORMAT);        toolbox_error("validate_date(" + $error_DATE + ", " + $error_FORMAT + ")", "2", "Date is invalid MDY");        $result=false;      }      else      {        // The format is good        $result=true;      } // if (!validate_date_DMY($DATE))    break; // MDY    //    case "BOTH":      // Is the date good?      if ((!validate_date_YMD($DATE)) || (!validate_date_MDY($DATE)))      {        // The date is bad        $error_DATE=toolbox_error_to_string($DATE);        $error_FORMAT=toolbox_error_to_string($FORMAT);        toolbox_error("validate_date(" + $error_DATE + ", " + $error_FORMAT + ")", "3", "Date is invalid YMD or MDY");        $result=false;      }      else      {        // The format is good        $result=true;      } // if ((!validate_date_MDY($DATE)) || (!validate_date_MDY($DATE)))    break; // BOTH    //    default:      // Format is not valid      $error_DATE=toolbox_error_to_string($DATE);      $error_FORMAT=toolbox_error_to_string($FORMAT);      toolbox_error("validate_date(" + $error_DATE + ", " + $error_FORMAT + ")", "4", "Invalid format parameter");      $result=false;    break;  } // switch ($FORMAT)  //  return $result;} // function validate_date($PHONE, $FORMAT)function validate_date_MDY($DATE){//alert ("validate_date_MDY("+$DATE+")");  // Checks to see if the given data is a vaild date in MM-DD-YYYY format  //                                                    0123456789  // Will accept either - or / as seperators  //  // WARNING:  // DOES NOT validate if the date is legal, just that it has the right format.  Beware leap years!  //  // Paramaters:  //  $DATE = (string) data to check  //  //  // Get rid of /'s  $DATE.replace("//", "_");  //  // Break into component pieces  $month=$DATE.substr(0, 2);  $div1=$DATE.substr(2, 1);  $day=$DATE.substr(3, 2);  $div2=$DATE.substr(4, 1);  $year=$DATE.substr(6, 4);  //  // Is the year correct?  if (!validate_year($year))  {    // No, it is not correct    $error_DATE=toolbox_error_to_string($DATE);    toolbox_error("validate_date_MDY(" + $error_DATE + ")", "1", "Invalid MM-DD-YYYY format: Invalid year");    $result=false;  }  else  {    // Yes, it is a good year    // Is the divider good?    if ($div1!='-')    {      // No, not a good divider      $error_DATE=toolbox_error_to_string($DATE);      toolbox_error("validate_date_MDY(" + $error_DATE + ")", "2", "Invalid MM-DD-YYYY format: Invalid divider (1)");      $result=false;    }    else    {      // Yes, the first divider is good      // Is the month valid?      if (!validate_month($month))      {        // Not a valid month        $error_DATE=toolbox_error_to_string($DATE);        toolbox_error("validate_date_MDY(" + $error_DATE + ")", "3", "Invalid MM-DD-YYYY format: Invalid month");        $result=false;      }      else      {        // Is the second divider good?        if ($div2!='-')        {          // No, not a good divider          $error_DATE=toolbox_error_to_string($DATE);          toolbox_error("validate_date_MDY(" + $error_DATE + ")", "4", "Invalid YYYY-MM-DD format: Invalid divider (2)");          $result=false;        }        else        {          // Yes, the divider is good          // Is the day valid?          if (!validate_day($day))          {            // Not a valid day            $error_DATE=toolbox_error_to_string($DATE);            toolbox_error("validate_date_MDY(" + $error_DATE + ")", "5", "Invalid MM-DD-YYYY format: Invalid day");            $result=false;          }          else          {            // Yes, it is a good MM-DD-YYYY format            $result=true;          } // if (!validate_day($day))        } // if ($div2!='-')      } // if (!validate_month($month))    } // if ($div1!='-')  } // if (!validate_year($year))  //  return $result;} // function validate_date_MDY($DATE)function validate_date_YMD($DATE){//alert ("validate_date_YMD("+$DATE+")");  // Checks to see if the given data is a vaild date in YYYY-MM-DD format  //                                                    0123456789  // Will accept either - or / as seperators  //  // WARNING:  // DOES NOT validate if the date is legal, just that it has the right format.  Beware leap years!  //  // Paramaters:  //  $DATE = (string) data to check  //  //  // Get rid of /'s  $DATE.replace("//", "_");  //  // Break into component pieces  $year=$DATE.substr(0, 4);  $div1=$DATE.substr(4, 1);  $month=$DATE.substr(5, 2);  $div2=$DATE.substr(7, 1);  $day=$DATE.substr(8, 2);  //  // Is the year correct?  if (!validate_year($year))  {    // No, it is not correct    $error_DATE=toolbox_error_to_string($DATE);    toolbox_error("validate_date_YMD(" + $error_DATE + ")", "1", "Invalid YYYY-MM-DD format: Invalid year");    $result=false;  }  else  {    // Yes, it is a good year    // Is the divider good?    if ($div1!='-')    {      // No, not a good divider      $error_DATE=toolbox_error_to_string($DATE);      toolbox_error("validate_date_YMD(" + $error_DATE + ")", "2", "Invalid YYYY-MM-DD format: Invalid divider (1)");      $result=false;    }    else    {      // Yes, the first divider is good      // Is the month valid?      if (!validate_month($month))      {        // Not a valid month        $error_DATE=toolbox_error_to_string($DATE);        toolbox_error("validate_date_YMD(" + $error_DATE + ")", "3", "Invalid YYYY-MM-DD format: Invalid month");        $result=false;      }      else      {        // Is the second divider good?        if ($div2!='-')        {          // No, not a good divider          $error_DATE=toolbox_error_to_string($DATE);          toolbox_error("validate_date_YMD(" + $error_DATE + ")", "4", "Invalid YYYY-MM-DD format: Invalid divider (2)");          $result=false;        }        else        {          // Yes, the divider is good          // Is the day valid?          if (!validate_day($day))          {            // Not a valid day            $error_DATE=toolbox_error_to_string($DATE);            toolbox_error("validate_date_YMD(" + $error_DATE + ")", "5", "Invalid YYYY-MM-DD format: Invalid day");            $result=false;          }          else          {            // Yes, it is a good YYYY-MM-DD format            $result=true;          } // if (!validate_day($day))        } // if ($div2!='-')      } // if (!validate_month($month))    } // if ($div1!='-')  } // if (!validate_year($year))  //  return $result;} // function validate_date_YMD($DATE)function validate_day($DAY){//alert ("validate_day("+$DAY+")");  // Checks to see if the given data is a valid day 01..31  //  // Parameters  //  $DAY = data to check  //  // Is this a valid date?  if (($DAY>=1) && ($DAY<=31))  {    // Yes, valid    $result=true;  }  else  {    // No, not valid    $result=false;  } // if (($DAY>=1) && ($DAY<=31))  //  return $result;} // function validate_day($DAY)function validate_element_as_date($ID, $FORMAT){//alert ("validate_element_as_date("+$ID+")");  // Checks to see if the given form element holds a valid date for a given format  //  // Parameters  //  $ID = (string) ID of a valid element  //  $FORMAT = (string) designated format to check: 'YMD', 'MDY' or 'BOTH'  //  //  // Does the element exist?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    $error_FORMAT=toolbox_error_to_string($FORMAT);    toolbox_error("validate_element_as_date(" + $error_ID + ", " + $error_FORMAT + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $PHONE=document.getElementById($ID).value;    $result=validate_phone($PHONE, $FORMAT);    // Is it a valid phone?    if (!$result)    {      // No, not a valid phone      $error_ID=toolbox_error_to_string($ID);      $error_FORMAT=toolbox_error_to_string($FORMAT);      toolbox_error("validate_element_as_date(" + $error_ID + ", " + $error_FORMAT + ")", "2", "Element is not a valid phone");    }    else    {      // Yes, valid phone      // Do nothing more    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_date($ID, $FORMAT)function validate_element_as_email($ID){//alert ("validate_element_as_email("+$ID+")");  // Return true if element is a valid email address (in format)  //  // Parameters:  //  $ID = (string) name of element  //  //  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    toolbox_error("validate_element_as_email(" + $error_ID + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $EMAIL=document.getElementById($ID).value;    $result=validate_email($EMAIL);    // Was it empty?    if (!$result)    {      // It is empty      $error_ID=toolbox_error_to_string($ID);      toolbox_error("validate_element_as_email(" + $error_ID + ")", "2", "Element value is not an email");      $result=false;    }    else    {      // No, not empty, which is good      // Do nothing else    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_email($ID)function validate_element_as_extention($ID){//alert ("validate_element_as_extention("+$ID+")");  // Returns true if the field has a valid extention  //  // Parameters  //  $ID = (string) object name  //  //  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    toolbox_error("validate_element_extention(" + $error_ID + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $ext=document.getElementById($ID).value;    // Is it all digits?  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_extention($ID)function validate_element_as_not_empty($ID){//alert ("validate_element_as_not_empty("+$ID+")");  // Return true if element is not empty  //  // Parameters:  //  $ID = (string) name of element  //  //  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    toolbox_error("validate_element_as_not_empty(" + $error_ID + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $data=document.getElementById($ID).value;    $result=validate_not_empty($data);    // Was it empty?    if (!$result)    {      // It is empty      $error_ID=toolbox_error_to_string($ID);      toolbox_error("validate_element_as_not_empty(" + $error_ID + ")", "2", "Element value is empty");      $result=false;    }    else    {      // No, not empty, which is good      // Do nothing else    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_not_empty($ID)function validate_element_as_phone($ID, $FORMAT, $EMPTY){//alert ("validate_element_as_phone("+$ID+", "+$FORMAT+", "+$EMPTY+")");  // Return true if element is a phone in format ###-###-####  //  // Parameters:  //  $ID = (string) name of element to validate  //  $FORMAT = (string) type of format list: "LONG", "SHORT", "BOTH"  //  $EMPTY = (boolean) allow empty to be considered valid  //  //  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    $error_FORMAT=toolbox_error_to_string($FORMAT);    $error_EMPTY=toolbox_error_to_string($EMPTY);    toolbox_error("validate_element_as_phone(" + $error_ID + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $phone=document.getElementById($ID).value;    // Does the phone validate?    if (!validate_phone($phone, $FORMAT, $EMPTY))    {      // No the phone does not validate      $error_ID=toolbox_error_to_string($ID);      $error_FORMAT=toolbox_error_to_string($FORMAT);      $error_EMPTY=toolbox_error_to_string($EMPTY);      toolbox_error("validate_element_as_phone(" + $error_ID + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "2", "Element value is not a phone");      $result=false;    }    else    {      // Yes, it validates      $result=true;    } // if (!validate_phone($phone, $FORMAT, $EMPTY))  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_phone($ID, $EMPTY)function validate_element_as_selection($ID, $LIST){//alert ("validate_element_as_selection("+$ID+")");  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    $error_LIST=toolbox_error_to_string($LIST);    toolbox_error("validate_element_as_selection(" + $error_ID + ", " + $error_LIST + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $VALUE=document.getElementById($ID).value;    $result=validate_selection($VALUE, $LIST);    // Did it validate?    if (!$result)    {      // No, did not validate      toolbox_error("validate_element_as_selection(" + $error_ID + ")", "2", "Element value is not a selection list");      $result=false;    }    else    {      // Yes, it validated      // Do nothing more    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_selection($ID, $LIST)function validate_element_as_ssn($ID){//alert ("validate_element_as_ssn("+$ID+")");  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    toolbox_error("validate_element_as_ssn(" + $error_ID + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $SSN=document.getElementById($ID).value;    $result=validate_ssn($SSN);    // Did it validate?    if (!$result)    {      // No, did not validate      $error_ID=toolbox_error_to_string($ID);      toolbox_error("validate_element_as_ssn(" + $error_ID + ")", "2", "Element value is not a SSN");      $result=false;    }    else    {      // Yes, it validated      // Do nothing more    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_ssn($ID)function validate_element_as_state($ID){//alert ("validate_element_as_state("+$ID+")");  // Is the object valid?  if (document.getElementById($ID).value==null)  {    // No, it does not exist    $error_ID=toolbox_error_to_string($ID);    toolbox_error("validate_element_as_state(" + $error_ID + ")", "1", "Element does not exist");    $result=false;  }  else  {    // Yes, element exists    $STATE=document.getElementById($ID).value;    $result=validate_state($STATE);    // Did it validate?    if (!$result)    {      // No, did not validate      toolbox_error("validate_element_as_state(" + $error_ID + ")", "2", "Element value is not a state");      $result=false;    }    else    {      // Yes, it validated      // Do nothing more    } // if (!$result)  } // if (document.getElementById($ID).value==null)  //  return $result;} // function validate_element_as_state($ID)function validate_digit($CHECK){//alert ("validate_digit("+$CHECK+")");  // Returns true if check is a digit 0..9  //  // Parameters:  //  $CHECK = (string) data to test  //  //  // Is this a digit?  if (($CHECK!="0") &&      ($CHECK!="1") &&      ($CHECK!="2") &&      ($CHECK!="3") &&      ($CHECK!="4") &&      ($CHECK!="5") &&      ($CHECK!="6") &&      ($CHECK!="7") &&      ($CHECK!="8") &&      ($CHECK!="9"))  {    // No, it is not a digit    $error_CHECK=toolbox_error_to_string($CHECK);    toolbox_error("validate_digit(" + $error_CHECK + ")", "1", "Not a digit");    $result=false;  }  else  {    // Yes, it is a digit    $result=true;  } // if [in range]  //  return $result;} // function validate_digit($CHECK)function validate_digits_all($CHECK){//alert ("validate_digits_all("+$CHECK+")");  // Returns true if check is all digits  //  // Parameters:  //  $CHECK = (string) data to test  //  //  var $a;  //  // Is the string empty?  if ($CHECK=="")  {    // Yes, the string is empty    $error_CHECK=toolbox_error_to_string($CHECK);    toolbox_error("validate_digits_all(" + $error_CHECK + ")", "1", "Not all digits [empty]");    $result=false;  }  else  {    // Not empty    for($a=0; $a<$CHECK.length; $a++)    {      $testme=$CHECK.substr($a, 1);      // Is this a digit?      if (!validate_digit($testme))      {        // No, it is not a digit        $error_CHECK=toolbox_error_to_string($CHECK);        toolbox_error("validate_digits_all(" + $error_CHECK + ")", "2", "Not all digits");        $result=false;        break;      }      else      {        // Yes, it is a digit        // Do nothing more      } // if (!validate_digit($testme))    } // for($a=0; $a<$CHECK.length; $a++)  } // if ($CHECK=="")  //  return $result;} // function validate_digits_all($CHECK)function validate_email($EMAIL){//alert ("validate_email("+$EMAIL+")");  // This script and many more are available free online at  // The JavaScript Source!! http://javascript.internet.com  //  // V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com)  // Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com)  // Changes:  //  // MODIFICATION:  //  Char-Lez Braden  //  2006-06-12  //   - Modified to fit the DKA javascript toolbox  //  /*  1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters  international characters) were allowed.  1.1.3: Added the restriction to only accept addresses ending in two  letters (interpreted to be a country code) or one of the known  TLDs (com, net, org, edu, int, mil, gov, arpa), including the  new ones (biz, aero, name, coop, info, pro, museum).  One can  easily update the list (if ICANN adds even more TLDs in the  future) by updating the knownDomsPat variable near the  top of the function.  Also, I added a variable at the top  of the function that determines whether or not TLDs should be  checked at all.  This is good if you are using this function  internally (i.e. intranet site) where hostnames don't have to  conform to W3C standards and thus internal organization e-mail  addresses don't have to either.  Changed some of the logic so that the function will work properly  with Netscape 6.  1.1.2: Fixed a bug where trailing . in e-mail address was passing  (the bug is actually in the weak regexp engine of the browser; I  simplified the regexps to make it work).  1.1.1: Removed restriction that countries must be preceded by a domain,  so abc@host.uk is now legal.  However, there's still the  restriction that an address must end in a two or three letter  word.  1.1: Rewrote most of the function to conform more closely to RFC 822.  1.0: Original  */  ////////////// INITIALIZE VARIABLES ////////////////////  /* var "checkTLD" tells the rest of the function whether or not  to verify that the address ends in a two-letter country or well-known  TLD.  1 means check it, 0 means don't. */  var checkTLD=1;  /* var "knownDomsPat" is the list of known TLDs that an e-mail address must end with. */  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;  /* var "emailPat" is used to check if the entered e-mail address  fits the user@domain format.  It also is used to separate the username  from the domain. */  var emailPat=/^(.+)@(.+)$/;  /* var "specialChars" represents the pattern for matching all special  characters.  We don't want to allow special characters in the address.  These characters include ( ) < > @ , ; : \ " . [ ] */  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";  /* var "validChars" represents the range of characters allowed in a  username or domainname.  It really states which chars aren't allowed.*/  var validChars="\[^\\s" + specialChars + "\]";  /* var "quotedUser" applies if the "user" is a quoted string (in  which case, there are no rules about which characters are allowed  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com  is a legal e-mail address. */  var quotedUser="(\"[^\"]*\")";  /* var "ipDomainPat" applies for domains that are IP addresses,  rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal  e-mail address. NOTE: The square brackets are required. */  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;  /* var "atom" represents an atom (basically a series of non-special characters.) */  var atom=validChars + '+';  /* var "word" represents one word in the typical username.  For example, in john.doe@somewhere.com, john and doe are words.  Basically, a word is either an atom or quoted string. */  var word="(" + atom + "|" + quotedUser + ")";  /* var "userPat" describes the structure of the user */  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");  /* var "domainPat" describes the structure of a normal symbolic  domain, as opposed to ipDomainPat, shown above. */  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");  $result=true; // Assume true, prove false. -CBB  ////////////// BEGIN //////////////  /* Finally, let's start trying to figure out if the supplied address is valid. */  /* Begin with the coarse pattern to simply break up user@domain into  different pieces that are easy to analyze. */  var matchArray=$EMAIL.match(emailPat);  if (matchArray==null)  {    /* Too many/few @'s or something; basically, this address doesn't    even fit the general mould of a valid e-mail address. */    //    $error_DATA=toolbox_error_to_string($EMAIL);    toolbox_error("validate_not_empty(" + $error_DATA + ")", "1", "Does not fit basic format name@domain");    $result=false;  }  else  {    var user=matchArray[1];    var domain=matchArray[2];    // Start by checking that only basic ASCII characters are in the strings (0-127).    for (i=0; i<user.length; i++)    {      if (user.charCodeAt(i)>127)      {        // Character is invalid        $error_DATA=toolbox_error_to_string($EMAIL);        toolbox_error("validate_not_empty(" + $error_DATA + ")", "2", "User has invalid characters");        $result=false;        break;      }      else      {        // Character is good        // Do nothing more      } // if (user.charCodeAt(i)>127)    } // for (i=0; i<user.length; i++)    //    for (i=0; i<domain.length; i++)    {      if (domain.charCodeAt(i)>127)      {        // Invalid character        $error_DATA=toolbox_error_to_string($EMAIL);        toolbox_error("validate_not_empty(" + $error_DATA + ")", "3", "Domain has invalid characters");        $result=false;        break;      }      else      {        // Character is valid        // Do nothing more      } // if (domain.charCodeAt(i)>127)    } // for (i=0; i<domain.length; i++)    // Any errors?    if (!$result)    {      // Yes errors      // Do no more    }    else    {      // No error      // See if "user" is valid      if (user.match(userPat)==null)      {        // user is not valid        $error_DATA=toolbox_error_to_string($EMAIL);        toolbox_error("validate_not_empty(" + $error_DATA + ")", "4", "User is invalid");        $result=false;      }      else      {        // User is valid        /* if the e-mail address is at an IP address (as opposed to a symbolic        host name) make sure the IP address is valid. */        //        var IPArray=domain.match(ipDomainPat);        if (IPArray!=null)        {          // this is an IP address          for (var i=1;i<=4;i++)          {            if (IPArray[i]>255)            {              $error_DATA=toolbox_error_to_string($EMAIL);              toolbox_error("validate_not_empty(" + $error_DATA + ")", "5", "IP address is invalid");              $result=false;              break;            } // if (IPArray[i]>255)          } // for (var i=1;i<=4;i++)          // return true;  // Assumed true now        }        else        {          // Not an IP number          // Domain is symbolic name.  Check if it's valid.          //          var atomPat=new RegExp("^" + atom + "$");          var domArr=domain.split(".");          var len=domArr.length;          for (i=0;i<len;i++)          {            if (domArr[i].search(atomPat)==-1)            {              $error_DATA=toolbox_error_to_string($EMAIL);              toolbox_error("validate_not_empty(" + $error_DATA + ")", "6", "Domain is invalid");              $result=false;              break;            } // if (domArr[i].search(atomPat)==-1)          } // for (i=0;i<len;i++)          //          // Any errors?          if (!$result)          {            // Yes an error            // Do nothing more          }          else          {            // No error yet            /* domain name seems valid, but now make sure that it ends in a            known top-level domain (like com, edu, gov) or a two-letter word,            representing country (uk, nl), and that there's a hostname preceding            the domain or country. */            if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)            {              // TLD failed              $error_DATA=toolbox_error_to_string($EMAIL);              toolbox_error("validate_not_empty(" + $error_DATA + ")", "7", "Top Level Domain is invalid");              $result=false;            }            else            {              // TLD is ok              // Make sure there's a host name preceding the domain.              if (len<2)              {                $error_DATA=toolbox_error_to_string($EMAIL);                toolbox_error("validate_not_empty(" + $error_DATA + ")", "8", "No host above Top Level Domain");                $result=false;              }              else              {                // If we've gotten this far, everything's valid!                // Do nothing more              } // if (len<2)            } // if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)          } // if (!$result)        } // if (IPArray!=null)      } // if (user.match(userPat)==null)    } // if (!$result)  } // if (matchArray==null)  //  return $result;} // function validate_email($EMAIL)function validate_extention($extention){  // Returns true if email is a valid extention ####  //  //  // Parameters:  //  $extention = (string) extention to check  //  //  // Is it all digits  if ($extention.length!=4)  {    $error_extention=toolbox_error_to_string($extention);    toolbox_error("validate_extention(" + $error_extention + ")", "1", "Invalid length");    $result=false;  }  else  {    // Length is good    if (!validate_digits_all($extention))    {      // Not all digits      $error_extention=toolbox_error_to_string($extention);      toolbox_error("validate_extention(" + $error_extention + ")", "2", "Not all digits");      $result=false;    }    else    {      $result=true;    } // if (!validate_digits_all($extention))  } // if ($extention.length!=4)  //  return $result;} // function validate_extention($extention)////function validate_in_selection_quiet($CHECK, $LIST){  // Returns true if check is in list  //  // Parameters  //  $CHECK = (string) item to look for  //  $LIST = (array of string) array to check  //  //  var $a;  //  // Is it empty?  if ($LIST.length==0)  {    // It is empty  (can't be in an empty set!)    $error_CHECK=toolbox_error_to_string($CHECK);    $error_LIST=toolbox_error_to_string($LIST);    toolbox_error("validate_in_selection(" + $error_CHECK + ", " + $error_LIST + ")", "1", "List is empty");    $result=false;  }  else  {    // It is not empty    $found=false;    for ($a=0; $a<$LIST.length; $a++)    {      // Does this one match?      if ($LIST[$a]==$CHECK)      {        // Yes, it matches        $found=true;        break;      }      else      {        // No, it does not match        // Do nothing more      } // if ($LIST[$a]==$CHECK)    } // for ($a=0; $a<=$LIST.length; $a++)    //    // Found?    if (!$found)    {      // No, not found      // It is empty  (can't be in an empty set!)      $error_CHECK=toolbox_error_to_string($CHECK);      $error_LIST=toolbox_error_to_string($LIST);      toolbox_error("validate_in_selection(" + $error_CHECK + ", " + $error_LIST + ")", "2", "Not found in the list");      $result=false;    }    else    {      // Yes, found      $result=true;    } // if (!$found)  } // if ($LIST.length==0)  //  return $result;} // validate_in_selection_quiet($CHECK, $LIST)////function validate_in_selection($CHECK, $LIST){//alert ("validate_in_selection("+$CHECK+","+$LIST+")");  // Returns true if check is in list  //  // Parameters  //  $CHECK = (string) item to look for  //  $LIST = (array of string) array to check  //  //  var $a;  //  // Is it empty?  if ($LIST.length==0)  {    // It is empty  (can't be in an empty set!)    $error_CHECK=toolbox_error_to_string($CHECK);    $error_LIST=toolbox_error_to_string($LIST);    toolbox_error("validate_in_selection(" + $error_CHECK + ", " + $error_LIST + ")", "1", "List is empty");    $result=false;  }  else  {    // It is not empty    $found=false;    for ($a=0; $a<$LIST.length; $a++)    {      // Does this one match?      if ($LIST[$a]==$CHECK)      {        // Yes, it matches        $found=true;        break;      }      else      {        // No, it does not match        // Do nothing more      } // if ($LIST[$a]==$CHECK)    } // for ($a=0; $a<=$LIST.length; $a++)    //    // Found?    if (!$found)    {      // No, not found      // It is empty  (can't be in an empty set!)      $error_CHECK=toolbox_error_to_string($CHECK);      $error_LIST=toolbox_error_to_string($LIST);      toolbox_error("validate_in_selection(" + $error_CHECK + ", " + $error_LIST + ")", "2", "Not found in the list");      $result=false;    }    else    {      // Yes, found      $result=true;    } // if (!$found)  } // if ($LIST.length==0)  //  return $result;} // function validate_in_selection($ID, $LIST)////function validate_integer_range($CHECK, $LOW, $HIGH){//alert ("validate_integer_range("+$CHECK+", "+$LOW+", "+$HIGH+")");  // Returns true if check is in the range low..high inclusive  (integers only)  //  // Parameters:  //  $CHECK = (number) data to test  //  $LOW = (number) low end of range  //  $HIGH = (number) high end of range  //  //  // Is the check all digits?  if (!validate_digits_all($CHECK))  {    // No, it is not all digits    $error_CHECK=toolbox_error_to_string($CHECK);    $error_LOW=toolbox_error_to_string($LOW);    $error_HIGH=toolbox_error_to_string($HIGH);    toolbox_error("validate_integer_range(" + $error_CHECK + ", " + $error_LOW + ", " + $error_HIGH + ")", "1", "CHECK is not a number");    $result=false;  }  else  {    // Yes, it is all digits    // Is the low all digits?    if (!validate_digits_all($LOW))    {      // No, it is not all digits      $error_CHECK=toolbox_error_to_string($CHECK);      $error_LOW=toolbox_error_to_string($LOW);      $error_HIGH=toolbox_error_to_string($HIGH);      toolbox_error("validate_integer_range(" + $error_CHECK + ", " + $error_LOW + ", " + $error_HIGH + ")", "2", "LOW is not a number");      $result=false;    }    else    {      // Yes, it is all digits      // Is the low all digits?      if (!validate_digits_all($HIGH))      {        // No, it is not all digits        $error_CHECK=toolbox_error_to_string($CHECK);        $error_LOW=toolbox_error_to_string($LOW);        $error_HIGH=toolbox_error_to_string($HIGH);        toolbox_error("validate_integer_range("  + $error_CHECK + ", " + $error_LOW + ", " + $error_HIGH + ")", "3", "HIGH is not a number");        $result=false;      }      else      {        // Yes, it is all digits        // Is it in range?        if (($LOW>$CHECK) || ($CHECK>$HIGH))        {          // No, not in range          $error_CHECK=toolbox_error_to_string($CHECK);          $error_LOW=toolbox_error_to_string($LOW);          $error_HIGH=toolbox_error_to_string($HIGH);          toolbox_error("validate_integer_range("  + $error_CHECK + ", " + $error_LOW + ", " + $error_HIGH + ")", "4", "CHECK is out of range");          $result=false;        }        else        {          // It is in range          $result=true;        } // if (($LOW>$CHECK) || ($CHECK>$HIGH))      } // if (!validate_digits_all($HIGH))    } // if (!validate_digits_all($LOW))  } // if (!validate_digits_all($CHECK))  //  return $result;} // function validate_integer_range($CHECK, $LOW, $HIGH)function validate_month($MONTH){//alert ("validate_month("+$MONTH+")");  // Returns true if month is 1..12  //  // Parameters:  //  $MONTH = (string) month to check  //  //  // Is the month valid?  if (($MONTH!="01") &&      ($MONTH!="02") &&      ($MONTH!="03") &&      ($MONTH!="04") &&      ($MONTH!="05") &&      ($MONTH!="06") &&      ($MONTH!="07") &&      ($MONTH!="08") &&      ($MONTH!="09") &&      ($MONTH!="10") &&      ($MONTH!="11") &&      ($MONTH!="12")     )  {    // Not a valid month    $error_MONTH=toolbox_error_to_string($MONTH);    toolbox_error("validate_month(" + $error_MONTH + ")", "1", "Invalid month");    $result=false;  }  else  {    // It is a good month    $result=true;  } // if ([IS MONTH])  //  return $result;} // function validate_month($MONTH)function validate_phone_LONG($PHONE){//alert ("validate_phone_LONG("+$PHONE+")");  // Returns true if phone is ###-###-####  //                          012345678901  //  // Parameters:  //  $PHONE = (string) phone to check  //  //  $area_code=$PHONE.substr(0, 3);  $div1=$PHONE.substr(3, 1);  $prefix=$PHONE.substr(4, 3);  $div2=$PHONE.substr(7, 1);  $line_number=$PHONE.substr(8, 4);//alert ($area_code+"x"+$div1+"/"+$prefix+"/"+$div2+"/"+$line_number);  //  // CHECK AREA CODE  // Is the area code the right length?  if ($area_code.length!=3)  {    // No, not the right length    $error_PHONE=toolbox_error_to_string($PHONE);    toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "1", "Area code has wrong length");    $result=false;  }  else  {    // Length is good    // Is area code all digits?    if (!validate_digits_all($area_code))    {      // Nope, some bad characters in there      $error_PHONE=toolbox_error_to_string($PHONE);      toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "2", "Area code is not all digits");      $result=false;    }    else    {      // Yes, area code is all digits      // Is the first divider right?      if ($div1!="-")      {        // No, the first divider is wrong        $error_PHONE=toolbox_error_to_string($PHONE);        toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "3", "First divider is invalid");        $result=false;      }      else      {        // First divider is good        // Is the prefix the right length?        if ($prefix.length!=3)        {          // No, the length is wrong          $error_PHONE=toolbox_error_to_string($PHONE);          toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "4", "Prefix has wrong length");          $result=false;        }        else        {          // Yes, prefix is right length          // Is prefix all digits?          if (!validate_digits_all($prefix))          {            // No, not all digits            $error_PHONE=toolbox_error_to_string($PHONE);            toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "5", "Prefix is not all digits");            $result=false;          }          else          {            // Yes, all digits            // Is the second divider good?            if ($div2!="-")            {              // No, second divider is bad              $error_PHONE=toolbox_error_to_string($PHONE);              toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "6", "Second divider is invalid");              $result=false;            }            else            {              // Yes, second divider is good              // Is the line number the right length?              if ($line_number.length!=4)              {                // No, not the right length                $error_PHONE=toolbox_error_to_string($PHONE);                toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "7", "Line number is wrong length");                $result=false;              }              else              {                // Yes, line number is right length                // Is the line number all digits?                if (!validate_digits_all($line_number))                {                  // No, not all digits                  $error_PHONE=toolbox_error_to_string($PHONE);                  toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "7", "Line number is not all digits");                  $result=false;                }                else                {                  // Yes, all digits                  // The phone number is good                  $result=true;                } // if (!validate_digits_all($line_number))              } // if ($line_number.length!=4)            } // if ($div2!="-")          } // if (!validate_digits_all($prefix))        } // if ($prefix.length!=3)      } // if ($div1!="-")    } // if (!validate_digits_all($area_code))  } // if ($area_code.length!=3)  //  return $result;} // function validate_phone_LONG($PHONE)function validate_phone_SHORT($PHONE){//alert ("validate_phone_SHORT("+$PHONE+")");  // Returns true if phone is ###-####  //                          01234567  //  // Parameters:  //  $PHONE = (string) phone to check  //  //  $prefix=$PHONE.substr(0, 3);  $div1=$PHONE.substr(3, 1);  $line_number=$PHONE.substr(4, 4);  //  // Is the prefix the right length?  if ($prefix.length!=3)  {    // No, the length is wrong    $error_PHONE=toolbox_error_to_string($PHONE);    toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "1", "Prefix has wrong length");    $result=false;  }  else  {    // Yes, prefix is right length    // Is prefix all digits?    if (!validate_digits_all($prefix))    {      // No, not all digits      $error_PHONE=toolbox_error_to_string($PHONE);      toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "2", "Prefix is not all digits");      $result=false;    }    else    {      // Yes, all digits      // Is the second divider good?      if ($div1!="-")      {        // No, second divider is bad        $error_PHONE=toolbox_error_to_string($PHONE);        toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "3", "Second divider is invalid");        $result=false;      }      else      {        // Yes, second divider is good        // Is the line number the right length?        if ($line_number.length!=4)        {          // No, not the right length          $error_PHONE=toolbox_error_to_string($PHONE);          toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "4", "Line number is wrong length");          $result=false;        }        else        {          // Yes, line number is right length          // Is the line number all digits?          if (!validate_digits_all($line_number))          {            // No, not all digits            $error_PHONE=toolbox_error_to_string($PHONE);            toolbox_error("validate_phone_LONG(" + $error_PHONE + ")", "5", "Line number is not all digits");            $result=false;          }          else          {            // Yes, all digits            // The phone number is good            $result=true;          } // if (!validate_digits_all($line_number))        } // if ($line_number.length!=4)      } // if ($div1!="-")    } // if (!validate_digits_all($prefix))  } // if ($prefix.length!=3)  //  return $result;} // function validate_phone_SHORT($PHONE)function validate_phone($PHONE, $FORMAT, $EMPTY){//alert ("validate_phone("+$PHONE+", "+$FORMAT+", "+$EMPTY+")");  // Returns true if the phone is a valid format  //  // Parameters:  //  $PHONE = (string) phone to check  //  $FORMAT = (string) format to allow from list: BOTH, LONG, SHORT  //  $EMPTY = (boolean) allow empty to validate?  //  //  // Allow empty?  if ($EMPTY)  {    // Yes, allow empty    // Is the phone empty?    if ($PHONE=="")    {      // Yes, the phone is empty      $result=true;    }    else    {      // No, the phone is not empty      $result=validate_phone($PHONE, $FORMAT, false);    } // if ($phone=="")  }  else  {    // No, do not allow empty    // Which format?    switch ($FORMAT)    {      case 'BOTH':        $result=validate_phone_LONG($PHONE) || validate_phone_SHORT($PHONE);        // Did it validate?        if (!$result)        {          // No, did not validate          $error_PHONE=toolbox_error_to_string($PHONE);          $error_FORMAT=toolbox_error_to_string($FORMAT);          $error_EMPTY=toolbox_error_to_string($EMPTY);          toolbox_error("validate_phone(" + $error_PHONE + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "1", "Phone is invalid");          $result=false;        }        else        {          // Yes, it validated fine          // Do nothing more        } // if (!$result)      break;      //      case 'LONG':        $result=validate_phone_LONG($PHONE);        // Did it validate?        if (!$result)        {          // No, did not validate          $error_PHONE=toolbox_error_to_string($PHONE);          $error_FORMAT=toolbox_error_to_string($FORMAT);          $error_EMPTY=toolbox_error_to_string($EMPTY);          toolbox_error("validate_phone(" + $error_PHONE + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "2", "Phone is invalid");          $result=false;        }        else        {          // Yes, it validated fine          // Do nothing more        } // if (!$result)      break;      //      case 'SHORT':        $result=validate_phone_SHORT($PHONE);        // Did it validate?        if (!$result)        {          // No, did not validate          $error_PHONE=toolbox_error_to_string($PHONE);          $error_FORMAT=toolbox_error_to_string($FORMAT);          $error_EMPTY=toolbox_error_to_string($EMPTY);          toolbox_error("validate_phone(" + $error_PHONE + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "3", "Phone is invalid");          $result=false;        }        else        {          // Yes, it validated fine          // Do nothing more        } // if (!$result)      break;      //      default:        // No, did not validate        $error_PHONE=toolbox_error_to_string($PHONE);        $error_FORMAT=toolbox_error_to_string($FORMAT);        $error_EMPTY=toolbox_error_to_string($EMPTY);        toolbox_error("validate_phone(" + $error_PHONE + ", " + $error_FORMAT + ", " + $error_EMPTY + ")", "4", "Phone format is invalid");        $result=false;      //    }; // switch ($FORMAT)  } // if ($EMPTY)  //  return $result;} // function validate_phone($PHONE, $FORMAT, $EMPTY)function validate_not_empty($DATA){//alert ("validate_not_empty("+$DATA+")");  // Returns true if data is not empty  //  // Parameters:  //  $DATA = (string) data to check for empty  //  //  // Is it NOT empty?  if ($DATA=='')  {    // No, not empty    $error_DATA=toolbox_error_to_string($DATA);    toolbox_error("validate_not_empty(" + $error_DATA + ")", "1", "Data is empty");    $result=false;  }  else  {    // Yes, not empty    $result=true;  } // if ($DATA=='')  //  return $result;} // function validate_not_empty($DATA)function validate_selection($VALUE, $LIST){alert("validate_selection("+$VALUE+", "+$LIST+")");  // Returns true if the value is found in the list  //  // Parameters:  //  $VALUE = (string) to be found in list  //  $LIST = (array) list to search  //  //  var $a;  //  $result=false;  // Assume false, prove true  // Does the array have any items?  if ($LIST.length()==0)  {    // No items in the array    $error_VALUE=toolbox_error_to_string($VALUE);    $error_LIST=toolbox_error_to_string($LIST);    toolbox_error("validate_phone(" + $error_VALUE + ", " + $error_LIST + ")", "1", "List is empty");  }  else  {    // Yes the array has items    for ($a=0; $a<$LIST.length(); $a++)    {      // Does the value match this item?      if ($VALUE==$LIST[$a])      {        // Yes, a match is found!        $result=true;        break;      }      else      {        // No not a match        // Do nothing more      } // if ($VALUE==$LIST[$a])    } // for ($a=0; $a<$LIST.length(); $a++)  } // if ($LIST.length()==0)  //  return $result;} // validate_selection($VALUE, $LIST)function validate_ssn($SSN){  // Checks to see if the ssn is a valid ssn ###-##-####  //  // Parameters:  //  $SSN = (string) ssn to check  //  //  var $a;  var $error_SSN;  var $result;  //  $result=true;  $error_SSN="";  // Does it have at least one - in it?  if ($SSN.indexOf("-", 0)==-1)  {    // No -'s in the string    $error_SSN=toolbox_error_to_string($SSN);    toolbox_error("validate_ssn(" + $error_SSN + ")", "1", "SSN does not have proper format");    $result=false;  }  else  {    // Yes, at least one -    // Break it into pieces    $pieces=$SSN.split("-");    // Did we get the correct number of pieces?    if ($pieces.length!=3)    {      // No, not the proper number of pieces      $error_SSN=toolbox_error_to_string($SSN);      toolbox_error("validate_ssn(" + $error_SSN + ")", "2", "SSN does not have proper format");      $result=false;    }    else    {      // Yes, the correct number of pieces      $result=true;      for($a=0; $a<=2; $a++)      {        // Is this section all digits?        if (!validate_digits_all($pieces[$a]))        {          // No, something is not a digit          $error_SSN=toolbox_error_to_string($SSN);          toolbox_error("validate_ssn(" + $error_SSN + ")", "3", "SSN has invalid characters");          $result=false;          break;        }        else        {          // Yes, all digits          // Do nothing more        } // if (!validate_digits_all($pieces[$a]))      } // for($a=0; $a<=2; $a++)      // So far so good?      if ($result==true)      {        // Yes, no errors yet        // Are they the proper lengths?        if (($pieces[0].length!=3) || ($pieces[1].length!=2) || ($pieces[2].length!=4))        {          // No, something is the wrong length          toolbox_error("validate_ssn(" + $error_SSN + ")", "4", "SSN has improper format");          $result=false;        }        else        {          // yes, all the right length        } // if (($pieces[0].length!=3) || ($pieces[1].length!=2) || ($pieces[2].length!=4))      }      else      {        // Nope, an error        // Do nothing more      } // if ($result==true)    } // if ($pieces.length!=3)  } // if ($SSN.indexOf("-", 0)==-1)  //  return $result;} // function validate_ssn($SSN)////function validate_state_quiet($STATE){  // Returns true if state is a valid US postal state abriviation  //  // Parameters:  //  $STATE = (string) state  //  //  // Is state a string?  if (!is_string($STATE))  {    // No, it is not a state    $error_STATE=toolbox_error_to_string($STATE);    toolbox_error("validate_not_empty(" + $error_STATE + ")", "1", "State is not a string");    $result=false;  }  else  {    // Is it the right length?    if ($STATE.length!=2)    {      // No, wrong length      $error_STATE=toolbox_error_to_string($STATE);      toolbox_error("validate_not_empty(" + $error_STATE + ")", "2", "State is wrong length");      $result=false;    }    else    {      // It is the right length      $states=define_states();      $result=validate_in_selection_quiet($STATE, $states);      // Did it validate?      if (!$result)      {        // No, did not validate        $error_STATE=toolbox_error_to_string($STATE);        toolbox_error("validate_not_empty(" + $error_STATE + ")", "3", "State is invalid");        $result=false;      }      else      {        // Yes, it validated        $result=true;      } // if (!$result)    } // if ($STATE.length!=2)  } // if (!is_string($STATE))  //  return $result;} // function validate_state($STATE)////////function validate_state($STATE){//alert ("validate_state("+$STATE+")");  // Returns true if state is a valid US postal state abriviation  //  // Parameters:  //  $STATE = (string) state  //  //  // Is state a string?  if (!is_string($STATE))  {    // No, it is not a state    $error_STATE=toolbox_error_to_string($STATE);    toolbox_error("validate_not_empty(" + $error_STATE + ")", "1", "State is not a string");    $result=false;  }  else  {    // Is it the right length?    if ($STATE.length!=2)    {      // No, wrong length      $error_STATE=toolbox_error_to_string($STATE);      toolbox_error("validate_not_empty(" + $error_STATE + ")", "2", "State is wrong length");      $result=false;    }    else    {      // It is the right length      $states=define_states();      $result=validate_in_selection($STATE, $states);      // Did it validate?      if (!$result)      {        // No, did not validate        $error_STATE=toolbox_error_to_string($STATE);        toolbox_error("validate_not_empty(" + $error_STATE + ")", "3", "State is invalid");        $result=false;      }      else      {        // Yes, it validated        $result=true;      } // if (!$result)    } // if ($STATE.length!=2)  } // if (!is_string($STATE))  //  return $result;} // function validate_state($STATE)////function validate_year($YEAR){//alert ("validate_year("+$YEAR+")");  // Checks to see if the year is in the vaild range as defined by $toolbox_year_low and $toolbox_year_high  //  // Parameters:  //  $YEAR = (string) as year  //  // Is the year in range?  if (!validate_integer_range($YEAR, $toolbox_year_low, $toolbox_year_high))  {    // Out of range    $error_YEAR=toolbox_error_to_string($YEAR);    toolbox_error("validate_year(" + $error_YEAR + ")", "1", "Year out of range");    $result=false;  }  else  {    // Good    $result=true;  } // if (!validate_integer_range($YEAR, $toolbox_year_low, $toolbox_year_high))  //  return $result;} // function validate_year($YEAR)function validate_zip($zip){//alert ("validate_zip("+$zip+")");  // Checks to see if the data is a zip in either ##### or #####-#### formats  $result=(validate_zip_short($zip) || validate_zip_long($zip));  // Is it a zip  if ($result==true)  {    // Yes, a zip    // Do nothing else  }  else  {    // Nope, it's bad!    $error_zip=toolbox_error_to_string($zip);    toolbox_error("validate_zip(" + $error_zip + ")", "1", "Not a valid zip");    $result=false;  } // if ($result==true)  //  return $result;} // function validate_zip($zip)function validate_zip_short($zip){//alert ("validate_zip_short("+$zip+")");  // Returns true if the $zip is 5 digits, false otherwise  //  // Is it the right length?  if ($zip.length==5)  {    // Yes, right size    // Is it all digits?    if (validate_digits_all($zip)==true)    {      // Yes, all digits      $result=true;    }    else    {      // Not all digits      $error_zip=toolbox_error_to_string($zip);      toolbox_error("validate_zip_short(" + $error_zip + ")", "1", "Invalid characters");      $result=false;    } // if (validate_digits_all($zip)==true)  }  else  {    // No, wrong length    $error_zip=toolbox_error_to_string($zip);    toolbox_error("validate_zip_short(" + $error_zip + ")", "2", "Zip wrong size");    $result=false;  }  //  return $result;} // function validate_zip_short($zip)function validate_zip_long($zip){//alert ("validate_zip_long("+$zip+")");  // Returns true if the input is format #####-####, false otherwise  //  // Is it the right length?  if ($zip.length!=10)  {    // Not the right length    $error_zip=toolbox_error_to_string($zip);    toolbox_error("validate_zip_long(" + $error_zip + ")", "1", "Zip wrong size");    $result=false;  }  else  {    // Yes, the right length    $zip5=$zip.substring(0,5);    $zip_dash=$zip.substring(5,6);    $zip4=$zip.substring(6,10);    // Is the dash actually a dash?    if ($zip_dash!="-")    {      // No, not a dash      $error_zip=toolbox_error_to_string($zip);      toolbox_error("validate_zip_long(" + $error_zip + ")", "2", "Invalid divider");      $result=false;    }    else    {      // Dash is a dash      // Is the zip5 all digits?      if (validate_digits_all($zip5))      {        // Yes, all digits        // Is the zip4 all digits?        if (validate_digits_all($zip4))        {          // Yes, all digits          $result=true;        }        else        {          $error_zip=toolbox_error_to_string($zip);          toolbox_error("validate_zip_long(" + $error_zip + ")", "3", "Invalid characters");          $result=false;        } // if (validate_digits_all($zip4))      }      else      {        $error_zip=toolbox_error_to_string($zip);        toolbox_error("validate_zip_long(" + $error_zip + ")", "4", "Invalid characters");        $result=false;      } // if (validate_digits_all($zip5))    } // if ($zip_dash!="-")  } // if ($zip.length!=10)  //  return $result;} // function validate_zip_long($zip)function calendar($form_name, $field_name){  // function to load the calendar window.  //  // You must have a copy of CFDateSelectPopupWindow_ymd.cfm in the local directory or javascript will throw permissions errors  //  window.open("CFDateSelectPopupWindow_ymd.cfm?FormName=" + $form_name + "&FieldName=" + $field_name, "CalendarWindow", "width=450,height=280");} // function calendar($form_name, $field_name)//function trim($value){  // Robert Lance  // 2010-03-09  //  // return $value trimmed of beginning and trailing whitespace  //  //////////////  // "\0" - NULL  //"\t" - tab  //"\n" - new line  //"\x0B" - vertical tab  //"\r" - carriage return  //" " - ordinary white space;  // Characters considered whitespace  $kill_string="\0"+"\t"+"\n"+"\x0B"+"\r"+" " ;  //  $original_length=$value.length;  // first char cleaning of anything in $kill_string  $counter=0;  while ($value.length != 0 && $kill_string.indexOf($value.charAt(0)) != -1 )  {    // Remove the first character    $value=$value.substr(1);    //     $counter++;    if ($counter > $original_length)    {      break; // this while loop    }  }  // last char cleaning of anything in $kill_string  $counter=0;  while ($value.length != 0 && $kill_string.indexOf($value.charAt($value.length-1)) != -1 )  {    // Remove the last character    $value=$value.substr(0,$value.length-1);    //     $counter++;    if ($counter > $original_length)    {      break; // this while loop    }  }  //  return $value;  //} // trim($value)