/*********************************/
/* common.js */
/* GD20050628 */
/********/

/*************************************/
/* DHTML  */
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
}

/* show & display */
function showLayer(id,flag) {
	if (!DHTML) return;
	var x = new getObj(id);
	x.style.visibility = (flag)? 'visible' : 'hidden';
}

function dispLayer(id,flag) {
	if (!DHTML) return;
	var x = new getObj(id);
	x.style.display = (flag)? 'block' : 'none';
}

function ExpandCollaps(id)
{
	if(!DHTML) return;
	var x = new getObj(id);
	var flag = (x.style.display == 'none')? 1 : 0;
	dispLayer(id,flag);
}

/*************************************/
/* Browser detect */

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,thestring;

/* browser */
if(checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if(checkIt('firefox')) browser = "Firefox";
else if(checkIt('camino')) browser = "Camino";
else if(checkIt('safari')) browser = "Safari";
else if(checkIt('omniweb')) browser = "OmniWeb";
else if(checkIt('opera')) browser = "Opera";
else if(checkIt('webtv')) browser = "WebTV";
else if(checkIt('icab')) browser = "iCab";
else if(checkIt('msie')) browser = "IE";
else if(!checkIt('compatible')) {
	browser = "Netscape Navigator";
	version = detect.charAt(8);
}
else browser = "unknown";

/* version */
if(!version) version = detect.charAt(place + thestring.length);

/* OS */
if(!OS) {
	if(checkIt('linux')) OS = "Linux";
	else if(checkIt('x11')) OS = "Unix";
	else if(checkIt('mac')) OS = "Mac";
	else if(checkIt('win')) OS = "Windows";
	else OS = "unknown";
}

/* checkIt */
function checkIt(str) {
	place = detect.indexOf(str) + 1;
	thestring = str;
	return place;
}

/*************************************/

/* matching */
function popup(page) {
	window.open(page, 'matching', 'toolbar=no, location=no, directories=no, status=yes, scrollbars=yes, resizable=no, copyhistory=no, width=580, height=500, left=300, top=50');
}

/* print */
function printR() {
	window.print();
}

/* pixel de presence */
pres_pixel = new Image();
cpt = 0;
function presence()
{
	cpt = Math.floor((Math.random()*10))+cpt;
	pres_pixel.src = '/home/presence.php?cpt='+cpt;
	mach = setTimeout("presence()",60000);
}
setTimeout("presence()",60000);
/* end */

/* affichage sur selftest et signup au niveau de l'ancre */
function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
	while (obj.offsetParent)
	{
		curtop += obj.offsetTop
		obj = obj.offsetParent;
	}
}
else if (obj.y)
	curtop += obj.y;
return curtop;
}

/**** script qui rafraichit la page quand la MatchList est en cours de calcul ****/
function refreshNet(methd, URL) {
	var xhr_object = null;
	if( window.XMLHttpRequest ) { // Firefox
		xhr_object = new XMLHttpRequest();
	} else if( window.ActiveXObject ) { // Internet Explorer
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	} else { // XMLHttpRequest non supporté par le navigateur
		return;
	}
	xhr_object.open(methd, URL, true );
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
			eval( xhr_object.responseText );
		}
	}
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(null);
}
/*********************************/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}