var user_agent = navigator.userAgent.toLowerCase();

var str, agent_name, agent_ver, agent_code, agent_lang, agent_lang_type, platform_id = "";

// analyse agent name

if ((str = user_agent.match(/(opera)(\s*\/*\s*)+([0-9]{1,2}(.[0-9]{1,3})*)+/i)) != null) {
    agent_name = "Opera";
    agent_ver = str[3];
}

else if ((str = user_agent.match(/(konqueror)\/([0-9]{1,2}.[0-9]{1,3})/i)) != null) {
    agent_name = "Konqueror";
    agent_ver = str[3];
}

else if ((str = user_agent.match(/(galeon)\/([0-9]{1,2}.[0-9]{1,3})/i)) != null) {
    agent_name = "Galeon";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(epiphany)(\s*\/*\s*)([0-9]{1,2}(.[0-9]{1,3})*)/i)) != null) {
    agent_name = "Epiphany";
    agent_ver = str[3];
}
else if ((str = user_agent.match(/(nautilus)\/([0-9]{1,2}.[0-9]{1,3})/i)) != null) {
    agent_name = "Nautilus";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(dillo)(\s*\/*\s*)+([0-9]{1,2}(.[0-9]{1,3})*)+/i)) != null) {
    agent_name = "Dillo";
    agent_ver = str[3];
}
else if ((str = user_agent.match(/(lynx)(\s*\/*\s*)+([0-9]{1,2}(.[0-9]{1,3})*)+/i)) != null) {
    agent_name = "Lynx";
    agent_ver = str[3];
}
else if ((str = user_agent.match(/(links)\s*\(([0-9]{1,2}(.[0-9]{1,3})*)+/i)) != null) {
    agent_name = "Links";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(w3m)(\s*\/*\s*)+([0-9]{1,2}(.[0-9]{1,3})*)+/i)) != null) {
    agent_name = "w3m";
    agent_ver = str[3];
}
else if ((str = user_agent.match(/(msie )([0-9]{1,2}.[0-9]{1,3})/i)) != null) {
    agent_name = "MSIE";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(netscape6)\/(6.[0-9]{1,3})/i)) != null) {
    agent_name = "Netscape";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(netscape7)\/(7.[0-9]{1,3})/i)) != null) {
    agent_name = "Netscape";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(netscape)\/(7.[0-9]{1,3})/i)) != null) {
    agent_name = "Netscape";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(firefox)\/([0-9](.[0-9])*)/i)) != null) {
    agent_name = "Firefox";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/(seamonkey)\/([0-9](.[0-9])*)/i)) != null) {
    agent_name = "SeaMonkey";
    agent_ver = str[2];
}
// mozilla check
else if ( user_agent.match(/mozilla/i) && ( !user_agent.match(/msie/i) && !user_agent.match(/\/4./i) && !user_agent.match(/gold/i) && !user_agent.match(/firefox/i) ) && user_agent.match(/gecko/i) ) {
    par1 = user_agent.indexOf(")");
    par2 = user_agent.indexOf(":");
    agent_ver = user_agent.substring(par2 + 1, par1);
    agent_name = "Mozilla";
}
else if ((str = user_agent.match(/mozilla\/5/i)) != null) {
    agent_name = "Netscape";
    agent_ver = "unknown";
}
else if ((str = user_agent.match(/(mozilla)\/([0-9]{1,2}.[0-9]{1,3})/i)) != null) {
    agent_name = "Netscape";
    agent_ver = str[2];
}
else if ((str = user_agent.match(/icab/i)) != null) {
    agent_name = "iCab";
    agent_ver = "unknown";
}
else if ((str = user_agent.match(/webtv/i)) != null) {
    agent_name = "WebTV";
    agent_ver = "unknown";
}
else {
    agent_name = "unknown";
    agent_ver = "unknown";
}

// analyse platform name

if ((str = user_agent.match(/linux([a-zA-Z0-9 .-]+){0,1}[;|\)]/i)) != null) {
  platform_id = "Linux "+ str[1];
}
else if ((str = user_agent.match(/win32/i)) != null) {
  platform_id = "Windows";
}
else if ((str = user_agent.match(/(win|windows)[ ]{0,1}([0-9]{2})/i)) != null) {
  platform_id = "Windows "+ str[2];
}
else if ((str = user_agent.match(/(win|windows)[ ]{0,1}(me|xp)/i)) != null) {
  platform_id = "Windows "+ str[2];
}
else if ((str = user_agent.match(/(winnt)([0-9]{1,2}.[0-9]{1,2}){0,1}/i)) != null) {
  platform_id = "Windows NT "+ str[2];
}
else if ((str = user_agent.match(/(windows nt)[ ]{0,1}(5.0)/i)) != null) {
  platform_id = "Windows 2000";
}
else if ((str = user_agent.match(/(windows nt)[ ]{0,1}(5.1)/i)) != null) {
  platform_id = "Windows XP";
}
else if (user_agent.match(/windows/i) && user_agent.match(/vista/i)) {
  platform_id = "Windows Vista";
}
else if ((str = user_agent.match(/(windows nt)[ ]{0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}/i)) != null) {
  platform_id = "Windows NT "+ str[2];
}
else if ((str = user_agent.match(/mac/i)) != null) {
  platform_id = "Macintosh";
}
else if ((str = user_agent.match(/(sunos)([0-9]{1,2}.[0-9]{1,2}){0,1}/i)) != null) {
  platform_id = "SunOS "+ str[2];
}
else if ((str = user_agent.match(/(beos)[r| ]{0,1}([0-9]{1,2}.[0-9]{1,2}){0,1}/i)) != null) {
  platform_id = "BeOS "+ str[2];
}
else if ((str = user_agent.match(/(freebsd[^;]*)[;|\)]/i)) != null) {
  platform_id = str[1];
}
else if ((str = user_agent.match(/openbsd/i)) != null) {
  platform_id = "OpenBSD";
}
else if ((str = user_agent.match(/irix/i)) != null) {
  platform_id = "IRIX";
}
else if ((str = user_agent.match(/os\/2/i)) != null) {
  platform_id = "OS/2";
}
else if ((str = user_agent.match(/plan9/i)) != null) {
  platform_id = "Plan9";
}
else if ((str = user_agent.match(/hp-ux/i)) != null) {
  platform_id = "Unix";
}
else if ((str = user_agent.match(/unix/i)) != null) {
  platform_id = "Unix";
}
else if ((str = user_agent.match(/osf/i)) != null) {
  platform_id = "OSF";
}
else if (user_agent.match(/spider/i) || user_agent.match(/bot/i) || user_agent.match(/http/i) || user_agent.match(/Scooter/i) || user_agent.match(/WebCopier/i))  {
  platform_id = "Spiders";
}
else {$platform_id = "unknown OS";}
if((str = user_agent.match(/\.net/i)) != null) {
  platform_id += " with .NET technology";
}
