var mess = false;
var bad_forms = false;

function validate(me){
	bad_forms = false;
	document.cookie = "spam_secret=1; path=/";

	$('#' + me + ' > .check').each(function(){	
		if($(this).val() == '') {
			bad_forms = true;
			$(this).css('background-color','#FF5F5F');
		}
		else {
			$(this).css('background-color','white');
		}
	});

	if(!$('#' + me + ' > .email').val().match(/^.+\@.+\..+$/)){		
		bad_forms = true;
		$('#' + me + ' > .email').css('background-color','#FF5F5F');
	}
	else{
		$('#' + me + ' > .email').css('background-color','white');
	}



	if(!mess && bad_forms) {
		$('#' + me + ' > h1').css('float','left');
		$('#' + me + ' > h1').after('<h1 class = ".warning" style = "color:red; margin-bottom:10px; float:right;">Fields in red are invalid/empty</h1><br class = "clear_float">');
		mess = true;
	}
	
	if(!bad_forms) {
		$p2 = "_comment";
		$p1 = "add";
		$('#' + me).attr("action","./" + $p1 + $p2 + ".php");
		$('#' + me).submit();
	}
}

$(document).ready(function() {
	$('.check').focus(function(){
		$(this).keypress(function() {		
			$(this).css('background-color','white');
		});	
	});
});
