Mini javascript common functionallity