You need to change this line
onreadystatechange must always be a function, not a function call as you wrote. If stateChanged(frm) was a function that returned a result, your line above would assign the result to onreadystatechange, which is not what you want to do (unless of course your function returned a function, but we won't go there just now!).
Hope that helps.