/*jslint devel: false, browser: true, undef: true, unparam: true, sloppy: true, vars: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */
/*global $, Event, Tx, SSApp, SSDialog */

/**
*  This supports EmailDialog.html
*/


function MEmailDialogContext()
{
    var emailFormElement = document.getElementById('emailForm');
    this._firstTextField = Tx.findFirstTextField(emailFormElement);
    this.selectFirstTextField();
}

MEmailDialogContext.prototype.selectFirstTextField = function()
{
    if (this._firstTextField !== null) {
        SSApp.selectTextField(this._firstTextField);
    }
};

MEmailDialogContext.prototype.handleOKClicked = function()
{
    SSApp.trimTextArea('body', 2000);
    SSDialog.postFormAndOpen('emailForm');
};

MEmailDialogContext.prototype.handleFormKeyPress = function(event)
{
    if (event.keyCode === Event.KEY_RETURN && !this.formIgnoreCR) {
        this.handleOKClicked(event);
        Event.stop(event);
    }
    this.formIgnoreCR = false;
};

MEmailDialogContext.prototype.handleTextAreaKeyPress = function(event)
{
    var eventKeyCode = event.keyCode;
    if (eventKeyCode === Event.KEY_TAB) {
        this.selectFirstTextField();
        Event.stop(event);
    }
    else if (eventKeyCode === Event.KEY_RETURN) {
        this.formIgnoreCR = true;
    }
};

