//*****************************************************************************************************
//FLASH PLUG IN CHECKER

var g_flashInstalled = 0;
var g_flashVersion = 0;

function FPI_Detect(){
	//NS
	if (navigator.plugins && navigator.plugins.length)
	{
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{
			this.installed = 2;
			if (x.description)
			{
				y = x.description;
				this.version = y.charAt(y.indexOf('.')-1);
			}
		}
		else
		{
			this.installed = 1;
			if (navigator.plugins["Shockwave Flash 2.0"])
			{
				this.installed = 2;
				this.version = 2;
			}
		}
	}
	//IE ON MAC
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			this.installed = 2;
		else
			this.installed = 1;
	}
	//IE ON PC
	else
	{
		
		var lines = [];
		lines[0]  = '<SCRIPT LANGUAGE="VBScript">';
		lines[1]  = 'on error resume next';
		lines[2]  = 'For i = 2 to 5';
		lines[3]  = 'If Not IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i)) Then';
		lines[4]  = 'g_flashInstalled = 0';
		lines[5]  = 'Else';
		lines[6]  = 'g_flashInstalled = 2';
		lines[7]  = 'g_flashVersion = i';
		lines[8]  = 'End If';
		lines[9]  = 'Next';
		lines[10] = 'If g_flashInstalled = 0 Then';
		lines[11] = 'g_flashInstalled = 1';
		lines[12] = 'End If';
		lines[13] = '</\SCRIPT>';

		var str = "";
		for(var i = 0; i < lines.length; i++)
		{
			str += lines[i];
			if(i < lines.length - 1)str += "\n";
		}

		document.write(str);
		this.installed = g_flashInstalled;
		this.version = g_flashVersion;
	}
}

function FPI_IsInstalled(){
	return (this.installed == 2);
}

function FPI_GetMovie(movieName, source){
	if(!source)source = window;
	if (navigator.appName.indexOf ("Microsoft") !=-1) 
	    	return source[movieName]
 	else
    		return source.document[movieName];
}

function FPI_IsMovieLoaded(m){
	if(m)
		return (m.PercentLoaded() == 100);
	else
		return false;
}

function FPI_Dump(){
	document.write("FLASH PLUG IN" + "<br>");
	document.write("Installed: " + this.IsInstalled() + "<br>");
	document.write("Installation details: " + this.installed + "<br>");
	document.write("Version: " + this.version + "<br>");
}

function FlashPlugIn(){
	//PROPERTIES
	this.name = "Flash";
	this.installed = 0;
	this.version = 0;

	//METHODS
	this.Detect = FPI_Detect;
	this.IsInstalled = FPI_IsInstalled;
	this.GetMovie = FPI_GetMovie;
	this.IsMovieLoaded = FPI_IsMovieLoaded;
	this.Dump = FPI_Dump;
	
	//INITIALISATION
	this.Detect();
}

//FLASH PLUG IN CHECKER
//*****************************************************************************************************


//*****************************************************************************************************
//SYSTEM INFO

function SI_Detect(){
	this.type = navigator.appName;
	this.version = navigator.userAgent;
	this.platform = navigator.platform;
	this.javaEnabled = navigator.javaEnabled();

	//make version info from navigator.userAgent
	var searchFor = null;
	var n = null;
	if (this.type == "Netscape")
	{
		//check for version 7+
		searchFor = "Netscape/7";
		n = this.version.indexOf(searchFor);
		if(n >= 0)
		{
			//this is version 7 so what sub-version
			this.version = this.version.substring(n + searchFor.length - 1, this.version.length);
		}

		//check for safari
		searchFor = "Safari/";
		n = this.version.indexOf(searchFor);
		if(n >= 0)
		{
			//this is safari so what version
			this.version = this.version.substring(n + searchFor.length, this.version.length);
		}
		
		//check for version 6+
		searchFor = "Netscape6/";
		n = this.version.indexOf(searchFor);
		if(n >= 0)
		{
			//this is version 6 so what sub-version
			this.version = this.version.substring(n + searchFor.length, this.version.length);
		}
		
		//check for version 4.75
		searchFor = "Mozilla/4.7";
		n = this.version.indexOf(searchFor);
		if(n >= 0)
		{
			//this is version 4.7 so what sub-version
			this.version = this.version.substring(n + searchFor.length - 3, this.version.length);
			this.version = this.version.substring(0, this.version.indexOf(" "));
		}
		this.version = parseFloat(this.version);
	}	
	if(this.type == "Microsoft Internet Explorer")
	{
		//check for version 5+
		searchFor = "MSIE ";
		n = this.version.indexOf(searchFor);
		if(n >= 0)
		{
			//this is version 5+ so what sub-version
			this.version = this.version.substring(n + searchFor.length, this.version.length);
			this.version = this.version.substring(0, this.version.indexOf(";"));			 
		}
		this.version = parseFloat(this.version);	
	}

	//determine css extension
	if(this.IsIE() && this.version >=5)this.browserCode = "IE5";
	if(this.IsNS() && this.version >=6.1)this.browserCode = "NS6"
	if(this.IsPC() && this.browserCode)this.browserCode = this.browserCode + "P";
	if(this.IsMac() && this.browserCode)this.browserCode = this.browserCode + "M";
	if(this.browserCode)this.cssExt = this.browserCode + this.cssExt;
}

function SI_IsValidBrowser(browserCodeList){
	for(var i = 0; i < browserCodeList.length; i++)
		if(browserCodeList[i] == this.browserCode)return true;

	return false;
}

function SI_IsIE(){
	return (this.type == "Microsoft Internet Explorer");
}

function SI_IsNS(){
	return (this.type == "Netscape");
}

function SI_IsPC(){
	return (this.platform == "Win32");
}

function SI_IsMac(){
	return (this.platform.indexOf("Mac") != -1);
}

function SI_GetPlugIn(plugInName){
	for(var i = 0; i < this.plugins.length; i++)
	{
		var plugIn = this.plugins[i];
		if(plugIn.name == plugInName)return plugIn;
	}

	return null;	
}

function SI_HasPlugIn(plugInName){
	var plugIn = this.GetPlugIn(plugInName);
	if(plugIn)
		return plugIn.IsInstalled();
	else
		return false;
}

function SI_GetPage(url, source){
	if(!source)source = window;
	if(!url)url = source.location.href;
	var ar = url.split("/");
	var page = ar[ar.length - 1];
	if(page.indexOf("?") != -1)page = page.substring(0, page.indexOf("?"));
	return page;
}
	
function SI_GetURL(url, source){
	if(!source)source = window;
	if(!url)url = source.location.href;
	var ar = url.split("?");
	return ar[0];
}

function SI_GetQueryString(param, url, source){
	if(!source)source = window;
	if(!url)url = source.location.href;
	if(url.indexOf("?") == -1)return null;
	
	var queryString = url.substring(url.indexOf("?") + 1, url.length);
	queryString = queryString.replace(/&amp;/g, "%26amp;");
	if(param)
	{
		var ar = queryString.split("&");
		for(var i = 0; i < ar.length; i++)
		{
			var pv = ar[i];
			if(pv.indexOf(param) == 0)
			{
				var i = pv.indexOf("=");
				var v = pv.substring(i + 1, pv.length);
				return unescape(v);
			}
		}
		return null;
	}
	else
		return queryString;
}

function SI_UpdateQueryString(url, param, newVal){
	var qsValue = this.GetQueryString(param, url);
		
	if(qsValue != null)
	{
		var regExp = new RegExp(param + "=" + qsValue, "gi");
		return url.replace(regExp, param + "=" + newVal);
	}
	else
		return null;
}

function SI_SetCookie(name, value){
	document.cookie = name + "=" + value;
}

function SI_GetCookie(name){
	if(document.cookie.length > 0)
	{
		var i = document.cookie.indexOf(name + "=");
		if(i != -1)
		{
			i = i + name.length + 1;
			var e = document.cookie.indexOf(";", i);
			if(e == -1)e = document.cookie.length;
			return unescape(document.cookie.substring(i, e));       
		}
	}
	return null;
}

function SI_DelCookie(name){
	if (this.GetCookie(name))
  		document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function SI_CaptureEvent(e, source){
	if(!source)source = window;
	if(source.event)
		this.event = source.event;
	else
		this.event = e;
	
	if(this.IsIE())
	{
		this.mouseX = this.event.clientX + source.document.body.scrollLeft;
		this.mouseY = this.event.clientY + source.document.body.scrollTop;
	}
	else
	{
		this.mouseX = this.event.pageX;
		this.mouseY = this.event.pageY;
	}

	return this.event;
}

function SI_GetDocWidth(source){
	if(!source)source = window;
	var docWidth = null;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerWidth || window.innerHeight){ 
		docwidth = source.innerWidth; 
	} 
	//IE Mozilla 
	if (source.document.body.clientWidth || source.document.body.clientHeight){ 
		docwidth = source.document.body.clientWidth; 
	} 
	return docwidth;
}

function SI_GetDocHeight(source){
	if(!source)source = window;
	var docheight = null;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (source.innerWidth || source.innerHeight){ 
		docheight = source.innerHeight; 
	} 
	//IE Mozilla 
	if (source.document.body.clientWidth || source.body.clientHeight){ 
		docheight = source.body.clientHeight; 
	} 
	return docheight
}

function SI_GetScrollLeft(source){
	if(!source)source = window;

	if(source.document.body.scrollLeft)
		return source.document.body.scrollLeft;

	if(source.pageXOffset)
		return source.pageXOffset;

	return 0;
}

function SI_GetScrollTop(source){
	if(!source)source = window;

	if(source.document.body.scrollTop)
		return source.document.body.scrollTop;

	if(source.pageYOffset)
		return source.pageYOffset;

	return 0;
}


function SI_GetCSSStyleRule(objectType, styleID, source){
	if(!source)source = window;
	var styleSheets = source.document.styleSheets;
	for(var i = 0; i < styleSheets.length; i++)
	{
		var rules = 0;
		if(styleSheets[i].rules)rules = source.document.styleSheets[i].rules;
		if(styleSheets[i].cssRules)rules = source.document.styleSheets[i].cssRules;
		for(var j = 0; j < rules.length; j++)
		{
			if(objectType == "ID")
			{
				//PC
				if (rules[j].selectorText == '#' + styleID)
					return rules[j];

				//MAC
				if (rules[j].selectorText == '*#' + styleID)
					return rules[j];
			}
			if(objectType == "CLASS")
			{
				//PC
				if (rules[j].selectorText == '.' + styleID)
					return rules[j];
				
				//MAC
				if (rules[j].selectorText == '*.' + styleID)
					return rules[j];
			}
		}
	}
	
	return null;
}

function SI_GetMouseCoords(){
	return this.mouseX + "," + this.mouseY;
}

function SI_Dump(){
	document.write("BROWSER INFO" + "<br>");
	document.write("UserAgent: " + navigator.userAgent + "<br>");
	document.write("Platform: " + this.platform + "<br>");
	document.write("Type: " + this.type + "<br>");
	document.write("Version: " + this.version + "<br>");
	document.write("Platform: " + this.platform + "<br>");
	document.write("Java enabled: " + this.javaEnabled + "<br>");
	document.write("Browser code: " + this.browserCode + "<br>");
	document.write("CSS ext.: " + this.cssExt + "<br>");

	for(var i = 0; i < this.plugins.length; i++)
		this.plugins[i].Dump();
}

function SystemInfo(){
	//PROPERTIES
	this.type = null;
	this.version = null;
	this.platform = null;
	this.javaEnabled = false;
	this.plugins = [];
	this.event = null;
	this.mouseX = Number.NaN;
	this.mouseY = Number.NaN;
	this.browserCode = null;
	this.cssExt = ".css";
	
	this.errorCode = null;
	this.errorDescription = null;
		
	//METHODS
	this.Detect = SI_Detect;
	this.IsValidBrowser = SI_IsValidBrowser;
	this.IsIE = SI_IsIE;
	this.IsNS = SI_IsNS;
	this.IsPC = SI_IsPC;
	this.IsMac = SI_IsMac;
	this.GetPlugIn = SI_GetPlugIn;
	this.HasPlugIn = SI_HasPlugIn;
	this.GetPage = SI_GetPage;
	this.GetURL = SI_GetURL;
	this.GetQueryString = SI_GetQueryString;
	this.UpdateQueryString = SI_UpdateQueryString;
	this.SetCookie = SI_SetCookie;
	this.GetCookie = SI_GetCookie;
	this.DelCookie = SI_DelCookie;
	this.CaptureEvent = SI_CaptureEvent;
	this.GetDocWidth = SI_GetDocWidth;
	this.GetDocHeight = SI_GetDocHeight;
	this.GetScrollLeft = SI_GetScrollLeft;	
	this.GetScrollTop = SI_GetScrollTop;
	this.GetCSSStyleRule = SI_GetCSSStyleRule;
	this.GetMouseCoords = SI_GetMouseCoords;
	this.Dump = SI_Dump;
	
	//INITIALISATION
	this.Detect();
	this.plugins[0] = new FlashPlugIn();
}

//create instance for user and validate browser
var g_systemInfo = new SystemInfo();

var validBrowsers = ["IE5P", "NS6P", "IE5M", "NS6M"];
var validBrowser = false;
for(var i = 0; i < validBrowsers.length; i++)
	if(validBrowsers[i] == g_systemInfo.browserCode)validBrowser = true;

if(!document.getElementById)validBrowser = false;

if(!validBrowser)window.location.href = "_invalid_browser.htm";
//SYSTEM INFO
//*****************************************************************************************************
