
/**
*  This supports EmailDialog.html
*/

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

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

MEmailDialogContext.prototype.handleOKClicked = function()
{
    trimTextArea('body', 2000);
    openDialogForForm('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;
    }
}
