function Trim(string)
{
	var start = 0, end = string.length;
	while(string.charAt(start) == ' ')	start++;
	if (start == end) return "";			// we reached the end... return empty string
	while(string.charAt(end-1) == ' ')	end--;
	return string.substring(start, end);
}
function isDate(pday, pmonth, pyear)
{
	var day, month, year;
	day	  = parseInt(pday, 10);
	month = parseInt(pmonth, 10);
	year  = parseInt(pyear, 10);

	//	Basic checks...
	if (year < 1000 || year > 3000)
		return false;
	if (day < 1 || month < 1)
		return false;

	//	Depending on the month and year, check if day is valid (related to leap year)
	//	Note that it follows Pope Gregory XIII's rule (1582)
	switch (month)
	{
		case 1: case 3: case 5: case 7: case 8: case 10: case 12:
			if (day > 31) return false;
			break;
		case 4: case 6: case 9: case 11:
			if (day > 30) return false;
			break;
		case 2:
			if (year % 100 == 0 )	{		// we are at a century change (1900, 2000 etc.)
				if (year % 400 == 0)	{	// we are at an exception century change (2000 etc.)
					if (day > 29) return false;
				}	else	{
					if (day > 28) return false;
				}
			}	else	{
				if (year % 4 == 0)	{
					if (day > 29) return false;
				}	else	{
					if (day > 28) return false;
				}
			}
			break;
		default:
			return false;
	}
	return true;
}
