// Copyright 2001-2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.

function isDOMRequired() { 
  // return true.  This will insert the object into the design view.
  return false;
}

function isAsset() {
	return true;
}

function objectTag(assetArgs)
{
    var dom = dw.getDocumentDOM();
    if (!dom) {
        return '';
    }

    var filePath = dw.getDocumentPath("document");
    var isSiteRelative = false;
    var siteRoot = "";

    if (filePath)
        siteRoot = dw.getSiteRootForURL(filePath);

    if (siteRoot != "") {
        isSiteRelative = dw.isUrlSiteRelative(filePath); 
    }
    
    // save document if not saved
    if (!filePath) {
        var saveDocMsg = dw.loadString("flash/save before insert");
        if (confirm(saveDocMsg) && dw.canSaveDocument(dreamweaver.getDocumentDOM())) {
            dw.saveDocument(dreamweaver.getDocumentDOM());
            filePath = dw.getDocumentPath("document");
        }
    }
    
    if (!filePath)
        return '';

    var bDialogState = dw.getShowDialogsOnInsert();
	
	// Return the html tag that should be inserted
	var theMovie = '';
	var isBlogSite = false;

	if (dw.appName == "Contribute")
	{
	    if (arguments.length == 0)
		{
			prefsAccessibilityOption = dw.getAdminEnforceAccessibilityPref();
			var ok = true;	
			if(dom)
            {
                if(CCWorkspaceManager.getManager(dom))
                { // if its a blog, do not display the accessibility warning
                    if(CCWorkspaceManager.getManager(dom).isBlogSite())        
                        isBlogSite = true;
                }
            }
            if(isBlogSite == false)
			{
			     ok = dw.displayOptionalDialog("Flash Accessibility Warning Dialog", 
					dw.loadString("insert doc dialog/flash accessibility warning"), 
						true);
			}
			if (!ok)
			{
				return '';
			}

			if (MM.InsertFlashType == "file") {

			    var filter = new Array(dw.loadString("insert doc dialog/flash doc desc") + " (*.swf)|*.swf|");

			    if (MM.InsertFlashType == "file") {
			        theMovie = dw.browseForFileURL("open", "", false, "", filter, "", "", "desktop");
			        if (dw.isGreaterThanMaxDependentFileSize(theMovie)) {
			            return '';
			        }
			    }

			}
			else if (MM.InsertFlashType == "website") {
			    theMovie = dw.browseForFlashOnWebsite();
			}

			//code added by ganesh j begins
			else if (MM.InsertFlashType == "internet") {

			    theMovie = dw.BrowseToInternetFlash();
			    if (theMovie.length == 0)
			        return; // No selection made

			    var retval = dw.validateMediaFile(theMovie);
			    if (!retval)
			        return;
			}
			else {
			    var index = MM.InsertFlashType.search("drop:file");
			    if (index != -1)
			        theMovie = MM.InsertFlashType.substr(5);			    
			}   
			
		}
	}
	else
	{
		theMovie = dw.browseForFileURL();
	}

	//block double byte ot high ascii filenames
	if (dw.appName == "Contribute") 
	{
		var fileName = dwscripts.getFileName(theMovie);

		if (hasDoubleByteChar(fileName))
		{
			alert(dw.loadString("file naming/doublebyte filename error"));
			return '';
		}
		else if (hasHighAsciiChar(fileName))
		{
			alert(dw.loadString("file naming/highascii filename error"));
			return '';
		}
	}

	if (theMovie != '')
	{
		theMovie = dw.doURLEncoding(theMovie);
	}

	if (assetArgs)
	{
		theMovie = assetArgs;
	}

	if ((theMovie == '') && bDialogState) 
	{
	    return '';
    }

    if (isBlogSite == true) {
        rtnStr = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
				' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" WIDTH="128" HEIGHT="128">\n' +
				'<PARAM NAME="movie" VALUE="' + theMovie + '"> <PARAM NAME="quality" VALUE="high">\n' +
				'<EMBED SRC="' + theMovie +
				'" quality="high" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" ' +
				'TYPE="application/x-shockwave-flash" WIDTH="128" HEIGHT="128">' +
				'</EMBED></OBJECT>';
    }
    else {
        var id = dwscripts.getUniqueId("FlashID");
        var assetList = new Array();
        var assetInfo = new AssetInfo("Shared/Flash/" + FlashObjectLibraryFile, "Scripts/" + FlashObjectLibraryFile, "javascript", false);
        assetList.push(assetInfo);

        assetInfo = new AssetInfo("Shared/Flash/expressInstall.swf", "Scripts/expressInstall.swf", "", false);
        assetList.push(assetInfo);

        var expInstallPath = "Scripts" + dwscripts.FILE_SEP;
        var absoluteExpInstallPath;

        if (siteRoot == "") {
            var docBase = filePath.substring(0, filePath.lastIndexOf('/') + 1);
            absoluteExpInstallPath = docBase + expInstallPath;
        }
        else {
            absoluteExpInstallPath = siteRoot + expInstallPath;
        }

        if (isSiteRelative)
            expInstallPath = dw.absoluteURLToSiteRelative(filePath, siteRoot, absoluteExpInstallPath, true);
        else
            expInstallPath = dw.absoluteURLToDocRelative(filePath, siteRoot, absoluteExpInstallPath, true);

        expInstallPath += "expressInstall.swf";
        
        var useEntities = isDoubleByteOrUtf8Encoding() == false;
        var innerObjComment = dw.loadString("flash/comment for inner object tag");
        var expressInstallComment = dw.loadString("flash/comment for express install");
        var altContentComment = dw.loadString("flash/comment for alternative content");
        var getNewPlayerMsg = dw.loadString("flash/get new player message");
        var altValueForImg = dw.loadString("flash/alt attribute value for get player image");
        if (useEntities) {
            getNewPlayerMsg = dwscripts.entityNameEncode(getNewPlayerMsg);
            altValueForImg = dwscripts.entityNameEncode(altValueForImg);
        }
        var paramTags = '<param name="quality" value="high">\n' +
		                '<param name="wmode" value="opaque">\n' +
		                '<param name="swfversion" value="9.0.28.0">\n';
        var expressInstallParam = '<param name="expressinstall" value="' + expInstallPath + '">\n';

        rtnStr = '<object id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="50" height="50">\n' +
                '<param name="movie" value="' + theMovie + '">\n' +
                paramTags + '<!-- ' + expressInstallComment + ' -->\n' + expressInstallParam +
		        '<!-- ' + innerObjComment + ' -->\n' +
                '<!--[if !IE]>-->\n' +
		        '<object type="application/x-shockwave-flash" data="' + theMovie + '" width="50" height="50">\n' +
		        '<!--<![endif]-->\n' +
                paramTags + expressInstallParam +
		        '<!-- ' + altContentComment + ' -->\n' +
		        '<div>\n<h4>' + getNewPlayerMsg + '</h4>\n' +
                '<p><a href="http://www.adobe.com/go/getflashplayer">' +
                '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="' +
		        altValueForImg + '" />' +
                '</a></p>\n</div>' +
		        '<!--[if !IE]>-->\n</object>\n<!--<![endif]-->\n' +
		        '</object>';
    }
		
	prefsAccessibilityOption = dw.getPreferenceString("Accessibility", "Accessibility Media Options", "");

	if (prefsAccessibilityOption == 'TRUE')
	{
	    rtnStr = addAccessibility(rtnStr);
	}

	if (isBlogSite == false) {
	    dom.copyAssets(assetList);

	    var scriptStr = FlashObjectFuncName + '("' + id + '");';
	    dom.addJavaScript(scriptStr, false);
	}
	
	return rtnStr;
}


function addAccessibility(rtnStr) {
   var cmdFile = dreamweaver.getConfigurationPath() + "/Commands/Object Options.htm";
   var cmdDOM = dreamweaver.getDocumentDOM(cmdFile);
 
   cmdDOM.parentWindow.setFormItem(rtnStr);
   dreamweaver.popupCommand("Object Options.htm");
   return (cmdDOM.parentWindow.returnAccessibilityStr(rtnStr));	
}
