/********************************************************************************
*  Script per la gestione dei moduli                                            *
********************************************************************************/

/*
*  Restituisce il trim della stringa passata
*/
function trim(sInString)
{
	sInString = sInString.replace( /^\s+/g, "" );
	return sInString.replace( /\s+$/g, "" );
}



/********************************************************************************
*  Modulo REGISTRAZIONE OPERATORE                                               *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo di Registrazione Operatore
*/          
function moduloRegistrazioneOperatoreInvia()
{
	if(trim(document.getElementById("azienda").value) == "")
	{
		alert(pMessageAziendaMancante);
		return;
	}
	
	if(trim(document.getElementById("via").value) == "")
	{
			alert(pMessageViaMancante);
			return;
	}
	
	if(trim(document.getElementById("num").value) == "")
	{
		alert(pMessageNumeroCivicoMancante);
		return;
	}
	
	if(trim(document.getElementById("cap").value) == "")
	{
		alert(pMessageCAPMancante);
		return;
	}
	
	if(trim(document.getElementById("citta").value) == "")
	{
		alert(pMessageCittaMancante);
		return;
	}
	
	if(trim(document.getElementById("provincia").value) == "")
 	{
		alert(pMessageProvinciaMancante);
		return; 
	}
	
	if(trim(document.getElementById("nazione").value) == "")
	{
			alert(pMessageNazioneMancante);
			return;
	}
	
	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageTelefonoMancante);
		return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeOperatoreMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
		alert(pMessageCognomeOperatoreMancante);
		return;
	}
		
	if(document.getElementById("scelta1").value == "Visitare")
	{
	    if ((!document.getElementById("primoGiorno").checked) && (!document.getElementById("secondoGiorno").checked) && (!document.getElementById("terzoGiorno").checked))
	    {
	        alert(pMessageDataVisitaMancante);
		    return;
	    }
	}
	
	document.getElementById("modulo").submit();
}

/*
*  Aggiorna il modulo di Registrazione Operatore
*/
function moduloRegistrazioneOperatoreRefresh()
{
	if(document.getElementById('scelta1').checked)
	{
		document.getElementById('primoGiorno').disabled = false;
		document.getElementById('secondoGiorno').disabled = false;
		document.getElementById('terzoGiorno').disabled = false;
		document.getElementById('categorie').disabled = false;		
	}
	else
	{
		document.getElementById('primoGiorno').disabled = true;
		document.getElementById('secondoGiorno').disabled = true;
		document.getElementById('terzoGiorno').disabled = true;
		document.getElementById('categorie').disabled = true;
	}
}

/********************************************************************************
*  Modulo HOTELS                                                                *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo degli Hotels
*/
function moduloHotelsInvia()
{

	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
		alert(pMessageCognomeMancante);
		return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}

	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageTelefonoMancante);
		return;
	}
		
	if((document.getElementById('checkout').value - document.getElementById('checkin').value) <= 0)
	{
		alert(pMessageDataCheckNonValida);
		return;
	}
	
	document.getElementById("modulo").submit();
}

/*
*  Aggiorna il numero di notti (modulo degli Hotels)
*/
function moduloHotelsUpdateGiorni()
{	
	if((document.getElementById('checkout').value - document.getElementById('checkin').value) > 0)
		document.getElementById('notti').value = document.getElementById('checkout').value - document.getElementById('checkin').value;
	else
		document.getElementById('notti').value = 0;
}

/********************************************************************************
*  Modulo REGISTRAZIONE ESPOSITORE                                              *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo di registrazione
*/
function moduloRegistrazioneEspositoreInvia()
{
	if(trim(document.getElementById("azienda").value) == "")
	{
		alert(pMessageAziendaMancante);
		return;
	}
	
	if(trim(document.getElementById("via").value) == "")
	{
			alert(pMessageViaMancante);
			return;
	}
	
	if(trim(document.getElementById("num").value) == "")
	{
		alert(pMessageNumeroCivicoMancante);
		return;
	}
	
	if(trim(document.getElementById("cap").value) == "")
	{
		alert(pMessageCAPMancante);
		return;
	}
	
	if(trim(document.getElementById("citta").value) == "")
	{
		alert(pMessageCittaMancante);
		return;
	}
	
	if(trim(document.getElementById("provincia").value) == "")
 	{
		alert(pMessageProvinciaMancante);
		return;
	}
	
	if(trim(document.getElementById("nazione").value) == "")
	{
			alert(pMessageNazioneMancante);
			return;
	}
	
	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageTelefonoMancante);
		return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeIncaricatoMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
		alert(pMessageCognomeIncaricatoMancante);
		return;
	}
	
	document.getElementById("modulo").submit();
}


/*
*  Aggiorna il modulo di registrazione
*/
function moduloRegistrazioneEspositoreRefresh()
{
	if(document.getElementById('scelta1').checked)
	{
		document.getElementById('tipo1').disabled = false;
		document.getElementById('tipo2').disabled = false;
		document.getElementById('tipo3').disabled = false;
		document.getElementById('tipo4').disabled = false;
		document.getElementById('tipo5').disabled = false;
		document.getElementById('produzione').disabled = false;
	}
	else
	{
		document.getElementById('tipo1').disabled = true;
		document.getElementById('tipo2').disabled = true;
		document.getElementById('tipo3').disabled = true;
		document.getElementById('tipo4').disabled = true;
		document.getElementById('tipo5').disabled = true;
		document.getElementById('produzione').disabled = true;
	}
}


/********************************************************************************
*  Modulo NEWSLETTER                                                            *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo dell'iscrizione alla Newsletters
*/
function moduloNewsletterInvia()
{
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
			alert(pMessageCognomeMancante);
			return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	document.getElementById("modulo").submit();
}


/********************************************************************************
*  Modulo CATALOGO                                                              *
********************************************************************************/


/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo dell'inserimento as catalogo
*/
function moduloCatalogoInvia()
{
	var tOpzione0;
	var tOpzioneA;
	
	if(trim(document.getElementById('denominazione').value) == '')
	{
		alert(pMessageDenominazioneMancante);
		return;
	}
	
	if(trim(document.getElementById('indirizzo').value) == '')
	{
		alert(pMessageIndirizzoMancante);
		return;
	}
	
	if(trim(document.getElementById('telefono').value) == '')
	{
		alert(pMessageTelefonoMancante);
		return;
	}

	if( trim(document.getElementById('email').value) == '' )
	{
		alert(pMessageIndirizzoEMail);
		return;
	}
	
	if(document.getElementById('email').value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}	
	
	if( trim(document.getElementById('prodotti').value) == '' )
	{
		alert(pMessageTipoProdottoMancante);
		return;
	}

	tOpzione0 = document.getElementById('opzione0').checked;
	tOpzioneA = document.getElementById('opzioneA').checked;

	if(!tOpzione0 && !tOpzioneA)
	{
		alert(pMessageOpzioneMancante);
		return;
	}

	if(tOpzione0 && tOpzioneA)
	{
		alert(pMessageOpzioneNonValida);
		return;
	}
	
	document.getElementById("modulo").submit();
}

/********************************************************************************
*  Modulo REGISTRAZIONE ESPOSITORE                                              *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo delle Disposizioni doganali
*/
function moduloDisposizioniInvia()
{	
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeEspositoreMancante);
		return;
	}
	
	if(trim(document.getElementById("indirizzo").value) == "")
	{
		alert(pMessageIndirizzoMancante);
		return;
	}
	
	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageContattoTelefonicoMancante);
		return;
	}

	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	if(trim(document.getElementById("merce").value) == "")
	{
		alert(pMessageMerceTrasportataMancante);
		return;
	}

	if(document.getElementById("trasporto1").checked)
	{
		if(trim(document.getElementById("trasportoLocalita").value) == "")
		{
			alert(pMessageLocalitaMancante);
			return;
		}
	}
	
	document.getElementById("modulo").submit();
}

/*
*  Aggiorna il modulo delle Disposizioni doganali
*/
function moduloDisposizioniRefresh()
{
	 if(document.getElementById("trasporto2").checked)
	 {
		document.getElementById("trasportoLocalita").value = "";
		document.getElementById("trasportoLocalita").disabled = true;		
	 }
	 else
	 {
		document.getElementById("trasportoLocalita").disabled = false; 
	 }
}


/********************************************************************************
*  Modulo REGISTRAZIONE ESPOSITORE                                              *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo di registrazione
*/
function moduloCatalogoPubblicitaInvia()
{
	if(trim(document.getElementById("azienda").value) == "")
	{
		alert(pMessageAziendaMancante);
		return;
	}
	
	if(trim(document.getElementById("via").value) == "")
	{
			alert(pMessageViaMancante);                                       
			return;
	}
	
	if(trim(document.getElementById("num").value) == "")
	{
		alert(pMessageNumeroCivicoMancante);
		return;
	}
	
	if(trim(document.getElementById("cap").value) == "")
	{
		alert(pMessageCAPMancante);
		return;
	}
	
	if(trim(document.getElementById("citta").value) == "")
	{
		alert(pMessageCittaMancante);
		return;
	}
	
	if(trim(document.getElementById("provincia").value) == "")
 	{
		alert(pMessageProvinciaMancante);
		return;
	}
	
	if(trim(document.getElementById("nazione").value) == "")
	{
			alert(pMessageNazioneMancante);
			return;
	}
	
	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageTelefonoMancante);
		return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeIncaricatoMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
		alert(pMessageCognomeIncaricatoMancante);
		return;
	}
	
	document.getElementById("modulo").submit();
}


/********************************************************************************
*  Modulo REGISTRAZIONE CONTATTO ESPOSITORE                                     *
********************************************************************************/

/*
*  Verifica che siano stati inseriti tutti i dati, prima di inviare il modulo di Contatto Espositore
*/          
function moduloInformazioniEspositoriDetInvia()
{
	if(trim(document.getElementById("nome").value) == "")
	{
		alert(pMessageNomeMancante);
		return;
	}
	
	if(trim(document.getElementById("cognome").value) == "")
	{
		alert(pMessageCognomeMancante);
		return;
	}
	
	if(trim(document.getElementById("telefono").value) == "")
	{
		alert(pMessageTelefonoMancante);
		return;
	}
	
	if(trim(document.getElementById("email").value) == "")
	{
		alert(pMessageEMailMancante);
		return;
	}
	
	if(document.getElementById("email").value.search("@") == -1)
	{
		alert(pMessageEmailNonValido);
		return;
	}
	
	if(document.getElementById("messaggio").value == "")
	{
		alert(pMessageMessaggioMancante);
		return;
	}
	
	document.getElementById("modulo").submit();
}

