Plenty of idiots leaving dogs in cars, What is the legal side IF I saw a dog in distress and broke the window to rescue it? Personally I don't think the owner would have a leg to stand on what with local / national press getting wind of it and possibly RSPCA prosecuting.
A possibility that, unless you are a vet or other trained animal professional and able to claim 'expert opinion', the owner would claim the dog was fine & you could be facing a charge of Criminal Damage.
If the dog is unresponsive/ collapsed, get witnesses together and get someone to call police whilst breaking window, if the dog is still alive at this points, it may only have minutes between survival and death if still barking but distressed call police first.
As above, if the dog is clearly in trouble and you break the window then you're acting as an agent of necessity so have a good defence against any criminal law matters.