/*************************************************************************
  Fonctions génériques utilisées dans le site internet
  Harrison & Wolf
  version : 3.3
  Date de modification : 08/12/05
*************************************************************************/


function sniffer() 
{

    var agent = navigator.userAgent.toLowerCase();
	//alert(agent);
    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 = 'fleche_nav_gauche1.gif';

function FixePuce(nombre, numero,relativePath,layerName, imgSrc)
{

	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];
			}
		currentImage.src = 'http://www.naftogaz-algeria.com/images/spacer.gif';
		}

	currentImage = document.getElementById(lequel);
	//currentImage.src = relativePath+"images/haut/commun/picto_fleche_sous_nav_bleu.gif";

	currentImage.src = relativePath+imgSrc;

}

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(!(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 MM_)         *
************************************************************************************************************/

function MM_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=MM_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 MM_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 MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_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];
	 
	 }
	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=MM_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 = MM_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 = MM_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 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;
}
function onsubmitCheckSimpleFormRecherche(nomFormulaire,langue)
{

        error = checkFormRecherche(nomFormulaire,langue);

        if(error!=true)
                return false;

        return true;
}
function checkFormRecherche(nomFormulaire,langue)
{
                var msgError = new Array();

        // définition des messages d'erreur;
        if(langue=="en")
        {
                msgError[0] = "Please type the text of your search.";
        }
        else
        {
                msgError[0] = "Veuillez saisir le texte à rechercher.";
        }


        formObj = eval("document."+nomFormulaire);

        if(formObj.texterecherche.value=="")
        {
                alert(msgError[0]);
                return false;
        }

        formObj.submit();
        return true;
}
/********************************************************************
*                   Tableaux                                        *
********************************************************************/
function getArrayPos(arrayToSearch,itemToFind)
{
        var found;
        for(var i=0;i<arrayToSearch.length;i++)
                if(arrayToSearch[i]==itemToFind) return i;

        return -1;
}

function openSendTo(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=450,';
lAttributes += 'height=422';
winId = window.open(URL,'',lAttributes);
}

function openBourseGL(URL)
{
lAttributes = '';
lAttributes += 'toolbar=0,';
lAttributes += 'Location=0,';
lAttributes += 'directory=0,';
lAttributes += 'status=0,';
lAttributes += 'menubar=0,';
lAttributes += 'scrollbars=1,';
lAttributes += 'resizable=0,';
lAttributes += 'width=582,';
lAttributes += 'height=422';
winId = window.open(URL,'',lAttributes);
}

function openMag(langue,URL)
{
//path = 'http://129.35.162.71/energies/';
path = '/energies/';
if (!URL) 
{
URL = '/energies/' + langue;
}
else
{
URL = path+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=780,';
lAttributes += 'height=532';
winId = window.open(URL,'',lAttributes);
}

function openMagSom(langue)
{
//var URL = 'http://129.35.162.76/energies/allissues/'+langue+'/tousnumeros.htm';
var URL = '/energies/allissues/'+langue+'/tousnumeros.htm';
lAttributes = '';
lAttributes += 'toolbar=0,';
lAttributes += 'Location=0,';
lAttributes += 'directory=0,';
lAttributes += 'status=0,';
lAttributes += 'menubar=0,';
lAttributes += 'scrollbars=1,';
lAttributes += 'resizable=0,';
lAttributes += 'width=420,';
lAttributes += 'height=400';
winId = window.open(URL,'',lAttributes);
}
function openWin(URL,w,h,resize,scroll,windowName)
{
lAttributes = '';
lAttributes += 'toolbar=0,';
lAttributes += 'Location=0,';
lAttributes += 'directory=0,';
lAttributes += 'status=0,';
lAttributes += 'menubar=0,';
lAttributes += 'scrollbars='+scroll+',';
lAttributes += 'resizable='+resize+',';
lAttributes += 'width='+w+',';
lAttributes += 'height='+h+'';
if(!windowName) windowName="";
winId = window.open(URL,windowName,lAttributes);
}

//17/06/2005 ajout fonction sur demande de M. MARTIN

function openRapport(page) {
var yes = 1;
var no = 0;
file = page
var menubar = no;      
var scrollbars = no;  
var locationbar = no;  
var directories = no; 
var resizable = yes;   
var statusbar = no;  
var toolbar = no;
windowprops = "width=" + (800) + ",height=" + (screen.height-50) + ",top=10,left=0";
windowprops += (menubar ? ",menubars" : "") +
(scrollbars ? ",scrollbars" : "") +
(locationbar ? ",location" : "") +
(directories ? ",directories" : "") +
(resizable ? ",resizable" : "") +
(statusbar ? ",status" : "") +
(toolbar ? ",toolbar" : "");
window.open(file, "", windowprops);

}

//06/09/2005 ajout de fonction a la demande de Valerie Sorrel
function xt_clic(typecl,site,section,page,url,nvlle)
{
Xt_r = document.referrer;
Xt_h = new Date();
xt_img = new Image();
Xt_i = 'http://logp.xiti.com/hit.xiti?s='+site+'&s2='+section;
Xt_i += '&p='+page+'&clic='+typecl+'&hl=' + Xt_h.getHours() + 'x' + Xt_h.getMinutes() + 'x' +
Xt_h.getSeconds();
if(parseFloat(navigator.appVersion)>=4)
{Xiti_s=screen;Xt_i += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' +
Xiti_s.colorDepth;}
Xt_i += '&ref=' + Xt_r.replace(/[<>"]/g, '').replace(/&/g, '$');
xt_img.src = Xt_i;
if ((url != null)&&(url!=undefined))
{ if ((nvlle=='')||(nvlle==null)) { document.location = url;} else {xfen =
window.open(url,'xfen',''); xfen.focus();}}
else
{return;}
}

function formcheck(layerName)
{
alert(layerName);
document.getElementById("formdiv").style.visibility='hidden';
}
