// Total - Fondation
// 05/06/04

function sniffer() 
{
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major == 4));
//    this.ns6 = (this.ns && (this.major >= 5));
//	this.ns7 = (this.ns6 && document.clientHeight);
	this.ns6 =(navigator.product == 'Gecko' && !window.find)?true:false;
	this.ns7 =(navigator.product == 'Gecko' && window.find)?true:false;

    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie5  = (this.ie && (this.major >= 4) && (document.getElementById) ) ? true : false ;
    this.ie6  = (this.ie5 && (agent.indexOf('msie 6')!=-1) ) ? true : false ;
    this.ie4  = (this.ie && (this.major >= 4) && !(this.ie5));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
    this.dom = (this.ns6 || this.ie5 );
}


clientIs = new sniffer();

/********************************************************************
*                   Ajout des feuilles de styles                    *
********************************************************************/
function linkCSS(filename,numerofichier)
{
	if(filename=='') return;
	
	// desactivée sous Netscape
	if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7) return;

	if(isNaN(numerofichier)) numerofichier ='';

	pos = filename.lastIndexOf("/");
	path = filename.substring(0,pos)+"/";

	filename = (clientIs.ie || clientIs.ns6 || clientIs.ns7) ? 'styleie' : 'stylens';
	linkString='\<link rel=\"stylesheet\" type=\"text\/css\" href=\"'+path+filename+numerofichier+'.css\"\>';

	document.write(linkString); 
	document.close();
}

/***************************************
*        gestion de la langue          *
***************************************/
/*function switchLanguage()
{
	var lPath = top.document.location.href;

	var newLanguage = "";
	if ((lPos = lPath.indexOf('/fr/'))>=0)
			newLanguage = "/en/";
		else
		{
			lPos = lPath.indexOf('/en/');
			newLanguage = "/fr/";
		}
	top.document.location.href = lPath.substring(0,lPos)+newLanguage+lPath.substring(lPos+4,lPath.length);
	
}*/
/************************************************************************************************************
*                   Roll Over (fonction native Dreamweaver renommées avec le prefixe MMNOAUTOLINK_)         *
************************************************************************************************************/

function MMNOAUTOLINK_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MMNOAUTOLINK_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MMNOAUTOLINK_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MMNOAUTOLINK_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MMNOAUTOLINK_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MMNOAUTOLINK_swapImage() { //v3.0
  var i,j=0,x,a=MMNOAUTOLINK_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MMNOAUTOLINK_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/********************************************************************
*                   Fonction de positionnement	                    *
********************************************************************/
function findParentDocument(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; 
	if(clientIs.ns6)
		return d[n].offsetParent;
		
	x=d.images[n];
	if(x) return d;


  for(i=0;d.layers&&i<d.layers.length;i++)
  	{
	 x=findParentDocument(n,d.layers[i].document);
	 if(!x) {continue}
	 else return d.layers[i];
	 
	 }
 // if(!x && d.getElementById) x=d.getElementById(n); 
  //x=d;
 
  return x; 
}
// retourne un new point() représentant la position d'une image dans la page

function getElementPosition(imageName)
{
	
	var position = new point();
	var layerOffset = new point();
	
	var img=MMNOAUTOLINK_findObj(imageName);
	if(!img) return new point();
	
	//// debug(img.offsetParent)
	if(clientIs.ns)
	{	
		// tous les ns
		if(!document.images[imageName] || clientIs.ns6)
		{
			var imgDoc = findParentDocument(imageName);
			// ns6 et ns7
			if(clientIs.ns6 || clientIs.ns7)
			{
				// Détecte l'offset du layer dans la page
				if(imgDoc.style) layerOffset.x = imgDoc.style.left;
				if(imgDoc.style) layerOffset.y = imgDoc.style.top;
				
				if(!layerOffset.x) layerOffset.x=0;
				if(!layerOffset.y) layerOffset.y=0;

			}
			// les versions antérieures
			else
			{
				if(imgDoc.left) layerOffset.x = parseInt(imgDoc.left) ;
				if(imgDoc.top) layerOffset.y = parseInt(imgDoc.top);	
			}
		}
	}


	if((clientIs.ns && !clientIs.ns7 &&!clientIs.ns6) ) 
	{
		position.x = img.x + 6;
		position.y = img.y;
	}
	if(clientIs.ns7) {
		position.x = img.x + 6;
		position.y = img.y;
	}
	if(clientIs.ns6 ) {
		position.x = img.offsetLeft + 6;
		position.y = img.offsetTop;
	}
	
	if(clientIs.ns ){
		
		position.x +=parseInt(layerOffset.x);
		position.y +=parseInt(layerOffset.y);
		
	}
	
	if(clientIs.ie ) {
		var imageObj;
		
    	position.x = img.offsetLeft + 6;    
		position.y = img.offsetTop; 

    	var objParent = img.offsetParent;    
		
    	while (objParent != null)
    	{                
		               
      		position.x += objParent.offsetLeft;    
			position.y += objParent.offsetTop;      
    	 	objParent = objParent.offsetParent;  
   		 }  
	}
	return position;		// point
}

// version 2 de point;
// on peut faire une iterface la la position temps réel d'un élément de la page.
// ref: chaine de caractères donnant le nom de l'élément de référence
function point(refName)
{
	
	if(!refName || refName==null)
	{
		this.refName="";
		this.ref=null;		
	}
	else
	{
		this.refName=refName;
		//this.ref = (clientIs.ns && !clientIs.ns6) ? document.images[this.refName] : document.getElementById(this.refName) ;
		this.ref = MMNOAUTOLINK_findObj(this.refName);
	}
	if(!this.ref) this.ref=null;
	
	this.x = 0;;
	this.y = 0;
	//this.name = "";
	this.type = "point";
	
	this.getPosition = function () {
		var error=getElementPosition(this.refName);
		
		//alert("error ="+error.x+" "+error.y);
		return error;
	}
	this.setRef = function (refName){
		this.refName = refName; 	// nom de l'element de référence ( image ! layer (à tester)?! )
		//this.ref = (clientIs.ns && !clientIs.ns6) ? document.images[this.refName] : document.getElementById(this.refName) ;
		this.ref = MMNOAUTOLINK_findObj(this.refName);
		return this.ref;
	}
	this.getRef = function (){
		//if(!this.ref) this.ref = (clientIs.ns && !clientIs.ns6) ? document.images[this.refName] : document.getElementById(this.refName) ;
		if(!this.ref) this.setRef(this.refName);
		return this.ref;
	}
	this.getRefName = function()
	{
		return this.refName;
	}
	this.getSize = function ()
	{
		var a = new point();
		if(!this.ref) return a;
		a.x = this.ref.width
		a.y = this.ref.height;
		return a;
	}
}
function ndigit(number, nDigit)
{
	str = ""+number;
	nDigit = nDigit-str.length;
	var i;
	for(i=0;i<nDigit;i++)
	{
		str="0"+str;
	}
	return str;
}

/********************************************************************
*                   Tableaux                                        *
********************************************************************/
function getArrayPos(arrayToSearch,itemToFind)
{
	var found;
	var nb= arrayToSearch.length
	for(var i=0;i<nb;i++)
		if(arrayToSearch[i]==itemToFind) return i;

	return -1;
}

debugWindow = null;
function debug(str)
{	
return ;
str1="";
	if(!debugWindow)
	{
		debugWindow = openWin("",500,400,1,1,"debugWindow");
		str1= '\<link rel=\"stylesheet\" href=\"..\/css\/styleie.css\"\>'
	}
	
	
	debugWindow.document.writeln(str1+"\<span class=\'contenuTexte\'\>"+str+"\<\/span\>\<br\>");
	//alert(str);
}

/********************************************************************
*                   Marquage XITI                                   *
********************************************************************/

function xt_clic(typecl,page)
{

site = '160602';
var pos = document.location.href.indexOf('/fr/');
if (pos>0) site = '160601';

hsh = new Date();
hsd = document;
hsr = hsd.referrer.replace(/[<>]/g, '');
xt_img = new Image();
hsi = 'http://logp.xiti.com/hit.xiti?s='+site;
hsi += '&p='+page+'&clic='+typecl+'&hl=' + hsh.getHours() + 'x' + hsh.getMinutes() + 'x' + hsh.getSeconds();
if(parseFloat(navigator.appVersion)>=4)
{Xiti_s=screen;hsi += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' + Xiti_s.colorDepth;}
hsi += '&ref=' + hsr.replace(/&/g, '$');
xt_img.src = hsi;

/*
if (url != null)
{ 
if ((nvlle=='')||(nvlle==null)) { hsd.location = url;} else {xfen = window.open(url,'xfen',''); xfen.focus();}}
else
{return;}
*/
}
function marquageXiti(site,site2,tagXiti)
{

	var requeteObject = new Image();
	var urlRequete = "";


	
	// modification du code de marquage Xiti //
	hsh = new Date();
	hsd = document;
	hsr = hsd.referrer.replace(/[<>]/g, '');
	
	//hsi = '<img width="1" height="1" src="http://logp.xiti.com/hit.xiti?s=136134&s2=2';
	hsi = 'http://logp.xiti.com/hit.xiti?s='+site+'&s2='+site2;

	
	//hsi += '&p=@@((xitiChapitre!='') ? xitiChapitre+'::' : '')@@@@((xitiSousChapitre!='') ? xitiSousChapitre+'::' : '')@@@@(xitiPage)@@';
	
	hsi +='&p='+tagXiti;
	//if(xitiChapitre!='') hsi += xitiChapitre+'::';
	//if(xitiSousChapitre!='') hsi += xitiSousChapitre+'::';
	//if(xitiSousSousChapitre!='') hsi += xitiSousSousChapitre+'::';
	//if(xitiPage!='') hsi += xitiPage;
	
	hsi += '&hl=' + hsh.getHours() + 'x' + hsh.getMinutes() + 'x' + hsh.getSeconds();
	if(parseFloat(navigator.appVersion)>=4)
	{Xiti_s=screen;hsi += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' + Xiti_s.colorDepth;}
	
	//hsd.writeln(hsi + '&ref=' + hsr.replace(/&/g, '$') + '"><\!--');
	urlRequete = hsi + '&ref=' + hsr.replace(/&/g, '$') ;
	
	//// debug(urlRequete);
	requeteObject.src = urlRequete;	
}

/********************************************************************
*                  Fond d'écran                                     *
********************************************************************/

var imagechoix = 0;

//function SelectionImg (nombre,numero,relativePath,layerName)
function SelectionImg (nombre,numero,relativePath)
{
	
	// on effaceles puces précédemment affichées
	for (i=0;i<nombre;i++)
	{   
		var compte=i+1;
		var imageon = "ecran_"+compte+"_on.jpg";
		var imageoff = "ecran_"+compte+"_off.jpg";
		var nomimage = "ecran"+compte;

		if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7)
			imageObj = document.images[nomimage];
		else
			imageObj = document.images[nomimage];
		if (!imageObj) break;
					
		imageObj.src = relativePath+"img/p9/"+imageoff; 
	}
	// on affiche la nouvelle puce
	var lequel = "ecran"+numero;
	var aff_image = "ecran_"+numero+"_on.jpg"
	if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7)
		imageObj = document.images[lequel];
	else
		imageObj = document.images[lequel];
		
	imageObj.src = relativePath+"img/p9/"+aff_image;
	return imagechoix = numero;
}

function checkResolution(langue)
{

	langue=languageIndex(langue);
	var objFormulaire = document.formulaire;

	var resolutionOK = false;
	for(var i=0;i<objFormulaire.resolution.length;i++)
	{
		if(objFormulaire.resolution[i].checked)
		{
			resolutionOK = true;
			resolutionchoix = objFormulaire.resolution[i].value;
		}
	}

	if(objFormulaire.resolution.checked=="") return formError(langue,16);
	if(!resolutionOK) return formError(langue,16);
	if(imagechoix==0)  return formError(langue,17);
	var urlfond = "open_fond/"+resolutionchoix+"_"+imagechoix+".htm";
	openImgFond(urlfond);
}

function openImgFond(URL)
{
lAttributes = '';
lAttributes += 'toolbar=0,';
lAttributes += 'Location=0,';
lAttributes += 'directory=0,';
lAttributes += 'status=0,';
lAttributes += 'menubar=0,';
lAttributes += 'scrollbars=0,';
lAttributes += 'resizable=0,';
lAttributes += 'width=320,';
lAttributes += 'height=270';
//var str = (isHP==1) ? '':'../';
winId = window.open(URL,'',lAttributes);
return false;
//document.location.href = str+'p9/p9_3.htm';
}