changed to jQuery and added error-checking
pre-jQuery
rewrote to use jQuery