//	enercity
//	Flash-Detection und Gabelfunktion
//	aw - pepperzak, flash.js - Version: Original 2004-06-06

//  2004-05-13: bs - swh, Ergaenzung der Variablen mn_path
//	2005-01-20: aw - pepperzak, Schutz vor doppeltem Aufruf integriert
//	2005-04-26: aw - pepperzak, "Show_Flash"-Syntax an "Show_Flash_Menu" angeglichen

if (typeof (gFlashNeeded) == "undefined") gFlashNeeded = 6;

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 () {

	gAppVersion = navigator.appVersion;
	gUserAgent = navigator.userAgent;
	
	gIsWin  = (gAppVersion.indexOf("Win") != -1) ? true : false;
	gIsMac  = (gAppVersion.indexOf("Mac") != -1) ? true : false;
	gIsIE	= (document.all)?true:false;
	
	CheckMSIE = gUserAgent.indexOf("MSIE");
	
	if (CheckMSIE > -1) {
		Short = gUserAgent.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 = 10 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 Show_Flash (FileAndParams, XSize, YSize, VersionOpt, BGColorOpt, ImageOpt, URLOpt, TrgtOpt) {

	if (typeof(VersionOpt) == 'undefined') VersionOpt = 6;
	
	if (VersionOpt > gFlashVersion) {
		if (typeof(ImageOpt) == 'string' && ImageOpt!='') Build_Img (ImageOpt, XSize, YSize, URLOpt, TrgtOpt);
		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;	}
	
	if (typeof(BGColorOpt) == 'undefined') {
		BGColorOpt = '#ffffff';
		BGMode = 'opaque';
	} else if (BGColorOpt == 'transparent') {
		BGColorOpt = '#ffffff';
		BGMode = 'transparent';
	} else {
		BGMode = 'opaque';
	}
	
	FXSize = XSize;
	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) ? '?' : '&';
	FileAndParams += 'js=1';
	if (this["mn_path"] != null) FileAndParams = this["mn_path"] + FileAndParams;
	
	FlLoop		= 'true';
	FlMenu		= 'false';
	FlQuality	= 'high';
	FlAlign		= 'lt';
	FlScale		= 'noscale';
		
	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 + '" /> ';
	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 + '" ';
	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);
}

//	----------

function Build_Img (File, XSize, YSize, URLOpt, TrgtOpt) {

	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">' + HRef2;
	document.write (ImgString);
}

//	----------

function Show_Flash_Menu (MNum, ColOpt) {

	//	Generalisierte Menuefunktion

	if (typeof(MNum) != "number") {

		document.write ("<b>FEHLER Flash-Aufruf: Nummer des Men&uuml;s nicht &uuml;bergeben!</b>");
		return false;
	}
	
	if (typeof(ColOpt) != "string")
		BGCol = "#ee0000";
	else
		BGCol = "#ffffff";


	MenuAct = this["mn_path"] + "menu_" + MNum;
	MStr = "mn" + MNum;
	MAlt = Check_Var (MStr + "_alt");
	if (MAlt == false) MAlt = "FEHLER Keine DIV-Alternative definiert!";
	
	ResStr = "";

	if (this[MStr + "_t1"] == null || this[MStr + "_u1"] == null) gFlashOK = false;
	
	if (gFlashOK) {
	
		ResStr += '<div id="fmPos' + MNum + '">';
		ResStr += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		ResStr += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '; 
		ResStr += 'id="' + MenuAct + '" ';
		ResStr += 'width="100%" ';
		ResStr += 'height="100%">'; 
		
		ResStr += '<param name="movie" value="' + MenuAct + '.swf?js=1';

		if (Check_Var (MStr + '_sel') != false) 	ResStr += ('&sel=' + Check_Var (MStr + '_sel'));
		if (Check_Var ('gSound') != false) 	ResStr += ('&snd=' + Check_Var ('gSound'));
		
		for (i=1; i<11; i++) {
		
			if (Check_Var (MStr + '_n' + i) != false) 	ResStr += ('&n' + i + '=' + Check_Var (MStr + '_n' + i));
			if (Check_Var (MStr + '_t' + i) != false) 	ResStr += ('&t' + i + '=' + SpecialCharsToFlash6 (Check_Var (MStr + '_t' + i)));
			if (Check_Var (MStr + '_u' + i) != false) 	ResStr += ('&u' + i + '=' + Check_Var (MStr + '_u' + i));
		}
	
		ResStr += '" />';
		ResStr += '<param name="scale" value="showAll" />';
		ResStr += '<param name="salign" value="lt" />';
		ResStr += '<param name="bgcolor" value="' + BGCol + '" />';
		

		ResStr += '<embed src="' + MenuAct + '.swf?js=1';

		if (Check_Var (MStr + '_sel') != false) ResStr += ('&sel=' + Check_Var (MStr + '_sel'));
		if (Check_Var ('gSound') != false) 	ResStr += ('&snd=' + Check_Var ('gSound'));
		
		for (i=1; i<11; i++) {

			if (Check_Var (MStr + '_n' + i) != false) 	ResStr += ('&n' + i + '=' + Check_Var (MStr + '_n' + i));
			if (Check_Var (MStr + '_t' + i) != false) 	ResStr += ('&t' + i + '=' + SpecialCharsToFlash6 (Check_Var (MStr + '_t' + i)));
			if (Check_Var (MStr + '_u' + i) != false) 	ResStr += ('&u' + i + '=' + Check_Var (MStr + '_u' + i));
		}

		ResStr += '" ';
		ResStr += 'width="100%" ';
		ResStr += 'height="100%" ';
		ResStr += 'name="' + MenuAct + '" ';
		ResStr += 'scale="showAll" ';
		ResStr += 'salign="lt" ';
		ResStr += 'bgcolor="' + BGCol + '" ';
		ResStr += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
		ResStr += '</embed>';
		ResStr += '</object>';
		
		ResStr += '</div>';

	} else {

		ResStr = MAlt;
	}

	document.write (ResStr);

}

//	----------

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 Check_Var (VarName) {

	//	Prueft, ob die Variable vorhanden ist

	if (typeof(this[VarName]) != "undefined")
		return (this[VarName]);
	else
		return false;
}

//	----------
