﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/$/$-1.4.4-vsdoc.js" />
function ValidaForm(form,errori) {
    $('label.required').append('&nbsp;<strong>*</strong>&nbsp;');
    // a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
    jQuery.validator.addMethod("defaultInvalid", function (value, element) {
        return value != element.defaultValue;
    }, "");

    //$("input.maskphone").mask("(999) 999-9999999");

    jQuery.validator.messages.required = "";
    $(form).validate({
        invalidHandler: function (e, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                var message = errori;
                $("div.error span").html(message);
                $("div.error").show();
                $("div.emailsend").hide();
            } else {
                $("div.error").hide();
            }
        },
        onkeyup: false,
        submitHandler: function (form) {
            $("div.error").hide();
            form.submit();
        },
        messages: {
            //            password2: {
            //                required: " ",
            //                equalTo: "Please enter the same password as above"
            //            },
            email: {
                required: " ",
                email: "Attenzione inserire un indirizzo email valido, Esempio: tu@tuodominio.com"
                //remote: jQuery.validator.format("{0} inserire un indirizzo differente.")
            }
        },
        debug: false
    });
    $.fn.vjustify = function () {
        var maxHeight = 0;
        $(".resize").css("height", "auto");
        this.each(function () {
            if (this.offsetHeight > maxHeight) {
                maxHeight = this.offsetHeight;
            }
        });
        this.each(function () {
            $(this).height(maxHeight);
            if (this.offsetHeight > maxHeight) {
                $(this).height((maxHeight - (this.offsetHeight - maxHeight)));
            }
        });
    };

    $.fn.hoverClass = function (classname) {
        return this.hover(function () {
            $(this).addClass(classname);
        }, function () {
            $(this).removeClass(classname);
        });
    };
};
