$(document).ready(function(){
	jQuery.validator.addMethod("phone", function(phone_number, element) {
	    phone_number = phone_number.replace(/\s+/g, "");
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^([\+]?[0-9]*[0-9\-\ \.\/\\]*[0-9]*)$/);
	}, "Please specify a valid phone number");

	jQuery.validator.addMethod("sito", function(sito_web, element) {
	    sito_web = sito_web.replace(/\s+/g, "");
		return this.optional(element) || sito_web.length > 9 &&
			sito_web.match(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/);
	}, "Please specify a valid URL");

    $("#frmPrv").validate({
	    errorElement: "span",
		rules: {
			nome: {
				required: true,
				minlength: "3"
			},
			email: {
				required: true,
				email: true
			},
			telefono: {
				 phone: true,
				 rangelength: [10, 19]
			},
			sito: "sito",
			autorizzazione: "required"
		},
	    messages: {
			nome: {
				required: "Nome richiesto",
				minlength: "Nome troppo corto"
			},
			email: {
				required: "Email mancante",
				email: "Email non valida"
			},
			telefono: {
				phone: "Telefono non valido",
				rangelength: "Telefono non valido"
			},
			sito: "Indirizzo Web non valido",
			autorizzazione: "Per continuare devi accettare le policies sulla privacy"
		}
	});
  });

