var g_showFlashes = new Array();
var g_showFlashSniffer = true;
var g_FlashSnifferActive = false;
var g_clientFlashSet = false;

function GetImageObj(sText, sStyle, lMouseOver)
{
	var oImage = new Image();
	var RenderText=sText;
	RenderText=ReplaceAll(RenderText, "<br />", "\\n");
	RenderText=ReplaceAll(RenderText, "<br>", "\\n");
	RenderText=ReplaceAll(RenderText, "&amp;", "&");
	oImage.src = g_global + "render.pcp?text=" + urlEncoded(RenderText) + "&" + sStyle + "&Theme="+g_theme;
	if( lMouseOver ) {oImage.setAttribute("onmouseover", "SetMouseover(this)");oImage.setAttribute("onmouseout", "SetMouseover(this)");}

	sText=ReplaceAll(sText, "<br />", " ");
	sText=ReplaceAll(sText, "<br>", " ");
	sText=ReplaceAll(sText, "\\n", " ");
	sText=ReplaceAll(sText, "&amp;", "&");

	oImage.alt = sText;
	oImage.title = sText;
	oImage.border = "0";
	oImage.style.border = "0px solid";
	return(oImage);
}

function ReplaceAll(Text, search, replace)
{
	while(Text.indexOf(search)>0)
	{
		Text=Text.replace( search, replace);
	}
	return(Text);
}
function Lupe(cImage, iHeight, iWidth)
{
	var cUrl="", Param;
	if(cImage.toUpperCase().indexOf("URL=")>0)
		{cUrl='/bigpicture.aspx?'+cImage;}
	else if(cImage.substr(0,1)=="/"||cImage.substr(0, 3).toUpperCase()=="%2F")
		{cUrl='/bigpicture.aspx?url='+cImage;}
	else if(cImage.substr(0,4).toUpperCase()=="HTTP")
		{cUrl='/bigpicture.aspx?url='+cImage;}
	else if(cImage.substr(0,5).toUpperCase()=="PARAM")
		{
			Param=decodeURIComponent(cImage.substr(5));
			if(Param.substr(0,1).toUpperCase()==":"){Param=Param.substr(1);}
			if(Param.substr(0,1).toUpperCase()=="&"){Param="?"+Param.substr(1);}
			cUrl='/bigpicture.aspx'+Param;
		}
	else
		{cUrl='/bigpicture.aspx?url=/Global/vw/Files/Images/Specials/CarInfo/'+cImage;}
	if(!iWidth){iWidth=640;}
	if(!iHeight){iHeight=570;}
	window.open( cUrl, 'bigpic', 'width='+iWidth+',height='+iHeight );
}

function sendEvent(obj,typ,prm) { 
	if (eval(document.getElementById(obj)))
	{
		document.getElementById(obj).sendEvent(typ,prm); 
	}
}

function openWindow(url, target, width, height, centered) {
    if (centered == true && (navigator.appName.indexOf("Netscape") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )
        || (navigator.appName.indexOf("Microsoft Internet Explorer") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )) {
        var w = (screen.width/2)-(width/2); 
        var h = (screen.height/2)-(height/2); 
        var parameter = "scrollbars=yes,resizable=1";
        
        if (width != 0) {
            parameter += ',width=' + width + ', screenX=' + w + ',left=' + w;
        }
        if (height != 0) {
            parameter += ',height=' + height + ', screenY=' + h + ',top=' + h;
        }
    } else {
        var parameter = "scrollbars=yes,resizable=1";
        if (width != 0) {
            parameter += ',width=' + width;
        }
        if (height != 0) {
            parameter += ',height=' + height;
        }
    }
    var win = window.open(url, target, parameter);
    if (win) {
        win.focus();
    }
}


function OpenKonfigurator(Haendlerid)
{
	window.open('http://ak4-de.audi.de/entry.do?carline=a4limo&partnerid='+Haendlerid,'','scrollbars=yes,resizable=yes,width=802,height=602');
}

function OpenNewPage(oLink)
{
	window.open(oLink.href);
	return false;
}

function crossboxRouteSubmit()
{
	var oObj=document.getElementById("HaendlerID"), HaenderlID='';
	if(oObj){HaenderlID=oObj.value;}
	return crossboxRouteSubmitEnter(this, event, 'http://194.25.187.67/Audi/eingabe.asp',HaenderlID,'Straße','PLZ','Stadt',true);
}
function crossboxopenRoute()
{
	var oObj=document.getElementById("HaendlerID"), HaenderlID='';
	if(oObj){HaenderlID=oObj.value;}
	return openRoute('http://194.25.187.67/Audi/eingabe.asp',HaenderlID,'Straße','PLZ','Stadt',true);
}
function crossboxExtSearch(Haendlerid)
{
	cms_openWindow('http://194.25.187.67/Audi/eingabe.asp?ID='+Haendlerid,'_blank','status=no,toolbar=no,location=no,scrollbars=yes,resizable=yes',null,670,545);
	return false;
}

function OpenWerkstattmodul(FileUri)
{
	window.open(FileUri,"serviceappoint", "width=500,height=500,scrollbars=yes");
}

function showKVFlash( url, width, height, flashbg, outerHeight, marginTop )
{
	var iI = document.getElementById( 'introImage' );
	if(iI)
	{
		var innerHTML = iI.innerHTML;
		iI.innerHTML = "<div style=\"width:" + width + "px;height:" + outerHeight + "px;background-color:" + flashbg + ";vertical-align:middle;align:center;padding-top:" + marginTop + "px\" id=\"innerIntroImage\">" + innerHTML + "</div>";
		showSnifferFlash( url, 'innerIntroImage', width, height, '7', flashbg, 'loop=true,menu=true,quality=high,wmode=opaque', '');
	}
}
function checkFlash()
{
	if( g_showFlashSniffer && ! g_FlashSnifferActive && ! g_clientFlashSet )
	{
		if( document.getElementById("checkflash") )
		{
			g_FlashSnifferActive = true;
			/*showFlash( g_global + 'sniffer.swf', "checkflash", 1, 1, "7" );*/
			showFlash( g_global + 'sniffer.swf', "checkflash", 1, 1, "7" );
			setTimeout( "setClientFlashDisabled(true)", 2500 );
		}
		else
		{
			if(!document.getElementById("NoCheckFlash"))
			{
				setTimeout( "checkFlash()", 250 );
			}
		}
	}
}
function showFlash( url, id, width, height, version, bgcolor, playerparamstr, flashparamstr )
{
	var fo = new SWFObject(url, id + "_flash", width, height, version, bgcolor);
	if (playerparamstr != undefined)
	{
		var playerparams = playerparamstr.split(",");
		for (var i=0; i < playerparams.length; i++ )
		{
			var param = playerparams[i].split("=");
			if( param[1] != "=undefined" )
			{
				fo.addParam(param[0], param[1]);
			}
		}
	}
	if (flashparamstr != undefined)
	{
		var flashparams = flashparamstr.split(",");
		for (var i=0; i < flashparams.length; i++ )
		{
			var param = flashparams[i].split("=");
			if( param[1] != "=undefined" ) 
			{
				fo.addVariable(param[0], param[1]);
			}
		}
	}
	return fo.write(id);
}
function setClientFlashDisabled( isDisabled )
{
	if( isDisabled && ! g_clientFlashSet )
	{
		g_clientFlashSet = true;
		/* update server */
		tellServerClientFlashAbility( false );
	}

}

function setClientFlashEnabled( isEnabled )
{
	if( isEnabled )
	{
		g_clientFlashSet = true;

		/*
		show all flashes
		*/
		var f;
		for( f in g_showFlashes )
		{
			showFlash(
				g_showFlashes[f][ "url" ],
				g_showFlashes[f][ "id" ],
				g_showFlashes[f][ "width" ],
				g_showFlashes[f][ "height" ],
				g_showFlashes[f][ "version" ],
				g_showFlashes[f][ "bgcolor" ],
				g_showFlashes[f][ "playerparamstr" ],
				g_showFlashes[f][ "flashparamstr" ]
			);
		}
		/* update server */
		tellServerClientFlashAbility( true );
	}
}

function tellServerClientFlashAbility( isEnabled )
{
	if( isEnabled )
	{
		createCookie( "flash", "true" );
	}
	else
	{
		createCookie( "flash", "false" );
	}
}
function showSnifferFlash( url, id, width, height, version, bgcolor, playerparamstr, flashparamstr )
{
	var supportsFlash = readCookie( "flash" ) == "true";
	if( supportsFlash )
	{
		showFlash( url, id, width, height, version, bgcolor, playerparamstr, flashparamstr );
	}
	else
	{
		g_showFlashSniffer = true;
		if( url && id )
		{
			g_showFlashes[ id ] = new Array();
			g_showFlashes[ id ][ "url" ] = url;
			g_showFlashes[ id ][ "id" ] = id;
			g_showFlashes[ id ][ "width" ] = width;
			g_showFlashes[ id ][ "height" ] = height;
			g_showFlashes[ id ][ "version" ] = version;
			g_showFlashes[ id ][ "bgcolor" ] = bgcolor;
			g_showFlashes[ id ][ "playerparamstr" ] = playerparamstr;
			g_showFlashes[ id ][ "flashparamstr" ] = flashparamstr;
		}
	}
}
checkFlash();
function ShowPremiumCar(CarID){window.open("/shared_audi/CarPresenter/default.asp?car="+CarID, "PopUp", "width=988,height=820,scrollbars=yes");}
function ShowPremiumCarPimp(CarID){window.open("/shared_audi/cp-pimpaudi/default.asp?car="+CarID, "PopUp", "width=988,height=820,scrollbars=yes");}
function ShowSpecialCarpresenter(CarID){window.open("/shared_audi/CP-Bielefeld/default.asp?car="+CarID, "PopUp", "width=988,height=820,scrollbars=yes");}

