/**
 * 
 * Function to capitalise the first letters of the words in a sentence.
 * This version is designed to work with onKeyUp
 */

function capitaliseFirstLetters(text) {
	textVal = text.value.toLowerCase();
	
	var regex = /[a-z]'/i;
	     
	newVal = '';
	for(var i=0; i < textVal.length; i++) {
			
		if (textVal.substring(i-1,i) == " ") {
	
			newVal += textVal.substring(i,i+1).toUpperCase();
			
		} else if (regex.test(textVal.substring(i-2,i))) {
			
			newVal += textVal.substring(i,i+1).toUpperCase();
			
		} else {
			newVal += textVal.substring(i,i+1);
		}
	}
	
	newVal = newVal.substring(0,1).toUpperCase() + newVal.substring(1,newVal.length);
	text.value = newVal;
  
}

function capitaliseAllLetters(text) {
	textVal = text.value.toUpperCase();
	text.value = textVal;
}
