// Pole Position 

if ( typeof( aryPolePositionAdsPartner     ) == "undefined" )  aryPolePositionAdsPartner     = new Array();
if ( typeof( aryPolePositionAdsTitle       ) == "undefined" )  aryPolePositionAdsTitle       = new Array();
if ( typeof( aryPolePositionAdsDescription ) == "undefined" )  aryPolePositionAdsDescription = new Array();
if ( typeof( aryPolePositionAdsImageUrl    ) == "undefined" )  aryPolePositionAdsImageUrl    = new Array();
if ( typeof( aryPolePositionAdsClickUrl    ) == "undefined" )  aryPolePositionAdsClickUrl    = new Array();
if ( typeof( aryPolePositionAdsPrice       ) == "undefined" )  aryPolePositionAdsPrice       = new Array();
if ( typeof( aryPolePositionAdsFooter      ) == "undefined" )  aryPolePositionAdsFooter      = new Array();
if ( typeof( aryPolePositionAdsOtherText   ) == "undefined" )  aryPolePositionAdsOtherText   = new Array();
if ( typeof( aryPolePositionAdsOtherUrl    ) == "undefined" )  aryPolePositionAdsOtherUrl    = new Array();
if ( typeof( aryPolePositionAdsGAurl       ) == "undefined" )  aryPolePositionAdsGAurl       = new Array();

function ShowPolePosition( adsIndex, strTemplate, lngPosition, lngMaxPolePositionAds ) {
	// var lngMaxPolePositionAds = 4;
	var lngPolePositionAds = aryPolePositionAdsTitle.length;

	if ( lngPosition  == null ) lngPosition  = 0;	// Position in Poleposition-Block

	// alert( "DEBUG: aryPolePositionAdsTitle = " + aryPolePositionAdsTitle.length );
	// alert( "DEBUG: Partneranzeigen = " + lngPolePositionAds );

	// alert( "DEBUG: ShowPolePosition( " + adsIndex + ", " + strTemplate + ")");

	if ( typeof(partnerAdsTitle) != "undefined" ) {
		if ( lngPolePositionAds == 0 ) {
			// alert( "DEBUG: aryPolePositionAdsxxx anlegen!" );
	
			lngMaxAds = 0;		// max. numbers of partner ads per partner available 
			lngPartners = partnerAdsTitle.length;		// Anzahl der Partner
	
			// alert( "DEBUG: Partners = " + lngPartners );
			// Create mixed List of all partner ads in Sequence
			for (var partnerName in partnerAdsTitle) {
			  	// alert ( "DEBUG: partnerName: " + partnerName + ", Anzahl: " + partnerAdsTitle[partnerName].length );
			  	if ( partnerAdsTitle[partnerName].length > lngMaxAds )
					lngMaxAds = partnerAdsTitle[partnerName].length;
			}

			//alert( "DEBUG: lngMaxAds = " + lngMaxAds );
			for ( i = 0; ( i < lngMaxAds ) && ( lngPolePositionAds < lngMaxPolePositionAds ); i++ ) {
				for (var partnerName in partnerAdsTitle) {
				  	if ( ( typeof( partnerAdsTitle[partnerName] ) == "object" ) && partnerAdsTitle[partnerName].length > i ) {
						// alert( "DEBUG: aryPolePositionAdsTitle[ "+lngPolePositionAds+" ]: Anzeige '" + partnerAdsTitle[partnerName][i] + "' von Partner " + partnerName );
						if ( ( typeof( partnerAdsImageUrl[partnerName][i] ) != "undefined" ) && partnerAdsImageUrl[partnerName][i].length > 0 ) { 
							// Only Ads with an image are allowed in Pole Position
							aryPolePositionAdsPartner[lngPolePositionAds]     = partnerName;
							aryPolePositionAdsTitle[lngPolePositionAds]       = partnerAdsTitle[partnerName][i];
							aryPolePositionAdsDescription[lngPolePositionAds] = partnerAdsDescription[partnerName][i];
							aryPolePositionAdsImageUrl[lngPolePositionAds]    = partnerAdsImageUrl[partnerName][i];
							aryPolePositionAdsClickUrl[lngPolePositionAds]    = partnerAdsClickUrl[partnerName][i];
							aryPolePositionAdsPrice[lngPolePositionAds]       = partnerAdsPrice[partnerName][i];
							aryPolePositionAdsFooter[lngPolePositionAds]      = partnerAdsFooter[partnerName][i];
							aryPolePositionAdsOtherText[lngPolePositionAds]   = partnerAdsOtherText[partnerName][i];
							aryPolePositionAdsOtherUrl[lngPolePositionAds]    = partnerAdsOtherUrl[partnerName][i];
							strGoogleAnalyticsURL                             = partnerAdsGAurl[partnerName][i];
							aryPolePositionAdsGAurl[lngPolePositionAds]       = strGoogleAnalyticsURL.replace( /jsresult/, "poleposition");
							lngPolePositionAds++;
//						} else {
//						alert( "DEBUG: aryPolePositionAdsTitle[ "+lngPolePositionAds+" ]: Anzeige '" + partnerAdsTitle[partnerName][i] + "' von Partner " + partnerName + " hat kein Bild" );
						}
					}	
				}
			}
		}
//		else
//			alert( "DEBUG: Partneranzeigen vorhanden!" );

//	} else {
//		alert( "DEBUG: partnerAdsTitle nicht vorhanden!" );
	}

//	alert( "DEBUG: Partneranzeigen = " + lngPolePositionAds + "\n adsIndex = " + adsIndex + "\n lngPosition = "+ lngPosition + "\n strTemplate = "+ strTemplate );
	if ( lngPolePositionAds >= adsIndex )	// Ads available?
		{
		 switch (strTemplate)
			{
			case "sectionpoleposition":
				{
				if ( lngPosition > 1 )
					document.writeln('<div class="separator"></div>');
				break;
				}
			   
			}

		
		}
	else 
		{
		// No Ads available
		/*switch (strTemplate)
			{
			case "resultpolepositionimage":	// Show empty table-cell for Pole Position Ad
				document.writeln('<td class="adtext">&nbsp;</td>');
				break;
		
			case "resultpolepositiontext":	// Show empty table-cell for Pole Position Ad
				document.writeln('<td class="adtext">&nbsp;</td>');
				break;

			case "sectionpoleposition":
				break;
			}*/

		// no ads at all and no partner ads available
		if ( ( lngPolePositionAds == 0 ) && ( adsIndex == lngMaxPolePositionAds ) )
			{
			//alert( "DEBUG: Keine Partneranzeigen vorhanden!!!\nBlende Box aus." );
			// Hide Pole Position in Section Area
			objElement = document.getElementById( "ContentPolepositionAds" );
			if ( objElement )
				objElement.style.display = "none";

			// Hide Pole Position in Result Area
			objElement = document.getElementById( "ContentPolepositionAds_Result" );
			if ( objElement )
				objElement.style.display = "none";
			}

		}	
}
