If you have a moving unit, especially a fast one such as spear cavalry, it's difficult to double click on it to select all units of that type, because both clicks have to be on the same unit, but if the unit has moved, you will often click empty ground the second time.
For instance, this happens often when cavalry raiding; each time you make new cavalry you want to select all cavalry and bind them to a hotkey, but if all cavalry are moving it's tricky to alt-double click on one.
This patch modifies input.js so that a double or triple click operates on the first unit to be clicked as part of the double or triple click. This makes the above use case much easier. Now that the requirement that all clicks be on the same unit has been removed, we need a different criterion for distinguishing a double click from rapid successive single clicks, and this patch chooses that the squared pixel distance between successive clicks must be no more than 5.
See also: trac ticket 4414 which may move all this double click code to C++. However, since this is a simple patch that solves a UI issue, I think it can serve as a temporary fix for the time being, until 4414 is addressed.