// default cookie expiry
 defaultDate = 'Tue, 6 Dec 2005 23:59:59 UTC';

// check box with id same as cookie 
function checkBox(){
	// get enrty val
	var entryValue, selectedBox
	entryValue = getCookie('entry'); 
	//alert('cookie is: '+entryValue+'');
	// get cb if in doc
	selectedBox = document.getElementById(''+entryValue+'');
	//{{{ 
	/*
	if(selectedBox){
		alert('the selection is on the page');
	}
	*/ //}}}
	
	if(entryValue && selectedBox){
		selectedBox.checked = 'true';
		//alert('Box '+entryValue+' has been checked');
	}
}
 

 // set the cookie
 function setMyCookie(myString){
	 document.cookie = myString;
	 
	 alert(''+document.cookie+'');
 }
 
 function getMyCookie(cookieName){
	 alert(getCookie(cookieName));
 }
 
 
 function checkSelection(selectedButton){
	// set cookie using value as entry number if box has been checked
	if(selectedButton.checked == true){
		document.cookie = 'entry='+selectedButton.value+'; expires='+defaultDate+'; path=/';
	
	}
	// set zero value cookie, as user has unchecked selection
	else{
		document.cookie = 'entry=0; expires='+defaultDate+'; path=/';
	}
	// deselect any other checked boxes
	
	// get all input elements
	cbs = document.getElementsByTagName('input');
	// loop through and check type
	for(i=0; i<= cbs.length; i++){
		// check if it's a checkbox and is checked and the id isn't the same as
		//this.id
		if(cbs[i] && cbs[i].type== 'checkbox' && cbs[i].checked == true && cbs[i].id != selectedButton.id){
			cbs[i].checked = false;
			//alert(''+i+' deselected');
		}
	}
	
	// confirm selection (debug only)
	//getMyCookie('entry');
 }
 
 
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */

 
 
function setCookie(name, value, expires, path, domain, secure)
{
	
	myCookieString = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
	document.cookie = myCookieString;	
	alert(''+myCookieString+'');
}


/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
 
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return false;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
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";
    }
}