//START: Browser Detection
function GetOSCode()
{
	var userAgent = navigator.userAgent.split(";");
	var osCode = "";
	var userAgentLower = "";
	
	for(var i = 0; i < userAgent.length; i++) {
		userAgentLower = userAgent[i].toLowerCase();
		
		if((userAgentLower.indexOf("windows") > -1 || userAgentLower.indexOf("win") > -1) && userAgentLower.lastIndexOf(" ") > -1) {
			if(userAgentLower.indexOf("windows 95") > -1)
				osCode = "4.0"
			else if(userAgentLower.indexOf("windows 98") > -1)
				osCode = "4.1"
			else
				osCode = parseFloat(userAgentLower.substr(userAgentLower.lastIndexOf(" "), userAgentLower.length));
			
			if(!isNaN(osCode))
				break;
		}
		else if(userAgentLower.indexOf("linux") > -1 && !(userAgentLower.indexOf("x86_64") > -1)) {
			osCode = "linux32";
			break;
		}
		else if(userAgentLower.indexOf("linux") > -1 && userAgentLower.indexOf("x86_64") > -1) {
			osCode = "linux64";
			break;
		}
		else if(userAgentLower.indexOf("sunos") > -1) {
			osCode = "sunos";
			break;
		}
		else if(userAgentLower.indexOf("freebsd") > -1)	{
			osCode = "freebsd";
			break;
		}
	}	
	return osCode;
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString( this.dataBrowser ) || "An unknown browser";
		this.version = this.searchVersion( navigator.userAgent )
			|| this.searchVersion( navigator.appVersion )
			|| "an unknown version";
		this.OS = this.searchString( this.dataOS ) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0; i < data.length; i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf( data[i].subString) != -1 )
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function( dataString ) {
		var index = dataString.indexOf( this.versionSearchString );
		if (index == -1) return;
		return parseFloat( dataString.substring( index+this.versionSearchString.length + 1 ) );
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
//END: Browser Detection

function GetCookie( name )
{
    var cookies = document.cookie.split( ';' );
    var cookie = null;    

    for (i = 0; i < cookies.length; i++) {
            
        cookie = cookies[i].split( '=' );
        if (name == cookie[0].replace(/^\s+|\s+$/g, '') ) {            
            if (cookie.length > 1)
                return unescape( cookie[1].replace(/^\s+|\s+$/g, '') );
            break;
        }
    }
    return null;
}

$_INCLUDE = new Array();
function include( jsFile )
{
    if($_INCLUDE.indexOf(jsFile) > -1)
        return;
    new Ajax.Request( jsFile, {
        method: 'get',
        asynchronous  : false,
        onSuccess: function( transport ) {    
            eval(transport.responseText);
            $_INCLUDE.push(transport.request.url);
        },
        onFailure : function() {
            alert( "Failure including file: " + jsFile );
        },
        OnException: function( ajaxRequest, exception ) {
            alert(exception);
        }
    });
}

function RegisterClickEvent()
{
    document.createElement('span');
    HTMLElement.prototype.click = function () {
        if (typeof this.onclick == 'function')
            this.onclick( { type: 'click' } );
    };
    document.createElement('a');
    HTMLElement.prototype.click = function () {
        if (typeof this.onclick == 'function') {
            if (this.onclick( { type: 'click' } ) && this.href)
                window.open( this.href, this.target? this.target : '_self' );
        }
        else if (this.href)
            window.open( this.href, this.target? this.target : '_self' );
    };  
}

Event.observe( window, "load",
    function() {
        Try.these( RegisterClickEvent );
    }
);


function DefaultAttribute( element, name, defaultValue )
{
    var attribute = element.getAttribute( name );
    if(attribute == null || attribute == '')
        return defaultValue;
    return attribute;
}