function error_box(item, content)
{
	$('#'+item).parent().append('<div class="error_box">'+content+'</div>');
	$('#'+item).attr('class', 'error_highlight');
	$('#'+item).fadeTo(100, 1, function(){
   		$('#'+item).focus();
  	});
}
function error_check(form)
{
	$('#'+form+' .error_box').each(function(index_el, item_el) { $(item_el).remove(); } );
	
	var focus = 0;
	var error = 0;

	$('#'+form+' fieldset').each(
		function(index_fset, item_fset)
		{	
			$('input[title]', $(this)).each(
				function(index_el, item_el)
				{
					if ( 
					 (($(this).attr('title').substring(0, 5) == "empty") && !$(this).val()) || 
					 (($(this).attr('title').substring(0, 5) == "isnum") && isNaN($(this).val())) ||
					 (($(this).attr('title').substring(0, 5) == "isnty") && (isNaN($(this).val()) || !$(this).val())) || 
					 (($(this).attr('title').substring(0, 5) == "isimg") && ($(this).val()) && ($(this).val().toLowerCase().lastIndexOf(".jpg") == -1)) || 
					 (($(this).attr('title').substring(0, 5) == "isvid") && ($(this).val()) && ($(this).val().toLowerCase().lastIndexOf(".wmv") == -1) && ($(this).val().toLowerCase().lastIndexOf(".avi") == -1) && ($(this).val().toLowerCase().lastIndexOf(".mpg") == -1) && ($(this).val().toLowerCase().lastIndexOf("mpeg") == -1))
					)
					{
						var desc;
						if ($(this).attr('title').substring(6, 100))
							desc = $(this).attr('title').substring(6, 100);
						else
						{
							if ($(this).attr('title').substring(0, 5) == "empty") desc = 'Campo obbligatorio.';
							else if ($(this).attr('title').substring(0, 5) == "isnum") desc = 'Campo numerico (decimali separati da . ex. 10.53).';
							else if ($(this).attr('title').substring(0, 5) == "isnty") desc = 'Campo obbligatorio e numerico (decimali separati da . ex. 10.53).';	
							else if ($(this).attr('title').substring(0, 5) == "isimg") desc = 'Inserire immmagini solo di formato .jpg (jpeg).';
							else if ($(this).attr('title').substring(0, 5) == "isvid") desc = 'Inserire video solo di tipo .wmv / .avi / .mpg / .mpeg.';
						}
						$(item_fset).append('<div class="error_box">'+desc+'</div>');
						
						$(item_el).attr('class','error_highlight');
						if (focus == 0) 
						{ 
							$(this).fadeTo(100, 1, function(){
   								 $(item_el).focus();
  							});
							focus = 1;
						}
						error = 1;
					}
					else
						$(this).attr('class','');
				}
			);
			$('textarea[title]', $(this)).each(
				function(index_el, item_el)
				{
					if (($(this).attr('title').substring(0, 5) == "empty") && (!$(this).val()))
					{
						var desc;
						if ($(this).attr('title').substring(6, 100))
							desc = $(this).attr('title').substring(6, 100);
						else
							if ($(this).attr('title').substring(0, 5) == "empty") desc = 'Campo obbligatorio.';
							
						$(item_fset).append('<div class="error_box">'+desc+'</div>');
						
						$(item_el).attr('class','error_highlight');
						if (focus == 0) 
						{ 
							$(this).fadeTo(100, 1, function(){
   								 $(item_el).focus();
  							});
							focus = 1;
						}
						error = 1;
					}
					else
						$(this).attr('class','');
				}
			);
		}
	);
	return error;
}