/**
 * Validate form given
 * If the form has errors create a list and show them.
 * Will return false if the form should not submit.
 */
function validateForm(form) {

	var submit = true;
	var msg = '<ul class="errList">';

	// Show validation Message and hide error message div
	$('#msg').show().html('<p>Validating Form</p>');

	// Loop over form input and select elements
	$('#' + form + ' p > input, select').each(function() {

		// If element has the class required check for a value
		if($(this).hasClass('required')) {
		
			if($(this).val() == '') {
				
				// No value so add to error message and add css to mark element
				msg = msg + '<li>You must enter a value for ' + $(this).attr('id') + '</li>';
				$(this).addClass('missing').css('border', '1px solid red');
				submit = false;
			
			} else { 
				// Remove class incase it had been set on previous try
				$(this).css('border', '1px solid black').removeClass('missing');
				
			}
		}
		
	});
	
	// If errors show error message
	if (submit == false) {

		$('#msg').html(msg + '</ul>').addClass('error');
		$('.missing').first().focus();
		
	}

	// Return value on whether the form can submit or not
	return submit;
		
}

