<!--
function trim(str)
{
  var temp = new String(str);
  while (temp.substr(0,1) == " ")
  {
    temp = temp.substr(1);
  }
  while (temp.substr(temp.length - 1) == " ")
  {
    temp = temp.substring(0,temp.length -1);
  }
  return temp;
}

/*
--------------------------------------
*** isDate(data, dateformat, flag) ***
--------------------------------------
data					input data
dateformat		"ddmmyyyy" "mmddyyyy" "yyyymmdd"
flag					flag = "Complete" or "C"  verifica i valori di giorno e mese
*/

function isDate(data, dateformat, flag)
{
	
	//alert(data);
	var a = 0;
	var b;
	var c;
	
	data =  trim(data);
	
	a = data.indexOf("/");
	if (a > 0)
	{
		b = data.split("/");
	}
	else
	{
		a = data.indexOf("-");
		if (a > 0)
		{
			b = data.split("-");
		}
		else
		{
			a = data.indexOf(" ");
			if (a > 0)
			{
				b = data.split(" ");
			}
			else
			{
				return false;
			}
		}
	}

/*	
	alert(dateformat);
	alert(dateformat.toString().indexOf('yyyy'));
*/	
	if(dateformat.toString().indexOf('yyyy')>2) {
		if ((b[0].valueOf().length > 2) || (isNaN(parseInt(b[0].valueOf()))))
		{
			return false;
		}
		else
		{
			switch (dateformat.substr(0,2))
			{
				case "dd":
					if (b[0].valueOf() > 31 || b[0].valueOf() < 1)
					{
						return false;
					}
					break;
				case "mm":
					if (b[0].valueOf() > 12 || b[0].valueOf() < 1)
					{
						return false;
					}
					break;	
			}
		}
	} else {
		if ((b[0].valueOf().length > 4) || (isNaN(parseInt(b[0].valueOf())))) {
			return false;
		} else {
			if (dateformat.substr(0,4) == "yyyy") {			
				if (b[0].valueOf() > 2050 || b[0].valueOf() < 2000) return false;
			}
		}
	}
	
	if ((b[1].valueOf().length > 2) || (isNaN(parseInt(b[1].valueOf()))))
	{
		return false;
	}
	else
	{
		switch (dateformat.substr(2,2))
		{
			case "dd":
				if (b[1].valueOf() > 31 || b[1].valueOf() < 1)
				{
					return false;
				}
				break;
			case "mm":
				if (b[1].valueOf() > 12 || b[1].valueOf() < 1)
				{
					return false;
				}
				break;
		}
	}
	if ((trim(b[2].valueOf()).length != 4) || (isNaN(parseInt(trim(b[2].valueOf())))))
	{
		return false;
	}
/* ************************************************************
VERIFICA COMPLETA DELLA DATA
************************************************************ */
	if (flag.toUpperCase().substr(0,1) != "C")
	{
		return true;
	}
	else
	{
		if (dateformat.substr(0,2) == "dd")
		{
			var d = b[0].valueOf();
			var m = b[1].valueOf();
		}
		else
		{
			var d = b[1].valueOf();
			var m = b[0].valueOf();
		}
		var a = b[2].valueOf();
		switch (m)
		{
			case "1":
			case "3":
			case "5":
			case "7":
			case "8":
			case "10":
			case "12":
				if (d > 31 || d < 1)
				{
					return false;
				}
				break;
			case "4":
			case "6":
			case "9":
			case "11":
				if (d > 30 || d < 1)
				{
					return false;
				}
				break;
			case "2":
				if (((a % 4) == 0 && (a % 100) != 0 || (a % 400) == 0))
				{
					if (d > 29 || d < 1)
					{
						return false;
					}
				}
				else
				{
					if (d > 28 || d < 1)
					{
						return false;
					}
				}
				break;
		}
	}
	return true;
}
//-->