/////////////////////////////////////////////
//           Créé Par Eric ROUSSEL         //
//           Pour la société Atoo          //
//    Stage du 16 avril au 22 juin 2007    //
/////////////////////////////////////////////



function getXhr(){
	  var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest(); 
	else 
		if(window.ActiveXObject)
		{ // Internet Explorer 
			try 
			{
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			    xhr = new ActiveXObject("Microsoft.XMLHTTP");
			   }
		}
		else 
			{ // XMLHttpRequest non supporté par le navigateur 
				alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhr = false; 
			} 
   return xhr
}

			
		function go(idsite,nom,lg,ref,typObj,idObj){
				var xhr = getXhr();
				// 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
						//document.getElementById('stat').innerHTML = leselect;
					}
				}
					var toto=navigator.userAgent;
					toto1=screen.width+'x'+screen.height;
					toto2=screen.availWidth+'x'+screen.availHeight;
					toto3=ref;
					toto4=document.URL;
					toto5=window.location.host;
					while(toto3.indexOf('&')!=-1)
						toto3=toto3.replace('&','$');
					while(toto4.indexOf('&')!=-1)
						toto4=toto4.replace('&','$');
				// Ici on va voir comment faire du post
				xhr.open("POST",'/atooentreprise/ajoutStat.php',true);
				// ne pas oublier ça pour le post
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				// ne pas oublier de poster les arguments
				// ici, le nom du navigateur et le nom du sytème d'exploitation
				navigClient=navigateur1(toto);
				osClient=OS(toto);
				typeMateriel=Materiel(toto);
				cookies=LireCookie("connectionAtoo");
				xhr.send("cookies="+cookies+"&idsite="+idsite+"&nom="+nom+"&lg="+lg+"&navig="+navigClient+"&os="+osClient+"&screen="+toto1+"&screen1="+toto2+"&ref="+toto3+"&pageC="+toto4+"&serveur="+toto5+"&materiel="+typeMateriel+"&typeObj="+typObj+"&idObj="+idObj);
			
			}
			
			
			

function navigateur1(toto){
if((tmp=toto.indexOf('Firefox', 0))!=-1)
		return ("Firefox " + toto.substr(tmp+8,7));
	else
		if((tmp=toto.indexOf('Opera', 0))!=-1)
			return ("Opera "+ toto.substr(tmp+6,4));
		else
			if((tmp=toto.indexOf('Konqueror',0))!=-1)
				return ("Konqueror "+toto.substr(tmp+10,3));
			else
				if((tmp=toto.indexOf('Safari',0))!=-1)
					return ("Safari");
				else
					if((tmp=toto.indexOf('MSIE',0))!=-1)
						return ("Internet Explorer "+toto.substr(tmp+5,3));
					else
						if((tmp=toto.indexOf('Netscape',0))!=-1)
							return ("Netscape "+toto.substr(tmp+9,3));
						else
							if((tmp=toto.indexOf('Camino',0))!=-1)
								return ("Camino "+toto.substr(tmp+7,5));
							else
								return (navigator.appCodeName);
}


function OS(toto){
	
//Pour les Systèmes Windows
if((tmp=toto.indexOf('Windows',0))!=-1)
{
	if(((tmp=toto.indexOf('Windows NT 5.1',0))!=-1) || ((tmp=toto.indexOf('Windows XP',0))!=-1))
		return ("Windows Xp");
	else
		if((tmp=toto.indexOf('Windows NT 6.0',0))!=-1)
			return ("Windows Vista");
		else
			if((tmp=toto.indexOf('Win 9x',0))!=-1)
				return ("Windows Me");
			else
				if(((tmp=toto.indexOf('Windows 98',0))!=-1) || ((tmp=toto.indexOf('Win98',0))!=-1))
					return ("Windows 98");
				else
					if(((tmp=toto.indexOf('Windows 95',0))!=-1) || ((tmp=toto.indexOf('Win95',0))!=-1))
						return ("Windows 95");
					else
						if((tmp=toto.indexOf('Windows NT 5.0',0))!=-1)
							return ("Windows 2000");
						else
							if((tmp=toto.indexOf('Windows NT',0))!=-1)
								return ("Windows NT");
							else 
								if((tmp=toto.indexOf('Windows NT 5.2',0))!=-1)
									return ("Windows Server 2003");
								else
									return ("OS Windows");
}
else
	//Pour les Systèmes Linux
	if((tmp=toto.indexOf('Linux',0))!=-1)
	{
		if((tmp=toto.indexOf('Ubuntu',0))!=-1)
			return ("Linux Ubuntu");
		else
			if((tmp=toto.indexOf('Debian',0))!=-1)
				return ("Linux Debian");
			else
				if((tmp=toto.indexOf('Fedora',0))!=-1)
					return ("Linux Fedora");
				else
					if((tmp=toto.indexOf('SUSE',0))!=-1)
						return ("Linux SUSE");
					else
						if((tmp=toto.indexOf('mdk',0))!=-1)
							return ("Linux Mandriva");
						else
							return ("OS Linux");
	}
	else
		// Pour les Systèmes Mac
		{
			if((tmp=toto.indexOf('Mac OS X',0))!=-1)
				return ("Mac OS X");
			else 
				if((tmp=toto.indexOf('Mac',0))!=-1)
					return ("Mac OS 9");
				else // Pour le reste
					return ("Inconnu");
		}
}

function Materiel(toto){
	if((tmp=toto.indexOf('bot',0))!=-1)
	{
		if((tmp=toto.indexOf('Googlebot',0))!=-1)
			return ("Robot Google");
		else
			if((tmp=toto.indexOf('msnbot',0))!=-1)
				return ("Robot msn");
			else
				if((tmp=toto.indexOf('VoilaBot',0))!=-1)
					return ("Robot voilà");
				else
					if((tmp=toto.indexOf('Slurp',0))!=-1)
						return ("Robot Yahoo");
					else
						if((tmp=toto.indexOf('almaden',0))!=-1)
							return ("Robot IBM");
						else
							if((tmp=toto.indexOf('Scooter',0))!=-1)
								return ("Robot Altavista");
							else
								if((tmp=toto.indexOf('Crawler',0))!=-1 || (tmp=toto.indexOf('crawler',0))!=-1)
									return ("Robot Inconnu");
		}
		else
			if((tmp=toto.indexOf('PSP',0))!=-1)
				return("Console PSP");
			else
				if((tmp=toto.indexOf('PLAYSTATION',0))!=-1)
					return("Console Playstation");
				else
					if((tmp=toto.indexOf('Mozilla',0))!=-1)
						return("Ordinateur");
					else
						return ("Portable ou autre");
				
}




function getCookieVal(offset)
{
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen)
{
var j=i+alen;
if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;

}
return null;
}