var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function sd_ajax_fcts(var_chemin,var_cible,var_variable)
{
	var xhr = null;
	if(window.XMLHttpRequest)
	   xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
	   try
	   {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
		   try
			{
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			   xmlhttp = false;
			}
		}
	}
	else
	{ // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				leselect = xhr.responseText;
				// On se sert de innerHTML pour rajouter les options a la liste
				if (document.getElementById){
					var element = document.getElementById(var_cible);
				}else if (document.all){
					var element = document.all[var_cible];
				}

				while (element.firstChild) {
				  element.removeChild(element.firstChild);
				}

				var new_el = document.createElement("div");
				new_el.innerHTML = leselect;


				if (document.getElementById)
					{
					//document.getElementById(var_cible).innerHTML = leselect;
					element.appendChild(new_el);
					}
				  else if (document.all)
					{
					//document.all[var_cible].innerHTML = leselect;
					element.appendChild(new_el);
					}
				
				if(BrowserDetect.browser !="Firefox"){
					new_script = element.getElementsByTagName('script');
					if(new_script.length>0){
						for(i=0;i<new_script.length;i++){
							eval(new_script[i].text);
						}
					}
				}
			}
		}

	if (document.getElementById){
	  if(document.getElementById(var_chemin)){
   		chemin = document.getElementById(var_chemin).value;
	  }else{
        chemin = var_chemin;
      }
    }else if (document.all){
	  if(document.all(var_chemin)){
   		chemin = document.all(var_chemin).value;
	  }else{
        chemin = var_chemin;
      }
	}

	xhr.open("POST",var_chemin,true);
	
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(var_variable);
}


function sd_ajax_fcts_element_select(var_chemin,var_cible,var_variable,var_selection)
{
	var xhr = null;
	if(window.XMLHttpRequest)
	   xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
	   try
	   {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
		   try
			{
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			   xmlhttp = false;
			}
		}
	}
	else
	{ // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				leselect = xhr.responseText;
				// On se sert de innerHTML pour rajouter les options a la liste

				if (document.getElementById){
					var element = document.getElementById(var_cible);
				}else if (document.all){
					var element = document.all[var_cible];
				}
				
				
				while (element.firstChild) {
				  element.removeChild(element.firstChild);
				}
				
			
				if(BrowserDetect.browser !="Firefox"){
					//cas ie ^^
					var text_element = element.outerHTML;
						
					element.outerHTML = text_element.substring(0, (text_element.length - 9)) + leselect + "</select>";
				}else{
					element.innerHTML = leselect;
				}
				
				if(var_selection != ""){
					element.value = var_selection;
				}
			//if (var_num){window.ajax_actu(var_num,var_type);}
			}
		}

	xhr.open("POST",var_chemin,true);
	
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(var_variable);
}

function sd_ajax_accueil_fcts(var_chemin,var_cible,var_variable)
{
	var xhr = null;
	if(window.XMLHttpRequest)
	   xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
	   try
	   {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
		   try
			{
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			   xmlhttp = false;
			}
		}
	}
	else
	{ // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				leselect = xhr.responseText;
				// On se sert de innerHTML pour rajouter les options a la liste
				if (document.getElementById){
					var element = document.getElementById(var_cible);
				}else if (document.all){
					var element = document.all[var_cible];
				}

				while (element.firstChild) {
				  element.removeChild(element.firstChild);
				}

				var new_el = document.createElement("div");
				new_el.innerHTML = leselect;


				if (document.getElementById)
					{
					//document.getElementById(var_cible).innerHTML = leselect;
					element.appendChild(new_el);
					}
				  else if (document.all)
					{
					//document.all[var_cible].innerHTML = leselect;
					element.appendChild(new_el);
					}
				
				document.getElementById('image_gau_terms_thematique_'+var_variable).src = base_path+"sites/all/themes/bbasic/images/bord_gau_them_actif.png";
				document.getElementById('image_dr_terms_thematique_'+var_variable).src = base_path+"sites/all/themes/bbasic/images/bord_dr_them_actif.png";
				document.getElementById('lien_terms_thematique_'+var_variable).className= "base_actif";

				if(BrowserDetect.browser !="Firefox"){
					new_script = element.getElementsByTagName('script');
					if(new_script.length>0){
						for(i=0;i<new_script.length;i++){
							eval(new_script[i].text);
						}
					}
				}
			}
		}

	xhr.open("POST",var_chemin,true);
	
	// ne pas oublier ça pour le post
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send('tid='+var_variable);
}

