﻿function EnableLoginEmailValidation(id) {
    $('#' + id).blur(function () {
        var userName = $(this).val();

        //check valid email address    
        var atpos = userName.indexOf("@");
        var dotpos = userName.lastIndexOf(".");
        var validationMessageElement = $(this).parent().children('#login_email_validationMessage');

        if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= userName.length) {
            validationMessageElement.html('Geen geldig e-mail adres. Denk aan @-teken en extensie (bijvoorbeeld: .nl of .com)');
        }
        else {
            validationMessageElement.html('');
        }
    });
}

function ajaxLoader(options) {
    //instance
    this.delay = (options.delay) || (options.delay == 0) ? options.delay : 1000;
    this.startAction = options.startAction;
    this.stopAction = options.stopAction;
    this.hasStarted = false;   
}
    
ajaxLoader.prototype.start = function () {
    var that = this;
    var execute = function () {
        that.hasStarted = true;
        that.startAction();
    }

    this.timeoutHandle = setTimeout(execute, this.delay);
}

ajaxLoader.prototype.stop = function () {
    clearTimeout(this.timeoutHandle);
    if (this.hasStarted) {
        if (this.stopAction)
            this.stopAction();
    }
}
