function initializeForm()
{
	toggleInternational(document.CalendarAddition.country[document.CalendarAddition.country.selectedIndex].value, 'USStateDiv', 'otherStateDiv', 'USStateInput', 'otherStateInput', 'state');
	toggleInternational(document.CalendarAddition.organizerCountry[document.CalendarAddition.organizerCountry.selectedIndex].value, 'organizerUSStateDiv', 'organizerOtherStateDiv', 'organizerUSStateInput', 'organizerOtherStateInput', 'organizerState');
	toggleInternational(document.CalendarAddition.contactCountry[document.CalendarAddition.contactCountry.selectedIndex].value, 'contactUSStateDiv', 'contactOtherStateDiv', 'contactUSStateInput', 'contactOtherStateInput', 'contactState');
	setDates(document.CalendarAddition.startDate.value);
	displayBroadcasts();
	displayDistances();
	displayFieldEvents();
	toggleSubEvents();
}

// show field events data-entry section for T&F events
function toggleSubEvents()
{
	var eventType = document.CalendarAddition.eventType.value;
	
	if (eventType == 'I' || eventType == 'O')
		modifyDisplay('fieldEventsSection', 'block');
	else
		modifyDisplay('fieldEventsSection', 'none');
}

// confirm that past dates are correct
function checkDate(thisDate)
{
	var myDate = new Date(thisDate);
	var currentDate = new Date();
	
	// compensate for Y2K
	if (myDate.getFullYear() < 2000)
		myDate = new Date( (myDate.getMonth() + 1) + '/' + myDate.getDate() + '/' + (myDate.getFullYear() + 100) );
	
	if (myDate < currentDate)
		alert('The date you entered has already passed.  Are you sure this is the correct date?');
	
	myDate = null;
	currentDate = null;
}

// default distance/field event dates to the event's start date
function setDates(startDate)
{
	document.CalendarAddition.distanceDate.value = startDate;
	document.CalendarAddition.fieldEventDate.value = startDate;
}

// display notice for officials-needed
function officialsNotice()
{
	if (document.CalendarAddition.officialsNeeded[0].checked)
		alert('You have indicated that your event needs officials.  USATF will include your event in a listing of events needing officials in the Officials section of the USATF website.  Officials will be able to browse the list and may contact your event\'s Contact Person if interested.  USATF does not guarantee that officials will be located for your event.');
}

// copy event director's contact info to public contact person's contact info if they're the same
function copyEventDirector()
{
	if (document.CalendarAddition.sameAsEventDirector.checked)		// it's checked
	{
		document.CalendarAddition.contactName.value = document.CalendarAddition.organizerName.value;
		document.CalendarAddition.contactStreet.value = document.CalendarAddition.organizerStreet.value;
		document.CalendarAddition.contactStreet2.value = document.CalendarAddition.organizerStreet2.value;
		document.CalendarAddition.contactCity.value = document.CalendarAddition.organizerCity.value;
		document.CalendarAddition.contactState.value = document.CalendarAddition.organizerState.value;
		document.CalendarAddition.contactOtherState.value = document.CalendarAddition.organizerOtherState.value;
		document.CalendarAddition.contactZipcode.value = document.CalendarAddition.organizerZipcode.value;
		document.CalendarAddition.contactCountry.value = document.CalendarAddition.organizerCountry.value;
		document.CalendarAddition.contactPhone.value = document.CalendarAddition.organizerPhone.value;
		document.CalendarAddition.contactEmail.value = document.CalendarAddition.organizerEmail.value;
		document.CalendarAddition.contactFax.value = document.CalendarAddition.organizerFax.value;
		
		toggleInternational(document.CalendarAddition.contactCountry[document.CalendarAddition.contactCountry.selectedIndex].value, 'contactUSStateDiv', 'contactOtherStateDiv', 'contactUSStateInput', 'contactOtherStateInput', 'contactState');
	}
	else
	{
		document.CalendarAddition.contactName.value = '';
		document.CalendarAddition.contactStreet.value = '';
		document.CalendarAddition.contactStreet2.value = '';
		document.CalendarAddition.contactCity.value = '';
		document.CalendarAddition.contactState.value = '';
		document.CalendarAddition.contactOtherState.value = '';
		document.CalendarAddition.contactZipcode.value = '';
		document.CalendarAddition.contactCountry.value = 'US';
		document.CalendarAddition.contactPhone.value = '';
		document.CalendarAddition.contactEmail.value = '';
		document.CalendarAddition.contactFax.value = '';
		
		toggleInternational(document.CalendarAddition.contactCountry[document.CalendarAddition.contactCountry.selectedIndex].value, 'contactUSStateDiv', 'contactOtherStateDiv', 'contactUSStateInput', 'contactOtherStateInput', 'contactState');
	}
}

function checkDescriptionLength()
{
	if (document.CalendarAddition.description.value.length > 1000)
	{
		alert('The description is limited to 1000 characters, and you have reached the limit.');
		document.CalendarAddition.description.value = document.CalendarAddition.description.value.substring(0,1000);
	}
}

// be sure form can't be submitted without sub-events (distances/field events) having been added to the list
function checkForErrors()
{
	if (document.CalendarAddition.broadcastDate.value != '')
	{
		alert('A broadcast date is entered in the "add a broadcast" form, but has not been added to the broadcasts list.  Please either click the "Add" button to add it to the list or clear the broadcast boxes.');
		return false;
	}
	else if (document.CalendarAddition.distance.value != '')
	{
		alert('A distance is entered in the "add a running/walking event" form, but has not been added to the running/walking events list.  Please either click the "Add" button to add it to the list or clear the distance boxes.');
		return false;
	}
	else if (document.CalendarAddition.fieldEvent.value != '')
	{
		alert('A field event is entered in the "add a field/combined event" form, but has not been added to the field/combined events list.  Please either click the "Add" button to add it to the list or clear the field event box.');
		return false;
	}
	else
	{
		if (document.CalendarAddition.distanceList.value == '' && document.CalendarAddition.fieldEventList.value == '')
			return confirm('It appears as though you have not entered any distances or field/combined events. We strongly recommend adding these, as many searches are based on them, and without them your event will not show up in the search results. Click \'OK\' to proceed without adding events, or click \'Cancel\' to go back and add them.');
		else
			return true;
	}
}
