var minFlashVersion = "6.0.65";

var isOpera=(navigator.userAgent.indexOf('Opera')!=-1);
var isIE=((navigator.appVersion.indexOf("MSIE") != -1) && !isOpera);
var isWindows=(navigator.platform.indexOf('Win')!=-1);
var isMac=(navigator.platform.indexOf('Mac')!=-1);
var isPower=(navigator.platform.indexOf('PPC')!=-1);

var detectableWithVB = false;
var pluginFlashInstalled = 0; 

function Detect_Flash()
{
   var flashVersion=minFlashVersion.split(".");
   pluginFlashInstalled = DetectFlashVer(parseInt(flashVersion[0]),parseInt(flashVersion[1]),parseInt(flashVersion[2])); 
}

function Reload_page()
{
   Detect_Flash();
   if (!pluginFlashInstalled)
     {
	 setTimeout("Reload_page();", 300);
     }	
    else 
     {
	 if(!isIE) navigator.plugins.refresh(true);
	 window.location.reload();
     }
}

function Install_Flash()
{
	var ref="";
	if (isMac)
	{
		if (isPower) ref="install_flash/flashplayer9r45_mac.dmg";
		 else ref="install_flash/flashplayer9r45_ub_mac.dmg";
	} 	else
	if (isWindows && isIE)
	{
		ref="install_flash/flashplayer9r45_winax.exe";
	}	else
	if (isWindows && !isIE)
	{
		ref="install_flash/flashplayer9r45_win.exe";
	}

	document.write('<br><br><br><br><br><a href="'+ref+'" target="_blank" title="У вас не установлен проигрыватель flash. Установите его, щелкнув по этой кнопке."><img src="js/install_flash.png" border="0" align="top"></a>');

	setTimeout("Reload_page();", 300);
}

function reloadPage()
{
	if(!isIE) navigator.plugins.refresh(true);
	window.location.reload();
}

function checkMinVersion(version,min,num)
{
	var installed=0;
	for (var i = 0; i < num; i++)
	{
		if(parseInt(version[i])>parseInt(min[i])) 
		{
			installed=1;
			break;
		}
		else if(parseInt(version[i])<parseInt(min[i]))
		{
			break;
		}
		else if(parseInt(version[i])==parseInt(min[i]) && i==num-1)
			installed=1;
	}
	return installed;
}


function IEGetSwfVer()
{
	flashVer=0;
		
	for(i=25;i>0 && flashVer==0;i--)
	{
		flashVer=VBGetSwfVer(i);
	}
	return flashVer;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer()
{
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	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;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// 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;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
}
 
// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
  	if (isIE && isWindows && !isOpera) {
		versionStr = IEGetSwfVer();
	} else {
		versionStr = JSGetSwfVer();		
	}

	//alert(versionStr);

	if (versionStr == -1 ) 
	{ 
		return false;
	} 
	else if (versionStr != 0) 
	{
		if(isIE && isWindows && !isOpera) {
			tempArray         = versionStr.split(" ");
			tempString        = tempArray[1];
			versionArray      = tempString .split(",");				
		} else {
			versionArray      = versionStr.split(".");
		}
		versionMajor      = versionArray[0];
		versionMinor      = versionArray[1];
		versionRevision   = versionArray[2];
			
		versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
		versionNum        = parseFloat(versionString);
    	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
			return true;
		} else {
			return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
		}
	}
	return (reqVer ? false : 0.0);
}



// Here we write out the VBScript block for MSIE Windows
if (isWindows && isIE) 
{
    document.writeln('<script language="VBscript" type="text/vbscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code \n');
    document.writeln('detectableWithVB = False \n');
    document.writeln('If ScriptEngineMajorVersion >= 2 then \n');
    document.writeln('  detectableWithVB = True \n');
    document.writeln('End If \n');

    document.writeln('\'Visual basic helper required to detect Flash Player ActiveX control version information \n');
    document.writeln('Function VBGetSwfVer(i) \n');
    document.writeln('  on error resume next \n');
    document.writeln('  Dim swControl, swVersion \n');
    document.writeln('  swVersion = 0 \n');
    document.writeln('  If detectableWithVB Then \n');
    document.writeln('		set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
    document.writeln('		If (IsObject(swControl)) then \n');
    document.writeln('			swVersion = swControl.GetVariable("$version") \n');
    document.writeln('		End If \n');
    document.writeln('  End If \n');
    document.writeln('  VBGetSwfVer = swVersion \n');
    document.writeln('End Function \n');
    document.writeln('</scr' + 'ipt>');
}