//=========================================================================================================
//
<!--
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2006 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
-->
//
// Feature: Insert Html Snippet
// Author:  GSR
// Module:  InsertHTMLSnippet.js
// Purpose:	To insert html snippet
// Source control start : 7/27/06	
// Updates:
// 	
//  
//
//=========================================================================================================

var helpDoc = MM.HELP_objInsertHTMLSnippet;   //gsrupdate hitch tochange

var g_file = null;
var g_return = null;

var g_rememberPrefs = true;


// ----------------------------------------

function insertSnippet(htmlsnippet)
{
	rtnStr='';

	var isBlogSite = false;
	if (dw.appName == "Contribute")
	{
	
		var dom = dw.getDocumentDOM();
	        if(dom)
	        {
	             if(CCWorkspaceManager.getManager(dom))
	              { // if its a blog, do not display the accessibility warning
	                    if(CCWorkspaceManager.getManager(dom).isBlogSite())        
	                        isBlogSite = true;
	              }
	        }
         }
         
        
	
	        htmlsnippet = dw.convertsnippettoXHTML(htmlsnippet);			
	
		rtnStr = htmlsnippet;
	
		prefsAccessibilityOption = dw.getPreferenceString("Accessibility", "Accessibility Media Options", "");

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


		/*const var bReplaceCurrentSelection = true;
		dw.getDocumentDOM().insertHTML(rtnStr, bReplaceCurrentSelection);*/
		
		if(g_return)
			g_return[0] = rtnStr;
		return true;
}

// ----------------------------------------

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));	
}


// ----------------------------------------
function receiveArguments()
{
	g_return = arguments[0];
	document.theForm.htmlcode.focus();
	
}

//-----------------------------------------

// ----------------------------------------

function commandButtons()
{
	return new Array( "PutButtonsOnBottom", 
					  "OkButton",			MM.BTN_OK,		"okclick();",
				      "CancelButton",		MM.BTN_Cancel,	"window.close();",
					  "PutButtonOnLeft",	MM.BTN_Help,	"displayHelp();");
}

function okclick()
{


 if(document.theForm.htmlcode.value.length == 0)
 {
 	alert(dw.loadString("insert htmlsnippet dialog/no code"));
 }
 else
 {

	if(!(dw.validateHTML(document.theForm.htmlcode.value)))
	{
	      	alert(dw.loadString("insert htmlsnippet dialog/not valid html error"));
	}
	else
	{ 
		window.close(); insertSnippet(document.theForm.htmlcode.value); 
	}

	
}

}