//*****************************************************************
//The following lines of code here are for setting and recieving 
//cookies.  They are used extensivly throughout this site for 
//the retrieval of variables such as resolution, colours etc.
//Please do not steal this one as it took me ages to perfect this. 
//Thanks to APC's Javascript tutorial for help with cookies.
//APC Magazines Javasctips tutorial (www.apcmag.com.au/javascript)
//Thankx .. Matthew Blume (a.k.a Zerlock) mblume@bigfoot.com
//****************************************************************

//********************************
//Expirartion settings for cookies
//********************************

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//These settings can be changed to
//change the time when the cookie
//will expire, currently set to 1
//year after creation. 
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

var now = new Date();
fixDate(now);				
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

//*******************
//SET COOKIE FUNCTION
//*******************

// Boolean variable if cookie is bigger than 4k
var caution = false

function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie exceeds 4KB and will be cut!"))
                        document.cookie = curCookie
}

//*******************
//GET COOKIE FUNCTION
//*******************

function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

//**********************
//DELETE COOKIE FUNCTION
//**********************

function deleteCookie(name, path, domain) {
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
        }
}

//*****************
//FIX DATE FUNCTION
//*****************

function fixDate(date) {
        var base = new Date(0)
        var skew = base.getTime()
        if (skew > 0)
                date.setTime(date.getTime() - skew)
}

//******************
//END OF COOKIE CODE
//******************