/*
* Copyright (c) 2002-2004 Victor A.Spirin. All rights reserved.
* author: Victor A.Spirin - victor_aspirin [at] mail [dot] ru
* 
* version: 1.0.0
* date:    2004.09.03
* started: 2004.09.02
*/



var userAgent = new UserAgent();

function UserAgent()
	{
	var type;
	var version;
	
	function init()
		{
		var MARKS = {msie: 'MSIE ', gecko: 'rv:'};
		
		var ua = navigator.userAgent;
			for( n in MARKS )
			{
			var i = ua.indexOf(MARKS[n]);
				if( i != -1 )
				{
				type = n;
				version = parseFloat(ua.substring(i + MARKS[n].length));
				break;
				}
			}
		}
	
	this.isMSIE = function ()
		{
		return type == 'msie';
		}
	
	this.isGecko = function ()
		{
		return type == 'gecko';
		}
	
	this.getVersion = function ()
		{
		return version;
		}
	
	this.loadScript = function ( fileName, availableUAs )
		{
			if( typeof(availableUAs) != 'object' || availableUAs.length == null )
			return alert('Argument "availableUAs" is not pecified');
		
			if( fileName.substring(fileName.length - 3) != '.js' )
			alert('Script file "' + fileName + '" must ends with ".js"');
		
		var script = fileName.substring(0, fileName.length - 3);
		var ua = type + Math.floor(10*version);
		var file = null;
		var exists = false;
			for( var i = 0 ; i < availableUAs.length ; i++ )
			{
				if( availableUAs[i] == type ) exists = true;
				else if( availableUAs[i] == ua )
				{
				file = script + '.' + ua + '.js';
				break;
				}
			}
			if( file == null && exists ) file = script + '.' + type + '.js';
			if( file != null )
			document.write('<' + 'script src="' + file + '"' + '><' + '/' + 'script' + '>');
		}
	
	init();
	}