function DenyKeysAndFormat(strBoxName, strFormat)
{
	//If it's a special key then just do it
	//"Tab"=9, "backspace"=8, "Delete"=46, "Enter"=13
	if (event.keyCode == 9 || event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 13) {return true;}
	
	//For some reason fromCharCode doesn't handle the number pad values, so we have to do this special stuff to get the right number back
	var strCharToAdd;
	//if (event.keyCode >= 96 && event.keyCode <= 105)
	//	{strCharToAdd = String.fromCharCode(event.keyCode - 48);}
	//else
	//	{strCharToAdd = String.fromCharCode(event.keyCode);}
	strCharToAdd = String.fromCharCode(event.keyCode);
	
	//Get the value of the box plus whatever key was hit
	var strBoxValue = document.getElementById(strBoxName).value; 
	
	//Add the char to the correct spot
	strBoxValue = strBoxValue.substring(0,GetSelectionStart(document.getElementById(strBoxName))) + strCharToAdd + strBoxValue.substring(GetSelectionEnd(document.getElementById(strBoxName)), strBoxName.length - GetSelectionEnd(document.getElementById(strBoxName)));

	//Clear the selection
	document.selection.clear();
	
	//Remove all non numbers
	var strPreFormat = "";
	for (var i = 0; i < strBoxValue.length; i++)
		{if (strBoxValue.substring(i,i+1) >= '0' && strBoxValue.substring(i,i+1) <= '9') {strPreFormat += strBoxValue.substring(i,i+1) + '';}}

	var strOut = ""; var intSource = 0;
	for (var i = 0; i < strFormat.length; i++)
	{
		if (strFormat.substring(i,i+1) == 'N' && intSource < strPreFormat.length) {strOut += strPreFormat.substring(intSource,intSource+1) + ''; intSource ++;}
		if (strFormat.substring(i,i+1) != 'N' && intSource < strPreFormat.length) {strOut += strFormat.substring(i,i+1) + '';}
	}

	//Put the output into the box
	document.getElementById(strBoxName).value = strOut;
	
	//Return false so we don't get the char in there twice
	return false;
}

function GetSelectionStart(cntBox) {
	if (cntBox.createTextRange) {
		var objRange = document.selection.createRange().duplicate();
		objRange.moveEnd('character', cntBox.value.length);
		if (objRange.text == '') return cntBox.value.length;
		return cntBox.value.lastIndexOf(objRange.text);
	} 
	else return cntBox.selectionStart
}

function GetSelectionEnd(cntBox) {
	if (cntBox.createTextRange) {
		var objRange = document.selection.createRange().duplicate();
		objRange.moveStart('character', -cntBox.value.length);	
		return objRange.text.length;
	}
} 

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
