$(document).ready(
	function() {
		// bind a submit event to the form
		$('form').submit(checkRequired);
		// remove the outline and icon when a required field get focus
		$('.required').focus(function() { $(this).css("border-color","#CCC").next().remove(); });
		
		$('#company').keyup(setVATStatus);
	}
);

// function that checks if all required fields are set
function checkRequired() {
	var correct = true;
	// all required fields
	var required = $('.required');
	// delete all error images
	$('.requiredEmpty').remove();
	
	// check the value of each required field
	required.each(
		function() {
			if($(this).val() == '') {
				correct = false;
				$(this).css("border-color","#FE523F").after("<img src='images/icons/exclamation.png' border='0' class='requiredEmpty' />");
			} else {
				$(this).css("border-color","#CCC");
			}
		}
	);

	return correct;
}

function setVATStatus()
{
	if($('#company').val() != '')
	{
		$('#vatRow').show();
		if(!$('#vat').hasClass('required'))
			$('#vat').addClass('required');
	}
	else
	{
		$('#vat').val('');
		$('#vat').removeClass('required');
		$('#vatRow').hide();
	}
}