// Global functions.

var currentVolume = "0.7";
var isCC = 0;
var isReady = false;
var isCookie = true;

// Get the data from the cookie, if any.
//
function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1)
				c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null;
}

// Save the data to the cookie.
//
function setCookie(c_name, value, expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

// Check and get the data from the cookie.
//
function checkCookie()
{
	isCC = getCookie('iscc');
	if ((isCC == null) || (isCC > 1))
	{
		isCC = 2;
		setCookie('iscc', isCC, 1);
		isCookie = false;
	}

	currentVolume = getCookie('currentVolume');
	if ((currentVolume == null) || (currentVolume == ""))
	{
		currentVolume = "0.7";
		setCookie('currentVolume', currentVolume, 365);
		isCookie = false;
	}
	isReady = true;
}

// Called by actionscript to get current language to display
//
function readLang()
{
	if (isFre)
		return "fr";
	else
		return "en";
}
// Called by actionscript to get current volume that was saved.
//
function readVolume()
{
	return currentVolume;
}

// Called by actionscript to save the current volume.
//
function saveVolume(value)
{
	currentVolume = value;
	setCookie('currentVolume', currentVolume, 365);
}

function readCC()
{
	if (isCC == 2)
		return 0;
	return isCC;
}

function saveCC(value)
{
	isCC = value;
	setCookie('iscc', isCC, 1);
}

// Called by actionscript just to verify that there is communication between
// Flash and HTML. If javascript is not enabled, this will fail.
//
function isJSready()
{
	return isReady;
}

// Called by actionscript to go to a new page.
//
function gotoPage(value)
{
	switch (value)
	{
		case "walls":
		case "ceilings":
		case "entrances":
		case "exoclad":
			break;
		default:
			return;
	}
	
	if (isFre)
		var destUrl = "indexfr.php?menu=" + value + "&second=introduction&fr=1";
	else
		var destUrl = "index.php?menu=" + value + "&second=introduction";
	
	myWindow = window.open(destUrl, '_self');
}

function gotoCapPage(product, destSwf)
{
	var destUrl = "menu=" + product + "&second=portfolio&playswf=" + destSwf;

	if (isCookie == false)
		destUrl = destUrl + "&capsel";

	if (isFre == true)
		destUrl = "indexfr.php?" + destUrl + "&fr=1";
	else
		destUrl = "index.php?" + destUrl;

	myWindow = window.open(destUrl, '_self');
	myWindow.focus();
}

function saveCapAndPlaySWF(cap, product, destSwf)
{
	var destUrl = "menu=" + product + "&second=portfolio&playswf=" + destSwf;

	if (isFre == true)
		destUrl = "indexfr.php?" + destUrl + "&fr=1";
	else
		destUrl = "index.php?" + destUrl;

	saveCC(cap);
	myWindow = window.open(destUrl, '_self');
	myWindow.focus();
}

function playSWF(destUrl)
{
	myWindow = window.open(destUrl, '_blank', 'height=500,location=no,menubar=no,resizeable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=800', 'false');
	myWindow.focus();
}


