/* Global JavaScript-File by ecom internet technology GmbH */

//Browser detection
var AgntUsr=navigator.userAgent.toLowerCase();
var DomYes=(document.getElementById)?1:0; 												// DOM
var NavYes=(AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1)?1:0; 	// Netscape
var ExpYes=(AgntUsr.indexOf('msie')!=-1)?1:0; 											// IExplorer
var Opr5=(AgntUsr.indexOf('opera 5')!=-1||AgntUsr.indexOf('opera/5')!=-1)?1:0; 			// Opera 5
var DomNav=(DomYes&&NavYes)?1:0; 														// Netscape 6 up
var DomExp=(DomYes&&ExpYes)?1:0; 														// IExplorer 5 up
var Nav4=(NavYes&&!DomYes&&document.layers)?1:0; 										// Netscape 4
var Exp4=(ExpYes&&!DomYes&&document.all)?1:0; 											// IExplorer 4
var PosStrt=((NavYes||ExpYes)&&!Opr5)?1:0; 												// Can start
var NN60=((AgntUsr.indexOf("netscape") != -1)&&(AgntUsr.indexOf("6/6.0") != -1))?1:0;	// Netscape 6.0

function writeDiv(div, html) 
//write content in a DIV
{
	var evaldiv;
	if (DomExp) 
	{
		evaldiv = eval(div);
		evaldiv.innerHTML = html;
	}
	else if (DomNav) 
	{
		(document.getElementById(div)).innerHTML = html;
	}
}

// scrolls content (DIV) to top
function goTop()
{
	c = document.getElementById('content');	
	c.scrollTop = 0;	
}

function showError (count) {
	var errText = '<span class="text_blue"><font color="#FF0000">Die Eingabe ist nicht vollst&auml;ndig oder es hat sich ein Fehlerteufel eingeschlichen. Bitte klicken Sie auf einen Pfeil um n&auml;here Informationen zu erhalten.</font></span>';
	if (count == "true")
		writeDiv('errorDiv',errText);
	}

// required elements: DIV id=content, TD id=tdLink, IMG id=linkTopSpacer
// if content is overflowed - shows link Go Top
function writeTopLink()
{			
	t = document.getElementById('tdLink');		// TD element to put link into									
	c = document.getElementById('content');		// DIV element
	i = document.getElementById('linkTopSpacer'); // image to make space between A and text
	h = 0;	
			
	if (ExpYes)
		h = c.scrollHeight;
																			
	if (h > 360)
	{								
		i.height=50;
		t.innerHTML = "<a href=\"javascript:goTop();\" class=\"gotop\">Seitenanfang</a>";
	}	
}

// every product definition (in flex module) calls this function
// only first call is registered (setFirst)
// this function is overriden in: hervis_mt_04_001
function setFirstProduct(n)
{
	//if (firstProduct==-1)
		//firstProduct = n;
}

// shows first product
function showFirstProduct(w,h)
{
	// prelaoad defaultImage
	if (defaultImage)	
	{
		if (defaultImage!=false)	
			MM_preloadImages(defaultImage);	
	}
	
	// preload all other product images (because of ie image rendering bug (doesn't render last image line))
	if (product)
	{
		for (i=0;i<product.length;i++)
		{
			if (product[i])
			{
				if (product[i].previewImage)
				{
					MM_preloadImages(product[i].previewImage);
				}
				if (product[i].clipImage)
				{
					MM_preloadImages(product[i].clipImage);
				}				
			}
		}
	}	
	
	showProduct(firstProduct,w,h);

}


// shows product 
// args: what - product id (generated by flex module)
function showProduct(what,w,h)
{
	var p = document.getElementById('products');
	var border = document.getElementById('div_border');
	var divImage = document.getElementById('divImage');	
	var hTemp;
	//p.style.overflow = 'visible'; // it's default value
	
	// only for mt_02_007_unternehmen
	if (border) border.style.border = 'solid Black 1px';
	
	if (what!=-1)	
	{	// if there is a first product
		
		if (product[what].previewImage == "empty" && product[what].previewHTML == "empty")
		{
			if (product[what].clipImage == "empty")
			{
				// in case it's windows OS and IE try to get MediaPlayer
				if (navigator.userAgent.toLowerCase().indexOf("windows")>0 && ExpYes)
				{
					var html = '';					
					html += '<OBJECT  id ="mplay" WIDTH="413" HEIGHT="295" ';
			    	html += '		CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
			    	html += '		STANDBY="Loading Windows Media Player components..." ';					
			    	html += '		TYPE="application/x-oleobject"> ';
					html += '</OBJECT> ';
					
					writeDiv('products',html);
					
					document.all.mplay.fileName = product[what].mediaClip;
				}
				else
				writeDiv('products', "<embed src='" + product[what].mediaClip + "' border='0' width='413' height='295' autostart='false'>");		
				
			}
			else
			{
				writeDiv('products', "<img id='divImage' src='" + product[what].clipImage + "' border='0' width='413' height='250'><br><embed src='" + product[what].mediaClip + "' border='0' width='413' height='45' autostart='false'>");		
			}
		}
		else
		{		
			if (product[what].previewImage != "")
			{	
				writeDiv('products', "<img id='divImage' src='" + product[what].previewImage + "' border='0' width='" + w + "' height='" + h + "'>");		
			}
			else if (product[what].previewHTML != "")
			{
				writeDiv('products', '<table border=0 cellpadding=5><tr><td>' + product[what].previewHTML) + '</td></tr></table>';
				//p.style.overflow = 'auto'; 	//NS problem - writeDiv works only if overflow = 'visible', so this is after writeDiv
			}
		}
			
		// set all to blue (inactive)
		for (var i = 0; i < product.length; i++)
		{
			if (product[i])
			{
				document.getElementById(product[i].link1).className = "sportwelten-alink-blue";
				if (document.getElementById(product[i].link1 + 't')) // if there are two links (special case - second has extra 't' in id)
					document.getElementById(product[i].link1 + 't').className = "sportwelten-alink-blue";
				
			}
		}

		// set curent to black (active)
		document.getElementById(product[what].link1).className = "sportwelten-alink-blue-active";
		if (document.getElementById(product[what].link1 + 't')) 
			document.getElementById(product[what].link1 + 't').className = "sportwelten-alink-blue-active";		
	}
	else	
	{	// there is no first product

		// only for mt_02_007_unternehmen
		if (border) border.style.border = 'solid White 1px';
		//alert(defaultImage);
		if (defaultImage!=null)
		{
			if (defaultImage=='' || defaultImage=='empty')
				defaultImage = '/hervis-at/images/spacer.gif';
				
			writeDiv('products', "<img id='divImage' src='" + defaultImage + "' border='0' width='" + w + "' height='" + h + "'>");			
		}
	}
}

function callPopUp(url, name, width, height)
{       
        if(name == "") name = "myPopUpWindow";
        if(width == 0 || width == "") width = 400;
        if(height == 0 || width == "") height = 500;
        if(url != "") window.open(url, name,"width="+width+",height="+height+",resizable=no,menubar=no,locationbar=no,scrollbars=auto");
}

// sportwelten-marken 
function oMarken()
{
	this.srcImage = "";
	this.imageLink = "";
}

function addMarken(src,lnk)
{
	var i = marken.length;
	marken[i] = new oMarken();
	marken[i].srcImage = src;
	marken[i].imageLink = lnk;
}		

// sportwelten-marken - end

	function oProduct()
	{
		this.bigImage = "";
		this.smallImage = "";
		this.markenLogo = "";
		this.previewHeader = "";
		this.previewText = "";
		this.popUpImage = "";
		this.hervisPreis = "";
		this.hervisStattPreis = "";
		this.popUpWidth = 450;
		this.popUpHeight = 450;
	}
	
	var product = new Array();
	var product2 = new Array();
	
	function addProduct(si,bi,pi,ml,ph,pt,price,statt)
	{
		var i = product.length;
		product[i] 				= new oProduct();
		product[i].smallImage = si;
		product[i].bigImage = bi;		
		product[i].popUpImage = pi;
		product[i].markenLogo = ml;
		product[i].previewHeader = ph;
		product[i].previewText = pt;
		product[i].previewPreis = price;
		product[i].previewStattPreis = statt;
		
	}	
	
	var pos = 0;
	var dest = 0;
	var distance = 0;
	var step = 0;
	var destination = 0;
	var thisPic = 0;
	var current = 1;
	
	function changeText(text)
	{
		writeDiv("descText", text);
	}

	function changeHeader(text)
	{
		writeDiv("header", text);
	}
	
	function changePreis(text)
	{
		writeDiv("hervisPreis", text);
	}
	
	function changeStattPreis(text)
	{
		writeDiv("hervisStattPreis", text);
	}
	
	function showPopUpImage()
	{
		if(product2[currentProduct].popUpImage != "")
			products.callPopUp("/global_hervis_hu/html/inc/popup_image.html?imgsrc=" + product2[currentProduct].popUpImage + "&width=" + product2[currentProduct].popUpWidth + "&height=" + product2[currentProduct].popUpHeight, "popup_image", product2[currentProduct].popUpWidth, (product2[currentProduct].popUpHeight+40));
	}
	
	function showPrintTemplate() {
		products.callPopUp("/global_hervis_hu/html/inc/product_print.html", "product_print", 650, 500);
	}



