/*
 * Browsers: IE 5+, Netscape 6+, Mozilla Firefox (all), Safari, Konqeror, Opera 4+
 * Notes: 
 *
 */


/******* BROWSER RECOGNITION *******/
/* Purpose: Grab all the information about the user
 * Usage: [variable] = new oBrowser();
 * Arguments: none
 * Returns: Object
 */
function oBrowser() {
	this.win = (navigator.platform=="Win32");
	this.mac = (navigator.platform=="MacPPC"||navigator.platform=="MacIntel");
	this.ver = navigator.appVersion;
	this.ua = navigator.userAgent;
	this.dom = document.getElementById;
	this.safari = (window.addEventListener && navigator.vendor == "Apple Computer, Inc.");
	this.ie7 = (this.ver.indexOf("MSIE 7")!=-1 && this.dom);
	this.ie6 = (this.ver.indexOf("MSIE 6")!=-1 && this.dom);
	this.ie5 = (this.ver.indexOf("MSIE 5")!=-1 && this.dom);
	this.ie4 = (document.all && !this.dom);
	this.ie = (this.ie5 || this.ie4 || this.ie6 ||this.ie7);
	this.ns7 = (this.ua.indexOf('Netscape/7')!=-1);
	this.ns6 = (this.dom && parseInt(this.ver)>=5);
	this.ns4 = (document.layers && !this.dom);
	this.ns = (this.ns4 || this.ns6 || this.ns7);
	this.op = window.opera || false;
	this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.ns7);
	this.bx = (this.ie5 || this.ns6 || this.ie6 || this.ns7);
	this.iWidth = 0;
	this.iHeight = 0;
	this.pLoaded = false;
	return this;
}
var browser = new oBrowser();
/******* END BROWSER RECOGNITION *******/


/******* SHORTCUTS *******/
var d = document;

/* Purpose: Get a DOM element
 * Usage: gE([String]);
 * Arguments: id string
 * Returns: Object
 */
function gE(e) { 
	return d.getElementById(e); 
}

var setOnce = true;
function setDomain() {
	if(setOnce) {
		setOnce = false;
	} else {
		return;
	}
	
	if(browser.ie) {
		try {
			var a = document.domain.split(".").reverse();
			if(isNaN(parseInt(a[0]))) {
				var b = [];
				for(var i=0; a[i]; i++) {
					b.push(a[i]); 
					if(a[i].length > 3) {
						break;
					}
				}
				document.domain = b.reverse().join(".");
			}
		} catch(e) { }
	}
}

/* Purpose: Get a querystring parameter variable value
 * Usage: getQS([String]);
 * Arguments: Parameter variable string
 * Returns: String
 */
function getQS(p) {
	setDomain();
	return new RegExp("[?&]+"+p+"=([^&$]*)", "gi").test(document.location.href) ? RegExp.$1 : "";
}

/**
 * Stop IE flicker
 */
try {
   document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
/******* END SHORTCUTS *******/


/******* OBJECT EXTENSIONS *******/
/* Patch IE 5.5 Array push method deficiency */
if(typeof Array.prototype.push != "function") {
	Array.prototype.push = function(o) {
		this[this.length] = o;
	};
}

/* Purpose: Converts all non-latin based characters to their ASCII entity value
 * Usage: [String].encode()
 * Arguments: none
 * Returns: String
 */
String.prototype.encode = function() {
	return this.replace(/([^\x01-\x7E])/g, function(s) { return "&#"+s.charCodeAt(0)+";"; });
};

/**
 * Converts all ASCII entity value characters into their unicode equivelant
 * @return (String)
 */
String.prototype.decode = function() {
	Number.prototype.toHex = function(pad) {
		var s = this.toString(16).toUpperCase();
		var v = "";
		if(typeof pad == "number") {
			while(v.length + s.length < pad) {
				v += "0";
			}
		}
		return v + s;
	};
	return this.replace(/(&#([^;]*);)/g, function(s) { return unescape("%u"+ Number(RegExp.$2).toHex(4)); });
};
/******* END EXTENSIONS *******/


/******* ONLOAD STACKER *******/
/* Purpose: Multiple window onload stacker
 * Usage: evt_load([Function]);
 * Arguments: Function
 * Returns: nothing
 */
function evt_load(fn) {
	var oldOnload = window.onload;
	if(typeof(window.onload) != "function") {
		window.onload = function() {
			if(typeof fn == "function") {
				fn();
			}
		};
	} else {
		window.onload = function() {
			oldOnload();
			if(typeof fn == "function") {
				fn();
			}
		};
	}
}
/******* END ONLOAD STACKER *******/

/******* MACROMEDIA FLASH FUNCTIONS *******/
/* Purpose: Check browser flash version
 * Usage: checkFlash([Number]);
 * Arguments: Flash version number to check for
 * Returns: Boolean
 */
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1){
      flashVer = 4;
   } else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1){
      flashVer = 3;
   } else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1){
      flashVer = 2;
   } else if ( isIE && isWin && !isOpera ){
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	var versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			var tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			var tempString        = tempArray[1];			// "2,0,0,11"
			var versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			var versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer)){
				return true;
			} else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision)){
					return true;
            }
			}
		}
		return false;
	}
}
var bFlash = (DetectFlashVer(9, 0, 0));
function detectFlash() {
	return bFlash;
}
/* End Flash Detection */

/* Purpose: Insert flash movie into document
 * Usage: showFlash([String], [Number], [Number], [String], [String], [String], [String|Object]);
 * Arguments: Movie URL string, width, height, window mode, background colour, movie variables, 
			  optional target for embed - id of HTML element or HTML object or no arg to write to document
 * Returns: None
 */
function insertFlash(movie, w, h, mode, bg, vars, target, replacementIMG, replacementURL) {
	if(bFlash) {
		var a = [["movie", movie], ["wmode", mode], ["bgcolor", bg], ["flashvars", vars]];
			
		var str = '<object type="application/x-shockwave-flash" data="'+ movie +'" width="' +w +'" height="'+ h +'">';
		for(var i=0; a[i]; i++) {
			if(a[i][1]) {
				str += '<param name="'+a[i][0]+'" value="'+a[i][1]+'" />';
			}
		}
		str += '</object>';
		
		if(!target || target == "undefined") { 
			d.write(str);
		} else if(target == "return string") { 
			return str;
		} else if(typeof target == "string") { 
			if(gE(target)) {
				gE(target).innerHTML = str;
			}
		} else if(typeof target == "object") { 
			target.innerHTML = str;
		}
	} else {
      if(replacementIMG && replacementURL){
         d.write("<a href="+ replacementURL +"><img src=\""+ replacementIMG +"\" width="+ w +" height="+ h +" border='0'></a>");
      }
   }
}
/******* END MACROMEDIA FLASH FUNCTIONS *******/

