
//==========================================================================================================
//---  prt_checkAndSubmitResearchGeneric(theForm) --------------------------------------
function prt_checkAndSubmitResearchGeneric(theForm)
{
	if (theForm.txtTesto.value == "")
	{
		alert("Per effettuare una ricerca compilare il campo");
		theForm.txtTesto.focus();
		return;
	}
	
	theForm.action = "prt_research.asp";
	theForm.submit();
	theForm.txtTesto.disabled = true;
}

//==========================================================================================================
//---  prt_checkAndSubmitResearchAdvanced(theForm) --------------------------------------
function prt_checkAndSubmitResearchAdvanced(theForm)
{
	if (theForm.txtTesto.value == "")
	{
		alert("Per effettuare una ricerca compilare il campo \"Testo da cercare\" ");
		theForm.txtTesto.focus();
		return;
	}
	
	theForm.action = "prt_research.asp";
	theForm.submit();
	theForm.btnReset.disabled = true;
	theForm.btnCerca.disabled = true;
}


//==========================================================================================================
//---  prt_checkAndSubmitLogin(theForm) --------------------------------------
function prt_checkAndSubmitLogin(theForm)
{
	if (theForm.txtLogin.value == "")
	{
		alert("Il campo \"Login\" è obbligatorio");
		theForm.txtLogin.focus();
		return;
	}

	if (theForm.txtPassword.value == "")
	{
		alert("Il campo \"Password\" è obbligatorio");
		theForm.txtPassword.focus();
		return;
	}
	//--- Conrolli superati
	theForm.action = "login_02.asp";
	theForm.submit();
}


//==========================================================================================================
//---  checkInsertUpdateNews(theForm): Form di Inserimento e Modifica --------------------------------------
function checkInsertNews01(theForm)
{
	dataScadenza = theForm.cldcalendario1.value.split('/');
	if (IsDateNotValid(dataScadenza[0], dataScadenza[1], dataScadenza[2]))
	{
		alert("La data inserita nel campo \"Data\" è errata o incompleta.\nCorreggere grazie.");
		theForm.cldcalendario1.focus();
		return false;
	}	
	
	if (IsStringEmpty(theForm.txtTitolo.value))
	{
		alert("Il campo \"Titolo\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	
	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.disabled = true;
}


//==========================================================================================================
//---  checkInsertPage(theForm) --------------------------------------
function checkInsertPage01(theForm)
{	
	if (IsStringEmpty(theForm.txtTitolo.value))
	{
		alert("Il campo \"Titolo\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	
	if (theForm.ddmTipoContenuto.value == "")
	{
		alert("Il campo \"Tipo\" è obbligatorio");
		theForm.ddmTipoContenuto.focus();
		return;
	}
	theForm.hdnIdTipoContenuto.value = theForm.ddmTipoContenuto.value;
	
	//--- Conrolli superati	
	theForm.submit();
}


//---  checkInsertSitiWeb(theForm): Form di Inserimento e Modifica --------------------------------------
function checkInsertSitiWeb(theForm)
{
	if (theForm.ddmTipoLink.value == 0)
	{
		alert("Il campo \"Tipo Link\" è obbligatorio");
		theForm.ddmTipoLink.focus();
		return;		
	}
	
	if (IsStringEmpty(theForm.txtTitolo.value))
	{
		alert("Il campo \"Titolo\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	if (IsStringEmpty(theForm.txtLink.value))
	{
		alert("Il campo \"Link\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.disabled = true;
}

//==========================================================================================================
//=== FORUM
//==========================================================================================================

//----------------------------------------------------------------------
function forum_checkAccesso()
{



	if (document.TheForm.txtUsername.value == "")
	{
		alert("Compilare il campo \"Username\"");
		document.TheForm.txtUsername.focus();
		return;
	}	 

	if (document.TheForm.txtPassword.value == "")
	{
		alert("Compilare il campo \"Password\"");
		document.TheForm.txtPassword.focus();
		return;
	}	 

	document.TheForm.action="login_02.asp";
	document.TheForm.submit();
}

//----------------------------------------------------------------------
function checkFormArg()
{
	if (document.TheForm.txtTitolo.value == "")
	{
		alert("Compilare il campo \"Titolo\"");
		document.TheForm.txtTitolo.focus();
		return;
	}	 

	if (document.TheForm.txaMessaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\"");
		document.TheForm.txaMessaggio.focus();
		return;
	}
		
	document.TheForm.btnInserisci.disabled = true;
	document.TheForm.submit();
}

function checkFormDiscMess(isDisc)
{
	if (isDisc == 0)
	{
		if (document.TheForm.txtTitolo.value == "")
		{
			alert("Compilare il campo \"Titolo\".");
			document.TheForm.txtTitolo.focus();
			return (false);
		}
	}

	if (document.TheForm.txaMessaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\".");
		document.TheForm.txaMessaggio.focus();
		return (false);
	}
	
	document.TheForm.submit();
	return (true);
}

//----------------------------------------------------------------------
function forum_checkFormMex()
{
	if (document.theForm.txaMessaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\"");
		document.theForm.txaMessaggio.focus();
		return;
	}
	
	document.theForm.btnInserisci.disabled = true;
	document.theForm.submit();
}


function forum_checkMessaggioPrivatoRisposta(theForm)
{
	if (theForm.Messaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\"");
		theForm.Messaggio.focus();
		return;
	}
	theForm.submit();
}

function check_RispondiInvioMessaggio(theForm)
{
	if (document.TheForm.Oggetto.value == "")
	{
		alert("Compilare il campo \"Oggetto\"");
		theForm.Oggetto.focus();
		return;
	}

	if (document.TheForm.Messaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\"");
		theForm.Messaggio.focus();
		return;
	}
	
	theForm.invia.disabled = true;
	theForm.submit();
}

function forum_checkMessaggioPrivato(theForm)
{
	if (theForm.hdnIdSel.value == "")
	{
		alert("Il campo \"Destinatario\" è obbligatorio");
		theForm.imgRubrica.focus();
		return;		
	}
	
	if (theForm.Oggetto.value == "")
	{
		alert("Compilare il campo \"Oggetto\"");
		theForm.Oggetto.focus();
		return;
	}

	if (theForm.Messaggio.value == "")
	{
		alert("Compilare il campo \"Messaggio\"");
		theForm.Messaggio.focus();
		return;
	}
	
	theForm.invia.disabled = true;
	theForm.submit();
}

//----------------------------------------------------------------------
function confirm_EliminaArgomento(idArgomento)
{
	if (confirm("Sei sicuro di voler eliminare l\'argomento?"))
	{
		window.location.href="argomentoElimina.asp?idArg="+ idArgomento;
	}
}

function confirm_EliminaDiscussione(idArgomento, idDiscussione)
{
	if (confirm("Sei sicuro di voler eliminare la discussione?"))
	{
		window.location.href="discussioneElimina.asp?idArg="+ idArgomento +"&idDisc="+ idDiscussione;
	}
}

function confirm_EliminaMessaggio(idDiscussione, idMessaggio)
{
	if (confirm("Sei sicuro di voler eliminare il messaggio?"))
	{
		window.location.href="messaggioElimina.asp?idDisc="+ idDiscussione +"&idMess="+ idMessaggio;
	}
}


function demo()
{
	alert("Funzionalità non disponibile nella versione demo")
}


//----------------------------------------------------------------------
//--- checkAccesso_AreaRiservata(theForm)
function checkAccesso_AreaRiservata(theForm, lPage)
{
	if (theForm.txtUsername.value == "")
	{
		alert("Compilare il campo \"Username\"");
		theForm.txtUsername.focus();
		return;
	}	 

	if (theForm.txtPassword.value == "")
	{
		alert("Compilare il campo \"Password\"");
		theForm.txtPassword.focus();
		return;
	}	 

	
	var strlPage
	switch (lPage) 
	{ 
	   case 1 : 
		  strlPage = "";
		  break; 
	   case 2 : 
		  strlPage = "../";
		  break; 
	   default : 
		  strlPage = "";
		  break; 
	} 
	
	theForm.action = strlPage + "prt_login_02.asp"
	theForm.submit();
}

//----------------------------------------------------------------------
//--- check_CercaNelSito(theForm)
function check_CercaNelSito(theForm)
{
	if (theForm.txtCerca.value == "")
	{
		alert("Per effettuare la ricerca compilare il campo di testo");
		theForm.txtCerca.focus();
		return;
	}	 
	theForm.submit();
	theForm.txtCerca.disabled = true;
	theForm.btnCerca.disabled = true;
}

//----------------------------------------------------------------------
//--- check_CercaNeiFeed(theForm)
function check_CercaNeiFeed(theForm)
{
	if (theForm.txtCercaNeiFeed.value == "")
	{
		alert("Per effettuare la ricerca nei canali RSS compilare il campo di testo");
		theForm.txtCercaNeiFeed.focus();
		return;
	}	 
	theForm.submit();
	theForm.txtCercaNeiFeed.disabled = true;
	theForm.btnCercaNeiFeed.disabled = true;
}

//---  checkInsertUtente(theForm): Form di Inserimento e Modifica --------------------------------------
function checkInsertUtente(theForm)
{
	if (IsStringEmpty(theForm.txtNome.value))
	{
		alert("Il campo \"Nome\" è obbligatorio");
		theForm.txtNome.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtCognome.value))
	{
		alert("Il campo \"Cognome\" è obbligatorio");
		theForm.txtCognome.focus();
		return false;		
	}

	/*if (theForm.ddmEnteAderente.value == 0)
	{
		alert("Compilare il campo \"Struttura di Appartenenza\"");
		return;
	}*/

	if (theForm.ddmSettoreAppartenenza.value == 0)
	{
		alert("Compilare il campo \"Settore\"");
		return;
	}
	
	if (IsStringEmpty(theForm.txtEmail.value))
	{
		alert("Il campo \"E-mail\" è obbligatorio");
		theForm.txtEmail.focus();
		return false;		
	}

	if (IsStringEmpty(theForm.txtTelefono.value))
	{
		alert("Il campo \"Telefono\" è obbligatorio");
		theForm.txtTelefono.focus();
		return false;		
	}
	
	if (isNaN(theForm.txtTelefono.value))
	{
		alert("Il campo \"Telefono\" deve essere numerico");
		theForm.txtTelefono.focus();
		return false;		
	}
	
	if (isNaN(theForm.txtCellulare.value))
	{
		alert("Il campo \"Cellulare\" deve essere numerico");
		theForm.txtCellulare.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtLogin.value))
	{
		alert("Il campo \"Login\" è obbligatorio");
		theForm.txtLogin.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtPassword1.value))
	{
		alert("Il campo \"Password\" è obbligatorio");
		theForm.txtPassword1.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtPassword2.value))
	{
		alert("Il campo \"Ripeti password\" è obbligatorio");
		theForm.txtPassword2.focus();
		return false;		
	}
	
	if (theForm.txtPassword1.value != theForm.txtPassword2.value)
	{
		alert("Le due password devono essere uguali");
		theForm.txtPassword1.focus();
		return false;		
	}
	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.disabled = true;
}

//---  checkInsertUtenteRed(theForm): Form di Inserimento e Modifica Utente Redattore--------------------------------------
function checkInsertUtenteRed(theForm)
{
	if (IsStringEmpty(theForm.txtNome.value))
	{
		alert("Il campo \"Nome\" è obbligatorio");
		theForm.txtNome.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtCognome.value))
	{
		alert("Il campo \"Cognome\" è obbligatorio");
		theForm.txtCognome.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtEmail.value))
	{
		alert("Il campo \"E-mail\" è obbligatorio");
		theForm.txtEmail.focus();
		return false;		
	}

	if (IsStringEmpty(theForm.txtTelefono.value))
	{
		alert("Il campo \"Telefono\" è obbligatorio");
		theForm.txtTelefono.focus();
		return false;		
	}
	
	if (isNaN(theForm.txtTelefono.value))
	{
		alert("Il campo \"Telefono\" deve essere numerico");
		theForm.txtTelefono.focus();
		return false;		
	}
	
	if (isNaN(theForm.txtCellulare.value))
	{
		alert("Il campo \"Cellulare\" deve essere numerico");
		theForm.txtCellulare.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtLogin.value))
	{
		alert("Il campo \"Login\" è obbligatorio");
		theForm.txtLogin.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtPassword1.value))
	{
		alert("Il campo \"Password\" è obbligatorio");
		theForm.txtPassword1.focus();
		return false;		
	}
	
	if (IsStringEmpty(theForm.txtPassword2.value))
	{
		alert("Il campo \"Ripeti password\" è obbligatorio");
		theForm.txtPassword1.focus();
		return false;		
	}
	
	if (theForm.txtPassword1.value != theForm.txtPassword2.value)
	{
		alert("Le due password devono essere uguali");
		theForm.txtPassword1.focus();
		return false;		
	}
	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.disabled = true;
}

//----------------------------------------------------
//--- checkRispostaSondaggio(TheForm)
function checkRispostaSondaggio(TheForm)
{	
	var radio_choice = false;
	var rdbRisposta, idSond;
	for ( counter = 0; counter < TheForm.rdbRisposta.length; counter++ )
	{
		if ( TheForm.rdbRisposta[counter].checked )
		{
			radio_choice = true;
			rdbRisposta = TheForm.rdbRisposta[counter].value; 
		}
	}
	var nameOfCookie, numberSond;
	idSond = document.getElementById("hdnIdSondaggioPage").value;
	nameOfCookie = "sondNum" + idSond;
	if (getCookie(nameOfCookie) != null)
	{
		alert("Hai gia partecipato a questo sondaggio.");
		return (false);
	}
	if (!radio_choice)	
	{
		alert("Per votare il sondaggio seleziona una risposta.");
		return (false);
	}
	setCookie(nameOfCookie, true, 365);
	votaSondaggioAJAX(rdbRisposta);
	return (true);
}

//----------------------------------------------------
//--- check_getBoxSondaggio(TheForm)
function check_getBoxSondaggio(TheForm)
{	
	var radio_choice = false;
	var rdbRisposta, idSond;
	for ( counter = 0; counter < TheForm.rdbRisposta.length; counter++ )
	{
		if ( TheForm.rdbRisposta[counter].checked )
		{
			radio_choice = true; 
			rdbRisposta = TheForm.rdbRisposta[counter].value;
		}
	}
	if (!radio_choice)
	{
		alert("Per votare il sondaggio seleziona una risposta.");
		return (false);
	}
	var nameOfCookie, numberSond;
	idSond = document.getElementById("hdnIdSondaggio").value;
	nameOfCookie = "sondNum" + idSond;
	if (getCookie(nameOfCookie) != null)
	{
		alert("Hai gia partecipato a questo sondaggio.");
		return (false);
	}
	setCookie(nameOfCookie, true, 365);
	votaSondaggioAJAX(rdbRisposta);
	return (true);
}

//----------------------------------------------------
//--- check_getBoxSondaggio(TheForm)
function check_getAlreadyVotedBoxSondaggio(TheForm)
{	
	var idSond;
	var nameOfCookie, numberSond;
	idSond = document.getElementById("hdnIdSondaggio").value;
	nameOfCookie = "sondNum" + idSond;
	if (getCookie(nameOfCookie) != null)
	{
		return (false);
	}
	return (true);
}

function ableBoxSondaggio()
{
	if(check_getAlreadyVotedBoxSondaggio(document.formBoxSondaggio) == true)
	{
		document.getElementById('boxSondaggioRisultati').style.display='none';
		document.getElementById('boxSondaggioVoto').style.display='block';
	}
	else
	{
		document.getElementById('boxSondaggioRisultati').style.display='block';
		document.getElementById('boxSondaggioVoto').style.display='none';
	}
}

//---  ismaxlength(obj) --------------------------------------
function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
	{
		obj.value=obj.value.substring(0,mlength);
	}
	if (document.getElementById("txtCarDisp"))
	{
		document.getElementById("txtCarDisp").value = mlength - obj.value.length;
	}
}

function checkNewsCommentBox()
{
	if(document.getElementById("txtNome").value.length < 3)
	{
		alert('Compilare il campo nome(almeno 3 caratteri)');
		document.getElementById("txtNome").focus();
		return false;
	}
	else if(document.getElementById("txtTesto").value.length < 5)
	{
		alert('Compilare il campo testo(almeno 5 caratteri)');
		document.getElementById("txtTesto").focus();
		return false;
	}
	else
	{
		return true;
	}
}