
// Validates form input
function ValidateFields()
{
	var form = document.forms[0];
	
	if (IsNotBlank(form.uiFirstName) 
		&& IsNotBlank(form.uiLastName)
		&& IsNotBlank(form.uiEmail)
		&& IsNotBlank(form.uiContactPhone)
		&& IsValidSelection(form.uiCountry)
		&& IsValidSelection(form.uiContactPhoneBestTime)
		&& IsValidSelection(form.uiReferralMethod))
	{
		return true;
	}
	else
	{
		var msg = "You must complete all the fields marked with a *";
		alert(msg);
		return false;
	}
}

// Checks for blanks
function IsNotBlank(textBoxField)
{
	return (textBoxField.value.length > 0) ? true : false;
}

// Checks for blanks
function IsValidSelection(dropDownField)
{
	return (dropDownField.options[dropDownField.selectedIndex].value != "") ? true : false;
}

// Toggles Course visibility
function ToggleCourseVisibility()
{
	// Hide or show appropriate courses based on Course Type selector
	if (document.getElementById("uiLongCourseRadio").checked)
	{
		if (document.all)
		{
			// IE does not like "table-row"
			document.getElementById("longCourseRow1").style.display = "block";
			document.getElementById("longCourseRow2").style.display = "block";
		}
		else
		{
			document.getElementById("longCourseRow1").style.display = "table-row";
			document.getElementById("longCourseRow2").style.display = "table-row";
		}

		document.getElementById("shortCourseRow1").style.display = "none";
		document.getElementById("shortCourseRow2").style.display = "none";
	}
	else
	{
		document.getElementById("longCourseRow1").style.display = "none";
		document.getElementById("longCourseRow2").style.display = "none";
		
		if (document.all)
		{
			document.getElementById("shortCourseRow1").style.display = "block";
			document.getElementById("shortCourseRow2").style.display = "block";
		}
		else
		{
			document.getElementById("shortCourseRow1").style.display = "table-row";
			document.getElementById("shortCourseRow2").style.display = "table-row";
		}
	}
}

// Wires up validation and initial focus
function window_onload()
{
	// Only wire up validation if the registration form is visible
	if (document.forms[0].uiFirstName)
	{
		// Initialisation
//		document.forms[0].uiFirstName.focus();
		
		// Add form validation handler
		document.forms[0].onsubmit = ValidateFields;
		
		// Hide or show appropriate courses based on Course Type selector
		//ToggleCourseVisibility();
		
		// Wire up Course Type selector to toggle visibility
		//document.getElementById("uiLongCourseRadio").onclick = ToggleCourseVisibility;
		//document.getElementById("uiShortCourseRadio").onclick = ToggleCourseVisibility;
	}
}

// Writes up initialisation handler code
window.onload = window_onload;
