
// bookmark.js

// Bookmark link via JavaScript
// Created for myBible

// Source:
// <http://www.reconn.us/content/view/43/64/>

// Usage:
// <a href="javascript:bookmark('http://www.reconn.us','You\'ll find here lots of free resources!')">Bookmark</a>

function bookmark(url, title){

	// If URL is not a full link,
	// prepend the page address to it (minus any arguments)
	// Source: Firefox
	// <file:///Applications/Firefox.app/Contents/MacOS/
	// components/nsSidebar.js> Line 48
	if(!/^(https?:|ftp:)/i.test(url)){
		url = "http://" + document.location.host + document.location.pathname + url;
		// alert(url); // <----- debug
	}

	if(window.sidebar){ // Firefox
		window.sidebar.addPanel(title, url, "");
	}else if(window.opera && window.print){
		// Opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}else if(document.all){
		// IE
		window.external.AddFavorite(url, title);
	}
	
}
