﻿/// <reference path="jquery.js" />

// валидация логина пользователя
function usernameValidate(source, args) {
    if (args) { // функция вызвана из CustomValidator
        if (args.Value.length > 0)
            $.ajax({
                type: 'POST',
                url: '/Services/Login/RegistrationValidate.aspx/ValidateUsername',
                data: '{ value: "' + args.Value + '" }',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function(data) {
                    args.IsValid = data.d.isValid;
                    source.errormessage = data.d.message;
                }
            });
    }
}

// валидация номера телефона
function phoneValidate(source, args) {
    if (args) { // функция вызвана из CustomValidator
        if (args.Value.length > 0)
            $.ajax({
                type: 'POST',
                url: '/Services/Login/RegistrationValidate.aspx/ValidatePhone',
                data: '{ value: "' + args.Value + '" }',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function(data) {
                    args.IsValid = data.d.isValid;
                    source.errormessage = data.d.message;
                }
            });
    }
}

// валидация e-mail
function emailValidate(source, args) {
    if (args) { // функция вызвана из CustomValidator
        if (args.Value.length > 0)
            $.ajax({
                type: 'POST',
                url: '/Services/Login/RegistrationValidate.aspx/ValidateEmail',
                data: '{ value: "' + args.Value + '" }',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function(data) {
                    args.IsValid = data.d.isValid;
                    source.errormessage = data.d.message;
                }
            });
    }
}
