function getCookie(Name) 
{   
	var search = Name + "=";
	
	if (document.cookie.length > 0) 
	{ 
		// if there are any cookies      
		offset = document.cookie.indexOf(search);
		if (offset != -1) 
		{ 
			// if cookie exists          
			offset += search.length;
			// set index of beginning of value         
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value         
			if (end == -1)             
				end = document.cookie.length;
			
			return unescape(document.cookie.substring(offset, end));
		}    
	}
}

function GetBookbagStatus(siteid)
{
	var arrayOfItems;
	var strBookbag = getCookie( siteid + "-BOOKBAG" );
	var nCount = 0;
	var strStatus;

	if(typeof(strBookbag) != "undefined")
	{
		arrayOfItems = strBookbag.split("*");

		if(arrayOfItems.length == 1)
		{
			// Must check length of first item because Netscape will still allocate 
			// an array element for it. We also test for a string length greater than
			// 1 as IE 5.0 for the Mac will report a 1 char length string if the
			// cookie value is empty, as MarcHeaderIDs are greater than 10000, this 
			// will pose no problems.
			if(arrayOfItems[0].length > 1)
			{
				nCount = 1;
			}
		}
		else
		{
			nCount = arrayOfItems.length;
		}
	}

	if(nCount == 1)
	{
		strStatus = nCount + " Item in <a href='/webopac/bookbag' title='View Bookbag' target=MAIN_FRAME>Bookbag</a>";
	}
	else
	{
		strStatus = nCount + " Items in <a href='/webopac/bookbag' title='View Bookbag' target=MAIN_FRAME>Bookbag</a>";
	}

	document.write(strStatus);
}
