Both words can be translated to "when" in English, but in Dutch they serve different functions. "Toen" is used to refer to past events, "wanneer" for questions.
Could the same sentence be written as "Toen ik daar was, regende het"? Or is it "Toen ik daar was, het regende"? I can't remember how the sub-clause affects the sentence in this case...