var ajaxMode;
var ajaxPath;

// ________________________________________ moteur chargement AJAX
//___ url : ulr du fichier XML ou autre à charger
//___ todo : fonction à éxécuter après le chargement
//___ ddiv : contenant

function ajaxLoadXML(url, todo, ddiv) 
{
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
            // Voir la note ci-dessous à propos de cette ligne
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Abandon :( Impossible de créer une instance XMLHTTP');
        return false;
    }
//document.write(ajaxPath+'getXML.php?xml='+url+'&mode='+ajaxMode);
    http_request.open('GET', ajaxPath+'getXML.php?xml='+url+'&mode='+ajaxMode, true);
    //http_request.open('GET', 'getXML.php?xml=rss.xml', true);
    //http_request.open('GET', url , true);
    http_request.onreadystatechange = function() { todo(http_request, ddiv, url); };
    http_request.send(null);
}

// ________________________________________ récupère une valeur de contenu XML
//___ node : noeud courant
//___ path : chemin du tag à récupérer, eg. channel/0/title/0

function xmlData( node, path)
{
	var i, tab, sz, xml;
	tab = path.split('/');
	sz = tab.length;
	xml = node;
	//alert(path);
	for(i=0; i<sz; i+=2)
	{
		if(xml && xml.getElementsByTagName(tab[i])) xml = xml.getElementsByTagName(tab[i]).item(tab[i+1]);
	}
	if(xml.firstChild) return xml.firstChild.data;
	return '';
}

// ________________________________________ récupère un noeud XML
//___ node : noeud courant
//___ path : chemin du tag à récupérer, eg. channel/0/title/0

function xmlNode( node, path)
{
	var i, tab, sz, xml;
	tab = path.split('/');
	sz = tab.length;
	xml = node;
	//alert(path);
	for(i=0; i<sz; i+=2)
	{
		xml = xml.getElementsByTagName(tab[i]).item(tab[i+1]);
	}
	if(xml) return xml;
	return '';
}


// ________________________________________ récupère un attribut de contenu XML
//___ node : noeud courant
//___ path : chemin du tag à récupérer, eg. channel/0/title/0
//___ attr : attribut

function xmlAttr( node, path, attr)
{
	var i, tab, sz, xml;
	tab = path.split('/');
	sz = tab.length;
	xml = node;
	//alert(path);
	for(i=0; i<sz; i+=2)
	{
		xml = xml.getElementsByTagName(tab[i]).item(tab[i+1]);
	}
	if(xml) return xml.getAttribute(attr);
	return '';
}

// ________________________________________ récupère un noeud XML
//___ node : noeud courant
//___ path : chemin du tag à récupérer, eg. channel/0/title/0

function xmlNode( node, path)
{
	var i, tab, sz, xml;
	tab = path.split('/');
	sz = tab.length;
	xml = node;
	for(i=0; i<sz; i+=2)
	{
		if(i+2<sz) xml = xml.getElementsByTagName(tab[i]).item(tab[i+1]);
		else xml = xml.getElementsByTagName(tab[i]);
	}
	if(xml) return xml;
	return null;
}


// ________________________________________________________________________________________________________________
// ________________________________________ manipulation OBJET ET CSS
// ________________________________________________________________________________________________________________

function GL_checkBrowser(){
	this.dom= (document.getElementById);
	this.op=this.opera= (navigator.userAgent.indexOf("Opera")>-1);
	this.konq=  (navigator.userAgent.indexOf("Konq")>-1);
	this.ie4= (document.all && !this.dom && !this.op && !this.konq);
	this.ie5= (document.all && this.dom && !this.op && !this.konq);
	this.ns4= (document.layers && !this.dom && !this.konq);
	this.ns5= (!document.all && this.dom && !this.op && !this.konq);
	this.ns6= (this.ns5);
	this.bw=  (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
	return this;
}
bw= new GL_checkBrowser();

	//Returns css
function GL_getObjCss(obj){								
	return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
};
function jsStyle(obj){								
	return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
};
function jsObj(obj){								
	return bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
};

//___________________________positionne un div par rapport à la souris
function showMouseDiv(div, dX, dY)
{
	jsStyle(div).display = 'block';
	//alert(posX);
	jsStyle(div).top = (tempY+dY)+'px';
	jsStyle(div).left = (tempX+dX)+'px';
	/*if(tempX<850)
	{
		jsStyle(div).top = (tempY-20)+'px';
		jsStyle(div).left = (tempX+10)+'px';
	}
	else
	{
		jsStyle(div).top = (tempY-20)+'px';
		jsStyle(div).left = (tempX-160)+'px';
	}*/
}

function showDiv(id)
{
	etat = GL_getObjCss(id).display;
	switch(etat)
	{
		case "none": GL_getObjCss(id).display="block"; break;
		case "block": GL_getObjCss(id).display="none"; break;
	}
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft; //document.body.scrollLeft
    tempY = event.clientY + document.documentElement.scrollTop; //document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}

// ________________________________________________________________________________________________________________

// __________________GESTION DES COOKIES

function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	
	}
	return null;
}

// ______________________ QueryString

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}
var q_GET = new Querystring(window.location.search.substring(1));

// _________________________________ parse du path

function parsePath(url)
{
	var http = url.split('/');
	var parsePath = new Array();
	var p;
	parsePath[0] = '';
	parsePath[1] = http[http.length-1];
	for(p=0; p<http.length-1; p++)
	{
		parsePath[0] += http[p]+'/';
	}
	return parsePath;
}
