var detect = navigator.userAgent.toLowerCase();
var browser = null ;
var OS,version,total,thestring;

if (checkIt('konqueror'))
{
  browser = "Konqueror";
  OS = "Linux";
}
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 = "Internet Explorer";
else if (!checkIt('compatible')){
  browser = "Netscape Navigator";
  version = detect.charAt(8);
}
else browser = "Unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

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 operating system";
}

function checkIt(string){
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}

function getXhrReturn (){
  if(window.XMLHttpRequest)
     var newxhr = new XMLHttpRequest();
  else if(window.ActiveXObject){
     try {
        var newxhr = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        var newxhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else {
     alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
     var newxhr = false;
  }
  return newxhr;
}

function ajaxEval(url) {
	xhrNew = getXhrReturn();
	xhrNew.onreadystatechange = function(){
		if(xhrNew.readyState == 4 && xhrNew.status == 200){
			str = xhrNew.responseText;
			eval(str);
		}
	}
	xhrNew.open("GET",url,true);
	xhrNew.send(null);
}

function ajaxInner(url,idInner) {
	xhrNew = getXhrReturn();
	xhrNew.onreadystatechange = function(){
		if(xhrNew.readyState == 4 && xhrNew.status == 200){
			str = xhrNew.responseText;
			id2elt(idInner).innerHTML = str;
		}
	}
	xhrNew.open("GET",url,true);
	xhrNew.send(null);
}

function loadSsStruc(){
	idStruct = document.getElementById('structure').value;
	var url = "ajax.inc.php?loadSsStruct=oui&idStructPere="+idStruct;
	ajaxEval(url);
}

function loadAgenda(){
	document.forms['test'].submit();
	//alert(document.getElementById('tytytytytyt').action);
		//.submit();
}
function loadAgendaSe(){
	document.getElementById('test').submit();
}

////////////////////////////////
//// Cadre pop up flottant
////////////////////////////////
function openCadre(urlPage,paramDivCadre){	
	divRepr = document.getElementById(paramDivCadre);
	if (divRepr.style.display != "block"){				
		divRepr.style.display = "block";
		divRepr.style.opacity="";
		divRepr.style.filter="";
	}
	chargementDivFlottant(urlPage ,paramDivCadre);
}

function chargementDivFlottant(url,cadreid){
	clickContenu(cadreid);
	getXhr();
	// On définit ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			//alert(xhr.responseText);
			oContenuMenu = getObjetContenu(cadreid);
			var rep = xhr.responseText.split('££££');
			oContenuMenu.innerHTML = rep[0];
			try{
				eval(rep[1]);
			}catch(e) {
				//
			}
			deroulerContenu(cadreid);
		}		
	}
	xhr.open("GET",url,true);
	xhr.send(null);	
}

function id2Elt(idElt) {
	return document.getElementById(idElt);
}

function ValideLd3(val) {
	Ld2Id=val; //id_commune
	id_liste='3'; //Utilisé dans la fonction ChargeLd() pour identifier la liste déroulante
	var url = 'ajax.inc.php?Ld3='+Ld2Id;
	ajaxEval(url);
}

function ValideLd2(val) {
	Ld2Id=val;
	var url = 'ajax.inc.php?Ld2='+Ld2Id;
	ajaxEval(url);

}

/*
function on_submit(){	
	//test des champs textes
	if(!teste_champ_text()){
		alert('Champ obligatoire (*)');
		return false;
	}
	
	return true;
}*/

function teste_champ_text(){
	var dfrm=document.frmMembre;
	var b=false;
	if(dfrm.nomText.value.length>0 && dfrm.mailText.value.length>0 && dfrm.fonctionText.value.length>0)
		b=true;
	return b;
}

/*
function insertContact(){
	if(on_submit())
		fermer('cadre_cadreMembre');
}*/
// ajout Fonctionnalités survol des images dans le volet 2.

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//Permet de choisir la borne ou la structure
function change_type_association()
{
	document.location.href='index.php?main=admin&adminPre=modif_utilisateur&modif=1&type_association='+document.getElementById("type_association").value;
}

//Permet de choisir la borne ou la structure pour l'ajout d'un utlisateur
function change_type_association2()
{
	document.location.href='index.php?main=admin&adminPre=ajout_utilisateur&type_association='+document.getElementById("type_association").value;
}

function modif_profil()
{
		document.location.href='index.php?main=admin&adminPre=modif_utilisateur&modif=1&type_association='+document.getElementById("type_association").value+"&profil="+document.getElementById("profil").value;

}

function modif_profil2()
{
		document.location.href='index.php?main=admin&adminPre=ajout_utilisateur&type_association='+document.getElementById("type_association").value+"&profil="+document.getElementById("profil").value;

}

