// Expire cookies in 30 days
var cookieExpire = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30);

/* Style sheet selection */
var styleCookie = 'selectedStyle';

function pickStyle(style) {
	lastStyle = getCookie(styleCookie);
	ss = document.getElementById(lastStyle);
	if (ss)
		ss.disabled = true;
	setCookie(styleCookie, style, cookieExpire);
	ss = document.getElementById(style);
	if (ss) {
		ss.disabled = true;
		ss.disabled = false;
	}
}

// Reset the user's font size pref when the page is loaded
var styleCookieVal = getCookie(styleCookie);
if (styleCookieVal && styleCookieVal != 'undefined') {
	pickStyle(styleCookieVal);
}
/* Style sheet selection */

// Browser / UA detection
var isMac = (window.navigator.appVersion.indexOf("Mac") != -1);

/* Page functions */
function bookmarkPage() {
	var bookmarkTitle = document.title;
	var bookmarkUrl = document.location;
	var macintosh = "Macintosh users, to Bookmark this page please press CTRL+D.";
	var opera = "Opera users, to Bookmark this page please press CTRL+D.";

	if (window.sidebar && window.sidebar.addPanel) {
		window.sidebar.addPanel(bookmarkTitle, bookmarkUrl, "");
	} else if (isMac) {
		alert(macintosh);
	} else if (document.all && window.external) {
		window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
	} else if (window.opera && window.print) {
		alert(opera);
	}
	return false;
}
function printPage() {
	self.print();
	return false;
}
function emailPage(page) {
	var url = window.location.href.replace("&", "%26");
	var title = document.title.replace("&", "%26");
	var href = "mailto:?subject=You have received a link from broadcomfoundation.com" +
		"&body=Title: " + title + "%0A%0ALink: " + url +
		"%0A%0AFor more information about the Broadcom Foundation please visit http://www.broadcomfoundation.com/";

	page.href = href;
}
/* Page functions */

/* Cookie handling */
function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		"; path=/";
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0)
			return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name) {
	if (getCookie(name))
		document.cookie = name + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
/* Cookie handling */