﻿var window_options = { IsModal: true, ForeColor: '#000', Font: { Family: 'helvetica, verdana', Size: '8pt' }, Background: { Color: '#C1BAAD' }, TitleBar: { Background: { Color: '#790102'}, Text: "Dealer Portal"} }

// LoginEmailCollector class
// --- provides a dialog for collecting and saving login user's email address to store in their login user record
function LoginEmailCollector(instanceName, ajaxObj) {
    LoginEmailCollector.baseConstructor.call(this, instanceName, ajaxObj, "/ajax/login_email_collector.ashx", false, "/images/");
    this.Window.LoadOptions(window_options);
    this.Window.Size.Set(400, 260);
    this.Window.StatusBar.Visible = true;
    this.Window.TitleBar.MaximizeButton.Visible = false;
    this.Window.TitleBar.MinimizeButton.Visible = false;
    this.LoginID = 0;
    this.DealerType = null; // can be "wilrich" or "wishek"
}
Extend(LoginEmailCollector, AjaxProcessorBase);

LoginEmailCollector.prototype.RenderIfNeeded = function() {
    this.Execute(QueryString.Create({ mode: "renderIfNeeded", name: this.Name, id: this.LoginID, dealerType: this.DealerType }), null, function(returnObj, identifier) { return false; }, true, null, __callback);
    var v_this = this;

    function __callback(returnObj, identifier) {
        v_this.Window.Show();
        v_this.Window.SetContent(returnObj.ReturnMessage);
        v_this.Window.StatusBar.SetText("Please enter your email...");
        returnObj.CanClose = false;
        return false;
    }
}
LoginEmailCollector.prototype.Render = function() {
    this.Execute(QueryString.Create({ mode: "render", name: this.Name, id: this.LoginID, dealerType: this.DealerType }), null, __callback, true);
    var v_this = this;
    
    function __callback(returnObj, identifier) {
        v_this.Window.Show();
        v_this.Window.SetContent(returnObj.ReturnMessage);
        v_this.Window.StatusBar.SetText("Please enter your email...");
        returnObj.CanClose = false;
        return false;
    }
}

LoginEmailCollector.prototype.Submit = function(p_form) {
    this.SubmitForm(p_form, null, __successCallback, true, null, __failureCallback);
    var v_this = this;

    function __successCallback(returnObj, identifier) {
        v_this.Window.Close();
    }
    function __failureCallback(returnObj, identifier) {
        window_options.Size = new Size(400, 150);
        Alert(returnObj.ReturnMessage, window_options);
        window_options.Size = null;
        returnObj.CanClose = false;
        return false;
    }
}

// LoginChangePassword class
// --- provides an AJAX interface for changing the login user's password on their login
function LoginChangePassword(instanceName, ajaxObj) {
    LoginChangePassword.baseConstructor.call(this, instanceName, ajaxObj, "/ajax/login_change_password.ashx", false, "/images/");
    this.Window.LoadOptions(window_options);
}
Extend(LoginChangePassword, AjaxProcessorBase);

LoginChangePassword.prototype.Submit = function(p_form) {
    // make sure password is not empty
    if (p_form.password.value.Trim().length <= 0) {
        Alert("Password cannot be blank. Please try again", window_options);
        return false;
    }
        
    // make sure that both password and confirm password match
    if (p_form.password.value != p_form.confirmPassword.value) {
        Alert("Passwords do not match. Please try again", window_options);
        return false;
    }
    
    this.SubmitForm(p_form, null, __successCallback, true);
    var v_this = this;
    
    function __successCallback(returnObject, identifier) {
        Alert("Your password has been updated.", window_options);
    }
}
