I am not a js or ajax expert but you wanted to know what this was, its ajax. Basically what ajax does is allows you to set up another page process many times its a php page with output to the user, in your case its a file called ajax.php and this process grabs that output and uses it on this page.
For example you have a php file called sample.php and all it does is display the text hello back to the user. Well what you can do is you can in simple terms listen for that output by telling ajax in this file that you want to grab the output from that sample.php file when it is done executing.
The stateChanged is what ajax watches for, when that is status 4 or completed (i think status 2 works as well) then the http object basically is the word "hello" and ajax sees by the status that the file is done executing and so it grabs the value of that "hello" text using the function saveName.
As far as all the other stuff the document.getElementById its grabbing the value from that id value and basically your building a final value with this process. Grabbing some data here some there.
So i hope that basically explains whats going on, im not an expert so i cant tell you why exactly its not working and i dont know what you mean by not working, are you getting an error or is there no output or what. But if you explain what you need that is not happening or maybe even give a screen shot somone can prob help you. But also they can prob just look at the code and see if they see any errors.
Hope that helps.
How did i do DanInMa?