function GetOS(agent)
{
	var os = "";
	if (agent.indexOf('mac') != -1)
		os = "Mac";
	else if (agent.indexOf("windows") != -1 || agent.indexOf("win") != -1)
		os = "Windows";
	return os;
}

function GetBrowserType(agent)
{		
	var type = "";
	if (agent.indexOf('msie') != -1 && agent.indexOf('opera') == -1)
		type = "IE";
	else if (agent.indexOf('firefox') != -1)
		type = "Firefox";
	else if (agent.indexOf('opera') != -1)
		type = "Opera";
	else if (agent.indexOf('netscape') != -1)
		type = "Netscape";
	else if (agent.indexOf('safari') != -1)
		type = "Safari";
	else if (agent.indexOf('aol') != -1)
		type = "AOL";
	else
		type = "Mozilla";
	
	return type;
}

function GetBrowserVersion(agent)
{
	var version = 'unknown', pos, temp, end;
	var appVer = navigator.appVersion.toLowerCase();
	switch(GetBrowserType(agent))
	{
		case "IE":
			pos = appVer.indexOf('msie');
			version = appVer.substring(pos + 5, appVer.indexOf(';',pos));			
			break;
		case "Firefox":
			pos = agent.indexOf('firefox');
			version = agent.substring(pos + 8, agent.length);
			break;
		case "Opera":
			//not support
			break;
		case "Netscape":
			pos = agent.indexOf('netscape');
			temp = agent.substring(pos + 9, agent.length);
			end = temp.indexOf('(');
			version = temp.substring(0, end);
			break;
		case "Safari":
			pos = agent.indexOf('safari');
			version = agent.substring(pos + 7, agent.length);
			break;		
		case "AOL":
			//not support
			break;	
		case "Mozilla":
			pos = agent.indexOf('rv:');
			temp = agent.substring(pos + 3);
			end = temp.indexOf(')');
			version = temp.substring(0, end);			
			break;		
	}
	
	return version;
}


function GetCompatibility()
{
	var compatible = false, mozilla, firefox, ie, netscape, safari;
	
	if (this.isMac)
	{
		mozilla = 1.0;
		firefox = 1.0;
		safari = 312; // (v1.3.2)
		if (this.isMozilla)
		{
			if (parseFloat(this.version) >= mozilla)
				compatible = true;
		}	
		else if (this.isFirefox)
		{
			if (parseFloat(this.version) >= firefox)
				compatible = true;
		}
		else if (this.isSafari)
		{
			if (parseFloat(this.version) >= safari)
				compatible = true;
		}
	}
	else
	{
		mozilla = 1.0;
		firefox = 1.0;	
		ie = 5.5;
		netscape = 6.0;
		safari = 525;		
		if (this.isIE)
		{
			if (parseFloat(this.version) >= ie)
				compatible = true;
		}
		else if (this.isMozilla)
		{
			if (parseFloat(this.version) >= mozilla)
				compatible = true;	
		}
		else if (this.isFirefox)
		{
			if (parseFloat(this.version) >= firefox)
				compatible = true;			
		}
		else if (this.isNetscape)
		{	
			if (parseFloat(this.version) >= parseFloat(netscape))
				compatible = true;			
		}
		else if (this.isSafari)
		{
			if (parseFloat(this.version) >= parseFloat(safari))
				compatible = true;
		}
	}
	return compatible;
}


function Browser()
{	
	var agent = navigator.userAgent.toLowerCase();
	
	this.os = GetOS(agent);
	this.type = GetBrowserType(agent);
	this.version = GetBrowserVersion(agent);
	this.isMac = (this.os == "Mac");
	this.isWindows = (this.os == "Windows");
	this.isIE = (this.type == "IE");
	this.isMozilla = (this.type == "Mozilla");
	this.isFirefox = (this.type == "Firefox");
	this.isNetscape = (this.type == "Netscape");
	this.isSafari = (this.type == 'Safari');
	this.isCompatible = GetCompatibility;
}


function GetCookieValue (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) 
{
	var arg = name + "=";
	var arglen = arg.length;
	var cookielen = document.cookie.length;
	var i = 0;
	while (i < cookielen) 
	{
		var j = i + arglen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieValue (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}


function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) 
				+ ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) 
				+ ((path == null) ? "" : ("; path=" + path)) 
				+ ((domain == null) ? "" : ("; domain=" + domain)) 
				+ ((secure == true) ? "; secure" : "");
}