// Expire cookie in 30 days
expire = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30);

// Reset the user's font size pref when the page is loaded
val = getCookie('selectedStyle');
if (val && val != 'undefined') {
	pickStyle(val);
}

// functions *********************************************
function OpenBrWindow(theURL, winName, features, myWidth, myHeight, isCenter) {
	if (window.screen) {
		if (isCenter) {
			if (isCenter == "true") {
				var myLeft = (screen.width - myWidth) / 2;
				var myTop = (screen.height - myHeight) / 2;
				features += (features != '') ? ',' : '';
				features += ',left=' + myLeft + ',top=' + myTop;
			}
		}
	}
	window.open(theURL, winName,
		features + ((features != '') ? ',' : '') + 'width=' + myWidth + ',height=' + myHeight);
}

// Bookmark Page
function bookmarkIt() {
	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 (Prototype.Platform.Mac) {
		alert(macintosh);
	} else if (document.all && window.external) {
		window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
	} else if (Prototype.Browser.Opera) {
		alert(opera);
	}
	return false;
}

// Print Page
function printIt() {
	if (Gizmos.Prototype.Platform.Mac) {
		alert("Attention Macintosh User. Unfortunately this functionality is not available on the Macintosh OS. Please click the page you would like to print a select print from your browser menu.");
	} else {
		self.print();
	}
}


function pickStyle(style) {
	var lastStyle = getCookie('selectedStyle');
	var ss = document.getElementById(lastStyle);
	if (ss)
		ss.disabled = true;
	setCookie('selectedStyle', style, expire);
	ss = document.getElementById(style);
	if (ss) {
		ss.disabled = true;
		ss.disabled = false;
	}
}

function shareWebPageLink(objLink) {
	var url = window.location.href.replace("&", "%26");
	var title = document.title.replace("&", "%26");

	var href = "mailto:?subject=You have received a link from broadcom.com" +
		"&body=Title: " + title + "%0A%0ALink: " + url +
		"%0A%0AFor more information about Broadcom products please visit http://www.broadcom.com/";

	objLink.href = href;
	return false;
}

function ignoreDetect() {
	setCookie('ignoreBrowserCheck', 1, expire);
}

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";
}


function eulaDownload(file) {
	window.open('/support/license.php?file=' + file, '_download',
		'height=550,width=640,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes');
	return false;
}

function careersCalendar(site, schoolID) {
	var target = site + "/careers/calendar.php";
	if (schoolID)
		target += "?school_id=" + schoolID;
	window.open(target, 'calendar',
		'width=775,height=575,scrollbars=yes,status=no');
	return false;
}

function shareWebPageLink(link) {
	var url = window.location.href.replace("&", "%26");
	var title = document.title.replace("&", "%26");
	
	var href = "mailto:?subject=You have received a link from broadcom.com" +
		"&body=Title: " + title + "%0A%0ALink: " + url +
		"%0A%0AFor more information about Broadcom products please visit http://www.broadcom.com/";
	
	link.href = href;
	return false;
}

function toggleDiv(imgID, divID) {
	var img = document.getElementById(imgID);
	var div = document.getElementById(divID);

	if (img == null || div == null)
		return;

	var show = false;
	if (div.style.display == "none")
		show = true;

	swapToggleImg(img, show);
	toggleDivVisibility(div, show);
}

function toggleAllDiv(imgID, divID, hidID) {
	var img = document.getElementById(imgID);
	var hid = document.getElementById(hidID);

	if (img == null || hid == null)
		return;

	var show = false;
	
	if (hid.value == "0") {
		hid.value = "1";
		show = true;
	} else
		hid.value = "0";
	
	swapToggleImg(img, show);
	
	$$('#' + divID + ' div.toggle_body').each(function(div) {
		toggleDivVisibility(div, show);
	});
	$$('#' + divID + ' div.toggle_header img').each(function(img) {
		swapToggleImg(img, show);
	});
}
function swapToggleImg(img, show) {
	if (!img)
		return;
	if (show)
		img.src = img.src.replace("directory_plus.gif", "directory_minus.gif");
	else
		img.src = img.src.replace("directory_minus.gif", "directory_plus.gif");
}
function toggleDivVisibility(div, show) {
	if (!div)
		return;
	if (show)
		div.style.display = "block";
	else
		div.style.display = "none";
}
