//-- Scrit chargé soit par le frameset principal
//-- soit par la page de changement de style.

SKIN_TAB = [
["Défaut", "Temple.css"],
["Temple", "Temple.css"],
["Crypte", "Crypt.css"]];

if (location.host.match(/^crypte/i)
||  location.host.match(/free\.fr$/i) )
	SKIN_TAB [0][1] = "Crypt.css";

function GET_SKIN_LIST()
{
	return SKIN_TAB;
}

function CHANGE_SKIN(NEW_SKIN)
{
	if (NEW_SKIN != CUR_SKIN)
	{
		CUR_SKIN = NEW_SKIN;
		for (I = 0; I < frames.length; I++)
			//-- Appliquer le style à toutes les frames
			SET_CHILD_SKIN (frames[I]);
			

		var SKIN_NAME = SKIN_TAB [CUR_SKIN][0];
		//-- Création des cookie locaux et remote
		CREATE_SKIN_COOKIE(SKIN_NAME);
		frames["TEMPLE_TOP"].CREATE_REMOTE_SKIN_COOKIE(SKIN_NAME);
	}
}

function SET_CHILD_SKIN(CHILD_FRAME)
{
	if (document.body.style.setProperty) // pas de changement de style avec IE pour éviter les catastrophes
	{
		STYLESHEET = CHILD_FRAME.document.getElementsByTagName("link")[0];
		if (typeof (STYLESHEET) != "undefined")
			STYLESHEET.href = STYLESHEET.href.replace (/[^\/]+$/, SKIN_TAB[CUR_SKIN][1]);
	}
}

function CREATE_SKIN_COOKIE(SKIN_NAME)
{
    var DATE = new Date();
    DATE.setTime(DATE.getTime()+100000000000);
  	document.cookie = "skin="+SKIN_NAME+"; expires="+DATE.toGMTString()+"; path=/";
}

function READ_SKIN_COOKIE ()
{
  COOKIE_TAB = document.cookie.split(';');
  for (I=0; I < COOKIE_TAB.length; I++)
  {
    var COOKIE = COOKIE_TAB[I];
    if (COOKIE.match(/^\s*skin=/) )
		return COOKIE.substring(COOKIE.indexOf("=")+1);
  }
  return "";
}

if (location.href.match(/\/SetRemoteSkin.htm\?/))
{
	SKIN_NAME = /\?.+$/.exec(location.href);
	if (SKIN_NAME)
	{
		SKIN_NAME = decodeURIComponent (SKIN_NAME[0].substring(1));
		CREATE_SKIN_COOKIE (SKIN_NAME);
	}
}
else
{
	var SKIN_NAME = READ_SKIN_COOKIE();
	for (CUR_SKIN = 1; CUR_SKIN < SKIN_TAB.length; CUR_SKIN++)
		if (SKIN_TAB [CUR_SKIN][0] == SKIN_NAME)
			break;
	if (CUR_SKIN >= SKIN_TAB.length)
		CUR_SKIN = 0;
}
