The key word is cases (basically, words change forms depending on their role in the sentence).
Whenever the third person feminine singular pronoun is the subject or the direct object (the thing being acted on) of the sentence, it has the form "ea":
Ea părăsește orașul. - She is leaving town.
Am anunțat-o pe ea prima. - I notified her first.
Otherwise, when used to indicated possession or someone at the receiving end of an action, it has the form "ei":
Acela e creionul ei. - That is her pencil.
Acel creion e al ei. - That pencil is hers. I-am dat ei pixul. - I gave her the pen.
It's an unfortunate coincidence that the third person masculine plural pronoun shares this last form when it's either the subject or the direct object:
Ei părăsesc orașul. - They are leaving town.
I-am anunțat pe ei primii. - I notified them first.