function largeur_fenetre()
{
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}

function hauteur_fenetre()
{
	if (window.innerHeight) return window.innerHeight;
	else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
	else return 0;
}

function popup(page,tx,ty,nom_fenetre,barre_status,barre_outils,barre_scroll)
{
	x = parseInt((screen.availWidth - tx) / 2);
	y = parseInt((screen.availHeight - ty) / 2);
	
	window.open(page,nom_fenetre,"status=" + barre_status + ",toolbar=" + barre_outils + ",resizable=1,scrollbars=" + barre_scroll + ",width=" + tx + ",height=" + ty + ",left=" + x  + ",top=" + y);
	return false;
}

function popupFlash(page,tx,ty,nom_fenetre,barre_status,barre_outils,barre_scroll)
{
	popup(page,tx,ty,nom_fenetre,barre_status,barre_outils,barre_scroll);
}

function imprime()
{
	if (window.print) window.print();

	return false;
}

function popPrint(version,id)
{
	tx = 640;
	ty = 400;
	x = parseInt((screen.availWidth - tx) / 2);
	y = parseInt((screen.availHeight - ty) / 2);
	
	var temp = document.location.href;
	var nom_page = temp.substring(temp.lastIndexOf("/")+1,temp.length);

	if (nom_page.indexOf("isens_stats") <  0)
		window.open("isens_print.php?id=" + id + "&lg=" + version + "&page=" + encodeURIComponent(nom_page),"imprimer","status=1,toolbar=0,resizable=1,scrollbars=1,width=" + tx + ",height=" + ty + ",left=" + x  + ",top=" + y);
}

function fermer()
{
	window.close();
}

function domaine(x)
{
	var i=x.host.indexOf(":");
	return (i>=0)?x.host.substring(0,i):x.host;
}

function goLinks(obj,lnks,i)
{
	var img = new Image();
		
	lien = 'isens_marker.php?externe=1&version=' + version + '&page=' + encodeURIComponent(obj.href);
	s = screen;
	lien += '&screen=' + s.width + 'x' + s.height + 'x' + s.colorDepth;
	
	var today = new Date();
	lien += "&time=" + today.getTime();
			
	img.src = lien;
}

function isFileInterne(lien, domaine_interne)
{
	if ((lien.indexOf(domaine_interne) > 0) && (lien.indexOf("/files/") > 0)) return true;
	else return false;
}

function doLinks()
{
	temp = document.location.href;
	if (temp.indexOf("isens_stats.php") < 0)
	{
		lnks = new Object();
		var ln = document.links.length;
		lnks.li = new Array(ln);
		var domaine_courant = domaine(location);
		for (var i=0; i<ln; i++)
		{
			var buff = document.links[i] + "";
			if ((buff.indexOf("javascript:") == -1) && (document.links[i] != "#"))
			{
				if ((domaine_courant != domaine(document.links[i])) || isFileInterne(document.links[i].href, domaine_courant))
				{
					if (document.links[i].onclick == null) eval("document.links[i].onclick=function(){goLinks(this,lnks,i);}");
				}
			}
		}
	}
	
	searchHighlight();
}

function highlightWord(node,word)
{
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			// check if we're inside a "nosearchhi" zone
			checkn = pn;
			while (checkn.nodeType != 9 && 
			checkn.nodeName.toLowerCase() != 'body') { 
			// 9 = top of doc
				if (checkn.className.match(/\bnosearchhi\b/)) { return; }
				checkn = checkn.parentNode;
			}
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function searchHighlight()
{
	var tmp = document.location.href;
	if (tmp.indexOf("&mot=") > 0) return;
	
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++)
	{
		qsip = qsa[i].split('=');
	      if (qsip.length == 1) continue;
        	if (qsip[0] == 'mot')
        	{
			words = decodeURIComponent(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	            for (w=0;w<words.length;w++)
	            {
				highlightWord(document.getElementsByTagName("body")[0],words[w]);
                	}
                	
                	if (typeof(version) == "string")
                	{
                		var img = new Image();
				lien = 'isens_search.php?version=' + version + '&mot=' + words.join();
				img.src = lien;
			}
	        }
	}
}

if (window.addEventListener) window.addEventListener("load", doLinks,false);
else window.attachEvent("onload", doLinks);

function goTo(url)
{
	Window.location = url;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function bullepop(idd,evt){
 
    
 var xfenetre,yfenetre,xpage,ypage,element=null;
 var offset= 20;           // decalage par defaut
 var bulleWidth=200;       // largeur par defaut 
 var hauteur=50;           // hauteur par defaut
 bulleStyle=null;
 
  if (document.layers) {
    bulleStyle=document.layers[idd];
    xpage = evt.pageX ; ypage  = evt.pageY;
    xfenetre = xpage ;yfenetre = ypage ;		
  } else if (document.all) {
    element=document.all[idd]
    xfenetre = evt.x ;yfenetre = evt.y ;
    xpage=xfenetre ; ypage=yfenetre	;	
    if (document.documentElement.scrollLeft) xpage = xfenetre + document.documentElement.scrollLeft ; 
    if (document.documentElement.scrollTop) ypage = yfenetre + document.documentElement.scrollTop;
  } else if (document.getElementById) {
	  element=document.getElementById(idd)
    xfenetre = evt.clientX ; yfenetre = evt.clientY ;
    xpage=xfenetre ; ypage=yfenetre	;	
    if(evt.pageX) xpage = evt.pageX ;
    if(evt.pageY) ypage  = evt.pageY ;
  }
    
  if(element)  bulleStyle=element.style;
		 	
  if(bulleStyle) {
   
     var yp0=ypage;
		 var yf0=yfenetre;
		 

     /* tests incongrus &#710; cause d'Opera5 */
    if(bulleStyle.width) bulleWidth = parseFloat(bulleStyle.width);
     //if(bulleStyle.height) hauteur = parseFloat(bulleStyle.height);

	//alert(parseFloat(bulleStyle.height));
		 
     /* on met la bulle &#710; gauche du pointeur (si c'est possible) 
        et en haut du pointeur si on est assez bas dans l'&#381;cran */
	/*
			
     if (xfenetre > bulleWidth+offset) xpage=xpage-bulleWidth-offset;
     else {
         if (xfenetre >0.5*bulleWidth+offset) xpage=xpage-0.5*bulleWidth-offset;
				 else xpage=xpage+15;}
     if ( yfenetre > hauteur+offset ) ypage=ypage-hauteur-offset
		 else ypage=ypage+offset;
		 */
		/* a cause des debilites d'Opera5 il faut rectifier 'ypage' pour eviter
		   que la bulle ne s'ouvre par-dessus la souris. La bulle s'ouvrira
			 TOUJOURS en bas avec Opera5. Derniere vacherie : il faut faire le test sur
			 bulleStyle.width pour se proteger des distraits qui n'auront pas
			 rempli bulleStyle.height */
			 
		/* if (!bulleStyle.width)	ypage=yfenetre+offset;
		 if(typeof(bulleStyle.left)=='string') {
				 bulleStyle.left=xpage+'px'; bulleStyle.top=ypage+'px';  
		} else {
				bulleStyle.left=xpage     ; bulleStyle.top=ypage ; }
     bulleStyle.visibility="visible"; 
     bulleStyle.zIndex="99";} */

			
		if (xfenetre > bulleWidth+offset) xpage=xpage-bulleWidth-offset;
			 else xpage=xpage+15;
			 if ( yfenetre > hauteur+offset ) ypage=ypage-hauteur-offset;
			 bulleStyle.width=bulleWidth;  
				 if(typeof(bulleStyle.left)=='string') {
						 bulleStyle.left=xpage+'px'; bulleStyle.top=ypage+'px';  
				} else {
						bulleStyle.left=xpage     ; bulleStyle.top=ypage ; }
			 bulleStyle.visibility="visible"; 

	}

}
 
function couic(){
  if(bulleStyle)  bulleStyle.visibility="hidden";
}

function popuporg(url) {

fiche = window.open(url,"fiche","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=566,height=420");
if(navigator.appVersion.indexOf("4") != -1){
            fiche.moveTo(0,0);
        }
}

function popupnews(url) {

fiche = window.open(url,"fiche","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=425");
if(navigator.appVersion.indexOf("4") != -1){
            fiche.moveTo(0,0);
        }
}

function popupnewsmedia(url) {

fiche = window.open(url,"fiche","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=250");
if(navigator.appVersion.indexOf("4") != -1){
            fiche.moveTo(0,0);
        }
}

function popupemail(url) {
	
url=url+'?email='+document.formemail.email.value ;	
fiche = window.open(url,"fiche","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=500");
if(navigator.appVersion.indexOf("4") != -1){
            fiche.moveTo(0,0);
        }
}
