function humanizeNumber(id,number) {
//Get the cursor position
var start = document.getElementById(id).selectionStart;
var end = document.getElementById(id).selectionEnd;
//Replace the space in number, and add again to the right position
numberString = number.replace(/\s/g, '');
value = (String(numberString).replace(/(.)(?=(\d{3})+$)/g,'$1 '));
//If the space were added, it move the cursor position +1
if(document.getElementById(id).value.length!=value.length)
{
start += 1;
end +=1;
}
//If the key pressed aren't arrowRight and arrowLeft, write the new value
var event = window.event ? window.event : e;
if(event.keyCode!=37 && event.keyCode!=39)
{
document.getElementById(id).value = value;
document.getElementById(id).setSelectionRange(start, end);
}
}