/*******************************************************************************************************************

	Form validation helper script

*******************************************************************************************************************/

function formValidationInteger(str) {
	var regex = /^([0-9]+)$/
	if(str.match(regex) == null) {
		return false;
	} 	
	return true;	
}

function formValidationForename(str) {
	var regex = /^([a-zA-Z\s'-]+){1}$/
	if(str.match(regex) == null) {
		return false;
	} 	
	return true;	
}

function formValidationSurname(str) {
	var regex = /^([a-zA-Z\s'-]+){2}$/
	if(str.match(regex) == null) {
		return false;
	}
	return true;	
}

function formValidationTelephone(str) {
	// Remove all spaces
	str = str.replace(/ /gi, "");

	if(str == '') {
		return false;
	}
	
	if(str.substring(0,1) != '0') {
		return false;
	}

	var regex = /^([0-9]){10,13}$/
	if(str.match(regex) == null) {
		return false;
	}
	
	return true;
}

function formValidationEmail(str) {
	var regex = /^([a-zA-Z0-9]+([\.+_-][a-zA-Z0-9]+)*)@(([a-zA-Z0-9]+((\.|[-]{1,2})[a-zA-Z0-9]+)*)\.[a-zA-Z]{2,6})$/
	if (str.match(regex) == null) {
		return false;
	}
	return true;
}

function formValidationPostcode(str) {
	if ((str.length < 2) || (str.length > 14)) {
		return false;
	}
	return true;
	
	// tests to see if string is in correct UK style postcode: AL1 1AB, BM1 5YZ etc.
	//var regex = /[A-Z]{1,2}[0-9R][0-9A-Z]? ?[0-9][A-Z]{2}/i;
	//if (str.match(regex) == null) {
	//	return false;
	//}
	//return true;
}

function formValidationComments(str){
	if(str == null || str.length == 0) {
		return false;
	}
	return true;
}


