//CCIG & GREX JAVASCRIPT
//VERSION 1.0

var cssDir = "/styles/";

// Radical des noms des feuilles de styles à utiliser
// nom de fichier du styles <radical>_<largeur ecran>.css

var NS4CSS = "ns4";
var winIECSS = "win_ie";
var winIE6CSS = "win_ie6";
var strdCSS = "strd";
var macCSS = "mac";

var s19p="_19p";
var s17p="_17p";

var is_19pouce = false;

winIE6CSS=strdCSS;
winIECSS=strdCSS;
NS4CSS=strdCSS;
macCSS=strdCSS;

detectScreen();

// *******************************************
// DETECTION DU  NAVIGATEUR UTILISE
var agt=navigator.userAgent.toLowerCase();


// Rq: IE5  4 ==> utilisation de is_ie5up pour detecter IE5
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Type de nagigateur
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));
var is_nav6 = (is_nav && (is_major == 6));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6up = (is_nav && (is_major >= 6));
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major <= 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_opera = (agt.indexOf("opera") != -1);

// Systeme
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_sun   = (agt.indexOf("sunos")!=-1);
var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
var is_hpux  = (agt.indexOf("hp-ux")!=-1);
var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
var is_linux = (agt.indexOf("inux")!=-1);
var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
var is_unixware = (agt.indexOf("unix_system_v")!=-1);
var is_mpras    = (agt.indexOf("ncr")!=-1);
var is_reliant  = (agt.indexOf("reliantunix")!=-1);
var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
       (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
       (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
var is_sinix = (agt.indexOf("sinix")!=-1);
var is_freebsd = (agt.indexOf("freebsd")!=-1);
var is_bsd = (agt.indexOf("bsd")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_irix || is_sco ||
is_unixware || is_mpras || is_reliant ||
             is_dec || is_sinix || is_aix || is_bsd || is_freebsd);
// *******************************************


// CHARGEMENT FEUILLE DE STYLES
ChooseStyleSheet();

// *******************************************
// CAS DES NAVIGATEURS VERSION 4
// Ev pour de nav version 4 si retaillage de fenetre
if (is_nav4up && !is_nav5up) {
   var initWidth, initHeight;
   initWidth = window.innerWidth;
   initHeight = window.innerHeight;
   window.captureEvents(Event.RESIZE);
   window.onresize = handleResize;
}

function handleResize() {
   if (((initWidth != window.innerWidth) || (initHeight != window.innerHeight)) && (typeof disableReload == "undefined")) {
     location.reload();
   }
   return false;
}
// *******************************************

// DETECTION TAILLE ECRAN UTILISATEUR
function detectScreen() {
	var l=screen.width;
	if (l>1000) {is_19pouce=true;} else {is_19pouce=false;}
	return true;
}

function ChooseStyleSheet() {
  var fileHead = cssDir;
  var styles;
  if (is_win) {
	if (is_nav4) {
	    styles = fileHead + NS4CSS;
	} else if (is_ie6) {
	    styles = fileHead + winIE6CSS;
	} else if (is_nav5up) {
	    styles = fileHead + macCSS;
	} else if (is_opera) {
	    styles = fileHead + macCSS;
	} else {
	    styles = fileHead + winIECSS;
	}
  } else if (is_mac) {
	    styles = fileHead + macCSS;
  } else {
	styles = fileHead + strdCSS;
  }
  if (is_19pouce) {styles += s19p;} else {styles += s17p;}
  document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + styles + ".css\">");
  //alert('style utilise : ' + styles);
  return true;
}