// Déclaration des fonctions

function changeskin(change) {
  var scheme = change;
  var name = 'theme';
  var pathname = location.pathname;
  var myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
  var ExpDate = new Date ();
  ExpDate.setTime(ExpDate.getTime() + (180 * 24 * 3600 * 1000));
  setCookie(name,scheme,ExpDate,myDomain);
}
function getCookie(name) {
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function modifierBouton(scheme) {

  if (document.getElementById('i_icon_mini_index'))
    document.getElementById('i_icon_mini_index').src = 'http://sandream.info/Themes/' + scheme + '/bouton_accueil.gif' ;
  if (document.getElementById('i_icon_mini_portal'))
    document.getElementById('i_icon_mini_portal').src = 'http://sandream.info/Themes/' + scheme + '/bouton_portail.gif' ;
  if (document.getElementById('i_icon_mini_calendar'))
    document.getElementById('i_icon_mini_calendar').src = 'http://sandream.info/Themes/' + scheme + '/bouton_calendrier.gif' ;
  if (document.getElementById('i_icon_mini_faq'))
    document.getElementById('i_icon_mini_faq').src = 'http://sandream.info/Themes/' + scheme + '/bouton_faq.gif' ;
  if (document.getElementById('i_icon_mini_search'))
    document.getElementById('i_icon_mini_search').src = 'http://sandream.info/Themes/' + scheme + '/bouton_rechercher.gif' ;
  if (document.getElementById('i_icon_mini_members'))
    document.getElementById('i_icon_mini_members').src = 'http://sandream.info/Themes/' + scheme + '/bouton_membres.gif' ;
  if (document.getElementById('i_icon_mini_groups'))
    document.getElementById('i_icon_mini_groups').src = 'http://sandream.info/Themes/' + scheme + '/bouton_groupes.gif' ;
  if (document.getElementById('i_icon_mini_profile'))
    document.getElementById('i_icon_mini_profile').src = 'http://sandream.info/Themes/' + scheme + '/bouton_profil.gif' ;
  if (document.getElementById('i_icon_mini_message'))
    document.getElementById('i_icon_mini_message').src = 'http://sandream.info/Themes/' + scheme + '/bouton_message.gif' ;
  if (document.getElementById('i_icon_mini_new_message'))
    document.getElementById('i_icon_mini_new_message').src = 'http://sandream.info/Themes/' + scheme + '/bouton_nouveau_message.gif' ;
  if (document.getElementById('i_icon_mini_logout'))
    document.getElementById('i_icon_mini_logout').src = 'http://sandream.info/Themes/' + scheme + '/bouton_deconnexion.gif' ;
  if (document.getElementById('i_icon_mini_login'))
    document.getElementById('i_icon_mini_login').src = 'http://sandream.info/Themes/' + scheme + '/bouton_connexion.gif' ;
  if (document.getElementById('i_whosonline'))
    document.getElementById('i_whosonline').src = 'http://sandream.info/Themes/' + scheme + '/bouton_qui.gif' ;
  
}

// Affichage du thème et modification
document.write('<style>body { margin-top: 30px; }</style><div style="position: absolute; top: 10px; left: 10px;" id="skinselector"><form><select id="id_theme" onchange="changeskin(this.options[this.selectedIndex].value); window.location.reload();"><option value="defaut">Defaut</option><option value="Skin1">Atlantis</option><option value="Skin2"> Lémuria </option><option value="Skin3"> Abydoss </option><option value="Skin4"> Cydonia </option><option value="Skin5"> Solaris </option><option value="Skin6"> Origya </option><option value="Skin7"> Terra </option><option value="Skin8"> Babylone </option><option value="Skin9"> NewsPlanète </option></select></form></div>');

// Récupération du thème
var scheme = getCookie('theme');
if (scheme == null) scheme = 'defaut' ;
 document.getElementById('id_theme').value = scheme ;

if (scheme != "defaut") {
  
  // Modification du CSS
  document.write('<LINK REL="stylesheet" TYPE="text/css" HREF="http://sandream.info/Themes/' + scheme + '/style.css">');
  // Modification de la bannière
  if (document.getElementById('logo')) { // phpBB3
    document.getElementById('logo').innerHTML = '<img src="http://sandream.info/Themes/' + scheme + '/banniere.gif" />'
  } else { // phpBB2
    document.getElementById('i_logo').src = 'http://sandream.info/Themes/' + scheme + '/banniere.gif' ;
  }
  // Modifications des boutons
  setTimeout("modifierBouton(scheme)", 1000) ;
    
}
