Clean up the parseInt and add some NaN safety as well

Pull out the repeated 'parseInt(doc.getElById(id).value)' things in favor of a helper function. The helper function also adds some safety: it checks for NaN, which happens if the number input field was set to the empty string (which browsers allow) and returns 0 in that case because it seems much saner to get back 0 than NaN.