/**
 * Methods to add bookmarks to the browser
 *
 * @authors		Martin Widemann
 * @copyright	Copyright 2009-2011 - Netigo GmbH
 * @version		1.1
 * @modified	2011-06-23
 */
var Bookmark = 
{

	/**
	 * Checks, if bookmarks can be added
	 *
	 * @return bool
	 */
	canBookmark: function()
	{
		var canBookmarkPage = (typeof window.external == 'object');

		return canBookmarkPage;
	},
		
	/**
	 * Return the keystroke for manually adding bookmarks to the browser
	 *
	 * @return string
	 */
	getKeystroke: function()
	{
		var browser = navigator.userAgent.toLowerCase();
		var keystroke = ((browser.indexOf('mac') != -1) ? 'Command/Cmd' : 'CTRL') + ' + D';

		return keystroke;
	},

	/**
	 * Sets a bookmark to the browser
	 *
	 * @param string url URL to bookmark
	 * @param string title Name to use for the bookmark
	 * @param string msg Message to display, if bookmark can not be set
	 * @param bool silent If false, message will be alerted
	 *
	 * @return bool
	 */
	bookmarkPage: function(url, label, msg, silent)
	{
		// Get URL from browser
		if(!url){
			url = window.location.href;
		} // if

		// Get URL from window
		if(!label){
			label = document.title;
	
			if(!label){
				label = window.name;
	
				if(!label){
					label = url;
				} // if
			} // if
		} // if

		// Default message
		if(!msg){
			msg = 'Your browser does not support this feature!';
		} // if

		if(this.canBookmark()){
			try{
				if(window.sidebar){
					window.sidebar.addPanel(label, url, '');
				}else{
					window.external.AddFavorite(url, label);
				} // if

				return true;
			}catch(e){
				if(!silent){
					alert(msg);
				} // if

				return false;
			} // try
		}else{
			if(!silent){
				alert(msg);
			} // if

			return false;
		} // if
	}

}

