/*
 Basic operations on cookies from within JavaScript
 Aleksander Maksymiuk, http://setpro.net.pl/
*/

function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
    var sCookie = sName + '=' + encodeURIComponent(sValue);
    if (oExpires) {
        sCookie += '; expires=' + oExpires.toGMTString();
    }
    if (sPath) {
        sCookie += '; path=' + sPath;
    }
    if (sDomain) {
        sCookie += '; domain=' + sDomain;
    }
    if (bSecure) {
        sCookie += '; secure';
    }
    document.cookie = sCookie;
}

function getCookie(sName) {
    var name_eq = sName + '=';
    var c_arr = document.cookie.split(';');
    for (var i = 0; i < c_arr.length; i++) {
        var c = c_arr[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(name_eq) == 0) {
            return decodeURIComponent(c.substring(name_eq.length, c.length));
        }
    }
    return null;
}

/*
function getCookie(sName) {
    var sRE = '(?:; ?)?' + sName + '=([^;]*);?';
    var oRE = new RegExp(sRE);
    if (oRE.test(document.cookie)) {
        return decodeURIComponent(RegExp["$1"]);
    } else {
        return null;
    }
}
*/

function removeCookie(sName, sPath, sDomain) {
    setCookie(sName, '', new Date(0), sPath, sDomain);
}
