function clearForm(f){
	$("#"+f+" input, #"+f+" textarea,#"+f+" select").attr('value','');
 	$("#"+f+" input[type=checkbox]").attr('checked', false);
}
$(function(){ 
	$("form").each(function() {
		$(this).submit(function(){ 
			if (validateForm($(this))){
				return true;
			}else{
				return false;
			}
		});
	});
});
function IsEmail(email) {
            var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (regex.test(email)) return true;
            else return false;
        } 
function validateForm(aFo ){
	var	msg='Please fill the following fields:\n';		
	var mailError=' - Email address is invalid ';
	var rt=true; 
	aFo.find(".req").each(function() {
							  if (!$(this).attr("value")||($(this).attr("name")=="email"&&!IsEmail($(this).attr("value")) ) ){
								 rt=false; 
							    fName=$(this).attr("title");
							    $(this).addClass("notValid");
								msg+=fName;
								if ($(this).attr("name")=="email"&&!IsEmail($(this).attr("value")) &&$(this).attr("value") )  msg+=mailError;
								msg+="\n";
							  } 
					 }) 
 	if(!rt) alert(msg);
	return rt;
}
