
//	Flash-Detection und Gabelfunktion
//	XHTML-Ausgabe, V-1.4
//	pepperzak, aw 2006-10-10

//	v1.4	Neue Funktion "Show_Flash_2 ();"
//	v1.3	"WMODE"-Tag abhängig von "transparent" auskommentiert!

/*
	Beispielhafte Aufrufe:

	---
	
	Minimal-Syntax:		Show_Flash ("name.swf?optParam1=1&optParam2=2", 1000, 620);
	
	- Dateiname mit optionalen Parametern
	- Breite
	- Hoehe
	
	Ist die installierte FlashPlugin-Version zu klein, wird nichts ausgegeben
	
	---

*/


var gFlashNeeded;
if (typeof (gFlashNeeded) == "undefined") gFlashNeeded = 7;

var gIsWin;
var gIsMac;
var gIsIE;

var gBrowserVersion;

var gFlashVersion;
var gFlashDetectable;
var gFlashInstalled;
var gFlashActive;
var gFlashImplementation;
var vbChecked;
var vbFlashInstalled;
var vbFlashVersion;
var gFlashOK;

Get_Environment();

//	----------

function Get_Environment () {

	var tAppVersion = navigator.appVersion;
	var tUserAgent = navigator.userAgent;
	
	gIsWin  = (tAppVersion.indexOf("Win") != -1) ? true : false;
	gIsMac  = (tAppVersion.indexOf("Mac") != -1) ? true : false;
	gIsIE	= (document.all)?true:false;
	
	var CheckMSIE = tUserAgent.indexOf("MSIE");
	
	if (CheckMSIE > -1) {
		Short = tUserAgent.substr(CheckMSIE+5,100);
		gBrowserVersion = Short.substr(0,Short.indexOf(";"));
	}

	if (gIsWin && gIsIE && typeof (vbChecked) == "undefined") {
	
		vbChecked = true;
		vbFlashInstalled = false;
		vbFlashVersion = false;
		
		document.writeln ('<script language="VBScript">');
		document.writeln ('Private i, ObjAct');
		document.writeln ('On Error Resume Next');
		document.writeln ('vbFlashInstalled = False');
		document.writeln ('vbFlashVersion = False');
		document.writeln ('For i = 20 To 1 Step -1');
		document.writeln ('Set ObjAct = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)');	// Anfuehrungszeichen nicht tauschen!
		document.writeln ('vbFlashInstalled = IsObject(ObjAct)');
		document.writeln ('If vbFlashInstalled Then');
		document.writeln ('vbFlashVersion = CStr(i)');
		document.writeln ('Exit For');
		document.writeln ('End If');
		document.writeln ('Next');
		document.writeln ('</script>');
	}

	gFlashDetectable = true;
	gFlashInstalled = false;
	gFlashActive = false;
	gFlashVersion = -1;
	gFlashImplementation = -1;

	if (vbFlashInstalled) {
	
		gFlashInstalled = true;
		gFlashActive = gFlashInstalled;
		gFlashVersion = 1*vbFlashVersion;
		gFlashImplementation = "ActiveX";
		
	} else if (navigator.plugins && navigator.plugins.length > 0) {
	
		gFlashImplementation = "Plugin";
		if (navigator.plugins["Shockwave Flash"]) {
		
			gFlashInstalled = true;
			var StringTmp = navigator.plugins["Shockwave Flash"].description.split(" ");

			for (var i=0; i<StringTmp.length; ++i) {
			
				if (isNaN(parseInt(StringTmp[i]))) continue;
				gFlashVersion = 1*StringTmp[i];
			}
		}

		if (navigator.mimeTypes["application/x-shockwave-flash"])
 			gFlashActive = (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin != null);
	}
	
	if (gIsIE && gIsMac && (1*gBrowserVersion) < 5) gFlashDetectable = false;
	if (gFlashVersion == -1) gFlashImplementation = -1;

	gFlashOK = (gFlashVersion >= 1*gFlashNeeded);
	if (!gFlashActive || !gFlashDetectable) gFlashOK = false;

}

//	----------

function Check_Flash (versOpt) {

	if (noValue (versOpt)) versOpt = gFlashNeeded;

	return (versOpt <= gFlashVersion);

}

//	----------

function Show_Flash_2 (FileAndParams, XSize, YSize, VersionOpt, BGColorOpt, NoFlashStringOpt) {

	//	Modifizierte Version von Show_Flash.
	//	Als noFLashString kann alles mögliche übergeben werden:
	//	Bild: '<img src="./_data/_images/_web/noFlash.gif" alt="noFlash" width="120" height="100" />'
	//	URL-Aufruf: '<script>location.href="http://www.noFLash.de";<\/script>'

	if (noValue (VersionOpt)) VersionOpt = gFlashNeeded;

	if (VersionOpt > gFlashVersion) {
		document.write (NoFlashStringOpt);
		return false;
	}

	if (typeof(FileAndParams) == 'undefined') {	
		document.write('<b>Show_Flash</b>: keine swf-Datei angegeben');
		return false;
	}

	if (typeof(XSize) == 'undefined' || typeof(YSize) == 'undefined') {
		document.write('<b>Show_Flash</b>: keine Gr&ouml;&szlig;enangabe');
		return false;	}

	var BGMode;
	
	if (typeof (BGColorOpt) == 'undefined') {
		BGColorOpt = '#ffffff';
		BGMode = 'opaque';
	} else if (BGColorOpt == 'transparent') {
		BGColorOpt = '#ffffff';
		BGMode = 'transparent';
	} else {
		BGMode = 'opaque';
	}
	
	var FXSize = XSize;
	var FYSize = YSize;

	FileAndParams += (FileAndParams.indexOf('?') == -1) ? '?' : '&amp;';
	FileAndParams += 'js=1';
	
	var FlLoop		= 'true';
	var FlMenu		= 'false';
	var FlQuality	= 'high';
	var FlAlign		= 'lt';
	var FlScale		= 'noscale';
	var FlashString = '';
	
	if (FXSize == '100%' || FYSize == '100%') FlScale = 'showAll';//'showAll';'scaleToFit'
	
	FlashString	+= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	FlashString	+= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + VersionOpt + ',0,0,0" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '"> ';
	FlashString	+= '<param name="movie" value="' + FileAndParams + '" /> ';
	FlashString	+= '<param name="loop" value="' + FlLoop + '" /> ';
	FlashString	+= '<param name="menu" value="' + FlMenu + '" /> ';
	FlashString	+= '<param name="quality" value="' + FlQuality + '" /> ';
	FlashString	+= '<param name="scale" value="' + FlScale + '" /> ';
	FlashString	+= '<param name="salign" value="' + FlAlign + '" /> ';
	if (BGMode == 'transparent') FlashString += '<param name="wmode" value="' + BGMode + '" /> ';
	FlashString	+= '<param name="bgcolor" value="' + BGColorOpt + '" /> ';
	FlashString	+= '<embed src="' + FileAndParams + '" ';
	FlashString	+= 'loop="' + FlLoop + '" ';
	FlashString	+= 'menu="' + FlMenu + '" ';
	FlashString	+= 'quality="' + FlQuality + '" ';
	FlashString	+= 'scale="' + FlScale + '" ';
	FlashString	+= 'salign="' + FlAlign + '" ';
	if (BGMode == 'transparent') FlashString += 'wmode="' + BGMode + '" ';
	FlashString	+= 'bgcolor="' + BGColorOpt + '" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '" ';
	FlashString	+= 'type="application/x-shockwave-flash" ';
	FlashString	+= 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	FlashString	+= '</embed></object>';

	document.write (FlashString);
	return false;

}

//	----------

function Show_Flash (FileAndParams, XSize, YSize, VersionOpt, BGColorOpt, ImageOpt, URLOpt, TrgtOpt) {

	if (noValue (VersionOpt)) VersionOpt = gFlashNeeded;

	if (VersionOpt > gFlashVersion) {

		if (typeof(ImageOpt) == 'string' && ImageOpt!='') {
			Build_Img (ImageOpt, XSize, YSize, URLOpt, TrgtOpt);
		} else if (typeof(URLOpt) == 'string' && URLOpt!='') {
			location.href = URLOpt;
		}
		
		return false;
	}

	if (typeof(FileAndParams) == 'undefined') {	
		document.write('<b>Show_Flash</b>: keine swf-Datei angegeben');
		return false;
	}

	var BGMode;

	if (typeof(XSize) == 'undefined' || typeof(YSize) == 'undefined') {
		document.write('<b>Show_Flash</b>: keine Gr&ouml;&szlig;enangabe');
		return false;	}
	
	if (typeof (BGColorOpt) == 'undefined') {
		BGColorOpt = '#ffffff';
		BGMode = 'opaque';
	} else if (BGColorOpt == 'transparent') {
		BGColorOpt = '#ffffff';
		BGMode = 'transparent';
	} else {
		BGMode = 'opaque';
	}
	
	var FXSize = XSize;
	var FYSize = YSize;
/*	
	if (FXSize == '100%') FXSize = window.innerWidth;
	if (FYSize == '100%') FYSize = window.innerHeight;
	if (isNaN(FXSize) || typeof(FXSize)=='undefined' || FXSize==0) FXSize = document.body.offsetWidth;
	if (isNaN(FYSize) || typeof(FYSize)=='undefined' || FYSize==0) FYSize = document.body.offsetHeight;
*/	
	FileAndParams += (FileAndParams.indexOf('?') == -1) ? '?' : '&amp;';
	FileAndParams += 'js=1';
	
	var FlLoop		= 'true';
	var FlMenu		= 'false';
	var FlQuality	= 'high';
	var FlAlign		= 'lt';
	var FlScale		= 'noscale';
	var FlashString = '';
	
	if (FXSize == '100%' || FYSize == '100%') FlScale = 'showAll';//'showAll';'scaleToFit'
	
	FlashString	+= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	FlashString	+= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + VersionOpt + ',0,0,0" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '"> ';
	FlashString	+= '<param name="movie" value="' + FileAndParams + '" /> ';
	FlashString	+= '<param name="loop" value="' + FlLoop + '" /> ';
	FlashString	+= '<param name="menu" value="' + FlMenu + '" /> ';
	FlashString	+= '<param name="quality" value="' + FlQuality + '" /> ';
	FlashString	+= '<param name="scale" value="' + FlScale + '" /> ';
	FlashString	+= '<param name="salign" value="' + FlAlign + '" /> ';
	if (BGMode == 'transparent') FlashString += '<param name="wmode" value="' + BGMode + '" /> ';
	FlashString	+= '<param name="bgcolor" value="' + BGColorOpt + '" /> ';
	FlashString	+= '<embed src="' + FileAndParams + '" ';
	FlashString	+= 'loop="' + FlLoop + '" ';
	FlashString	+= 'menu="' + FlMenu + '" ';
	FlashString	+= 'quality="' + FlQuality + '" ';
	FlashString	+= 'scale="' + FlScale + '" ';
	FlashString	+= 'salign="' + FlAlign + '" ';
	if (BGMode == 'transparent') FlashString += 'wmode="' + BGMode + '" ';
	FlashString	+= 'bgcolor="' + BGColorOpt + '" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '" ';
	FlashString	+= 'type="application/x-shockwave-flash" ';
	FlashString	+= 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	FlashString	+= '</embed></object>';

	document.write (FlashString);
	return false;
}

//	----------

function Build_Img (File, XSize, YSize, URLOpt, TrgtOpt) {

	if (typeof(File) != 'string' || File == '') return false;
	
	var HRef1 = '';
	var HRef2 = '';
	var Trgt  = '';
	
	if (typeof(TrgtOpt) == 'string' && TrgtOpt != '') Trgt = 'target="' + TrgtOpt + '"';
	
	if (typeof(URLOpt) == 'string' && URLOpt != '') {
	
		HRef1 = '<a href="' + URLOpt + '" ' + Trgt + '>';
		HRef2 = '</a>';
	}
	
	var ImgString = HRef1 + '<img src="' + File + '" alt="" width="' + XSize + '" height="' + YSize + '" border="0" align="top" usemap="#noflash" />' + HRef2;
	document.write (ImgString);
	
	//alert (ImgString);
	
	return false;
}

//	----------

function SpecialCharsToFlash6 (SrcTxt) {

	//	Ersetzt die HTML-Entities durch Flash 6-konforme 2-Byte-Maskierungen
	
	SrcTxt = Replace (SrcTxt, '&auml;','%C3%A4');
	SrcTxt = Replace (SrcTxt, '&ouml;','%C3%B6');
	SrcTxt = Replace (SrcTxt, '&uuml;','%C3%BC');
	SrcTxt = Replace (SrcTxt, '&Auml;','%C3%84');
	SrcTxt = Replace (SrcTxt, '&Ouml;','%C3%96');
	SrcTxt = Replace (SrcTxt, '&Uuml;','%C3%9C');
	SrcTxt = Replace (SrcTxt, '&szlig;','%C3%9F');
	
	return (SrcTxt);
}

//	----------

function Replace (SrcTxt, OldStr, NewStr) {

	//	Ersetzt einen Teil-String
	
	while (SrcTxt.indexOf(OldStr) != -1) {
	
		SrcTxt = SrcTxt.substring (0,SrcTxt.indexOf(OldStr)) + NewStr + SrcTxt.substring (SrcTxt.indexOf(OldStr) + OldStr.length ,SrcTxt.length); 
	}

	return (SrcTxt);
}

//	----------

function noValue (varToCheck) {
	return (varToCheck == null || varToCheck == '');
}

//	----------

function isValue (varToCheck) {
	return !(varToCheck == null || varToCheck == '');
}

//	----------

function isString (varToCheck) {

	return (typeof(varToCheck) == 'string' && varToCheck != '');
}