var xmlHttpRequest_HelpCompte = getXmlHttpRequest();


if(xmlHttpRequest_HelpCompte){
	
	xmlHttpRequest_HelpCompte.onreadystatechange = function(){

		if(xmlHttpRequest_HelpCompte.readyState == 4){

			if(xmlHttpRequest_HelpCompte.status == 200){
				var links = document.getElementsByTagName("a");
				for(i = 0; i < links.length - 1; i++){
					if(links.item(i).href && links.item(i).getAttribute("href").search("aide") != -1){
						anchor = links.item(i).getAttribute("href").split("#")[1];
						if(anchor) {
							foobar(xmlHttpRequest_HelpCompte, anchor, links.item(i));
						} else {
						}
					}
				}
			}
		}
	}  
}


/********************/
window.onload = function(){

	var i;
	var links  = document.getElementsByTagName("a");

	// Boucle sur les liens
	for(i = 0; i < links.length - 1; i++){
		// Lien poitant sur l'aide
		if(links.item(i).href && links.item(i).getAttribute("href").search("/aide/") != -1){
			if(xmlHttpRequest_HelpCompte.readyState == 0){
				url = window.location.href;
				if(url.lastIndexOf("64mc.com")!=-1 || url.lastIndexOf("www.64mc.com")!=-1 ) newurl = "http://www.64mc.com";
				else if(url.lastIndexOf("jepariesports.fr")!=-1 || url.lastIndexOf("www.jepariesports.fr")!=-1 ) newurl = "http://www.jepariesports.fr";
				else if(url.lastIndexOf("jepariefoot.fr")!=-1 || url.lastIndexOf("www.jepariefoot.fr")!=-1 ) newurl = "http://www.jepariefoot.fr";
				else if(url.lastIndexOf("jeparierugby.fr")!=-1 || url.lastIndexOf("www.jeparierugby.fr")!=-1 ) newurl = "http://www.jeparierugby.fr";
				else if(url.lastIndexOf("tournoides6nations.fr")!=-1 || url.lastIndexOf("www.tournoides6nations.fr")!=-1 ) newurl = "http://www.tournoides6nations.fr";
				else if(url.lastIndexOf("64matchs.fr")!=-1 || url.lastIndexOf("www.64matchs.fr")!=-1 ) newurl = "http://www.64matchs.fr";
				else if(url.lastIndexOf("64matchs.com")!=-1 || url.lastIndexOf("www.64matchs.com")!=-1 ) newurl = "http://www.64matchs.com";
				else if(url.lastIndexOf("coupedumondefifa.fr")!=-1 || url.lastIndexOf("www.coupedumondefifa.fr")!=-1 ) newurl = "http://www.coupedumondefifa.fr";
				else newurl = "http://www.64matchschrono.com";
				xmlHttpRequest_HelpCompte.open("GET", newurl+"/aide/", true);
				xmlHttpRequest_HelpCompte.setRequestHeader("User-Agent", "64matchschrono");
				xmlHttpRequest_HelpCompte.send(null);
			}
		}
	} 
}

/********************/
function foobar(request, anchor, link){
	var i;
	var div = document.createElement("div");
	var button = document.createElement("button");
	var tmp = document.createElement("div");

	tmp.innerHTML = request.responseText;
	for(i = 0; i < tmp.getElementsByTagName("div").length; i++){
		if(tmp.getElementsByTagName("div")[i].getAttribute("id") == anchor){
			div.appendChild(tmp.getElementsByTagName("div")[i]);
			break;
		}
	}
	
	div.style.display = "none";
	div.style.width = "250px";
	div.style.color = "#000000";
	div.style.border = "1px solid #8CBA42";
	div.style.backgroundColor = "#DAEE96";
	div.style.position = "absolute";
	div.style.zIndex = "10";
	div.style.padding = "1ex";
	div.style.textAlign = "left";
	div.className = "aide";
	        
	button.onclick = function(){
		div.style.display = "none";
	}
	button.appendChild(document.createTextNode("Fermer"));
	//button.style.backgroundColor = "#95C45C";
	button.style.color = "#000000";
	//button.style.border = "0 solid #8CBA42";
	button.style.margin = "2px 0 0 0";
	button.style.fontSize = "0.9em";
	button.style.fontWeight = "bold";
		div.appendChild(button);
	
	link.onclick = function(evt){
		var divs  = document.getElementsByTagName("div");
		var j;

		for(j = 0; j < divs.length - 1; j++){
			if(divs.item(j).getAttribute("class") == "aide" && divs.item(j).style.display == "block"){
				divs.item(j).style.display = "none";
			}
		}
          
		div.style.display = "block";
    
		if(evt){
			if(evt.pageX > 300) {
				div.style.left = evt.pageX - 300 + "px";
			} else {
				div.style.left = evt.pageX + "px";
			}
	      
			div.style.top = evt.pageY + "px";
		}else if(typeof(event) != "undefined"){
			if(event.clientX > 300) {
				div.style.left = event.clientX + document.body.scrollLeft - 300 + "px";
			} else {
				div.style.left = event.clientX + document.body.scrollLeft + "px";
			}
 
			if (window.innerHeight){
				div.style.top = window.pageYOffset + event.clientY;
			}else if (document.documentElement && document.documentElement.scrollTop){
				div.style.top = document.documentElement.scrollTop + event.clientY;
			}else if (document.body){
				div.style.top = document.body.scrollTop + event.clientY;
			}
		}
		          
    	return false;
	}
        
	document.body.appendChild(div);
}