// Leap Year Calculator
//
// Written by M.A.Smith, January 1999	Version 1.0
//
// Please email Mark.Smith@dataIP.co.uk with any comments or bug  reports.
//
// The layout below is not intended to be particularly efficient...
// it is just supposed to illustrate the method clearly.
// P.S. Yes, I know its not "efficient" to comment JavaScript code!
//
// Efficient function is more like;
// function Leap(y) {(y%4 == 0 && !(y%100 == 0 && !(y%400 == 0)))};


function Leap(Year)
	{
	if ( (Year % 4) == 0)
		{
		// It is exactly divisible by 4

		if ( (Year % 100) == 0)
			{
			// It is exactly divisible by 100
			// Is it also exactly divisible by 400?
			Result = ( (Year % 400) == 0);
			}
		else
			{
			Result = 1;
			}
		}
	else
		{
		// It is not exactly divisible by 4
		// It is not a leap year
		Result = 0;
		}

	return (Result);
	}


function Calculate(form)
	{
	if (form.Year.value == "")
		{
		alert("Please enter a year.");
		}
	else
		{
		if (Leap(form.Year.value))
			{
			form.Result.value = "YES";
			}
		else
			{
			form.Result.value = "NO";
			}
		}
	}


// Clear the output field
function Clear(form)
	{
	form.Result.value = "";
	}
