var tab_browser=browser_detect();
var platform=os_detect();
tab_browser[0]=tab_browser[0].toLowerCase();
platform[0]=platform[0].toLowerCase();

if(tab_browser[0]=="" || Number(tab_browser[1])<=0 || platform[0]==""){
var c=navigator.userAgent.toLowerCase();
Detect_File('/trace_detect.php','POST','p='+platform+'&b='+tab_browser[0]+'&v='+tab_browser[1]+'&ch='+c);
}
function browser_detect(){
var c=navigator.userAgent.toLowerCase();
var browser="";
var version="";

if(c.indexOf("iemobile")!=-1){
 if(c.indexOf("iemobile/")!=-1){
 version=version_detect(c,"iemobile/",".");
 }
 else{
 version=version_detect(c,"iemobile ",".");
 }
 browser="IE Mobile";
}
else if(c.indexOf("msie")!=-1){
 version=version_detect(c,"msie ",".");
 browser="Microsoft Internet Explorer";
}
else if(c.indexOf("konqueror")!=-1){
 version=version_detect(c,"konqueror/",".");
 browser="Konqueror";
}
else if(c.indexOf("firefox")!=-1){
 if(c.indexOf("navigator")!=-1){
 version=version_detect(c,"navigator/",".");
 browser="Netscape";
 }
 else if(c.indexOf("opera")!=-1){
  version=version_detect(c,"version/",".");
  browser="Opera";
 }
 else{
  version=version_detect(c,"firefox/",".");
  browser="Firefox";
 }
}
else if(c.indexOf("chrome")!=-1){
 version=version_detect(c,"chrome/",".");
 browser="Chrome";
}
else if(c.indexOf("safari")!=-1){
 if(c.indexOf("mobile")!=-1){
 browser="Mobile Safari";
 }
 else{
 browser="Safari"; 
 }
 version=version_detect(c,"version/",".");
}
else if(c.indexOf("opera")!=-1){
 if(c.indexOf("opera mini")!=-1){
 version=version_detect(c,"opera mini/",".");
 browser="Opera Mini";
 }
 else if(c.indexOf("opera mobi")!=-1){
 version=version_detect(c,"version/",".");
 browser="Opera Mobile";
 }
 else{
 browser="Opera";
 if(c.indexOf("version/")!=-1){
 version=version_detect(c,"version/",".");
 }
 else{
 version=version_detect(c,"opera/",".");
 }
 }
}
else if(c.indexOf("netscape")!=-1){
 version=version_detect(c,"netscape/",".");
 browser="Netscape";
}
else if(c.indexOf("playstation")!=-1){
 version=version_detect(c,"playstation ",";");
 browser="Playstation";
}
else if(c.indexOf("midori")!=-1){
 version=version_detect(c,"midori/",".");
 browser="Midori";
}
else if(c.indexOf("gecko")!=-1){
 if(c.indexOf("bonecho")!=-1){
 version=version_detect(c,"bonecho/",".");
 browser="Bonecho";
 }
 else if(c.indexOf("seamonkey")!=-1){
 version=version_detect(c,"seamonkey/",".");
 browser="Seamonkey";
 }
 else if(c.indexOf("browserng")!=-1){
 version=version_detect(c,"version/",".");
 browser="Mobile Browser";
 }
 else if(c.indexOf("iceweasel")!=-1){
 version=version_detect(c,"iceweasel/",".");
 browser="Iceweasel";
 }
 else if(c.indexOf("iceape")!=-1){
 version=version_detect(c,"iceape/",".");
 browser="Iceape";
 }
 else if(c.indexOf("k-meleon")!=-1){
 version=version_detect(c,"k-meleon/",".");
 browser="K-meleon";
 }
 else if(c.indexOf("namoroka")!=-1){
 version=version_detect(c,"namoroka/",".");
 browser="Namoroka";
 }
 else if(c.indexOf("megaupload")!=-1){
 version=version_detect(c,"megaupload/",".");
 browser="Megaupload";
 }
 else if(c.indexOf("iphone")!=-1 && c.indexOf("mobile")!=-1){
 version=version_detect(c,"mobile/",".");
 browser="Iphone Mobile";
 }
 else{
 //version=version_detect(c,"netscape/",".");
 browser="Gecko";
 }
 }
 else if(c.indexOf("blackberry")!=-1){
 version=version_detect(c,"blackberry","");
 browser="Blackberry";
 }


//return(browser+" "+version);
//if(browser=="" || Number(version)<=0){
//Detect_File('/trace_detect.php','POST','b='+browser+'&v='+version+'&ch='+c);
return(new Array(browser,version));
//}
}

function version_detect(c,c1,c2){
c=c.substring(c.indexOf(c1));
return(c.substring(c1.length,c.indexOf(c2)));
}

function os_detect(){
var c=navigator.userAgent.toLowerCase();
var system="";var platform="";
var tab_system=new Array("windows","linux","midp","mac");
var tab_other=new Array();
tab_other["blackberry"]="Blackberry";
tab_other["java"]="java";
tab_other["cfnetwork"]="CFNetwork";
tab_other["freebsd"]="FreeBSD";
tab_other["symbianos"]="SymbianOS mobile";
tab_other["sunos"]="SunOs";
tab_other["playstation"]="PlayStation";
tab_other["gnash"]="Gnash";
//tab_other["quicktime"]="QuickTime";
//tab_other["lynx"]="lynx";
tab_other["webtv"]="webtv";
tab_other["Wii"]="Wii";
tab_other["nintendo"]="Nintendo";
tab_other["snappreviewbot"]="Snappreviewbot";
//tab_other["SnapPreviewBot"]="SnapPreviewBot";

var tab_win=new Array();
tab_win["windows mobile"]="Windows Mobile";
tab_win["windows 7"]="Windows 7";
tab_win["nt 6.1"]="Windows 7";
tab_win["windows Vista"]="Windows Vista";
tab_win["nt 6.0"]="Windows Vista";
tab_win["nt 5.2"]="Windows Xp 64 / Server 2003";
tab_win["nt 5.1"]="Windows Xp";
tab_win["nt 5.01"]="Windows 2000 sp1";
tab_win["nt 5.0"]="Windows 2000";
tab_win["nt 4.0"]="Windows nt";
tab_win["win 9x 4.90"]="Windows me";
tab_win["windows me"]="Windows me";
tab_win["windows 98"]="Windows 98";
tab_win["windows 95"]="Windows 95";
tab_win["windows ce"]="Windows ce";
tab_win["win98"]="Windows 98";
tab_win["win95"]="Windows 95";
tab_win["winnt4.0"]="Windows nt";
//tab_win["windows nt"]="Windows nt";
tab_win["windows 2000"]="Windows 2000";
tab_win["windows-nt"]="Windows nt";
tab_win["winnt"]="Windows nt";
tab_win["windows xp"]="Windows Xp";

var tab_lin=new Array();
tab_lin["android"]="Android";
tab_lin["debian"]="Debian";
tab_lin["fedora"]="Fedora";
tab_lin["red hat"]="Red Hat";
tab_lin["ubuntu"]="Ubuntu";
tab_lin["suse"]="Suse";
tab_lin["mandriva"]="Mandriva";
tab_lin["pclinux"]="pclinux";
tab_lin["linux x86_64"]="Linux 64";
tab_lin["linux i686"]="Linux i686";
tab_lin["linux i586"]="Linux i586";

var tab_mac=new Array();
tab_mac["iphone"]="Iphone";
tab_mac["ipod"]="Ipod";
tab_mac["ipad"]="Ipad";;
tab_mac["ppc mac os"]="Mac Os";
tab_mac["mac os x"]="Mac Os X";
tab_mac["ppc"]="Mac Ppc";
tab_mac["mac_powerpc"]="Mac Power Pc";
tab_mac["mac 10"]="Mac 10";

var tab_mipd=new Array();
tab_mipd["nokia"]="Nokia Mobile";
tab_mipd["sonyericsson"]="SonyEricsson Mobile";
tab_mipd["j2me"]="Java Mobile";
tab_mipd["samsung"]="Samsung Mobile";
tab_mipd["blackberry"]="Blackberry";

for(var i=0;i<tab_system.length;i++){
if(c.indexOf(tab_system[i])!=-1){
 system=tab_system[i];
 break;
 }
}

if(system==""){
platform="other";
for (var ind in tab_other){
if(c.indexOf(ind)!=-1){
 system=tab_other[ind];
 break;
 }
}
}
else if(system=="windows"){
platform="win";
for (var ind in tab_win){
if(c.indexOf(ind)!=-1){
 system=tab_win[ind];
 break;
 }
}
}
else if(system=="mac"){
platform="mac";
for (var ind in tab_mac){
if(c.indexOf(ind)!=-1){
 system=tab_mac[ind];
 break;
 }
}
}
else if(system=="linux"){
platform="lin";
for (var ind in tab_lin){
if(c.indexOf(ind)!=-1){
 system=tab_lin[ind];
 break;
 }
}
}
else if(system=="midp"){
platform="mid";
for (var ind in tab_midp){
if(c.indexOf(ind)!=-1){
 system=tab_midp[ind];
 break;
 }
}
}
return(new Array(system,platform));
}

function Detect_File(fichier,method,data)
{
if(method=="" || method==undefined){method="GET";}
if(window.XMLHttpRequest) // FIREFOX
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // IE
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else
return(false);
if(method=="GET"){
xhr_object.open("GET", fichier, false);
xhr_object.send(null);
}
else{
xhr_object.open("POST", fichier, false);
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr_object.send(data);
}
if(xhr_object.readyState == 4) return(xhr_object.responseText);
else{return(false);}
}


