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;
}
}
function checknewsletter(){
var newslettername = document.newsletterform.wpnewsletter_name.value;
var newsletteremail = document.newsletterform.wpnewsletter_email.value;
if(newslettername.length<1||newslettername=="Il tuo nome"){
alert("Inserisci il tuo nome");
}else if (!newsletteremail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
alert('Indirizzo e-mail assente o non valido');
}else{
document.newsletterform.submit();
}
}

function colora(elementid, colore){
document.getElementById(elementid).style.background = colore;
}


var sitepath = "http://www.technoaware.com/ita/wp-content/themes/technoaware";

function checkprivacycert(){
	var formpath = document.certif;
	if(formpath.privacycert.checked){
	formpath.sendcertificazione.disabled = false;
	}else{
	formpath.sendcertificazione.disabled = true;
	}
}


$(document).ready(function(){
var formpath = document.certif;
$("#sendcertificazione").click(function(){
var nome = $("#nome").val();
var cognome = $("#cognome").val();
var email = $("#email").val();
var tel = $("#tel").val();
var tel2 = $("#tel2").val();
var fax = $("#fax").val();
var rsa = $("#rsa").val();
var via = $("#via").val();
var cap = $("#cap").val();
var localita = $("#localita").val();
var comune = $("#comune").val();
var provincia = $("#provincia").val();
var stato = $("#stato").val();
var cf = $("#cf").val();
var iva = $("#iva").val();

if(formpath.tipo1.checked){
var tipo1 = $("#tipo1").val();
}else{
var tipo1 = "";
}
if(formpath.tipo2.checked){
var tipo2 = $("#tipo2").val();
}else{
var tipo2 = "";
}
if(formpath.tipo3.checked){
var tipo3 = $("#tipo3").val();
}else{
var tipo3 = "";
}
if(formpath.tipo4.checked){
var tipo4 = $("#tipo4").val();
}else{
var tipo4 = "";
}
if(formpath.tipo5.checked){
var tipo5 = $("#tipo5").val();
}else{
var tipo5 = "";
}
if(formpath.tipo6.checked){
var tipo6 = $("#tipo6").val();
}else{
var tipo6 = "";
}
if(formpath.tipo7.checked){
var tipo7 = $("#tipo7").val();
}else{
var tipo7 = "";
}

var specifica = $("#specifica").val();
var sito = $("#sito").val();
var note = $("#note").val();

    while (note.indexOf("\n") != -1) {
        note = note.replace("\n", "<br/>");
    }


if (nome.length<1||cognome.length<1||tel.length<1||rsa.length<1||via.length<1||cap.length<1||localita.length<1||comune.length<1||provincia.length<1||stato.length<1||cf.length<1||iva.length<1) {
	alert('Mancano informazioni necessarie al corretto invio della registrazione.');
}
else if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
	alert('Indirizzo e-mail assente o non valido');
}
else {
	var datastr ='nome=' + nome + '&cognome=' + cognome + '&email=' + email + '&tel=' + tel + '&tel2=' + tel2 + '&fax=' + fax + '&rsa=' + rsa + '&via=' + via + '&cap=' + cap + '&localita=' + localita + '&comune=' + comune + '&provincia=' + provincia + '&stato=' + stato + '&cf=' + cf + '&iva=' + iva + '&tipo1=' + tipo1 + '&tipo2=' + tipo2 + '&tipo3=' + tipo3 + '&tipo4=' + tipo4 + '&tipo5=' + tipo5 + '&tipo6=' + tipo6 + '&tipo7=' + tipo7 + '&specifica=' + specifica + '&sito=' + sito + '&note=' + note;
	$("#risposta").css("display", "block");
	$("#risposta").html('<img src=\"'+sitepath+'/images/ajax-loader.gif\" width=\"16\" height=\"16\" alt=\"ajax-loader\"/> Invio registrazione in corso...');
	$("#risposta").fadeIn("slow");
	setTimeout("send('"+datastr+"')",2000);
	
}
return false;
	});
});

function send(datastr){
	$.ajax({	
		type: "POST",
		url: sitepath+"/sendregistrazione.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#risposta").fadeIn("slow");
		$("#risposta").html(html);
		document.certif.reset();
		document.certif.sendcertificazione.disabled = true;
		setTimeout('$("#risposta").fadeOut("slow")',2000);	
		setTimeout('$("#modulocertificazione").slideToggle("slow")',4000);
	}
	});
}
