function cBrowserInfo() {
    this.userAgent = navigator.userAgent.toLowerCase();
    this.appVer = navigator.appVersion.toLowerCase();
    this.name = navigator.appName;
    this.product = navigator.product;
    this.version = parseInt(navigator.appVersion);
    this.subVersion = parseFloat(navigator.appVersion);

    this.mozilla = (this.product == "Gecko");
    this.ns = ((this.userAgent.indexOf('mozilla') != -1) && (this.userAgent.indexOf('spoofer') == -1) && (this.userAgent.indexOf('compatible') == -1) && (this.userAgent.indexOf('opera') == -1));
    this.ns2 = (this.ns && (this.version >= 2));
    this.ns3 = (this.ns && (this.version >= 3));
    this.ns4b = (this.ns && (this.subVersion < 4.04));
    this.ns4 = (this.ns && (this.version >= 4));
    this.ns5 = (this.ns && (this.version >= 5));
    this.ns6 = (this.ns && (this.version >= 6));
    this.ns7 = (this.ns && (this.version >= 7));
    this.ns8 = (this.ns && (this.version >= 8));
    this.ie = ((this.appVer.indexOf('msie') != -1) && (this.userAgent.indexOf('opera') == -1));
    this.ie3 = (this.ie && (this.version >= 3));
    this.ie4 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 4.') != -1));
    this.ie5 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 5.0') != -1));
    this.ie55 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 5.5') != -1));
    this.ie6 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 6.0') != -1));
    this.ie7 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 7.0') != -1));
    this.ie8 = (this.ie && (this.version >= 4) && (this.userAgent.indexOf('msie 8.0') != -1));
    this.avant = (this.ie && (this.userAgent.indexOf('avant') != -1));
    this.chrome = (this.ie && (this.userAgent.indexOf('chrome') != -1));

    this.mac = (this.userAgent.indexOf('mac') != -1);

    // Note: On IE, start of appVersion return 3 or 4  which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string and on Mac IE5+, we look for subversion in the this.userAgent; since 
    // it appears to be more accurate than appVersion - 06/17/2004

    if (this.ie) {
        var iePos = this.appVer.indexOf('msie');
        if (this.mac) {
            iePos = this.userAgent.indexOf('msie');
            this.subversion = parseFloat(this.userAgent.substring(iePos + 5, this.userAgent.indexOf(';', iePos + 1)));
        }
        else {
            this.subversion = parseFloat(this.appVer.substring(iePos + 5, this.appVer.indexOf(';', iePos)));
            this.version = parseInt(this.subversion);
        }
    }

    //Konqueror
    this.konq = false;
    var kqPos = this.userAgent.indexOf('konqueror');
    if (kqPos != -1) {
        this.konq = true;
        this.subversion = parseFloat(this.userAgent.substring(kqPos + 10, this.userAgent.indexOf(';', kqPos)));
        this.version = parseInt(this.subversion);
    }

    //Safari
    this.safari = (this.userAgent.indexOf('safari') != -1);
    this.safari10 = (this.userAgent.indexOf('safari/85') != -1);
    this.safari11 = (this.userAgent.indexOf('safari/100') != -1);
    this.safari12 = (this.userAgent.indexOf('safari/125') != -1);
    this.safari13 = (this.userAgent.indexOf('safari/312') != -1);
    this.safari20 = (((this.userAgent.indexOf('safari/412') != -1) || (this.userAgent.indexOf('safari/416') != -1) || (this.userAgent.indexOf('safari/417') != -1)));

    //Safari Version
    if (this.safari) {
        if (this.safari10) this.safver = '1.0';
        else if (this.safari11) this.safver = '1.1';
        else if (this.safari12) this.safver = '1.2';
        else if (this.safari13) this.safver = '1.3';
        else if (this.safari20) this.safver = '2.0';
        else this.safver = '2.0+';
    }

    //is it a kHTML browser
    this.khtml = this.safari || this.konq;
    this.gecko = (!this.khtml && (this.product) && (this.product.toLowerCase() == "gecko"));

    //Firefox
    this.firefox = ((this.userAgent.indexOf('mozilla/5') != -1) && (this.userAgent.indexOf('spoofer') == -1) && (this.userAgent.indexOf('compatible') == -1) && (this.userAgent.indexOf('opera') == -1) && (this.userAgent.indexOf('webtv') == -1) && (this.userAgent.indexOf('hotjava') == -1) && (this.gecko) && ((navigator.vendor == "Firefox") || (this.userAgent.indexOf('firefox') != -1)));
    this.firefox1 = (this.firefox && (this.version == 5) && (this.userAgent.indexOf('firefox/1.0') != -1));
    this.firefox15 = (this.firefox && (this.version == 5) && (this.userAgent.indexOf('firefox/1.5') != -1));
    if (this.firefox) {
        var is_moz_ver = (navigator.vendorSub) ? navigator.vendorSub : 0;
        if (!is_moz_ver) {
            is_moz_ver = this.userAgent.indexOf('firefox/');
            is_moz_ver = this.userAgent.substring(is_moz_ver + 8);
            is_moz_ver = parseFloat(is_moz_ver);
        }
        if (!(is_moz_ver)) {
            is_moz_ver = this.userAgent.indexOf('rv:');
            is_moz_ver = this.userAgent.substring(is_moz_ver + 3);
            is_paren = is_moz_ver.indexOf(')');
            is_moz_ver = is_moz_ver.substring(0, is_paren);
        }
        this.subversion = is_moz_ver;
        this.version = parseInt(is_moz_ver);
    }

    //Opera
    this.op = (this.userAgent.indexOf('opera') != -1);
    this.opv = (parseFloat(this.userAgent.substring(this.userAgent.indexOf('opera') + 6)));
    this.op7 = (this.op && this.opv >= 7);
    this.op8 = (this.op && this.opv >= 8);
    this.op9 = (this.op && this.opv >= 9);

    this.dom = document.getElementById ? true : false;

    // ***OPERATING SYSTEM PLATFORM ***
    this.win = ((this.userAgent.indexOf("win") != -1) || (this.userAgent.indexOf("16bit") != -1));
    // NOTE: On Opera 3.0, the this.userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    this.win95 = ((this.userAgent.indexOf("win95") != -1) || (this.userAgent.indexOf("windows 95") != -1));

    // is this a 16 bit compiled version?
    this.win16 = ((this.userAgent.indexOf("win16") != -1) || (this.userAgent.indexOf("16bit") != -1) || (this.userAgent.indexOf("windows 3.1") != -1) || (this.userAgent.indexOf("windows 16-bit") != -1));
    this.win31 = ((this.userAgent.indexOf("windows 3.1") != -1) || (this.userAgent.indexOf("win16") != -1) || (this.userAgent.indexOf("windows 16-bit") != -1));
    this.winme = ((this.userAgent.indexOf("win 9x 4.90") != -1));
    this.win2k = ((this.userAgent.indexOf("windows nt 5.0") != -1) || (this.userAgent.indexOf("windows 2000") != -1));
    this.winxp = ((this.userAgent.indexOf("windows nt 5.1") != -1) || (this.userAgent.indexOf("windows xp") != -1));
    this.win2k3 = ((this.userAgent.indexOf("windows nt 5.2") != -1));
    this.winvista = (this.userAgent.indexOf("windows nt 6.0") != -1);
    this.win2k8 = (this.userAgent.indexOf("windows nt 6.0") != -1);
    this.win7 = (this.userAgent.indexOf("windows nt 6.1") != -1);

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in this.userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    this.win98 = ((this.userAgent.indexOf("win98") != -1) || (this.userAgent.indexOf("windows 98") != -1));
    this.winnt = ((this.userAgent.indexOf("winnt") != -1) || (this.userAgent.indexOf("windows nt") != -1));
    this.win32 = (this.win95 || this.winnt || this.win98 || ((this.version >= 4) && (navigator.platform == "Win32")) ||
					  (this.userAgent.indexOf("win32") != -1) || (this.userAgent.indexOf("32bit") != -1));

    this.os2 = ((this.userAgent.indexOf("os/2") != -1) || (this.appVer.indexOf("OS/2") != -1) || (this.userAgent.indexOf("ibm-webexplorer") != -1));

    if (this.mac) { this.win = !this.mac; } //Double check - if mac, make sure win is false
    this.mac68k = (this.mac && ((this.userAgent.indexOf("68k") != -1) || (this.userAgent.indexOf("68000") != -1)));
    this.macppc = (this.mac && ((this.userAgent.indexOf("ppc") != -1) || (this.userAgent.indexOf("powerpc") != -1)));

    if (this.mac && ((this.userAgent.indexOf("mac os x") != -1) || (this.ie && (this.subversion >= 5.2)))) {
        this.macosx = true;
        this.macclassic = false;
    } else {
        this.macclassic = true;
        this.macosx = false;
    }

    this.sun = (this.userAgent.indexOf("sunos") != -1);
    this.linux = (this.userAgent.indexOf("inux") != -1);
    this.freebsd = (this.userAgent.indexOf("freebsd") != -1);
    this.bsd = (this.userAgent.indexOf("bsd") != -1);
    this.unix = ((this.userAgent.indexOf("x11") != -1) || this.sun || this.linux || this.bsd || this.freebsd);
}

var browserInfo = new cBrowserInfo();

//**********

function $location(url) {
    this.href = url;
    this.hash = "";
	this.host = "";
    this.hostname = "";
    this.pathname = "";
    this.port = "";
    this.effectivePort = 80;
    this.protocol = "";
    this.search = "";

	if (this.href != "")
	{
		var segments;
		if (this.href.indexOf("/") == 0)
		{
			segments = window.location.href.split("/");
			this.href = segments[0] + "//" + segments[2] + this.href;
		}
		
	    //protocol://host:port/path_name?search#hash
        segments = this.href.split("#");
		if (segments.length > 1) this.hash = "#" + segments[1];
		
        segments = segments[0].split("?");
		if (segments.length > 1) this.search = "?" + segments[1];
		
        var segments = segments[0].split("/");
        if (segments.length > 2)
        {
        	for (var i=3; i<segments.length; i++) this.pathname += "/" + segments[i];
        	
            this.protocol = segments[0];
            
            segments = segments[2].split(":");
            if (segments.length > 2)
            {
                //Format: protocol://user:pass@host:port/rest_of_url
                this.port = segments[2];
				segments = segments[1].split("@");
        		this.hostname = segments[(segments.length > 1) ? 1 : 0];
            }
            else if (segments.length > 1)
           	{
                this.port = segments[1];
                if (parseDecimal(this.port) > 0)
                {
	                //Format: protocol://[user@]host:port/rest_of_url
            		segments = segments[0].split("@");
                    this.hostname = segments[(segments.length > 1) ? 1 : 0];
                }
                else
            	{
	                //Format: protocol://user:pass@host/rest_of_url
            		segments = segments[1].split("@");
                    this.hostname = segments[(segments.length > 1) ? 1 : 0];
                    this.port = "";
            	}
            }
            else
        	{
                //Format: protocol://[user@]host/rest_of_url
        		segments = segments[0].split("@");
                this.hostname = segments[(segments.length > 1) ? 1 : 0];
        	}
        	
        	this.effectivePort = (parseDecimal(this.port) > 0) ? parseDecimal(this.port) : 0;
        	
        	if (!(this.effectivePort > 0))
        	{
        	    switch (this.protocol)
        	    {
        	    	case "https:": this.effectivePort = 443; break;
        	    	case "ftp:": this.effectivePort = 21; break;
        	    	default: this.effectivePort = (parseDecimal(window.location.port) > 0) ? parseDecimal(window.location.port) : 80;
        	    }
        	}
        	
        	this.host = this.hostname;
        	if (parseDecimal(this.port) > 0)
        		this.host += ":" + this.port;
        }
	}
}
$location.prototype.go = function()
{
	if (arguments.length > 0)
		redirectTo(this.href, arguments[0]);
	else
		redirectTo(this.href, WinTargets.Self);
}
$location.prototype.replace = function()
{
	if (arguments.length > 0)
		redirectTo(this.href, arguments[0], true);
	else
		redirectTo(this.href, WinTargets.Self, true);
}
$location.prototype.isCurrentWebsite = function()
{
	return (this.protocol == window.location.protocol) &&
		(this.host == window.location.host);
}

