//FUNZIONI CONTROLLO MODULO D'ISCRIZIONE
function ctrl_form () {
	var df = d.forms['form2006'];

	var flg = 1;
	var flg_txt = 1;
	var flg_tel = 0;
	var flg_gg = 1;

	var elm_focus;
	var elm_tel = new Array();
	var x = 0;
	var elm_iscr;
	var txt_gg;

	for (i=0;i<df.elements.length;i++) {
		switch (df.elements[i].name) {
			case "nome":
			case "cognome":
			case "via":
			case "city":
			case "sex":
			case "dscp":
			case "iscr":
				if (df.elements[i].value=="") {
					df.elements[i].previousSibling.previousSibling.style.color = "#cc0000";
					df.elements[i].style.backgroundColor = "#ddeeff";

					if (flg) {
						elm_focus = i;
						flg_txt = 0;
					}
				}
				break;
			case "tel1":
			case "tel2":
			case "cell":
			case "mail":
				if (df.elements[i].value) {
					flg_tel = 1;
					elm_tel = "";
				}
				if (!flg_tel) {
					elm_tel[x] = i;
					x++;
				}
				break;
			case "gg[]":
				var chk = df.elements['gg'];
				var gg = 0;

				switch (df.elements['iscr'].value) {
					case "carnet":
						for (n=0;n<chk.length;n++) {
							if (chk[n].checked==true) gg++;
						}

						if (gg>5) {
							txt_gg = "Con il tipo d'iscrizione CARNET, Lei può partecipare al massimo 5 giornata di laboratorio.";

							for (n=0;n<chk.length;n++) {
								chk[n].checked=false;
							}
							flg_gg = 0;
						} else if (gg==0) {
							txt_gg = "Selezionare i giorni (al massimo 5) in cui Lei vuole partecipare al laboratorio.";
							flg_gg = 0;
						}
						break;
					case "giornaliera":
						for (n=0;n<chk.length;n++) {
							if (chk[n].checked==true) {
								gg = 1;
								break;
							}
						}

						if (!gg) {
							txt_gg = "Selezionare il giorno che Lei vuole partecipare al laboratorio.";
							flg_gg = 0;
						}
						break;
					default:
						break;
				}

				if (!flg_gg) {
					chk[0].previousSibling.previousSibling.style.color = "#cc0000";
				}
				break;
			default:
				break;
		}
	}

	var txt = "";
	if (!flg_txt) {
		txt += "Per favore, riempite i campi evidenziati";
	}
	if (!flg_tel) {
		if (!flg_txt) {
			txt += ",\n";
			txt += "e indicate";
		} else {
			txt += "Indicate";
		}

		txt += " almeno un numero di telefono o l'indirizzo e-mail per l'eventuale comunicazione";

		for (n=0;n<elm_tel.length;n++) {
			df.elements[elm_tel[n]].previousSibling.previousSibling.style.color = "#0000cc";
			df.elements[elm_tel[n]].style.backgroundColor = "#ccffee";
		}
	}
	if (txt) txt += ".";

	if (txt_gg) {
		if (txt) txt += "\n";
		txt += txt_gg;
	}

	if (txt) {
		window.alert(txt);

		if (elm_focus) df.elements[elm_focus].focus();
		else df.elements['gg'][0].focus();

		return false;
	} else {
		return true;
	}
}

//CONTROLLO GIORNI INTERESSATI
function ctrl_gg (elm) {
	var df = elm.form;
	var gg_input = df.elements['gg'];
	var n = gg_input.length;
	var gg_array = new Array(n);

	for (i=0;i<n;i++) {
		gg_array[i] = gg_input[i];
	}

	switch(elm.options[elm.selectedIndex].value) {
		case "effettiva":
			for (i=0;i<n;i++) {
				gg_array[i].type = "checkbox";
				gg_array[i].checked = true;
			}
			break;
		case "giornaliera":
			for (i=0;i<n;i++) {
				gg_array[i].type = "radio";
				gg_array[i].checked = false;
			}
			break;
		default:
			for (i=0;i<n;i++) {
				gg_array[i].type = "checkbox";
				gg_array[i].checked = false;
			}
			break;
	}
}
