Javascript common functionallity