/**
 * jQuery MV_requiredFields plugin
 * Copyright (C) MediaVault International 2009
 * 
 * @param Array fieldArray An array with the
 * field IDs from the form.
 * 
 * @param string msg The message to alert with
 * if the requirements failed.
 * 
 * @return bool False if the requirements fails.
 */
function MV_requiredFields(fieldArray)
{
	
	/**
	 * Reverse the array so the tooltip will
	 * alert on the first required field and
	 * not the last.
	 */
	fieldArray.reverse();

	valid = 1;
	
	jQuery.each(fieldArray, function() {

		formElement = this[0];
		msg = this[1];
		value = ( typeof(this[2]) != "undefined" ) ? this[2] : ""; 
		
		obj = $("#" + formElement)

		if ( !MV_requiredFields_checkValue(obj.val(), value) )
		{
			
			obj.addClass("backgroundWarning");
			obj.MV_tooltip(msg, { onevent : 'other', className : 'MV_tooltip_notice', noClose : 1 } );

			valid = 0;

		}
		else
		{
			
			obj.removeClass("backgroundWarning");
			
		}

	});
	
	return valid;
	
}

function MV_requiredFields_checkValue(objVal, value)
{
	
	if ( value == "" )
	{

		if ( objVal == value )
		{
					
			return 0;
					
		}
		else
		{
					
			return 1;
					
		}
				
		
	}
	else
	{

		if ( objVal == value )
		{
					
			return 0;
					
		}
		else
		{
					
			return 1;
					
		}
				
	}
			
}
