What is the primary purpose of the margin system in stock markets?

When is the Value at Risk (VAR) margin typically calculated and collected?

What does the Extreme Loss Margin (ELM) aim to cover?

How is the Mark to Market (MTM) margin determined?