// JavaScript to set and get cookie information

//set the 'bouncingImage' div block depending on whether cookies are enabled or not
function setBounceImage()
{
	//first check if there is already a cookie to get (from a previous visit)
	visitCount = getcookie("BirdsAndGarden");
	//alert("Cookie="+visitCount);
	if (visitCount == "")
	{
		//cookie not found - try and set one up now
		checkCookie = setcookie("BirdsAndGarden",0,1);
		if (checkCookie == false)
		{
			//cookie cannot be set - browser not accepting
			document.all.bouncingImage.innerHTML = "<img src='BounceNoCookies.gif'>";
		} else {
			document.all.bouncingImage.innerHTML = "<img src='Bounce.gif'>";
		}
		
		//start off the bounce routine
		startBounce();
		
	} else {
		// update the visit count
		visitCount++;
		checkCookie = setcookie("BirdsAndGarden",visitCount,1);
		//alert ('Welcome back! This is visit number ' + visitCount);
	
	}
}

//Function to set the expiry of the cookie
//Called by setcookie function
function getexpirydate (hours){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli + hours*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}

//Function to retrieve cookie data. Returns just the value of the named cookie.
function getcookie(cookiename) 
{
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 
 //cookie of that name not found?
 if (index1==-1 || cookiename=="") return ""; 
 
 //can we find value within named cookie
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

//Function to set the cookie data with a single value and duration
//eg:
//cookiecheck=setcookie(name,value,expires);
//The setcookie function takes three parameters. The cookie name, its value and a cookie duration measured in days(365 for a year, 1 for a //day,1/24 for an hour,1/24/60 for one minute etc.). The value returned cookiecheck is true or false depending on whether it was possible to set
//the cookie. Some browsers do not accept cookies or the cookie facility has been turned off. 

function setcookie(name,value,duration)
{
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
if(!getcookie(name)){
	return false;
}
else{
	return true;
	}
}