<!--
function isNull(vValue, vDefault)
{
	if (typeof(vDefault) == "undefined")
	{
		if (typeof(vValue) == "undefined" || vValue == null)
			return true;
		else
			return false;
	}
	else
	{
		var vTmp;

		if (typeof(vValue) == "undefined" || vValue == null)
			return vDefault;
	
		vTmp = String(vValue);
		if (vTmp == "undefined" || vTmp == "" || vTmp == "null")
			return vDefault;

		return vValue;
	}
}
	
function FormatStrForDB( pstrValue )
{
	pstrValue = pstrValue.replace(/\'/gi, "''"); //'
	return pstrValue;
}

function FormatStrForInput( pstrValue )
{
	pstrValue = pstrValue.replace(/\"/gi, "&#34;");	//"
	pstrValue = pstrValue.replace(/\'/gi, "&#39;");
	return pstrValue;
}

function fnFormatStrFromTextAreaToDBForSite ( pstrValue )
{
	pstrValue = escape ( pstrValue );
	pstrValue = pstrValue.replace(/%3C/gi, ""); // elimino l'apertura del tag <
	pstrValue = pstrValue.replace(/%3E/gi, ""); // elimino la chiusura del tag >
	pstrValue = pstrValue.replace(/%0D%0A/gi, "%3Cbr%3E"); // sostituisco gli a capo con <br> per PC
	pstrValue = pstrValue.replace(/%0A/gi, "%3Cbr%3E"); // sostituisco gli a capo con <br> per MAC
	pstrValue = unescape ( pstrValue );
	return pstrValue;
}

function fnFormatStrFromTextAreaToDBForCMS ( pstrValue )
{
	pstrValue = escape ( pstrValue );
	pstrValue = pstrValue.replace(/%0D%0A/gi, "%3Cbr%3E"); // sostituisco gli a capo con <br> per PC
	pstrValue = pstrValue.replace(/%0A/gi, "%3Cbr%3E"); // sostituisco gli a capo con <br> per MAC
	pstrValue = unescape ( pstrValue );
	return pstrValue;
}

function sqlString(vValue)
{
	var vTmp = String(isNull(vValue, "null"));
	
	if (vTmp != "null")
		vTmp = "'" + vTmp.replace(/'/g, "''") + "'";	//"
	
	return vTmp;
}

function sqlNumber(vValue)
{
	vValue		= isNull(vValue, "null");
	var vTmp	= Number(vValue);
	
	if (isNaN(vTmp))
		vTmp = "null";
	
	return vTmp;
}

function CheckDATE (Form, Element, Separator, CanBeNull, NoMessage, bCheckCurrentYear )
{
	bCheckCurrentYear = isNull ( bCheckCurrentYear, false);

	var vElement		= document.forms[Form].elements[Element];
	var vElementValue	= ReadElementValue( vElement );

	if ( !CanBeNull )
	{
		if (isNull(vElementValue,"")=="")
		{
			if ( (NoMessage == null) || (NoMessage == false) ) {
				ShowCheckError(0);
				vElement.focus();
			}
			
			return false;
		}
	}
	else
	{
		if (isNull(vElementValue,"")=="")
			return true;
	}

	var vIntDay;
	var vIntMonth;
	var vIntYear;
	
	var vVarArray;
	vVarArray = vElementValue.split( Separator );
	
	if ( vVarArray.length != 3 ) {
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nData non valida.");
			vElement.focus();
		}
		
		return false;
	}

	if ( (vVarArray[0].length != 1) && (vVarArray[0].length != 2) ) {
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nGiorno non valido.");
			vElement.focus();
		}
		
		return false;
	}

	vIntDay = ((vVarArray[0].charAt(0) == "0") && (vVarArray[0].length == 2)) ? parseInt(vVarArray[0].charAt(1)) : parseInt(vVarArray[0]);
	
	if (isNaN(vIntDay))
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nGiorno non valido.");
			vElement.focus();
		}
		
		return false;
	}
	else
	{
		if ( (vIntDay < 1) || (vIntDay > 31) )
		{
			if ( (NoMessage == null) || (NoMessage == false) ) {
				alert("Attenzione!\nGiorno non valido.");
				vElement.focus();
			}
			
			return false;
		}
	}

	if ( (vVarArray[1].length != 1) && (vVarArray[1].length != 2) ) {
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nMese non valido.");
			vElement.focus();
		}
		
		return false;
	}

	vIntMonth = ((vVarArray[1].charAt(0) == "0") && (vVarArray[1].length == 2)) ? parseInt(vVarArray[1].charAt(1)) : parseInt(vVarArray[1]);
	if (isNaN(vIntMonth))
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nMese non valido.");
			vElement.focus();
		}
		
		return false;
	}
	else
	{
		if ((vIntMonth < 1) || (vIntMonth > 12))
		{
			if ( (NoMessage == null) || (NoMessage == false) ) {
				alert("Attenzione!\nMese non valido.");
				vElement.focus();
			}
			
			return false;
		}
	}

	vIntYear = parseInt(vVarArray[2]);
	
	if (isNaN(vIntYear) || (String(vIntYear).length != 4))
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nAnno non valido.");
			vElement.focus();
		}
		
		return false;
	}
	
	var vDate;
	
	vDate = new Date(vIntYear, vIntMonth - 1, vIntDay);
	if ( vDate == null ) {
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nData non valida.");
			vElement.focus();
		}
		
		return false;		
	}

	if ( (vDate.getDate() != vIntDay) || (vDate.getMonth() != (vIntMonth - 1)) || (vDate.getFullYear() != vIntYear) ) {
		if ( (NoMessage == null) || (NoMessage == false) ) {
			alert("Attenzione!\nData non valida.");
			vElement.focus();
		}
		
		return false;		
	}

	if ( bCheckCurrentYear )
	{
		if ((vIntYear < ((new Date()).getFullYear() - 1)) || (vIntYear > (new Date()).getFullYear()))
		{
			if ( (NoMessage == null) || (NoMessage == false) ) {
				alert("Attenzione!\nAnno non valido.");
				vElement.focus();
			}
			
			return false;
		}

		// controlla che la data non sia maggiore della data corrente

		var vToday = new Date();
		
		if ( vDate.getFullYear() == vToday.getFullYear() ) {
			if ( vDate.getMonth() > vToday.getMonth() ) {
				if ( (NoMessage == null) || (NoMessage == false) ) {
					alert("Attenzione!\nData maggiore di quella odierna.");
					vElement.focus();
				}
				
				return false;		
			}
			else if ( vDate.getMonth() == vToday.getMonth() ) {
				if ( vDate.getDate() > vToday.getDate() ) {
					if ( (NoMessage == null) || (NoMessage == false) ) {
						alert("Attenzione!\nData maggiore di quella odierna.");
						vElement.focus();
					}
					
					return false;		
				}
			}
		}
		
	}

	return true;
}

function fnGetDATE( pValue, pSeparator )
{
	var vIntDay;
	var vIntMonth;
	var vIntYear;
	
	var vVarArray;
	vVarArray = String(pValue).split( pSeparator );
	
	if ( vVarArray.length != 3 ) {
		return ( null );
	}

	if ( (vVarArray[0].length != 1) && (vVarArray[0].length != 2) ) {
		return ( null );
	}

	vIntDay = ((vVarArray[0].charAt(0) == "0") && (vVarArray[0].length == 2)) ? parseInt(vVarArray[0].charAt(1)) : parseInt(vVarArray[0]);
	if (isNaN(vIntDay))
	{
		return ( null );
	}
	else
	{
		if ( (vIntDay < 1) || (vIntDay > 31) )
		{
			return ( null );
		}
	}

	if ( (vVarArray[1].length != 1) && (vVarArray[1].length != 2) ) {
		return ( null );
	}

	vIntMonth = ((vVarArray[1].charAt(0) == "0") && (vVarArray[1].length == 2)) ? parseInt(vVarArray[1].charAt(1)) : parseInt(vVarArray[1]);
	if (isNaN(vIntMonth))
	{
		return ( null );
	}
	else
	{
		if ((vIntMonth < 1) || (vIntMonth > 12))
		{
			return ( null );
		}
	}

	vIntYear = parseInt(vVarArray[2]);
	if (isNaN(vIntYear))
	{
		return ( null );
	}

	var vDate;
	vDate = new Date(vIntYear, vIntMonth - 1, vIntDay);
	if ( vDate == null ) {
		return ( null );		
	}

	if ( (vDate.getDate() != vIntDay) || (vDate.getMonth() != (vIntMonth - 1)) || (vDate.getFullYear() != vIntYear) ) {
		return ( null );		
	}
	
	return String(vDate.getFullYear()) + String(addZero(String(vDate.getMonth() + 1))) + String(addZero(String(vDate.getDate())));
}

function CheckTime ( Form, Element, TimeSeparator, CanBeNull )
{
	var vElement		= document.forms[Form].elements[Element];
	var vElementValue	= ReadElementValue( vElement );

	if ( !CanBeNull )
	{
		if (isNull(vElementValue, "") == "")
		{
			ShowCheckError(0);
			vElement.focus();
			return false;
		}
	}
	else
	{
		if (isNull(vElementValue, "") == "")
			return true;
	}
	
	TimeSeparator	= isNull ( TimeSeparator,	":" );
	CanBeNull		= isNull ( CanBeNull,		false );
	
	var vIntHour;
	var vIntMinute;
	
	
	
	var arrTime = vElementValue.split( TimeSeparator );
	
	if ( arrTime.length != 2 )
	{
		alert("Attenzione!\nOrario non valido.");
		vElement.focus();
		return false;
	}
	
	//--------------- controllo ora ----------------------------
	
	if ( (arrTime[0].length != 1) && (arrTime[0].length != 2) )
	{
		alert("Attenzione!\nOra non valida.");
		vElement.focus();
		return false;
	}

	vIntHour = ((arrTime[0].charAt(0) == "0") && (arrTime[0].length == 2)) ? parseInt(arrTime[0].charAt(1)) : parseInt(arrTime[0]);
	
	if (isNaN(vIntHour))
	{
		alert("Attenzione!\nOra non valida.");
		vElement.focus();
		return false;
	}
	else
	{
		if ( (vIntHour < 0) || (vIntHour > 23) )
		{
			alert("Attenzione!\nOra non valida.");
			vElement.focus();
			return false;
		}
	}
	
	//--------------- controllo minuti ----------------------------
	
	if ( (arrTime[1].length != 1) && (arrTime[1].length != 2) )
	{
		alert("Attenzione!\nMinuti non validi.");
		vElement.focus();
		return false;
	}

	vIntMinute = ((arrTime[1].charAt(0) == "0") && (arrTime[1].length == 2)) ? parseInt(arrTime[1].charAt(1)) : parseInt(arrTime[1]);
	
	if (isNaN(vIntMinute))
	{
		alert("Attenzione!\nMinuti non validi.");
		vElement.focus();
		return false;
	}
	else
	{
		if ( (vIntMinute < 0) || (vIntMinute > 59) )
		{
			alert("Attenzione!\nMinuti non validi.");
			vElement.focus();
			return false;
		}
	}
	
	return true;
}

function CheckSTR(Form, Element, CanBeNull, NoMessage)
{
	var pElement		= document.forms[Form].elements[Element];
	var ElementValue	= ReadElementValue( pElement );
	
	if (!CanBeNull)
	{
		if (isNull(ElementValue, "") == "")
		{
			if ( (NoMessage == null) || (NoMessage == false) )
				ShowCheckError(0);
			else
				ShowCheckError(NoMessage);
			
			pElement.focus();
			return false;
		}
	}
	
	return true;
}

function ReadElementValue( pElement )
{
	var vLength	= isNull( pElement.length, 1);
	var vValue	= "";
	
	if ( vLength > 1)
	{
		if ( ( pElement[0].tagName == "INPUT" ) && ( pElement[0].type == "radio" ) )
		{
			for (i = 0; i < vLength; i++)
			{
				if ( pElement[i].checked )
				{
					vValue = pElement[i].value;
					break;
				}
			}
		}
	}
	else
	{
		switch ( pElement.tagName )
		{
			case "INPUT"	:
			{
				switch ( pElement.type )
				{				
					case "password"	: vValue = pElement.value; break;
					case "text"		: vValue = pElement.value; break;
					case "textarea"	: vValue = pElement.value; break;
					case "hidden"	: vValue = pElement.value; break;
					case "checkbox"	: vValue = pElement.checked ? true : false; break;
					case "radio"	: vValue = pElement.checked ? true : false; break;
				}
	
				break;
			}
			case "TEXTAREA"	:
			{
				vValue = pElement.value;
				break;
			}
			case "SELECT"	: 
				if ( pElement.selectedIndex != -1 ) {
					vValue = pElement.options[pElement.selectedIndex].value; 
				}
				
				break;
		}
	}

	return vValue;
}

function ShowCheckError( pintType )
{
	var strMessage = "";
	
	if ( isNaN ( pintType ) )
	{
		strMessage = pintType;
	}
	else
	{
		switch ( pintType )
		{
			case 0	: strMessage = "Attenzione!\nIl dato non puņ essere nullo.";											break;
			case 1	: strMessage = "Attenzione!\nDato non valido.";															break;
			case 2	: strMessage = "Attenzione!\nAccettare le condizioni generali di utilizzo del servizio (\"CGUS\").";	break;
			case 3	: strMessage = "Attenzione!\nIl dato relativo al Sesso non puņ essere nullo.";							break;
			case 4	: strMessage = "Attenzione!\nSelezionare Maschile o Femminile.";										break;
			case 5	: strMessage = "Attenzione!\nSelezionare la Professione.";												break;
			case 6	: strMessage = "Attenzione!\nAutorizzare il trattamento dei Dati Personali.";							break;
			case 7	: strMessage = "Attention!\nThe data must be a numeric data.";											break;
			case 9	: strMessage = "Attenzione!\nE-mail non valida.";														break;
			default	: strMessage = "Attenzione!\nErrore nell'inserimento del dato.";
		}
	}

	alert( strMessage );
}

function CheckSELECT ( Form, Element, NoMessage )
{
	var pElement		= document.forms[Form].elements[Element];
	var vselectedIndex	= pElement.selectedIndex;
	var strReturn		= false;
	
	if ( vselectedIndex != 0 )
	{
		strReturn = pElement.options[vselectedIndex].value;
	}
	
	if (!strReturn)
	{
		pElement.focus();
		
		if ( (NoMessage == null) || (NoMessage == false) )
			ShowCheckError(0);
		else
			alert ( NoMessage );
	}
		
	return strReturn;
}

function CheckEMAIL(Form, Element, CanBeNull, NoMessage)
{
	NoMessage			= isNull ( NoMessage, false );
	var vElement		= document.forms[Form].elements[Element];
	var vElementValue	= ReadElementValue(vElement);
	
	if ( !CanBeNull )
	{
		if ( isNull ( vElementValue, "" ) == "" )
		{
			if ( (NoMessage == null) || (NoMessage == false) )
				ShowCheckError(9);
			else
				ShowCheckError(NoMessage);
			
			vElement.focus();
			return false;
		}
	}
	else
	{
		if ( isNull ( vElementValue, "" ) == "" )
			return true;
	}

	var vArrayAt = vElementValue.split( "@" );
	
	if ( vArrayAt.length != 2 )
	{
		if ( (NoMessage == null) || (NoMessage == false) )
			ShowCheckError(9);
		else
			ShowCheckError(NoMessage);
			
		vElement.focus();
		return false;
	}	

	var vArrayDotPre = vArrayAt[0].split( "." );
	var vArrayDotPost = vArrayAt[1].split( "." );
	
	
	
	if ( vArrayDotPost.length < 2 )
	{
		if ( (NoMessage == null) || (NoMessage == false) )
			ShowCheckError(9);
		else
			ShowCheckError(NoMessage);
			
		vElement.focus();
		return false;
	}

	var ii;
	var jj;
	
	for ( jj = 0; jj < vArrayDotPre.length; jj++ )
	{
		if ( vArrayDotPre[jj].length < 1 )
		{
			if ( (NoMessage == null) || (NoMessage == false) )
				ShowCheckError(9);
			else
				ShowCheckError(NoMessage);
			
			vElement.focus();
			return false;
		}
		
		for ( ii = 0; ii < vArrayDotPre[jj].length; ii++ )
		{
			if ( ( (vArrayDotPre[jj].charCodeAt(ii) > 0) && (vArrayDotPre[jj].charCodeAt(ii) < 45) ) || ( (vArrayDotPre[jj].charCodeAt(ii) > 57) && (vArrayDotPre[jj].charCodeAt(ii) < 65) ) || ( (vArrayDotPre[jj].charCodeAt(ii) > 91) && (vArrayDotPre[jj].charCodeAt(ii) < 95) ) || (vArrayDotPre[jj].charCodeAt(ii) == 96) || (vArrayDotPre[jj].charCodeAt(ii) > 122) )
			{
				if ( (NoMessage == null) || (NoMessage == false) )
					ShowCheckError(9);
				else
					ShowCheckError(NoMessage);
			
				vElement.focus();
				return false;
			}
		}		
	}

	for ( jj = 0; jj < vArrayDotPost.length; jj++ )
	{
		if ( vArrayDotPost[jj].length < 1 )
		{
			if ( (NoMessage == null) || (NoMessage == false) )
				ShowCheckError(9);
			else
				ShowCheckError(NoMessage);
			
			vElement.focus();
			return false;
		}
		
		for ( ii = 0; ii < vArrayDotPost[jj].length; ii++ )
		{
			if ( ( ( vArrayDotPost[jj].charCodeAt(ii) > 0 ) && ( vArrayDotPost[jj].charCodeAt(ii) < 45 ) ) || ( ( vArrayDotPost[jj].charCodeAt(ii) > 57 ) && ( vArrayDotPost[jj].charCodeAt(ii) < 65 ) ) || ( ( vArrayDotPost[jj].charCodeAt(ii) > 91 ) && ( vArrayDotPost[jj].charCodeAt(ii) < 97 ) ) || ( vArrayDotPost[jj].charCodeAt(ii) > 122 ) )
			{
				if ( (NoMessage == null) || (NoMessage == false) )
					ShowCheckError(9);
				else
					ShowCheckError(NoMessage);
						
				vElement.focus();
				return false;
			}
		}		
	}

	return true;
}

function CheckRADIO(Form, Element, NoMessage)
{
	var pElement		= document.forms[Form].elements[Element];
	var ElementLength	= pElement.length;
	var strReturn		= false;
	
	for (i = 0; i < ElementLength; i++)
	{
		if (pElement[i].checked)
			strReturn = pElement[i].value;
	}
	
	if (!strReturn)
	{
		if ( (NoMessage == null) || (NoMessage == false) )
			ShowCheckError(0);
		else
			ShowCheckError(NoMessage);
	}
		
	return strReturn;
}

function fnFormatDataSQLFromData ( strData, bHasHours )
{
	strData		= String ( strData );
	bHasHours	= isNull ( bHasHours, "YES" );
	
	var intY = Number ( strData.substr(0, 4) );
	var intM = Number ( trimZero ( strData.substr(4, 2) ) );
	var intD = Number ( trimZero ( strData.substr(6, 2) ) );
	var intH = (strData.length >  8) ? Number ( trimZero ( strData.substr( 8, 2) ) ) : 0;
	var intT = (strData.length > 10) ? Number ( trimZero ( strData.substr(10, 2) ) ) : 0;
	var intS = (strData.length > 12) ? Number ( trimZero ( strData.substr(12, 2) ) ) : 0;

	var szDate = new Date(intY, intM - 1, intD, intH, intT, intS);
	
	var szReturn = szDate.getFullYear() + "-" + addZero ( szDate.getMonth() + 1 ) + "-" + addZero ( szDate.getDate() );

	if ( bHasHours == "YES" ) szReturn += " " + addZero ( szDate.getHours() ) + ":" + addZero ( szDate.getMinutes() );

	return szReturn;
}

function trimZero ( pszStr )
{
	pszStr = String ( pszStr );
	
	if ( pszStr == "00" )
		return 0;

	if ( pszStr.charAt(0) == "0" )
		return Number ( pszStr.charAt(1) );
	else
		return Number ( pszStr );
}

function addZero(vNumber)
{
	var vNumber = parseInt(vNumber);
	if (vNumber < 10) vNumber = "0" + vNumber;
	return vNumber;
}

function fnGoToPage( pintLastPage, pintValue )
{
	pintValue = Number ( isNull ( pintValue, -1 ) );
	
	var intPageToGo = 0;
	
	if ( pintValue == -1 )
	{
		intPageToGo = Number ( document.forms["mainForm"].elements["PageToGo"].value );
		
		if ( isNaN ( intPageToGo ) || ( intPageToGo < 1 ) || ( intPageToGo > pintLastPage ) )
		{
			alert("Attention!\nInsert a correct page number.");
			document.forms["mainForm"].elements["PageToGo"].select();
		}
		else
		{
			document.forms["mainForm"].elements["Page"].value = document.forms["mainForm"].elements["PageToGo"].value;
			document.forms["mainForm"].submit();
		}
	}
	else
	{
		var intFromPage = Number ( document.forms["mainForm"].elements["Page"].value );
		
		if ( ( pintValue > 0 ) && ( pintValue < ( pintLastPage + 1 ) ) )
		{
			intPageToGo = pintValue;
			
			if ( intPageToGo != intFromPage )
			{
				document.forms["mainForm"].elements["Page"].value = intPageToGo;
				document.forms["mainForm"].submit();
			}
		}
	}
}

function windowOpen(szUrl, szName, iWidth, iHeight)
{
	var iTop, iLeft;

	var szFeatures = "";
	
	if (iWidth != null)	{
		szFeatures += "width=" + iWidth + ",";
		iLeft = (window.screen.availWidth - iWidth) >> 1;
		szFeatures += "left=" + iLeft + ",";
	}
	if (iHeight != null) {
		szFeatures += "height=" + iHeight + ",";
		iHeight = (window.screen.availHeight - iHeight) >> 1;
		szFeatures += "top=" + iHeight + ",";
	}

	szFeatures += "scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no,fullscreen=no,resizable=yes";

	window.open(szUrl, szName, szFeatures);
}

function CheckDateTime ( Form, Element, DateSeparator, TimeSeparator, CanBeNull )
{
	var vElement		= document.forms[Form].elements[Element];
	var vElementValue	= ReadElementValue(vElement);

	if ( !CanBeNull )
	{
		if ( isNull ( vElementValue, "" ) == "" )
		{
			ShowCheckError(0);
			vElement.focus();
			return false;
		}
	}
	else
	{
		if ( isNull ( vElementValue, "" ) == "" )
			return true;
	}

	DateSeparator	= isNull ( DateSeparator,	"/" );
	TimeSeparator	= isNull ( TimeSeparator,	":" );
	CanBeNull		= isNull ( CanBeNull,		false );
	
	var vIntDay;
	var vIntMonth;
	var vIntYear;
	var vIntHour;
	var vIntMinute;
	
	var arrDateTime = vElementValue.split(" ");
	if ( arrDateTime.length != 2 )
	{
		alert("Attenzione!\nData non valida.");
		vElement.focus();
		return false;
	}
	
	var vVarArray;
	vVarArray = arrDateTime[0].split( DateSeparator );
	
	if ( vVarArray.length != 3 )
	{
		alert("Attenzione!\nData non valida.");
		vElement.focus();
		return false;
	}

	if ( (vVarArray[0].length != 1) && (vVarArray[0].length != 2) )
	{
		alert("Attenzione!\nGiorno non valido.");
		vElement.focus();
		return false;
	}

	vIntDay = ((vVarArray[0].charAt(0) == "0") && (vVarArray[0].length == 2)) ? parseInt(vVarArray[0].charAt(1)) : parseInt(vVarArray[0]);
	
	if (isNaN(vIntDay))
	{
		alert("Attenzione!\nGiorno non valido.");
		vElement.focus();
		return false;
	}
	else
	{
		if ( (vIntDay < 1) || (vIntDay > 31) )
		{
			alert("Attenzione!\nGiorno non valido.");
			vElement.focus();
			return false;
		}
	}

	if ( (vVarArray[1].length != 1) && (vVarArray[1].length != 2) )
	{
		alert("Attenzione!\nMese non valido.");
		vElement.focus();
		return false;
	}

	vIntMonth = ((vVarArray[1].charAt(0) == "0") && (vVarArray[1].length == 2)) ? parseInt(vVarArray[1].charAt(1)) : parseInt(vVarArray[1]);
	if (isNaN(vIntMonth))
	{
		alert("Attenzione!\nMese non valido.");
		vElement.focus();
		return false;
	}
	else
	{
		if ((vIntMonth < 1) || (vIntMonth > 12))
		{
			alert("Attenzione!\nMese non valido.");
			vElement.focus();
			return false;
		}
	}

	vIntYear = parseInt(vVarArray[2]);
	
	if (isNaN(vIntYear) || (String(vIntYear).length != 4))
	{
		alert("Attenzione!\nAnno non valido.");
		vElement.focus();
		return false;
	}
	
	var vDate;
	
	vDate = new Date(vIntYear, vIntMonth - 1, vIntDay);
	
	if ( vDate == null )
	{
		alert("Attenzione!\nData non valida.");
		vElement.focus();
		return false;		
	}

	if ( (vDate.getDate() != vIntDay) || (vDate.getMonth() != (vIntMonth - 1)) || (vDate.getFullYear() != vIntYear) )
	{
		alert("Attenzione!\nData non valida.");
		vElement.focus();
		return false;		
	}
	
	var arrTime = arrDateTime[1].split( TimeSeparator );
	
	if ( arrTime.length != 2 )
	{
		alert("Attenzione!\nOrario non valido.");
		vElement.focus();
		return false;
	}
	
	//--------------- controllo ora ----------------------------
	
	if ( (arrTime[0].length != 1) && (arrTime[0].length != 2) )
	{
		alert("Attenzione!\nOra non valida.");
		vElement.focus();
		return false;
	}

	vIntHour = ((arrTime[0].charAt(0) == "0") && (arrTime[0].length == 2)) ? parseInt(arrTime[0].charAt(1)) : parseInt(arrTime[0]);
	
	if (isNaN(vIntHour))
	{
		alert("Attenzione!\nOra non valida.");
		vElement.focus();
		return false;
	}
	else
	{
		if ( (vIntHour < 0) || (vIntHour > 23) )
		{
			alert("Attenzione!\nOra non valida.");
			vElement.focus();
			return false;
		}
	}
	
	//--------------- controllo minuti ----------------------------
	
	if ( (arrTime[1].length != 1) && (arrTime[1].length != 2) )
	{
		alert("Attenzione!\nMinuti non validi.");
		vElement.focus();
		return false;
	}

	vIntMinute = ((arrTime[1].charAt(0) == "0") && (arrTime[1].length == 2)) ? parseInt(arrTime[1].charAt(1)) : parseInt(arrTime[1]);
	
	if (isNaN(vIntMinute))
	{
		alert("Attenzione!\nMinuti non validi.");
		vElement.focus();
		return false;
	}
	else
	{
		if ( (vIntMinute < 0) || (vIntMinute > 59) )
		{
			alert("Attenzione!\nMinuti non validi.");
			vElement.focus();
			return false;
		}
	}
	
	return true;
}

function fnCompattaTimeFromTimeAndAddZero ( strTime, pstrSeparator, pbooCanBeNull )
{
	pbooCanBeNull	= isNull ( pbooCanBeNull, false );
	strTime			= String ( strTime );
	
	if ( ( pbooCanBeNull ) && ( strTime == "" ) )
	{
		return strTime;
	}
	else
	{
		var fnarrTime;
		fnarrTime = strTime.split( pstrSeparator );
		
		var strReturn	= "";
		
		strReturn		= addZero ( Number ( fnarrTime[0] ) ) + "" + addZero ( Number ( fnarrTime[1] ) );
		
		return strReturn;
	}
}

function CheckINT ( Form, Element, CanBeNull, NoMessage )
{
	var pElement		= document.forms[Form].elements[Element];	
	var ElementValue	= ReadElementValue ( pElement );

	if ( !CanBeNull )
	{
		if ( isNull ( ElementValue, "" ) == "" )
		{
			if ( (NoMessage == null) || (NoMessage == false) ) {
				ShowCheckError(0);
				pElement.focus();
			}
			else
			{
				alert(NoMessage);
				pElement.focus();
			}
			return false;
		}
	}
	else
	{
		if ( isNull ( ElementValue, "" ) == "" )
			return true;
	}

	if (ElementValue.indexOf(",") >= 0)
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			ShowCheckError(1);
			pElement.focus();
		}
		else
		{
			alert(NoMessage);
			pElement.focus();
		}
			
		return false;
	}

	if (ElementValue.indexOf(".") >= 0)
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			ShowCheckError(1);
			pElement.focus();
		}
		else
		{
			alert(NoMessage);
			pElement.focus();
		}
			
		return false;
	}

	var ii;
	ii = 0;
	
	if ( (ElementValue.charAt(0) == "+") || (ElementValue.charAt(0) == "-") )
	{
		ii = 1;
	}

	for ( ; ii < ElementValue.length; ii++ ) {
		if ( !((ElementValue.charAt(ii) >= "0") && (ElementValue.charAt(ii) <= "9")) ) {
			if ( (NoMessage == null) || (NoMessage == false) ) {
				ShowCheckError(1);
				pElement.focus();
			}
			else
			{
				ShowCheckError(1);
				pElement.focus();
			}
			return false;
		}
	}

/*
	if ( isNaN(parseInt(ElementValue)) )
	{
		if ( (NoMessage == null) || (NoMessage == false) ) {
			ShowCheckError(1);
			pElement.focus();
		}
		
		return false;
	}	
	else return true;
*/

	return true;	
}

function CheckCHECK ( pstrForm, pstrElement, pstrMessage, pintMin, pintMax )
{
	pintMin	= isNull ( pintMin, 0 );
	pintMax	= isNull ( pintMax, 0 );
	var fnObjElement	= document.forms[pstrForm].elements[pstrElement];
	var fnIntLength		= isNull ( fnObjElement.length, 1 );
	var fnBooIsChecked	= false;
	var fnIntElementChecked	= 0;
		
	if ( fnIntLength == 1 )
	{
		if ( fnObjElement.checked )
			fnBooIsChecked = true;
	}
	else
	{
		var fnIntCounter		= 0;
		
		for ( fnIntCounter = 0; fnIntCounter < fnIntLength; fnIntCounter++ )
		{
			if ( fnObjElement[fnIntCounter].checked )
			{
				fnBooIsChecked = true;
				fnIntElementChecked++;
			}
		}
	}
	
	if ( fnBooIsChecked )
	{
		if ( pintMin != 0 )
		{
			if ( fnIntElementChecked <  pintMin )
			{
				ShowCheckError ( pstrMessage + "\nSelezionare almeno " + pintMin + " elementi." );
				fnBooIsChecked = false;
			}
		}
		
		if ( pintMax != 0 )
		{
			if ( fnIntElementChecked >  pintMax )
			{
				ShowCheckError ( pstrMessage + "\nSelezionare al massimo " + pintMax + " elementi." );
				fnBooIsChecked = false;
			}
		}
	}
	else
	{
		if ( ( pstrMessage == null ) || ( pstrMessage == false ) )
			ShowCheckError ( 0 );
		else
			ShowCheckError ( pstrMessage );
	}
	
	return fnBooIsChecked;
}

function fnSelectRadio(pstrFieldName, pintIDRisposta)
{
	for ( var ii = 0; ii < document.forms["mainForm"].elements[pstrFieldName].length ; ii++ ) { document.forms["mainForm"].elements[pstrFieldName][ii].checked = false; }
	if (Number(pintIDRisposta) != -1) { document.forms["mainForm"].elements[pstrFieldName][pintIDRisposta].checked = true; }
}

function fnFormatStrForPop( pstrValue )
{
	pstrValue = pstrValue.replace(/\"/gi, "&#34;");	//"
	//pstrValue = pstrValue.replace(/\'/gi, "\\'");
	pstrValue = pstrValue.replace(/\'/gi, "&rsquo;");
	return pstrValue;
}

function fnCompareTwoDate ( pobjDateSmall, pobjDateBig, pstrMessage )
{
	if ( pobjDateSmall > pobjDateBig )
	{
		if ( ( pstrMessage == null ) || ( pstrMessage == false ) )
			ShowCheckError ( 1 );
		else
			ShowCheckError ( pstrMessage );
		
		return false;
	}
	
	return true;
}

function fnFormatInputDateToObjDate ( pstrData, pSeparatorDate, bHasHours, pSeparatorTime )
{
	pstrData		= String ( pstrData );
	pSeparatorDate	= isNull ( pSeparatorDate,	"/" );
	bHasHours		= isNull ( bHasHours,		false );
	pSeparatorTime	= isNull ( pSeparatorTime,	":" );
	
	if ( pstrData == "" )
		return "";
	
	var tmpDate	= "";
	var tmpTime	= "";
	
	if ( bHasHours )
	{
		var arrArray	= pstrData.split( " " );
		tmpDate			= arrArray[0];
		tmpTime			= arrArray[1];
	}
	else
	{
		tmpDate			= pstrData;
	}
	
	var arrDate		= tmpDate.split( pSeparatorDate );
	
	var objNewDate	= new Date();
	
	objNewDate.setDate(Number(arrDate[0]));
	objNewDate.setMonth(Number(arrDate[1]) - 1);
	objNewDate.setFullYear(Number(arrDate[2]));
	
	if (bHasHours)
	{
		var arrTime		= tmpTime.split ( pSeparatorTime );
		
		objNewDate.setHours		( Number ( arrTime[0] ) );
		objNewDate.setMinutes	( Number ( arrTime[1] ) );
	}
	
	return objNewDate;
}

function formatHTMLforXML(pstrValue)
{
	pstrValue = escape(pstrValue);
	pstrValue = pstrValue.replace(/%23%23%23ACAPO%23%23%23/gi, "%0D%0A"); // sostituisco gli ###ACAPO### con /r/n per textarea
	pstrValue = unescape(pstrValue);
	return pstrValue;
}

function removeCDATAtag(pstrText)
{
	pstrText = pstrText.replace(/<!\[CDATA\[/, "");
	pstrText = pstrText.replace(/\]\]>/, "");
	
	return pstrText;
}

function appendCDATAtag(pstrText)
{
	return "<![CDATA[" + pstrText + "]]>";
}

function fnOpenDivSI() {
	document.getElementById("SapernePiu").style.display = "block";
}

function fnCloseDivSI() {
	document.getElementById("SapernePiu").style.display = "none";
}

function fnAddZero ( pintNumber )
{
	pintNumber = Number ( pintNumber );
	
	if ( pintNumber == 0 ) return "00";
	else
	{
		if ( pintNumber < 10 ) return "0" + pintNumber;
		else return pintNumber;
	}
}

function fnFormatObjDateToMDBDate ( pObjDate, pintDigit )
{
	pintDigit	= isNull ( pintDigit, 8 );
	pObjDate	= isNull ( pObjDate, new Date() );
	pObjDate	= new Date ( pObjDate );
	
	var szData	= pObjDate.getFullYear() + "" + fnAddZero ( pObjDate.getMonth() + 1 ) + "" + fnAddZero ( pObjDate.getDate() );
	
	if ( pintDigit >  8 )	szData += "" + fnAddZero ( pObjDate.getHours() );
	if ( pintDigit > 10 )	szData += "" + fnAddZero ( pObjDate.getMinutes() );
	if ( pintDigit > 12 )	szData += "" + fnAddZero ( pObjDate.getSeconds() );
	
	return szData;
}
//-->