var thisForm



function validateNYCOSApplication(frmName) {

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('userName')) {
		errors += 'Please enter your name\n';
	}

	if (isEmpty('userAddress')) {
		errors += 'Please enter your address\n';
	}

	if (isEmpty('userPostcode')) {
		errors += 'Please enter your postcode\n';
	}

	if (isEmpty('userTelephone')) {
		errors += 'Please enter your telephone number\n';
	}

	if (isEmpty('dateOfBirth')) {
		errors += 'Please enter your date of birth\n';
	}	else	{
		if (!isDate('dateOfBirth')) {
			errors += 'Please enter a valid date in the date of birth field\n';
		}
	}

	if (isEmpty('ageAtCourseYears')) {
		errors += 'Please enter your age in years at the start of the course\n';
	}
	if (isEmpty('ageAtCourseMonths')) {
		errors += 'Please enter your age in months at the start of the course\n';
	}

	if (isEmpty('localCouncil')) {
		errors += 'Please enter your local council\n';
	}

	// Need to only validate these fields if term time address is filled
	/*  if (!isEmpty('termTimeAddress')) {
		if (isEmpty('termPostcode')) {
			errors += 'Please enter your term time postcode\n';
		}

		if (isEmpty('termTelephone')) {
			errors += 'Please enter your term time telephone number\n';
		}

		if (isEmpty('termTelephone')) {
			errors += 'Please enter your term time email address\n';
		}
	}
*/
	if (isEmpty('auditionLocation')) {
		errors += 'Please enter your preferred audition location\n';
	}


	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}


	document.returnValue = (errors == '');
	return document.returnValue;
}


function validateNYCOSFriends(frmName) {

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('userName')) {
		errors += 'Please enter your name\n';
	}

	if (isEmpty('userAddress')) {
		errors += 'Please enter your address\n';
	}

	if (isEmpty('userPostcode')) {
		errors += 'Please enter your postcode\n';
	}

	if (isEmpty('userTelephone')) {
		errors += 'Please enter your telephone number\n';
	}
/*
	if (!isEmpty('userEmail')) {
		if (!isEmail('userEmail')) {	
			errors += 'Your email address is not valid\n';
		}
	}
*/

	if (isEmpty('userDonation')) {
		errors += 'Please enter your donation amount\n';
	}	else	{
		if (!isNumber('userDonation')) {
			errors += 'Please enter only numbers in the donation amount field\n';
		}	else	{
			var currentRadio = parseInt(getRadioValue('friendType'))
			if (currentRadio == 0)			{
				errors += 'Please select a friend package\n';
			}	else	{
				var currentDonation = parseInt(getFormValue('userDonation'))
				if (currentDonation < currentRadio)		{
					errors += 'This friend package requires a donation of at least £' +currentRadio+ '\n';
				}
			}
		}
	}

	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}

	document.returnValue = (errors == '');
	return document.returnValue;
}




function validateNYCOSTrainingEnquiry(frmName) {

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('userName')) {
		errors += 'Please enter your name\n';
	}

	if (isEmpty('Email')) {
		errors += 'Please enter your email address\n';
	}	else	{
		if (!isEmail('Email')) {	
			errors += 'Your email address is not valid\n';
		}
	}

	//if (isEmpty('Telephone')) {
	//	errors += 'Please enter your telephone number\n';
	//}

	if (isEmpty('Enquiry')) {
		errors += 'Please enter your enquiry\n';
	}



	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}


	document.returnValue = (errors == '');
	return document.returnValue;
}




function validateNYCOSTrainingBooking(frmName)	{

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('userName')) {
		errors += 'Please enter your name\n';
	}

	//if (isEmpty('JobTitle')) {
	//	errors += 'Please enter your job title\n';
	//}

	if (isEmpty('Address')) {
		errors += 'Please enter your address\n';
	}

	if (isEmpty('Telephone')) {
		errors += 'Please enter your telephone number\n';
	}

	if (isEmpty('Workshop')) {
		errors += 'Please enter your workshop\n';
	}

	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}


	document.returnValue = (errors == '');
	return document.returnValue;
}





function validateNYCOSMiniMusic(frmName)	{

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('mmClass')) {
		errors += 'Please enter your class location\n';
	}

	if (isEmpty('mmTime')) {
		errors += 'Please enter your class time\n';
	}

	if (isEmpty('mmParent')) {
		errors += 'Please enter your parents name\n';
	}

	if (isEmpty('mmAddress')) {
		errors += 'Please enter your address\n';
	}

	if (isEmpty('mmPostcode')) {
		errors += 'Please enter your workshop\n';
	}

	if (!isEmpty('mmEmail')) {
		if (!isEmail('mmEmail')) {	
			errors += 'Your email address is not valid\n';
		}
	}

	if (isEmpty('Telephone')) {
		errors += 'Please enter your telephone number\n';
	}

	if (isEmpty('mmc1Name')) {
		errors += 'Please enter the name of child one\n';
	}

	if (isEmpty('mmc1DOB')) {
		errors += 'Please enter child one\'s date of birth (dd/mm/yyyy)\n';
	}	else	{
		if (!isDate('mmc1DOB')) {
			errors += 'The date you have entered for child one\'s DOB is invalid. Please format as (dd/mm/yyyy)\n';
		}
	}

	// Only want to check these fields if there are 2 children
	noOfKids = parseInt(eval('document.' + thisForm + '.mmHowMany.value'));
	if (noOfKids == 2)	{
		if (isEmpty('mmc2Name')) {
			errors += 'Please enter the name of child two\n';
		}

		if (isEmpty('mmc2DOB')) {
			errors += 'Please enter child two\'s date of birth (dd/mm/yyyy)\n';
		}	else	{
			if (!isDate('mmc2DOB')) {
				errors += 'The date you have entered for child two\'s DOB is invalid. Please format as (dd/mm/yyyy)\n';
			}
		}
	}

	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}


	document.returnValue = (errors == '');
	return document.returnValue;
}





function validateWhatsOnSearch(frmName) {

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';

	//alert("checking")

	if (!isEmpty('fromDate')) {
		if (!isDate('fromDate'))		{
			errors += 'From date is not valid\n';
		}
	}

	if (!isEmpty('toDate')) {
		if (!isDate('toDate'))		{
			errors += 'To date is not valid\n';
		}
	}


	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}


	document.returnValue = (errors == '');
	return document.returnValue;
}


function unChanged(strVal) {
	elmVal = eval('document.' + thisForm + '.' + strVal +'.value');
	if (strVal == 'name' && elmVal == 'Name') {
		return false;
	} else if (strVal == 'email' && elmVal == 'Email') {
		return false;
	}
	return true;
}

function isEmpty(strVal) {
	elmVal = eval('document.' + thisForm + '.' + strVal +'.value');
	elmLen = elmVal.length;
	if (elmLen == null || elmLen == 0) {
		return true;
	}
	return false;
}

function checkTick(strVal) {
	elmVal = eval('document.' + thisForm + '.' + strVal +'.checked');
	if (!elmVal) {
		return false;
	}
	return true;
}

function isEmail(strVal) {
	elmVal = eval('document.' + thisForm + '.' + strVal +'.value');
	testRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(elmVal);
	if (!testRe) {
		return false;
	}
	return true;
}

function checkOther(strVal, otherVal) {
	elmVal = eval('document.' + thisForm + '.' + strVal +'[3].checked');
	elmOtherVal = eval('document.' + thisForm + '.' + otherVal +'.value');
	elmOtherLen = elmOtherVal.length;
	if (elmVal && (elmOtherLen == 0)) {
		return false;
	} else if (elmOtherLen > 0) {
		document.questForm.Develop[3].checked = true;
	}
	return true;
}

function isNumber(nVal)	{
	nVal =	eval('document.' + thisForm + '.' + nVal + '.value');
	if (parseInt(nVal) == nVal)	{
		return true;
	}	else	{
		return false;
	}
}

// UK dates
function isDate(strVal) {

	sDate =	eval('document.' + thisForm + '.' + strVal + '.value');
	var match = sDate.match(/^(\d\d?)\/(\d\d?)\/(\d{4})$/);
	if (match == null || match == 'undefined') {
		return false;
		//alert('return false : ' + match)
	}
	var da = Number(match[1]); // day
	var mt = Number(match[2]); // month
	var yr = Number(match[3]); // year
	var d = new Date(yr,mt-1,da);
	//alert(d);
	return (d.getDate() == da && d.getMonth()+1 == mt && d.getFullYear() ==yr);
}

function getRadioValue(strVal) {
	for (index=0; index < eval('document.' + thisForm + '.' + strVal + '.length'); index++) {
		if (eval('document.' + thisForm + '.' + strVal +  '[index].checked')) {
			return radioValue = eval('document.' + thisForm + '.' + strVal +  '[index].value');
		}
	}
	return 0;
}

function getFormValue(strVal)	{
	return eval('document.' + thisForm + '.' + strVal + '.value');
}