 $(document).ready(function(){
	var msg1 = "Gentile 2beet,\nsono il responsabile commerciale della {Nome Società},\nvorrei essere contattato da un vostro commerciale per avere informazioni ed un eventuale preventivo per lo sviluppo di una applicazione web.\nIn attesa di un cortese riscontro porgo cordiali saluti.\n{Nome Cognome}";
	var msg2 = "Gentile 2beet,\nsono {Nome Cognome} vorrei essere contattato per effettuare un colloquio informativo\npresso la vostra sede.\nIn attesa di un cortese riscontro porgo cordiali saluti.\n{Nome Cognome}";
	var msg3 = "";
	$("#sendmail").click(function(){
		var mail = $("#mail").val();
		var text = $("#text").val();
		var valid = true;
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid = false;
			$("#invalidMail").fadeIn("fast");
			setTimeout('$("#invalidMail").fadeOut("fast")',6000);
		}
		if (text.length<1) {
			valid = false;
			$("#invalidText").fadeIn("fast");
			setTimeout('$("#invalidText").fadeOut("fast")',6000);
		}
		if (valid) {
			var datastr ='mail=' + mail + '&text=' + text;
			$("#sendmail").css("display", "none");
			$("#response").css("display", "block");
			$("#response").html("Invio messaggio.... ");
			$("#response").fadeIn("slow");
			send(datastr);
			//setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
	$("#text").val(msg1);
	$("#type1").click(function(){ $("#text").val(msg1); });
	$("#type2").click(function(){ $("#text").val(msg2); });
	$("#type3").click(function(){ $("#text").val(msg3); });
});
function send(datastr){
	$.ajax({	
		type: "POST",
		url: "phpfun/mail.php",
		data: datastr,
		cache: false,
		success: function(html){
			$("#response").fadeIn("slow");
			$("#response").html(html);
			//setTimeout('$("#response").fadeOut("slow")',4000);
			//setTimeout('$("#sendmail").fadeIn("fast");',5000);
		}
	});
}
function show(){
	$("#mailcontent").fadeIn("slow");
}
$(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 300);
                return false;
            }
        }
    });
});

