What's the purpose of the 1M resistor in this comparator circuit?
That would appear to be part of the hysteresis feedback path. It's part of the voltage divider with the other half being the 510k ohm resistor coming from the output. In that way, it takes a touch more input voltage change to switch between high and low output. Just by adding a few mV of difference to the input side reference, you can drown out noise-caused switching.

For more info:
http://en.wikipedia.org/wiki/Hysteresis
What is a Schmitt Trigger and its application exactly? 
http://www.ecircuitcenter.com/Circuits/op_comp/op_comp.htm