/* /static/js/flashtitle.js
------------------------------------------------------------------------
flashtitle.js of INTERSPORT International Coperation

Author: elements.at [RG]

Version: v 1.2
------------------------------------------------------------------------*/
function handleError() {
	return true;
}

// Unicode setting for fonts
var unicode = true;

window.onerror = handleError;
/*
var hasFlash = function()
{
    var a=6;
    if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1)
    {
		
        document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+a+'))) \n</script\> \n');
        if(window.hasFlash!=null)return window.hasFlash
    }
    if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
    {
        var b=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;
        return parseInt(b.charAt(b.indexOf(".")-1))>=a
    }
    return false
}
*/

var hasFlash = function()
{
    var a=6;
    if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1)
    {
        document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+a+'))) \n</script\> \n');
        if(window.hasFlash!=null)return window.hasFlash
    }
    if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
    {
        var b=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;
        return b.indexOf("Shockwave Flash") != -1;
    }
    return false
}

function URLEncode(s) {
     if (window.encodeURIComponent) {
        return encodeURIComponent(s);
     }
     else if (window.escape) {
        return escape(s); 
     }
     return s;
}


function replaceHeading(htmltag) {

	for(var i = 0; i < document.getElementsByTagName(htmltag).length; i++) 
						
	{
		myValue = document.getElementsByTagName(htmltag)[i].innerHTML;
		
		var regExp=/<br>/gi;
		myValue = myValue.replace(regExp,"xbrx");
		
		// Hacks for Opera
		var regExp=/<br\/>/gi;
		myValue = myValue.replace(regExp,"xbrx"); 
		
		var regExp=/<br \/>/gi;
		myValue = myValue.replace(regExp,"xbrx");

		var regExp=/<BR \/>/gi;
		myValue = myValue.replace(regExp,"xbrx");
		
		var regExp=/<BR\/>/gi;
		myValue = myValue.replace(regExp,"xbrx");
		//
		
		var regExp=/<span[^>]*>/gi;
		myValue = myValue.replace(regExp,"[B]");
		
		var regExp=/<\/span>/gi;
		myValue = myValue.replace(regExp,"[/B]");
		
		var regExp=/<b>/gi;
		myValue = myValue.replace(regExp,"[B]");
		
		var regExp=/<\/b>/gi;
		myValue = myValue.replace(regExp,"[/B]");
		
		var regExp=/<strong>/gi;
		myValue = myValue.replace(regExp,"[B]");
		
		var regExp=/<\/strong>/gi;
		myValue = myValue.replace(regExp,"[/B]");
		
		var regExp=/<[^>]*>/gi;
		myValue = myValue.replace(regExp,"");
		
		var regExp=/\">/gi;
		myValue = myValue.replace(regExp,"");
		
		var regExp=/&amp\;/gi;
		myValue = myValue.replace(regExp,"T99806TDR");	
		
				
		
		//Debugging
		//(myValue);
		
		if (myValue != undefined) 
		{
				flashstyle = '';
				
				var regExp=/\s/gi;
				chars = myValue.replace(regExp,"");
				chars = chars.length;
				flashstyle = ' style="width:' + chars *10 + 'px; overflow:hidden;"';	
				

				var vars = document.getElementsByTagName(htmltag)[i].className;
				
				
				if(htmltag == 'h1')
				{
					var regExp=/\s/gi;
					chars = myValue.replace(regExp,"");
					chars = chars.length;


					if (chars < 40 && chars >= 15)
					{
						flashstyle = ' style="width:100%; height:29px; overflow:hidden;"';
					}
					else if (chars > 40 && chars < 80)
					{
						flashstyle = ' style="width:100%; height:48px; overflow:hidden;"';
					}
					
					else if (chars < 15)
					{
						flashstyle = ' style="width:100%; height:29px; overflow:hidden;"';						
					}
					
					else
					{
						flashstyle = ' style="width:100%; height:29px; overflow:hidden;"';
					}
					
				}
				
				if(htmltag == 'h3')
				{					
					var regExp=/\s/gi;
					chars = myValue.replace(regExp,"");
					chars = chars.length;  
					
					var linecontroller = myValue.split("xbrx");
					
					if (linecontroller.length < 2)
					{		
						flashstyle = ' style="width:280px; height:48px; overflow:hidden;"';
					}	
					
					if (linecontroller.length > 1)
					{
						flashstyle = ' style="width:280px; height:80px; overflow:hidden;"';

					}	
				}
				
				
				myObj = document.getElementsByTagName(htmltag)[i];
				myParent = myObj.parentNode;
			
				width = myObj.offsetWidth;
				height = myObj.offsetHeight;
			
				// FLASH AUSGABE
				
		        myValue = myValue.replace(/^\s*|\s*$/g,"");
				myValue = URLEncode(myValue);
				
				unicodePostFix = "";
					
				if (document.getElementsByTagName(htmltag)[i].parentNode.className == "flashheadline")
					{
						
					unicodePostFix = "_unicode";
					myFlash = ('<object ' + flashstyle + ' classid="clsid:d27cdb6e-ae6d'
					 +'-11cf-96b8-444553540000" codebase="http://fpdownlo'
					 +'ad.macromedia.com/pub/shockwave/cabs/flash/swflash'
					 +'.cab#version=6,0,0,0" id="'
					 +'boxtitle" align="middle"> <param name="allowScrip'
					 +'tAccess" value="sameDomain" /> <param name="wmode" value="transparent" /> <param name="movie'
					 +'" value="/static/swf/pro_' + htmltag + '_replacement' + unicodePostFix + '.swf" /><param name="FlashVars" value="headline=' + myValue + '&vars=' + vars + '" /> <param name="quality" v'
					 +'alue="high" /> <param name="scale" value="noscale' 
					 +'" /> <param name="salign" value="lt" /><embed' + flashstyle + ' src="/static/swf/pro_' + htmltag + '_replacement' + unicodePostFix + '.swf" FlashVars="headline=' + myValue + '&vars=' + vars + '" quality="high" wmode="transparent" scale="noscale" salign="l'
					 +'t" name='
					 +'"boxtitle" align="middle" allowScriptAccess="always'
					 +'omain" type="application/x-shockwave-flash" plugin'
					 +'spage="http://www.macromedia.com/go/getflashplayer'
					 +'" wmode="transparent" /> </object>');	
					}

				if (document.getElementsByTagName(htmltag)[i].parentNode.className == "flashprice")
				{					
					unicodePostFix = "_price";								
					myFlash = ('<object ' + flashstyle + ' classid="clsid:d27cdb6e-ae6d'
					 +'-11cf-96b8-444553540000" codebase="http://fpdownlo'
					 +'ad.macromedia.com/pub/shockwave/cabs/flash/swflash'
					 +'.cab#version=6,0,0,0" id="'
					 +'boxtitle" align="middle"> <param name="allowScrip'
					 +'tAccess" value="sameDomain" /> <param name="wmode" value="transparent" /> <param name="movie'
					 +'" value="/static/swf/pro_' + htmltag + '_replacement' + unicodePostFix + '.swf" /><param name="FlashVars" value="headline=' + myValue + '&vars=' + vars + '" /> <param name="quality" v'
					 +'alue="high" /> <param name="scale" value="noscale' 
					 +'" /> <param name="salign" value="lt" /><embed' + flashstyle + ' src="/static/swf/pro_' + htmltag + '_replacement' + unicodePostFix + '.swf" FlashVars="headline=' + myValue + '&vars=' + vars + '" quality="high" wmode="transparent" scale="noscale" salign="l'
					 +'t" name='
					 +'"boxtitle" align="middle" allowScriptAccess="always'
					 +'omain" type="application/x-shockwave-flash" plugin'
					 +'spage="http://www.macromedia.com/go/getflashplayer'
					 +'" wmode="transparent" /> </object>');
					
					
				} 	
				// FLASH AUSGABE
				replaceDiv = document.createElement('span');
				if(htmltag=='h1')
				{				
					replaceDiv.className = 'flashheader';
				}
				replaceDiv.innerHTML = myFlash;
				myParent.replaceChild(replaceDiv, myObj);
				i--;
		}
	
	}
	
}


if (hasFlash()) 
{
	replaceHeading("h3");
	replaceHeading("h2");
	replaceHeading("h1");
}