home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / ccDate.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  23.8 KB  |  755 lines

  1.  
  2. //
  3. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved. 
  4. //
  5. // ----------------------------------------------------
  6. //
  7. // Date.js
  8. //
  9. //This object inserts the current date and optionally time
  10. //and day at the current insertion point. An Update Automatically
  11. //On Save Option will update the date when the document is saved.
  12. //
  13. //
  14. //Localization Note:
  15. //Read the comments in the initGlobals function for instructions
  16. //on controlling the order of the date formats in the Date Format list,
  17. //as well as specifying that certain date formats should not appear
  18. //in a localized language.
  19.  
  20.  
  21.  
  22. //*********************GLOBAL VARIABLES***********************
  23.  
  24. //see initGlobals for info on global vars
  25.  
  26. var helpDoc = MM.HELP_objDate;
  27.  
  28. //global arrays
  29. var GarrDateFormats; 
  30. var GarrDayFormats;
  31. var GarrTimeFormats;
  32.  
  33. //form element objects
  34. var GlistDateFormats;
  35. var GselDayFormats;
  36. var GselTimeFormats;
  37. var GcbUpdate;
  38.  
  39. //global strings needed for accessor functions
  40. var GstrFullDate;
  41. var GstrHTMLFullDate;
  42. var GstrDateID;
  43.  
  44. function initGlobals(){
  45.  
  46.     //The GarrDateFormats array controls the order the date formats are shown in the UI
  47.     //The list of formats is in Date.htm
  48.     GarrDateFormats = LIST_DateFormats;
  49.  
  50.     //The GarrDateFormats array controls the order the day formats are shown in the UI
  51.     //The list of formats is in Date.htm
  52.     GarrDayFormats  =  LIST_DayFormats;
  53.  
  54.     //The GarrTimeFormats array controls the order of the time formats.
  55.     //The list of formats is in Date.htm
  56.     GarrTimeFormats =  LIST_TimeFormats;
  57.  
  58.  
  59.  
  60.    //-----------------------------------------------------------------------------
  61.    
  62.    //initialize global form elements
  63.    theForm = document.forms[0]; 
  64.    GlistDateFormats = theForm.DateFormats;
  65.    GselDayFormats   = theForm.DayFormats;
  66.    GselTimeFormats  = theForm.TimeFormats;
  67.    GcbUpdate        = theForm.Update;
  68. }
  69.  
  70. function charToEntity(thechar,charCode)
  71. {
  72.     switch(thechar) {
  73.         case '\x80' :         return "€";
  74.         case '\xA1' :         return "¡";
  75.         case '\xA2' :         return "¢";
  76.         case '\xA3' :         return "£";
  77.         case '\xA4' :         return "¤";
  78.         case '\xA5' :         return "¥";
  79.         case '\xA6' :         return "¦";
  80.         case '\xA7' :         return "§";
  81.         case '\xA8' :         return "¨";
  82.         case '\xA9' :         return "©";
  83.         case '\xAA' :         return "ª";
  84.         case '\xAB' :         return "«";
  85.         case '\xAC' :         return "¬";
  86.         case '\xAD' :         return "­";
  87.         case '\xAE' :         return "®";
  88.         case '\xAF' :         return "¯";
  89.         case '\xB0' :         return "°";
  90.         case '\xB1' :         return "±";
  91.         case '\xB2' :         return "²";
  92.         case '\xB3' :         return "³";
  93.         case '\xB4' :         return "´";
  94.         case '\xB5' :         return "µ";
  95.         case '\xB6' :         return "¶";
  96.         case '\xB7' :         return "·";
  97.         case '\xB8' :         return "¸";
  98.         case '\xB9' :         return "¹";
  99.         case '\xBA' :         return "º";
  100.         case '\xBB' :         return "»";
  101.         case '\xBC' :         return "¼";
  102.         case '\xBD' :         return "½";
  103.         case '\xBE' :         return "¾";
  104.         case '\xBF' :         return "¿";
  105.         case '\xD7' :         return "×";
  106.         case '\xF7' :         return "÷";
  107.         case '\xC6' :         return "Æ";
  108.         case '\xC1' :         return "Á";
  109.         case '\xC2' :         return "Â";
  110.         case '\xC0' :         return "À";
  111.         case '\xC5' :         return "Å";
  112.         case '\xC3' :         return "Ã";
  113.         case '\xC4' :         return "Ä";
  114.         case '\xC7' :         return "Ç";
  115.         case '\xD0' :         return "Ð";
  116.         case '\xC9' :         return "É";
  117.         case '\xCA' :         return "Ê";
  118.         case '\xC8' :         return "È";
  119.         case '\xCB' :         return "Ë";
  120.         case '\xCD' :         return "Í";
  121.         case '\xCE' :         return "Î";
  122.         case '\xCC' :         return "Ì";
  123.         case '\xCF' :         return "Ï";
  124.         case '\xD1' :         return "Ñ";
  125.         case '\xD3' :         return "Ó";
  126.         case '\xD4' :         return "Ô";
  127.         case '\xD2' :         return "Ò";
  128.         case '\xD8' :         return "Ø";
  129.         case '\xD5' :         return "Õ";
  130.         case '\xD6' :         return "Ö";
  131.         case '\xDE' :         return "Þ";
  132.         case '\xDA' :         return "Ú";
  133.         case '\xDB' :         return "Û";
  134.         case '\xD9' :         return "Ù";
  135.         case '\xDC' :         return "Ü";
  136.         case '\xDD' :         return "Ý";
  137.         case '\xE1' :         return "á";
  138.         case '\xE2' :         return "â";
  139.         case '\xE6' :         return "æ";
  140.         case '\xE0' :         return "à";
  141.         case '\xE5' :         return "å";
  142.         case '\xE3' :         return "ã";
  143.         case '\xE4' :         return "ä";
  144.         case '\xE7' :         return "ç";
  145.         case '\xE9' :         return "é";
  146.         case '\xEA' :         return "ê";
  147.         case '\xE8' :         return "è";
  148.         case '\xF0' :         return "ð";
  149.         case '\xEB' :         return "ë";
  150.         case '\xED' :         return "í";
  151.         case '\xEE' :         return "î";
  152.         case '\xEC' :         return "ì";
  153.         case '\xEF' :         return "ï";
  154.         case '\xF1' :         return "ñ";
  155.         case '\xF3' :         return "ó";
  156.         case '\xF4' :         return "ô";
  157.         case '\xF2' :         return "ò";
  158.         case '\xF8' :         return "ø";
  159.         case '\xF5' :         return "õ";
  160.         case '\xF6' :         return "ö";
  161.         case '\xDF' :         return "ß";
  162.         case '\xFE' :         return "þ";
  163.         case '\xFA' :         return "ú";
  164.         case '\xFB' :         return "û";
  165.         case '\xF9' :         return "ù";
  166.         case '\xFC' :         return "ü";
  167.         case '\xFD' :         return "ý";
  168.         case '\xFF' :         return "ÿ";
  169.  
  170.     }
  171.     if (charCode > 128)
  172.         return('&#' + parseInt(charCode) + ';');
  173.     else
  174.         return(thechar);
  175. }
  176.  
  177.  
  178. function entityNameEncode(string)
  179. {
  180.     //latin1Str = dreamweaver.nativeToLatin1(string);
  181.     latin1Str = string;
  182.     returnString = new String();
  183.     for (i=0;i<latin1Str.length;i++) {
  184.         returnString += charToEntity(latin1Str.charAt(i),latin1Str.charCodeAt(i));
  185.     }
  186.     return(returnString);
  187. }
  188.  
  189. //*********************** API ***********************
  190.  
  191. function isDOMRequired() { 
  192.     // Return false, indicating that this command is available in code view.
  193.     return false;
  194. }
  195.  
  196. //function: commandButtons
  197. //description: generic API function, returns string to be inserted at IP
  198.  
  199. function commandButtons(){
  200.  /*  return new Array(MM.BTN_OK,         "setDateStr();window.close()",
  201.                     MM.BTN_Cancel,     "window.close()",
  202.                     MM.BTN_Help,       "displayHelp()"    );
  203. */
  204.  
  205.     return new Array( "PutButtonsOnBottom",
  206.                          "OkButton", MM.BTN_OK,     "setDateStr();window.close()", 
  207.                          "CancelButton", MM.BTN_Cancel,  "window.close()",
  208.                          "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()");
  209.  
  210.  
  211. }
  212.  
  213. //***********************ACCESSOR FUNCTIONS***********************
  214.  
  215. function getDateStr(){
  216.    return GstrFullDate;
  217. }
  218.  
  219. function getDateID(){
  220.    return GstrDateID;
  221. }
  222.  
  223. function getHTMLDateStr(){
  224.    return GstrHTMLFullDate;
  225. }
  226.  
  227. //***********************LOCAL FUNCTIONS***********************
  228.  
  229. //function: setDateStr
  230. //description: called from OK button of dialog,
  231. //sets the global GstrFullDate variable
  232.  
  233. function setDateStr(){
  234.     var dateStr = "";
  235.     var dateStrHTML = "";
  236.     var dateID = "";
  237.     var now = new Date();
  238.     
  239.     var dayFormat  = getSelectedOptionAttr(GselDayFormats,"value");
  240.     var dateFormat = getSelectedOptionAttr(GlistDateFormats,"value");
  241.     var timeFormat = getSelectedOptionAttr(GselTimeFormats,"value");        
  242.     
  243.     //create the date that is inserted
  244.     //if selected a Japanese date format in J version of Dreamweaver, concatenate in order of
  245.     //date, day, time
  246.     if ((dateFormat.indexOf("Japan") == 0 || dateFormat.indexOf("Korean") == 0 || dateFormat.indexOf("Chinese") == 0) && (dreamweaver.appVersion.indexOf('ja') != -1 || dreamweaver.appVersion.indexOf('ko') != -1 || dreamweaver.appVersion.indexOf('zh') != -1)) {
  247.         dateStr += createDateStr(now,dateFormat,true);
  248.         dateStr += " " + createDayStr(now,dayFormat,dateFormat,false,true);
  249.         // we don't want a comma at the end of Western days if it appears within an Asian date format
  250.         if (dayFormat == "WestFullDayComma" || dayFormat == "WestAbbrDayComma")
  251.             dateStr = dateStr.substring(0, dateStr.length-2) + " ";
  252.         dateStr += createTimeStr(now,timeFormat);
  253.         dateStrHTML += createDateStr(now,dateFormat,true);
  254.         dateStrHTML += " " + createDayStr(now,dayFormat,dateFormat,false,true);
  255.         // we don't want a comma at the end of Western days if it appears within an Asian date format
  256.         if (dayFormat == "WestFullDayComma" || dayFormat == "WestAbbrDayComma")
  257.             dateStrHTML = dateStrHTML.substring(0, dateStrHTML.length-2) + " ";
  258.         dateStrHTML += createTimeStr(now,timeFormat);
  259.     }
  260.     else
  261.     {
  262.         dateStr += createDayStr(now,dayFormat,dateFormat,false,true);
  263.         dateStr += createDateStr(now,dateFormat,true);
  264.         dateStr += createTimeStr(now,timeFormat);
  265.         // we don't want to encode for J or K or C day formats
  266.         if (dreamweaver.appVersion && (dreamweaver.appVersion.indexOf('ja') != -1 || dreamweaver.appVersion.indexOf('ko') != -1 || dreamweaver.appVersion.indexOf('zh') != -1) )
  267.             dateStrHTML += createDayStr(now,dayFormat,dateFormat,false,true);
  268.         else
  269.             dateStrHTML += createDayStr(now,dayFormat,dateFormat,false,false);
  270.         dateStrHTML += createDateStr(now,dateFormat,false);
  271.         dateStrHTML += createTimeStr(now,timeFormat);
  272.     }
  273.     
  274.     //dateID is inserted into the format attribute of the lock
  275.     //and also placed in the opening comment
  276.     dateID = createDateID(dayFormat,dateFormat,timeFormat);
  277.     
  278.     //if Update Automatically On Save is visible and checked,
  279.     //add locks around the date
  280.     if (GcbUpdate!=null && GcbUpdate.checked){
  281.        dateStr = addLockMarkup(dateStr,dateID);  
  282.        dateStrHTML = addLockMarkup(dateStrHTML,dateID);   
  283.     }
  284.     
  285.     //assign to global variables accessed by accessor functions
  286.     GstrFullDate = dateStr;
  287.     GstrHTMLFullDate = dateStrHTML;
  288.     GstrDateID = dateID;  
  289. }
  290.  
  291.  
  292.  
  293. //function: addLockMarkup
  294. //description: adds correct lock markup to the date that is 
  295. //inserted
  296.  
  297. function  addLockMarkup(dateStr,dateID){
  298.  
  299.    var openBracket = "%3C";
  300.    var closeBracket = "%3E";
  301.    var quote = "%22";
  302.  
  303.    var openComment = openBracket + '!-- #BeginDate ' +
  304.                      'format:' + dateID + ' --' + closeBracket;
  305.    var closeComment = openBracket + '!-- #EndDate --' + closeBracket;
  306.    var origAttr = openComment + dateStr + closeComment;
  307.    
  308.    var openLock = '<MM:BeginLock type="mmdate" format="' + dateID + 
  309.                   '" orig="' + origAttr + '">';
  310.    var closeLock =  '<MM:EndLock>';
  311.    
  312.    return openLock +  dateStr + closeLock;
  313. }
  314.  
  315.  
  316.  
  317. //function: initializeUI
  318. //description: initializes the global variables, and populates
  319. //the UI with date format examples.
  320.  
  321. function initializeUI(){
  322.    //return if already initialized
  323.    //(this happens if command is called from PI)
  324.    if (GarrDateFormats){
  325.       GlistDateFormats.focus();
  326.       return;
  327.    }
  328.       
  329.    initGlobals(); //initialize global variables
  330.    populateUI();  //populate UI
  331. }
  332.  
  333.  
  334.  
  335. //function: populateUI
  336. //description: populate the UI with date format examples
  337.  
  338. function populateUI(){
  339.    var dateFormatsArr = GarrDateFormats;  //shorter names easier to work with
  340.    var dayFormatsArr  = GarrDayFormats;
  341.    var timeFormatsArr = GarrTimeFormats;
  342.    
  343.    var nDateFormats = dateFormatsArr.length;
  344.    var nDayFormats  = dayFormatsArr.length;
  345.    var nTimeFormats = timeFormatsArr.length;
  346.    
  347.    var dateObj = new Date("74","2","7","22","18");  //examples are for March 7, 1974
  348.    var dateStr = "",timeStr="",dayStr=""; 
  349.    
  350.     //populate day format list in UI
  351.    //the first line creates an array of formatted dayes
  352.    //(the createDayStr function is overloaded to return one item
  353.    //or an array, therefore, unfortunately the function name isn't 
  354.    //always entirely accurate)
  355.    dayFormatsArr = createDayStr(dateObj,dayFormatsArr,dateFormatsArr,true,true);
  356.    var counter = 0;
  357.    for (i in dayFormatsArr){
  358.       if (!dayFormatsArr[i].prototype){ 
  359.          // Val 13-aug-99 use temporary for speedier UI loading
  360.          var curr = new Option(dayFormatsArr[i]);
  361.          curr.value = i;
  362.          GselDayFormats.options[ counter++ ] = curr;
  363.       }
  364.    }
  365.    
  366.    //populate date format list in UI
  367.    //the first line creates an array of formatted dates
  368.    //(the createDateStr function is overloaded to return one item
  369.    //or an array, therefore, unfortunately, the function name isn't 
  370.    ///always entirely accurate)
  371.    dateFormatsArr  = createDateStr(dateObj,dateFormatsArr,true);
  372.    counter = 0;
  373.    for (i in dateFormatsArr){
  374.       if (!dateFormatsArr[i].prototype){
  375.          // Val 13-aug-99: use a temporary to make initialization faster,
  376.          // and only assign to the formats array once.
  377.            var currObj = new Option(dateFormatsArr[i]);
  378.          currObj.value = i;
  379.          GlistDateFormats.options[ counter++ ] = currObj;
  380.       }
  381.    }
  382.    
  383.    //populate time format list
  384.    for (i=0;i<nTimeFormats;i++){
  385.       timeStr = createTimeStr(dateObj, timeFormatsArr[i], true);
  386.       GselTimeFormats.options[ i ] = new Option(timeStr);
  387.       GselTimeFormats.options[ i ].value = timeFormatsArr[i];
  388.    }
  389.   
  390.    
  391.    //select first option of each menu
  392.    GselDayFormats.selectedIndex = 0;
  393.    GlistDateFormats.selectedIndex = 0;
  394.    GselTimeFormats.selectedIndex = 0;
  395.    
  396.    //put focus in date formats field
  397.    GlistDateFormats.focus();
  398. }
  399.  
  400.  
  401.  
  402. //function: lead
  403. //description: given a one or two digit number,
  404. //adds a leading 0 if a 1 digit number
  405.  
  406. function lead(num){
  407.    if (num.toString().length == "1")
  408.       return "0" + num;
  409.    return ( num );
  410. }
  411.  
  412.  
  413. //function: createDateStr
  414. //description: given a date obj and a date format or formats
  415. //returns an array with the correctly formatted date strings
  416. //overloaded: dateFormat can be one item or an array
  417. //if it is one item, returns one item
  418. //if it is an array, returns an array
  419.  
  420. function createDateStr(dateObj,dateFormat,highAscii){
  421.    var date = dateObj.getDate();
  422.    var day = dateObj.getDay();
  423.    var month = dateObj.getMonth();
  424.    var year = dateObj.getYear();
  425.    var abbrYear = (year<100)? year : year.toString().substring(1);
  426.    var fullYear = (year<100)? "19" + year : year + 1900;
  427.    
  428.    var retVal; //return value;
  429.    
  430.    var abbrMonth;
  431.    var westabbrMonth;
  432.    var fullMonth;
  433.    var westfullMonth;
  434.  
  435.    if (highAscii || isDoubleByteVersion()) { //highAscii is true when date format is one of double-byte ones. but we also want to use this for western date format on double-byte versions.
  436.        westabbrMonth = ARR_WestAbbrMonths[ month ];
  437.        abbrMonth = ARR_AbbrMonths[ month ];
  438.        westfullMonth = ARR_WestFullMonths[ month ];
  439.        fullMonth = ARR_FullMonths[ month++ ];
  440.  
  441.    } else {
  442.        abbrMonth = entityNameEncode(ARR_AbbrMonths[ month ]);
  443.        westabbrMonth = abbrMonth;
  444.        fullMonth = entityNameEncode(ARR_FullMonths[ month++ ]); 
  445.        westfullMonth = fullMonth;
  446.  
  447.  
  448.    }
  449.    //the dateFormat argument is overloaded so that it
  450.    //can be either a string or an array. Handle accordingly.
  451.    if (typeof dateFormat == "string"){
  452.       if (useEnglishDate(dateFormat)) 
  453.         fullMonth = westfullMonth;
  454.         retVal = createCorrectDateFormat(dateFormat,date,day,month,abbrMonth,westabbrMonth,fullMonth,westfullMonth,
  455.                                        year,abbrYear,fullYear);
  456.    } else { //dateFormat is an array
  457.         retVal = new Array();
  458.         dateFormats = dateFormat; //rename
  459.         var nFormats = dateFormats.length;
  460.  
  461.         
  462.         for (var i=0;i<nFormats;i++){
  463.            retVal[dateFormats[i]] = createCorrectDateFormat(dateFormat[i],date,day,month,abbrMonth,westabbrMonth,
  464.                                                fullMonth,westfullMonth,year,abbrYear,fullYear);
  465.             
  466.         }
  467.    }    
  468.    
  469.    return retVal;
  470. }
  471.  
  472.  
  473. //function: createCorrectDateFormat
  474. //description: returns a correclty formatted date string
  475.  
  476. function createCorrectDateFormat(dateFormat,date,day,month,abbrMonth,westabbrMonth,fullMonth,westfullMonth,
  477.                                  year,abbrYear,fullYear,time){
  478.  
  479.     var dateStr = "";
  480.    
  481.     switch (dateFormat){
  482.     
  483.        case "American1":  // Thursday, March 7, 1974
  484.           dateStr += fullMonth + " " + date + ", " + fullYear;
  485.           break;
  486.           
  487.        case "American2":  // 3/7/74
  488.           dateStr += month + "/" + date + "/" + abbrYear;
  489.           break;
  490.           
  491.        case "American3":  // 03/07/1974
  492.           dateStr += lead(month) + "/" + lead(date) + "/" + fullYear;
  493.           break;
  494.  
  495.        case "ISO8601":  // 1974-03-07
  496.           dateStr += fullYear + "-" + lead(month) + "-" + lead(date);
  497.           break;
  498.           
  499.        case "English1":  // 7-mar-74
  500.           dateStr += date + "-" + westabbrMonth + "-" + abbrYear;
  501.           break;
  502.       
  503.        case "English2":  // 07-Mar-1974
  504.           westabbrMonth = westabbrMonth.charAt(0).toUpperCase()+westabbrMonth.substring(1);
  505.           dateStr += lead(date) + "-" + westabbrMonth + "-" + fullYear;
  506.           break;
  507.           
  508.        case "Spanish1":  // 7/3/74 
  509.           dateStr += date + "/" + month + "/" + abbrYear;
  510.           break;
  511.           
  512.        case "French1":  //  7/03/74
  513.           dateStr += date + "/" + lead(month) + "/" + abbrYear;
  514.           break;
  515.           
  516.        case "Italian1":  // 7-03-1974
  517.           dateStr += date + "-" + lead(month) + "-" + fullYear;
  518.           break;
  519.           
  520.        case "Brazilian1":  // 07.03.74
  521.           dateStr += lead(date) + "." + lead(month) + "." + abbrYear;
  522.           break;
  523.           
  524.        case "German1":  // 07.03.1974
  525.           dateStr += lead(date) + "." + lead(month) + "." + fullYear;
  526.           break;
  527.           
  528.        case "Japanese1":  // 74/03/07
  529.           dateStr += abbrYear + "/" + lead(month) + "/" + lead(date) ;
  530.           break;
  531.  
  532.        case "Japanese2":  // 1974 (yearJapanese) 3(month) 7(dayJapanese)
  533.           dateStr += fullYear + yearJapanese + fullMonth + date + dayJapanese;
  534.           break;
  535.  
  536.        case "Japanese3":  // 1974(yearJapanese)03(month) 07(dayJapanese)
  537.           dateStr += fullYear + yearJapanese + lead(month) + monthJapanese + lead(date) + dayJapanese;
  538.           break;
  539.                     
  540.        case "Swedish1":  //  7 March, 1974
  541.           dateStr +=  date + " " + fullMonth + ", " + fullYear;
  542.           break;
  543.           
  544.        case "Korean1":  //  1974(korean year) 3(korean month) 7(korean day)
  545.           dateStr +=  fullYear + yearKorean + fullMonth + " " + date + dayKorean;
  546.           break;
  547.           
  548.        case "Korean2":  //  1974.3.7
  549.           dateStr +=  fullYear + "." + month + "." + date;
  550.           break;
  551.  
  552.        case "Korean3":  //  3.7.1974
  553.           dateStr +=  month + "." + date + "." + fullYear;
  554.           break;
  555.  
  556.        case "Korean4":  //  March 7,1974
  557.           dateStr += westfullMonth + " " + date + ", " + fullYear;
  558.           break;
  559.  
  560.        case "Korean5":  //  74.03.07
  561.           dateStr += abbrYear + "." + lead(month) + "." + lead(date);
  562.           break;
  563.  
  564.        case "Korean6":  // 3/7/ 1974
  565.           dateStr +=  abbrMonth + "/" + lead(date) + " " + fullYear;
  566.           break;
  567.  
  568.        case "Korean7":  //  74-03-07
  569.           dateStr += abbrYear + "-" + lead(month) + "-" + lead(date);
  570.           break;
  571.  
  572.        case "Chinese1":  // 74/3/7
  573.           dateStr += abbrYear + "/" + month + "/" + date ;
  574.           break;
  575.  
  576.        case "Chinese2":  // 1974 (yearChinese) 3(monthChinese) 7(dayChinese)
  577.           dateStr += fullYear + yearChinese + fullMonth + date + dayChinese;
  578.           break;
  579.  
  580.        case "Euroasian1":  // 07-Mar-1974
  581.           //abbrMonth = abbrMonth.charAt(0).toUpperCase()+abbrMonth.substring(1);
  582.           dateStr += lead(date) + " " + westfullMonth + " " + fullYear;
  583.           break;
  584.       
  585.        default:
  586.           break;
  587.    }
  588.    
  589.    return dateStr;
  590.  
  591. }
  592.  
  593.  
  594.  
  595. //function: createDayStr
  596. //description: see createDateStr notes. Except of course this function
  597. //returns a correctly formatted day (or days) instead of a date
  598.  
  599. function createDayStr(dateObj,dayFormat,dateFormat,bPreview,highAscii){
  600.    var    day = dateObj.getDay();
  601.    var    WestFullDay = ARR_WestFullDays[day];
  602.    var    WestAbbrDay = ARR_WestAbbrDays[day];
  603.    var    fullDay;
  604.    var    abbrDay;
  605.  
  606.    if (highAscii || isDoubleByteVersion()) { //highAscii is true when data format is one of double-byte ones. but we also want to use this for western data format on double-byte versions.
  607.      fullDay = ARR_FullDays[day];
  608.      abbrDay = ARR_AbbrDays[day];
  609.    } else {
  610.       fullDay = entityNameEncode(ARR_FullDays[day]);
  611.       abbrDay = entityNameEncode(ARR_AbbrDays[day]);
  612.    }
  613.  
  614.    if (typeof dayFormat == "string"){
  615.       dayFormat = useEnglishDayFormat(dayFormat, dateFormat);
  616.       retVal = createCorrectDayFormat(dayFormat,fullDay,abbrDay,WestFullDay,WestAbbrDay,bPreview);
  617.    } else { //dayFormat is an array
  618.         retVal = new Array();
  619.         dayFormats = dayFormat; //rename for clarity
  620.         var nFormats = dayFormats.length;
  621.  
  622.         for (var i=0;i<nFormats;i++){
  623.            retVal[dayFormats[i]] = createCorrectDayFormat(dayFormat[i],fullDay,abbrDay,WestFullDay,WestAbbrDay,bPreview);
  624.         }
  625.    }    
  626.    return retVal;
  627. }
  628.  
  629.  
  630.  
  631. //function: createCorrectDayFormat
  632. //description: returns the correctly formatted day format
  633.  
  634. function createCorrectDayFormat(dayFormat,fullDay,abbrDay,WestFullDay,WestAbbrDay,bPreview){
  635.  
  636.    var dayStr = "";
  637.    switch (dayFormat){
  638.    
  639.       case "NoDay":
  640.          if (bPreview)
  641.             dayStr = "[" + OPTION_NoDay + "]";
  642.          break;
  643.           
  644.       case "FullDayComma":
  645.          dayStr = CHAR_PreDay + fullDay + CHAR_PostDay;
  646.          break;
  647.          
  648.       case "FullDay":
  649.          dayStr = fullDay + " ";
  650.          break;
  651.          
  652.       case "AbbrDayComma":
  653.          dayStr = CHAR_PreDay + abbrDay + CHAR_PostDay;
  654.          break;
  655.          
  656.       case "AbbrDay":
  657.          dayStr = abbrDay + " ";
  658.          break;
  659.          
  660.       case "LowAbbrDayComma":
  661.          dayStr = abbrDay.toLowerCase() + ", ";
  662.          break;
  663.          
  664.       case "LowAbbrDay":
  665.          dayStr = abbrDay.toLowerCase() + " ";
  666.          break;
  667.  
  668.       case "WestFullDayComma":
  669.          dayStr = WestFullDay + westSeparator;
  670.          break;
  671.     
  672.       case "WestAbbrDayComma":
  673.          dayStr = WestAbbrDay + westSeparator; 
  674.          break;
  675.          
  676.       default:
  677.          break;
  678.    
  679.    }
  680.  
  681.    return dayStr;
  682.  
  683. }
  684.  
  685.  
  686.  
  687. //function: createTimeStr
  688. //description: given a dateObj and a time format,
  689. //returns the correctly formatted time string
  690. //The time format argument is "a" for AM/PM,
  691. //"m" for military time, and "" for no time
  692.  
  693. function createTimeStr(dateObj,timeFormat,bPreview){
  694.    var hours = dateObj.getHours();
  695.    var minutes = lead(dateObj.getMinutes());
  696.    var timeStr = "";  //return value
  697.    
  698.    switch (timeFormat){
  699.       case "NoTime":
  700.          if (bPreview)
  701.             timeStr = "[" + OPTION_NoTime + "]";
  702.          break;
  703.          
  704.        case "AMPMTime":
  705.              timeStr += (hours>=12) ? ((hours-12==0)?hours:hours-12) + ":" + minutes + " " + PM :
  706.                   hours + ":" + minutes + " " + AM;
  707.            timeStr = " " + timeStr;
  708.            break;
  709.           
  710.       case "MilitaryTime":
  711.          timeStr += " " + hours + ":" + minutes;
  712.            timeStr = " " + timeStr;
  713.            break;
  714.          
  715.       default:
  716.          break;
  717.    }
  718.          
  719.    return timeStr;
  720. }
  721.  
  722. // Check if user is running localized DW
  723. function isDoubleByteVersion(){
  724.     if (dreamweaver.appVersion && (dreamweaver.appVersion.indexOf('ja') != -1 || dreamweaver.appVersion.indexOf('ko') != -1 || dreamweaver.appVersion.indexOf('zh') != -1) )
  725.         return true;
  726.     else
  727.         return false;
  728. }
  729.  
  730. // Return true if selected date format is not localized specific one (i.e. Japanese1).
  731. // For example, 
  732. // -If user selected "American1" date format on Japanese DW, this function returns true.
  733. // -If user selected "Japanese1" date format on Japanese DW, this function returns false.
  734. function useEnglishDate(format) {
  735.     if ((dreamweaver.appVersion && dreamweaver.appVersion.indexOf('ja') != -1) && format.indexOf("Japan") != 0)
  736.         return true;
  737.     else if ((dreamweaver.appVersion && dreamweaver.appVersion.indexOf('ko') != -1) && format.indexOf("Korean") != 0) 
  738.         return true;
  739.     else if ((dreamweaver.appVersion && dreamweaver.appVersion.indexOf('zh') != -1) && format.indexOf("Chinese") != 0) 
  740.         return true;
  741.     else
  742.         return false;
  743. }
  744.  
  745. // if selected date was not localized specific one (i.e. Japanese1), force to use Western day formats.
  746. function useEnglishDayFormat(dayFormat, dateFormat) {
  747.     var rtnDayFormat = dayFormat;
  748.     if (useEnglishDate(dateFormat)) {
  749.         if (dayFormat == "FullDayComma" || dayFormat == "FullDay" || dayFormat == "WestFullDayComma")
  750.             rtnDayFormat = "WestFullDayComma";
  751.         else if (dayFormat != "NoDay")
  752.             rtnDayFormat = "WestAbbrDayComma";
  753.     }
  754.     return rtnDayFormat;
  755. }