When declaring war, war is also declared on all allies of the regime in question.
You cannot ally to a regime that is at war with one of your allies. Neither can you ally with a regime while you are at war with one of its allies.
In that case only he will be at war with the 3rd party. You will not be dragged into conflict when your ally is the one declaring war.
In that case you will automaticly also be at war with that 3rd party. Alliances are defensive in nature.
The AI will measure its strength (any possible allies it has included) to the enemy's regime (and its allies) to judge if it should attack or not.
This situation should normally not occur, but it can be constructed in the editor. Rulevar 342 allows a regime to fight against ally if caught in a land battle between two of its allies. Standard in AT Gold rules the ally of both will stay out of combat. When caught in between ally and a neutral it always fights with its ally however.
An ally in the same hex (or in intercept range) now only supports the defenders if it is at war with the attacker. Otherwise it stays neutral.