function email_focus() {
	if ($(this).val() == 'tua@email.com') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function email_blur() {
	if ($(this).val() == '') {
		$(this).val('tua@email.com')
		$(this).addClass('faded');
	}	
}


function nome_focus() {
	if ($(this).val() == 'Nome') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function nome_blur() {
	if ($(this).val() == '') {
		$(this).val('Nome')
		$(this).addClass('faded');
	}	
}

function cognome_focus() {
	if ($(this).val() == 'Cognome') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function cognome_blur() {
	if ($(this).val() == '') {
		$(this).val('Cognome')
		$(this).addClass('faded');
	}	
}

function ragione_sociale_focus() {
	if ($(this).val() == 'Ragione Sociale') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function ragione_sociale_blur() {
	if ($(this).val() == '') {
		$(this).val('Ragione Sociale')
		$(this).addClass('faded');
	}	
}

function telefono_focus() {
	if ($(this).val() == 'Telefono') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function telefono_blur() {
	if ($(this).val() == '') {
		$(this).val('Telefono')
		$(this).addClass('faded');
	}	
}


function subscribe_submit() {
	email = $('#email_field').val();

	$.post('subscribe.php?json=1', $('#subscribe_form').serialize(), subscribe_result, 'json');
	$('#subscribe_button').attr("disabled","disabled");
	$('.form_message').fadeOut('fast');
	$('#loading').fadeIn('fast');
	return false;
}

function subscribe_result(data) {
	$('#loading').hide();
	if (data.error) {
		display_message(data.error);
	} else {
		display_message(data.info, 'info')
	}
	$('#subscribe_button').removeAttr("disabled");
}

function display_message(msg, type) {

	if (!type) type = 'error';

	if (type == 'error') {
		$('#error_message').html(msg).fadeIn('slow');
		setTimeout('hide_error()', 4000);
	} else {
		$('#error_message').hide();
		$('#info_message').html(msg).fadeIn('slow');
	}
}

function hide_error() {
	$('#error_message').fadeOut('slow');
}

