/* utils.js

 <script type="text/javascript" src="../scripts/utils.js"> </script>

*/

/*
** Function: upperCamelCase
**	IN: 	
**			elementID		id				The ID of the element you want to change
**			onlyspaces		true/false		Only upper case the wirst letter after a space? (default is false)
**	OUT:
**			Changes the value of the element with matching ID.
**	USAGE EXAMPLE:
			<cfinput 
				type="text" 
				class="bodytext3" 
				name="Familyname" 
				required="Yes" 
				message="Please enter patient Family name." 
				id="Familyname"
				onchange="javascript:upperCamelCase('Familyname');" 
				maxlength="250"
			> 
**
**	Last Modified:	20080812_1616	Gus
*/
function upperCamelCase(elementId, onlyspaces){
	var onlyspaces = (onlyspaces == null) ? false : onlyspaces;   // Use all punctation as a demarcation point by default
	
	var currValue = document.getElementById(elementId).value;

	var parts = currValue.split(/\W+/);		// Split into words (splits at punctation)
	var retVal = "";

	var currPos = 0;
	var nextDemarcation = "";
	var changePart;
	
	for ( var i = 0; i < parts.length; i++ ) {
		changePart = true;				// By default upperCamelCase this 'part'
		
		if ( (onlyspaces) && !( (nextDemarcation == " ") || (nextDemarcation == ""))) changePart = false;
		
		currPos += parts[i].length + 1;
		nextDemarcation = currValue.substr(currPos-1,1);
		
		if (changePart){
			retVal += parts[i].substr(0,1).toUpperCase() + parts[i].substr(1).toLowerCase() + nextDemarcation;
		} else {
			retVal += parts[i] + nextDemarcation;
		}
	}	
	document.getElementById(elementId).value = retVal;
}



