$(document).ready( function(){
	/*
		Al click sparisce il valore di default e cambia lo stile.
		All'uscita, se non è stato inserito niente, torna il valore di default
	*/
	$('.default_value').each( function(){
		$(this).attr( 'start_value', $(this).val() );
		if( $(this).attr('start_value') == $(this).val() ){
			$(this).css('font-style', 'italic');
			$(this).css('color', '#888');
		}

		$(this).bind( 'focus', function(){
			if( $(this).val() == $(this).attr('start_value') ){
				$(this).css('font-style', 'normal');
				$(this).css('color', '#333');
				$(this).val('');
			}
		} );

		$(this).bind( 'focusout', function(){
			if( $(this).val()=='' ){
				$(this).css('font-style', 'italic');
				$(this).css('color', '#888');
				$(this).val( $(this).attr('start_value') );
			}
		});
	} );
});

/**
  * Verifica che un campo sia stato compilato e fa il submit del form
  *
  *$formid string	id del form da verificare
  *
*/
function check_and_submit(formid){
	all_ok = true;
	$("#"+formid+" input.mandatory").each( function(){
		if( $(this).val()=="" || $(this).val()==$(this).attr("start_value") ){
			all_ok = false;
		}
	});
	
	if( all_ok )
		$("#"+formid).submit();
	else
		alert( "Compilare tutti i campi!" );
}


