/**********************************************************************
BROWSERCOMPAT.JS : Browser Compatibility Checking Library

Makes sure browser type can be properly supported.
**********************************************************************/
/*
Function:	  browserCompatCheck()		   
Notes:      
			  -Allowed Browser TYPE
			  -Allowed Browser Range High includes highest pass.
			  -Allowed Browser Range Low includes lowest pass.
			  -Browser Exclusions
			  -Browser Warning
			  -Simple Version
			  -note: I.E. 3.0 is not included in comparsion 
			  -aSimple should be recorded as an INT.
			  -Exclusions and warnings should have two decimal places.
			  
*/
function browserCompatCheck()
{
	// Initialize new object member variables that will be passed out
	// of the browserCompatCheck Function.
	this.compat = false;
	this.simple = false;
	this.warn   = false;
	this.version= ""; 

	//Establish Allowed Browser types, ranges and exclusions in an array
	//These could be passed in as parameters if the values are stored in 
	//XML or in the config files

	var AlBrowsers = new Array();
	var o = new Object();
	
		o.aExclusion		= new Array();
		o.aSimple			= new Array();
		o.aWarning			= new Array();
		
		//browser type
	   o.strType			= "NNAV";
	   
	   //browser high and low range
		o.nHiRange			= 4.78;
		o.nLoRange			= 4.50;
		
		//browser exclusion list
		o.aExclusion[0]	= 5.00;
		o.aExclusion[1]	= 6.00;	
		
		//browser routing to simple functionality, no css
		o.aSimple[0]		= 4;
		
		//Handle warning screen for current browser
		o.aWarning[0]		= 4.10;
		o.aWarning[1]		= 4.20;
		o.aWarning[2]		= 4.30;		
		o.aWarning[3]		= 4.40;		
		o.aWarning[4]		= 0.00;	
				
		
		//Read this object into an object array.
		AlBrowsers[o.strType]= o;
		
		//re initialize the object for reuse.
		o = "";
		o = new Object();
		
		o.aExclusion		= new Array();
		o.aSimple			= new Array();
		o.aWarning			= new Array();
		
		//browser type
		o.strType			= "MSIE";
	   
	   //browser high and low range	
		o.nHiRange			= 8.00;
		o.nLoRange			= 5.01;
		
		//browser exclusion list
		o.aExclusion[0]	= 0.00;
		
		//browser routing to simple functionality
		o.aSimple[0]		= 0;
		
		//Handle warning screen for current browser
		o.aWarning[0]		= 4.01;
		o.aWarning[1]		= 4.10;
		o.aWarning[2]		= 4.20;
		o.aWarning[3]		= 4.30;
		o.aWarning[4]		= 4.40;
		o.aWarning[5]		= 4.50;
		o.aWarning[6]		= 4.60;				
		o.aWarning[7]		= 4.70;
		o.aWarning[8]		= 4.80;
		o.aWarning[9]		= 4.90;
		o.aWarning[10]		= 5.00;
		o.aWarning[11]		= 0.00;						
		
		//Read this object into an object array.
		AlBrowsers[o.strType]= o;


	//Create the browser detection object
	var BrowserDetect = new Object();

	//Determine the type of browser from Navigator Object.
	//Additional Code must be added to determine version if
	//a new Browser is added
	BrowserDetect.isType = null;
	BrowserDetect.isVersion = null;

	//Test the user's browsers to see which browser type
	if ( navigator.appName.indexOf("Netscape") != -1 )
	{
		BrowserDetect.isType = "NNAV";
		BrowserDetect.isVersion = parseFloat(navigator.appVersion);
		
		//Set The version property
		this.version   = BrowserDetect.isVersion;

	}
	else if ( navigator.appName.indexOf("Microsoft" ) != -1 )
	{
		//Find the version for MSIE
	   BrowserDetect.isType = "MSIE";
	   
	   //Find the string MSIE and return position
	   BrowserDetect.ieFind = navigator.appVersion.indexOf('MSIE',0);
	   
	   //Find the version number and MSIE *.**
		BrowserDetect.ieNum = navigator.appVersion.substring((BrowserDetect.ieFind + 5),255);
		
		//Change the string to a float number
		BrowserDetect.isVersion = parseFloat(BrowserDetect.ieNum);
		
		//Special Case to handle non javascript 1.1 compliant IE browser version 3.0:
		//Take no risk with the browser getting through array for loops.
		if (BrowserDetect.isVersion < 4.0)
		{
			this.compat		= false;
			this.simple		= true;
			this.version   = BrowserDetect.isVersion;
			return;
		}
		//Set The version property
		this.version   = BrowserDetect.isVersion;
		
	}
	else 
	{
	   BrowserDetect.isType = null;
		this.compat				= true;
		this.simple				= true;
		this.warn				= true;
		return;
	}

	if (BrowserDetect.isVersion == null)
	{
	//if the browser version is null or not a number then return not compatible
	this.compat = false;
	this.simple = false;
	return;
	}

	//Create a new comparison object.
	var oBrowser;
	
	//Create container for the type of browser we have and allowed properties
	var oTargetBrowser = BrowserDetect.isType;

	//Loop through all defined browser properties in the AlBrowsers object and test current
	//browser
	for ( strKey in AlBrowsers)
	{
		//Compare the target browser to the allowed properties array
		if ( strKey == oTargetBrowser)
		{
		  
			oBrowser = "";
			//Set the oBrowser used in conditionals to the correct browser type-MSIE or NAV
			oBrowser = AlBrowsers[strKey];
			
			for ( BrowserProp in oBrowser)
			{

				if (BrowserProp == "nHiRange")
				{
					if ( parseFloat( BrowserDetect.isVersion ) > parseFloat( oBrowser[BrowserProp] ) )
					{
						// Return Not Compat
						this.compat = false;
						this.simple = false;
						return;				
					}
				}
				if ( BrowserProp == "nLoRange" )
				{
					//Test to see if the detected browser is below low range
					if (  parseFloat( BrowserDetect.isVersion ) < parseFloat( oBrowser[BrowserProp] )  )
					{
						// Return Not Compat
						this.compat = false;
						this.simple = false;
						return;				
					}
				}
				if(BrowserProp == "aExclusion")
				{
					for (var i = 0; i < oBrowser[BrowserProp].length; i++) 
					{
						
						//Check to see if detected browser is in the list of exclusions
						if (parseFloat(oBrowser[BrowserProp][i])== parseFloat(BrowserDetect.isVersion))
						{
							//Return Not Compat
							this.compat = false;
							this.simple = false;
							return;
						}
					}
				}				
				if(BrowserProp == "aWarning")
				{
					for ( var i = 0; i < oBrowser[BrowserProp].length; i++ ) 
					{
						
						//Check to see if detected browser is in the list of warnings.
						if (  parseFloat( oBrowser[BrowserProp][i] )== parseFloat( BrowserDetect.isVersion )  )
						{
							//Return that the version is a warning version.
							this.warn   = true;
						}
				    }				
				}    
				if( BrowserProp == "aSimple" )
				{
					for ( var i = 0; i < oBrowser[BrowserProp].length; i++ ) 
					{
						if (  parseInt(  oBrowser[BrowserProp][i]  )== parseInt( BrowserDetect.isVersion )  )
						{
							// Set router to simple and return
							this.simple = true;
						}
					}//End for

				}//End Browser prop simple if

		   }//End "BrowserProp in oBrowser" for
		     
			
			//If browser reaches here without being returned then it is compatable
			//If the browser is complex but screen height less than 500 pixels
			//then take browser to simple logon screen.
			if (!this.simple)
			{
				if( screen.availHeight < 500 )
				{
					this.simple = true;   
				}
			}
			
			//Return true if the browser is fully compatible.
			this.compat = true;
			return;
			
		}// End  "strKey == oTargetBrowser" if	
			
	}// End "strKey in AlBrowsers" for


}//End - browserCompatCheck - Function

// -= END of BrowserCompat.js =-

