OMG ... It's all about a pair of parentheses () !!
Even I was surprised at first sight, how can that code give some errors ?!
Finally found it, though. Here is the rectified code :
alert("Required fields can't be left empty");
alert("Username and password are same");
You missed a pair of parentheses behind the trim function.