//Messaggio del validatore
var validatorErrorMessage = "";

//Funzione che chiama l'httphandler per la validazione della singola proprietà

function ServerValidator(entityName, propertyName, value) {
	$.ajax({
			type : "POST",
			cache : false,
			data : { Entita : entityName, Proprieta : propertyName, Valore : value },
			url : "/code/httphandler/validatorhandler.ashx",
			dataType : "json",
			async : false,
			success : function(datijson) {
				validatorErrorMessage = datijson.message;
				return datijson.valid;
			}
		});
}

//Validatori per ogni entità
jQuery.validator.addMethod("Impostazioni", function(value, element) {
	ServerValidator("Impostazioni", element.name, value);
	return (validatorErrorMessage == "");

}, function() {
	return validatorErrorMessage;
});

jQuery.validator.addMethod("Pagine", function(value, element) {
	ServerValidator("Pagine", element.name, value);
	return (validatorErrorMessage == "");

}, function() {
	return validatorErrorMessage;
});

jQuery.validator.addMethod("PaginePersonali", function(value, element) {
	ServerValidator("PaginePersonali", element.name, value);
	return (validatorErrorMessage == "");

}, function() {
	return validatorErrorMessage;
});

jQuery.validator.addMethod("Utenti", function(value, element) {
	ServerValidator("Utenti", element.name, value);
	return (validatorErrorMessage == "");

}, function() {
	return validatorErrorMessage;
});
