function Validate(f)
{
var i

	for (i = 0; i < f.elements.length; i++)
	{
		if (f.elements[i].type == 'text')
		{
			f.elements[i].value = Trim(f.elements[i].value)
		}
	}

   	if (f.category.selectedIndex == 0 && 
		f.location.selectedIndex == 0 && 
   		f.tutor.selectedIndex == 0 && 
   		f.day.selectedIndex == 0 &&
   		f.coursecode.value.length == 0 && 
   		f.month.selectedIndex == 0 &&
   		f.title.value.length == 0) 
   	{
   		if (confirm('You haven\'t specified any criteria, so the list will show all of the available courses at all locations.\n\nThis list of several hundred courses may take a while to display - are you sure you want to proceed?') == false)
   		{
   			f.caegory.focus()
	   		return false
	   	}
   	}

	f.submit.disabled = true
	return true
}

//=======================================================================
function CheckAndFormatDate(sInput)
{
var d = 0
var m = 0
var y = 0
var dd, mm, yyyy
var i, ch
var slash = '/'
var ErrAlert = "Invalid date, please enter in d/m/y format"
var sReturn = ''
var days = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

	if (sInput.length < 5 || sInput.length > 10)
	{
		alert('Invalid date format, must be between 5 and 10 characters')
		return sReturn
	}

//	Locate the first slash
	i = sInput.indexOf(slash)
	if (i == -1)
	{
		alert(ErrAlert)
		return sReturn
	}

//	Set d to the chars up to the slash
	ch = sInput.substr(0, i)
	if (ch.length == 0 || ch.length > 2)
	{
		alert('Invalid date format, day must be 1 or 2 characters')
		return sReturn
	}

//	Bizarre bug stops parseInt from working for 08 and 09
	if (ch == '08' || ch == '09')
	{
		d = parseInt(ch.substr(1, 1))
	}
	else
	{
		d = parseInt(ch)
	}
	
	if (isNaN(d))
	{
		alert('Invalid day, must be numeric')
		return sReturn
	}

	if (d < 1 || d > 31)
	{
		alert('Invalid day, must be between 1 and 31')
		return sReturn
	}
	
	dd = d
	if (d < 10)
	{
		dd = '0' + d
	}

//	Remove the day portion from the input
	sInput = sInput.substring(++i, sInput.length)

//	Locate the second slash
	i = sInput.indexOf(slash)
	if (i == -1)
	{
		alert(ErrAlert)
		return sReturn
	}

//	Set m to the chars up to the slash
	ch = sInput.substr(0, i)
	if (ch.length == 0 || ch.length > 2)
	{
		alert('Invalid date format, month must be 1 or 2 characters')
		return sReturn
	}

//	Bizarre bug stops parseInt from working for 08 and 09
	if (ch == '08' || ch == '09')
	{
		m = parseInt(ch.substr(1, 1))
	}
	else
	{
		m = parseInt(ch)
	}

	if (isNaN(m))
	{
		alert('Invalid month, must be numeric')
		return sReturn
	}

	if (m < 1 || m > 12)
	{
		alert('Invalid month, must be between 1 and 12')
		return sReturn
	}

	mm = m
	if (m < 10)
	{
		mm = '0' + m
	}

//	Remove the month portion from the input
	sInput = sInput.substring(++i, sInput.length)

//	Set y to the remaining chars
	ch = sInput

	if (ch.length != 1 && ch.length != 2 && ch.length != 4)
	{
		alert('Invalid date format, year must be 1, 2 or 4 characters')
		return sReturn
	}

//	Bizarre bug stops parseInt from working for 08 and 09
	if (ch == '08' || ch == '09')
	{
		y = parseInt(ch.substr(1, 1))
	}
	else
	{
		y = parseInt(ch)
	}

	if (isNaN(y))
	{
		alert('Invalid year, must be numeric')
		return sReturn
	}

	if (y < 1 || y > 2100)
	{
		alert('Invalid year, cannot be greater than 2100 ' + y)
		return sReturn
	}

	yyyy = y
	if (ch.length == 1)
	{
		yyyy = '200' + ch
	}

	if (ch.length == 2)
	{
		yyyy = '20' + ch
	}

	if (d > days[m])
	{
		alert('Invalid date, day greater than the maximum for the month')
		return sReturn
	}

	sReturn = dd + slash + mm + slash + yyyy
      return sReturn
}
