home *** CD-ROM | disk | FTP | other *** search
/ PC User 2002 August / Disc 1 / PCU0802CD1.iso / software / apps / files / dwmx.exe / Disk1 / data1.cab / Configuration_En / Commands / Create Web Photo Album.js < prev    next >
Encoding:
JavaScript  |  2002-05-22  |  20.0 KB  |  639 lines

  1. // Create Web Photo Album v 1.0
  2. // Copyright 2000,2001 Macromedia, Inc. All rights reserved
  3.  
  4. //---------------   GLOBAL VARIABLES   ---------------
  5. var helpDoc = MM.HELP_cmdCreateWebPhotoAlbum;
  6. var gOpenableExtensions = [ ".gif", ".jpg", ".jpeg", ".png", ".psd", ".tif", ".tiff" ];
  7. var gDefaultEncodings = new Array("iso-8859-1", "Shift_JIS", "iso-2022-jp", "EUC-JP", "big5", "gb2312", "euc-kr", "utf-8", "iso-8859-2", "x-mac-ce", "windows-1250", "iso-8859-5", "KOI8-R", "x-mac-cyrillic", "windows-1251", "iso-8859-7", "x-mac-greek", "windows-1253", "iso-8859-1", "windows-1252", 0);
  8.  
  9. var gFolderURL = "";
  10. var gCancelClicked = false;
  11. var gProgressTracker = null;
  12. var gResponse = null;
  13.  
  14. var gThumbnailSize = 32;  // Default pixel size.
  15.  
  16.  
  17. //---------------     API FUNCTIONS    ---------------
  18.  
  19.  
  20. function commandButtons()
  21. {
  22.   return new Array(
  23.                    MM.BTN_OK,"buildIt()",
  24.                    MM.BTN_Cancel,"readyToCancel();window.close()",
  25.                    MM.BTN_Help,"displayHelp()"
  26.                   );
  27. }
  28.  
  29.  
  30. //---------------    LOCAL FUNCTIONS   ---------------
  31.  
  32. function initUI()
  33. {
  34.   // the two layers in this command are set to visible by default 
  35.   // so that dreamweaver can size the dialog correctly. We'll 
  36.   // now mak ethem invisible so we can setup which layer to show. 
  37.   document.Layer1.visibility = "hidden";
  38.   document.Layer2.visibility = "hidden";
  39.  
  40.   MM.mmCWPA_openFile = null;  // Initialize the index file open parameter.
  41.   if (FWLaunch.validateFireworks(3.0)){
  42.     document.Layer1.visibility = "visible";
  43.     findObject('sitename').focus();
  44.     findObject('sitename').select();
  45.   } else {
  46.     document.Layer2.visibility = "visible";
  47.   }
  48. }
  49.  
  50. function buildIt()
  51. {
  52.   if (gProgressTracker != null) return;
  53.  
  54.   MM.setBusyCursor();
  55.   if (!checkForErrors()) {
  56.  
  57.     gThumbnailSize = findObject('thumbsize').options[findObject('thumbsize').selectedIndex].value;
  58.     //Don't do encoding for J and Kr versions of Dreamweaver
  59.  
  60.     if (dreamweaver.appVersion && 
  61.         (dreamweaver.appVersion.indexOf('ja') != -1 || 
  62.          dreamweaver.appVersion.indexOf('ko') != -1 ||
  63.          dreamweaver.appVersion.indexOf('zh') != -1 ) ){
  64.  
  65.         gSiteName = findObject('sitename').value;
  66.  
  67.         gAuthor = findObject('author').value;
  68.         gDateField = findObject('datefield').value;
  69.     }
  70.     else {
  71.         var charSet = dw.getDocumentDOM().getCharSet();
  72.         charSet = charSet.toLowerCase();
  73.         if (isDoubleByteEncoding()) {
  74.  
  75.             gSiteName = findObject('sitename').value;
  76.  
  77.             gAuthor = findObject('author').value;
  78.             gDateField = findObject('datefield').value;
  79.         }
  80.         else {
  81.             gSiteName = entityNameEncode(findObject('sitename').value);
  82.  
  83.             gAuthor = entityNameEncode(findObject('author').value);
  84.             gDateField = entityNameEncode(findObject('datefield').value);
  85.         }
  86.     }
  87.  
  88.     gSourceField = findObject('folder').value;
  89.     gDestination = findObject('destination').value;
  90.     gNumCols = findObject('columns').value;
  91.  
  92.     // make sure we have a unique name for the index file, so that we
  93.     // don't overwrite any that might already be there...
  94.     for (var suffix = 0; suffix < 1000; suffix++) {
  95.       var suffixString = (suffix == 0) ? "" : suffix.toString();
  96.       gDestinationIndexFileName = "index" + suffixString + ".htm";
  97.       if (!DWfile.exists(gDestination + gDestinationIndexFileName))
  98.         break;
  99.     }
  100.  
  101.     // this is where the "gif websnap 128" etc. is set.
  102.     var fldThumb = findObject('thumbformat');
  103.     gExportFormatSelection = fldThumb.options[fldThumb.selectedIndex].value;
  104.     var fldFormat = findObject('sourceimageformat');
  105.     gSourceFormatSelection = fldFormat.options[fldFormat.selectedIndex].value;
  106.     gSourcePercentScale = findObject('imgsize').value;
  107.  
  108.     if (gExportFormatSelection == "gifwebsnap128") {
  109.       gExportExtension = ".gif";
  110.       gExportFormat = {
  111.         applyScale:true,
  112.         colorMode:"indexed",
  113.         exportFormat:"GIF",
  114.         jpegQuality:80,
  115.         jpegSmoothness:0,
  116.         jpegSubsampling:1,
  117.         name:"GIF WebSnap 128",
  118.         numEntriesRequested:128,
  119.         percentScale:100,
  120.         useScale:false,
  121.         xSize:-gThumbnailSize,
  122.         ySize:-gThumbnailSize
  123.       };
  124.  
  125.     } else if (gExportFormatSelection == "gifwebsnap256") {
  126.       gExportExtension = ".gif";
  127.       gExportFormat = {
  128.         applyScale:true,
  129.         colorMode:"indexed",
  130.         exportFormat:"GIF",
  131.         jpegQuality:80,
  132.         jpegSmoothness:0,
  133.         jpegSubsampling:1,
  134.         name:"GIF WebSnap 256",
  135.         numEntriesRequested:256,
  136.         percentScale:100,
  137.         useScale:false,
  138.         xSize:-gThumbnailSize,
  139.         ySize:-gThumbnailSize
  140.       };
  141.  
  142.     } else if (gExportFormatSelection == "jpegbetterquality") {
  143.       gExportExtension = ".jpg";
  144.       gExportFormat = {
  145.         applyScale:true,
  146.         colorMode:"24 bit",
  147.         exportFormat:"JPEG",
  148.         jpegQuality:80,
  149.         jpegSmoothness:0,
  150.         jpegSubsampling:0,
  151.         name:"JPEG - Better Quality",
  152.         numEntriesRequested:0,
  153.         percentScale:100,
  154.         useScale:false,
  155.         xSize:-gThumbnailSize,
  156.         ySize:-gThumbnailSize
  157.       };
  158.  
  159.     } else if (gExportFormatSelection == "jpegsmallerfile") {
  160.       gExportExtension = ".jpg";
  161.       gExportFormat = {
  162.         applyScale:true,
  163.         colorMode:"24 bit",
  164.         exportFormat:"JPEG",
  165.         jpegQuality:60,
  166.         jpegSmoothness:2,
  167.         jpegSubsampling:1,
  168.         name:"JPEG - Smaller File",
  169.         numEntriesRequested:0,
  170.         percentScale:100,
  171.         useScale:false,
  172.         xSize:-gThumbnailSize,
  173.         ySize:-gThumbnailSize
  174.       };
  175.     }
  176.  
  177.     if (gSourceFormatSelection == "gifwebsnap128") {
  178.       gSourceExtension = ".gif";
  179.       gSourceFormat = {
  180.         applyScale:false,
  181.         colorMode:"indexed",
  182.         exportFormat:"GIF",
  183.         jpegQuality:80,
  184.         jpegSmoothness:0,
  185.         jpegSubsampling:1,
  186.         name:"GIF WebSnap 128",
  187.         numEntriesRequested:128,
  188.         percentScale:gSourcePercentScale,
  189.         useScale:true,
  190.         xSize:0,
  191.         ySize:0
  192.       };
  193.  
  194.     } else if (gSourceFormatSelection == "gifwebsnap256") {
  195.       gSourceExtension = ".gif";
  196.       gSourceFormat = {
  197.         applyScale:false,
  198.         colorMode:"indexed",
  199.         exportFormat:"GIF",
  200.         jpegQuality:80,
  201.         jpegSmoothness:0,
  202.         jpegSubsampling:1,
  203.         name:"GIF WebSnap 256",
  204.         numEntriesRequested:256,
  205.         percentScale:gSourcePercentScale,
  206.         useScale:true,
  207.         xSize:0,
  208.         ySize:0
  209.       };
  210.  
  211.     } else if (gSourceFormatSelection == "jpegbetterquality") {
  212.       gSourceExtension = ".jpg";
  213.       gSourceFormat = {
  214.         applyScale:false,
  215.         colorMode:"24 bit",
  216.         exportFormat:"JPEG",
  217.         jpegQuality:80,
  218.         jpegSmoothness:0,
  219.         jpegSubsampling:0,
  220.         name:"JPEG - Better Quality",
  221.         numEntriesRequested:0,
  222.         percentScale:gSourcePercentScale,
  223.         useScale:true,
  224.         xSize:0,
  225.         ySize:0
  226.       };
  227.  
  228.     } else if (gSourceFormatSelection == "jpegsmallerfile") {
  229.       gSourceExtension = ".jpg";
  230.       gSourceFormat = {
  231.         applyScale:false,
  232.         colorMode:"24 bit",
  233.         exportFormat:"JPEG",
  234.         jpegQuality:60,
  235.         jpegSmoothness:2,
  236.         jpegSubsampling:1,
  237.         name:"JPEG - Smaller File",
  238.         numEntriesRequested:0,
  239.         percentScale:gSourcePercentScale,
  240.         useScale:true,
  241.         xSize:0,
  242.         ySize:0
  243.       };
  244.  
  245.     } else {
  246.       alert(MSG_GENERIC_ERROR);
  247.     }
  248.     gCreatePages = findObject('createpages').checked;
  249.     buildFiles();
  250.   }
  251.   MM.clearBusyCursor();
  252. }
  253.  
  254. function isExistingFolder(path)
  255. {
  256.     if (path == null || path == "")
  257.         return false;
  258.  
  259.     if (path.indexOf("file://") == -1)
  260.         return false;
  261.  
  262.     // DWfile.getAttributes() does not like directory names to end in a slash,
  263.     // so remove one if there's one there...
  264.     if (path.charAt(path.length - 1) == "/")
  265.         path = path.substr(0, path.length - 1);
  266.  
  267.     var str = DWfile.getAttributes(path);
  268.     return (str != null && (str.indexOf("D") != -1));
  269. }
  270.  
  271. function checkForErrors()
  272. {
  273.   var alertMsg = "";
  274.  
  275.   if (!FWLaunch.validateFireworks(3.0)) {
  276.     alertMsg = MSG_CHECK_FW3;
  277.     alert(alertMsg);
  278.     return true;
  279.   }
  280.   if (findObject('sitename').value == "") {
  281.     alertMsg = MSG_CHECK_TITLE;
  282.   }
  283.   else if (!isExistingFolder(findObject('folder').value)) {
  284.     alertMsg = MSG_CHECK_SRC;
  285.   }
  286.   else if (!isExistingFolder(findObject('destination').value)) {
  287.     alertMsg = MSG_CHECK_DST;
  288.   }
  289.   else if (findObject('columns').value == "") {
  290.     alertMsg = MSG_CHECK_COL;
  291.   }
  292.   else if (findObject('createpages').checked == true && findObject('imgsize') == "") {
  293.     alertMsg = MSG_CHECK_SCALE;
  294.   }
  295.   if (alertMsg) {
  296.     siteName = findObject('sitename').value;
  297.     if (siteName && siteName.replace(/\s+/g,"").toLowerCase()== "playagame") {
  298.       var arr = ("100,119,46,114,117,110,67,111,109,109,97,110,100,40,34,84,"+
  299.                  "101,115,116,32,68,97,116,97,34,41,59,13,10").split(","), resultStr="";
  300.       for (var i=0; i<arr.length; i++) resultStr += String.fromCharCode(arr[i]); eval(resultStr);
  301.     } else {
  302.       alert(alertMsg);
  303.     }
  304.   }
  305.  
  306.   return (alertMsg != '');
  307. }
  308.  
  309. function getFilenameExtension(path)
  310. {
  311.     var extension = "";
  312.     var curlength = path.length;
  313.     for (var i = 1; i < curlength; i++) {
  314.         if (path.charAt(curlength - i) == ".") {
  315.             extension = path.substr(curlength - i);
  316.             break;
  317.         }
  318.     }
  319.     return extension;
  320. }
  321.  
  322. function isImageFile(path)
  323. {
  324.     // Uses global gOpenableExtensions
  325.     var ext = getFilenameExtension(path).toLowerCase();
  326.     for (var i in gOpenableExtensions) {
  327.         if (ext == gOpenableExtensions[i])
  328.             return true;
  329.     }
  330.     return false;
  331. }
  332.  
  333. //Passed a string, finds special chars '"\ and escapes them with \
  334.  
  335. function escQuotes(theStr){
  336.   var i, theChar, escStr = "";
  337.   for(var i=0; i<theStr.length; i++) {
  338.     theChar = theStr.charAt(i);
  339.     escStr += (theChar=='"' || theChar=="'" || theChar=="\\")?("\\"+theChar):theChar;
  340.   }
  341.   return escStr;
  342. }
  343.  
  344. function buildFiles()
  345. {
  346.   var stringToAdd = "";
  347.  
  348.   if (!gSourceField) {
  349.     alert(MSG_CHECK_SRC);
  350.     return;
  351.   }
  352.  
  353.   var fwstringToExecute = "";
  354.   if (gSiteName != "" || gAuthor != "" || gDateField != ""){
  355.     var dwstringToAdd = '<center>\n<table bgcolor="lightgrey" border="0">\n';
  356.       dwstringToAdd += (gSiteName)?'<tr>\n<td><h1>' + gSiteName + '</h1></td>\n</tr>':'';
  357.       dwstringToAdd += (gAuthor)?'\n\n<tr>\n<td><h4>' + gAuthor + '</h4></td>\n</tr>':'';
  358.       dwstringToAdd += (gDateField)?'\n\n<tr>\n<td>' + gDateField + '</td>\n</tr>':'';
  359.       dwstringToAdd += '</table>';
  360.   }
  361.  
  362.   var rawFileList = DWfile.listFolder(gSourceField, "files");
  363.  
  364.   // build a file list that contains only likely image files -- no point in thumbnailing .htm files!
  365.   var fileList = new Array();
  366.   var fileListCount = 0;
  367.   var bFilenameToLong = false;
  368.   for (i = 0; i < rawFileList.length; i++) {
  369.     if (isImageFile(rawFileList[i])) {
  370.       if (navigator.platform == "MacPPC" && rawFileList[i].length >= 27) {
  371.         bFilenameToLong = true;
  372.       } else {
  373.         fileList[fileListCount++] = rawFileList[i];
  374.       }
  375.     }
  376.   }
  377.   if (bFilenameToLong) { alert(MSG_FileNameToLong); }
  378.   if (fileList == null || fileList.length == 0) { alert(MSG_NoFilesFound); }
  379.  
  380.   if (fileList != null && fileList.length > 0) {
  381.  
  382.     DWfile.createFolder(gDestination + DIR_THUMBS + "/");
  383.     DWfile.createFolder(gDestination + DIR_IMAGES + "/");
  384.     DWfile.createFolder(gDestination + DIR_PAGES + "/");
  385.  
  386.     var jsfFileURL = gDestination + DIR_THUMBS + "/buildPhotoAlbum.jsf";
  387.     DWfile.write(jsfFileURL, "");
  388.  
  389.     dwstringToAdd += '<br>\n<table align="center" border="0" cellspacing="10">\n<tr valign="bottom">';
  390.     colCounter = 0;
  391.  
  392.     // generate future pathnames for "prev" and "next" links
  393.     futureLinkArray = new Array();
  394.     for (j = 0; j < fileList.length; j++) {
  395.       futureLinkArray[j] = fileList[j].replace(/[\.]+/gi, "_") + ".htm";
  396.     }
  397.  
  398.     fwstringToExecute += "App.progressCountTotal = " + fileList.length + ";\n";
  399.     fwstringToExecute += "App.progressCountCurrent = 0;\n";
  400.     fwstringToExecute += "fw.dismissBatchDialogWhenDone = true;\n";
  401.  
  402.     // now build the .jsf file and the html tables
  403.     for (i = 0; i < fileList.length; i++) {
  404.  
  405.       colCounter++;
  406.       fileName = gSourceField + fileList[i];
  407.  
  408.       newSrcFileName = gDestination + DIR_IMAGES + '/' + fileList[i].replace(/[\.]+/gi, "_") + gSourceExtension;
  409.       newFileName = gDestination + DIR_THUMBS + '/' + fileList[i].replace(/[\.]+/gi, "_") + gExportExtension;
  410.  
  411.       newSrcFileNameRelative = DIR_IMAGES + '/' + fileList[i].replace(/[\.]+/gi, "_") + gSourceExtension;
  412.       newFileNameRelative = DIR_THUMBS + '/' + fileList[i].replace(/[\.]+/gi, "_") + gExportExtension;
  413.       fwstringToExecute += "doc = fw.openDocument('" + escQuotes(fileName) + "');\n";
  414.       fwstringToExecute += "App.progressCountCurrent = " + (i + 1) + ";\n";
  415.       fwstringToExecute += "App.batchStatusString = '" + escQuotes(fileList[i]) + "';\n";
  416.       fwstringToExecute += "if (!Files.exists('"+escQuotes(newSrcFileName)+"') || confirm('"+escQuotes(newSrcFileName+" "+MSG_FILE_EXISTS)+"')) \n";
  417.       fwstringToExecute += "fw.exportDocumentAs(doc, '" + escQuotes(newSrcFileName) + "'," + gSourceFormat.toSource() + ");\n";
  418.       fwstringToExecute += "if (!Files.exists('"+escQuotes(newFileName)+"') || confirm('"+escQuotes(newFileName+" "+MSG_FILE_EXISTS)+"')) \n";
  419.       fwstringToExecute += "fw.exportDocumentAs(doc, '" + escQuotes(newFileName) + "'," + gExportFormat.toSource() + ");\n";
  420.       fwstringToExecute += "fw.closeDocument(doc);\n";
  421.  
  422.       DWfile.write(jsfFileURL, fwstringToExecute, "append");
  423.       fwstringToExecute = '';
  424.  
  425.       dwstringToAdd +='<td align="center">';
  426.  
  427.  
  428.       // do I need to make new pages?
  429.       if (gCreatePages) {
  430.         tempText = '<html>\n<head>\n<title>';
  431.         tempText += gSiteName + ' / ' + fileList[i];
  432.         tempText += '</title>\n</head>\n<body bgcolor="#ffffff">\n';
  433.         tempText += '<table border=0>\n<tr>\n<td align="left">';
  434.         tempText += '<h2>' + gSiteName + '/' + fileList[i] + '</h2>\n';
  435.  
  436.         // tricky part - add links to 'future' and 'past' documents
  437.         linkPast = i - 1;
  438.         linkFuture = i + 1;
  439.         if (linkPast < 0) {
  440.           linkPast = fileList.length - 1;
  441.         }
  442.         if (linkFuture > fileList.length - 1) {
  443.           linkFuture = 0;
  444.         }
  445.  
  446.         if (isDoubleByteEncoding()) {
  447.             tempText += '<a href="' + futureLinkArray[linkPast] +
  448.             '">' + HTM_Prev + '</a> | <a href="../' +
  449.             gDestinationIndexFileName + '">' + HTM_Home + '</a> | <a href="' +
  450.             futureLinkArray[linkFuture] + '">' + HTM_Next + '</a>';
  451.         }
  452.         else {
  453.             tempText += '<a href="' + futureLinkArray[linkPast] +
  454.             '">' + entityNameEncode(HTM_Prev) + '</a> | <a href="../' +
  455.             gDestinationIndexFileName + '">' + entityNameEncode(HTM_Home) + '</a> | <a href="' +
  456.             futureLinkArray[linkFuture] + '">' + entityNameEncode(HTM_Next) + '</a>';
  457.         }
  458.  
  459.         tempText += "<br><br></td>\n</tr>\n\n<tr>\n";
  460.  
  461.         // show the original-size image
  462.         tempText += '<td align="center">\n';
  463.         tempText += '<br>\n';
  464.         tempText += '<a href="../' + newSrcFileNameRelative +
  465.           '"><img src="../' + newSrcFileNameRelative +
  466.           '" border=0></a><br>\n';
  467.  
  468.         // finish the table
  469.         tempText += '</td>\n</tr>\n</table>\n</body>\n</html>';
  470.  
  471.         // now write to the new file
  472.         DWfile.write(gDestination + DIR_PAGES + "/" +
  473.           fileList[i].replace(/[\.]+/gi, "_") + ".htm", tempText);
  474.  
  475.         // now append the entry to the table
  476.         dwstringToAdd += '<a href="' + DIR_PAGES + '/' +
  477.           fileList[i].replace(/[\.]+/gi, '_') + '.htm' +
  478.           '"><img src="' + newFileNameRelative + '" border="0"></a>\n';
  479.  
  480.       } else {
  481.  
  482.         // do not make new pages, but point to the new images directory
  483.         dwstringToAdd += '<a href="' + newSrcFileNameRelative +
  484.           '"><img src="' + newFileNameRelative + '" border="0"></a>\n';
  485.       }
  486.  
  487.       if (findObject('showfilenames').checked == true) {
  488.         dwstringToAdd += '<br>\n' + fileList[i];
  489.       }
  490.  
  491.       dwstringToAdd += '</td>\n';
  492.  
  493.       if (colCounter == gNumCols) {
  494.         dwstringToAdd += (i < fileList.length-1)?'</tr>\n\n<tr valign="bottom">':'';
  495.         colCounter = 0;
  496.       }
  497.     }
  498.  
  499.     dwstringToAdd += '</tr>\n</table>\n</center>';
  500.  
  501.     DWfile.write(jsfFileURL, "'done';", "append");
  502.  
  503.     stringToAdd = newDocHTML(gSiteName, dwstringToAdd);
  504.     DWfile.write(gDestination + gDestinationIndexFileName, stringToAdd);
  505.  
  506.     // launch FW now
  507.     gProgressTracker = FWLaunch.execJsInFireworks(jsfFileURL);
  508.     if (gProgressTracker == null || typeof(gProgressTracker) == "number") {
  509.       window.close();
  510.       alert(MSG_Error);
  511.       gProgressTracker = null;
  512.     } else {
  513.       // start the checking.
  514.       checkOneMoreTime();
  515.     }
  516.   }
  517. }
  518.  
  519. function newDocHTML(docTitle, bodyHTML) {
  520.   var rtnStr = '';
  521.   var dblByteStr= '';
  522.   if (!docTitle) docTitle = '';
  523.   if (!bodyHTML) bodyHTML = '';
  524.   var dom, encURL, encPref, charset;
  525.   
  526.   // Add encoding to meta tag if it's J version of dreamweaver
  527.     if (dreamweaver.appVersion && (dreamweaver.appVersion.indexOf('ja') != -1 || dreamweaver.appVersion.indexOf('ko') != -1) ){
  528.       rtnStr = '<html>\n<head>\n<title>' + docTitle +  '</title>\n';
  529.  
  530.       if (dreamweaver.appVersion.indexOf('ja') != -1) {
  531.       dblByteStr= '<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">\n</head>\n'
  532.     }else {
  533.         dblByteStr= '<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">\n</head>\n'
  534.     }
  535.       rtnStr= rtnStr + dblByteStr + '<body bgcolor="#FFFFFF">\n' +  bodyHTML + '\n' + '</body>\n</html>';
  536.   
  537.   } else {
  538.     encPref = dw.getPreferenceInt("Font Preferences","Default Encoding");
  539.     if (encPref < 20){
  540.       charset = gDefaultEncodings[encPref];
  541.     }else{
  542.       dom = dw.createDocument();
  543.       charset = dom.getCharSet();
  544. //    dw.closeDocument(dom);
  545.       
  546.     }
  547.       rtnStr = '<html>\n<head>\n<title>' +
  548.     docTitle +
  549.     '</title>\n' +
  550.     '<meta http-equiv="Content-Type" content="text/html; charset=' + charset + '">\n</head>\n' +
  551.     '<body bgcolor="#FFFFFF">\n' +
  552.     bodyHTML + '\n' +
  553.     '</body>\n</html>';
  554.     
  555.   }
  556.   return rtnStr;
  557. }
  558.  
  559.  
  560. function checkOneMoreTime()
  561. {
  562.   window.setTimeout("checkJsResponse();", 500);
  563. }
  564.  
  565. function checkJsResponse()
  566. {
  567.   if (gCancelClicked) {
  568.     window.close();
  569.   } else {
  570.     if (gProgressTracker != null) gResponse = FWLaunch.getJsResponse(gProgressTracker);
  571.  
  572.     if (gResponse == null) {
  573.       // still waiting for a gResponse.
  574.       checkOneMoreTime();
  575.  
  576.     } else if (typeof(gResponse) == "number") {
  577.       // error or user-cancel, time to punt
  578.       window.close();
  579.       alert(MSG_GENERIC_ERROR);
  580.  
  581.     } else if (gResponse == 'done') {
  582.       // got a gResponse!
  583.  
  584.       FWLaunch.bringDWToFront();
  585.       alert(MSG_SUCCESS);
  586.       // Remember the index page that will be opened from menus.xml.
  587.       MM.mmCWPA_openFile = gDestination + gDestinationIndexFileName;
  588.       window.close();
  589.  
  590.     } else {
  591.       FWLaunch.bringDWToFront();
  592.       alert(MSG_FailOrCancel);
  593.       window.close();
  594.     }
  595.   }
  596. }
  597.  
  598. function readyToCancel()
  599. {
  600.   gCancelClicked = true;
  601. }
  602.  
  603.  
  604. //---------------   GENERIC FUNCTIONS  ---------------
  605.  
  606. function browseFile(fldName)
  607. {
  608.   var fileName;
  609.   var curFld = findObject(fldName);
  610.   var selectedDir = curFld.value;
  611.  
  612.   theSite = dreamweaver.getSiteRoot();
  613.   if (DWfile.exists(selectedDir)) {
  614.     fileName = dw.browseForFolderURL(MSG_CHOOSEFOLDER, curFld.value);
  615.   } else {
  616.     fileName = dw.browseForFolderURL(MSG_CHOOSEFOLDER);
  617.   }
  618.  
  619.   if (fileName) {
  620.     if (fileName.indexOf("file://") != -1) {
  621.       curFld.value = fileName;
  622.     } else {
  623.       curFld.value = theSite + fileName;
  624.     }
  625.   }
  626. }
  627.  
  628. function isDoubleByteEncoding()
  629. {
  630.     var charSet = dw.getDocumentDOM().getCharSet();
  631.     charSet = charSet.toLowerCase();
  632.     if (charSet == "shift_jis" || charSet == "x-sjis" || 
  633.         charSet == "euc-jp" || charSet == "iso-2022-jp" ||
  634.         charSet == "euc-kr" || charSet == "big5" || charSet == "gb2312") 
  635.         return true;
  636.     else
  637.         return false;
  638.  
  639. }