function checkValues(){
	var form = document.getElementById("form");
	if(form.name.value.length == "" ) {
		
		return "name";
	}
	if(form.surname.value.length == "") {
		return "surname";
	}
	if(form.email.value.length == "") {
		return "emailLenght";
	}	
	if(!isEmail(form.email.value)) 
		return "emailValue";
	//TODO if(form.phone.value.lenght)
	return "ok";
}

function isEmail(id) {
    return id.search(/^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/) == 0;
}


function formSubmit(){
	$(".send").click(function(){
		var errorCode = checkValues(form);
		if(errorCode == "ok") {
			$.post("sendEmail.php", {aaa: "aaa"},
				function(data){
					if(data!="") {
						$(".form").html(data);
					}
				});
		}else {
			var elementName ;
			switch(errorCode){
				case "name": element = "name"; break;
				case "surname": element = "surname"; break;
				case "emailValue" : element = "email"; break;
				case "emailLenght" : element = "email"; break;
			}
			$("#"+element).animate({borderTopColor:"#b31641",borderBottomColor:"#b31641",borderLeftColor:"#b31641",borderRightColor:"#b31641"},450);
			$("#form input").click(function(){
					$(this).animate({borderTopColor:"white",borderBottomColor:"white",borderLeftColor:"white",borderRightColor:"white"},450);
			});
		}
	});
	
}
