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=" + escape(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 retour = true;
	if (lnks.li[i]) retour = lnks.li[i].oc();

	var img = new Image();
		
	lien = 'isens_marker.php?externe=1&version=' + version + '&page=' + escape(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;

	return retour;
}

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)
					{
						lnks.li[i] = document.links[i];
						lnks.li[i].oc = document.links[i].onclick;
					}
					eval("document.links[i].onclick=function(){return 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()
{
	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 = unescape(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);