$(document).ready(function(){
	$('#form_contatti2').animate({opacity:0}, 1);
	$("a.fancy").fancybox({ 'zoomSpeedIn': 100, 'zoomSpeedOut': 100, 'overlayShow': true}); 
	$('.hide').hide();
		
	$('a.port').click(function(){
		$.scrollTo($('#a_portfolio'), 1000);
	});
	$('a.chi').click(function(){
		$.scrollTo($('#top'), 1000);
	});
	$('a.cont').click(function(){
		$.scrollTo($('#contatti'), 1000);
	});

	$('#textfield').blur(function(){
		if($('#textfield').val() == "") {
			$("#n_novalid").html("Inserire nome");
			$("#textfield").css('border', '1px solid red');
			textfield.focus();
			return false;
		}else {
			$("#n_novalid").html("");
			$("#textfield").css('border', '1px solid green');
		}
	});
	
	$('#textfield2').blur(function(){
		if($('#textfield2').val() == "") {
			$("#m_novalid").html("Inserire mail");
			$("#textfield2").css('border', '1px solid red');
			textfield2.focus();
			return false;
		}else {
			$("#m_novalid").html("");
			$("#textfield2").css('border', '1px solid green');
		}
		
		var regexp = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
		var mail = $('#textfield2').val();
		if (!regexp.test(mail)){
			$("#m_novalid").html("Inserire mail valida");
			$("#textfield2").css('border', '1px solid red');
			textfield2.focus();
			return false;
		}else {
			$("#m_novalid").html("");
			$("#textfield2").css('border', '1px solid green');
		}
	});
	
	$('#textarea').blur(function(){
		if($('#textarea').val() == "") {
			$("#t_novalid").html("Inserire messaggio");
			$("#textarea").css('border', '1px solid red');
			textarea.focus();
			return false;
		}else {
			$("#t_novalid").html("");
			$("#textarea").css('border', '1px solid green');
		}
	});
});

function controllo(){
	with(document.form1) {
		if(textfield.value=="") {
			$("#n_novalid").html("Inserire nome");
			$("#textfield").css('border', '1px solid red');
			textfield.focus();
			return false;
		}else {
			$("#n_novalid").html("");
			$("#textfield").css('border', '1px solid green');
		}
		
		if(textfield2.value=="") {
			$("#m_novalid").html("Inserire mail");
			$("#textfield2").css('border', '1px solid red');
			textfield2.focus();
			return false;
		}else {
			$("#m_novalid").html("");
			$("#textfield2").css('border', '1px solid green');
		}
		
		var regexp = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
		if (!regexp.test(textfield2.value)){
			$("#m_novalid").html("Inserire mail valida");
			$("#textfield2").css('border', '1px solid red');
			textfield2.focus();
			return false;
		}else {
			$("#m_novalid").html("");
			$("#textfield2").css('border', '1px solid green');
		}
		
		if(textarea.value=="") {
			$("#t_novalid").html("Inserire messaggio");
			$("#textarea").css('border', '1px solid red');
			textarea.focus();
			return false;
		}else {
			$("#t_novalid").html("");
			$("#textarea").css('border', '1px solid green');
		}
	}
	$('#tasto_invia').animate({opacity:0}, 500);
	var nomek = $('#textfield').val();
	var mailk = $('#textfield2').val();
	var testok = $('#textarea').val();
	$('#formm').animate({opacity:0}, 500);
	ajaxGet("inviaMail2.php?n="+nomek+"&m="+mailk+"&t="+testok, myHandler, "form_contatti2");
	$('#form_contatti2').animate({opacity:100}, 500);
	return false;
}