JsInclude.js
上传用户:sami52198
上传日期:2010-02-11
资源大小:5174k
文件大小:70k
源码类别:

电子政务应用

开发平台:

MultiPlatform

  1. // FormChek.js
  2. //
  3. // SUMMARY
  4. //
  5. // This is a set of JavaScript functions for validating input on 
  6. // an HTML form.  Functions are provided to validate:
  7. //
  8. //      - U.S. and international phone/fax numbers
  9. //      - U.S. ZIP codes (5 or 9 digit postal codes)
  10. //      - U.S. Postal Codes (2 letter abbreviations for names of states)
  11. //      - U.S. Social Security Numbers (abbreviated as SSNs)
  12. //      - email addresses
  13. // - dates (entry of year, month, and day and validity of combined date)
  14. // - credit card numbers
  15. //
  16. // Supporting utility functions validate that:
  17. //
  18. //      - characters are Letter, Digit, or LetterOrDigit
  19. //      - strings are a Signed, Positive, Negative, Nonpositive, or
  20. //        Nonnegative integer
  21. //      - strings are a Float or a SignedFloat
  22. //      - strings are Alphabetic, Alphanumeric, or Whitespace
  23. //      - strings contain an integer within a specified range
  24. //
  25. // Functions are also provided to interactively check the
  26. // above kinds of data and prompt the user if they have
  27. // been entered incorrectly.
  28. //
  29. // Other utility functions are provided to:
  30. //
  31. //  - remove from a string characters which are/are not 
  32. //   in a "bag" of selected characters
  33. //  - reformat a string, adding delimiter characters
  34. // - strip whitespace/leading whitespace from a string
  35. //      - reformat U.S. phone numbers, ZIP codes, and Social
  36. //        Security numbers
  37. //
  38. //
  39. // Many of the below functions take an optional parameter eok (for "emptyOK")
  40. // which determines whether the empty string will return true or false.
  41. // Default behavior is controlled by global variable defaultEmptyOK.
  42. //
  43. // BASIC DATA VALIDATION FUNCTIONS:
  44. //
  45. // isWhitespace (s)                    Check whether string s is empty or whitespace.
  46. // isLetter (c)                        Check whether character c is an English letter 
  47. // isDigit (c)                         Check whether character c is a digit 
  48. // isLetterOrDigit (c)                 Check whether character c is a letter or digit.
  49. // isInteger (s [,eok])                True if all characters in string s are numbers.
  50. // isSignedInteger (s [,eok])          True if all characters in string s are numbers; leading + or - allowed.
  51. // isPositiveInteger (s [,eok])        True if string s is an integer > 0.
  52. // isNonnegativeInteger (s [,eok])     True if string s is an integer >= 0.
  53. // isNegativeInteger (s [,eok])        True if s is an integer < 0.
  54. // isNonpositiveInteger (s [,eok])     True if s is an integer <= 0.
  55. // isFloat (s [,eok])                  True if string s is an unsigned floating point (real) number. (Integers also OK.)
  56. // isSignedFloat (s [,eok])            True if string s is a floating point number; leading + or - allowed. (Integers also OK.)
  57. // isAlphabetic (s [,eok])             True if string s is English letters 
  58. // isAlphanumeric (s [,eok])           True if string s is English letters and numbers only.
  59. // 
  60. // isSSN (s [,eok])                    True if string s is a valid U.S. Social Security Number.
  61. // isUSPhoneNumber (s [,eok])          True if string s is a valid U.S. Phone Number. 
  62. // isInternationalPhoneNumber (s [,eok]) True if string s is a valid international phone number.
  63. // isZIPCode (s [,eok])                True if string s is a valid U.S. ZIP code.
  64. // isStateCode (s [,eok])              True if string s is a valid U.S. Postal Code
  65. // isEmail (s [,eok])                  True if string s is a valid email address.
  66. // isYear (s [,eok])                   True if string s is a valid Year number.
  67. // isIntegerInRange (s, a, b [,eok])   True if string s is an integer between a and b, inclusive.
  68. // isMonth (s [,eok])                  True if string s is a valid month between 1 and 12.
  69. // isDay (s [,eok])                    True if string s is a valid day between 1 and 31.
  70. // daysInFebruary (year)               Returns number of days in February of that year.
  71. // isDate (year, month, day)           True if string arguments form a valid date.
  72. // FUNCTIONS TO REFORMAT DATA:
  73. //
  74. // stripCharsInBag (s, bag)            Removes all characters in string bag from string s.
  75. // stripCharsNotInBag (s, bag)         Removes all characters NOT in string bag from string s.
  76. // stripWhitespace (s)                 Removes all whitespace characters from s.
  77. // stripInitialWhitespace (s)          Removes initial (leading) whitespace characters from s.
  78. // reformat (TARGETSTRING, STRING,     Function for inserting formatting characters or
  79. //   INTEGER, STRING, INTEGER ... )       delimiters into TARGETSTRING.                                       
  80. // reformatZIPCode (ZIPString)         If 9 digits, inserts separator hyphen.
  81. // reformatSSN (SSN)                   Reformats as 123-45-6789.
  82. // reformatUSPhone (USPhone)           Reformats as (123) 456-789.
  83. // FUNCTIONS TO PROMPT USER:
  84. //
  85. // prompt (s)                          Display prompt string s in status bar.
  86. // promptEntry (s)                     Display data entry prompt string s in status bar.
  87. // warnEmpty (theField, s)             Notify user that required field theField is empty.
  88. // warnInvalid (theField, s)           Notify user that contents of field theField are invalid.
  89. // FUNCTIONS TO INTERACTIVELY CHECK FIELD CONTENTS:
  90. //
  91. // checkString (theField, s [,eok])    Check that theField.value is not empty or all whitespace.
  92. // checkStateCode (theField)           Check that theField.value is a valid U.S. state code.
  93. // checkZIPCode (theField [,eok])      Check that theField.value is a valid ZIP code.
  94. // checkUSPhone (theField [,eok])      Check that theField.value is a valid US Phone.
  95. // checkInternationalPhone (theField [,eok])  Check that theField.value is a valid International Phone.
  96. // checkEmail (theField [,eok])        Check that theField.value is a valid Email.
  97. // checkSSN (theField [,eok])          Check that theField.value is a valid SSN.
  98. // checkYear (theField [,eok])         Check that theField.value is a valid Year.
  99. // checkMonth (theField [,eok])        Check that theField.value is a valid Month.
  100. // checkDay (theField [,eok])          Check that theField.value is a valid Day.
  101. // checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
  102. //                                     Check that field values form a valid date.
  103. // getRadioButtonValue (radio)         Get checked value from radio button.
  104. // checkCreditCard (radio, theField)   Validate credit card info.
  105. // CREDIT CARD DATA VALIDATION FUNCTIONS
  106. // 
  107. // isCreditCard (st)              True if credit card number passes the Luhn Mod-10 test.
  108. // isVisa (cc)                    True if string cc is a valid VISA number.
  109. // isMasterCard (cc)              True if string cc is a valid MasterCard number.
  110. // isAmericanExpress (cc)         True if string cc is a valid American Express number.
  111. // isDinersClub (cc)              True if string cc is a valid Diner's Club number.
  112. // isCarteBlanche (cc)            True if string cc is a valid Carte Blanche number.
  113. // isDiscover (cc)                True if string cc is a valid Discover card number.
  114. // isEnRoute (cc)                 True if string cc is a valid enRoute card number.
  115. // isJCB (cc)                     True if string cc is a valid JCB card number.
  116. // isAnyCard (cc)                 True if string cc is a valid card number for any of the accepted types.
  117. // isCardMatch (Type, Number)     True if Number is valid for credic card of type Type.
  118. //
  119. // Other stub functions are retained for backward compatibility with LivePayment code.
  120. // See comments below for details.
  121. //
  122. // Performance hint: when you deploy this file on your website, strip out the
  123. // comment lines from the source code as well as any of the functions which
  124. // you don't need.  This will give you a smaller .js file and achieve faster
  125. // downloads.
  126. //
  127. // 18 Feb 97 created Eric Krock
  128. //
  129. // (c) 1997 Netscape Communications Corporation
  130. // VARIABLE DECLARATIONS
  131. var digits = "0123456789";
  132. var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
  133. var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  134. // whitespace characters
  135. var whitespace = " tnr";
  136. // decimal point character differs by language and culture
  137. var decimalPointDelimiter = "."
  138. // non-digit characters which are allowed in phone numbers
  139. var phoneNumberDelimiters = "()- ";
  140. // characters which are allowed in US phone numbers
  141. var validUSPhoneChars = digits + phoneNumberDelimiters;
  142. // characters which are allowed in international phone numbers
  143. // (a leading + is OK)
  144. var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
  145. // non-digit characters which are allowed in 
  146. // Social Security Numbers
  147. var SSNDelimiters = "- ";
  148. // characters which are allowed in Social Security Numbers
  149. var validSSNChars = digits + SSNDelimiters;
  150. // U.S. Social Security Numbers have 9 digits.
  151. // They are formatted as 123-45-6789.
  152. var digitsInSocialSecurityNumber = 9;
  153. // U.S. phone numbers have 10 digits.
  154. // They are formatted as 123 456 7890 or (123) 456-7890.
  155. var digitsInUSPhoneNumber = 10;
  156. // non-digit characters which are allowed in ZIP Codes
  157. var ZIPCodeDelimiters = "-";
  158. // our preferred delimiter for reformatting ZIP Codes
  159. var ZIPCodeDelimeter = "-"
  160. // characters which are allowed in Social Security Numbers
  161. var validZIPCodeChars = digits + ZIPCodeDelimiters
  162. // U.S. ZIP codes have 5 or 9 digits.
  163. // They are formatted as 12345 or 12345-6789.
  164. var digitsInZIPCode1 = 5
  165. var digitsInZIPCode2 = 9
  166. // non-digit characters which are allowed in credit card numbers
  167. var creditCardDelimiters = " "
  168. // CONSTANT STRING DECLARATIONS
  169. // (grouped for ease of translation and localization)
  170. // m is an abbreviation for "missing"
  171. var mPrefix = "You did not enter a value into the "
  172. var mSuffix = " field. This is a required field. Please enter it now."
  173. // s is an abbreviation for "string"
  174. var sUSLastName = "Last Name"
  175. var sUSFirstName = "First Name"
  176. var sWorldLastName = "Family Name"
  177. var sWorldFirstName = "Given Name"
  178. var sTitle = "Title"
  179. var sCompanyName = "Company Name"
  180. var sUSAddress = "Street Address"
  181. var sWorldAddress = "Address"
  182. var sCity = "City"
  183. var sStateCode = "State Code"
  184. var sWorldState = "State, Province, or Prefecture"
  185. var sCountry = "Country"
  186. var sZIPCode = "ZIP Code"
  187. var sWorldPostalCode = "Postal Code"
  188. var sPhone = "Phone Number"
  189. var sFax = "Fax Number"
  190. var sDateOfBirth = "Date of Birth"
  191. var sExpirationDate = "Expiration Date"
  192. var sEmail = "Email"
  193. var sSSN = "Social Security Number"
  194. var sCreditCardNumber = "Credit Card Number"
  195. var sOtherInfo = "Other Information"
  196. // i is an abbreviation for "invalid"
  197. var iStateCode = "This field must be a valid two character U.S. state abbreviation (like CA for California). Please reenter it now."
  198. var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now."
  199. var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."
  200. var iWorldPhone = "This field must be a valid international phone number. Please reenter it now."
  201. var iSSN = "This field must be a 9 digit U.S. social security number (like 123 45 6789). Please reenter it now."
  202. var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
  203. var iCreditCardPrefix = "This is not a valid "
  204. var iCreditCardSuffix = " credit card number. (Click the link on this form to see a list of sample numbers.) Please reenter it now."
  205. var iDay = "This field must be a day number between 1 and 31.  Please reenter it now."
  206. var iMonth = "This field must be a month number between 1 and 12.  Please reenter it now."
  207. var iYear = "This field must be a 2 or 4 digit year number.  Please reenter it now."
  208. var iDatePrefix = "The Day, Month, and Year for "
  209. var iDateSuffix = " do not form a valid date.  Please reenter them now."
  210. // p is an abbreviation for "prompt"
  211. var pEntryPrompt = "Please enter a "
  212. var pStateCode = "2 character code (like CA)."
  213. var pZIPCode = "5 or 9 digit U.S. ZIP Code (like 94043)."
  214. var pUSPhone = "10 digit U.S. phone number (like 415 555 1212)."
  215. var pWorldPhone = "international phone number."
  216. var pSSN = "9 digit U.S. social security number (like 123 45 6789)."
  217. var pEmail = "valid email address (like foo@bar.com)."
  218. var pCreditCard = "valid credit card number."
  219. var pDay = "day number between 1 and 31."
  220. var pMonth = "month number between 1 and 12."
  221. var pYear = "2 or 4 digit year number."
  222. // Global variable defaultEmptyOK defines default return value 
  223. // for many functions when they are passed the empty string. 
  224. // By default, they will return defaultEmptyOK.
  225. //
  226. // defaultEmptyOK is false, which means that by default, 
  227. // these functions will do "strict" validation.  Function
  228. // isInteger, for example, will only return true if it is
  229. // passed a string containing an integer; if it is passed
  230. // the empty string, it will return false.
  231. //
  232. // You can change this default behavior globally (for all 
  233. // functions which use defaultEmptyOK) by changing the value
  234. // of defaultEmptyOK.
  235. //
  236. // Most of these functions have an optional argument emptyOK
  237. // which allows you to override the default behavior for 
  238. // the duration of a function call.
  239. //
  240. // This functionality is useful because it is possible to
  241. // say "if the user puts anything in this field, it must
  242. // be an integer (or a phone number, or a string, etc.), 
  243. // but it's OK to leave the field empty too."
  244. // This is the case for fields which are optional but which
  245. // must have a certain kind of content if filled in.
  246. var defaultEmptyOK = false
  247. // Attempting to make this library run on Navigator 2.0,
  248. // so I'm supplying this array creation routine as per
  249. // JavaScript 1.0 documentation.  If you're using 
  250. // Navigator 3.0 or later, you don't need to do this;
  251. // you can use the Array constructor instead.
  252. function makeArray(n) {
  253. //*** BUG: If I put this line in, I get two error messages:
  254. //(1) Window.length can't be set by assignment
  255. //(2) daysInMonth has no property indexed by 4
  256. //If I leave it out, the code works fine.
  257. //   this.length = n;
  258.    for (var i = 1; i <= n; i++) {
  259.       this[i] = 0
  260.    } 
  261.    return this
  262. }
  263. var daysInMonth = makeArray(12);
  264. daysInMonth[1] = 31;
  265. daysInMonth[2] = 29;   // must programmatically check this
  266. daysInMonth[3] = 31;
  267. daysInMonth[4] = 30;
  268. daysInMonth[5] = 31;
  269. daysInMonth[6] = 30;
  270. daysInMonth[7] = 31;
  271. daysInMonth[8] = 31;
  272. daysInMonth[9] = 30;
  273. daysInMonth[10] = 31;
  274. daysInMonth[11] = 30;
  275. daysInMonth[12] = 31;
  276. // Valid U.S. Postal Codes for states, territories, armed forces, etc.
  277. // See http://www.usps.gov/ncsc/lookups/abbr_state.txt.
  278. var USStateCodeDelimiter = "|";
  279. var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP"
  280. // Check whether string s is empty.
  281. function isEmpty(s)
  282. {   return ((s == null) || (s.length == 0))
  283. }
  284. // Returns true if string s is empty or 
  285. // whitespace characters only.
  286. function isWhitespace (s)
  287. {   var i;
  288.     // Is s empty?
  289.     if (isEmpty(s)) return true;
  290.     // Search through string's characters one by one
  291.     // until we find a non-whitespace character.
  292.     // When we do, return false; if we don't, return true.
  293.     for (i = 0; i < s.length; i++)
  294.     {   
  295.         // Check that current character isn't whitespace.
  296.         var c = s.charAt(i);
  297.         if (whitespace.indexOf(c) == -1) return false;
  298.     }
  299.     // All characters are whitespace.
  300.     return true;
  301. }
  302. // Removes all characters which appear in string bag from string s.
  303. function stripCharsInBag (s, bag)
  304. {   var i;
  305.     var returnString = "";
  306.     // Search through string's characters one by one.
  307.     // If character is not in bag, append to returnString.
  308.     for (i = 0; i < s.length; i++)
  309.     {   
  310.         // Check that current character isn't whitespace.
  311.         var c = s.charAt(i);
  312.         if (bag.indexOf(c) == -1) returnString += c;
  313.     }
  314.     return returnString;
  315. }
  316. // Removes all characters which do NOT appear in string bag 
  317. // from string s.
  318. function stripCharsNotInBag (s, bag)
  319. {   var i;
  320.     var returnString = "";
  321.     // Search through string's characters one by one.
  322.     // If character is in bag, append to returnString.
  323.     for (i = 0; i < s.length; i++)
  324.     {   
  325.         // Check that current character isn't whitespace.
  326.         var c = s.charAt(i);
  327.         if (bag.indexOf(c) != -1) returnString += c;
  328.     }
  329.     return returnString;
  330. }
  331. // Removes all whitespace characters from s.
  332. // Global variable whitespace (see above)
  333. // defines which characters are considered whitespace.
  334. function stripWhitespace (s)
  335. {   return stripCharsInBag (s, whitespace)
  336. }
  337. // WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
  338. //
  339. // The below function *should* be unnecessary.  In general,
  340. // avoid using it.  Use the standard method indexOf instead.
  341. //
  342. // However, because of an apparent bug in indexOf on 
  343. // Navigator 2.0.2, the below loop does not work as the
  344. // body of stripInitialWhitespace:
  345. //
  346. // while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
  347. //   i++;
  348. //
  349. // ... so we provide this workaround function charInString
  350. // instead.
  351. //
  352. // charInString (CHARACTER c, STRING s)
  353. //
  354. // Returns true if single character c (actually a string)
  355. // is contained within string s.
  356. function charInString (c, s)
  357. {   for (i = 0; i < s.length; i++)
  358.     {   if (s.charAt(i) == c) return true;
  359.     }
  360.     return false
  361. }
  362. // Removes initial (leading) whitespace characters from s.
  363. // Global variable whitespace (see above)
  364. // defines which characters are considered whitespace.
  365. function stripInitialWhitespace (s)
  366. {   var i = 0;
  367.     while ((i < s.length) && charInString (s.charAt(i), whitespace))
  368.        i++;
  369.     
  370.     return s.substring (i, s.length);
  371. }
  372. // Returns true if character c is an English letter 
  373. // (A .. Z, a..z).
  374. //
  375. // NOTE: Need i18n version to support European characters.
  376. // This could be tricky due to different character
  377. // sets and orderings for various languages and platforms.
  378. function isLetter (c)
  379. {   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
  380. }
  381. // Returns true if character c is a digit 
  382. // (0 .. 9).
  383. function isDigit (c)
  384. {   return ((c >= "0") && (c <= "9"))
  385. }
  386. // Returns true if character c is a letter or digit.
  387. function isLetterOrDigit (c)
  388. {   return (isLetter(c) || isDigit(c))
  389. }
  390. // isInteger (STRING s [, BOOLEAN emptyOK])
  391. // 
  392. // Returns true if all characters in string s are numbers.
  393. //
  394. // Accepts non-signed integers only. Does not accept floating 
  395. // point, exponential notation, etc.
  396. //
  397. // We don't use parseInt because that would accept a string
  398. // with trailing non-numeric characters.
  399. //
  400. // By default, returns defaultEmptyOK if s is empty.
  401. // There is an optional second argument called emptyOK.
  402. // emptyOK is used to override for a single function call
  403. //      the default behavior which is specified globally by
  404. //      defaultEmptyOK.
  405. // If emptyOK is false (or any value other than true), 
  406. //      the function will return false if s is empty.
  407. // If emptyOK is true, the function will return true if s is empty.
  408. //
  409. // EXAMPLE FUNCTION CALL:     RESULT:
  410. // isInteger ("5")            true 
  411. // isInteger ("")             defaultEmptyOK
  412. // isInteger ("-5")           false
  413. // isInteger ("", true)       true
  414. // isInteger ("", false)      false
  415. // isInteger ("5", false)     true
  416. function isInteger (s)
  417. {   var i;
  418.     if (isEmpty(s)) 
  419.        if (isInteger.arguments.length == 1) return defaultEmptyOK;
  420.        else return (isInteger.arguments[1] == true);
  421.     // Search through string's characters one by one
  422.     // until we find a non-numeric character.
  423.     // When we do, return false; if we don't, return true.
  424.     for (i = 0; i < s.length; i++)
  425.     {   
  426.         // Check that current character is number.
  427.         var c = s.charAt(i);
  428.         if (!isDigit(c)) return false;
  429.     }
  430.     // All characters are numbers.
  431.     return true;
  432. }
  433. // isSignedInteger (STRING s [, BOOLEAN emptyOK])
  434. // 
  435. // Returns true if all characters are numbers; 
  436. // first character is allowed to be + or - as well.
  437. //
  438. // Does not accept floating point, exponential notation, etc.
  439. //
  440. // We don't use parseInt because that would accept a string
  441. // with trailing non-numeric characters.
  442. //
  443. // For explanation of optional argument emptyOK,
  444. // see comments of function isInteger.
  445. //
  446. // EXAMPLE FUNCTION CALL:          RESULT:
  447. // isSignedInteger ("5")           true 
  448. // isSignedInteger ("")            defaultEmptyOK
  449. // isSignedInteger ("-5")          true
  450. // isSignedInteger ("+5")          true
  451. // isSignedInteger ("", false)     false
  452. // isSignedInteger ("", true)      true
  453. function isSignedInteger (s)
  454. {   if (isEmpty(s)) 
  455.        if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
  456.        else return (isSignedInteger.arguments[1] == true);
  457.     else {
  458.         var startPos = 0;
  459.         var secondArg = defaultEmptyOK;
  460.         if (isSignedInteger.arguments.length > 1)
  461.             secondArg = isSignedInteger.arguments[1];
  462.         // skip leading + or -
  463.         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
  464.            startPos = 1;    
  465.         return (isInteger(s.substring(startPos, s.length), secondArg))
  466.     }
  467. }
  468. // isPositiveInteger (STRING s [, BOOLEAN emptyOK])
  469. // 
  470. // Returns true if string s is an integer > 0.
  471. //
  472. // For explanation of optional argument emptyOK,
  473. // see comments of function isInteger.
  474. function isPositiveInteger (s)
  475. {   var secondArg = defaultEmptyOK;
  476.     if (isPositiveInteger.arguments.length > 1)
  477.         secondArg = isPositiveInteger.arguments[1];
  478.     // The next line is a bit byzantine.  What it means is:
  479.     // a) s must be a signed integer, AND
  480.     // b) one of the following must be true:
  481.     //    i)  s is empty and we are supposed to return true for
  482.     //        empty strings
  483.     //    ii) this is a positive, not negative, number
  484.     return (isSignedInteger(s, secondArg)
  485.          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
  486. }
  487. // isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
  488. // 
  489. // Returns true if string s is an integer >= 0.
  490. //
  491. // For explanation of optional argument emptyOK,
  492. // see comments of function isInteger.
  493. function isNonnegativeInteger (s)
  494. {   var secondArg = defaultEmptyOK;
  495.     if (isNonnegativeInteger.arguments.length > 1)
  496.         secondArg = isNonnegativeInteger.arguments[1];
  497.     // The next line is a bit byzantine.  What it means is:
  498.     // a) s must be a signed integer, AND
  499.     // b) one of the following must be true:
  500.     //    i)  s is empty and we are supposed to return true for
  501.     //        empty strings
  502.     //    ii) this is a number >= 0
  503.     return (isSignedInteger(s, secondArg)
  504.          && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
  505. }
  506. // isNegativeInteger (STRING s [, BOOLEAN emptyOK])
  507. // 
  508. // Returns true if string s is an integer < 0.
  509. //
  510. // For explanation of optional argument emptyOK,
  511. // see comments of function isInteger.
  512. function isNegativeInteger (s)
  513. {   var secondArg = defaultEmptyOK;
  514.     if (isNegativeInteger.arguments.length > 1)
  515.         secondArg = isNegativeInteger.arguments[1];
  516.     // The next line is a bit byzantine.  What it means is:
  517.     // a) s must be a signed integer, AND
  518.     // b) one of the following must be true:
  519.     //    i)  s is empty and we are supposed to return true for
  520.     //        empty strings
  521.     //    ii) this is a negative, not positive, number
  522.     return (isSignedInteger(s, secondArg)
  523.          && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );
  524. }
  525. // isNonpositiveInteger (STRING s [, BOOLEAN emptyOK])
  526. // 
  527. // Returns true if string s is an integer <= 0.
  528. //
  529. // For explanation of optional argument emptyOK,
  530. // see comments of function isInteger.
  531. function isNonpositiveInteger (s)
  532. {   var secondArg = defaultEmptyOK;
  533.     if (isNonpositiveInteger.arguments.length > 1)
  534.         secondArg = isNonpositiveInteger.arguments[1];
  535.     // The next line is a bit byzantine.  What it means is:
  536.     // a) s must be a signed integer, AND
  537.     // b) one of the following must be true:
  538.     //    i)  s is empty and we are supposed to return true for
  539.     //        empty strings
  540.     //    ii) this is a number <= 0
  541.     return (isSignedInteger(s, secondArg)
  542.          && ( (isEmpty(s) && secondArg)  || (parseInt (s) <= 0) ) );
  543. }
  544. // isFloat (STRING s [, BOOLEAN emptyOK])
  545. // 
  546. // True if string s is an unsigned floating point (real) number. 
  547. //
  548. // Also returns true for unsigned integers. If you wish
  549. // to distinguish between integers and floating point numbers,
  550. // first call isInteger, then call isFloat.
  551. //
  552. // Does not accept exponential notation.
  553. //
  554. // For explanation of optional argument emptyOK,
  555. // see comments of function isInteger.
  556. function isFloat (s)
  557. {   var i;
  558.     var seenDecimalPoint = false;
  559.     //if (isEmpty(s)) return "1"; 
  560.     if (s == decimalPointDelimiter) return "1";
  561.     // Search through string's characters one by one
  562.     // until we find a non-numeric character.
  563.     // When we do, return false; if we don't, return true.
  564.     for (i = 0; i < s.length; i++)
  565.     {   
  566.         // Check that current character is number.
  567.         var c = s.charAt(i);
  568.         if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
  569.         else if (!isDigit(c)) return "1";
  570.     }
  571.     // All characters are numbers.
  572.     return "0";
  573. }
  574. // isSignedFloat (STRING s [, BOOLEAN emptyOK])
  575. // 
  576. // True if string s is a signed or unsigned floating point 
  577. // (real) number. First character is allowed to be + or -.
  578. //
  579. // Also returns true for unsigned integers. If you wish
  580. // to distinguish between integers and floating point numbers,
  581. // first call isSignedInteger, then call isSignedFloat.
  582. //
  583. // Does not accept exponential notation.
  584. //
  585. // For explanation of optional argument emptyOK,
  586. // see comments of function isInteger.
  587. function isSignedFloat (s)
  588. {   if (isEmpty(s)) 
  589.        if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
  590.        else return (isSignedFloat.arguments[1] == true);
  591.     else {
  592.         var startPos = 0;
  593.         var secondArg = defaultEmptyOK;
  594.         if (isSignedFloat.arguments.length > 1)
  595.             secondArg = isSignedFloat.arguments[1];
  596.         // skip leading + or -
  597.         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
  598.            startPos = 1;    
  599.         return (isFloat(s.substring(startPos, s.length), secondArg))
  600.     }
  601. }
  602. // isAlphabetic (STRING s [, BOOLEAN emptyOK])
  603. // 
  604. // Returns true if string s is English letters 
  605. // (A .. Z, a..z) only.
  606. //
  607. // For explanation of optional argument emptyOK,
  608. // see comments of function isInteger.
  609. //
  610. // NOTE: Need i18n version to support European characters.
  611. // This could be tricky due to different character
  612. // sets and orderings for various languages and platforms.
  613. function isAlphabetic (s)
  614. {   var i;
  615.     if (isEmpty(s)) 
  616.        if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
  617.        else return (isAlphabetic.arguments[1] == true);
  618.     // Search through string's characters one by one
  619.     // until we find a non-alphabetic character.
  620.     // When we do, return false; if we don't, return true.
  621.     for (i = 0; i < s.length; i++)
  622.     {   
  623.         // Check that current character is letter.
  624.         var c = s.charAt(i);
  625.         if (!isLetter(c))
  626.         return false;
  627.     }
  628.     // All characters are letters.
  629.     return true;
  630. }
  631. // isAlphanumeric (STRING s [, BOOLEAN emptyOK])
  632. // 
  633. // Returns true if string s is English letters 
  634. // (A .. Z, a..z) and numbers only.
  635. //
  636. // For explanation of optional argument emptyOK,
  637. // see comments of function isInteger.
  638. //
  639. // NOTE: Need i18n version to support European characters.
  640. // This could be tricky due to different character
  641. // sets and orderings for various languages and platforms.
  642. function isAlphanumeric (s)
  643. {   var i;
  644.     if (isEmpty(s)) 
  645.        if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
  646.        else return (isAlphanumeric.arguments[1] == true);
  647.     // Search through string's characters one by one
  648.     // until we find a non-alphanumeric character.
  649.     // When we do, return false; if we don't, return true.
  650.     for (i = 0; i < s.length; i++)
  651.     {   
  652.         // Check that current character is number or letter.
  653.         var c = s.charAt(i);
  654.         if (! (isLetter(c) || isDigit(c) ) )
  655.         return false;
  656.     }
  657.     // All characters are numbers or letters.
  658.     return true;
  659. }
  660. // reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
  661. //
  662. // Handy function for arbitrarily inserting formatting characters
  663. // or delimiters of various kinds within TARGETSTRING.
  664. //
  665. // reformat takes one named argument, a string s, and any number
  666. // of other arguments.  The other arguments must be integers or
  667. // strings.  These other arguments specify how string s is to be
  668. // reformatted and how and where other strings are to be inserted
  669. // into it.
  670. //
  671. // reformat processes the other arguments in order one by one.
  672. // * If the argument is an integer, reformat appends that number 
  673. //   of sequential characters from s to the resultString.
  674. // * If the argument is a string, reformat appends the string
  675. //   to the resultString.
  676. //
  677. // NOTE: The first argument after TARGETSTRING must be a string.
  678. // (It can be empty.)  The second argument must be an integer.
  679. // Thereafter, integers and strings must alternate.  This is to
  680. // provide backward compatibility to Navigator 2.0.2 JavaScript
  681. // by avoiding use of the typeof operator.
  682. //
  683. // It is the caller's responsibility to make sure that we do not
  684. // try to copy more characters from s than s.length.
  685. //
  686. // EXAMPLES:
  687. //
  688. // * To reformat a 10-digit U.S. phone number from "1234567890"
  689. //   to "(123) 456-7890" make this function call:
  690. //   reformat("1234567890", "(", 3, ") ", 3, "-", 4)
  691. //
  692. // * To reformat a 9-digit U.S. Social Security number from
  693. //   "123456789" to "123-45-6789" make this function call:
  694. //   reformat("123456789", "", 3, "-", 2, "-", 4)
  695. //
  696. // HINT:
  697. //
  698. // If you have a string which is already delimited in one way
  699. // (example: a phone number delimited with spaces as "123 456 7890")
  700. // and you want to delimit it in another way using function reformat,
  701. // call function stripCharsNotInBag to remove the unwanted 
  702. // characters, THEN call function reformat to delimit as desired.
  703. //
  704. // EXAMPLE:
  705. //
  706. // reformat (stripCharsNotInBag ("123 456 7890", digits),
  707. //           "(", 3, ") ", 3, "-", 4)
  708. function reformat (s)
  709. {   var arg;
  710.     var sPos = 0;
  711.     var resultString = "";
  712.     for (var i = 1; i < reformat.arguments.length; i++) {
  713.        arg = reformat.arguments[i];
  714.        if (i % 2 == 1) resultString += arg;
  715.        else {
  716.            resultString += s.substring(sPos, sPos + arg);
  717.            sPos += arg;
  718.        }
  719.     }
  720.     return resultString;
  721. }
  722. // isSSN (STRING s [, BOOLEAN emptyOK])
  723. // 
  724. // isSSN returns true if string s is a valid U.S. Social
  725. // Security Number.  Must be 9 digits.
  726. //
  727. // NOTE: Strip out any delimiters (spaces, hyphens, etc.)
  728. // from string s before calling this function.
  729. //
  730. // For explanation of optional argument emptyOK,
  731. // see comments of function isInteger.
  732. function isSSN (s)
  733. {   if (isEmpty(s)) 
  734.        if (isSSN.arguments.length == 1) return defaultEmptyOK;
  735.        else return (isSSN.arguments[1] == true);
  736.     return (isInteger(s) && s.length == digitsInSocialSecurityNumber)
  737. }
  738. // isUSPhoneNumber (STRING s [, BOOLEAN emptyOK])
  739. // 
  740. // isUSPhoneNumber returns true if string s is a valid U.S. Phone
  741. // Number.  Must be 10 digits.
  742. //
  743. // NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
  744. // from string s before calling this function.
  745. //
  746. // For explanation of optional argument emptyOK,
  747. // see comments of function isInteger.
  748. function isUSPhoneNumber (s)
  749. {   if (isEmpty(s)) 
  750.        if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
  751.        else return (isUSPhoneNumber.arguments[1] == true);
  752.     return (isInteger(s) && s.length == digitsInUSPhoneNumber)
  753. }
  754. // isInternationalPhoneNumber (STRING s [, BOOLEAN emptyOK])
  755. // 
  756. // isInternationalPhoneNumber returns true if string s is a valid 
  757. // international phone number.  Must be digits only; any length OK.
  758. // May be prefixed by + character.
  759. //
  760. // NOTE: A phone number of all zeros would not be accepted.
  761. // I don't think that is a valid phone number anyway.
  762. //
  763. // NOTE: Strip out any delimiters (spaces, hyphens, parentheses, etc.)
  764. // from string s before calling this function.  You may leave in 
  765. // leading + character if you wish.
  766. //
  767. // For explanation of optional argument emptyOK,
  768. // see comments of function isInteger.
  769. function isInternationalPhoneNumber (s)
  770. {   if (isEmpty(s)) 
  771.        if (isInternationalPhoneNumber.arguments.length == 1) return defaultEmptyOK;
  772.        else return (isInternationalPhoneNumber.arguments[1] == true);
  773.     return (isPositiveInteger(s))
  774. }
  775. // isZIPCode (STRING s [, BOOLEAN emptyOK])
  776. // 
  777. // isZIPCode returns true if string s is a valid 
  778. // U.S. ZIP code.  Must be 5 or 9 digits only.
  779. //
  780. // NOTE: Strip out any delimiters (spaces, hyphens, etc.)
  781. // from string s before calling this function.  
  782. //
  783. // For explanation of optional argument emptyOK,
  784. // see comments of function isInteger.
  785. function isZIPCode (s)
  786. {  if (isEmpty(s)) 
  787.        if (isZIPCode.arguments.length == 1) return defaultEmptyOK;
  788.        else return (isZIPCode.arguments[1] == true);
  789.    return (isInteger(s) && 
  790.             ((s.length == digitsInZIPCode1) ||
  791.              (s.length == digitsInZIPCode2)))
  792. }
  793. // isStateCode (STRING s [, BOOLEAN emptyOK])
  794. // 
  795. // Return true if s is a valid U.S. Postal Code 
  796. // (abbreviation for state).
  797. //
  798. // For explanation of optional argument emptyOK,
  799. // see comments of function isInteger.
  800. function isStateCode(s)
  801. {   if (isEmpty(s)) 
  802.        if (isStateCode.arguments.length == 1) return defaultEmptyOK;
  803.        else return (isStateCode.arguments[1] == true);
  804.     return ( (USStateCodes.indexOf(s) != -1) &&
  805.              (s.indexOf(USStateCodeDelimiter) == -1) )
  806. }
  807. // isEmail (STRING s [, BOOLEAN emptyOK])
  808. // 
  809. // Email address must be of form a@b.c -- in other words:
  810. // * there must be at least one character before the @
  811. // * there must be at least one character before and after the .
  812. // * the characters @ and . are both required
  813. //
  814. // For explanation of optional argument emptyOK,
  815. // see comments of function isInteger.
  816. function isEmail (s)
  817. {   if (isEmpty(s)) 
  818.        if (isEmail.arguments.length == 1) return defaultEmptyOK;
  819.        else return (isEmail.arguments[1] == true);
  820.    
  821.     // is s whitespace?
  822.     if (isWhitespace(s)) return false;
  823.     
  824.     // there must be >= 1 character before @, so we
  825.     // start looking at character position 1 
  826.     // (i.e. second character)
  827.     var i = 1;
  828.     var sLength = s.length;
  829.     // look for @
  830.     while ((i < sLength) && (s.charAt(i) != "@"))
  831.     { i++
  832.     }
  833.     if ((i >= sLength) || (s.charAt(i) != "@")) return false;
  834.     else i += 2;
  835.     // look for .
  836.     while ((i < sLength) && (s.charAt(i) != "."))
  837.     { i++
  838.     }
  839.     // there must be at least one character after the .
  840.     if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
  841.     else return true;
  842. }
  843. // isYear (STRING s [, BOOLEAN emptyOK])
  844. // 
  845. // isYear returns true if string s is a valid 
  846. // Year number.  Must be 2 or 4 digits only.
  847. // 
  848. // For Year 2000 compliance, you are advised
  849. // to use 4-digit year numbers everywhere.
  850. //
  851. // And yes, this function is not Year 10000 compliant, but 
  852. // because I am giving you 8003 years of advance notice,
  853. // I don't feel very guilty about this ...
  854. //
  855. // For B.C. compliance, write your own function. ;->
  856. //
  857. // For explanation of optional argument emptyOK,
  858. // see comments of function isInteger.
  859. function isYear (s)
  860. {   if (isEmpty(s)) 
  861.        if (isYear.arguments.length == 1) return defaultEmptyOK;
  862.        else return (isYear.arguments[1] == true);
  863.     if (!isNonnegativeInteger(s)) return false;
  864.     return ((s.length == 2) || (s.length == 4));
  865. }
  866. // isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
  867. // 
  868. // isIntegerInRange returns true if string s is an integer 
  869. // within the range of integer arguments a and b, inclusive.
  870. // 
  871. // For explanation of optional argument emptyOK,
  872. // see comments of function isInteger.
  873. function isIntegerInRange (s, a, b)
  874. {   if (isEmpty(s)) 
  875.        if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
  876.        else return (isIntegerInRange.arguments[1] == true);
  877.     // Catch non-integer strings to avoid creating a NaN below,
  878.     // which isn't available on JavaScript 1.0 for Windows.
  879.     if (!isInteger(s, false)) return false;
  880.     // Now, explicitly change the type to integer via parseInt
  881.     // so that the comparison code below will work both on 
  882.     // JavaScript 1.2 (which typechecks in equality comparisons)
  883.     // and JavaScript 1.1 and before (which doesn't).
  884.     var num = parseInt (s);
  885.     return ((num >= a) && (num <= b));
  886. }
  887. // isMonth (STRING s [, BOOLEAN emptyOK])
  888. // 
  889. // isMonth returns true if string s is a valid 
  890. // month number between 1 and 12.
  891. //
  892. // For explanation of optional argument emptyOK,
  893. // see comments of function isInteger.
  894. function isMonth (s)
  895. {   if (isEmpty(s)) 
  896.        if (isMonth.arguments.length == 1) return defaultEmptyOK;
  897.        else return (isMonth.arguments[1] == true);
  898.     return isIntegerInRange (s, 1, 12);
  899. }
  900. // isDay (STRING s [, BOOLEAN emptyOK])
  901. // 
  902. // isDay returns true if string s is a valid 
  903. // day number between 1 and 31.
  904. // 
  905. // For explanation of optional argument emptyOK,
  906. // see comments of function isInteger.
  907. function isDay (s)
  908. {   if (isEmpty(s)) 
  909.        if (isDay.arguments.length == 1) return defaultEmptyOK;
  910.        else return (isDay.arguments[1] == true);   
  911.     return isIntegerInRange (s, 1, 31);
  912. }
  913. // daysInFebruary (INTEGER year)
  914. // 
  915. // Given integer argument year,
  916. // returns number of days in February of that year.
  917. function daysInFebruary (year)
  918. {   // February has 29 days in any year evenly divisible by four,
  919.     // EXCEPT for centurial years which are not also divisible by 400.
  920.     return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
  921. }
  922. // isDate (STRING year, STRING month, STRING day)
  923. //
  924. // isDate returns true if string arguments year, month, and day 
  925. // form a valid date.
  926. // 
  927. function isDate (year, month, day)
  928. {   // catch invalid years (not 2- or 4-digit) and invalid months and days.
  929.     if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return "1";
  930.     // Explicitly change type to integer to make code work in both
  931.     // JavaScript 1.1 and JavaScript 1.2.
  932.     var intYear = parseInt(year);
  933.     var intMonth = parseInt(month);
  934.     var intDay = parseInt(day);
  935.     // catch invalid days, except for February
  936.     if (intDay > daysInMonth[intMonth]) return "1"; 
  937.     if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return "1";
  938.     return "0";
  939. }
  940. /* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */
  941. // Display prompt string s in status bar.
  942. function prompt (s)
  943. {   window.status = s
  944. }
  945. // Display data entry prompt string s in status bar.
  946. function promptEntry (s)
  947. {   window.status = pEntryPrompt + s
  948. }
  949. // Notify user that required field theField is empty.
  950. // String s describes expected contents of theField.value.
  951. // Put focus in theField and return false.
  952. function warnEmpty (theField, s)
  953. {   theField.focus()
  954.     alert(mPrefix + s + mSuffix)
  955.     return false
  956. }
  957. // Notify user that contents of field theField are invalid.
  958. // String s describes expected contents of theField.value.
  959. // Put select theField, pu focus in it, and return false.
  960. function warnInvalid (theField, s)
  961. {   theField.focus()
  962.     theField.select()
  963.     //alert(s)
  964.     return false
  965. }
  966. /* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */
  967. // checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
  968. //
  969. // Check that string theField.value is not all whitespace.
  970. //
  971. // For explanation of optional argument emptyOK,
  972. // see comments of function isInteger.
  973. function checkString (theField, s, emptyOK)
  974. {   // Next line is needed on NN3 to avoid "undefined is not a number" error
  975.     // in equality comparison below.
  976.     if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
  977.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  978.     if (isWhitespace(theField.value)) 
  979.        return warnEmpty (theField, s);
  980.     else return true;
  981. }
  982. // checkStateCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
  983. //
  984. // Check that string theField.value is a valid U.S. state code.
  985. //
  986. // For explanation of optional argument emptyOK,
  987. // see comments of function isInteger.
  988. function checkStateCode (theField, emptyOK)
  989. {   if (checkStateCode.arguments.length == 1) emptyOK = defaultEmptyOK;
  990.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  991.     else
  992.     {  theField.value = theField.value.toUpperCase();
  993.        if (!isStateCode(theField.value, false)) 
  994.           return warnInvalid (theField, iStateCode);
  995.        else return true;
  996.     }
  997. }
  998. // takes ZIPString, a string of 5 or 9 digits;
  999. // if 9 digits, inserts separator hyphen
  1000. function reformatZIPCode (ZIPString)
  1001. {   if (ZIPString.length == 5) return ZIPString;
  1002.     else return (reformat (ZIPString, "", 5, "-", 4));
  1003. }
  1004. // checkZIPCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
  1005. //
  1006. // Check that string theField.value is a valid ZIP code.
  1007. //
  1008. // For explanation of optional argument emptyOK,
  1009. // see comments of function isInteger.
  1010. function checkZIPCode (theField, emptyOK)
  1011. {   if (checkZIPCode.arguments.length == 1) emptyOK = defaultEmptyOK;
  1012.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1013.     else
  1014.     { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
  1015.       if (!isZIPCode(normalizedZIP, false)) 
  1016.          return warnInvalid (theField, iZIPCode);
  1017.       else 
  1018.       {  // if you don't want to insert a hyphen, comment next line out
  1019.          theField.value = reformatZIPCode(normalizedZIP)
  1020.          return true;
  1021.       }
  1022.     }
  1023. }
  1024. // takes USPhone, a string of 10 digits
  1025. // and reformats as (123) 456-789
  1026. function reformatUSPhone (USPhone)
  1027. {   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
  1028. }
  1029. // checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
  1030. //
  1031. // Check that string theField.value is a valid US Phone.
  1032. //
  1033. // For explanation of optional argument emptyOK,
  1034. // see comments of function isInteger.
  1035. function checkUSPhone (theField, emptyOK)
  1036. {   if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
  1037.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1038.     else
  1039.     {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
  1040.        if (!isUSPhoneNumber(normalizedPhone, false)) 
  1041.           return warnInvalid (theField, iUSPhone);
  1042.        else 
  1043.        {  // if you don't want to reformat as (123) 456-789, comment next line out
  1044.           theField.value = reformatUSPhone(normalizedPhone)
  1045.           return true;
  1046.        }
  1047.     }
  1048. }
  1049. // checkInternationalPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
  1050. //
  1051. // Check that string theField.value is a valid International Phone.
  1052. //
  1053. // For explanation of optional argument emptyOK,
  1054. // see comments of function isInteger.
  1055. function checkInternationalPhone (theField, emptyOK)
  1056. {   if (checkInternationalPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
  1057.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1058.     else
  1059.     {  if (!isInternationalPhoneNumber(theField.value, false)) 
  1060.           return warnInvalid (theField, iWorldPhone);
  1061.        else return true;
  1062.     }
  1063. }
  1064. // checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
  1065. //
  1066. // Check that string theField.value is a valid Email.
  1067. //
  1068. // For explanation of optional argument emptyOK,
  1069. // see comments of function isInteger.
  1070. function checkEmail (theField, emptyOK)
  1071. {   if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  1072.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1073.     else if (!isEmail(theField.value, false)) 
  1074.        return warnInvalid (theField, iEmail);
  1075.     else return true;
  1076. }
  1077. // takes SSN, a string of 9 digits
  1078. // and reformats as 123-45-6789
  1079. function reformatSSN (SSN)
  1080. {   return (reformat (SSN, "", 3, "-", 2, "-", 4))
  1081. }
  1082. // Check that string theField.value is a valid SSN.
  1083. //
  1084. // For explanation of optional argument emptyOK,
  1085. // see comments of function isInteger.
  1086. function checkSSN (theField, emptyOK)
  1087. {   if (checkSSN.arguments.length == 1) emptyOK = defaultEmptyOK;
  1088.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1089.     else
  1090.     {  var normalizedSSN = stripCharsInBag(theField.value, SSNDelimiters)
  1091.        if (!isSSN(normalizedSSN, false)) 
  1092.           return warnInvalid (theField, iSSN);
  1093.        else 
  1094.        {  // if you don't want to reformats as 123-456-7890, comment next line out
  1095.           theField.value = reformatSSN(normalizedSSN)
  1096.           return true;
  1097.        }
  1098.     }
  1099. }
  1100. // Check that string theField.value is a valid Year.
  1101. //
  1102. // For explanation of optional argument emptyOK,
  1103. // see comments of function isInteger.
  1104. function checkYear (theField, emptyOK)
  1105. {   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
  1106.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1107.     if (!isYear(theField.value, false)) 
  1108.        return warnInvalid (theField, iYear);
  1109.     else return true;
  1110. }
  1111. // Check that string theField.value is a valid Month.
  1112. //
  1113. // For explanation of optional argument emptyOK,
  1114. // see comments of function isInteger.
  1115. function checkMonth (theField, emptyOK)
  1116. {   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
  1117.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1118.     if (!isMonth(theField.value, false)) 
  1119.        return warnInvalid (theField, iMonth);
  1120.     else return true;
  1121. }
  1122. // Check that string theField.value is a valid Day.
  1123. //
  1124. // For explanation of optional argument emptyOK,
  1125. // see comments of function isInteger.
  1126. function checkDay (theField, emptyOK)
  1127. {   if (checkDay.arguments.length == 1) emptyOK = defaultEmptyOK;
  1128.     if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  1129.     if (!isDay(theField.value, false)) 
  1130.        return warnInvalid (theField, iDay);
  1131.     else return true;
  1132. }
  1133. // checkDate (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false])
  1134. //
  1135. // Check that yearField.value, monthField.value, and dayField.value 
  1136. // form a valid date.
  1137. //
  1138. // If they don't, labelString (the name of the date, like "Birth Date")
  1139. // is displayed to tell the user which date field is invalid.
  1140. //
  1141. // If it is OK for the day field to be empty, set optional argument
  1142. // OKtoOmitDay to true.  It defaults to false.
  1143. function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
  1144. {   // Next line is needed on NN3 to avoid "undefined is not a number" error
  1145.     // in equality comparison below.
  1146.     if (checkDate.arguments.length == 4) OKtoOmitDay = false;
  1147.     if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
  1148.     if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
  1149.     if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
  1150.     else if (!isDay(dayField.value)) 
  1151.        return warnInvalid (dayField, iDay);
  1152.     if (isDate (yearField.value, monthField.value, dayField.value))
  1153.        return true;
  1154.     //alert (iDatePrefix + labelString + iDateSuffix)
  1155.     return false
  1156. }
  1157. // Get checked value from radio button.
  1158. function getRadioButtonValue (radio)
  1159. {   for (var i = 0; i < radio.length; i++)
  1160.     {   if (radio[i].checked) { break }
  1161.     }
  1162.     return radio[i].value
  1163. }
  1164. // Validate credit card info.
  1165. function checkCreditCard (radio, theField)
  1166. {   var cardType = getRadioButtonValue (radio)
  1167.     var normalizedCCN = stripCharsInBag(theField.value, creditCardDelimiters)
  1168.     if (!isCardMatch(cardType, normalizedCCN)) 
  1169.        return warnInvalid (theField, iCreditCardPrefix + cardType + iCreditCardSuffix);
  1170.     else 
  1171.     {  theField.value = normalizedCCN
  1172.        return true
  1173.     }
  1174. }
  1175. /*  ================================================================
  1176.     Credit card verification functions
  1177.     Originally included as Starter Application 1.0.0 in LivePayment.
  1178.     20 Feb 1997 modified by egk:
  1179.            changed naming convention to initial lowercase
  1180.                   (isMasterCard instead of IsMasterCard, etc.)
  1181.            changed isCC to isCreditCard
  1182.            retained functions named with older conventions from
  1183.                   LivePayment as stub functions for backward 
  1184.                   compatibility only
  1185.            added "AMERICANEXPRESS" as equivalent of "AMEX" 
  1186.                   for naming consistency 
  1187.     ================================================================ */
  1188. /*  ================================================================
  1189.     FUNCTION:  isCreditCard(st)
  1190.  
  1191.     INPUT:     st - a string representing a credit card number
  1192.     RETURNS:  true, if the credit card number passes the Luhn Mod-10
  1193.     test.
  1194.       false, otherwise
  1195.     ================================================================ */
  1196. function isCreditCard(st) {
  1197.   // Encoding only works on cards with less than 19 digits
  1198.   if (st.length > 19)
  1199.     return (false);
  1200.   sum = 0; mul = 1; l = st.length;
  1201.   for (i = 0; i < l; i++) {
  1202.     digit = st.substring(l-i-1,l-i);
  1203.     tproduct = parseInt(digit ,10)*mul;
  1204.     if (tproduct >= 10)
  1205.       sum += (tproduct % 10) + 1;
  1206.     else
  1207.       sum += tproduct;
  1208.     if (mul == 1)
  1209.       mul++;
  1210.     else
  1211.       mul--;
  1212.   }
  1213. // Uncomment the following line to help create credit card numbers
  1214. // 1. Create a dummy number with a 0 as the last digit
  1215. // 2. Examine the sum written out
  1216. // 3. Replace the last digit with the difference between the sum and
  1217. //    the next multiple of 10.
  1218. //  document.writeln("<BR>Sum      = ",sum,"<BR>");
  1219. //  alert("Sum      = " + sum);
  1220.   if ((sum % 10) == 0)
  1221.     return (true);
  1222.   else
  1223.     return (false);
  1224. } // END FUNCTION isCreditCard()
  1225. /*  ================================================================
  1226.     FUNCTION:  isVisa()
  1227.  
  1228.     INPUT:     cc - a string representing a credit card number
  1229.     RETURNS:  true, if the credit card number is a valid VISA number.
  1230.     
  1231.       false, otherwise
  1232.     Sample number: 4111 1111 1111 1111 (16 digits)
  1233.     ================================================================ */
  1234. function isVisa(cc)
  1235. {
  1236.   if (((cc.length == 16) || (cc.length == 13)) &&
  1237.       (cc.substring(0,1) == 4))
  1238.     return isCreditCard(cc);
  1239.   return false;
  1240. }  // END FUNCTION isVisa()
  1241. /*  ================================================================
  1242.     FUNCTION:  isMasterCard()
  1243.  
  1244.     INPUT:     cc - a string representing a credit card number
  1245.     RETURNS:  true, if the credit card number is a valid MasterCard
  1246.     number.
  1247.     
  1248.       false, otherwise
  1249.     Sample number: 5500 0000 0000 0004 (16 digits)
  1250.     ================================================================ */
  1251. function isMasterCard(cc)
  1252. {
  1253.   firstdig = cc.substring(0,1);
  1254.   seconddig = cc.substring(1,2);
  1255.   if ((cc.length == 16) && (firstdig == 5) &&
  1256.       ((seconddig >= 1) && (seconddig <= 5)))
  1257.     return isCreditCard(cc);
  1258.   return false;
  1259. } // END FUNCTION isMasterCard()
  1260. /*  ================================================================
  1261.     FUNCTION:  isAmericanExpress()
  1262.  
  1263.     INPUT:     cc - a string representing a credit card number
  1264.     RETURNS:  true, if the credit card number is a valid American
  1265.     Express number.
  1266.     
  1267.       false, otherwise
  1268.     Sample number: 340000000000009 (15 digits)
  1269.     ================================================================ */
  1270. function isAmericanExpress(cc)
  1271. {
  1272.   firstdig = cc.substring(0,1);
  1273.   seconddig = cc.substring(1,2);
  1274.   if ((cc.length == 15) && (firstdig == 3) &&
  1275.       ((seconddig == 4) || (seconddig == 7)))
  1276.     return isCreditCard(cc);
  1277.   return false;
  1278. } // END FUNCTION isAmericanExpress()
  1279. /*  ================================================================
  1280.     FUNCTION:  isDinersClub()
  1281.  
  1282.     INPUT:     cc - a string representing a credit card number
  1283.     RETURNS:  true, if the credit card number is a valid Diner's
  1284.     Club number.
  1285.     
  1286.       false, otherwise
  1287.     Sample number: 30000000000004 (14 digits)
  1288.     ================================================================ */
  1289. function isDinersClub(cc)
  1290. {
  1291.   firstdig = cc.substring(0,1);
  1292.   seconddig = cc.substring(1,2);
  1293.   if ((cc.length == 14) && (firstdig == 3) &&
  1294.       ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
  1295.     return isCreditCard(cc);
  1296.   return false;
  1297. }
  1298. /*  ================================================================
  1299.     FUNCTION:  isCarteBlanche()
  1300.  
  1301.     INPUT:     cc - a string representing a credit card number
  1302.     RETURNS:  true, if the credit card number is a valid Carte
  1303.     Blanche number.
  1304.     
  1305.       false, otherwise
  1306.     ================================================================ */
  1307. function isCarteBlanche(cc)
  1308. {
  1309.   return isDinersClub(cc);
  1310. }
  1311. /*  ================================================================
  1312.     FUNCTION:  isDiscover()
  1313.  
  1314.     INPUT:     cc - a string representing a credit card number
  1315.     RETURNS:  true, if the credit card number is a valid Discover
  1316.     card number.
  1317.     
  1318.       false, otherwise
  1319.     Sample number: 6011000000000004 (16 digits)
  1320.     ================================================================ */
  1321. function isDiscover(cc)
  1322. {
  1323.   first4digs = cc.substring(0,4);
  1324.   if ((cc.length == 16) && (first4digs == "6011"))
  1325.     return isCreditCard(cc);
  1326.   return false;
  1327. } // END FUNCTION isDiscover()
  1328. /*  ================================================================
  1329.     FUNCTION:  isEnRoute()
  1330.  
  1331.     INPUT:     cc - a string representing a credit card number
  1332.     RETURNS:  true, if the credit card number is a valid enRoute
  1333.     card number.
  1334.     
  1335.       false, otherwise
  1336.     Sample number: 201400000000009 (15 digits)
  1337.     ================================================================ */
  1338. function isEnRoute(cc)
  1339. {
  1340.   first4digs = cc.substring(0,4);
  1341.   if ((cc.length == 15) &&
  1342.       ((first4digs == "2014") ||
  1343.        (first4digs == "2149")))
  1344.     return isCreditCard(cc);
  1345.   return false;
  1346. }
  1347. /*  ================================================================
  1348.     FUNCTION:  isJCB()
  1349.  
  1350.     INPUT:     cc - a string representing a credit card number
  1351.     RETURNS:  true, if the credit card number is a valid JCB
  1352.     card number.
  1353.     
  1354.       false, otherwise
  1355.     ================================================================ */
  1356. function isJCB(cc)
  1357. {
  1358.   first4digs = cc.substring(0,4);
  1359.   if ((cc.length == 16) &&
  1360.       ((first4digs == "3088") ||
  1361.        (first4digs == "3096") ||
  1362.        (first4digs == "3112") ||
  1363.        (first4digs == "3158") ||
  1364.        (first4digs == "3337") ||
  1365.        (first4digs == "3528")))
  1366.     return isCreditCard(cc);
  1367.   return false;
  1368. } // END FUNCTION isJCB()
  1369. /*  ================================================================
  1370.     FUNCTION:  isAnyCard()
  1371.  
  1372.     INPUT:     cc - a string representing a credit card number
  1373.     RETURNS:  true, if the credit card number is any valid credit
  1374.     card number for any of the accepted card types.
  1375.     
  1376.       false, otherwise
  1377.     ================================================================ */
  1378. function isAnyCard(cc)
  1379. {
  1380.   if (!isCreditCard(cc))
  1381.     return false;
  1382.   if (!isMasterCard(cc) && !isVisa(cc) && !isAmericanExpress(cc) && !isDinersClub(cc) &&
  1383.       !isDiscover(cc) && !isEnRoute(cc) && !isJCB(cc)) {
  1384.     return false;
  1385.   }
  1386.   return true;
  1387. } // END FUNCTION isAnyCard()
  1388. /*  ================================================================
  1389.     FUNCTION:  isCardMatch()
  1390.  
  1391.     INPUT:    cardType - a string representing the credit card type
  1392.       cardNumber - a string representing a credit card number
  1393.     RETURNS:  true, if the credit card number is valid for the particular
  1394.       credit card type given in "cardType".
  1395.     
  1396.       false, otherwise
  1397.     ================================================================ */
  1398. function isCardMatch (cardType, cardNumber)
  1399. {
  1400. cardType = cardType.toUpperCase();
  1401. var doesMatch = true;
  1402. if ((cardType == "VISA") && (!isVisa(cardNumber)))
  1403. doesMatch = false;
  1404. if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
  1405. doesMatch = false;
  1406. if ( ( (cardType == "AMERICANEXPRESS") || (cardType == "AMEX") )
  1407.                 && (!isAmericanExpress(cardNumber))) doesMatch = false;
  1408. if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
  1409. doesMatch = false;
  1410. if ((cardType == "JCB") && (!isJCB(cardNumber)))
  1411. doesMatch = false;
  1412. if ((cardType == "DINERS") && (!isDinersClub(cardNumber)))
  1413. doesMatch = false;
  1414. if ((cardType == "CARTEBLANCHE") && (!isCarteBlanche(cardNumber)))
  1415. doesMatch = false;
  1416. if ((cardType == "ENROUTE") && (!isEnRoute(cardNumber)))
  1417. doesMatch = false;
  1418. return doesMatch;
  1419. }  // END FUNCTION CardMatch()
  1420. /*  ================================================================
  1421.     The below stub functions are retained for backward compatibility
  1422.     with the original LivePayment code so that it should be possible
  1423.     in principle to swap in this new module as a replacement for the  
  1424.     older module without breaking existing code.  (There are no
  1425.     guarantees, of course, but it should work.)
  1426.     When writing new code, do not use these stub functions; use the
  1427.     functions defined above.
  1428.     ================================================================ */
  1429. function IsCC (st) {
  1430.     return isCreditCard(st);
  1431. }
  1432. function IsVisa (cc)  {
  1433.   return isVisa(cc);
  1434. }
  1435. function IsVISA (cc)  {
  1436.   return isVisa(cc);
  1437. }
  1438. function IsMasterCard (cc)  {
  1439.   return isMasterCard(cc);
  1440. }
  1441. function IsMastercard (cc)  {
  1442.   return isMasterCard(cc);
  1443. }
  1444. function IsMC (cc)  {
  1445.   return isMasterCard(cc);
  1446. }
  1447. function IsAmericanExpress (cc)  {
  1448.   return isAmericanExpress(cc);
  1449. }
  1450. function IsAmEx (cc)  {
  1451.   return isAmericanExpress(cc);
  1452. }
  1453. function IsDinersClub (cc)  {
  1454.   return isDinersClub(cc);
  1455. }
  1456. function IsDC (cc)  {
  1457.   return isDinersClub(cc);
  1458. }
  1459. function IsDiners (cc)  {
  1460.   return isDinersClub(cc);
  1461. }
  1462. function IsCarteBlanche (cc)  {
  1463.   return isCarteBlanche(cc);
  1464. }
  1465. function IsCB (cc)  {
  1466.   return isCarteBlanche(cc);
  1467. }
  1468. function IsDiscover (cc)  {
  1469.   return isDiscover(cc);
  1470. }
  1471. function IsEnRoute (cc)  {
  1472.   return isEnRoute(cc);
  1473. }
  1474. function IsenRoute (cc)  {
  1475.   return isEnRoute(cc);
  1476. }
  1477. function IsJCB (cc)  {
  1478.   return isJCB(cc);
  1479. }
  1480. function IsAnyCard(cc)  {
  1481.   return isAnyCard(cc);
  1482. }
  1483. function IsCardMatch (cardType, cardNumber)  {
  1484.   return isCardMatch (cardType, cardNumber);
  1485. }
  1486. //if all the checkboxes of account were unchecked ,then the "checkall" checkbox was unchecked.
  1487. //written by Charles Cao
  1488. //date:2000.8.14
  1489. function checknull(each,all){
  1490. var countit=0;
  1491. if (each.length==null)
  1492.    {
  1493.      all.checked=each.checked;
  1494.    }
  1495.   else
  1496.    {
  1497.      for(i=0;i<each.length;i++)
  1498.         {
  1499. if (each[i].checked)
  1500. countit+=1;
  1501. }
  1502. if (countit==0)
  1503. all.checked=false;
  1504. }
  1505. }
  1506. //click the "checkall" button, then all the accounts or operators will be checked.
  1507. //written by Charles Cao
  1508. //date:2000.8.14
  1509. function checkall(each,all)
  1510. {
  1511. if(each.length==null)
  1512. {
  1513.      each.checked=all.checked;
  1514.     }
  1515. else
  1516.   for(i=0;i<each.length;i++)
  1517.   {
  1518.    each[i].checked = all.checked;
  1519. }
  1520.   }
  1521. }
  1522. //check if the date is valid at these format: yyyymmdd OR yymmdd
  1523. //written by Charles Cao
  1524. //date:2000.8.16
  1525. function validDate(my)
  1526. {
  1527. var cot=my.value;
  1528. if (cot.length==8)
  1529. {
  1530. var y=cot.substring(0,4);
  1531. if (cot.charAt(4)=='0')
  1532. var m=cot.substring(5,6);
  1533. else
  1534. var m=cot.substring(4,6);
  1535. if (cot.charAt(6)=='0')
  1536. var d=cot.substring(7);
  1537. else
  1538. var d=cot.substring(6);
  1539. }
  1540. if (cot.length==6)
  1541. {
  1542. var y=cot.substring(0,2);
  1543. if (cot.charAt(2)=='0')
  1544. var m=cot.substring(3,4);
  1545. else
  1546. var m=cot.substring(2,4);
  1547. if (cot.charAt(4)=='0')
  1548. var d=cot.substring(5);
  1549. else
  1550. var d=cot.substring(4);
  1551. }
  1552. if (cot.length==0)
  1553. return "0";
  1554. var a=isDate(y,m,d);
  1555. return a;
  1556. }
  1557. //these function is to show a layer
  1558. function Change()
  1559. {
  1560. aa.value=document.form2.changeIt.value;
  1561. }
  1562. function create(tag, left, top, width, height, visible, content) 
  1563. {
  1564.    var layer;
  1565.   
  1566.    document.writeln('<div id="' + tag + '" style="position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + '">');
  1567.    document.writeln(content);
  1568.    document.writeln('</div>');
  1569.  }
  1570. function creatediv(tag, left, top, width, height, visible, content) 
  1571. {
  1572.    var layer;
  1573.   
  1574.    document.writeln('<div id="' + tag + '" style="overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + '">');
  1575.    document.writeln(content);
  1576.    document.writeln('</div>');
  1577.  
  1578. function hide(tag) {
  1579.   var layer = get(tag);
  1580.        layer.visibility = "hidden";
  1581. }
  1582. function show(tag) {
  1583.   var layer = get(tag);
  1584.        layer.visibility = "visible";
  1585. }
  1586. function get(tag) {
  1587.        layer = eval('document.all.' + tag+ '.style');
  1588.     return(layer);
  1589.  }
  1590. function change(my) {
  1591. my.value=document.form2.changeIt.value;
  1592. }
  1593. //add dot to the number.
  1594. function dot(num) {
  1595. var count=0;
  1596. var numer=0;
  1597. for (i = 0; i < num.length; i++)
  1598.     {   
  1599.         var c = num.charAt(i);
  1600.         if (c == decimalPointDelimiter)
  1601.          count=1;
  1602.     }
  1603. if (count==0 && num.length>2)
  1604. numer=num.substring(0,num.length-2)+"."+num.substring(num.length-2);
  1605. if (count==0 && num.length<3)
  1606. numer="0."+num;
  1607. if (count==1)
  1608. {
  1609. DotIndex=num.indexOf('.');
  1610. if (num.substring(DotIndex+1).length>2)
  1611. numer=num.substring(0,DotIndex)+"."+num.substring(DotIndex+1,DotIndex+3);
  1612. else
  1613. numer=num.substring(0,DotIndex)+"."+(num+"000").substring(DotIndex+1,DotIndex+3);
  1614. }
  1615. return(numer);
  1616. }
  1617. //when click "other use",pop up a text dialog,insert another use.
  1618. function selct(my)
  1619. {
  1620. var countme=0;
  1621. for (i=0;i<my.length;i++)
  1622. {
  1623. if (my.options[i].text=="其他" && my.options[i].selected)
  1624. {
  1625. countme=1;
  1626. show(useIt1);
  1627. }
  1628. }
  1629. if (countme==0)
  1630. {
  1631. hide(useIt1);
  1632. }
  1633. }
  1634. //load current date at this format(xxxxxxxx)
  1635. function loaddate(my)
  1636. {
  1637.    dt=new Date();
  1638. var y=dt.getYear().toString();
  1639. m1=dt.getMonth()+1;
  1640. if(m1<10) 
  1641. var m="0"+m1;
  1642. else
  1643. var m=m1.toString();
  1644. if(dt.getDate()<10)
  1645.     var d="0"+dt.getDate();
  1646. else
  1647. var d=dt.getDate().toString();
  1648. my.value=y+m+d;
  1649. }
  1650. //print the current date on the page
  1651. function printdate()
  1652. {
  1653.    dt=new Date();
  1654. var y=dt.getYear().toString();
  1655. m1=dt.getMonth()+1;
  1656. if(m1<10)
  1657. var m="0"+m1;
  1658. else
  1659. var m=m1.toString();
  1660. if(dt.getDate()<10)
  1661.     var d="0"+dt.getDate();
  1662. else
  1663. var d=dt.getDate().toString();
  1664. return(y+'/'+m+'/'+d);
  1665. }
  1666. //load current date at this format(xxxx/xx/xx)
  1667. function loaddate1()
  1668. {
  1669.    dt=new Date();
  1670. var y=dt.getYear().toString();
  1671. m1=dt.getMonth()+1;
  1672. if(m1<10)
  1673. var m="0"+m1;
  1674. else
  1675. var m=m1.toString();
  1676. if(dt.getDate()<10)
  1677.     var d="0"+dt.getDate();
  1678. else
  1679. var d=dt.getDate().toString();
  1680. var return_me=y+"/"+m+"/"+d;
  1681. return return_me;
  1682. }
  1683. //count most close date to pay interest
  1684. function count_day()
  1685. {
  1686. dt=new Date();
  1687. var current_year=dt.getYear();
  1688. var current_month=dt.getMonth()+1;
  1689. var current_day=dt.getDate();
  1690. if (current_month>=1 && current_month<3)
  1691. countday=current_year+"/03/20";
  1692. if (current_month==3)
  1693. if (current_day>20)
  1694. countday=current_year+"/06/20";
  1695. else
  1696. countday=current_year+"/03/20";
  1697. if (current_month>3 && current_month<6)
  1698. countday=current_year+"/06/20";
  1699. if (current_month==6)
  1700. if (current_day>20)
  1701. countday=current_year+"/09/20";
  1702. else 
  1703. countday=current_year+"/06/20";
  1704. if (current_month>6 && current_month<9)
  1705. countday=current_year+"/09/20";
  1706. if (current_month==9)
  1707. if (current_day>20)
  1708. countday=current_year+"/12/20";
  1709. else
  1710. countday=current_year+"/09/20";
  1711. if (current_month>9 && current_month<12)
  1712. countday=current_year+"/12/20";
  1713. if (current_month==12)
  1714. if (current_day>20)
  1715. {
  1716. t_year=parseInt(current_year)+1;
  1717. countday=t_year+"/03/20";
  1718. }
  1719. else
  1720. countday=current_year+"/12/20";
  1721. return countday;
  1722. }
  1723. //set the first radio to checked
  1724. function check_radio(my)
  1725. {
  1726. if (my.length!=null)
  1727. {
  1728. if (my[0].disabled==true)
  1729. {
  1730. for (i=0;i<my.length-1;i++)
  1731. {
  1732. if (my[i].disabled==true && my[i+1].disabled!=true)
  1733. {
  1734. my[i+1].checked=true;
  1735. return false;
  1736. }
  1737. }
  1738. if (my[my.length-1].disabled==true)
  1739. {
  1740. return false;
  1741. }
  1742. }
  1743. else
  1744. {
  1745. my[0].checked=true;
  1746. }
  1747. }
  1748. }
  1749. //clear comma in cash
  1750. function comma_clr(my)
  1751. {
  1752. var return_me="";
  1753. for (i=0;i<my.value.length;i++)
  1754. {
  1755. if (my.value.charAt(i)!=",")
  1756. {
  1757. return_me+=my.value.charAt(i);
  1758. }
  1759. }
  1760. return return_me;
  1761. }
  1762. //if num is cash,then add comma.
  1763. function AddComma(num)
  1764. {
  1765. var returnNum="";
  1766. var y='0';
  1767. num=trim(num);
  1768. DotIndex=num.indexOf('.');
  1769. if(DotIndex!=-1)
  1770. {
  1771. Bignum=num.substring(0,DotIndex);
  1772. while(y=='0')
  1773. {
  1774. y=Bignum.substring(0,1);
  1775. if(y=='0')
  1776. {
  1777. Bignum=Bignum.substring(1);
  1778. }
  1779. }
  1780. returnNum=num.substring(DotIndex);
  1781. }
  1782. else
  1783. {
  1784. Bignum=num;
  1785. while(y=='0')
  1786. {
  1787. y=Bignum.substring(0,1);
  1788. if(y=='0')
  1789. {
  1790. Bignum=Bignum.substring(1);
  1791. }
  1792. }
  1793. }
  1794. BignumLength=Bignum.length;
  1795. countMe=Math.floor(BignumLength/3);
  1796. if(countMe!=0)
  1797. {
  1798. for(x=1;x<countMe+1;x++)
  1799. {
  1800. if(x!=1)
  1801. returnNum=Bignum.substring(BignumLength-x*3,BignumLength-(x-1)*3)+","+returnNum;
  1802. else
  1803. returnNum=Bignum.substring(BignumLength-x*3,BignumLength-(x-1)*3)+returnNum;
  1804. }
  1805. if (BignumLength!=countMe*3)
  1806. returnNum=Bignum.substring(0,BignumLength-countMe*3)+","+returnNum;
  1807. }
  1808. else
  1809. returnNum=Bignum+returnNum;
  1810. if(returnNum=='')
  1811. returnNum='0';
  1812. return returnNum;
  1813. }
  1814. //if the num have comma, then clear it.
  1815. function ClearComma(num)
  1816. {
  1817. var returnNum="";
  1818. for(i=0;i<num.length;i++)
  1819. {
  1820. per=num.substring(i,i+1);
  1821. if(per!=',')
  1822. {
  1823. returnNum+=per;
  1824. }
  1825. }
  1826. return returnNum;
  1827. }
  1828. function trim( trimString )
  1829. {
  1830. var strResult = "";
  1831. if( trimString == null || trimString.length == 0 )
  1832. return strResult;
  1833. strResult = leftTrim( trimString );
  1834. strResult = rightTrim( strResult );
  1835. return strResult;
  1836. }
  1837. function leftTrim( trimString )
  1838. {
  1839. var strResult = "";
  1840. var i = 0;
  1841. if( trimString == null || trimString.length == 0 )
  1842. return strResult;
  1843. for( ; i < trimString.length; i++ )
  1844. {
  1845. var cCurrentChar = trimString.charAt(i);
  1846. if( cCurrentChar == 't' ||
  1847. cCurrentChar == ' ' ||
  1848. cCurrentChar == 'r' ||
  1849. cCurrentChar == 'n' )
  1850. continue;
  1851. else
  1852. break;
  1853. }
  1854. strResult = trimString.substring( i, trimString.length );
  1855. return strResult;
  1856. }
  1857. function rightTrim( trimString )
  1858. {
  1859. var strResult = "";
  1860. var i = 0;
  1861. if( trimString == null || trimString.length == 0 )
  1862. return strResult;
  1863. for( i = trimString.length; i > 0; i-- )
  1864. {
  1865. var cCurrentChar = trimString.charAt(i-1);
  1866. if( cCurrentChar == 't' ||
  1867. cCurrentChar == ' ' ||
  1868. cCurrentChar == 'r' ||
  1869. cCurrentChar == 'n' )
  1870. continue;
  1871. else
  1872. break;
  1873. }
  1874. strResult = trimString.substring( 0, i );
  1875. return strResult;
  1876. }
  1877. function validMonth(my)
  1878. {
  1879. var cot=my;
  1880. var m = '';
  1881. //alert(cot.length);
  1882. if (cot.length==6)
  1883. {
  1884. var y=cot.substring(0,4);
  1885. if (cot.charAt(4)=='0')
  1886. m=cot.substring(5);
  1887. else
  1888. m=cot.substring(4);
  1889. }
  1890. if (cot.length==0)
  1891. return "0";
  1892. var a=isDate(y,m,'01');
  1893. return a;
  1894. }
  1895. function validDateValue(my)
  1896. {
  1897. var cot=my;
  1898. if (cot.length==8)
  1899. {
  1900. var y=cot.substring(0,4);
  1901. if (cot.charAt(4)=='0')
  1902. var m=cot.substring(5,6);
  1903. else
  1904. var m=cot.substring(4,6);
  1905. if (cot.charAt(6)=='0')
  1906. var d=cot.substring(7);
  1907. else
  1908. var d=cot.substring(6);
  1909. }
  1910. if (cot.length==6)
  1911. {
  1912. var y=cot.substring(0,2);
  1913. if (cot.charAt(2)=='0')
  1914. var m=cot.substring(3,4);
  1915. else
  1916. var m=cot.substring(2,4);
  1917. if (cot.charAt(4)=='0')
  1918. var d=cot.substring(5);
  1919. else
  1920. var d=cot.substring(4);
  1921. }
  1922. if (cot.length==0)
  1923. return "0";
  1924. var a=isDate(y,m,d);
  1925. return a;
  1926. }
  1927. function printpage(m_printpage1){
  1928.    
  1929.    var newstr = document.all.item(m_printpage1).innerHTML;
  1930.    //newwindow = window.open();
  1931.    //newwindow.document.body.innerHTML = newstr;
  1932.    //newwindow.document.write("<input type='button' value='打印' onclick='window.print()'/>")
  1933.    var oldstr = document.body.innerHTML;
  1934.    document.body.innerHTML = newstr;
  1935.    window.print(); 
  1936.    document.body.innerHTML = oldstr;
  1937.    
  1938.    return false;
  1939. }
  1940. //
  1941. function set_currdate(m_year,m_month,m_day)
  1942. {
  1943.    var date = new Date();
  1944.    m_year.value = date.getFullYear();
  1945.    var mon = "00" + (date.getMonth()+1);
  1946.    m_month.value = mon.substring(mon.length-2,mon.length);   
  1947.    var dat = "00" + date.getDate();
  1948.    m_day.value = dat.substring(dat.length-2,dat.length);
  1949. }
  1950. //
  1951. function set_currmonth(m_year,m_month)
  1952. {
  1953.    var date = new Date();
  1954.    m_year.value = date.getFullYear();
  1955.    var mon = "00" + (date.getMonth()+1);
  1956.    m_month.value = mon.substring(mon.length-2,mon.length);
  1957. }