﻿function formLoadAction(form) {

    var cform = "form#" + form;

    jQuery.validator.addMethod("isInstallerNameValid", function() 
    {

            if ($('#InstallerName').val().length > 0) 
            {
                return true;
            }
            else 
            {
                return false;
            }
    }
    );

    jQuery.validator.addMethod("isInstallerEnterpriseValid", function() 
    {

            var x = $('#InstallerEnterprise').val();
            var y = x.length;
            if (y > 0) 
            {
                return true;
            } else 
            {
                return false;
            }
    }
    );


    jQuery.validator.addMethod("isMatosValid", function() 
    {
        if (($('#adoucisseur_id')[0]).checked == true || ($('#purificateur_id')[0]).checked == true || ($('#filtre_id')[0]).checked == true || ($('#antitarte_id')[0]).checked == true) 
        {
            return true;
        } 
        else 
        {
            return false;
        }
    }
    );

    jQuery.validator.addMethod("isInstallerPhoneNumberValid", function() 
    {

            if ($('#InstallerPhoneNumber').val().length > 0) 
            {
                return true;
            } 
            else 
            {
                return false;
            }

    }
    );

    jQuery.validator.addMethod("isInstallerMailValid", function() 
    {

            if ($('#InstallerMail').val().length > 0) 
            {
                return true;
            } else 
            {
                return false;
            }

    }
    );

    jQuery.validator.addMethod("isInstallerFirstnameValid", function() 
    {

            if ($('#InstallerFirstname').val().length > 0) 
            {
                return true;
            } else 
            {
                return false;
            }

    }
    );

    jQuery.validator.addMethod("isInstallerAddressValid", function() 
    {

            if (($('#InstallerAddress').val()).length > 0) 
            {
                return true;
            }
            else 
            {
                return false;
            }

    }
    );

    jQuery.validator.addMethod("isInstallerZipcodeValid", function() 
    {

            if ($('#InstallerZipCode').val().length > 0) 
            {
                return true;
            } 
            else 
            {
                return false;
            }

    }
    );

    jQuery.validator.addMethod("isInstallerCityValid", function() 
    {

            if ($('#installer_ville_id').val().length > 0 || ($('#InstallerCity').attr('disabled') == false)) 
            {
                return true;
            }
            else 
            {
                return false;
            }

    }
    );


    $(cform).validate({
        rules: {
            Mail: {
                required: true,
                email: true
            },
            Login:
            {
                required: true,
                minlength: 6
            },
            InstallerName:
            {
                isInstallerNameValid: true
            },
            InstallerFirstname:
            {
                isInstallerFirstnameValid: true
            },
            InstallerAddress:
            {
                isInstallerAddressValid: true
            },
            InstallerZipCode:
            {
                isInstallerZipcodeValid: true
            },
            InstallerMail:
            {
                email: true,
                isInstallerMailValid: true
            },
            InstallerEnterprise:
            {
                isInstallerEnterpriseValid: true
            },
            InstallerPhoneNumber:
            {
                isInstallerPhoneNumberValid: true
            },
            TypeDevice:
            {
                isMatosValid: true
            },
            InstallerCity:
            {
                isInstallerCityValid: true
            },
            City:
            {
                required:true
            }
        },
        messages: {
            Mail: ' ',
            Login: ' ',
            InstallerName: ' ',
            InstallerFirstname: ' ',
            InstallerAddress: ' ',
            InstallerZipCode: ' ',
            InstallerPhoneNumber: ' ',
            InstallerEnterprise: ' ',
            InstallerMail: ' ',
            TypeDevice: ' ',
            InstallerCity: ' ',
            City:' '

        },
        ignore: ".ignore",
        success: function(label) { label.addClass("valid").fadeOut(5000); }
    })

    $(cform).submit(function() {
        $(cform).valid();
    });
}