// Check the given date
function checkDate( yyyy, mm, dd )
{
	var error = 0;

	// Check if the fields are numeric
	if( isNaN( yyyy ) ) error = 1;
	if( isNaN( mm ) ) error = 2;
	if( isNaN( dd ) ) error = 3;

	// Basic error checking
	if( ( dd < 1 ) || ( dd > 31 ) ) error = 1;
	if( ( mm < 1 ) || ( mm > 12 ) ) error = 2;
	if( yyyy < 1830 ) error = 3;

	// Advanced error checking

	// Months with 30 days
	if ( mm == 4 || mm == 6 || mm == 9 || mm == 11 )
	{
		if( dd == 31 ) error = 1;
	}

	// Frebruary, leap year
	if( mm == 2 )
	{
		// Feb
		if( dd > 29 ) error = 1;

		// Check leap year
		if( dd == 29 && !isLeap( yyyy ) ) error = 1;
	}

	return error;
}

// determine if the given year is a leap year.
function isLeap( year )
{
	if( ( year % 4 == 0 ) && ( year % 100 != 0 ) || ( year % 400 == 0 ) )
		return true;
	else
		return false;
}

// compare the given dates
function compareDate( fromDate, toDate )
{

	if ( fromDate > toDate ) error = 1;
	else if ( fromDate == toDate ) error = 0;
	else error = -1;

	return error;
}

// Get current timestamp
function getCurrentDateTime()
{
	var now = new Date();
	var yr  = now.getYear();
	var mn  = now.getMonth()+1;
	var dt  = now.getDate();
	var dy  = now.getDay();
	var hh  = now.getHours();
	var mm  = now.getMinutes();
	var ss  = now.getSeconds();
	var refresh = yr + mn + dt + dy + hh + mm + ss;

	return refresh;
}
