//----------------------------------------------------------------------
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 checkFormDisc()
{
	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 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 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;
	}
}

//==========================================================================================================
//---  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;
	theForm.btnCerca.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;
}

//----------------------------------------------------------------------
//--- 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();
}


//==========================================================================================================
//---  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();
	theForm.btnAccedi.disabled = true;
}


//==========================================================================================================
//---  checkInsertUpdateNews(theForm): Form di Inserimento e Modifica --------------------------------------
function checkInsertNews01(theForm)
{
	if ((theForm.ddmDayddmData.value == -1) || (theForm.ddmMonthddmData.value == -1) || (theForm.ddmYearddmData.value == -1) )
	{
		alert("Compilare correttamente il campo \"Data\" ");
		theForm.ddmDayddmData.focus();
		return true;
	}

	if (IsDateNotValid(theForm.ddmDayddmData.value, theForm.ddmMonthddmData.value, theForm.ddmYearddmData.value)) {
		alert ("La data inserita nel campo \"Data\" è errata o incompleta.\nCorreggere grazie.");
		theForm.ddmDayddmData.focus();
		return (0);
	}	
	
	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.txtCod.value))
	{
		alert("Il campo \"Codice\" è obbligatorio");
		theForm.txtCod.focus();
		return;
	}
	
	if (IsStringEmpty(theForm.txtTitolo.value))
	{
		alert("Il campo \"Titolo\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	
	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.disabled = true;
}


//---  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;
}


//---  checkInsertOf(theForm): Form di Inserimento e Modifica --------------------------------------
function checkInsertOf(theForm)
{
	if (theForm.ddmTipoOf.value == 0)
	{
		alert("Il campo \"Tipo Offerta\" è obbligatorio");
		theForm.ddmTipoOf.focus();
		return;		
	}
	if (IsStringEmpty(theForm.txtTitolo.value))
	{
		alert("Il campo \"Titolo\" è obbligatorio");
		theForm.txtTitolo.focus();
		return;
	}
	
	if ((theForm.ddmDayddmDataScadenza.value == -1) || (theForm.ddmMonthddmDataScadenza.value == -1) || (theForm.ddmYearddmDataScadenza.value == -1) )
	{
		alert("Compilare correttamente il campo \"Data scadenza\" ");
		theForm.ddmDayddmDataScadenza.focus();
		return true;
	}

	// Controllo date
	if (IsDateNotValid(theForm.ddmDayddmDataScadenza.value, theForm.ddmMonthddmDataScadenza.value, theForm.ddmYearddmDataScadenza.value))
	{
		alert ("La data inserita nel campo \"Data Inizio Visualizzazione\" è errata o incompleta.\nCorreggere grazie.");
		theForm.ddmDayDataInizio.focus();
		return false;
	}		


	//--- Conrolli superati	
	theForm.submit();
	theForm.btnSubmit.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 (IsStringEmpty(theForm.txtEmail.value))
	{
		alert("Il campo \"E-mail\" è obbligatorio");
		theForm.txtEmail.focus();
		return false;		
	}
	
	//--- Conrolli superati	
	theForm.submit();
}

//---  confirm_DeleteNews(idStep, idNews) --------------------------------------
function confirm_DeleteUtente(idStep, idUtente, idStepDest,idTipoUtente)
{
	if (confirm("Sei sicuro di voler eliminare l'Utente?"))
	{
		window.location.href = "cmsUtenti.asp?idStep="+ idStep +"&idUtente="+ idUtente + "&idStepDest="+ idStepDest +"&idTipoUtente="+idTipoUtente;		
	}
}

// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers più recenti e diffusi
function assegnaXMLHttpRequest()
{
	var XHR = null, browserUtente = navigator.userAgent.toUpperCase();
	
	// browser standard con supporto nativo non importa il tipo di browser
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
	{
		XHR = new XMLHttpRequest();
	}

	// browser Internet Explorer - è necessario filtrare la versione 4
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0)
	{
 
		// la versione 6 di IE ha un nome differente per il tipo di oggetto ActiveX
		if(browserUtente.indexOf("MSIE 5") < 0)
		{
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		}
		// le versioni 5 e 5.5 invece sfruttano lo stesso nome
		else
		{
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return XHR;
}

var http = assegnaXMLHttpRequest();

function getStateResponse(id,imgID,stateAbil,stateDisab)
{
	if(http.readyState == 4)
	{  
		var response = http.responseText;
		if (response != "")
		{
			imgIDName = imgID + id;
			if(response == stateDisab)
			{
				document.getElementById(imgIDName).setAttribute("src","../Images/ico_abilita.gif");
			}
			else if(response == stateAbil)
			{
				document.getElementById(imgIDName).setAttribute("src","../Images/ico_disabilita.gif");
			}
			else
			{
				return;
			}
		}
		else
		{
			return;
		}
	}
}

function changeStateUtenti(id)
{
	http.open('post', 'cmsUtenti.asp?idStep=3&id='+id);
	http.onreadystatechange = function() { getStateResponse(id,"imgUtenti",1,7); };
	http.send(null);
}