// Utility functions

// Client platform
var sUndef	= "Undefined";
var sWin	= "Windows";
var sMac	= "Mac";
var sUnix	= "Unix";
var sLinux	= "Linux";
var agent	= navigator.userAgent.toLowerCase();
var platform = sUndef;
if		(agent.indexOf("win")   != -1) platform = sWin;
else if	(agent.indexOf("mac")   != -1) platform = sMac;
else if	(agent.indexOf("x11")   != -1) platform = sUnix;
else if	(agent.indexOf("linux") != -1) platform = sLinux;

// viewPlatform determines which platform user wishes to view
// If user already chose a platform use that, else use user's current platform
var viewPlatform = readCookie('viewPlatform');
if (viewPlatform == null)
  viewPlatform = platform;	// Use actual platform

function switchPlatform (newPlatform) {
// Switch product view to a different platform by saving choice as a cookie and reloading page
  createCookie ('viewPlatform', newPlatform, 7);
  window.location.reload();
}

// Cookie support
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// Switch page - don't add current page to browser history
function gotoPage (URL) {
	if (window.location.protocol == 'file:')
		URL = 'file:///E:/Internet/JigSite/'+URL;
	location.replace (URL);
}

function openWin(URL) {
	if (window.location.protocol == 'file:')
		URL = 'file:///E:/Internet/JigSite/'+URL;
	aWindow=window.open(URL,"Info","toolbar=no,width=550,height=300,status=no,scrollbars=yes,resize=yes,menubar=no");
}

