﻿// Global Variables
var Browser;
var BrowserVersion;
var BrowserMajorVersion;

///////////////////////////////////////////////////////
// DetectDownlevelBrowser -
//	For purposes of graceful handling of browsers not
//  supported in JQuery.  Add any incompatible browser
//  discoveries to this list until it is decided there
//  should be a custom render mode for it.
//
// return - true if detected as downlevel browser
function DetectDownlevelBrowser() {
    var UserAgent = String(navigator.userAgent);

    /*
    // Code that alerts browser product string variables
    var AppName = String(navigator.appName);
    var AppVer = String(navigator.appVersion);
    var Platform = String(navigator.platform);
    var Vendor = String(navigator.vendor);
    var Product = String(navigator.product);
	
	alert("AppName = " + AppName + "\r\n" +
    "AppVer = " + AppVer + "\r\n" +2
    "Platform = " + Platform + "\r\n" +
    "UserAgent = " + UserAgent + "\r\n" +
    "Vendor = " + Vendor + "\r\n" +
    "Product = " + Product + "\r\n");
    */

    // MSIE 4/5/6 are considered downlevel
    if ((UserAgent.indexOf("MSIE 5") > -1) ||
		(UserAgent.indexOf("MSIE 4") > -1) ||
		(UserAgent.indexOf("MSIE 6") > -1))
    {
        Browser = 'msie';
        return 1;
    }
    // AppleWebkit less than "500" is considered downlevel
    else if (UserAgent.indexOf("AppleWebKit") > -1) {
        //if(parseInt(UserAgent.match(/AppleWebKit\/(\d+(\.\d+)?)/)[1]) < 500)
        if (parseInt(UserAgent.substring(UserAgent.indexOf("AppleWebKit") + 12)) < 500) {
            Browser = 'safari';
            return 1;
        }
    }
    // Opera MINI, as it is not quite there at rendering advanced designs.
    else if (UserAgent.indexOf("Opera Mini") > -1) {
        Browser = 'opera mini';
        return 1;
    }
    // Opera less than 8 is considered downlevel
    else if (UserAgent.indexOf("Opera") > -1) {
        if (parseInt(UserAgent.substring(UserAgent.indexOf("Opera") + 6)) < 8) {
            Browser = 'opera';
            return 1;
        }
    }
    // Firefox 1 (Gecko) is considered downlevel
    else if (UserAgent.indexOf("Gecko") > -1) {
        if (parseFloat(UserAgent.substring(UserAgent.indexOf("rv:") + 3)) < 1.8) {
            Browser = 'gecko';
            return 1;
        }
    }

    // Any browser that makes it through these checks will go on to load the JQuery code.
    // The first thing the JQuery code does (in DefenseGov_Master.js) is use jQuery's own
    // browser feature detection to decide if the CSS BoxModel is supported.
    //
    // If that check returns false, the browser will also become a downlevel browser.
    //
    // Essentially, this function is method of excluding known downlevel browsers.  JQuery's
    // CSS BoxModel detection is a method of inclusion for any browser capable of passing
    // the JQuery check.
    return 0;
}

///////////////////////////////////////////////////////
// LoadJQuery -
//	Load all global assets for JQuery Support
function LoadJQuery()
{
	document.write("<script type=\"text/javascript\" src=\"/script/jquery-1.4.2.min.js\"></script>");
	document.write("<script type=\"text/javascript\" src=\"/script/dln_temp_Master.js\"></script>");

	// Load local page assets listed by global PageAssets Array
	// The array has been created in the <filename>.aspx.cs code of the related page.
	if (typeof PageAssets != "undefined")
	{
		for (i = 0; i < PageAssets.length; i++)
		{
			LoadPageAsset(PageAssets[i].type, PageAssets[i].path);
		}
	}
	
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/dln_temp_advanced.css\" />");
}

///////////////////////////////////////////////////////
// LoadPageAsset -
//	Dynamically loads a page asset.
//
//	type - The type of asset, conforming to the HTML type attribute
//
//	path - the full path of the asset.
//
function LoadPageAsset(type, path)
{
	if (type == "text/javascript")
	{
		document.write("<script type=\"text/javascript\" src=\"" + path + "\"></script>");
	}
	else if (type == "text/css")
	{
		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + path + "\"/>");
	}
}

// If this browser has not been flagged as downlevel, proceed to load JQuery,
// Global and Local javascript/css assets.
if (!DetectDownlevelBrowser())
{
	LoadJQuery();
}

