		var delim = ',';
		var MaxFavorites = 4;
		function SetCookie(name, value)
		{
			var expiredays = 10;
			
			var curr = GetCookie(name);	
			if (AlreadyExists(name, value)) return;
			
			var exdate=new Date()
			exdate.setDate(exdate.getDate()+expiredays);
			if (value != '' && curr != "") value = curr + delim + value;
			document.cookie=name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString() + ";path=/")
			return false;
		}
		
		function OnFavoritePage()
		{
			return document.location.indexOf('Favorites.aspx') >= 0;
		}
		
		function MaxReached(name)
		{
			return PageCount(name) >= MaxFavorites;
		}
		
		function PageCount(name)
		{
			if (GetCookie(name) == '') return 0;
			var arr = GetCookie(name).split(',');
			return arr.length;
		}
		
		function AlreadyExists(name, value)
		{
			var arr = GetCookie(name).split(',');
			for (j=0; j<arr.length; ++j)
				if (arr[j] == value) return true;
			return false;
		}
		
		function Remove(name, value)
		{
			var arr = GetCookie(name).split(',');
			var str = '';
			AddItem('');
			str = '';
			for (j=0; j<arr.length; ++j)
				if (arr[j] != value && arr[j] != '') 
					str += (str == '' ? '' : ',') + arr[j];
			AddItem(str);
		}
		
		function AddItem(value)
		{
			SetCookie('pages', value);
			if (value == '')
			{
				var url = new String(window.location);
				window.location = url.replace('#', '');
			}
		}
		
		function ContainsData()
		{
			return GetCookie('pages').length > 0;
		}

		function SubmitForm(url)
		{
			if (!ContainsData())
				alert('You have not selected anything');
			else
				window.location = url + fronts + ',' + GetCookie('pages') + ',' + backs;
		}
		
		function ClearCookie(name)
		{
			SetCookie(name, '');
			for (var b=0; b<document.links.length; ++b)
			{
				if (document.links[b].innerHTML == 'Favorite')
				{
					document.links[b].innerHTML = 'Add to Favorites';
				}
			}
		}
		
		function GetCookie(c_name)
		{
			if (document.cookie.length>0)
			{
				c_start=document.cookie.indexOf(c_name + "=")
				if (c_start!=-1)
				{ 
					c_start=c_start + c_name.length+1 
					c_end=document.cookie.indexOf(";",c_start)
					if (c_end==-1) c_end=document.cookie.length
					return unescape(document.cookie.substring(c_start,c_end))
				} 
			}
			return ""
		}
		function ShowValue(name)
		{
			window.status = GetCookie(name);
		}
		
		function Process(name, value, elem)
		{
			if (elem.checked) 
				SetCookie(name, value); 
			ShowValue('number');
		}

		function SubmitFavorite(f)
		{
			if (GetCookie('pages') == '') 
			{
				alert('You have no selection'); 
				return false; 
			} 
			f.properties.value = GetCookie('pages'); 
			f.url.value = document.location; 
			f.submit(); 
		}
		
		function WriteFavorite()
		{
			if (PageCount('pages') > 0) 
				document.write('Compare Favorites'); 
		}
		
		function FavoriteClick(id, alink, portfolio)
		{
			var elem = document.getElementById('sp' + id); 
			if (elem != null) 
				elem.innerHTML = 'Favorite'; 
			alink.innerHTML = ''; 

			var str = new String(GetCookie('pages'));
			var headPage = '';
			try {
			eval('headPage = MiddlePagesHeader_' + portfolio);
			} 
			catch (err) {}
			if (str.search(headPage) < 0)
			{
				id = headPage + ',' + id;
			}

			AddItem(id); 
			elem = document.getElementById('compareLink'); 
			if (elem != null) 
				elem.innerHTML = 'Compare Favorites';
			return false;
		}
		
		function Status(id)
		{
			if (!AlreadyExists('pages', id)) 
				document.write('Add to Favorites'); 
		}
		
		function Status2(id)
		{
			if (AlreadyExists('pages', id))  
				document.write('Favorite'); 
		}