﻿var BC_EXTENSION_SECTION = "Business Catalyst";

/**
 * 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 dreamweaver preference setting in the BC_EXTENSION section key index to specified value
*/
function setPreferenceString(key, value)
{
	dw.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 = dw.getPreferenceString(BC_EXTENSION_SECTION, key, defaultValue);
    return serialize(returnValue);
}

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