// JavaScript Document

function setProvince()
//  Resets the Province popup depending on the selected county
{
	switch(document.Search.wsCounty1.options[document.Search.wsCounty1.selectedIndex].value)
	{
		case "Galway":
		case "Leitrim":
		case "Mayo":
		case "Roscommon":
		case "Sligo":
			document.Search.wsProvince1.options[1].selected = true;
		break;
		
		case "Carlow":
		case "Dublin":
		case "Kildare":
		case "Kilkenny":
		case "Laois":
		case "Longford":
		case "Louth":
		case "Meath":
		case "Offaly":
		case "Westmeath":
		case "Wexford":
		case "Wicklow":
			document.Search.wsProvince1.options[2].selected = true;
		break;
		
		case "Clare":
		case "Cork":
		case "Cork":
		case "Kerry":
		case "Limerick":
		case "Tipperary":
		case "Waterford":
			document.Search.wsProvince1.options[3].selected = true;
		break;
		
		case "Antrim":
		case "Armagh":
		case "Cavan":
		case "Derry":
		case "Donegal":
		case "Down":
		case "Fermanagh":
		case "Monaghan":
		case "Tyrone":
			document.Search.wsProvince1.options[4].selected = true;
		break;
		
		default:
			document.Search.wsProvince1.options[0].selected = true;
		break;
	}
}

function setCounty()
//  Resets the Province popup depending on the selected county
{
	document.Search.wsCounty1.options[0].selected = true;
}

function validateYears()
//  Validate that a valid Year was entered.
{
	if(document.Search.wsConjunction.value == "between")
	{
		var fromYear = document.Search.wsFromYear;
		var toYear = document.Search.wsToYear;
	
		if( fromYear.value != "YYYY")
		{
			if(isNaN(fromYear.value) == true)
			{
				alert("The 'From' Year is invalid.");
				fromYear.value = "YYYY";
				fromYear.focus();
				fromYear.select();
				return false;
			}
		}
	
		if( toYear.value != "YYYY")
		{
			if(isNaN(toYear.value) == true)
			{
				alert("The 'To' Year is invalid.");
				toYear.value = "YYYY";
				toYear.focus();
				toYear.select();
				return false;
			}
		}
	
		if((fromYear.value != "YYYY") && ( toYear.value != "YYYY"))
		{
			if( parseInt(toYear.value) < parseInt(fromYear.value) )
			{
				alert("The 'To' Year must be after the 'From' Year.");
				toYear.focus();
				toYear.select();
				return false;
			}
		}
	}
	else
	{
		var fromYear = document.Search.wsFromYear;
		
		if( fromYear.value != "YYYY")
		{
			if(isNaN(fromYear.value) == true)
			{
				alert("The Year entered is invalid.");
				fromYear.value = "YYYY";
				fromYear.focus();
				fromYear.select();
				return false;
			}
		}
	}
}

function formSubmit1()
{
	document.Search.wsTimeIndicator.value = "SubmitYes1";
	document.getElementById("Search").submit();
}

function formSubmit2()
{
	document.Search.wsTimeIndicator.value = "SubmitYes2";
	document.getElementById("Search").submit();
}
