
function checkEmail(email)
{
	mask = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					
	if (mask.test(email)){
		return true;
	}
	else return false;
}

function addDivElement(id, text)
{
	$("#" + id).after('<div id="div_' + id + '" style="display: none; margin: 3px; color:#990000;">' + text + '</div>');
	$("#div_" + id).animate({opacity: "show", height: "show"}, 500);
}

function checkForm()
{	
	
	var validForm = true;

	$("#regForm input, textarea").each(function (i) {
		if (this.type != 'submit' && this.type != 'reset' && this.name != 'email') {
			
			if (this.value == '') {
				
				validForm = false;
				
				if (!$("#div_" + this.id).html()) {
					addDivElement(this.id, 'Необходимо указать значение!');
				}
				
			} else {
				
				if ($("#div_" + this.id).html()) {
					$("#div_" + this.id).remove();
				}
			}
			
		} else {
			if(this.name == "email") {
								
				if (!checkEmail(this.value)) {
					
					validForm = false;
					
					if (!$("#div_" + this.id).html()) {
						addDivElement(this.id, 'Неверный формат e-mail!');
					}
				} else {
					if ($("#div_" + this.id).html()) {
						$("#div_" + this.id).remove();
					}
				}
			}
		}
	});
	
	return validForm;
}