function sendForm() {
	var s=["cmd=form"]
	getFieldValue("title",s)
	var vCampi=$("campi").value.split(",")
	var vNomi=$("ncampi").value.split(",")
	
	s.push("check="+encodeURI($("checkcampi").value.replace(/\+/gi,"%2b").replace(/\&/gi,"%26")))
	s.push("ncheck="+encodeURI($("ncheckcampi").value.replace(/\+/gi,"%2b").replace(/\&/gi,"%26")))
	
	var vc=[]
	var vn=[]
	var vf=[]
	getFieldValues(vCampi,vc,vf,vNomi,vn)
	s.push(vc.join("&"))
	s.push("ncampi="+vn.join(","))
	s.push("campi="+vf.join(","))
	callAction(["P",formsent,"/_interno/mail.php",s.join("&"),"T"])
}
function formsent(m,x,a,b) {
	if (m) {
		var r=x.parseJSON()
		if (r) {
			if (r.ok) {
				alert("Messaggio inviato")	
			} else {
				msg=["Non ho inviato il messaggio"]
				if (r.err!="") {msg.push(r.err.split(",").join("\n"))}
				if (r.cerr!="") {
					msg.push("Verificare:")
					msg.push(r.cerr.split(",").join("\n"))
				}
				alert(msg.join("\n"))
			}
		} else {
			alert("Errore nell'invio!")	
		}
	} else {
		alert("Errore nell'invio")	
	}
}

function getFieldValues(vf,vc,vfn,vnc,vn) {
	for(var i=0;i<vf.length;i++) {
		getFieldValueVV(vf[i],vc,vfn,vnc[i],vn)	
	}
}

function getFieldValueVV(id,vc,vfn,n,vn) {
	var o=$(id)
	if (o) {
		var s=""
		switch(o.type) {
			case "checkbox":
				if(o.checked) {s=encodeURI(o.value)}
				break
			default:
				s=encodeURI(o.value).replace(/\+/gi,"%2b").replace(/\&/gi,"%26")
		}
		if (s!="") {
			vc.push(id+"="+s)
			vfn.push(id)
			vn.push(encodeURI(n))
		}
	} else {
		alert(id+":NonTrovato")
	}
}
function getFieldValue(id,v) {
	var o=$(id)
	if (o) {
		var s=""
		switch(o.type) {
			case "checkbox":
				if(o.checked) {s=encodeURI(o.value)}
				break
			default:
				s=encodeURI(o.value).replace(/\+/gi,"%2b").replace(/\&/gi,"%26")
		}
		if (s!="") {
			v.push(id+"="+s)
		}
	}
}

String.prototype.parseJSON = function () {
    try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                this.replace(/"(\\.|[^"\\])*"/g, ''))) &&
            eval('(' + this + ')');
    } catch (e) {
        return false;
    }
};
