var allcookies = document.cookie;

//// ---------- Clearing the SWMBR cookie when logged off: -----

var poz = allcookies.indexOf("SESSION_ID=");
var cookyval = allcookies;
// If we find a cookie named SESSION_ID, extract and use its value, which is like:  -1,Ae6Htj4vHmggO0JN.....

if (poz != -1) {
    var st = poz + 11;							// Start of cookie value
    var j = allcookies.indexOf(",",st);			// position of the intermediate comma
    cookyval = allcookies.substring(st, j);		// Extract the value
    //cookyval = unescape(cookyval);       		// Decode it
    if(cookyval == "-1")						// In this case clear the old SWMBR cookie. 
    	document.cookie = "SWMBR=;path=/";
}
//// ---------------------------------------------------------------

allcookies = document.cookie;					// Read again the cookies. 
var swbalance = "";
var swfirstname = "";
var swlastname = "";

// Look for the start of the cookie named "SWMBR"
var pos = allcookies.indexOf("SWMBR=");
var cookyvalue = allcookies;

// If we find a cookie by that name, extract and use its value
if (pos != -1) {
    var start = pos + 6;      						// Start of cookie value
    var end = allcookies.indexOf(";", start);		// End of cookie value
    if (end == -1) end = allcookies.length;
    cookyvalue = allcookies.substring(start, end);  // Extract the value
    //cookyvalue = unescape(cookyvalue);            // Decode it

    valArray = cookyvalue.split(",",3)				// Split it in maximum 3 individual values
    
   	if(valArray[0] != undefined)
   		swbalance = valArray[0];
   	if(valArray[1] != undefined)
		swfirstname = valArray[1];
	if(valArray[2] != undefined)
		swlastname = valArray[2];
}
//alert("2nd time cookie value: "+cookyvalue); 