function is_email(value) 
{
	return /^[\w\-]+(\.[\w\-]+)*@[\w\-]+\.([\w\-]+\.)*[a-z]{2,}$/i.test(value);
}

function invia_gusto()
{
	var messaggio = 'Per favore, correggi i seguenti errori:\n\n';
	if(!$('nome').value || $('nome').value == "il tuo nome")
	{
		messaggio += "- Devi inserire il tuo nome!\n";
		var errore = true;
	}
	if(!$('email').value || !is_email($('email').value))
	{
		messaggio += "- Devi inserire una tua e-mail valida!\n";
		var errore = true;
	}
	if(!$('gusto').value || $('gusto').value == "il gusto che vorresti")
	{
		messaggio += "- Devi inserire il nome del gusto che vorresti!\n";
		var errore = true;
	}
	if(errore)
	{
		alert(messaggio);
		return false;
	}
	else
	{
		$('contenuto').fade('out').get('tween').chain(function() {
			var myRequest = new Request.HTML({
				url: 'ajax.php',
				method: 'post',
				update: $('contenuto'),
				onComplete: function(){
					$('contenuto').fade('in');
				}
			}).send($('form_gusto').toQueryString());
		});
	}
}

function invia_foto()
{
	var messaggio = 'Per favore, correggi i seguenti errori:\n\n';
	if(!$('nome').value || $('nome').value == "il tuo nome")
	{
		messaggio += "- Devi inserire il tuo nome!\n";
		var errore = true;
	}
	if(!$('email').value || !is_email($('email').value))
	{
		messaggio += "- Devi inserire una tua e-mail valida!\n";
		var errore = true;
	}
	if(!$('hidden_nomefile').value)
	{
		messaggio += "- Devi caricare la tua foto!\n";
		var errore = true;
	}
	if(errore)
	{
		alert(messaggio);
		return false;
	}
	else
	{
		$('contenuto').fade('out').get('tween').chain(function() {
			var myRequest = new Request.HTML({
				url: 'ajax.php',
				method: 'post',
				update: $('contenuto'),
				onComplete: function(){
					$('contenuto').fade('in');
				}
			}).send($('form_foto').toQueryString());
		});
	}
}

function invia_messaggio()
{
	var messaggio = 'Per favore, correggi i seguenti errori:\n\n';
	if(!$('nome').value)
	{
		messaggio += "- Devi inserire il tuo nome!\n";
		var errore = true;
	}
	if(!$('email').value || !is_email($('email').value))
	{
		messaggio += "- Devi inserire una tua e-mail valida!\n";
		var errore = true;
	}
	if(!$('messaggio').value)
	{
		messaggio += "- Devi scrivere un messaggio!\n";
		var errore = true;
	}
	if(errore)
	{
		alert(messaggio);
		return false;
	}
	else
	{
		$('contenuto').fade('out').get('tween').chain(function() {
			var myRequest = new Request.HTML({
				url: 'ajax.php',
				method: 'post',
				update: $('contenuto'),
				onComplete: function(){
					$('contenuto').fade('in');
				}
			}).send($('form_contatti').toQueryString());
		});
	}
}

window.addEvent("domready", function() {
									 
	// SqueezeBox
	SqueezeBox.initialize({ size: {x: 696, y: 434}});
	SqueezeBox.assign($$('a[rel=boxed]'));
	 	
	// bottone form contatti
	if($('btn_inviamessaggio'))
	{
		$('btn_inviamessaggio').addEvent('click',invia_messaggio);
	}
			
	// Top home page
	if($('flash'))
	{
		var obj = new Swiff('flash/top.swf', {
			id: 'flash_home',
			width: 1084,
			height: 596,
			container: $('flash'),
			params: {
				wMode: 'opaque'
			}
		});
	}
	
	// Top pagina storia
	if($('flash1930'))
	{
		var obj = new Swiff('flash/top1930.swf', {
			id: 'flash_storia',
			width: 1084,
			height: 596,
			container: $('flash1930'),
			params: {
				wMode: 'opaque'
			}
		});
	}
	
	// Top altre pagine
	if($('flash_small'))
	{
		var obj = new Swiff('flash/top_small.swf', {
			id: 'flash_storia',
			width: 1084,
			height: 468,
			container: $('flash_small'),
			params: {
				wMode: 'opaque'
			},
			vars: {
				pagina: pagina
			}
		});
	}
	
	// bottoni app
	if($('bottone_appstore'))
	{
		$('bottone_appstore').addEvent('click',function(){
			document.location.href = 'http://itunes.apple.com/au/app/gelato-cesare/id423400815?mt=8';
		});
		$('bottone_android').addEvent('click',function(){
			document.location.href = 'https://market.android.com/details?id=it.novaware.gelatocesare';
		});
	}
});
