var sitepath = "http://www.scelgolaliberta.it/wp-content/themes/liberta";

function convalidaCapitolo(){
var result = "";
var captemail = document.formcapitolo.captemail.value
var captname = document.formcapitolo.captname.value
if(!captemail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)){
result = "Indirizzo e-mail mancante o non valido";
$("#confermacapitolo").html(result);
$("#confermacapitolo").fadeIn("slow");
}else if(captname.length<1){
result = "Inserirsci il tuo nome";
$("#confermacapitolo").html(result);
$("#confermacapitolo").fadeIn("slow");
}else{
var datastr ='captemail=' + captemail + "&captname=" + captname;
$("#confermacapitolo").css("display", "block");
$("#confermacapitolo").html('Invio in corso...');
$("#confermacapitolo").fadeIn("slow");
setTimeout("send('"+datastr+"')",2000);
}
}


function send(datastr){
$("#result").hide();
	$.ajax({	
		type: "POST",
		url: sitepath+"/sendCapitolo.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#confermacapitolo").fadeIn("slow");
		$("#confermacapitolo").html(html);
		document.formcapitolo.reset();
		setTimeout('$("#confermacapitolo").fadeOut("slow")',2000);
		confermaCapitolo();
	}
	});
}

function writefield(id,testo){
if(!document.getElementById(id).value.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)){
document.getElementById(id).value = testo;
}
}
function resetfield(fieldid,text){
var valore = document.getElementById(fieldid).value;
if(valore==text){
document.getElementById(fieldid).value = "";
}
}
function ripristinaCampi(fieldid, text){
if(document.getElementById(fieldid).value==""){
document.getElementById(fieldid).value = text;
}
}
