/*
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
description:	domtamer useragent library
created:		17.02.2002
author:			benjamin nowack
copyright:		2002, appmosphere.com, germany, all rights reserved
language:		JavaScript
version:		1.1 (27.02.2002)
changes:		"konqueror" added to get_category()
comments:		
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
*/

function get_ua(){
	if(window["my_ua"]){
		return window.my_ua;
	}
	else{
		if(parent["my_ua"]){
			return parent.my_ua;
		}
		else{
			parent.my_ua=new DT_useragent();
			return parent.my_ua;
		}
	}
};


function get_ua_cat(){
	var ua=window.get_ua();
	return ua.get_category();
};


/* # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # */

function DT_useragent(ua){

	/* methods */
	this.has_substr=dt_useragent_has_substr;
	this.get_tag=dt_useragent_get_tag;

	this.get_pre_name=dt_useragent_get_pre_name;
	
	this.is_opera=dt_useragent_is_opera;
	this.is_konqueror=dt_useragent_is_konqueror;
	this.is_webtv=dt_useragent_is_webtv;
	this.is_lotusnotes=dt_useragent_is_lotusnotes;
	this.is_mozilla=dt_useragent_is_mozilla;
	this.is_ie=dt_useragent_is_ie;
	this.is_ns=dt_useragent_is_ns;
	
	this.get_name=dt_useragent_get_name;
	this.get_version=dt_useragent_get_version;
	
	this.is_win=dt_useragent_is_win;
	this.is_mac=dt_useragent_is_mac;
	this.is_unix=dt_useragent_is_unix;
	this.get_os=dt_useragent_get_os;
	
	this.is_supported=dt_useragent_is_supported;
	this.get_category=dt_useragent_get_category;
	
	/* init */
	if(ua){
		this.tag=ua.toLowerCase();ua=null;
	}
	else{
		if(navigator && navigator.userAgent){
			this.tag=navigator.userAgent.toLowerCase();
		}
		else{
			this.tag="_null";
		}
	}
};

/* # # # # # # # # # # */

function dt_useragent_has_substr(v){
	return (this.tag.indexOf(v)!=-1)? true:false;
};


function dt_useragent_get_tag(){
	return this.tag;
};


/* # # # # # # # # # # */

function dt_useragent_get_pre_name(){
	var r="";
	var ua=this.get_tag()+" ;";
	var slash_pos=ua.indexOf("/");
	var blank_pos=ua.indexOf(" ");
	if(slash_pos && slash_pos<blank_pos){
		r=ua.substring(0, slash_pos);
	}
	return r;
};


/* # # # # # # # # # # */

function dt_useragent_is_opera(){
	return (this.has_substr("opera"))? true:false;
}


function dt_useragent_is_konqueror(){
	return (this.has_substr("konqueror"))? true:false;
}


function dt_useragent_is_webtv(){
	return (this.has_substr("webtv"))? true:false;
}


function dt_useragent_is_lotusnotes(){
	return (this.has_substr("lotus-notes"))? true:false;
}


function dt_useragent_is_mozilla(){
	return (this.get_pre_name()=="mozilla" && this.has_substr("gecko") && !this.has_substr("netscape") && !this.has_substr("compatible"))? true:false;
}


function dt_useragent_is_ie(){
	return (this.get_pre_name()=="mozilla" && this.has_substr("msie") && this.has_substr("compatible") && !this.is_opera() && !this.is_webtv())? true:false;
}


function dt_useragent_is_ns(){
	return (this.get_pre_name()=="mozilla" && !this.is_ie() && !this.is_opera() && !this.is_mozilla() && !this.is_konqueror() && !this.is_lotusnotes())? true:false;
}
	
/* # # # # # # # # # # */

function dt_useragent_get_name(short_name){
	var sn=short_name;
	if(this.is_ie()){
		return sn? "ie":"Internet Explorer";
	}
	if(this.is_ns()){
		return sn? "ns":"Netscape";
	}
	if(this.is_opera()){
		return sn? "opera":"Opera";
	}
	if(this.is_konqueror()){
		return sn? "konqueror":"Konqueror";
	}
	if(this.is_mozilla()){
		return sn? "mozilla":"Mozilla";
	}
	if(this.is_webtv()){
		return sn? "webtv":"WebTV";
	}
	if(this.is_lotusnotes()){
		return sn? "lotusnotes":"Lotus Notes";
	}
	return "";
}


function dt_useragent_get_version(){
	var ua=this.get_tag()+" ";
	var v_start=ua.length;
	/* Mozilla/5.0 (Windows 98; U) Opera 5.01 [en] || Opera/5.01 (Windows 2000; U)  [en] */
	if(v_start==ua.length && this.is_opera()){
		v_start=(this.get_pre_name()=="mozilla")? 6+ua.indexOf("opera "):6;
	}
	/* Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T-Online Internatinal AG) */
	if(v_start==ua.length && this.is_ie()){
		v_start=5+ua.indexOf("msie");
	}
	/* Mozilla/4.75 [de]C-CCK-MCD DT (Win98; U) || Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1 */
	if(v_start==ua.length && this.is_ns()){
		v_start=(this.has_substr("gecko"))? 10+ua.indexOf("netscape"):8;
	}
	/* Mozilla/5.0 (compatible; Konqueror/2.0.1; X11) */
	if(v_start==ua.length && this.is_konqueror()){
		v_start=10+ua.indexOf("konqueror");
	}
	/* Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.5) Gecko/20010726 */
	if(v_start==ua.length && this.is_mozilla()){
		v_start=3+ua.indexOf("rv:");
	}
	return parseFloat(ua.substring(v_start, ua.length));
}


/* # # # # # # # # # # */

function dt_useragent_is_win(){
	return (this.has_substr("win"))? true:false;
}


function dt_useragent_is_mac(){
	return (this.has_substr("mac"))? true:false;
}


function dt_useragent_is_unix(){
	return (this.has_substr("linux")||this.has_substr("x11")||this.has_substr("sunos")||this.has_substr("aix")||this.has_substr("unix"))? true:false;
}


function dt_useragent_get_os(short_os){
	var so=short_os;
	if(this.is_win()){
		if(this.has_substr("win95") || this.has_substr("windows 95")){
			return so? "win95":"Windows 95";
		}
		if(this.has_substr("win98") || this.has_substr("windows 98")){
			return so? "win98":"Windows 98";
		}
		if(this.has_substr("winme") || this.has_substr("windows me")){
			return so? "winME":"Windows ME";
		}
		if(this.has_substr("winnt") || this.has_substr("windows nt")){
			return so? "winNT":"Windows NT";
		}
		if(this.has_substr("Win2") || this.has_substr("Windows 2")){
			return so? "win2K":"Windows 2000";
		}
		if(this.has_substr("winxp") || this.has_substr("windows xp")){
			return so? "winXP":"Windows XP";
		}
		return so? "win":"Windows";
	}
	if(this.is_mac()){
		return so? "mac":"Macintosh";
	}
	if(this.is_unix()){
		if(this.has_substr("linux")){
			return so? "linux":"Linux";
		}
		if(this.has_substr("sunos")){
			return so? "sunos":"SunOS";
		}
		if(this.has_substr("aix")){
			return so? "aix":"AIX";
		}
		return so? "unix":"Unix";
	}
	return "";
}


/* # # # # # # # # # # */

function dt_useragent_is_supported(){
	var r=true;
	if(this.is_ie() && this.get_version()<4){
		r=false;
	}
	if(this.is_ns() && this.get_version()<3){
		r=false;
	}
	if(this.is_opera() && this.get_version()<5){
		r=false;
	}
	return r;
}


function dt_useragent_get_category(){
	if(this.is_supported()){
		/* opera */
		if(this.is_opera()){
			return "opera"; /* z.B. opera5: document_write, css, get_by_id */
		}
		/* ns */
		if(this.is_ns() && this.get_version()<6){
			return "ns4"; /* z.B. ns4: document_write, css, div_write */
		}
		if(this.is_ns() && this.get_version()>=6){
			return "gecko"; /* z.B. ns6: document_write, css, get_by_id, DOM, innerHTML */
		}
		/* mozilla */
		if(this.is_mozilla()){
			return "gecko"; /* z.B. mozilla 0.9.7: document_write, css, get_by_id, DOM, innerHTML */
		}
		/* ie */
		if(this.is_ie() && this.get_version()<5){
			return "ie4"; /* z.B. ie4: document_write, css, document.all, innerHTML */
		}
		if(this.is_ie() && this.get_version()<6){
			if(this.is_mac()){
				return "ie5mac"; /* z.B. ie5mac: document_write, css, document.all, get_by_id, DOM, innerHTML */
			}
			else{
				return "ie5"; /* z.B. ie5: document_write, css, document.all, get_by_id, DOM, innerHTML	 */
			}
		}
		if(this.is_ie() && this.get_version()>=6){
			if(this.is_mac()){
				return "ie6mac"; /* z.B. ie6mac: document_write, css, document.all, get_by_id, DOM, innerHTML */
			}
			else{
				return "ie6"; /* z.B. ie6: document_write, css, document.all, get_by_id, DOM, innerHTML	 */
			}
		}
		/* konqueror */
		if(this.is_konqueror()){
			return "konqueror";
		}
	}
	return "html3";
}


/* # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # */

if(!window.libs_loaded){
	window.libs_loaded=1;
}
else{
	window.libs_loaded++;
}
