// --------------------------------------------------------------------------
// This file contains a list of general use client side JavaScript functions.
// The functions of this file can be accessed externally by specifying the
// URL of this file as a value for the 'src' attribute of the script tag:
//
// <SCRIPT language="JavaScript" src="/cnacs/pub-doc/common.js"></SCRIPT>
//
// Note:
// There is the potential that this file will be loaded by numerous html
// files, so whenever changes are made to this file the changes can be
// be reflected on several pages. This means that if the file contains
// incorrect code, a number of pages may work incorrectly.
// -------------------------------------------------------------------------

// This function returns true if the date represented by the parameters is
// after the current day. Otherwise, it returns false. The year must be
// a 4 digit representation, the month must be a number in the range 0 - 11,
// and the day must be a number in the range 1 - 31.
//
// Before invoking this function the year, month, day combination must be 
// validate. The isValidDate(year, month, day) function can be used for this
// purpose.
function isAfterCurrentDate(year, month, day)
{
	var testDate = new Date(year, month, day);
	var currentDate = new Date();
		
	if	(testDate.getYear() > currentDate.getYear() ) return true;

	if (testDate.getYear() == currentDate.getYear() &&
		testDate.getMonth() > currentDate.getMonth() ) return true;

	if (testDate.getYear() == currentDate.getYear() &&
		testDate.getMonth() == currentDate.getMonth() &&
		testDate.getDate() > currentDate.getDate()) return true;

	return false;

}

// This function returns true if the date represented by the parameters is
// the same as the current day. Otherwise, it returns false. The year must be
// a 4 digit representation, the month must be a number in the range 0 - 11,
// and the day must be a number in the range 1 - 31.
//
// Before invoking this function the year, month, day combination must be 
// validate. The isValidDate(year, month, day) function can be used for this
// purpose.
function isCurrentDate(year, month, day)
{
	var testDate = new Date(year, month, day);
	var currentDate = new Date();

	if(currentDate.getYear() == testDate.getYear() && 
	   currentDate.getMonth() == testDate.getMonth() &&
	   currentDate.getDate() == testDate.getDate())						   
		return true;
	else
		return false;
}

// This function returns true if the date represented by the parameters is
// a valid date. Otherwise, it returns false. The year must be a 4 digit 
// representation, the month must be a number in the range 0 - 11, and the
// day must be a number in the range 1 - 31.
function isValidDate(year, month, day)
{
	if(isNaN(year) || isNaN(month) || isNaN(day))
		return false;

	if((month == 3 || month == 5 || month == 9 || month == 11) && day == 31)
		return false;
	
	if(month == 1)
	{
		if(day > 29)
			return false;
	
//		if(day == 29 && (year % 4) != 0)
//			return false;

		if(day == 29)
			if(year%4 != 0)
				return false;
			else
				if(year%100 != 0)
					return true;
				else
					if(year%400 != 0)
						return false;
	}

	return true;
}

// This function disables all checkboxes which have a certain name, but
// don't have a certain value. In addition to the name, and the value, the
// form object that contains the checkboxes is passed as a parameter to
// the method.
function disableOthers(formObject, checkboxName, checkboxValue)
{
	for(i = 0; i < formObject.length; i++)		
		if(formObject.elements[i].name == checkboxName && formObject.elements[i].value != checkboxValue)
			formObject.elements[i].checked = false;
}
	  
            








	
	
	

