﻿jQuery.validator.addMethod("require_from_group", function(value, element, options) {
    var valid = $(options[1], element.form).filter(function() {
        return $(this).val();
    }).length >= options[0];

    if (!$(element).data('reval')) {
        var fields = $(options[1], element.form);
        fields.data('reval', true).valid();
        fields.data('reval', false);
    }
    return valid;
}, jQuery.format("Please fill out at least {0} of these fields."));

jQuery.validator.addMethod("email_or_phone", function(value, element, options) {
    if (options[0].val().length > 0) {
        if ($.validator.methods.email.call({ optional: function() { return false; } }, options[0].val(), null) == false) {
            return false;
        }
    }

    return $.validator.methods.email.call({ optional: function() { return false; } }, options[0].val(), null) ||
        $.validator.methods.phone.call({ optional: function() { return false; } }, options[1].val(), null);
}, "*");

jQuery.validator.addMethod("phone", function(a, b) {
    a = a.replace(/\s+/g, ""); return this.optional(b) || a.length > 9 && a.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/)
}, "*"); 

function multicast() {
    if (arguments == null || arguments.length == 0) return function() { };

    var fns = [], j = 0;
    for (var i = 0; i < arguments.length; i++) {
        if (typeof (arguments[i]) == "function")
            fns[j++] = arguments[i];
    }

    return function() {
        for (var i = 0; i < fns.length; i++)
            fns[i]();
    };
}

function platformSpecificCustomizations() {
    this.customizations = function() { }
    this.addCustomization = function(customizationFunc) {
        this.customizations = multicast(this.customizations, customizationFunc);
    }
    this.runCustomizations = function() {
        this.customizations();
    }
    this.canChangeEmail = false;
    this.canChangeAvailable = false;    
    this.canChangeFileNumber = false;
    this.setSkillsSignature = function(dialog) {
    } 
}

var _customizations = new platformSpecificCustomizations();

