//
// Cross-browser event handling for IE5+, NS6 and Mozilla
// By Scott Andrew 

function AddEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) { 
		elm.addEventListener(evType, fn, useCapture); 
		return true; 
	} else if (elm.attachEvent) { 
		var r = elm.attachEvent('on' + evType, fn); 
		return r; 
	} else {
		elm['on' + evType] = fn;
	}
}

//
//

//
// BEGIN functions to check that required fields on the contact form have been filled out.

function CheckContactRequiredFields() {
	if (!document.getElementById) return false;
	var ContactForm = document.getElementById("ContactForm");
	if (ContactForm) {
		ContactForm.onsubmit = function() {
			var Name = document.getElementById("Name");
			var Email = document.getElementById("Email");
			var Subject = document.getElementById("Subject");
			var Message = document.getElementById("Message");
			if ((Name.value == '') || (Email.value == '') || (Subject.value == '') || (Message.value == '')) {
				alert("Please make sure that you have filled out ALL of the required fields.");
				return false;
			} else {
				return true;
			}
		}
	}
}

AddEvent(window,'load',CheckContactRequiredFields,false);

// END functions to check that required fields on the contact form have been filled out.
//

//
// BEGIN functions to check that required fields on the advertising request form have been filled out.

function CheckAdvertisingRequiredFields() {
	if (!document.getElementById) return false;
	var AdvertisingForm = document.getElementById("AdvertisingForm");
	if (AdvertisingForm) {
		AdvertisingForm.onsubmit = function() {
			var Name = document.getElementById("Name");
			var Email = document.getElementById("Email");
			var Organization = document.getElementById("Organization");
			if ((Name.value == '') || (Email.value == '') || (Organization.value == '')) {
				alert("Please make sure that you have filled out ALL of the required fields.");
				return false;
			} else {
				return true;
			}
		}
	}
}

AddEvent(window,'load',CheckAdvertisingRequiredFields,false);

// END functions to check that required fields on the advertising request form have been filled out.
//

//
// BEGIN mailing list functions.

// Begin checking that required fields on the mailing list signup form have been filled out
function CheckMailingListRequiredFields() {
	if (!document.getElementById) return false;
	var MailingListForm = document.getElementById("MailingListForm");
	if (MailingListForm) {
		MailingListForm.onsubmit = function() {
			var Email = document.getElementById("MailingListEmail");
			var HearAboutUs = document.getElementById("HearAboutUs");
			var SpecifyHearAboutUsEntry = document.getElementById("SpecifyHearAboutUsEntry");
			if ((Email.value == '') || 
				(HearAboutUs.value == '') || 
				(SpecifyHearAboutUsEntry.value == '')) {

				alert("Please make sure that you have filled out ALL of the required fields.");
				return false;

			} else {

				return true;

			}
		}
	}
}

AddEvent(window,'load',CheckMailingListRequiredFields,false);
// End checking that required fields on the mailing list signup form have been filled out

// Begin functions for displaying "Please Specify" field
function DisplayOtherCountrySpecify() {

	if (!document.getElementById) return false;
	
	var Region = document.getElementById("Region");
	var SpecifyOtherCountry = document.getElementById("SpecifyOtherCountry");
	var SpecifyOtherCountryLabel = document.getElementById("SpecifyOtherCountryLabel");
	var OtherCountry = document.getElementById("OtherCountry");
	
	if ((Region) && (SpecifyOtherCountry) && (OtherCountry)) {
		Region.onchange = function() {
			var RegionSelected = Region.options[Region.selectedIndex].value;
						
			if (RegionSelected == "Other") {
			
				SpecifyOtherCountryLabel.lastChild.nodeValue = 'Please specify your country: *';
				
			} else {

				SpecifyOtherCountry.style.display = "none";

			}
		}
	}
}

//AddEvent(window,'load',DisplayOtherCountrySpecify,false);
// Begin functions for displaying "Please Specify" field

// Begin functions for displaying "Please Specify" field
function DisplayPleaseSpecify() {
	if (!document.getElementById) return false;
	var HearAboutUs = document.getElementById("HearAboutUs");
	var SpecifyHearAboutUs = document.getElementById("SpecifyHearAboutUs");
	var SpecifyHearAboutUsLabel = document.getElementById("SpecifyHearAboutUsLabel");
	
	if ((HearAboutUs) && (SpecifyHearAboutUs) && (SpecifyHearAboutUsLabel)) {

		HearAboutUs.onchange = function() {
		
				var HearAboutUsSelected = HearAboutUs.options[HearAboutUs.selectedIndex].value;
			
				if (HearAboutUsSelected == 'Online') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify website: *';
				} else if (HearAboutUsSelected == 'Magazine') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify magazine: *';
				} else if (HearAboutUsSelected == 'Newspaper') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify newspaper: *';
				} else if (HearAboutUsSelected == 'Poster') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify where you saw the poster: *';
				} else if (HearAboutUsSelected == 'Flyer/Brochure') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify where you got the flyer/brochure: *';
				} else if (HearAboutUsSelected == 'DVD') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify where you got the DVD: *';
				} else if (HearAboutUsSelected == 'Film Screening') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify film screening: *';
				} else if (HearAboutUsSelected == 'Film Festival') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify film festival: *';
				} else if (HearAboutUsSelected == 'Convention/Special Event') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify which Convention or Special Event: *';
				} else if (HearAboutUsSelected == 'TV') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify TV station: *';
				} else if (HearAboutUsSelected == 'Radio') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify radio station: *';
				} else if (HearAboutUsSelected == 'Member of festival staff') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please specify staff member: *';
				} else if (HearAboutUsSelected == 'E-mail/Newsletter from the Festival') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Are you already on the Festival mailing list? *';
				} else if (HearAboutUsSelected == 'Other') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Please give more detail: *';
				} else if (HearAboutUsSelected == 'Friend, acquaintance, co-worker') {
					SpecifyHearAboutUsLabel.lastChild.nodeValue = 'Did you get an e-mail from them? *';
				}
				
		}
	}
}

AddEvent(window,'load',DisplayPleaseSpecify,false);
// Begin functions for displaying "Please Specify" field

// END mailing list functions
//

//
// BEGIN functions for bottom nav pulldown redirection.

function PageRedirect() {
	var RedirectSelect = document.getElementById('RedirectSelect');
	window.location.href = RedirectSelect.options[RedirectSelect.selectedIndex].value;
}

function AttachRedirectHandlers() {
	var RedirectSelect = document.getElementById('RedirectSelect');
	RedirectSelect.onchange = PageRedirect;
}

AddEvent(window,'load',AttachRedirectHandlers,false);

// END functions for bottom nav pulldown redirection.
//
