Why do dogs have a third eyelid?

In addition to the upper and lower eyelids, your dog has a third eyelid located in the inner corner of the eye near the snout.