var agent = navigator.userAgent.toLowerCase();
var is_ie = (agent.indexOf('msie') != -1);
var is_ie5 = (agent.indexOf('msie 5') != -1);

/*
 * 0.0619
 */

function journal_admin(news_id) {
}

function isadmin(news_id) {
	
}

function isadmintips(tips_id) {
	
}

function forums_admin(news_id) {
}

function tracker_admin(tracker_id) {
	
}

function display_authbox() {
}
var isidentified = 0;
var istoolbar = 0;
var is_admin = 0;
var is_moderator=0;
function users_arrows(name,spanid) {
	if (isidentified == 1 && window.btoa) {
		var newname = window.btoa(name);

		document.write('<span class="move-box">');
		document.write('<a onmouseout="window.status=\'\'; return true;" onmouseover="window.status=\'Monter cette boite\'; return true;" href="/users/changebox,1,'+newname+'.html"><img src="/images/box-up.png" alt="/\" title="Monter cette boite"/></a> ');
		document.write('<a onmouseout="window.status=\'\'; return true;" onmouseover="window.status=\'Descendre cette boite\'; return true;" href="/users/changebox,2,'+newname+'.html"><img src="/images/box-down.png" alt="\/" title="Descendre cette boite"/></a> ');
		document.write('<a onmouseout="window.status=\'\'; return true;" onmouseover="window.status=\'Fermer cette boite\'; return true;" href="/users/changebox,3,'+newname+'.html"><img src="/images/box-drop.png" alt="X" title="Fermer cette boite"/></a>');
		document.write('</span>');
	}
}

function create_account_print() {
	if (isidentified == 1) {
		document.write('<a href="/close_session.html">déconnexion</a> | ');
	} else {
		document.write('<a href="/user_new.html">créer un compte</a> | ');
	}
}

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;
	if (is_ie) {
		var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
		try {
			xmlhttp = new ActiveXObject(control);
			xmlhttp.onreadystatechange = handler;
		} catch(e) {
			alert("You need to enable active scripting and activeX controls");
		}
	} else {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onload = handler;
		xmlhttp.onerror = handler;
	}
	return xmlhttp;
}
function DummyHandler() { }

function XmlHttpGET(xmlhttp, url) {
	xmlhttp.open('GET', url, true);
	xmlhttp.send(null);
}
function SendRequest(url) {
	var xmlhttp = CreateXmlHttpReq(DummyHandler);
	XmlHttpGET(xmlhttp, url);
}


function fermeraide(req) {
	if (document.getElementById('aide'))
		document.getElementById('aide').style.display="none";
	if (document.getElementById('aidehidden'))
		document.getElementById('aidehidden').style.display="block";
	if (document.getElementById('login')) {
		document.getElementById('login').style.display="none";
		document.getElementById('login').style.display="block";
	}
	if (req != 1) 
		SendRequest("/users/fermeraide,1.html");
}
function ouvriraide(req) {
	if (document.getElementById('aide'))
		document.getElementById('aide').style.display="block";
	if (document.getElementById('aidehidden'))
		document.getElementById('aidehidden').style.display="none";
	if (document.getElementById('login')) {
		document.getElementById('login').style.display="none";
		document.getElementById('login').style.display="block";
	}
	if (req != 1) 
		SendRequest("/users/fermeraide,0.html");
}

function notercomment(elmt, comid,type) {
	elmt.parentNode.style.display="none";
	SendRequest('/score,'+comid+','+type+',.html');
}

function noaide(req) {
	if (document.getElementById('aidehidden'))
		document.getElementById('aidehidden').style.display="none";
	if (document.getElementById('aide'))
		document.getElementById('aide').style.display="none";
	if (document.getElementById('login')) {
		document.getElementById('login').style.display="none";
		document.getElementById('login').style.display="block";
	}
}

function nosignature() {
	var head = document.getElementsByTagName('head').item(0);
	var link = 0;

	link = document.createElement('style');
	link.setAttribute('type', 'text/css');
	link.innerHTML = "div.signature{ display: none; }";
	link.textContent= "div.signature{ display: none; }";

	head.appendChild(link)
}
if (!window.Node) { // Guess for who ? IE !
	var Node = {        // If there is no Node object, define one
	ELEMENT_NODE: 1,    // with the following properties and values.
	ATTRIBUTE_NODE: 2,  // Note that these are HTML node types only.
	TEXT_NODE: 3,       // For XML-specific nodes, you need to add
	COMMENT_NODE: 8,    // other constants here.
	DOCUMENT_NODE: 9,
	DOCUMENT_FRAGMENT_NODE: 11
	}
}

if (document.evaluate) {
  // version originale par NoNo https://trollfr.org/tracker/560.html
	function getElementsByClass(seed, needle) {
		var results = [];
		var query = document.evaluate('.//*[@class = "' + needle + '"]', seed.parentNode,
			null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		for (var i = 0, length = query.snapshotLength; i < length; i++) {
			results.push(query.snapshotItem(i));
		}
		return results;
	}
} else {
	// version originale par daniel glazman - www.glazman.org
	function getElementsByClass(seed, needle) {
		var outArray = new Array();
	
		function _GetElementsByClass(outArray, seed, needle) {
			while (seed) {
				if (seed.nodeType == Node.ELEMENT_NODE) {
					if (seed.className) {
						var c = " " + seed.className + " ";
						
						if (c.indexOf(" " + needle + " ") != -1)
						outArray.push(seed);
					}
					_GetElementsByClass(outArray, seed.firstChild, needle);
				}
				seed = seed.nextSibling;
			}
		}
		_GetElementsByClass(outArray, seed, needle);
		return (outArray);
	}
}

function loadContent(file){
	var head = document.getElementsByTagName('head').item(0)
	var scriptTag = document.getElementById('loadScript');
	if(scriptTag) head.removeChild(scriptTag);
	script = document.createElement('script');
	script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}

function blabla() {
	eval("display_isnew();");
}

function debut() {

	if (isidentified) {
		fermeraide(1);

		var array = getElementsByClass(document.documentElement, "isnew");
		var string=new Array();
		for (var i=0; i< array.length; i++) {
			var tmp = array[i].id.indexOf(':');
			var tmp2 = array[i].id.lastIndexOf(':');
			var newsid = parseInt(array[i].id.substr(tmp+1,tmp2-(tmp+1)));
			var restype = array[i].id.substr(tmp2+1);
			if (string[restype] == undefined) {
				string[restype] = new Array();
				string[restype][0] = newsid;
				string[restype][1] = newsid;
			} else {
				if (newsid > string[restype][0])
					string[restype][0] = newsid;
				if (newsid < string[restype][1])
					string[restype][1] = newsid;
			}
		}
		var finalestring='';
		if (array.length > 0) {
			for (var i=0; i< string.length; i++) {
				if (string[i] != undefined) {
					finalestring += ';'+i+':'+string[i][0]+':'+string[i][1];
				}
			}
			loadContent('/js/isnew,'+finalestring+',.js');
		}

	} else {
		noaide();
	}

	if (document.forms['formulaire'] && 
			document.forms['formulaire'].login) {
	//	document.forms['formulaire'].login.focus();

		if (getcookie("login",'Login') != "Login") {
			document.forms['formulaire'].login.value = getcookie("login",'Login');
			document.getElementById('logindelete').style.display="block";
			document.forms['formulaire'].passwd.focus();
		}
	}
	if (window.comments_focus) 
		comments_focus();

}

function logindelete() {
	var cookie = "login" + "=" + escape("Login");
	var expire = new Date();
	var today = new Date();
	expire.setTime(today.getTime()-1000);
	cookie += "; expires=" + expire.toGMTString();
	cookie += "; path=/";
	document.cookie = cookie;
	if (document.forms['formulaire'] && document.forms['formulaire'].login) {
		document.forms['formulaire'].login.value = "Login";
	}
	document.getElementById('logindelete').style.display="none";
}

function https_infos() {
	if (location.protocol == "http:") {
		document.write('<a href="https://'+location.hostname+location.pathname+'">accès sécurisé/SSL</a>');
	} else if(location.protocol == "https:") {
		document.write('<a href="http://'+location.hostname+location.pathname+'">accès non sécurisé</a>');
	}
}

function https_warning() {
	if (location.protocol == "http:") {
	} else {
		document.write('Vous êtes connecté en SSL.');
	}
}

function https_icon() {
}
function getcookie(name, defaultvalue)
{
	name += "=";
	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(name);
		if (offset != -1)
		{
			offset += name.length;
			end = document.cookie.indexOf(";", offset) 
			return unescape(document.cookie.substring(offset, (end != -1) ? end : document.cookie.length));
		}
	}
	return (defaultvalue);
}
function display_envoyermessageperso(login,homesite) {
	if (isidentified == 1 && window.btoa) {
		var recipient = window.btoa(login);
		if (homesite == 1) {
			document.write(', ');
			document.write('<a href="/users/messages,'+ recipient +',.html">envoyer un message privé</a>');
		} else {
			document.write(' (<a href="/users/messages,'+ recipient +',.html">envoyer un message privé</a>)');
		}
	}
	
}


