 // --------------------------------------
function controlloForm_Bomboniere()
 // --------------------------------------
{
	var msg='';
	var avviso=true;

	// indirizzo di recapito
	var nome = document.ordine_bs.nome;
	var cognome = document.ordine_bs.cognome;
	var via = document.ordine_bs.via;
	var cap = document.ordine_bs.cap;
	var citta = document.ordine_bs.citta;
	var provincia = document.ordine_bs.provincia;
	var tel = document.ordine_bs.tel;
	var email = document.ordine_bs.email;

	// evento
	for (var i=0; i < document.ordine_bs.evento.length; i++){
   		if (document.ordine_bs.evento[i].checked){
      		var evento_val  = document.ordine_bs.evento[i].value;
      		var elem_evento = document.ordine_bs.evento[i];
      	}
   	}

   	// tipo ordine
   	if(document.ordine_bs.tipo_p.checked){
  		var tipo_p=document.ordine_bs.tipo_p.value;
  		}
  	else{
  		var tipo_p=null;
  		}

   	if(document.ordine_bs.tipo_b.checked){
		var tipo_b=document.ordine_bs.tipo_b.value;
		}
	else{
  		var tipo_b=null;
  		}

   	if(document.ordine_bs.tipo_bp.checked){
		var tipo_bp=document.ordine_bs.tipo_bp.value;
		}
	else{
  		var tipo_bp=null;
  		}
  	// quantità ordine
	var n_p  = document.ordine_bs.n_pergamene;
	var n_b  = document.ordine_bs.n_bomboniere;
	var n_bp = document.ordine_bs.n_bp;

	// personalizzazioni
	var nome_p=document.ordine_bs.nome_p;
	var data=document.ordine_bs.data_p;
	var luogo=document.ordine_bs.luogo_p;

	// ------------------------------------------------------> INIZIO CONTROLLI

	if ((nome.value==null)||(nome.value=="")){
		msg+=". Per favore inserisci il tuo Nome\n";
		nome.focus();
		avviso=false;
	}

	if ((cognome.value==null)||(cognome.value=="")){
		msg+=". Per favore inserisci il tuo Cognome\n";
		cognome.focus();
		avviso=false;
	}

	if ((via.value==null)||(via.value=="")){
		msg+=". Per favore inserisci l'indirizzo di recapito\n";
		via.focus();
		avviso=false;
	}

	if ((cap.value==null)||(cap.value=="")){
		msg+=". Per favore inserisci il cap dell'indirizzo di recapito\n";
		cap.focus();
		avviso=false;
	}

	if ((citta.value==null)||(citta.value=="")){
		msg+=". Per favore inserisci il comune dell'indirizzo di recapito\n";
		citta.focus();
		avviso=false;
	}

	if ((provincia.value==null)||(provincia.value=="")){
		msg+=". Per favore inserisci la provincia di recapito\n";
		via.focus();
		avviso=false;
	}

	if ((tel.value==null)||(tel.value=="")){
		msg+=". Per favore inserisci il telefono per eventuali comunicazioni\n";
		cap.focus();
		avviso=false;
	}

	if ((email.value==null)||(email.value=="")){
		msg+=". Per favore inserisci l'email per eventuali comunicazioni\n";
		email.focus();
		avviso=false;
	}

	if ((evento_val==null)||(evento_val=="")){
		msg+=". Per favore indica l'evento per il quale desideri ricevere le nostre proposte\n";
		//elem_evento.focus();
		avviso=false;
	}

	if (tipo_b==null && tipo_p==null && tipo_bp==null){
		msg+=". Per favore indicaci quale proposta desideri ricevere (Bomboniere ? Pergamene ? etc )\n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_p!=null && (n_p.value==null || n_p.value=="")) {
		msg+=". Per favore indicaci quante pergamene desideri ricevere \n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_p!=null && (n_p.value!=null || n_p.value!="") && (n_p.value <10)) {
		msg+=". Il numero delle pergamene deve essere superiore a 9 \n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_b!=null && (n_b.value==null || n_b.value=="")) {
		msg+=". Per favore indicaci quante bomboniere desideri ricevere \n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_b!=null && (n_b.value!=null || n_b.value!="") && (n_b.value <10)) {
		msg+=". Il numero delle bomboniere deve essere superiore a 9 \n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_bp!=null && (n_bp.value==null || n_bp.value=="")) {
		msg+=". Per favore indicaci quante bomboniere con portachiavi desideri ricevere \n";
		//tipo_b.focus();
		avviso=false;
	}

	if (tipo_bp!=null && (n_bp.value!=null || n_bp.value!="") && (n_bp.value <10)) {
		msg+=". Il numero delle bomboniere con portachiavi deve essere superiore a 9 \n";
		//tipo_b.focus();
		avviso=false;
	}

  	//nastro
  	if(document.ordine_bs.tipo_b.checked || document.ordine_bs.tipo_bp.checked){
		for (var i=0; i < document.ordine_bs.nastro.length; i++){
   			if (document.ordine_bs.nastro[i].checked){
      			var nastro_val  = true;
				break;
      		} else {
      		    var nastro_val  = false;
			}
   		}

   		if(nastro_val== false){
   			msg+=". Per favore indica almeno un colore per il nastro\n";
			avviso=false;
		}
  	}

  	//colore confetti
  	if(document.ordine_bs.tipo_b.checked || document.ordine_bs.tipo_bp.checked){
		for (var i=0; i < document.ordine_bs.colore_c.length; i++){
   			if (document.ordine_bs.colore_c[i].checked){
      			var colore_c_val  = true;
				break;
      		} else {
      		    var colore_c_val  = false;
			}
   		}

   		if(colore_c_val== false){
   			msg+=". Per favore indica almeno un colore per i confetti\n";
			avviso=false;
		}
  	}

  	//gusto confetti
  	if(document.ordine_bs.tipo_b.checked || document.ordine_bs.tipo_bp.checked){
		for (var i=0; i < document.ordine_bs.gusto.length; i++){
   			if (document.ordine_bs.gusto[i].checked){
      			var gusto_val  = true;
				break;
      		} else {
      		    var gusto_val  = false;
			}
   		}

   		if(gusto_val== false){
   			msg+=". Per favore indica almeno un gusto per i confetti\n";
			avviso=false;
		}
  	}

  	if ((nome_p.value==null)||(nome_p.value=="")){
		msg+=". Per favore inserisci i nomi che verranno stampati sulle pergamene\n";
		nome.focus();
		avviso=false;
	}

  	if ((luogo.value==null)||(luogo.value=="")){
		msg+=". Per favore inserisci il luogo dell'evento\n";
		luogo.focus();
		avviso=false;
	}

	// - - - - - - - - - - - - - - - - - - - - - - -  controlli data
	if ((data.value==null)||(data.value=="")){
		msg+=". Per favore inserisci la data dell'evento \n";
		avviso=false;
	}

	if(data.value!=null){
	   if(controlloData(data.value)){
		   // controlli sui giorni che mancano
		   var strData = data.value;
		   var gg = strData.substring(0,2);
		   var mm = strData.substring(3,5);
		   var aa = strData.substring(6);

		   if(mm.substring(0,1) == 0){
		   		mm = mm.substring(1,2);
		   }

		   var mem = parseInt(mm);
		   mem-=1;

		   // pergamene: 20gg
		   if(tipo_p!=null){
		   		if(!comparazioneData(aa,mem,gg,20)){
		   			msg+=". La realizzazione delle pergamene necessita di almeno 20 giorni da oggi ! \n";
		   			msg+=" Non consegneremo in tempo. \n";
					avviso=false;
				}
		   }

		   // bomboniere: 30 gg
		   if(tipo_b!=null){
		   		if(!comparazioneData(aa,mem,gg,30)){
		   			msg+=". La realizzazione delle bomboniere necessita di almeno 30 giorni da oggi ! \n";
		   			msg+="  Non consegneremo in tempo. \n";
					avviso=false;
				}
		   }

		   // bombo + porta: 50 gg
		   if(tipo_bp!=null){
		   		if(!comparazioneData(aa,mem,gg,50)){
		   			msg+=". La realizzazione delle bomboniere + portachiave necessita di almeno 50 giorni da oggi ! \n";
		   			msg+="  Non consegneremo in tempo. \n";
					avviso=false;
				}
		   }

	   } else {
		   	msg+=". Il formato della data evento non è corretto. \n";
			avviso=false;
	   }

	}

	// trattamento dati
	for (var i=0; i < document.ordine_bs.leggedati.length; i++){
   		if (document.ordine_bs.leggedati[i].checked){
      		var leggedati_val  = true;
      		break;
      	} else {
      		var leggedati_val  = false;
		}
   	}

   	if(leggedati_val== false){
   			msg+=". Per favore indica la tua decisione in merito al trattamento dei dati\n";
			avviso=false;
	}


	if (avviso==false) {
		alert(msg,300,150);
	}

	return avviso;
 }


 // --------------------------------------
 function controlloData(data)
 // --------------------------------------
{
  	//var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
  	var re = /^\d{2}\/\d{2}\/\d{4}$/;
 	if(!data.match(re)) {
 		return false;
 	}
	return true;
}

 // --------------------------------------
 function comparazioneData(anno,mese,giorno,tolleranza)
 // --------------------------------------
{
 	var days = 0;
	var difference = 0;

	evento = new Date(anno,mese,giorno);
	today = new Date();
	difference = evento - today;
	days = Math.round(difference/(1000*60*60*24));

	if (days < tolleranza) {
		return false;
	}
	return true;
 }

 // --------------------------------------
 function controlloForm_Esperienze()
 // --------------------------------------
 {
	var msg='';
	var avviso=true;

//alert(document.form_esperienze.nome.value);
	// indirizzo di recapito
	var nome = document.form_esperienze.nome;
	var cognome = document.form_esperienze.cognome;
	var email = document.form_esperienze.email;
	var esperienza = document.form_esperienze.esperienza;
	var giornalino = document.form_esperienze.autorizzazione_newsletter_1;

	if ((nome.value==null)||(nome.value=="")){
		msg+=". Per favore inserisci il tuo Nome\n";
		nome.focus();
		avviso=false;
	}


	if ((email.value==null)||(email.value==""))
	{
		msg+=". Per favore inserisci la tua Email\n";
		email.focus();
		avviso=false;
	}
	else
	{
			var ctrl_mail = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
			if (!ctrl_mail.test(email.value))
			{
				msg+=". Per favore, controlla: l'Email inserita non è valida\n";
				email.focus();
				avviso=false;
			}
	}


	if ((esperienza.value==null)||(esperienza.value=="")){
		msg+=". Per favore inserisci un testo per l'esperienza\n";
		esperienza.focus();
		avviso=false;
	}

	if (giornalino.checked==true && (
			document.form_esperienze.indirizzo.value==""||
			document.form_esperienze.comune.value==""||
			document.form_esperienze.cap.value==""||
			document.form_esperienze.provincia.value=="")	)
	{
		msg+=". Per favore, per ricevere il giornalino devi compilare tutti i campi del domicilio (indirizzo, comune, cap e provincia)\n";
		document.form_esperienze.indirizzo.focus();
		avviso=false;
	}

	// se c'è un errore, mostra un msg
	if (avviso==false) {
		alert(msg,300,150);
	}

	return avviso;
 }
