function ffw_getCookie(name)
{
	var value;
	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)
		{
			value = unescape(c.substring(nameEQ.length,c.length));
			
			return value;
		}
	}
	return null;
}

function ffw_setCookie(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=/";
}	

var currentOS = 'windows';

function swapToOS(os)
{
	if (os == currentOS)
		return;

	var osTab;
	var osCategories;
	var box;

	// Deactive old tab
		osTab = document.getElementById('ostab-' + currentOS);
		osTab.className = '';
	
	// Hide old category list
		osCategories = document.getElementById('categories-' + currentOS);
		osCategories.style.display = 'none';

	// Switch OS
		currentOS = os;	

	// Activate new tab
		osTab = document.getElementById('ostab-' + currentOS);
		osTab.className = 'active';

	// Show new category list
		osCategories = document.getElementById('categories-' + currentOS);
		osCategories.style.display = 'block';

	// Change box
		box = document.getElementById('downloads-category');
		box.className = 'box-style1 box-style1-' + os;

	// Register cookie
		ffw_setCookie('ostab', os, 365);
}
