// For Trimming:
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");}

// Add Event handler:
function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener) { 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent) { 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

// The function to attach:
function trimAndCap(){this.value=capitalizeNames(this.value).trim();}

// The init function will load after the page is done loading.
function init()
{
	// Trim and Capitalize all name fields.
	document.getElementById("fname").onblur=trimAndCap;
	document.getElementById("lname").onblur=trimAndCap;
	document.getElementById("addr").onblur=trimAndCap;
	document.getElementById("city").onblur=trimAndCap;
}

// Add the function.
addEvent(window,'load',init);
