/*------------------------------------------------------------------------------
 *  innerLabel_validation.js
 *------------------------------------------------------------------------------
 * 	AUTHOR  : E.PERREAU	
 *  PURPOSE : a small update to the orginal validation routine to check against innerlabels to make sure the labels are not submitted as values
 *  Version : 1.1
 *  Last CHange: 18th August 2010
 *  Path
 *
 ------------------------------------------------------------------------------*/
 
 
 
$('form:has(.required)').live('submit', function() 
{
	var ok = true;
	   
	   $('.required',this).each(function()
	   {
	   		
	   		
	   		//if the value is empty or the innerlable class applied	   
	   		if ((!$(this).val()) ||  ($(this).hasClass('jIL_labelled')) )
	       	{
	            ok = false;
	            
	            //apply warn class
	            $(this).addClass('warn');
	            //apply inner labels
	            if($(this).hasClass('innerlabel'))
	        	{
	            	$('input.innerlabel').innerLabel();
	            	$(this).addClass('jIL_labelled');
	            }
	        }
	        else
	        {
	       		$(this).removeClass('warn');
	       	}
	   });
	     
	   if(!ok)
	   {
	   		var error = $(this).find('#form_error');
	       	$(this).find('.warn').eq(0).focus();
		   	error.hide().find('.error').remove();
		   	error.append('<p class="error">Please fill in all the required fields</p>').fadeIn();
	 	}
	   
	   return ok;
	});
