//#### FLASH FUNCTIONS ####

//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  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;
var isVista = (navigator.userAgent.indexOf("NT 6") != -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"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			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;
	}
}

function Flash(flash, id, width, height, color, version, transparent){
	this.width = width;
	this.height = height;
	this.flash = flash;
	this.id = id;
	this.color = color;
	this.transparent = transparent;
	this.flashvars = "";
	this.parameters = "";
	this.parametersEmbedded = "";
	this.version = version;
	
	this.useExpressInstall = false;
	
	// functions
	this.addFlashVar = addFlashVar;
	this.addParam = addParam;
	this.writeFlash = writeFlash;	
	this.expressInstall = expressInstall;
}

function expressInstall(flash){
	var ver = this.version.split(".");
	
	// Major version of Flash required
	var requiredMajorVersion = ver[0];
	// Minor version of Flash required
	var requiredMinorVersion = ver[1];
	// Minor version of Flash required
	var requiredRevision = ver[2];
	
	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(6, 0, 65);

	// Version check based upon the values defined in globals
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);	

	if(hasProductInstall && !hasReqestedVersion){
		// no express install on vista IE
		//if(isVista && isIE){
		//}else{
			this.useExpressInstall = true;
			// change source
			this.flash = flash;
				
			var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
			
			var MMredirectURL = "" + window.location;
			MMredirectURL = MMredirectURL.replace(/&/g,"%26");
			
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			var MMdoctitle = document.title;

			this.addFlashVar("MMredirectURL", MMredirectURL);
			this.addFlashVar("MMplayerType", MMPlayerType);
			this.addFlashVar("MMdoctitle", MMdoctitle);
		//}
	}
}

function addFlashVar(name, value){
	if(this.flashvars=="")
		this.flashvars = name + "=" + value;
	else
		this.flashvars += "&" + name + "=" + value;
}

function addParam(name, value){
	this.parameters += "<param name=\"" + name + "\" value=\"" + value + "\" />\n";
	this.parametersEmbedded += " " + name + "=\"" + value + "\"";	
}

function writeFlash(){
	var ver = this.version.split(".");
	var hasRightVersion = DetectFlashVer(ver[0],ver[1],ver[2]);
	
	if(hasRightVersion || this.useExpressInstall){
		if(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length){ 
			var mode = "";
			if(this.transparent)
				mode = "wmode=\"transparent\"";
			else
				mode = "bgcolor=\"" + this.color + "\"";

			var strOut = '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="' + this.id + '" name="' + this.id + '" src="' + this.flash + '" quality="high" scale="noscale" '+mode+' width="' + this.width + '" height="' + this.height +'" allowScriptAccess="sameDomain" FlashVars="' + this.flashvars + '"' + this.parametersEmbedded + ' />\n';						
		}	
		else{ // IE
			var strOut = '<object id="' + this.id + '" name="' + this.id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="' + this.width + '" height="' + this.height + '">\n'						
			+ '<param name="movie" value="' + this.flash + '" />\n'
			+ '<param name="allowScriptAccess" value="sameDomain" />\n'
			+ '<param name="scale" value="noscale" />\n'
			+ '<param name="quality" value="high" />\n';
		
			if(this.transparent)
				strOut += '<param name="wmode" value="transparent" />\n';
			else
				strOut += '<param name="bgcolor" value="' + this.color + '" />\n';

			
			strOut += this.parameters;
			strOut += '<param name="FlashVars" value="' + this.flashvars + '" />\n'
			strOut += '<\/object>\n';			
		}

		var obj = document.getElementById(this.id+"_alt");
		
		if(obj){
			obj.innerHTML = "";
			obj.style.display = "none";
		}	
		
		//alert(strOut);	
		document.write(strOut);
	}
}

//#### GENERAL FUNCTIONS ####

function doPrint(){
	if ((window.print) && (document.all)){
		window.print();
		//window.close();
	} else if (window.print) {
		window.print();
	} else if ((document.all) && !(navigator.userAgent.indexOf("Mac") != -1)) {			
		var printWindowObject = "<object id='printWindowObject1' width=0 height=0 classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>";
		document.body.insertAdjacentHTML("BeforeEnd",printWindowObject);
		window.document.printWindowObject1.ExecWB(6,1);
		//ID=window.setTimeout("window.close();",100);
	}

}

function $(id){
	return document.getElementById(id);
}
 
function openPopup(url,pwidth,pheight){
	var posLeft = (parseInt(screen.width)/2) - (parseInt(pwidth)/2); 
	var posTop = ((parseInt(screen.height)/2) - (parseInt(pheight)/2)) - 50;
 
	newwindow = window.open(url,null,'toolbar=0,menubar=0,location=0,directories=0,status=0,resizable=0,scrollbars=1,HEIGHT='+pheight+',WIDTH='+pwidth+',left='+posLeft+',top='+posTop);
	if (window.focus)
		newwindow.focus();
}

function openQuickTour(url,pwidth,pheight){
	var posLeft = (parseInt(screen.width)/2) - (parseInt(pwidth)/2); 
	var posTop = ((parseInt(screen.height)/2) - (parseInt(pheight)/2)) - 50;
 
	newwindow = window.open(url,null,'toolbar=0,menubar=0,location=0,directories=0,status=0,resizable=0,scrollbars=0,HEIGHT='+pheight+',WIDTH='+pwidth+',left='+posLeft+',top='+posTop);
	if (window.focus)
		newwindow.focus();
}

function preload(imgObj,imgSrc){
	if(document.images){
		eval(imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}

var isIE6 = false;
if(navigator.userAgent.indexOf("MSIE 6") != -1)
	isIE6 = true;

function imgSwap(imgName, newImgSource){
	if($(imgName)){
		if(!isIE6){
			eval("document.getElementById('" + imgName + "').src = " + newImgSource + ".src");
		}else{
			$(imgName).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + eval(newImgSource + ".src") + "', sizingMethod='image')";
		}
	}
}

function doChangeBorder(id){
/*		
	var obj = document.getElementById(id);
	if(obj){
		if(obj.className == "cBoxA")
			obj.className = "cBoxB";
		else
			obj.className = "cBoxA";
	}
*/			
}

//#### MODAL LAYER ####

var Modal = new function() {

	this.show = function(content, width, height) {
		scroll(0,0);	
				
		// Cut window and remove scrollbars
		var body = document.getElementsByTagName('body')[0];
		body.style.height = "100%";
		body.style.overflow = "hidden";
  
		var html = document.getElementsByTagName('html')[0];
		html.style.height = "100%";
		html.style.overflow = "hidden";

		// Create opacity overlay
		this.ol = el = document.createElement('DIV');
		el.style.width = '110%';
		el.style.height = '100%';
		el.style.position = 'absolute';
		el.style.backgroundColor = 'gray';
		el.style.filter = 'alpha(opacity=65)';
		el.style.opacity = '0.65';
		el.style.left = -document.body.style.marginLeft;
		el.style.top = -document.body.style.marginTop;
		el.style.zIndex = 10000;
		el.onclick = function() {Modal.close();};
		el.id = 'Modal_overlay';
		document.body.insertBefore(el, document.body.childNodes[0]);

		// Create window		
		this.ow = el = document.createElement('DIV');
		el.innerHTML = content;
		el.style.width = width + 'px';
		el.style.height = height + 'px';
		el.style.position = 'absolute';
		el.style.left = parseInt((parseInt(document.body.clientWidth)-width)/2) + "px";
		el.style.top = '100px';
		el.style.zIndex = 10001;
		el.id = 'Modal_window';
		document.body.insertBefore(el, document.body.childNodes[0]);

		this.handleSelects(false);

		document["onkeydown"] = Modal.keyPress;
		if (document.getElementById('Modal_focus'))
			document.getElementById('Modal_focus').focus();
	}

	this.close = function()
	{
		if (this.ol)
		{
			document.body.removeChild(document.getElementById('Modal_overlay'));
			document.body.removeChild(document.getElementById('Modal_window'));
			this.ol = null;
			this.ow = null;
			document["onkeydown"] = null;
			
			// Cut window and remove scrollbars
			var body = document.getElementsByTagName('body')[0];
			body.style.height = '';
			body.style.overflow = '';
  
			var html = document.getElementsByTagName('html')[0];
			html.style.height = '';
			html.style.overflow = '';

			this.handleSelects(true);
		}
	}
	
	this.keyPress = function(e) {
		if (!e)
			e=event;
		var key = e.keyCode;
		
		switch(key)
		{
			case 9:
				return false;

			case 27:
				Modal.close();
				return false;
			
			default:
				break;
		}
		return true;
	}

	this.handleSelects = function(show)
	{
		if (navigator.appVersion.match(/\bMSIE\b/))
		{
			var selects = document.getElementsByTagName("select");
			
			for(var i=0;i<selects.length;i++)
				selects[i].style.visibility = show?"":"hidden";
		}
	}

}
