// JavaScript Document
function doInvia() {
	var s=getValues(["nome","email","musicista","interesse","specifico","accetto"])
	//alert(s)
	var f=$("newsletterform")
	var o=$("sending")
	var e=$("errori")
	var t=$("iscrizioneok")
	if (f&&o) {
		o.style.height=f.clientHeight+"px"
		e.style.height=f.clientHeight+"px"
		t.style.height=f.clientHeight+"px"
		sc(f,"hide")
		sc(o,"","hide")
		callAction(["P",doInviaDone,"/_interno/newsletter.asp",s])
	}
}
function doInviaDone(m,x,a,b) {
	var id="iscrizioneok"
	var msg=""
	if (m) {
		var v=$t(x,"OK")
		if (v.length!=1) {
			id="errori"
			msg="Errore interno riprovare pił tardi"
		} else {
			v=v[0]
			if ((v.getAttribute("okdata")=="")&&(v.getAttribute("okmail")=="")) {
				for(var i=0;i<v.attributes.length;i++) {setErrore(v.attributes[i])}
				id="errori"
				setTimeout(reshow,2000)
			} else if	(v.getAttribute("okmail")!="0") {
				id="errori"
				msg="Non sono ruiscito ad inviare il messaggio<br/>Riprovare pił tardi"
			}
		}
	} else {
		id="errori"
		msg="Errore interno riprovare pił tardi"
	}
	sc($("sending"),"hide")
	var o=$(id)
	if (msg!="") {o.innerHTML=msg}
	sc(o,"","hide")
	
}
function reshow() {
	var o=$("errori")
	var f=$("newsletterform")
	sc(o,"hide")
	sc(f,"","hide")
}

function setErrore(a) {
	var o=$(a.name)
	if (o) {
		if (o.type=="checkbox") {o=$("ok"+a.name)}
	}
	if (o) {
		sc(o,(a.value=="")?"":"errore",	(a.value=="")?"errore":"")
		o.title=a.value
	}
}

function getValues(v) {
	var r=[]
	var c=""
	for(var i=0;i<v.length;i++) {
		c=getValue(v[i])
		if (c!="") {r.push(c)}	
	}
	return r.join("&")
}
function getValue(id) {
	var o=$(id)
	if (o) {
		switch(o.type) {
			case "checkbox":
				return id+"="+(o.checked?o.value:"")
				break
			case "select":
				return id+"="+o.value.replace(/\+/gi,'%2b')
				break
			default:
				return id+"="+o.value.replace(/\+/gi,'%2b')
		}
	} else {
		return ""
	}
}
