
// -----------------------------------------------------------------------------
// Quick calls

function newsalert_register(form)
{
	newsalert(form, false, false);
}

function newsalert_unregister(form)
{
	newsalert(form, true, false);
}

// -----------------------------------------------------------------------------
// Real calls

function newsalert(form, unregister, massive)
{
	if (form.email.value.length == 0 || form.email.value.indexOf("@") == -1)
	{
		if (shortlang == "it")
		{
			alert("Inserire un'email valida.");
		}
		else
		{
			alert("Insert a valid email.");
		}
		return;
	}
	
	if (!form.autorizzo.checked)
	{
		if (shortlang == "it")
		{
			alert("E' necessario autorizzare per i dati personali.");
		}
		else
		{
			alert("It is necessary to authorize for personal data.");
		}
		return;
	}
	
	var pars = $(form).serialize(true);
	pars.unregister = unregister;
	var url = contextPath + "/" + shortlang + "/ajax/emailAlertRegister.action";
	
	if (massive)
	{
		url = contextPath + "/" + shortlang + "/ajax/emailAlertRegisterMassive.action";
	}
	
	new Ajax.Request(url,
	{
		method: "post",
		
		parameters: pars,
		
		onSuccess: function (t)
		{
			if (shortlang == "it")
			{
				alert("Il messaggio di conferma è stato inviato all'email specificata: seguire le istruzioni nel messaggio.");
			}
			else
			{
				alert("The confirmation message has been sent to the email specified: follow the instructions on that message.");
			}
		},
		
		onFailure: function (t)
		{
			if (shortlang == "it")
			{
				alert("Non è stato possibile inviare il messaggio di conferma, controllare che l'indizizzo email esista e sia attivo per ricevere messaggi.");
			}
			else
			{
				alert("Couldn't send the confitmation message, check that email field is correct, and the email is able to receive messages.");
			}
		}
	});	
}