function fsubmit(form_name) {
	document.forms[form_name].submit();
}

function refresh() {
  location.reload(true);
}

function setCook(nom,valeur) {
  document.cookie = nom + "=" + escape(valeur)
  refresh();
}

function getCook(nom) {
	deb = document.cookie.indexOf(nom + "=")
	if (deb >= 0) {
		deb += nom.length + 1
		fin = document.cookie.indexOf(";",deb)
		if (fin < 0) fin = document.cookie.length
			return unescape(document.cookie.substring(deb,fin))
	}
	return ""
}

function loadXML(filename){
	var docXml	= null;
	var fileName = "./lang/"+filename+"_"+getCook("langue")+".xml";
//alert(fileName);
	// Déclaration pour Mozilla
	if(document.implementation && document.implementation.createDocument){
		//docXml = document.implementation.createDocument('', '', null);
		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET", fileName, false);
		xmlhttp.send(null);
		docXml = xmlhttp.responseXML.documentElement;
	}

	// Déclaration pour IE
	else if (window.ActiveXObject){
		docXml = new ActiveXObject("Microsoft.XMLDOM");
		docXml.async = false;
		docXml.load(fileName);
	}

	return docXml;
}

function set_menu(){
	var menuXml = loadXML("menu");
	var menu = menuXml.getElementsByTagName('menu')[0];

	var links = menu.getElementsByTagName('link');
	
	var writtenString 	= "<table width='100%' border='0' cellpadding='0' cellspacing='12'><tr>";	
	
	for(var i = 0 ; i < links.length ; i++){
		var url 	= links[i].getElementsByTagName('url')[0].firstChild.nodeValue;
		var name 	= links[i].getElementsByTagName('name')[0].firstChild.nodeValue;
		writtenString += "<td height='20'>";
		writtenString += "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		writtenString += "<tr>";
		writtenString += "<td width='16' height='20'><img src='images/gauche.png' alt='' width='16' height='20' /></td>";
		writtenString += "<td height='20' background='images/milieu.png' class='rubriques'><a href=\"" + url + "\">" + name  + "</a></td>";
		if((document.getElementById('new_info') != null && url == 'news.php') || (document.getElementById('new_forum_msg') != null && url == 'forum.php'))
			writtenString += "<td width='17' height='20' background='images/droit.png'><img src='images/clignotant.gif'/></td>";
		else
			writtenString += "<td width='17' height='20' background='images/droit.png'></td>";
		writtenString += "</tr>";
		writtenString += "</table>";
		writtenString += "</td>";
	}
	
	writtenString += "</tr>";
	writtenString += "</table>";
	
	document.getElementById("write_menu").innerHTML = writtenString;
	
	if(document.getElementById('write_connect') != null) {
		document.getElementById("write_id").innerHTML 			= menuXml.getElementsByTagName('id')[0].firstChild.nodeValue;
		document.getElementById("write_pass").innerHTML 		= menuXml.getElementsByTagName('pass')[0].firstChild.nodeValue;
		document.getElementById("write_connect").innerHTML 		= "<input type='submit' value='"+menuXml.getElementsByTagName('connect')[0].firstChild.nodeValue+"'>";
		document.getElementById("write_inscription").innerHTML 	= menuXml.getElementsByTagName('inscription')[0].firstChild.nodeValue;
	}else if(document.getElementById('write_disconnect') != null){
		document.getElementById("write_disconnect").innerHTML 	= "<input type='submit' value='"+menuXml.getElementsByTagName('disconnect')[0].firstChild.nodeValue+"'>";
		if(document.getElementById('write_administration') != null)
			document.getElementById("write_administration").innerHTML 	= menuXml.getElementsByTagName('administration')[0].firstChild.nodeValue;
	}
	
	if(document.getElementById('write_contact') != null)
		document.getElementById("write_contact").innerHTML = menuXml.getElementsByTagName('contact')[0].firstChild.nodeValue;
}

function set_inscription(){
	var inscriptionXml 	= loadXML("inscription");

	document.getElementById("write_recordinfos").innerHTML 		= inscriptionXml.getElementsByTagName('recordinfos')[0].firstChild.nodeValue;
	document.getElementById("write_login").innerHTML 			= inscriptionXml.getElementsByTagName('login')[0].firstChild.nodeValue;
	document.getElementById("write_name").innerHTML 			= inscriptionXml.getElementsByTagName('name')[0].firstChild.nodeValue;
	document.getElementById("write_surname").innerHTML 			= inscriptionXml.getElementsByTagName('surname')[0].firstChild.nodeValue;
	document.getElementById("write_password").innerHTML 		= inscriptionXml.getElementsByTagName('password')[0].firstChild.nodeValue;
	document.getElementById("write_password2").innerHTML 		= inscriptionXml.getElementsByTagName('password2')[0].firstChild.nodeValue;
	document.getElementById("write_mail").innerHTML 			= inscriptionXml.getElementsByTagName('mail')[0].firstChild.nodeValue;
	document.getElementById("write_country").innerHTML 			= inscriptionXml.getElementsByTagName('country')[0].firstChild.nodeValue;
	document.getElementById("write_phone").innerHTML 			= inscriptionXml.getElementsByTagName('phone')[0].firstChild.nodeValue;
	document.getElementById("write_occupation").innerHTML 		= inscriptionXml.getElementsByTagName('occupation')[0].firstChild.nodeValue;
	document.getElementById("write_createaccount").innerHTML 	= inscriptionXml.getElementsByTagName('createaccount')[0].firstChild.nodeValue;
}

function set_zone(){
	var paysXml 		= loadXML("zone_pays");
	var list 			= paysXml.getElementsByTagName('list')[0];
	var pays 			= list.getElementsByTagName('pays');
	
	var writtenString 	= "";
	
	for(var i = 0 ; i < pays.length ; i++){
		writtenString += "<a href=sponsor.php?code="+ pays[i].getElementsByTagName('code')[0].firstChild.nodeValue +">"+ pays[i].getElementsByTagName('name')[0].firstChild.nodeValue+"</a>";
		if(i < pays.length-1)
			writtenString += " - ";
	}

	document.getElementById("write_p1").innerHTML 	= paysXml.getElementsByTagName('p1')[0].firstChild.nodeValue;
	document.getElementById("write_p2").innerHTML 	= paysXml.getElementsByTagName('p2')[0].firstChild.nodeValue;
	document.getElementById("write_zone").innerHTML = writtenString;
}

function set_need_inscription(){
	var newsXml = loadXML("news");	
	document.getElementById("write_notloggedmsg_l1").innerHTML 	= newsXml.getElementsByTagName('notloggedmsg_l1')[0].firstChild.nodeValue;
	document.getElementById("write_notloggedmsg_l2").innerHTML 	= newsXml.getElementsByTagName('notloggedmsg_l2')[0].firstChild.nodeValue;
	document.getElementById("write_inscription_news").innerHTML = newsXml.getElementsByTagName('inscription')[0].firstChild.nodeValue;
}

function load_interface(){	
	setTimeout("set_menu();", 60);
	if(document.getElementById('inscription-form') != null)
		setTimeout("set_inscription();", 60);
	else if(document.getElementById('write_zone') != null)
		setTimeout("set_zone();", 60);
	else if(document.getElementById('need_inscription') != null)
		setTimeout("set_need_inscription();", 60);
};

FuncOL = new Array(); 
function StkFunc(Obj) { 
    FuncOL[FuncOL.length] = Obj; 
} 

window.onload = function() { 
    for(i=0; i<FuncOL.length; i++){
		FuncOL[i]();
	}
}

StkFunc(load_interface);

