﻿var BC_EXTENSION_SECTION = "Business Catalyst";


function jsxFunction()
{
	var appName;
	if(app.name == undefined)
	{
		// JavaScript only apps
		appName = app.appName;
	}
	else
	{	
		// ExtendScript enabled apps
		appName = app.name;
	}


	//your JSX code here
	var xml = '<object>';
	xml += '<property id="success"><true/></property>';
	xml += '</object>';
	return xml;
}

/**
 * Serializes the given object so that it can be passed to Flash
 *
 * @param Object obj The object to be serialized
 * @return String The object serialized
 */
function serialize( obj ) {
	var retStr = "";

	if ( "object" == typeof( obj ) ) {
		for ( var i in obj ) {
			retStr += "<property id=\"" + i + "\">" + serialize( obj[i] ) + "</property>";
		}
		retStr = "<object>" + retStr + "</object>";
	} else {
		retStr = "<string>" + obj + "</string>";
	}

	return retStr;
};

/* set the login token on a new object hanging off of the dw object
*/
function setLoginToken(token)
{
	dw.bc.loginToken = token;
}

/* set the dreamweaver preference setting in the BC_EXTENSION section key index to specified value
*/
function setPreferenceString(key, value)
{
	dreamweaver.setPreferenceString(BC_EXTENSION_SECTION, key, value);
}

/* return the dreamweaver preference setting in the BC_EXTENSION section for the index, key
* default to defaultValue if the key is not set
*/
function getPreferenceString(key, defaultValue)
{
    var returnValue = dreamweaver.getPreferenceString(BC_EXTENSION_SECTION, key, defaultValue);
    return serialize(returnValue);
}

/* returns a five-letter language code that corresponds to the language that Dreamweaver is running in 
   for example en_EN = English, de_DE = German
*/
function getAppLanguage()
{
    var returnValue = dw.getAppLanguage();
    return serialize(returnValue);
}

/* do a site import given the path to the ste site definition file
*/
function importSite(stePath,downloadString)
{	
	// we can't pass boolean values between actionscript and javascript so convert from a string back to boolean
	var autoDownload = false;
	if (downloadString == "true") {
		autoDownload = true;
	}
	var success = site.importSite(stePath,autoDownload);
	return serialize(success);
}

/* do a site import given the path to the ste site definition file
 * stePath = path to the ste file to be imported into Dreamweaver
 * downloadString = a string with "true" or "false" to indicate whether we should download (passing a boolean from Actionscript was not working)
*/
function importSiteFromSiteManagerDialog(stePath, downloadString)
{	var autoDownload = false;
	if (downloadString == "true")
		autoDownload = true;
	var success = site.importSiteFromSiteManagerDialog(stePath, autoDownload);
	return serialize(success);
}


/* open the edit site dialog for the specified site
*/
function editSite(siteName)
{
	var success = site.editSite(siteName);
	return serialize(success);
}

/* Invokes function in panel.
*/
function callPanelFunction(fn, status)
{
    if (dw.getFloaterVisibility('BCModulePanel'))    
        dw.callPanelFunction("BCModulePanel", fn, status);
}

function getConfigurationPath() {
    var path = dw.getConfigurationPath();
    return serialize(path);
}

function getTempFolderPath() {
    var path = dw.getTempFolderPath();
    return serialize(path);
}

function removeFile(file) {
    var removeSuccess = DWfile.remove(file);
    return serialize(removeSuccess);
}

/*
*	Displays the help page associated with the input help id.
*/
function displayHelp(helpID) {
	if (helpID) {
    	dw.openHelpURL(helpID);
    }
}
function openLegalDoc(touText) {
    var result = {returnValue: ""};
    dw.runCommand("Show ToU", touText, result);
    
    return serialize(result.returnValue);
}
