Hi guys,

I have some problems with cookies and need your help about this.

This is my code:

Code:
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

var man = readCookie("sex");
if (man == null) 
{
    man = true;
    createCookie("sex", man, 365);
    man = readCookie("sex");
    alert("man : " + man);
}
else
{
    alert("my sex is man. " + man);
    man = !man;
    createCookie("sex", man, 365);
}
When I run this script, the result will show below:

- first refresh
man : true

- second refresh
my sex is man. true

- next
my sex is man. false

- next
my sex is man. false

It seems that "man = !man;" only run one.
But I tried with this test and no problem happened.

Code:
var bValue = true;
alert(bValue);

bValue = !bValue;
alert(bValue);

bValue = !bValue;
alert(bValue);
Can anyone help me?

Many thanks