// 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 downloadNICDriver(driver, archive) {
	window.open('/support/ethernet_nic/driver-sla.php?driver=' + driver + '&archive=' + archive, '_download_driver',
		'height=550,width=640,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes');
	return false;
}

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

function toggleInputInGroups(divAllId, divId) {
	if (divAllId != '') {
		var inputs = $(divAllId).select('input', 'textarea');
		for (var i = 0; i < inputs.length; i++) {
			inputs[i].disabled = true;
			switch(inputs[i].type) {
				case "radio":
				case "checkbox":
	  			inputs[i].checked = false;
	  		break;
				case "text":
				case "textarea":
				  inputs[i].value = "";
			  break;
				default:
			}
		}

		var spans = $(divAllId).select('span');
		for (var i = 0; i < spans.length; i++) {
			spans[i].addClassName("disabled_text");
		}
	}

	var inputs = $(divId).select('input', 'textarea');
	for (var i = 0; i < inputs.length; i++)
		inputs[i].disabled = false;

	var spans = $(divId).select('span');
	for (var i = 0; i < spans.length; i++) {
		spans[i].removeClassName("disabled_text");	
	}
}

function FlowPlayer(key, videoID, videoFile) {
	var player = flowplayer(videoID,
		"/flowplayer/flowplayer.commercial-3.2.2.swf",
		{
			key: key,
			clip: {
				baseUrl: '/flash/',
				url: videoFile,
				autoPlay: true, 
				autoBuffering: true,
				bufferLength: 5,
				fadeInSpeed: 500
			},
			canvas: {
				backgroundColor: "#000000"
			},
			plugins: {
				TMPlugin: {
        	url: 'http://static.inplay.tubemogul.com/bootloader/TubeMogulFlowPlayer.swf',
        	playerID: 'P-IIQ-QXO',
        	trackerIDs: 'TD-6Y9-AZI',
        	publisherID: 'broadcom.com',
        	videoID: videoFile,
        	displayName: videoFile
      	},
				gatracker: {
					url: "/flowplayer/flowplayer.analytics-3.2.0.swf",
					labels: {
						start: "Start",	
						play: "Play",	
						pause: "Pause",	
						resume: "Resume",	
						seek: "Seek",	
						stop: "Stop",	
						finish: "Finish",	
						mute: "Mute",	
						unmute: "Unmute",	
						fullscreen: "Full Screen",	
						fullscreenexit: "Full Screen Exit"	
					},
				debug: false,
				trackingMode: "AS3",
				googleId: "UA-2678116-1"
				},
				viral: {
					url: "/flowplayer/flowplayer.viralvideos-3.2.1.swf",
					share: {
						description: 'Broadcom Video',
						digg:false,
						myspace:false,
						livespaces:false,
						orkut:false,
						stubmbleupon:false,
						bebo:false
					},
					email: false,
					embed: false
				},
				controls: {
					timeBgColor: '#555555',
					buttonOverColor: '#B30924',
					sliderGradient: 'none',
					durationColor: '#FFFFFF',
					volumeSliderColor: '#000000',
					progressGradient: 'medium',
					timeColor: '#EB0024',
					backgroundColor: '#000000',
					tooltipTextColor: '#FFFFFF',
					progressColor: '#9E0005',
					bufferColor: '#8F0005',
					tooltipColor: '#5F747C',
					backgroundGradient: 'low',
					borderRadius: '0',
					volumeSliderGradient: 'none',
					buttonColor: '#750012',
					bufferGradient: 'none',
					sliderColor: '#000000',
					height: 20,
					opacity: 1.0
				}
			}
		});
	
	return player;
}

var player = FlowPlayer(fpKey, 'overlay_videoplayer', '');

jQuery(function() {
	jQuery('a[rel]').overlay({
		speed: 'normal',
		expose: {
			color: '#F1F1F1',
			opacity: 0.9
		},
		onClose: function() { player.stop(); player.unload(); }
	});	
});

function playOverlayVideo(videoFile, videoID) {
	var divInfo = document.getElementById("overlay_videoinfo");
	if (divInfo != null && videoID != null) {
		var title = videos[videoID][1];
		var description = videos[videoID][2];
		divInfo.innerHTML = "<br/><br/>" + description;
	}

	player = FlowPlayer(fpKey, "overlay_videoplayer", videoFile);
	jQuery(function() {
		player.play([{url: videoFile}]);	
	});
}
