﻿jQuery.validator.addMethod("validdate", function(value, element) {
    if (value.length == 0 || value == '__/__/____')
        return true;

    return $(element).ValidateDate(value);
}, "(dd/mm/yyyy)");

jQuery.validator.addMethod("compare", function(value, element) {
    // Get the email value.
    var email = $('.question input[name=SubscriberEmail]').val();
    return value == email;
}, " ");


function showErrors(errorMap, errorList) {
    with (this) {
        if (errorList.length > 0) {
            $(errorList).each(function() {
                $(this.element).parents('.question:first').addClass('error'); //.find('p.error').html(this.message);
            });
        } else if (typeof (lastElement) !== 'undefined') {
            $(lastElement).parents('.question:first').removeClass('error');
        }
    }
};

$(document).ready(function() {
    // Add masks
    $('.validdate').mask('99/99/9999');
    $('.question input[name=MobileNumber]').mask('99 9999 9999');
    $('.question input[name=Postcode]').mask('9999');

    $('.SubmitButton input').click(function(e) {
        return $('.StandardForm').validate({
            showErrors: showErrors
        }).form();
    });
});

