﻿function captchaValidator(rule) {
    // initiate code goes here
    var validateUrl = rule.ValidationParameters["validateUrl"];

    return function(value, context) {
        if (value.length > 0) {
            var retval;
            jQuery.ajax({
                url: validateUrl,
                data: { input: value },

                type: 'post', // post is required because of the security feature of mvc2
                async: false,
                cache: false,

                dataType: 'json',
                error: function(ex) {
                    alert('error in validators.js/captchaValidator');
                },
                success: function(data) {
                    retval = data;
                }
            });
            return retval;
        }
    };
}

Sys.Mvc.ValidatorRegistry.validators["captcha"] = captchaValidator;


