home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2005 December / CyberMycha 12-2005 (Poland) (Disc 2).7z / CyberMycha 12-2005 (Poland) (Disc 2).bin / Uzytki / arce505pol.exe / Reader / JavaScripts / aform.js
Encoding:
JavaScript  |  2002-03-21  |  34.9 KB  |  1,288 lines

  1. /*
  2.     ==========================================================================
  3.     Module: AForm.js
  4.     ==========================================================================
  5.     Pre-canned functions to map the user interface into JavaScripts.
  6.     ==========================================================================
  7.     The Software, including this file, is subject to the End User License
  8.     Agreement.
  9.     Copyright (c) 1998, Adobe Systems Incorporated, All Rights Reserved.
  10.     ==========================================================================
  11. */
  12.  
  13. // The following code "exports" any strings in the list into the current scope.
  14. var esStrsToExport =["IDS_GREATER_THAN", "IDS_GT_AND_LT", "IDS_LESS_THAN", "IDS_INVALID_MONTH",
  15.                    "IDS_INVALID_DATE", "IDS_INVALID_VALUE", "IDS_AM", "IDS_PM", "IDS_MONTH_INFO", 
  16.                    "IDS_STARTUP_CONSOLE_MSG"];
  17.  
  18. for(var n = 0; n < esStrsToExport.length; n++)
  19.     eval(esStrsToExport[n] + " = " + app.getString("EScript", esStrsToExport[n]).toSource());
  20.  
  21. console.println(IDS_STARTUP_CONSOLE_MSG);
  22.  
  23. RE_NUMBER_ENTRY_DOT_SEP = new Array(
  24.     "[+-]?\\d*\\.?\\d*"
  25. );
  26. RE_NUMBER_COMMIT_DOT_SEP = new Array(
  27.     "[+-]?\\d+(\\.\\d+)?",        /* -1.0 or -1 */
  28.     "[+-]?\\.\\d+",                /* -.1 */
  29.     "[+-]?\\d+\\."                /* -1. */
  30. );
  31. RE_NUMBER_ENTRY_COMMA_SEP = new Array(
  32.     "[+-]?\\d*,?\\d*"
  33. );
  34. RE_NUMBER_COMMIT_COMMA_SEP = new Array(
  35.     "[+-]?\\d+([.,]\\d+)?",        /* -1,0 or -1 */
  36.     "[+-]?[.,]\\d+",                /* -,1 */
  37.     "[+-]?\\d+[.,]"                /* -1, */
  38. );
  39. RE_ZIP_ENTRY = new Array(
  40.     "\\d{0,5}"
  41. );
  42. RE_ZIP_COMMIT = new Array(
  43.     "\\d{5}"
  44. );
  45. RE_ZIP4_ENTRY = new Array(
  46.     "\\d{0,5}(\\.|[- ])?\\d{0,4}"
  47. );
  48. RE_ZIP4_COMMIT = new Array(
  49.     "\\d{5}(\\.|[- ])?\\d{4}"
  50. );
  51. RE_PHONE_ENTRY = new Array(
  52.     "\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",        /* 555-1234 or 408 555-1234 */
  53.     "\\(\\d{0,3}",                                            /* (408 */
  54.     "\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* (408) 555-1234 */
  55.         /* (allow the addition of parens as an afterthought) */
  56.     "\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* (408 555-1234 */
  57.     "\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",    /* 408) 555-1234 */
  58.     "011(\\.|[- \\d])*"                                        /* international */
  59. );
  60. RE_PHONE_COMMIT = new Array(
  61.     "\\d{3}(\\.|[- ])?\\d{4}",                            /* 555-1234 */
  62.     "\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",            /* 408 555-1234 */
  63.     "\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}",    /* (408) 555-1234 */
  64.     "011(\\.|[- \\d])*"                                    /* international */
  65. );
  66. RE_SSN_ENTRY = new Array(
  67.     "\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"
  68. );
  69. RE_SSN_COMMIT = new Array(
  70.     "\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"
  71. );
  72.  
  73. /* Function definitions for the color object. */
  74.  
  75. function ColorConvert(oColor, cColorspace)
  76. {    // Converts a color to a specific colorspace.
  77.     var oOut = oColor;
  78.  
  79.     switch (cColorspace) {
  80.         case "G":
  81.             // Note that conversion to the DeviceGray colorspace is lossy in the same
  82.             // way that a color signal on a B/W TV is lossy.
  83.             if (oColor[0] == "RGB")
  84.                 oOut = new Array("G", 0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3]);
  85.             else if (oColor[0] == "CMYK")
  86.                 oOut = new Array("G", 1.0 - Math.min(1.0, 
  87.                     0.3 * oColor[1] + 0.59 * oColor[2] + 0.11 * oColor[3] + oColor[4]));
  88.         break;
  89.         case "RGB":
  90.             if (oColor[0] == "G")
  91.                 oOut = new Array("RGB", oColor[1], oColor[1], oColor[1]);
  92.             else if (oColor[0] == "CMYK")
  93.                 oOut = new Array("RGB", 1.0 - Math.min(1.0, oColor[1] + oColor[4]), 
  94.                     1.0 - Math.min(1.0, oColor[2] + oColor[4]),
  95.                     1.0 - Math.min(1.0, oColor[3] + oColor[4]));
  96.         break;
  97.         case "CMYK":
  98.             if (oColor[0] == "G")
  99.                 oOut = new Array("CMYK", 0, 0, 0, 1.0 - oColor[1]);
  100.             else if (oColor[0] == "RGB")
  101.                 oOut = new Array("CMYK", 1.0 - oColor[1], 1.0 - oColor[2], 1.0 - oColor[3], 0); 
  102.         break;
  103.     }
  104.  
  105.     return oOut;
  106. }
  107.  
  108. function ColorEqual(c1, c2)
  109. {    // Compare two colors. 
  110.     /* The gray colorspace conversion is lossy so we avoid if possible. */
  111.     if (c1[0] == "G")
  112.         c1 = color.convert(c1, c2[0]);
  113.     else
  114.         c2 = color.convert(c2, c1[0]);
  115.  
  116.     /* Colorspace must be equal. */
  117.     if (c1[0] != c2[0])    {
  118.         return false;
  119.     }
  120.  
  121.     /* Compare the individual components. */
  122.     var nComponents = 0;
  123.         
  124.     switch (c1[0]) {
  125.         case "G":
  126.             nComponents = 1;
  127.         break;
  128.         case "RGB":
  129.             nComponents = 3;
  130.         break;
  131.         case "CMYK":
  132.             nComponents = 4;
  133.         break;
  134.     }
  135.  
  136.     for (var i = 1; i <= nComponents; i++) {
  137.         if (c1[i] != c2[i])    {
  138.             return false;
  139.         }
  140.     }
  141.  
  142.     return true;
  143. }
  144.  
  145. /* ==== Convenience Objects ==== */
  146.  
  147. /* Stock color definitions for ease of use. */
  148. color = new Object();
  149. color.equal = ColorEqual;
  150. color.convert = ColorConvert;
  151. color.transparent = new Array("T");
  152. color.black = new Array("G", 0);
  153. color.white = new Array("G", 1);
  154. color.dkGray = new Array("G", 0.25);
  155. color.gray = new Array("G", 0.5);
  156. color.ltGray = new Array("G", 0.75);
  157. color.red = new Array("RGB", 1, 0, 0);
  158. color.green = new Array("RGB", 0, 1, 0);
  159. color.blue = new Array("RGB", 0, 0, 1);
  160. color.cyan = new Array("CMYK", 1, 0, 0, 0);
  161. color.magenta = new Array("CMYK", 0, 1, 0, 0);
  162. color.yellow = new Array("CMYK", 0, 0, 1, 0);
  163.  
  164. /* Font definitions for ease of use */
  165. font = new Object();
  166. font.Times = "Times-Roman";
  167. font.TimesB = "Times-Bold";
  168. font.TimesI = "Times-Italic";
  169. font.TimesBI = "Times-BoldItalic";
  170. font.Helv = "Helvetica";
  171. font.HelvB = "Helvetica-Bold";
  172. font.HelvI = "Helvetica-Oblique";
  173. font.HelvBI = "Helvetica-BoldOblique";
  174. font.Cour = "Courier";
  175. font.CourB = "Courier-Bold";
  176. font.CourI = "Courier-Oblique";
  177. font.CourBI = "Courier-BoldOblique";
  178. font.Symbol = "Symbol";
  179. font.ZapfD = "ZapfDingbats";
  180. font.KaGo = "HeiseiKakuGo-W5-UniJIS-UCS2-H";
  181. font.KaMi = "HeiseiMin-W3-UniJIS-UCS2-H";
  182. font.MyrProRg = "@MyriadPro-Regular";
  183. font.MyrProBd = "@MyriadPro-Bold";
  184. font.MyrProBdIt = "@MyriadPro-BoldIt";
  185. font.MyrProIt = "@MyriadPro-It";
  186. font.MinProRg = "@MinionPro-Regular"
  187. font.MinProBd = "@MinionPro-Bold"
  188. font.MinProBdIt = "@MinionPro-BoldIt"
  189. font.MinProIt = "@MinionPro-It"
  190.  
  191. /* Compatibility with previous version */
  192. font.MyCE = "MyCE";
  193. font.MyCEB = "MyCEB";
  194. font.MiCE = "MiCE";
  195. font.MiCEB = "MiCEB";
  196. font.CourCE = "CourCE";
  197. font.CourCEB = "CourCEB";
  198. font.MiCy = "MiCy";
  199. font.MiCyB = "MiCyB";
  200. font.Gr01 = "Gr01";
  201. font.Tu01 = "Tu01";
  202.  
  203. font.WNMe = "WinSoftNaskhMedium"
  204. font.WNBo = "WinSoftNaskhBold"
  205. font.WTLi = "WinSoftThuluthLight"
  206. font.WTBo = "WinSoftThuluthBold"
  207. font.WSMe = "WinSoftSerifMedium"
  208. font.WSBo = "WinSoftSerifBold"
  209. font.WSSM = "WinSoftSansSerifMedium"
  210.  
  211. /* Font encoding */
  212. subset = new Object();
  213. subset.All = 0;
  214. subset.Roman = 1;
  215. subset.Kanji = 2;
  216. subset.ChineseT = 3;
  217. subset.ChineseS = 4;
  218. subset.Korean = 5;
  219. subset.EastEuropean = 6;
  220. subset.Cyrillic = 7;
  221. subset.Greek = 8;
  222. subset.Turkish = 9;
  223. subset.Arabic = 10;
  224. subset.Hebrew = 11;
  225.  
  226. /* Border style definitions for ease of use */
  227. border = new Object();
  228. border.s = "solid";
  229. border.d = "dashed";
  230. border.b = "beveled";
  231. border.i = "inset";
  232. border.u = "underline";
  233.  
  234. /* Radio/Check button style definitions for ease of use */
  235. style = new Object();
  236. style.ch = "check";
  237. style.cr = "cross";
  238. style.di = "diamond";
  239. style.ci = "circle";
  240. style.st = "star";
  241. style.sq = "square"; 
  242.  
  243. /* highlight modes of on a push button */
  244. highlight = new Object();
  245. highlight.n = "none";
  246. highlight.i = "invert";
  247. highlight.p = "push";
  248. highlight.o = "outline";
  249.  
  250. /* zoom types for a document */
  251. zoomtype = new Object();
  252. zoomtype.none = "NoVary";
  253. zoomtype.fitW = "FitWidth";
  254. zoomtype.fitH = "FitHeight";
  255. zoomtype.fitP = "FitPage";
  256. zoomtype.fitV = "FitVisibleWidth";
  257. zoomtype.pref = "Preferred";
  258.  
  259. /* Cursor behavior in full screen mode. */
  260. cursor = new Object();
  261. cursor.visible = 0;
  262. cursor.hidden = 1;
  263. cursor.delay = 2;
  264.  
  265. /* Transition definitions. */
  266. trans = new Object();
  267. trans.blindsH        = "BlindsHorizontal";
  268. trans.blindsV        = "BlindsVertical";
  269. trans.boxI            = "BoxIn";
  270. trans.boxO            = "BoxOut";
  271. trans.dissolve        = "Dissolve";
  272. trans.glitterD        = "GlitterDown";
  273. trans.glitterR        = "GlitterRight";
  274. trans.glitterRD        = "GlitterRightDown";
  275. trans.random        = "Random";
  276. trans.replace        = "Replace";
  277. trans.splitHI        = "SplitHorizontalIn";
  278. trans.splitHO        = "SplitHorizontalOut";
  279. trans.splitVI        = "SplitVerticalIn";
  280. trans.splitVO        = "SplitVerticalOut";
  281. trans.wipeD            = "WipeDown";
  282. trans.wipeL            = "WipeLeft";
  283. trans.wipeR            = "WipeRight";
  284. trans.wipeU            = "WipeUp";
  285.  
  286. /* Icon/Text placement. */
  287. position = new Object();
  288. position.textOnly    = 0;
  289. position.iconOnly    = 1;
  290. position.iconTextV    = 2;
  291. position.textIconV    = 3;
  292. position.iconTextH    = 4;
  293. position.textIconH    = 5;
  294. position.overlay    = 6;
  295.  
  296. /* When does icon scale. */
  297. scaleWhen = new Object();
  298. scaleWhen.always    = 0;
  299. scaleWhen.never        = 1;
  300. scaleWhen.tooBig    = 2;
  301. scaleWhen.tooSmall    = 3;
  302.  
  303. /* How does icon scale. */
  304. scaleHow = new Object();
  305. scaleHow.proportional    = 0;
  306. scaleHow.anamorphic        = 1;
  307.  
  308.  
  309. /* Field display. */
  310. display = new Object();
  311. display.visible        = 0;
  312. display.hidden        = 1;
  313. display.noPrint        = 2;
  314. display.noView        = 3;
  315.  
  316. /* ==== Functions ==== */
  317.  
  318. /* these may be used a lot -- they are language independent */
  319.  
  320. AFDigitsRegExp = new RegExp();
  321. AFDigitsRegExp.compile("\\d+");
  322. AFPMRegExp = new RegExp();
  323. AFPMRegExp.compile(IDS_PM, "i");
  324. AFAMRegExp = new RegExp();
  325. AFAMRegExp.compile(IDS_AM, "i");
  326. AFTimeLongRegExp = new RegExp();
  327. AFTimeLongRegExp.compile("\\d{1,2}:\\d{1,2}:\\d{1,2}");
  328. AFTimeShortRegExp = new RegExp();
  329. AFTimeShortRegExp.compile("\\d{1,2}:\\d{1,2}");
  330.  
  331. function AFBuildRegExps(array)
  332. /* Takes an array of strings and turns it into an array of compiled regular
  333.  * expressions -- is used for the definitions that follow */
  334. {
  335.     var retVal = new Array();
  336.  
  337.     retVal.length = array.length;
  338.     for(var it = 0; it < array.length; it++)
  339.     {
  340.         retVal[it] = new RegExp();
  341.         retVal[it].compile(array[it], "i");
  342.     }
  343.     return retVal;
  344. }
  345.  
  346. /* these may be used a lot -- they are NOT language independent and are 
  347.  * derived from the localizable (RE_xxx) stuff above */
  348.  
  349. AFNumberDotSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_DOT_SEP);
  350. AFNumberDotSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_DOT_SEP);
  351. AFNumberCommaSepEntryRegExp = AFBuildRegExps(RE_NUMBER_ENTRY_COMMA_SEP);
  352. AFNumberCommaSepCommitRegExp = AFBuildRegExps(RE_NUMBER_COMMIT_COMMA_SEP);
  353. AFZipEntryRegExp = AFBuildRegExps(RE_ZIP_ENTRY);
  354. AFZipCommitRegExp = AFBuildRegExps(RE_ZIP_COMMIT);
  355. AFZip4EntryRegExp = AFBuildRegExps(RE_ZIP4_ENTRY);
  356. AFZip4CommitRegExp = AFBuildRegExps(RE_ZIP4_COMMIT);
  357. AFPhoneEntryRegExp = AFBuildRegExps(RE_PHONE_ENTRY);
  358. AFPhoneCommitRegExp = AFBuildRegExps(RE_PHONE_COMMIT);
  359. AFSSNEntryRegExp = AFBuildRegExps(RE_SSN_ENTRY);
  360. AFSSNCommitRegExp = AFBuildRegExps(RE_SSN_COMMIT);
  361. AFMonthsRegExp = AFBuildRegExps(IDS_MONTH_INFO.split(/\[\d+\]/));
  362.  
  363. function AFExactMatch(rePatterns, sString)
  364. {    /* match a string against an array of RegExps */
  365.     var it;
  366.  
  367.     if(!rePatterns.length && rePatterns.test(sString) && RegExp.lastMatch == sString)
  368.         return true;
  369.     for(it = 0; it < rePatterns.length; it++)
  370.         if(rePatterns[it].test(sString) && RegExp.lastMatch == sString)
  371.             return it + 1;
  372.     return 0;
  373. }
  374.  
  375. function AFExtractNums(string)
  376. {    /* returns an array of numbers that it managed to extract from the given 
  377.      * string or null on failure */
  378.     var nums = new Array();
  379.  
  380.     if (string.charAt(0) == '.' || string.charAt(0) == ',')
  381.         string = "0" + string;
  382.          
  383.     while(AFDigitsRegExp.test(string)) {
  384.         nums.length++;
  385.         nums[nums.length - 1] = RegExp.lastMatch;
  386.         string = RegExp.rightContext;
  387.     }
  388.     if(nums.length >= 1) return nums;
  389.     return null;
  390. }
  391.  
  392. function AFMakeNumber(string)
  393. {    /* attempts to make a number out of a string that may not use '.' as the
  394.      * seperator; it expects that the number is fairly well-behaved other than
  395.      * possibly having a non-JavaScript friendly separator */
  396.     var type = typeof string;
  397.  
  398.     if (type == "number")
  399.         return string;
  400.     if (type != "string")
  401.         return null;
  402.  
  403.     var array = AFExtractNums(string);
  404.  
  405.     if(array)
  406.     {
  407.         var joined = array.join(".");
  408.  
  409.         if (string.indexOf("-.") >= 0)
  410.             joined = "0." + joined;
  411.         return joined * (string.indexOf("-") >= 0 ? -1.0 : 1.0);
  412.     }
  413.     else
  414.         return null;
  415. }
  416.  
  417. function AFExtractRegExp(rePattern, string)
  418. {    /* attempts to match the pattern given against the string given; on 
  419.      * success, returns an array containing (at index 0) the initial
  420.      * string with the matched text removed and (at index 1) the matched
  421.      * text; on failure, returns null */
  422.     var retVal = new Array();
  423.  
  424.     if(rePattern.test(string))
  425.     {
  426.         retVal.length = 2;
  427.         retVal[0] = RegExp.leftContext + RegExp.rightContext;
  428.         retVal[1] = RegExp.lastMatch;
  429.         return retVal;
  430.     }
  431.     return null;
  432. }
  433.  
  434. function AFMakeArrayFromList(string)
  435. {
  436.   var type = typeof string;
  437.  
  438.   if(type == "string")
  439.   {
  440.      var reSep = new RegExp();
  441.     reSep.compile(",[ ]?");
  442.     return string.split(reSep);
  443.   }
  444.   return string;
  445. }
  446.  
  447. function AFExtractTime(string)
  448. {    /* attempts to extract a WELL FORMED time from a string; returned 
  449.      * is an array in the same vein as AFExtractRegExp or null on
  450.      * failure. a WELL FORMED time looks like 12:23:56pm */
  451.     
  452.     var pm = "";
  453.     var info;
  454.  
  455.     info = AFExtractRegExp(AFPMRegExp, string);
  456.     if(info)
  457.     {
  458.         pm = info[1];
  459.         string = info[0];
  460.     }
  461.     info = AFExtractRegExp(AFAMRegExp, string);
  462.     if(info)
  463.     {
  464.         string = info[0];
  465.     }
  466.     info = AFExtractRegExp(AFTimeLongRegExp, string);
  467.     if(info)
  468.     {
  469.         info[1] += pm;
  470.         return info;
  471.     }
  472.     info = AFExtractRegExp(AFTimeShortRegExp, string);
  473.     if(info)
  474.     {
  475.         info[1] += pm;
  476.         return info;
  477.     }
  478.  
  479.     return null;
  480. }
  481.  
  482. function AFGetMonthIndex(string)
  483. {    /* attempts to identify the given string as a month or a valid abbreviation,
  484.      * it expects the given string to be the valid month from the matced RegExp.
  485.      * returns the month index (January = 1) or zero on failure */
  486.     var monthre = new RegExp(string + "\\[(\\d+)\\]", "i");
  487.     var result = monthre.exec(IDS_MONTH_INFO);
  488.     
  489.     if(string && result) return 1.0 * result[1];
  490.     return 0;
  491. }
  492.  
  493. function AFMatchMonth(string)
  494. {    /* attempts to find a valid month embedded in a string; returns the month
  495.      * index (January = 1) or zero on failure */
  496.  
  497.     for(var it = 0; it < AFMonthsRegExp.length; it++)
  498.         if(AFMonthsRegExp[it].test(string))
  499.             return AFGetMonthIndex(RegExp.lastMatch);
  500.     return 0;
  501. }
  502.  
  503. function AFGetMonthString(index)
  504. {    /* returns the string corresponding to the given month or a string that
  505.      * is indicative of the fact that the index was invalid */
  506.     var monthre = new RegExp("(\\w+)\\[" + index + "\\]");
  507.     var result = monthre.exec(IDS_MONTH_INFO);
  508.  
  509.     if(result) return result[1];
  510.     return IDS_INVALID_MONTH;
  511. }
  512.  
  513. function AFParseTime(string, date)
  514. {    /* attempts to parse a string containing a time; returns null on failure
  515.      * or a Date object on success. Time can be in ugly format. */
  516.     var pm, am;
  517.     var nums = AFExtractNums(string);
  518.     if (!date)
  519.         date = new Date();
  520.     var hour, minutes, seconds;
  521.  
  522.     if(!string) return date;
  523.     if(!nums) return null;
  524.     if(nums.length < 2 || nums.length > 3) return null;
  525.     if(AFPMRegExp.test(string)) pm = true;
  526.     else pm = false;
  527.     if(AFAMRegExp.test(string)) am = true;
  528.     else am = false;
  529.     hour = new Number(nums[0]); /* force it to number */
  530.     if(pm)
  531.     {
  532.         if(hour < 12) hour += 12;
  533.     }
  534.     else if (am)
  535.     {
  536.         if(hour >= 12) hour -= 12;
  537.     }
  538.     minutes = nums[1];
  539.     if(nums.length == 3) seconds = nums[2];
  540.     else seconds = 0;
  541.     date.setHours(hour);
  542.     date.setMinutes(minutes);
  543.     date.setSeconds(seconds);
  544.     if(date.getHours() != hour)
  545.         return null;
  546.     if(date.getMinutes() != minutes)
  547.         return null;
  548.     if(date.getSeconds() != seconds)
  549.         return null;
  550.     return date;
  551. }
  552.  
  553. function AFDateFromYMD(nYear, nMonth, nDate)
  554. {    /* Validates the given fields and returns a date based on them */
  555.     var dDate = new Date();
  556.  
  557.     dDate.setFullYear(nYear, nMonth, nDate);
  558.     if(dDate.getFullYear() != nYear)
  559.         return null;
  560.     if(dDate.getMonth() != nMonth)
  561.         return null;
  562.     if(dDate.getDate() != nDate)
  563.         return null;
  564.     return dDate;
  565. }
  566.  
  567. function AFParseDateEx(cString, cOrder)
  568. {    /* Attempts to parse a string containing some form of date; returns null
  569.     ** on failure or a Date object on success. cOrder should be the order in
  570.     ** which the date is entered (e.g. ymd, mdy, etc.). Use AFParseDateOrder to
  571.     ** generate this string from an arbitrary format string. */
  572.     var nYear;
  573.     var nMonth;
  574.     var nDate;
  575.     var nYCount;
  576.     var dDate = new Date();
  577.  
  578.     dDate.setHours(12, 0, 0);
  579.  
  580.     /* Empty string returns current date/time. */
  581.     if (!cString) { 
  582.         return dDate;
  583.     }
  584.  
  585.     nYCount = AFParseDateYCount(cOrder); /* count the number of digits for year in the selected format */
  586.     cOrder = AFParseDateOrder(cOrder); /* make sure its in the "ymd" format */
  587.  
  588.     /* Extract any time information in the string. */
  589.     var info = AFExtractTime(cString);
  590.     if (info)
  591.         cString = info[0];
  592.  
  593.     /* Break down the date into an array of numbers. */
  594.     var aNums = AFExtractNums(cString);
  595.     if(!aNums) 
  596.         return null;    /* No numbers? */
  597.  
  598.     /* User supplied three numbers. */
  599.     if (aNums.length == 3) {
  600.         nYear = 1.0 * aNums[cOrder.indexOf("y")];
  601.         if (nYCount > 2 && nYear < 100)
  602.             return null; /* must enter 4 digits for the year to match with the format of the field */
  603.         nYear = AFDateHorizon(nYear);
  604.  
  605.         dDate = AFDateFromYMD(nYear, aNums[cOrder.indexOf("m")] - 1, aNums[cOrder.indexOf("d")]);
  606.         if (info)
  607.             dDate = AFParseTime(info[1], dDate);
  608.         return dDate;
  609.     }
  610.  
  611.     /* Find text based month, if supplied. */
  612.     nMonth = AFMatchMonth(cString);    
  613.  
  614.     /* User supplied two numbers. */
  615.     if(aNums.length == 2) {
  616.         if (nMonth) {
  617.             /* Easy case, the month was text and we have two numbers. */
  618.             if (cOrder.indexOf("y") < cOrder.indexOf("d")) {
  619.                 nYear = 1.0 * aNums[0];
  620.                 nDate = aNums[1];
  621.             } else {
  622.                 nYear = 1.0 * aNums[1];
  623.                 nDate = aNums[0];
  624.             }
  625.             if (nYCount > 2 && nYear < 100)
  626.                 return null; /* must enter 4 digits for the year to match with the format of the field */
  627.         
  628.             nYear = AFDateHorizon(nYear);
  629.             dDate = AFDateFromYMD(nYear, nMonth - 1, nDate);
  630.  
  631.             if (info)
  632.                 dDate = AFParseTime(info[1], dDate);
  633.             return dDate;
  634.         }
  635.  
  636.         /* More difficult case. We have two numbers and three slots, how
  637.         ** to allocate them? */
  638.         if (cOrder.indexOf("y") < cOrder.indexOf("d"))    {
  639.             /* Year comes before date and as such we allocate the two
  640.             ** numbers to the month and the year only. */
  641.             if (cOrder.indexOf("y") < cOrder.indexOf("m")) {
  642.                 nYear = 1.0 * aNums[0];
  643.                 nMonth = aNums[1];
  644.             } else {
  645.                 nYear = 1.0 * aNums[1];
  646.                 nMonth = aNums[0];
  647.             }
  648.             if (nYCount > 2 && nYear < 100)
  649.                 return null; /* must enter 4 digits for the year to match with the format of the field */
  650.         
  651.             nYear = AFDateHorizon(nYear);
  652.             dDate = AFDateFromYMD(nYear, nMonth - 1, 1);
  653.         } else {
  654.             /* Date comes before year and so we allocate the two numbers
  655.             ** to the date and the month only. */
  656.             nYear = dDate.getFullYear();
  657.             if (cOrder.indexOf("d") < cOrder.indexOf("m")) {
  658.                 dDate = AFDateFromYMD(nYear, aNums[1] - 1, aNums[0]);
  659.             } else {
  660.                 dDate = AFDateFromYMD(nYear, aNums[0] - 1, aNums[1]);
  661.             }
  662.         }
  663.     
  664.         if (info)
  665.             dDate = AFParseTime(info[1], dDate);
  666.         return dDate;
  667.     }
  668.  
  669.     /* User supplied one number. */
  670.     if(aNums.length == 1)    {
  671.         if (nMonth) {
  672.             /* We have one number and two slots (y/d) and need to allocate
  673.             ** them based on who came first in the format. */
  674.             if(cOrder.indexOf("y") < cOrder.indexOf("d")) {
  675.                 nYear = 1.0 * aNums[0];
  676.                 if (nYCount > 2 && nYear < 100)
  677.                     return null; /* must enter 4 digits for the year to match with the format of the field */
  678.             
  679.                 nYear = AFDateHorizon(nYear);
  680.                 dDate = AFDateFromYMD(nYear, nMonth - 1, 1);
  681.             } else {
  682.                 nYear = dDate.getFullYear();
  683.                 dDate = AFDateFromYMD(nYear, nMonth - 1, aNums[0]);
  684.             }
  685.             if (info)
  686.                 dDate = AFParseTime(info[1], date);
  687.             return dDate;
  688.         }
  689.  
  690.         /* We have one number and three slots and need to allocate them
  691.         ** based on who came first in the format. */
  692.         nYear = dDate.getFullYear();
  693.         nMonth = dDate.getMonth();
  694.         nDate = dDate.getDate();
  695.         switch (cOrder.charAt(0)) {
  696.             case "y":
  697.                 nYear = 1.0 * aNums[0];
  698.                 if (nYCount > 2 && nYear < 100)
  699.                     return null; /* must enter 4 digits for the year to match with the format of the field */
  700.             
  701.                 nYear = AFDateHorizon(nYear);
  702.             break;
  703.             case "m":
  704.                 nMonth = aNums[0] - 1;
  705.             break;
  706.             case "d":
  707.                 nDate = aNums[0];
  708.             break;
  709.         }
  710.         dDate = AFDateFromYMD(nYear, nMonth, nDate);
  711.  
  712.  
  713.         if (info)
  714.             dDate = AFParseTime(info[1], date);
  715.         return dDate;
  716.     }
  717.  
  718.     /* No idea how to deal with the other combinations. */
  719.     return null;
  720. }
  721.  
  722. function AFDateHorizon(nYear)
  723. {    /* Takes the year supplied and applies the date horizon heuristic.
  724.     ** All years between 50 and 100 we add 1900. All years less than 50 we add 2000. */
  725.     if (nYear < 100 && nYear >= 50) {
  726.         nYear += 1900;
  727.     } else if (nYear >= 0 && nYear < 50) {
  728.         nYear += 2000;
  729.     }
  730.  
  731.     return nYear;
  732. }
  733.  
  734. function AFParseDate(string, longEntry, shortEntry, wordMonthEntry, monthYearEntry)
  735. {    /* OBSOLETE: Use AFParseDateEx instead. */
  736.     var nums;
  737.     var year, month;
  738.     var date;
  739.     var info = AFExtractTime(string);
  740.  
  741.     if(!string) return new Date();
  742.  
  743.     if(info)
  744.         string = info[0];
  745.  
  746.     date = new Date();
  747.     nums = AFExtractNums(string);
  748.     if(!nums) return null;
  749.     if(nums.length == 3)
  750.     {
  751.         year = 1.0 * nums[eval(longEntry.charAt(0))];
  752.         year = AFDateHorizon(year);
  753.         date = AFDateFromYMD(year, nums[eval(longEntry.charAt(1))] - 1, nums[eval(longEntry.charAt(2))]);
  754.         if (info)
  755.             date = AFParseTime(info[1], date);
  756.         return date;
  757.     }
  758.     month = AFMatchMonth(string);
  759.     if(nums.length == 2)
  760.     {
  761.         if(month)
  762.         {
  763.             year = 1.0 * nums[eval(wordMonthEntry.charAt(0))];
  764.             year = AFDateHorizon(year);
  765.             date = AFDateFromYMD(year, month - 1, nums[eval(wordMonthEntry.charAt(1))]);
  766.             if (info)
  767.                 date = AFParseTime(info[1], date);
  768.             return date;
  769.         }
  770.         if(monthYearEntry)
  771.         {
  772.             year = 1.0 * nums[eval(monthYearEntry.charAt(0))];
  773.             year = AFDateHorizon(year);
  774.             date = AFDateFromYMD(year, nums[eval(monthYearEntry.charAt(1))] - 1, 1);
  775.         }
  776.         else
  777.             date = AFDateFromYMD(date.getFullYear(),
  778.                 nums[eval(shortEntry.charAt(0))] - 1,
  779.                 nums[eval(shortEntry.charAt(1))]);
  780.         if (info)
  781.             date = AFParseTime(info[1], date);
  782.         return date;
  783.     }
  784.     if(month && nums.length == 1)
  785.     {
  786.         if(monthYearEntry)
  787.         {
  788.             year = 1.0 * nums[0];
  789.             year = AFDateHorizon(year);
  790.             date = AFDateFromYMD(year, month - 1, 1);
  791.         }
  792.         else
  793.             date = AFDateFromYMD(date.getFullYear(), month - 1,    nums[0]);
  794.         if (info)
  795.             date = AFParseTime(info[1], date);
  796.         return date;
  797.     }
  798.  
  799.     return null;
  800. }
  801.  
  802. function AFParseDateWithPDF(value, pdf)
  803. { /* OBSOLETE: Use AFParseDateEx instead. */
  804.     var cOldFormats = new Array(
  805.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  806.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  807.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  808.    
  809.     return AFParseDateEx(value, cOldFormats[pdf]);
  810. }
  811.  
  812. function AFMergeChange(event)
  813. {    /* merges the last change with the uncommitted change */
  814.     var prefix, postfix;
  815.     var value = event.value;
  816.  
  817.     if(event.willCommit) return event.value;
  818.     if(event.selStart >= 0)
  819.         prefix = value.substring(0, event.selStart);
  820.     else prefix = "";
  821.     if(event.selEnd >= 0 && event.selEnd <= value.length)
  822.         postfix = value.substring(event.selEnd, value.length);
  823.     else postfix = "";
  824.     return prefix + event.change + postfix;
  825. }
  826.  
  827. function AFRange_Validate(bGreaterThan, nGreaterThan, bLessThan, nLessThan)
  828. {       /* This function validates the current event to ensure that its value is 
  829.     ** within the specified range. */
  830.     var cError = "";
  831.  
  832.     if (event.value == "")
  833.         return;
  834.  
  835.     if (bGreaterThan && bLessThan) {
  836.         if (event.value < nGreaterThan || event.value > nLessThan)
  837.             cError = util.printf(IDS_GT_AND_LT, nGreaterThan, nLessThan);
  838.     } else if (bGreaterThan) {
  839.         if (event.value < nGreaterThan)
  840.             cError = util.printf(IDS_GREATER_THAN, nGreaterThan);
  841.     } else if (bLessThan) {
  842.         if (event.value > nLessThan)
  843.             cError = util.printf(IDS_LESS_THAN, nLessThan);
  844.     }
  845.     
  846.     if (cError != "") {
  847.         app.alert(cError, 0);
  848.         event.rc = false;
  849.     }
  850. }
  851.  
  852. function AFSimpleInit(cFunction)
  853. {    /* Convenience function used by AFSimple_Calculate. */
  854.     switch (cFunction)
  855.     {
  856.         case "PRD":
  857.             return 1.0;
  858.             break;
  859.     }
  860.  
  861.     return 0.0;
  862. }
  863.  
  864. function AFSimple(cFunction, nValue1, nValue2)
  865. {    /* Convenience function used by AFSimple_Calculate. */
  866.     var nValue = 1.0 * nValue1;
  867.  
  868.     /* Have to do this otherwise JavaScript thinks it's dealing with strings. */
  869.     nValue1 = 1.0 * nValue1;
  870.     nValue2 = 1.0 * nValue2;
  871.  
  872.     switch (cFunction)
  873.     {
  874.         case "AVG":
  875.         case "SUM":
  876.             nValue = nValue1 + nValue2;
  877.             break;
  878.         case "PRD":
  879.             nValue = nValue1 * nValue2;
  880.             break;
  881.         case "MIN":
  882.             nValue = Math.min(nValue1,nValue2);
  883.             break;
  884.         case "MAX":
  885.             nValue = Math.max(nValue1, nValue2);
  886.             break;
  887.     }
  888.  
  889.     return nValue;
  890. }
  891.  
  892. function AFSimple_Calculate(cFunction, cFields)
  893. {   /* Calculates the sum, average, product, etc. of the listed field values. */
  894.     var nFields = 0;
  895.     var nValue = AFSimpleInit(cFunction);
  896.  
  897.     /* Field name separator is one or more spaces followed by a comma, 
  898.     ** followed by one or more spaces.
  899.     ** or an array of field names */
  900.      var aFields = AFMakeArrayFromList(cFields);
  901.  
  902.     for (var i = 0; i < aFields.length; i++) {
  903.         /* Found a field, process it's value. */
  904.         var f = this.getField(aFields[i]);
  905.         var a = f.getArray();
  906.  
  907.         for (var j = 0; j < a.length; j++) {
  908.             var nTemp = AFMakeNumber(a[j].value); 
  909.             if (i == 0 && j == 0 && (cFunction == "MIN" || cFunction == "MAX"))
  910.                 nValue = nTemp;
  911.             nValue = AFSimple(cFunction, nValue, nTemp);
  912.             nFields++;
  913.         }
  914.     }
  915.  
  916.     if (cFunction == "AVG" && nFields > 0)
  917.         nValue /= nFields;
  918.  
  919.     event.value = nValue;
  920. }
  921.  
  922. function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  923. {       /* This function validates the current keystroke event to make sure the
  924.         key pressed is reasonable for a numeric field. */
  925.  
  926.     var value = AFMergeChange(event);
  927.     var commit, noCommit;
  928.  
  929.     if(!value) return;
  930.     if(sepStyle > 1)
  931.     {
  932.         commit = AFNumberCommaSepCommitRegExp;
  933.         noCommit = AFNumberCommaSepEntryRegExp;
  934.     }
  935.     else
  936.     {
  937.         commit = AFNumberDotSepCommitRegExp;
  938.         noCommit = AFNumberDotSepEntryRegExp;
  939.     }
  940.     if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
  941.     {
  942.         if (event.willCommit) {
  943.             var cAlert = IDS_INVALID_VALUE;
  944.             if (event.target != null)
  945.                 cAlert += " [ " + event.target.name + " ]";
  946.             app.alert(cAlert);
  947.         }
  948.         else
  949.             app.beep(0);
  950.         event.rc = false;
  951.     }
  952. }
  953.  
  954. function AFPercent_Keystroke(nDec, sepStyle)
  955. {
  956.         AFNumber_Keystroke(nDec, sepStyle, 0, 0, "", true);
  957. }
  958.  
  959. function AFSpecial_Keystroke(psf)
  960. {       /* This function validates the current keystroke event to make sure the
  961.         key pressed is reasonable for a "special" field. */
  962.         
  963.     /* The special formats, indicated by psf, are:
  964.     
  965.     psf             format
  966.     ---             ------
  967.     0               zip code
  968.     1               zip + 4
  969.     2               phone
  970.     3                SSN
  971.     
  972.     */
  973.  
  974.     var value = AFMergeChange(event);
  975.     var commit, noCommit;
  976.  
  977.     if(!value) return;
  978.     switch (psf)
  979.     {
  980.         case 0:
  981.             commit = AFZipCommitRegExp;
  982.             noCommit = AFZipEntryRegExp;
  983.             break;
  984.         case 1:
  985.             commit = AFZip4CommitRegExp;
  986.             noCommit = AFZip4EntryRegExp;
  987.             break;
  988.         case 2:
  989.             commit = AFPhoneCommitRegExp;
  990.             noCommit = AFPhoneEntryRegExp;
  991.             break;
  992.         case 3:
  993.             commit = AFSSNCommitRegExp;
  994.             noCommit = AFSSNEntryRegExp;
  995.             break;
  996.     }        
  997.     if(!AFExactMatch(event.willCommit ? commit : noCommit, value))
  998.     {
  999.         if (event.willCommit) {
  1000.             var cAlert = IDS_INVALID_VALUE;
  1001.             if (event.target != null)
  1002.                 cAlert += " [ " + event.target.name + " ]";
  1003.             app.alert(cAlert);
  1004.         }
  1005.         else
  1006.             app.beep(0);
  1007.         event.rc = false;
  1008.     }
  1009. }
  1010.  
  1011. function AFDate_KeystrokeEx(cFormat)
  1012. {    /* This function validates the current keystroke event to make sure the
  1013.     ** key pressed is reasonable for a date field. */
  1014.     if(event.willCommit && !AFParseDateEx(AFMergeChange(event), cFormat)) {
  1015.         /* Dates are only validated on commit */
  1016.         if (event.willCommit) {
  1017.             var cAlert = IDS_INVALID_DATE;
  1018.             if (event.target != null)
  1019.                 cAlert += " [ " + event.target.name + " ]";
  1020.             app.alert(cAlert);
  1021.         }
  1022.         else
  1023.             app.beep(0);
  1024.         event.rc = false;
  1025.     }
  1026. }
  1027.  
  1028. function AFDate_Keystroke(pdf)
  1029. {    /* OBSOLETE: Use AFDate_KeystrokeEx. */
  1030.     var cOldFormats = new Array(
  1031.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  1032.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  1033.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  1034.  
  1035.     AFDate_KeystrokeEx(cOldFormats[pdf]);
  1036. }
  1037.  
  1038. function AFTime_Keystroke(ptf)
  1039. {    /* This function validates the current keystroke event to make sure the
  1040.     key pressed is reasonable for a time field. */
  1041.  
  1042.     if(event.willCommit && !AFParseTime(event.value, null))
  1043.                     /* times are only validated on commit */
  1044.     {
  1045.         if (event.willCommit) {
  1046.             var cAlert = IDS_INVALID_VALUE;
  1047.             if (event.target != null)
  1048.                 cAlert += " [ " + event.target.name + " ]";
  1049.             app.alert(cAlert);
  1050.         }
  1051.         else
  1052.             app.beep(0);
  1053.         event.rc = false;
  1054.     }
  1055. }
  1056.  
  1057. function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  1058. {       /* This function formats a numeric value according to the parameters. */
  1059.  
  1060.     var value = AFMakeNumber(event.value);
  1061.     var sign = (value < 0 ? -1 : 1);
  1062.     var f = event.target;
  1063.  
  1064.     if(value == null)
  1065.     {
  1066.         event.value = "";
  1067.         return;
  1068.     }    
  1069.     if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
  1070.         var formatStr = "(";
  1071.     else 
  1072.         var formatStr = "";
  1073.     
  1074.     if (bCurrencyPrepend)
  1075.         formatStr = formatStr + strCurrency;
  1076.         
  1077.     formatStr = formatStr + "%," + sepStyle + "." + nDec + "f";
  1078.     if (! bCurrencyPrepend)
  1079.         formatStr = formatStr + strCurrency;
  1080.         
  1081.     if ((negStyle == 2 /* ParensBlack */ || negStyle == 3 /* ParensRed */) && value < 0)
  1082.         formatStr = formatStr + ")";
  1083.  
  1084.     if (negStyle != 0 /* MinusBlack */ || bCurrencyPrepend)
  1085.         value = Math.abs(value);
  1086.         
  1087.     if (negStyle == 1 /* Red */ || negStyle == 3 /* ParensRed */) {
  1088.         if (sign > 0 )
  1089.             f.textColor = color.black;
  1090.         else 
  1091.             f.textColor = color.red;
  1092.     }
  1093.  
  1094.     var tmp = util.printf(formatStr, value);
  1095.     if (sign < 0 && bCurrencyPrepend && negStyle == 0)
  1096.         tmp = '-' + tmp; /* prepend the -ve sign */
  1097.     event.value = tmp;
  1098. }
  1099.  
  1100. function AFPercent_Format(nDec, sepStyle)
  1101. {       /* This function formats a percentage value according to the parameters. */
  1102.  
  1103.     var value = AFMakeNumber(event.value) * 100;
  1104.     
  1105.     var formatStr = "%," + sepStyle + "." + nDec + "f";
  1106.         
  1107.     if(value == null)
  1108.     {
  1109.         event.value = "";
  1110.         return;
  1111.     }    
  1112.  
  1113.     value = util.printf(formatStr, value);
  1114.     
  1115.     event.value = value + "%";
  1116. }
  1117.  
  1118. function AFSpecial_Format(psf)
  1119. {   /* This function formats a "special" value according to the "PropsSpecialFormat" parameter psf. */
  1120.     /* The special formats, indicated by psf, are: 0 = zip code, 1 = zip + 4, 2 = phone, 3 = SSN. */
  1121.     var value = event.value;
  1122.  
  1123.     if(!value) return;    
  1124.     switch (psf) {
  1125.     
  1126.         case 0:                         
  1127.             var formatStr = "99999";
  1128.             break;
  1129.         case 1:                         
  1130.             var formatStr = "99999-9999";
  1131.             break;
  1132.         case 2:                         /* must distinguish between 2 styles: with and without area code */
  1133.             var NumbersStr = util.printx("9999999999", value);      /* try to suck out 10 numeric chars */
  1134.             if (NumbersStr.length >= 10 )
  1135.                 var formatStr = "(999) 999-9999";
  1136.             else 
  1137.                 var formatStr = "999-9999";
  1138.             break;
  1139.         case 3:
  1140.             var formatStr = "999-99-9999";
  1141.             break;
  1142.     }
  1143.         
  1144.     event.value = util.printx(formatStr, value);
  1145. }
  1146.  
  1147. function AFParseDateYCount(cFormat)
  1148. {
  1149.     /* Determine the order of the date. */
  1150.     var yCount = 0;
  1151.     for (var i = 0; i < cFormat.length; i++) {
  1152.         switch (cFormat.charAt(i)) {
  1153.             case "\\":    /* Escape character. */
  1154.                 i++;
  1155.             break;
  1156.             case "y":
  1157.                 yCount += 1;
  1158.             break;
  1159.         }
  1160.     }
  1161.     return yCount;
  1162. }
  1163.  
  1164. function AFParseDateOrder(cFormat)
  1165. {
  1166.     /* Determine the order of the date. */
  1167.     var cOrder = "";
  1168.     for (var i = 0; i < cFormat.length; i++) {
  1169.         switch (cFormat.charAt(i)) {
  1170.             case "\\":    /* Escape character. */
  1171.                 i++;
  1172.             break;
  1173.             case "m":
  1174.                 if (cOrder.indexOf("m") == -1)
  1175.                     cOrder += "m";
  1176.             break;
  1177.             case "d":
  1178.                 if (cOrder.indexOf("d") == -1)
  1179.                     cOrder += "d";
  1180.             break;
  1181.             case "y":
  1182.                 if (cOrder.indexOf("y") == -1)
  1183.                     cOrder += "y";
  1184.             break;
  1185.         }
  1186.     }
  1187.  
  1188.     /* Make sure we have a full complement of 3 chars. */
  1189.     if (cOrder.indexOf("m") == -1)
  1190.         cOrder += "m";
  1191.     if (cOrder.indexOf("d") == -1)
  1192.         cOrder += "d";
  1193.     if (cOrder.indexOf("y") == -1)
  1194.         cOrder += "y";
  1195.  
  1196.     return cOrder;
  1197. }
  1198.  
  1199. function AFDate_FormatEx(cFormat)
  1200. {    /* cFormat is a format string with which the date is to be formatted. */
  1201.     if (!event.value) 
  1202.         return;    /* Blank fields remain blank */
  1203.  
  1204.     var date = AFParseDateEx(event.value, cFormat);
  1205.     if (!date) {
  1206.         event.value = "";
  1207.         return;
  1208.     }
  1209.     
  1210.     event.value = util.printd(cFormat, date);
  1211. }
  1212.  
  1213. function AFDate_Format(pdf)
  1214. {    /* OBSOLETE: Use AFDate_FormatEx. */
  1215.     var cOldFormats = new Array(
  1216.         "m/d", "m/d/yy", "mm/dd/yy", "mm/yy", "d-mmm", "d-mmm-yy", "dd-mmm-yy",
  1217.         "yy-mm-dd", "mmm-yy", "mmmm-yy", "mmm d, yyyy", "mmmm d, yyyy",
  1218.         "m/d/yy h:MM tt", "m/d/yy HH:MM" );
  1219.  
  1220.     AFDate_FormatEx(cOldFormats[pdf]);
  1221. }
  1222.  
  1223. function AFTime_Format(ptf)
  1224. {    /* This function formats a time value according to the "PropsTimeFormat" parameter ptf.
  1225.     ** The time formats, indicated by ptf, are:
  1226.     ** ptf             format                                                          
  1227.     ** ---             ------                                                          
  1228.     ** 0               PTF_24HR_MM     [ 14:30      ]
  1229.     ** 1               PTF_12HR_MM     [ 2:30 PM    ]
  1230.     ** 2               PTF_24HR_MM_SS  [ 14:30:15   ]
  1231.     ** 3               PTF_12HR_MM_SS  [ 2:30:15 PM ] */
  1232.  
  1233.     if(!event.value) return;    /* Blank fields remain blank */
  1234.  
  1235.     var date = new AFParseTime(event.value, null);
  1236.     if(!date) {
  1237.         event.value = "";
  1238.         return;
  1239.     }
  1240.  
  1241.     var cFormats = new Array(
  1242.         "HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt" ); 
  1243.     
  1244.     event.value = util.printd(cFormats[ptf], date);
  1245. }
  1246.  
  1247. function AFSignatureLock(doc, cOperation, cFields, bLock)
  1248. {    // Locks or unlocks a set of fields according to the specified operation.
  1249.     /* Field name separator is one or more spaces followed by a comma, 
  1250.     ** followed by one or more spaces.
  1251.     ** or an array of field names */
  1252.      var aFields = AFMakeArrayFromList(cFields);
  1253.  
  1254.     /* Three cases: ALL, EXCEPT, THESE for the field name list. */
  1255.     if (cOperation != "THESE") {
  1256.         for (var i = 0; i < doc.numFields; i++) {
  1257.             var f = doc.getField(doc.getNthFieldName(i));
  1258.                 
  1259.             f.readonly = bLock;
  1260.          }
  1261.     }
  1262.     
  1263.     if (cOperation == "EXCEPT")
  1264.         /* EXCEPT = ALL(lock) then THESE(unlock) */
  1265.         bLock = !bLock;
  1266.  
  1267.     if (cOperation == "THESE" || (cOperation == "EXCEPT" && !bLock)) {
  1268.         for (var i = 0; i < aFields.length; i++) {
  1269.             var f = doc.getField(aFields[i]);
  1270.             var a = f.getArray();
  1271.  
  1272.             for (var j = 0; j < a.length; j++) {
  1273.                 a[j].readonly = bLock;
  1274.             }
  1275.         }
  1276.     }
  1277. }
  1278.  
  1279. function AFSignature_Format(cOperation, cFields)
  1280. {    /* This function is invoked at format time but really is used to lock fields
  1281.     ** in the document. We unlock all the specified fields if the value is
  1282.     ** null (which means the signature hasn't been applied). */
  1283.  
  1284.     var bLock = (event.value != "");
  1285.  
  1286.     AFSignatureLock(this, cOperation, cFields, bLock);
  1287. }
  1288.