I don't know what type of pain medications your talking about, but opiate based ones can vary depending on the type.
As for GHB, intraveniously it is unable to detect after 4-5 hours. Orally, it is possible, but unlikely that it or its analogues can be found up to 24 hours. In 99% of cases though, its gone in less than 8. Being that it metabolizes into water and CO2, it leaves no metabolites to be found. Unlike THC, and some other drugs, GHB is not fat soluble and is out of the system quickly.
-FC