various javascript function and utilities #internal use only