var thisForm

function trimAll(sString){
	while (sString.substring(0,1) == ' ')	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function validateRegister(frmName) {

	thisForm = frmName;

	var errors = '';
	var errorMsg = '';


	if (isEmpty('FirstName')) {
		errors += 'Please enter your first name\n';
	}

	if (isEmpty('Surname')) {
		errors += 'Please enter your surname\n';
	}

	if (isEmpty('Email')) {
		errors += 'Please enter your email address\n';
	}	else	{
		email = document.registerForm.Email.value.length
		if (email > 1)	{
			if (!trimAll(isEmail('Email'))) {	
				errors += 'Your email address is not valid\n';
			}
		}

	}

	if (isEmpty('DOBDay') || isEmpty('DOBMonth') || isEmpty('DOBYear')) {
		errors += 'Please enter your date of birth\n';
	}

	if (isEmpty('Postcode')) {
		errors += 'Please enter your postcode\n';
	}

	if (errors) {
		alert('There is an error in your form. Please check the following fields\n\n' + errors);
	}

	return (errors == '');
}




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);
}