// Total - Fondation
// 05/06/04
/********************************************************************
*                   fonctionnalité open window                    *
********************************************************************/

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.safari = (navigator.product == 'Gecko' && agent.indexOf('Safari')!=-1) ? true:false;
	this.ns6 =(navigator.product == 'Gecko' && !window.find && !this.safari)?true:false;
	this.ns7 =(navigator.product == 'Gecko' && window.find && !this.safari)?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.ns7 || this.ie5 || this.safari );
/*
	snifferWin = openWin("",500,500,1,1,"snifferwin");
	//snifferWin.document.write("<HTML>");
	snifferWin.document.write("User Agent: "+navigator.userAgent+"<br>");
	snifferWin.document.write("Application version: "+navigator.appVersion+"<br>");
	snifferWin.document.write("Product: "+navigator.product+"<br>");
	snifferWin.document.write("ClientIs.ns: "+this.ns+"<br>");
	snifferWin.document.write("ClientIs.ns2: "+this.ns2+"<br>");
	snifferWin.document.write("ClientIs.ns3: "+this.ns3+"<br>");
	snifferWin.document.write("ClientIs.ns4: "+this.ns4+"<br>");
	
	snifferWin.document.write("ClientIs.ns4b: "+this.ns4b+"<br>");
	snifferWin.document.write("ClientIs.ns6 "+this.ns6+"<br>");
	snifferWin.document.write("ClientIs.ns7"+this.ns7+"<br>");
	snifferWin.document.write("ClientIs.ie: "+this.ie+"<br>");
	snifferWin.document.write("ClientIs.ie3: "+this.ie3+"<br>");
	snifferWin.document.write("ClientIs.ie4: "+this.ie4+"<br>");
	snifferWin.document.write("ClientIs.ie5: "+this.ie5+"<br>");
	snifferWin.document.write("ClientIs.ie6: "+this.ie6+"<br>");
	snifferWin.document.write("ClientIs.op3: "+this.op3+"<br>");
	snifferWin.document.write("ClientIs.win: "+this.win+"<br>");
	snifferWin.document.write("ClientIs.mac: "+this.mac+"<br>");
	snifferWin.document.write("ClientIs.unix: "+this.unix+"<br>");
	snifferWin.document.write("ClientIs.dom: "+this.dom+"<br>");
	
		//snifferWin.document.write("</HTML>");

	snifferWin.document.close();
	snifferWin.focus();
	*/
}
/***************************************************
//fonctions esotériques
***************************************************/
var imageSelecteur = 'picto_fleche_sous_nav.gif';
function FixePuce(nombre, numero,relativePath,layerName)
{

	for (i=1;i<=nombre;i++) // on commence à l'index 1 par soucis de compatibilté avec le site http://www.total.com
		{
		//var compte=i+1;
		var compte=i;
		//var image = "puce"+layerName+"0"+compte;
		//var lequel = "puce"+layerName+"0"+numero;
		var image = 'puce'+layerName+ndigit(i,2);
		var lequel = 'puce'+layerName+ndigit(numero,2);
		//document[image].src = relativePath+"images/shim.gif";
		if(clientIs.dom)
			currentImage = document.getElementById(image);
		else 
			{
			currentImage = document[image];
			//QcurrentImage.src = relativePath+'shim.gif';
			//alert(currentImage.src);
			}
		currentImage.src = relativePath+'shim.gif';
		//alert('doc '+document.getElementById(image)+' '+image);
		//document[image].src = relativePath+'shim.gif';
		}
	//document[lequel].src = relativePath+"images/n_1/nav_haut/"+imageSelecteur;
	//document[lequel].src = relativePath+imageSelecteur;
	currentImage = document.getElementById(lequel);
	//currentImage.src = relativePath+''+imageSelecteur;
	if (HP == "1"){
		currentImage.src = 'media/navtop/'+imageSelecteur;
		}
	else {
		currentImage.src = '../media/navtop/'+imageSelecteur;}
	
	//alert('fin ='+currentImage.src);
}

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.dom) ? '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 || clientIs.ns7)
		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 || clientIs.ns7|| clientIs.safari)
		{
			var imgDoc = findParentDocument(imageName);
			// ns6 et ns7
			if(clientIs.ns6 || clientIs.ns7|| clientIs.safari)
			{
				// 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.dom) ) 
	{
		position.x = img.x;
		position.y = img.y;
	}
	if(clientIs.ns7) {
		position.x = img.x;
		position.y = img.y;
	}
	if(clientIs.ns6 ) {
		position.x = img.offsetLeft;
		position.y = img.offsetTop;
	}
	
	if(clientIs.ns ){
		position.x +=parseInt(layerOffset.x);
		position.y +=parseInt(layerOffset.y);
		
	}
	
	if(clientIs.dom ) {
		var imageObj;
    	position.x = img.offsetLeft;    
		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,y)
{	this.className = "point";
	this.refName=null;
	this.ref=null;
	this.x = 0;
	this.y = 0;

	if (typeof(refName) != "string") 
	{
		this.x = refName;
		this.y = y;		
	}
	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.getPosition = function () {
		//if(!this.refName) return new point(this.x,this.y);
		if(!this.refName) return this;
		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;
		*/
		var a = new Array()
		a.x=0; a.y=0;
		
		if(!this.ref) return a;
		a.x = this.ref.width ;	a.y = this.ref.height;
		return a;
	}
	this.set = function(x,y)
	{
		this.x = x;
		this.y = y;
	}
}

function rect()
{
	this.set = function()
	{
	}
}

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
}
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);
}

/********************************************************************
*                   Open Window                                        *
********************************************************************/

//open window d'ouverture du démonstrateur

function openDemo()
{
theURL = 'demo.htm';
lfeatures = '';
lfeatures += 'toolbar=0,';
lfeatures += 'Location=0,';
lfeatures += 'directory=0,';
lfeatures += 'status=0,';
lfeatures += 'menubar=0,';
lfeatures += 'scrollbars=0,';
lfeatures += 'resizable=0,';
lfeatures += 'width=1000,';
lfeatures += 'height=700';
winName="";
winId = window.open(theURL,winName,lfeatures);
}

function contact ()
{
window.opener.location="pluriel_contact.htm";
window.opener.focus();
}
