
	var n1 = '<div class="skres_stat"><table align="center"><tbody><tr><td><a href="/member/viewMessages.do?folder=inbox">New Messages</a></td><td>(&nbsp;';
	var n2 = '&nbsp;)&nbsp;</td><td><a href="/member/myFriends.do?listType=requests">Friend Requests</a></td><td>(&nbsp;';
	var n3 = '&nbsp;)&nbsp;</td></tr><tr><td><a href="/member/myFriends.do?listType=live">Friends Live</a></td><td>(&nbsp;';
	var n4 = '&nbsp;)&nbsp;</td><td><a href="/member/viewProfileComments.do">New Comments</a></td><td>(&nbsp;';
	var n5 = '&nbsp;)&nbsp;</td></tr></tbody></table></div>';
	
	function noticeAjaxRequest(nUrl) {
		req = newXMLHttpRequest();

		if (req) {
	        req.onreadystatechange = updateNotifications;
			var newUrl = nUrl + '?unique=' + Math.random();
			req.open('GET', newUrl, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send('');
		}
	}
	
	function checkCookie() {
	
		if (!loggedIn) {
			// not logged in
			return 'false';
		} else {
			// logged in
			var notices = getCookie("notifications");
			if(notices == "") {
				// cookie is expired, need to get fresh set of notificatons
				return 'true';
			} else {
				// cookie is valid, will populate header with cookie data
				var dataArray = new Array();
				dataArray = notices.split('&');
				
				var unreadMessages = dataArray[0];
				var pendingFriends = dataArray[1];
				var liveFriends = dataArray[2];
				var unreadComments = dataArray[3];
				
				var regExp = /[^0-9]/;
				var matcher1 = regExp.exec(unreadMessages);
				var matcher2 = regExp.exec(pendingFriends);
				var matcher3 = regExp.exec(liveFriends);
				var matcher4 = regExp.exec(unreadComments);
				if(matcher1 != null || matcher2 != null || matcher3 != null || matcher4 != null) {
					// non-numeric entry found, get fresh set of notifications
					return 'true';
				} 
				
				var expireStr = dataArray[4];
				var now = new Date();
				
				var expire = new Date(expireStr);
				
				if(expire >= now) {
					// cookie is still valid, just do content replace
					replaceContent(unreadMessages, pendingFriends, liveFriends, unreadComments);
					return 'false';				
				} else {				
					// cookie has expired, need to get fresh set of notifications
					return "true";
				}
			}			
		}	
	}
	
	function setNotificationCookie(cookieValue) {
	 	var today = new Date();
 		var expire = new Date();
 		expire.setTime(today.getTime() + 300000); // 300 second expire time
	 	document.cookie = "notifications="+escape(cookieValue + "&" + expire.toGMTString()) +";path=/;"; //+";expires="+expire.toGMTString();
	}

	function getCookie(cookieName) {
		 var theCookie=""+document.cookie;
		 var ind=theCookie.indexOf(cookieName);
		 if (ind==-1 || cookieName=="") return ""; 
		 var ind1=theCookie.indexOf(';',ind);
		 if (ind1==-1) ind1=theCookie.length; 
		 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}	
	
	function getNotifications() {
		if (headerDebug)
			alert('in getNotifications(), checkCookie():"'+checkCookie()+'"');
			
		if(checkCookie() == 'true') {
			if (headerDebug)
				alert('make getNotifications ajax call');
				
			var newUrl = '/servlet/ajax/getNotifications';
			noticeAjaxRequest(newUrl);
		}
	}
	
	function replaceContent(unreadMessages, pendingFriends, liveFriends, unreadComments) {
	
		var replaceMe = document.getElementById('skres_ct');
		
		if (replaceMe != undefined)
			replaceMe.innerHTML = n1 + unreadMessages + 
								  n2 + pendingFriends + 
								  n3 + liveFriends + 
								  n4 + unreadComments + n5;	
	}
	
	function updateNotifications() {
		if (req.readyState == 4 && req.responseText.lastIndexOf('notification') != -1) {
			if (headerDebug)
				alert('in updateNotifications()'+req.responseText);
			
			var data = eval('(' + req.responseText + ')');
			
			if(data.loggedIn == 'true') {
				
				var unreadMessages = data.unreadMessages;
				var pendingFriends = data.pendingFriends;
				var liveFriends = data.liveFriends;
				var unreadComments = data.unreadComments;
								
				replaceContent(unreadMessages, pendingFriends, liveFriends, unreadComments);								
									  
				setNotificationCookie(unreadMessages + "&" + pendingFriends + "&" + liveFriends + "&" + unreadComments);									  						
				
			} else {
				if (headerDebug)
					alert('not logged in');
			}
        }
	}