It is called learning how to program and thinking how things work.
You set up conditions. If player is in X1 area, I do this. If player is in X2 area I do this.
If I were you, I would worry less about enemies at this time and get a character moving through some screen.
Here is an example for you to start out with: http://ajaxpatterns.org/wiki/index.p...rite#Solutions