Clean attempts to set authkey by javascript from json data responses
Update changeflavour.php

Sometimes the referrer has already resolved url encoding to symbols. Fall back to a re-encoded segment if a path segment is not found. If neither is found, fall back to the root node of the target flavour.
Fixed direct mysql_ api call to use  wrapper