/*Use cookName as the name of the cookie, create a string for cookStr (consisting of name=value pairs)
  If you know what you're doing, add a full GMT expires time, a path and a domain. If there's no expires, we have
  a session cookie.
*/
// Start any debug lines with /*DBG*/ to allow ease of search-and-replace on live files.
    /*DBG*/ //if (jsDebug>=1) alert("Included Cookie file (jsCook0_1.js)");

function setCookie(cookName, cookStr, expires, path, domain)
{
    var expr = ((typeof(expires)=='undefined') ||(expires==''))? "":("; expires="+expires);
    var pth  = ((typeof(path)   =='undefined') ||(path==''))   ? "; path=/":("; path="+path);
    var dmn  = ((typeof(domain) =='undefined') || (domain==''))? "; domain=bbc.co.uk":("; domain="+domain);
    /*DBG*/ //if (jsDebug>=2) alert("Setting cookie '"+cookName+"' with:\n"+cookStr+"\n"+expr+"\n"+pth+"dmn");
    document.cookie = cookName+"="+ escape(cookStr) + expr + pth + dmn;	
}

//Gets a cookie named 'name' from the browser, then creates an associative array called cookieData (see comments below)
function getCookies()
{

  //IE can detect if cookies are disabled. Use with browser detect maybe!?
    if (navigator.appName == "Microsoft Internet Explorer" & parseInt(navigator.appVersion) > 3)
    {
        if (!navigator.cookieEnabled) alert("Cookies are disabled on this browser.\n" +
                                            "Please enable them if you require this functionality.");
    }
   	
    cookieData = new Array();
    var allCookies = document.cookie.split("; ");
    for (var i=0; i<allCookies.length; i++)
    {
        var tmpCookname = unescape(allCookies[i].split("=")[0]);
        /*DBG*/ //if (jsDebug>=4) alert("Found cookie: '"+tmpCookname+"'.");
        if (tmpCookname.charAt(0)==" ") tmpCookname = tmpCookname.substring(1,tmpCookname.length);
        var tmpArray = unescape(allCookies[i].split("=")[1]).split("&");
        cookieData[tmpCookname] = new Array();
        for (var c=0; c<tmpArray.length; c++)
        {
            //loop through, store as cookieData["name"] = "value"
            cookieData[tmpCookname][unescape(tmpArray[c].split("=")[0])] = unescape(tmpArray[c].split("=")[1]);
        }
    }

}

function jsCookTest()
{
    alert(document.cookie);
}

/*if (document.cookies) {getCookies(); var ckEnabled = true;}
else var ckEnabled = true;*/
getCookies();
