// Comments validations

var error_icon_url = '/wp-content/themes/thegcomplot/img/ico/forms/error.gif';

$(document).ready(function() {
	$('form#respond').submit(function() {
		$('.formerror ul li').remove();
		$('.formerror').hide();
		$('form#commentform dl').removeClass("error");								  
		$('.errorMessage').remove();
		
		var hasError = false;
		$('.required').each(function() {
			if($(this).val() == '') {
				$(this).parent().parent().addClass("error");
				$(this).before('<img class="errorMessage" width="15" height="15" alt="Error" src="' + error_icon_url + '" />');
				$(this).after('<dd class="errorMessage"><strong>' + $(this).attr("title") + '</strong></dd>');
				
				var labelText = $("label[for='" + $(this).attr("id") + "']").text().replace('(*) ','').replace(':','');
				$('.formerror ul').append('<li><a href="#' + $(this).attr("name") + '">' + labelText + '</a>.</li>');
				
				hasError = true;
			}
		});
		
		if(hasError){
			$('.formerror').show();
			return false;
		}
	});
});
