//    CONVALIDA DI UNA EMAIL
//    emailvalidation(this,text)
//    text è il testo di errore mostrato

function emailvalidator(entered,alertbox)				
{
with (entered)
	{
	apos = value.indexOf("@");
	dotpos = value.lastIndexOf(".");
	lastpos = value.lenght - 1;
	if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2)
		 {
		 if (alertbox) 
		 	{
			alert(alertbox);
			}
		return false;
		}
	else
		{
		return true;
		}
	}
}


//    CONVALIDA NUMERO IN UN'AREA
//    valuevalidation(this, min, max, text, type)
//	  min è il valore minimo consentito
//    max è il valore massimo consentito
//    text è il testo di errore mostrato
//    type inserire 'i' valori devono essere numeri interi


function valuevalidation(entered, min, max, alertbox, datatype)
{
with (entered)
	{
	checkvalue = parseFloat(value);
	if (checkvalue)
		{
		if (datatype)
			{
			smalldatatype = datatype.toLowerCase();
			if (smalldatatype.charAt(0) == "i")
				{
				checkvalue = parseInt(value);
				}
			}
			if ((parseFloat(min) == min && checkvalue < min) || (parseFloat(max) == max && checkvalue > max) || value != checkvalue)
				{
				if (alertbox != "")
					{
					alert(alertbox);
					}
				return false;
				}
		else
			{
			return true;
			}
		}
	else
		{
		return true;
		}
 	}
}


//    CONVALIDA CARATTERI 
//    digitvalidation(this, min, max, text, type)
//	  min è il valore minimo consentito di caratteri
//    max è il valore massimo consentito di caratteri
//    text è il testo di errore mostrato
//    type inserire 'i' valori devono essere numeri interi


function digitvalidation(entered, min, max, alertbox, datatype)
{
with(entered)
	{
	
	checkvalue = parseFloat(value);
	if (datatype)
		{
		smalldatatype = datatype.toLowerCase();
		if (smalldatatype.charAt(0) == "i")
			{
			checkvalue = parseInt(value);
			if (value.indexOf(".") != -1)
				{
				checkvalue = checkvalue + 1;
				}
			}
		}
		if ((parseFloat(min) == min && value.lenght < min) || (parseFloat(max) == max && value.lenght > max) || value != checkvalue)
			{
			if (alertbox != "")
				{
				alert(alertbox);
				}
		return false;
		}
	else 
		{
		return true;
		}
	}
}
	
	
//    CONVALIDA CAMPO NON VUOTO
//    empityvalidation(this,text)
//    text è il testo di errore mostrato
	
function emptyvalidation(entered, alertbox)
{
with (entered)
	{
	if (value == null || value == "")
		{
		if (alertbox != "")
			{
			alert(alertbox);
			}
		return false;
		}
	else
		{
		return true;
		}
	}
}


//    CONVALIDA CAMPO DATA
//    empityvalidation(this,text)
//    text è il testo di errore mostrato

function datavalidation(entered, alertbox)
{
with (entered)
	{
	gg = value.substring(0,2);
	mm = value.substring(3,5);
	aa = value.substring(6,10);
	if (value != "")
		{
		if (gg <= 31 && gg >= 1 && mm <= 12 && mm >= 1 && aa <= 3000 && aa >= 1900 )
			{
			return true;
			}
		else
			{
			if (alertbox != "")
				{
				alert(alertbox);
				}
			return false;
			}
		}
	else
		{
		return true;
		}
	}
}		



//    CONVALIDA CAMPO NUMERICO
//    empityvalidation(this,text)
//    text è il testo di errore mostrato
	
function numericvalidation(entered, alertbox)
{
var strValidChars = "0123456789.,";
var strChar;
var blnResult = true;
with (entered)
	{
	if (entered.value == "")
		{
		if (alertbox != "")
				{
				alert(alertbox);
				}
		return false;
		}
		else
		{
		for (i = 0; i < entered.value.length && blnResult == true; i++)
		  {
		  strChar = entered.value.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 if (alertbox != "")
				{
				alert(alertbox);
				}
			 return false;
			 }
		  }
		}
		return true;
	}
}







