/*************************************************************************************
Animiert das addToCart-Bild und legt das Produkt in den Warenkorb
**************************************************************************************/

var addToCartImg1 = '_images/global/addToCart.gif';
var addToCartImg2 = '_images/global/addToCart_anim.gif';

function f_addToCart(){
	if (document.MM_returnValue){
		args = f_addToCart.arguments;
		if (args[0].getAttribute('src') != addToCartImg2){
			args[0].setAttribute('src',addToCartImg2);
			// Produkt in Cart legen Funktion. args[1] ist die Produkt-ID. 
			top.hiddenFrame.location.href="main_cart.aspx?sku='"+args[1]+"'&count="+ document.Form1.elements[args[2]].value +"&oldsku='"+args[4]+"'";	
		}
		window.setTimeout("args[0].setAttribute('src',addToCartImg1)",500);
		if(args[3]){
			f_showFrame("2")
		}
	}
}

/*************************************************************************************
Detail anzeigen
**************************************************************************************/
var v_lastElm = false;
var v_detailFrame = 'detailFrame'; // v_arFrameName[8]
var v_contentFrame = 'contentFrame' // v_arFrameName[7]
var v_detailFile = 'detail.htm';
var v_detailFrameView = true; // Anzeige des Details in detailFrame-Frame
var v_spaceGr = 10; // Abstand zwischen den Gruppen

function f_showDetail(v_id,v_detail){
	if (document.getElementById(v_id)){
		if (document.getElementById(v_id) != v_lastElm){
			document.getElementById(v_id).style.display = 'block';
			if (v_lastElm){
				v_lastElm.style.display = 'none';
			}
			/* In sichtbaren Bereich scrollen */
			v_posDivGr = document.getElementById(v_id).parentNode.offsetTop;
			v_scrollPos = (bw.safari)?v_posDivGr:v_posDivGr-v_spaceGr;
			window.scrollTo(0,v_scrollPos);
		}
	}
	v_lastElm = document.getElementById(v_id);
	if (v_detail){
		v_winDetailElm = window.eval('top.window.'+v_detailFrame);
		v_winContentElm = window.eval('top.window.'+v_contentFrame);
		if (v_detailFrameView){
			v_winDetailElm.location.href = v_detailFile + '?prodId=' + v_id;
			f_showFrame('1');
		}
		else {
			v_winContentElm.location.href = v_contentFile + '?prodId=' + v_id;
		}
	}
}

/*************************************************************************************
Detail- bzw. Cart-Frame ein- / ausblenden
**************************************************************************************/
var frmSet = 'detail_cart';
var frmWidthContent = '49.41%';
var frmWidthDetail = '50.59%';

// v_frmIndex = 1 --> detailFrame
// v_frmIndex = 2 --> cartFrame
function f_showFrame(v_frmIndex){
	if (top.document.getElementById(frmSet)){
		v_frmSetCols = top.document.getElementById(frmSet).getAttribute('cols');
		v_frmSetCols = v_frmSetCols.split(',');
		switch (v_frmIndex) {
		case "1": // Cart-Frame einblenden
			if (v_frmSetCols[2] != 0){
				top.document.getElementById(frmSet).setAttribute('cols',frmWidthContent + ',' + frmWidthDetail + ',0');
				f_writeTitle('Warenkorb einblenden &raquo;');
			}
			break;
		case "2": // Cart-Frame ausblenden
			if (v_frmSetCols[1] != 0){
				top.document.getElementById(frmSet).setAttribute('cols',frmWidthContent + ',0,' + frmWidthDetail);
				f_writeTitle('Warenkorb ausblenden &raquo;');
			}
			break;
		case "3": // Detail-Frame und Cart-Frame ausblenden
			top.document.getElementById(frmSet).setAttribute('cols','*' + ',0,0');
			break;
		default:
			if (v_frmSetCols[2] != 0){
				top.document.getElementById(frmSet).setAttribute('cols',frmWidthContent + ',' + frmWidthDetail + ',0');
				f_writeTitle('Warenkorb einblenden &raquo;');
			}
			else {
				top.document.getElementById(frmSet).setAttribute('cols',frmWidthContent + ',0,' + frmWidthDetail);
				f_writeTitle('Warenkorb ausblenden &raquo;');
			}
			break;
		}
	}
}

var frmNavCart = 'navCart';
var v_idNavCartTitle = 'navCartTitle';

function f_writeTitle(v_innerTxt){
	v_frmNavCart = window.eval('top.'+frmNavCart);
	v_frmNavCart.document.getElementById(v_idNavCartTitle).innerHTML = v_innerTxt;
}

/*************************************************************************************
Navigation des Content-Frame definieren
**************************************************************************************/
var v_frmContentNav = 'top.navContent';
//var v_frmContent = 'contentFrame';

// v_frmIndex = 1 --> Anzeige Liste 1
// v_frmIndex = 2 --> Anzeige Liste 2
var i=0;
function f_showContentList(v_frmIndex){
	if (window.eval(v_frmContentNav)){
		switch (v_frmIndex) {
		case "1": // Anzeige Liste 1 -> "Zur Liste ohne Bilder"
			f_writeTitleContent('Zur Liste ohne Bilder &raquo;',true);
			break;
		case "2": // Anzeige Liste 2 -> "Zur Liste mit Bildern"
			f_writeTitleContent('Zur Liste mit Bildern &raquo;',true);
			break;
		case "3":
			var Ergebnis = (top.contentFrame)?top.contentFrame.location.href.search(/catalog.+/):-1;
			if (Ergebnis != -1)
			{
				i++;
				if(i<5)
				{
					setTimeout("f_showContentList('3')",200);
				}
			}
			else
			{
				f_writeTitleContent('&nbsp;',false);
			}
			break;
		default:
			var Ergebnis = (top.contentFrame)?top.contentFrame.location.href.search(/catalog.+/):-1;
			if (Ergebnis != -1)
			{
				i=0
				if(i<5)
				{
					setTimeout("f_showContentList('3')",200);
				}
			}
			else
			{
				f_writeTitleContent('&nbsp;',false);
			}
			break;
		}
	}
}

var v_idNavContentTitle = 'navContentTitle';

function f_writeTitleContent(v_innerTxt,v_link){
	v_frmContentNav = window.eval(v_frmContentNav);
	v_frmContentNav.document.getElementById(v_idNavContentTitle).innerHTML = v_innerTxt;
	if (v_link){
		v_frmContentNav.document.getElementById(v_idNavContentTitle).onclick = function (){
			top.hiddenFrame.location.href='function.aspx?function=catalogView';
		}
	}
	else
	{
		v_frmContentNav.document.getElementById(v_idNavContentTitle).onclick = function (){}
	}
}
/*************************************************************************************
Selektion und Deselektion des Listeneintrages (Produkt)
**************************************************************************************/
var v_LastClass;	// Beinhaltet alle Klassen welche vor der Selektion zugewiesen waren
var v_TitleElm;	// Beinhaltet alle Elemente welche selektiert werden

function f_selPro(v_id){
	v_winContentElm = window.eval('top.window.'+v_contentFrame);
	if (v_winContentElm && (v_winContentElm.location.href.length > 11) && v_winContentElm.document){ // Prüfung auf Frame
		if (v_winContentElm.document.getElementById(v_id)){ // Prüfung auf Objekt
		 v_TitleElm=v_winContentElm.document.getElementById(v_id);
			if (bw.ie){
				v_LastClass = v_TitleElm.getAttribute('className');
				v_TitleElm.setAttribute('className','proSel');
			}
			else if (v_winContentElm){
				v_LastClass = v_TitleElm.getAttribute('class');
				v_TitleElm.setAttribute('class','proSel');
			}
		}
		else {window.setTimeout("f_selPro('"+v_id+"')",500);} 
	}
	else {window.setTimeout("f_selPro('"+v_id+"')",500);}
}
function f_deSelPro(v_id){
	if (v_TitleElm){
		v_winContentElm = window.eval('top.window.'+v_contentFrame);
		if (v_winContentElm && (v_winContentElm.location.href.length > 11) && v_winContentElm.document){ // Prüfung auf Frame
			if (v_winContentElm.document.getElementById(v_id)){ // Prüfung auf Objekt
			v_TitleElm=v_winContentElm.document.getElementById(v_id);
				if (bw.ie){
					v_TitleElm.setAttribute('className',v_LastClass);
				}
				else if (v_winContentElm){
					v_TitleElm.setAttribute('class',v_LastClass);
				}
			}
		}
	}
}
/*************************************************************************************
Werte von MainCart in CartMonitor schreiben
**************************************************************************************/
function f_writeMiniCartValue(v_frm){
	v_oFrm = window.eval('top.'+v_frm);
	if (v_oFrm){
		if (v_frm == 'cartFrame'){v_frm1 = eval('window'); v_frm2 = v_oFrm;}
		else {v_frm1 = v_oFrm; v_frm2 = eval('window');}
		if (bw.safari){
			if ((v_frm2.location.href.length > 11) && (v_frm1.location.href.length > 11)){ // http://www. (file://D/)
				f_writeMiniCartElement(v_frm1,v_frm2);
			}
		}
		else {
			f_writeMiniCartElement(v_frm1,v_frm2);
		}
	}
}
function f_writeMiniCartElement(v_frm1,v_frm2){
	if (v_frm2.document){
		if (v_frm1.document.getElementById('Product_name') && v_frm2.document.getElementById('Last_Name')){
			v_frm1.document.getElementById('Product_name').innerHTML = '<b>'+v_frm2.document.getElementById('Last_Name').value+'</b>';
			v_frm1.document.getElementById('Product_count').innerHTML = '<b>'+v_frm2.document.getElementById('Last_Count').value+'</b> Stk.';
			v_frm1.document.getElementById('Total_count').innerHTML = '<b>'+v_frm2.document.getElementById('Total_Count').value+'</b> Stk.';
			v_frm1.document.getElementById('Total_value').innerHTML = '<b>'+v_frm2.document.getElementById('Total_price').innerHTML+'</b>';
		}
		else {
			v_path = v_frm1.location.href;
			if (v_path.indexOf('mini_cart.aspx')==-1){
				v_frm1.location.href = 'mini_cart.aspx';
			}
			f_writeMiniCartValue();
		}
	}
}

/*************************************************************************************
Schreibt nach dem Laden der Seite die Artikelbilder und Logos in die Katalogliste 
**************************************************************************************/
var v_rootImg = '';
var v_rootLogo = '';

function f_writeImgInCatalog(){
	if (v_arrImgId.length >0 && v_arrImgId[0]!='')
		{
		for (i=0;i < v_arrImgId.length;i++){
			// Hinweis: IE versteht die Variante mit setAttribute im Zusammenhang mit "style" nicht
			if(document.getElementById(v_arrImgId[i])!=null)
			{
				v_oImgFile = v_arrImgFile[i].replace(/\s/g, "%20");
				document.getElementById(v_arrImgId[i]).style.backgroundImage = 'url('+v_rootImg+v_oImgFile+')';
			}
		}
	}
	if(v_arrLogoId.length>0 && v_arrLogoId[0]!='')
		{
		for (i=0;i < v_arrLogoId.length;i++){
			if(document.getElementById(v_arrLogoId[i])!=null)
			{
				v_oLogoFile = v_arrImgFile[i].replace(/\s/g, "%20");
				document.getElementById(v_arrLogoId[i]).setAttribute('src',v_rootLogo+v_oLogoFile);
			}
		}
	}
}
