// ================================================================
// Detection object
// An object that stores information about each plugin
// ================================================================
function DetectObj( name, minVersion, detectFn, fatal ) {
    this.name = name;
    this.minVersion = minVersion;
    this.getVersion = detectFn;
    this.plugErrorEng = "";
    this.plugErrorFre = "";
    this.detectErrorEng = "";
    this.detectErrorFre = "";
    this.fatal = fatal;
}
// ================================================================

// ================================================================
// custom stack object
// ================================================================

// Push an item on to the stack and return that object
function stackPush( objToPush ) {
    this.stack[this.curPos] = objToPush;
    this.curPos++;
    return objToPush;
}

// Pop an item off the stack
function stackPop() {
    var tempStackObj = this.stack[this.curPos];
    this.curPos--;
    return tempStackObj;
}

// Get the stack array
function getStack() {
    return this.stack;
}

// Get the current position in the array
function getCurPos() {
    return this.curPos;
}

// Build a stack object because Mac IE versions don't support push/pop for arrays
function StackObj() {
    // Data
    this.stack = new Array();
    this.curPos = 0;

    // Methods
    this.stackPush = stackPush;
    this.stackPop = stackPop;
    this.getStack = getStack;
    this.getCurPos = getCurPos;
}
// ================================================================

// Set all the variables that need to be global.
var browserVersion = 0;

//var htmlHeader = "<html><body><font face='Arial, Helvetica, sans-serif' size='-1'><p>&nbsp;</p>";
var htmlHeader = "";
htmlHeader += "<html>\n";
htmlHeader += "  <head>\n";
htmlHeader += "    <title>You Require the following Plugins:</title>\n";
htmlHeader += "    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\n";
htmlHeader += "  </head>\n";
htmlHeader += "  <body bgcolor='#FFFFFF' text='#000000' link='#000000' vlink='#000000' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>\n";
htmlHeader += "    <table width='720' border='1' align='center' cellpadding='0' cellspacing='2'>\n";
htmlHeader += "      <tr> \n";
htmlHeader += "        <td><img src='graphics/browser_detect_header.gif' width='720' height='125'></td>\n";
htmlHeader += "      </tr>\n";
htmlHeader += "      <tr> \n";
htmlHeader += "        <td align='center'> \n";
htmlHeader += "          <table width='90%' border='0' cellpadding='0' cellspacing='0'>\n";
htmlHeader += "              <td><font face='Arial, Helvetica, sans-serif'><font size='-1'>\n";

//var htmlFooter = "</font></body></html>";
var htmlFooter = "";
htmlFooter += "              </font></font></td>\n";
htmlFooter += "            </tr>\n";
htmlFooter += "          </table>\n";
htmlFooter += "        </td>\n";
htmlFooter += "      </tr>\n";
htmlFooter += "    </table>\n";
htmlFooter += "  </body>\n";
htmlFooter += "</html>\n";

var englishError = "";
var frenchError = "";

var minBrowserVersion = 6;
var minFlashVersion = 5;
var minAcrobatVersion = 4;

var pluginArray = new StackObj();

// Add Browser detect to array
pluginArray.stackPush( new DetectObj( "Browser", minBrowserVersion, getBrowserVersion, true ) );
var myStack = pluginArray.getStack();
myStack[ pluginArray.getCurPos()-1 ].plugErrorEng = "<p><b>Browser:</b> ASSET Inc's Highway Websites REQUIRE Microsoft Internet Explorer 6.0 or higher. Without it you may experience undesired results. Please upgrade your browser in order to access the ASSET Inc's Highway Websites. It can be found at: <a href='http://www.microsoft.com/downloads/search.aspx' target='_blank'>www.microsoft.com/downloads</a>. If you believe you already have Microsoft Internet Explorer 6.0 or higher installed, you may proceed into the site.</p>";
myStack[ pluginArray.getCurPos()-1 ].detectErrorEng = "<p><b>Browser:</b> There was an error detecting your Internet Explorer. ASSET Inc's Highway Websites REQUIRE Microsoft Internet Explorer 6.0 or higher. Without it you may experience undesired results. Please upgrade your browser in order to access the ASSET Inc's Highway Websites. It can be found at: <a href='http://www.microsoft.com/downloads/search.aspx' target='_blank'>www.microsoft.com/downloads</a>. If you believe you already have Microsoft Internet Explorer 6.0 or higher installed, you may proceed into the site.</p>";

// Add Flash detect to array
pluginArray.stackPush( new DetectObj( "Flash", minFlashVersion, getFlashVersion, false ) );
myStack = pluginArray.getStack();
myStack[ pluginArray.getCurPos()-1 ].plugErrorEng = "<p><b>Flash:</b> ASSET Inc's Highway Websites recommends Macromedia Flash Player version 5.0 or higher. We could not detect the required version. Without this version of Flash, you will not be able to view certain pages within the sites. The latest version can be found at: <a href='http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&P5_Language=English' target='_blank'>www.macromedia.com/shockwave/download</a>.</p>";
myStack[ pluginArray.getCurPos()-1 ].detectErrorEng = "<p><b>Flash:</b> There was an error detecting your Flash Player. ASSET Inc's Highway Websites recommends Macromedia Flash Player version 5.0 or higher. Without this version of Flash, you will not be able to view certain pages within the sites. It can be found at: <a href='http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&P5_Language=English' target='_blank'>www.macromedia.com/shockwave/download</a>. If you believe you already have Flash Player 5.0 installed, you may proceed into the site.</p>";


// Add Acrobat detect to array
pluginArray.stackPush( new DetectObj( "Acrobat", minAcrobatVersion, getAcrobatVersion, false ) );
myStack = pluginArray.getStack();
myStack[ pluginArray.getCurPos()-1 ].plugErrorEng = "<p><b>Acrobat:</b> ASSET Inc's Highway Websites recommends the Adobe Acrobat Reader 4.0. We could not detect the recommended version. Without this version, you will not be able to view certain pages within the sites. The latest version can be found at: <a href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>www.adobe.com/products/acrobat/readstep2.html</a>.</p>";
myStack[ pluginArray.getCurPos()-1 ].detectErrorEng = "<p><b>Acrobat:</b> There was an error detecting your Adobe Acrobat Reader. ASSET Inc's Highway Websites recommends Adobe Acrobat Reader 4.0 or higher. Without this version, you will not be able to view certain pages within the sites. The latest version can be found at: <a href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>www.adobe.com/products/acrobat/readstep2.html</a>. If you believe you have Adobe Acrobat Reader 4.0 installed, you may proceed into the site.</p>";

// ------------------------------------------------------------------------------
// browserDetect()
// This function does browser and plugin detects. If all tests pass, then it redirects
// the user to the main site page. If any test fails, messages for each test that failed
// are printed to the page with instructions for the user.
// ------------------------------------------------------------------------------
function browserDetect() {

    var numErrors = 0;
    var proceed = true;

    englishError += "<p align='center'><font size='+2'>ASSET Inc. Tech Support - Browser Check</font></p>\n";
    

    // ------------------------------------------------------------------------------
    // Loop through the array and check each plugin in it. We use the function stored in each
    // object to do a custom check for that plugin

    var tempStack = pluginArray.getStack();
    for ( var i = 0; i < pluginArray.getCurPos(); i++ ) {
	// Grab a reference to the array element
	var tempObj = tempStack[i];
	// Call the function that returns the plugin version
	var plugVersion = tempObj.getVersion();

	//alert( "name: " + tempObj.name + "; minVersion: " + tempObj.minVersion + "; plugVersion: " + plugVersion );

	if ( plugVersion >= tempObj.minVersion ) {
	    // The user has the plugin version we want
	}
	else if ( plugVersion >= 0 ) {
	    // User has a plugin but it's out of date, or they don't have the plugin
	    englishError += tempObj.plugErrorEng;
	    frenchError += tempObj.plugErrorFre;
	    if ( tempObj.fatal ) {
		proceed = false;
	    }
	    numErrors++;
	}
	else if ( plugVersion == -1 || plugVersion == null || isNaN(plugVersion) ) {
	    // Could not detect the plugin for some reason
	    englishError += tempObj.detectErrorEng;
	    frenchError += tempObj.detectErrorFre;
	    numErrors++;
	}
    } // for i

    // ------------------------------------------------------------------------------

    // Write out the errors, now that everything has been tested
    if ( numErrors > 0 ) {
	// We behave different based on whether the errors were fatal or not
	if ( proceed ) {
	    // The user didn't have recommended plugins, but met the minimum requirements
	    var wholeError = htmlHeader + englishError;
	    wholeError += "<p align='center'><font size='2'><b>You didn't have recommended plugins, but meet the minimum requirements</b></font></p>\n";
	    wholeError += htmlFooter;
	    document.write( wholeError );
	} 
	else {
	    // User didn't meet minimum requirements
	    var wholeError = htmlHeader + englishError + htmlFooter;
	    document.write( wholeError );
	}
    } 
    else {
	// There were no problems, let the user in!
	document.location = "uptodate.htm";
    }

} // browserDetect()

