/* Bookmarking a page. */
function bookmarkPage(){
	var bookmarkLink = document.getElementById('addToFavourites');
	if(bookmarkLink){
		bookmarkLink.onclick = function(){
			if( typeof window.external!="undefined" && navigator.userAgent.indexOf("MSIE") != -1 ) {
		        window.external.AddFavorite( document.URL, document.title );
		    } else if( typeof window.opera!="undefined" ) {
	        	alert( addBookmarkAlert.replace('{0}', '[Ctrl] + [T]') );
		    } else {
	        	alert( addBookmarkAlert.replace('{0}', '[Ctrl] + [D]') );
	    	}		
		}
	}
	
	bookmarkLink = document.getElementById('addToFavouritesFooter');
	if(bookmarkLink){
		bookmarkLink.onclick = function(){
			if( typeof window.external!="undefined" && navigator.userAgent.indexOf("MSIE") != -1 ) {
		        window.external.AddFavorite( document.URL, document.title );
		    } else if( typeof window.opera!="undefined" ) {
	        	alert( addBookmarkAlert.replace('{0}', '[Ctrl] + [T]') );
		    } else {
	        	alert( addBookmarkAlert.replace('{0}', '[Ctrl] + [D]') );
	    	}		
		}
	}
	
	return false;
}

if (w3cDOM) {
	listenEvent (window, "load", bookmarkPage);
}

/* Homepage */
function homePage() {
	var homePageLink = document.getElementById('homePage');
	if(homePageLink){	
		homePageLink.onclick = function(){
			if( window.external ) {
				document.body.style.behavior = "url(#default#homepage)";
				document.body.setHomePage(document.URL);
			 } else {
				alert( setHomePageAlert );
			}
		}
	}
}

if (w3cDOM) {
	listenEvent (window, "load", homePage);
}

/* Login/logout */
function login(){
	var loginLink = document.getElementById('login');
	if(loginLink){
		var userId = getCookie( 'userId' );
		var auth = getCookie( 'auth' );
		/* contextUserId is defined only in "/genericLogin.do" action, it is necessary to check user when HttpSsession expires*/
		if( (userId && userId.length > 0 && (typeof contextUserId == 'undefined' || contextUserId == userId)) || (auth && auth.length > 0) ) {
			loginLink.className = 'logout';
			loginLink.innerHTML = logout;
			loginLink.onclick = function(){
				document.location = URILogout;
			}
		} else {
			loginLink.onclick = function(){
				document.location = URILoginGeneric;
			}
		}
	}
}
if (w3cDOM) {
	listenEvent (window, "load", login);
}