Plugins.ThreeGiG.ProspectDirector.BuiltIn.OpenEmailClientMessageAction =
PD.Actions.ActionDefinition.extend({

    init: function (options) {

        this._super({
            id: "open-email-client-message",
            pluginId: "builtin",
            name: "Open Email Client Message",
            description: "Opens an email for sending using the default mail client of the user.",
            parameters: [
                new PD.Actions.ActionParameterDefinition({
                    name: "To",
                    type: PD.Actions.ActionParameterType.STRING,
                    optional: true,
                    description: "The email address of the recepient."
                }),
                new PD.Actions.ActionParameterDefinition({
                    name: "CC",
                    type: PD.Actions.ActionParameterType.STRING,
                    optional: true,
                    description: "The email addresses to CC."
                }),
                new PD.Actions.ActionParameterDefinition({
                    name: "Subject",
                    type: PD.Actions.ActionParameterType.STRING,
                    optional: true,
                    description: "The subject of the email."
                }),
                new PD.Actions.ActionParameterDefinition({
                    name: "Body",
                    type: PD.Actions.ActionParameterType.STRING,
                    optional: true,
                    description: "The body of the email."
                }),
            ]
        });

    },

    method: function (to, cc, subject, body) {

        var mailto = "mailto:";
        var params = "";

        if (to != null) {
            mailto += encodeURIComponent(to);
        }
        
        params += this._buildParamsString(params, "cc", cc);
        params += this._buildParamsString(params, "subject", subject);
        params += this._buildParamsString(params, "body", body);
        
        window.location.href = mailto + params;

    },
    
    _buildParamsString: function (params, name, value) {

        var result = "";

        if (value != null) {
            result += (params.length == 0 ? "?" : "&") + name + "=" + encodeURIComponent(value);
        }

        return result;
        
    }

});