As far as I know, application of templates are completely under the control of the DM. Some DM allow PCs to gain a template in the middle of an adventure even if the template was originally meant to represent being born special.
There could be anyway some template around which are clearly inherited later, such as lycanthrope or lich, but are applicable to an "Animal"*.
In any case I think that if the template changes the creature's type to anything other than animal, it won't remain your animal companion.
Of course, your DM may simply house-ruled that he doesn't care...
*the SRD says it is treated as a Magical Beast for purpose of effects depending on the type, but I think I heard already that WotC will change it back to Animal to allow spells like Animal Growth.