/**
 * @author cristiano
 */

function NewsletterSubscribe()
{
	this.script_page = "/ajax/newsletter.php";
	
	this.sendSubscription = function()
	{
		this.setLoadingSrc("/immagini/newsl_loader.gif");
		this.setLoadingTarget(document.getElementById("newsl_response"));
		this.setTarget(this.handleResponse);

		var email = document.getElementById('newsl_email');
		
		if (!email.value.match(/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})){1}$/))
		{
			alert("E' necessario inserire un'email valida.");
			email.focus();
		}
		else
		{
			this.params["email"] = email.value;
			this.makeRequest(this.script_page);
		}
	}
	
	this.handleResponse = function(response)
	{
		var vars = decodeUrlVars(response);
		
		if (vars['success'] == 'yes')
			document.getElementById('newsl_email').value = "Indirizzo E-mail...";
		else
			document.getElementById('newsl_email').focus();
		
		document.getElementById('newsl_response').innerHTML = '<a href="javascript:;" onclick="newsl.sendSubscription();"><span class="footer_newsletter_dx"></span></a>';
		alert(vars['messaggio']);
	}
}

NewsletterSubscribe.prototype = new AjaxModule();
NewsletterSubscribe.prototype.constructor = NewsletterSubscribe;
