/*
 * Browser detection code
 * Usage: var browser = new Browser;
 *        browser.name, browser.version, etc.
 * 
 * "$Id: browser.js,v 1.10.16.1 2008/02/28 23:34:06 kyevenko Exp $"
 */
function Browser() {
    var name = navigator.appName;
    if (name == "Netscape")
        this.name = "ns";
    else if (name == "Microsoft Internet Explorer")
        this.name = "ie";

    this.version = navigator.appVersion;
    this.vMajor  = parseInt(this.version);
    this.isNS    = (this.name =="ns" && this.vMajor >= 4);
    this.isNS4   = (this.name =="ns" && this.vMajor == 4);
    this.isNS6   = (this.name =="ns" && this.vMajor == 5);
    this.isIE    = (this.name =="ie" && this.vMajor >= 4);
    this.isIE4   = (this.version.indexOf ('MSIE 4')   >0);
    this.isIE5   = (this.version.indexOf ('MSIE 5')   >0);
    this.isDOM   = (document.createElement
                    && document.appendChild
                    && document.getElementsByTagName) ? true : false;

    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf ("win") > - 1)
        this.platform = "win";
    else if (ua.indexOf("mac") > -1)
        this.platform = "mac";
    else
        this.platform="other";
}

function getBaseHref() {
	return document.getElementsByTagName("base")[0]['href'];
}

/**
 * prefixes the base href to the uri passed in.
 */
function toAbsoluteUrl(uri) {
	return getBaseHref() + uri; 
}

/**
 * return true if we don't have a <base> tag 
 * to worry about.
 */
function hasNoBaseHref() {
    return document.getElementsByTagName("base").length == 0;
}

function loadUrl(url){
	var pattern = "^http[s]?[:]//.*$";
	if ( url.match(pattern) || hasNoBaseHref() ){
		window.location.href = url;
	} else {
		window.location.href = toAbsoluteUrl(url);
	}
}

function addBookmark(title, url) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

if (typeof(scripts) == 'undefined') {
    var scripts = new Object();
}

function importJavaScript(filename, callback){
    if (scripts[filename] != null){
        if (callback) {callback();}
        return;
    }
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    if (callback) {
        Event.observe(script, 'load', callback);
    }
    script.src = filename;
    head.appendChild(script);
    scripts[filename] = "imported";
}
