This can be done using the getActive() method from the JMenu class with the Application subpackage. Read More here
Anywhere in your Joomla! code use the following codeline to get the parent IDfor the active id.
$parentID = JSite::getMenu()->getActive()->tree[0];