Mushy-pea 36 What, you can change this tag?

Hello everyone. I've got the stuff working I talked about here ( http://www.daniweb.com/techtalkforums/thread68292.html ). Now, I am working on this problem; I need to check if a cookie is present on the client machine. It's presense will indicate the user is logged in. If it is there I need to read a username and hashed password from it and set two form fields with these values. If it isn't I need to do what I mentioned in that other post (read a password, hash it and replace it in the form).

So, a user will be able to verify themself manually or by cookie, depending on whether a valid cookie is present. I have this code:

function read_cookie() {
var user_data = document.cookie;
if (user_data) {
var big_crumbs = user_data.split("=");
var small_crumbs = big_crumbs[1].split("~");
document.getElementById("username").value = small_crumbs[0];
document.getElementById("password").value = small_crumbs[1];
}
else {
pwd_hash(0);
}
return true;

}

function pwd_hash(action) {
var password = document.getElementById("password").value;
var pwd_hash = hex_md5(password);
document.getElementById("password").value = pwd_hash;
if (action == 1) {
document.getElementById("confirm-password").value = pwd_hash;
}
return true;
}

The cookie looks like this:

user_data
steven02~15b21c00a3627133fbed027637b0f902
www.mushy-pea.org.uk/
1600
773815424
29836681
373550016
29836679
*

Notice that I've separated the username and password hash with a tilda(~). But when I submit the form only the password hash is sent and not the username. I've fiddled about with it for a fair while and I can't work out what going wrong. Could anyone suggest some possibilities here? Thanks in advance.

Steven.