﻿function CurrentBrowser()
{
    // Record standard strings
    //
    this.agent = navigator.userAgent;
    
    // Record supported standards
    //
    this.supportsDOMRanges = false;
    if (document.implementation && document.implementation.hasFeature)
        this.supportsDOMRanges = document.implementation.hasFeature("Range", "2.0");

    // Record browser type
    //
    this.isIE    = false;  // Internet Explorer
    this.isOP    = false;  // Opera
    this.isNS    = false;  // Netscape
    this.isFF    = false;  // Firefox
    this.isSI    = false;  // Safari
    this.isCR    = false;  // Chrome
    this.version = null;

    var s, i;

    s = "Opera";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isOP = true;
        this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }
    
    s = "Firefox/";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isFF = true;
        this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }

    s = "Chrome/";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isCR = true;
        //this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }  
    
    s = "Safari/";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isSI = true;
        this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }  

    // Treat any other "Gecko" browser as Netscape 6.1.

    s = "Gecko";
    if ((i = this.agent.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = 6.1;
        return;
    }

    s = "MSIE";
    if ((i = this.agent.indexOf(s)))
    {
        this.isIE = true;
        this.version = parseFloat(this.agent.substr(i + s.length));
        return;
    }
}

var currBrowser = new CurrentBrowser();

function MakeBrowserSpecifcIncludes(basePath)
{
    if (currBrowser.isSI)
    {
        WriteCssInclude(basePath, "safari");
    }
    else if (currBrowser.isIE)
    {
        WriteCssInclude(basePath, "msie");     
            
        if (currBrowser.version <= 6) {
            WriteCssInclude(basePath, "msie6");     
        } 
        else if (currBrowser.version == 7) {
            WriteCssInclude(basePath, "msie7");     
        } 
        else if (currBrowser.version == 8) {
            WriteCssInclude(basePath, "msie8");     
        } 
    }
    else if (currBrowser.isFF)
    {
        WriteCssInclude(basePath, "ff");     
        
        if (currBrowser.version <= 2) {
            WriteCssInclude(basePath, "ffold");     
        }        
    }
    else if (currBrowser.isCR)
    {
        WriteCssInclude(basePath, "chrome");
    }
}

function WriteCssInclude(basePath, cssFilename)
{
    if (basePath && basePath.length)
    {
        cssFilename = "/" + cssFilename;
    }
    
    document.write("<link type=\"text/css\" href=\"" + basePath + cssFilename + ".css\" rel=\"stylesheet\" />");
}

function setCookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length);
		
		if (c.indexOf(nameEQ) == 0)
		    return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name)
{
	setCookie(name, "", -1);
}

function changeCurrentSiteStyle(styleName)
{
    setCookie('MyBizzBugStyle', styleName, 360);
    document.location = document.location;
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}