$(document).ready(function() {
	$("#sendmail").click(function() 
	{
		var valid = '';
		var isr = ' este obligatoriu.';
		var nume = $("#nume").val();
		var telefon = $("#telefon").val();
		var mesaj = $("#mesaj").val();

		if (nume.length<1) {
			valid += '<p>Campul nume'+isr+'</p>';
		}
		if (telefon.length<1) {
			valid += '<p>Campul telefon'+isr+'</p>';
		}
		if (mesaj.length<1) {
			valid += '<p>Campul mesaj'+isr+'</p>';
		}
		if (valid!='') {
			var destination = $("#contact-data").offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100);
			$("#response").fadeIn("slow");
			$("#response").html("<strong>Eroare la validare:</strong>"+valid);
		}

		else {
			var datastr ='nume=' + nume + '&telefon=' + telefon + '&mesaj=' + mesaj;
//			alert (datastr);
			$("#response").fadeIn("slow");
			$("#response").css("display", "block");
			$("#response").html("<strong>Mesajul se trimite</strong>");
			setTimeout("send('"+datastr+"')",3000);
			}
		return false;
	});
});

function send(datastr){
	jQuery.ajax ({	
		type: "POST",
		url: "js-global/form-contact.php",
		data: datastr,
		cache: false,
		success: function( success ) {
			$("#response").fadeIn("slow");
			$("#response").html("<p>" + success + "</p>");
			setTimeout('$("#response").fadeOut("slow")',8000);
		}
	});
}

