moved javascript functionality out of this file