var TIMEOUT_CUTS_LAYER = 500;

findID = function (el, sClass) {
	if(el.id == sClass)
		return el;
	if(!el || !el.parentNode)
		return false;
	else
		return findID(el.parentNode, sClass);
}

var arrayListFontCuts = new Array();

//$D = Yahoo.util.Dom, set in "helpfunctions"

//function for updating a layer rendered by yui dialog
function updateLayerBody(ev, elId, fontPKString, title) {
	var htmlContent = getCutsAsLayerContent(fontPKString);
	
	if (title == null) {
		title = "";
	}
	if (YAHOO.hmmh.dialog2) {
      YAHOO.hmmh.dialog2.destroy
    }
     
  YAHOO.hmmh.openSchriftenLayer.showSchnitteLayer(ev, this, elId, htmlContent, title, fontPKString);
}

function getCutsAsLayerContent(fontPKString) {
	
	var html2Get = document.getElementById("cutsLayer" + fontPKString);
	
	if (html2Get!= null) {
		return html2Get.innerHTML;
	}
	return null;
}

var innerProcess = null;
function callCutsLayer(divId, lines, setStyle, e) {
	var element = $E.getTarget(e);
	if(innerProcess != null) {
		clearTimeout(innerProcess);
	}
	innerProcess = setTimeout(function() {
		doCallCutsLayer(divId, lines, setStyle, element); // do not transfer event since there is only one event object in IE
	}, TIMEOUT_CUTS_LAYER);
}


/**
 * function for displaying hidden font style layer
 */
function doCallCutsLayer(divId, lines, setStyle, element) {
	var myParent = element.parentNode;
	while(myParent != null && myParent.className != 'fontSearchResultBox'){
		myParent = myParent.parentNode;
	}
	/*
	var linesAmount = lines;
	if (linesAmount == null || linesAmount == 0) {
		linesAmount = 6;
	}
	
	var linesCalc = linesAmount * 32;
	
	var myLinesCalc = (YAHOO.util.Selector.query('img', divId).length/2) * 70;
	*/
	var cutsDiv = $D.get(divId);
	if (cutsDiv != null  && setStyle==true) {
		// lazy initializer
		// Move layer to right position once for Moz/Safari; for IE move on each call
		if(!cutsDiv.mode || YAHOO.env.ua.ie >0 ) {
			if(myParent) {
				myParent.appendChild(cutsDiv);
			}
		}
		if(!cutsDiv.mode) {
			cutsDiv.mode="true";
			$E.on(cutsDiv,'mouseover', function(){ clearTimeout(YAHOO.hmmh.openSchriftenLayer.prozess); });
			$E.on(cutsDiv,'mouseout',  function(){ closeCutsLayer(divId); clearTimeout(innerProcess); }, true);
		}
		
		
		$D.setStyle(cutsDiv, 'display', 'block');
		$D.setStyle(cutsDiv, 'opacity', '0');
		var aniCutsLayer = new YAHOO.util.Anim(cutsDiv , {opacity: {from: 0, to: 1 }}, .4, YAHOO.util.Easing.easeIn);
		aniCutsLayer.animate();
		
		// Set layer to bottom line
		$D.setStyle(cutsDiv,"margin-top",(-parseInt(cutsDiv.clientHeight) - 5) +"px");
		
		/*
		// IE Fix for overlapping layer (Add layer to document root, keep position)
		if(YAHOO.env.ua.ie >0) {
			$D.setStyle(cutsDiv,"top","");
			$D.setStyle(cutsDiv,"left","");
			var xPos = $D.getX(cutsDiv) - parseInt($D.getStyle(cutsDiv,"margin-left"));
			var yPos = $D.getY(cutsDiv) - parseInt($D.getStyle(cutsDiv,"margin-top"));
			$D.setStyle(cutsDiv,"top",yPos+"px");
			$D.setStyle(cutsDiv,"left",xPos+"px");
			document.body.appendChild(cutsDiv);
		}
		*/
	} 
	
    var selectBox = YAHOO.util.Selector.query("select", divId);
    $D.addClass(selectBox, "active");
	YAHOO.hmmh.removeSelectBoxSelection.removeSelection(true);
}

/**
 * Close font style layer with small delay (stoppable)
 * @param divId
 * @return
 */
function closeCutsLayer(divId) {
	if(innerProcess != null) {
		clearTimeout(innerProcess);
	}
	YAHOO.hmmh.openSchriftenLayer.prozess = setTimeout("closeLayer('"+divId+"')",100);
}

/**
 * function for displaying a hidden layer (i.e. the mouse over layer for fonts)
 * @param divId
 * @param lines
 * @param setStyle
 * @param e
 * @return
 */
function callLayer(divId, lines, setStyle, e) {
	var myParent = $E.getTarget(e);
	while(myParent != null && myParent.className != 'fontSearchResultBox'){
		myParent = myParent.parentNode;
	}
	var myParentPosition = $D.getXY(myParent);
	
	// for IE: Move Layer to document root
	if(document.body) {
		document.body.appendChild($D.get(divId));
	}
	var linesAmount = lines;
	if (linesAmount == null || linesAmount == 0) {
		linesAmount = 6;
	}
	var x = parseInt($E.getPageX(e))+20;
	var y = parseInt($E.getPageY(e))-220;
	
	var linesCalc = linesAmount * 32;
	// fudge the position if it is off the document size
	//if(x+100 >= getWindowWidth()) { x = x-80; }
	//if(y+linesCalc >= getWindowHeight()) { y = y-linesCalc; }
	
	var myLinesCalc = (YAHOO.util.Selector.query('img', divId).length/2) * 70;
	
	if (divId!=null && setStyle==true) {
		//$D.setStyle(divId, 'top', y+'px');
		$D.setStyle(divId, 'top', myParentPosition[1]-myLinesCalc+'px');
		//$D.setStyle(divId, 'left', x+'px');
		$D.setStyle(divId, 'left', myParentPosition[0]+'px');
		$D.setStyle(divId, 'position', 'absolute');
		$D.setStyle(divId, 'z-index', '99999');
		
		
		$D.setStyle(divId, 'padding-left', '5px');
		$D.setStyle(divId, 'padding-right', '5px');
		$D.setStyle(divId, 'background-color', '#fdfdfd');
		$D.setStyle(divId, 'border', '1px solid black');
		$D.setStyle(divId, 'opacity', '0.9');
		$D.setStyle(divId, 'display', 'block');
	
	} else if (divId!=null && setStyle==false) {
		//our "buying layer" - place it accordingly
		if(document.getElementById('fontBag') != null){
			x = parseInt($E.getPageX(e))-540;
		} else {
			x = parseInt($E.getPageX(e))-620;
		}
		y = parseInt($E.getPageY(e))-220;
		$D.setStyle(divId, 'top', y+'px');
		//$D.setStyle(divId, 'top', myParentPosition[1]-myLinesCalc+'px');
		$D.setStyle(divId, 'left', x+'px');
		//$D.setStyle(divId, 'left', myParentPosition[0]+'px');
		$D.setStyle(divId, 'position', 'absolute');
		$D.setStyle(divId, 'z-index', '99999');
		
		$D.setStyle(divId, 'padding-left', '5px');
		$D.setStyle(divId, 'background-color', '#fdfdfd');
		$D.setStyle(divId, 'opacity', '0.95');
		$D.setStyle(divId, 'display', 'block');	
	}
    var selectBox = YAHOO.util.Selector.query("select", divId);
    $D.addClass(selectBox, "active");
	YAHOO.hmmh.removeSelectBoxSelection.removeSelection(true);
	
}

function callSpecialLayerEvent(divId) {
    var display = $D.getStyle(divId, "display");
    window.setTimeout(function() {
    	if(display == "block") {
			$E.on(document.getElementsByTagName("body")[0], 'click', closeBuyLayer, divId);
    	}
    }, 100);
}

//function for hiding al layer
function closeLayer(divId) {
	if (divId!=null) {
		$D.setStyle(divId, 'display', 'none');
	       var selectBox = YAHOO.util.Selector.query("select", divId);
	       $D.removeClass(selectBox, "active");
	}
}

function closeLayerCheckCPU(divId, wrapperPK) {
	var cpuInput = getAnzahlLizenzenBuyLayer(wrapperPK);
	var _inputs = YAHOO.util.Selector.query('div input', divId, false);
	// das gew�hlte Format
	var selectedFormat = getSelectedFormatsBuyLayer(_inputs);
	 	
	if (cpuInput != null && selectedFormat != null) {
		closeLayer(divId);
	}
	
}


function closeBuyLayer(e, divId) {
	if(YAHOO.util.Event.getTarget(e)) {
		if(YAHOO.util.Event.getTarget(e).className == "closeFontBuyLayer") {
    		$D.setStyle(divId, 'display', 'none');
			$E.removeListener(document.getElementsByTagName("body")[0]);
		    var selectBox = YAHOO.util.Selector.query("select", divId);
		    $D.removeClass(selectBox, "active");
	    	}

		if(!findID(YAHOO.util.Event.getTarget(e), divId)) {
			$D.setStyle(divId, 'display', 'none');
			$E.removeListener(document.getElementsByTagName("body")[0]);    	
		    var selectBox = YAHOO.util.Selector.query("select", divId);
		    $D.removeClass(selectBox, "active");
		}
	}
}


/*
function updateNotePadIcons(fontProductPK, fontImgUrl) {
try { 	
	if (fontImgUrl!=null) {
		
		var ourNotepadAHref = document.getElementById("notepadCall"+fontProductPK);
	    var newRelValue = "{ prodId : '" + fontProductPK + "' , imgURL : '" + fontImgUrl + "' }";
		var aTag = document.createElement('a');
	        aTag.setAttribute("href", "javascript:;");
	        aTag.setAttribute("id", "notepadCall" +  fontProductPK);
	        aTag.setAttribute("rel", newRelValue);
	        aTag.setAttribute("title", "Auf die Merkliste legen");
	        aTag.setAttribute("class", "addToClipboard");
	        aTag.appendChild(document.getElementById("notepadIcon" +  fontProductPK));
	  	
	  try {  	    
		   var parentEl = document.getElementById("td"+fontProductPK)
		   if (parentEl!=null) {
		   		parentEl.replaceChild(aTag, ourNotepadAHref);
		   		return true;
		   }
	  } catch(x) {
	  	//alert(x);
	  	return false;
	  }
	 return true;	
	} else {
		return false;
	}
} catch(z) {
//alert(z);
  	return false;
}		
}

function updateWakoPadIcons(fontProductPK, payableWeights) {
try {  
	
	var isPackageChecked = document.getElementById("radiobuttonPackage" + wrapperPK) != null && document.getElementById("radiobuttonPackage" + wrapperPK).checked;  
	
	var price4Package = recalculatePrice(1, fontProductPK, payableWeights, callFromDetailsPage, isPackageChecked);
	
	if (price4Package!=null) {
		
		//***********************************************************
		//since we retrieved the current price: update the price span
		//NOTE: commented out, because lowest price is retrieved on server call for now
		//updatePriceSpan(fontProductPK, price4Package);
		
		var ourNotepadAHref = document.getElementById("wakoCall"+fontProductPK);
	    var newRelValue = "{ prodId : '" + fontProductPK +"', prices : [{ 'res': 'none','unit': 'Font','format': 'Font', 'price': '" + price4Package +"' }] }";
		var aTag = document.createElement('a');
	        aTag.setAttribute("href", "javascript:;");
	        aTag.setAttribute("id", "wakoCall" +  fontProductPK);
	        aTag.setAttribute("rel", newRelValue);
	        aTag.setAttribute("title", "Auf die Merkliste legen");
	        aTag.setAttribute("class", "addToClipboard");
	        aTag.appendChild(document.getElementById("wakoIcon" +  fontProductPK));
		  	
		  try {  	    
			   var parentEl = document.getElementById("td"+fontProductPK)
			   if (parentEl!=null) {
			   		parentEl.replaceChild(aTag, ourNotepadAHref);
			   		return true;
			   }
		  } catch(x) {
		  	//alert(x);
		  	return false;
		  }
	
	
	 return true;	
	
	} else {
		return false;
	}
} catch(z) {
//alert(z);
  	return false;
}	
}
* */

function updatePriceSpan(fontPK, price4Package) {
	var spanEl = document.getElementById("priceSpan" + fontPK);
	if (spanEl!=null) {
		spanEl.innerHTML = price4Package;
	}
}


function checkAll(field) {
	
	if (null != document.getElementById('pIsPackage')) {
		document.getElementById('pIsPackage').checked = false;
	}
	for (i = 0; i < field.length; i++) {
		field[i].checked = true ;
	}
	showBlueBorder4All(document.checkFontsForm.font, true);
}

function uncheckAll(field) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = false ;
	}
	showBlueBorder4All(document.checkFontsForm.font, false);
}

/*
 * Setzt den Haken an die Checkbox 'Einzelschintt',
 * sobald eine Schnitte markiert wird.
 */
function setPackageOrCut(himself){
	
	if(himself != null){
		if(himself.checked){
			document.getElementById('pIsCut').checked = true;
		}
	}
	enableShippingButton('pShipping', '', false, 'pDownload', '');
	
}

// IMPORTANT :: "name" is "switched" for simple replace of function
function getFontProductPrice(pDivisionLayerId) {
	//window.setTimeout(getFontProductPriceWako, 1000, pIsMini, pWaKoEntryPK); NICHT IE-kompatibel
	
	if(typeof(wakoProcess) != "undefined"){
		if(wakoProcess != null) {
			clearTimeout(wakoProcess);
		}
	} else {
		var wakoProcess = null;
	}
	wakoProcess = window.setTimeout(function(){getFontProductPriceAfterWait(pDivisionLayerId)}, 300);
}

/*
 * Holt �ber Ajax den Verkaufspreis / MUL request.
 * Bisher nur auf der FontDetail Seite in Verwendung.
 * getFontProductPrice('detailFontBox')
 */
function getFontProductPriceAfterWait(pDivisionLayerId){
	
	var pAnzahlLizenzen  	= null;		//0 - Anzahl Lizenzen
	var pProductPK		 	= null;		//1 - PK des Produktes
	var pIsPackageBuy	 	= null; 	//2 - Paket oder Schnittekauf
	var pPayabelWeights	 	= null;		//3 - Anzahl verkaufbarer FontAtom-Produkte
	var pFormats		 	= null;		//4 - Ausgew�hlte Font Formate
	var pSelectedCuts		= null;		//5 - Anzahl Ausgew�hlter Schnitte (Paket == alle, Schnitte == selektierte) ... haben die PK des TopLevelProduktes
	var pWrapperPK			= null;		//6 - PK des Wrappers

	if (null == pDivisionLayerId || pDivisionLayerId == "" || pDivisionLayerId == 0 ) {
		pDivisionLayerId = "detailFontBox";
	}
	
	var _inputs = _inputs = YAHOO.util.Selector.query('div input', pDivisionLayerId, false);
	
	// Nach der pDivisionLayerId kann entschieden werden
	// ob es sich um den Kaufen oder Detail-Layer handelt:
	// ... entsprechend m�ssten dann die Hilfsmethode angepasst werden !!
	if(pDivisionLayerId.contains('buyLayer')){
		pWrapperPK			= getWrapperPKBuyLayer(_inputs);			//6 - PK des Wrappers
		pAnzahlLizenzen  	= getAnzahlLizenzenBuyLayer(pWrapperPK);	//0 - Anzahl Lizenzen
		pProductPK		 	= getProductPKBuyLayer(_inputs);			//1 - PK des Produktes
		pIsPackageBuy	 	= getIsPackageBuyLayer(pWrapperPK); 		//2 - Paket oder Schnittekauf
		pPayabelWeights	 	= getPayableWeightsBuyLayer(_inputs);		//3 - Anzahl verkaufbarer FontAtom-Produkte
		pFormats		 	= getSelectedFormatsBuyLayer(_inputs);		//4 - Ausgew�hlte Font Formate
		pSelectedCuts		= getSelectedCutsAsStringBuyLayer(_inputs);	//5 - Anzahl Ausgew�hlter Schnitte (Paket == alle, Schnitte == selektierte)... haben die PK des TopLevelProduktes
		
	} else if(pDivisionLayerId.contains('detailFontBox')){
		pAnzahlLizenzen  	= getAnzahlLizenzen();		//0 - Anzahl Lizenzen
		pProductPK		 	= getProductPK();			//1 - PK des Produktes
		pIsPackageBuy	 	= getIsPackage(); 			//2 - Paket oder Schnittekauf
		pPayabelWeights	 	= getPayableWeights();		//3 - Anzahl verkaufbarer FontAtom-Produkte
		pFormats		 	= getSelectedFormats();		//4 - Ausgew�hlte Font Formate
		pSelectedCuts		= getSelectedCutsAsString(_inputs);	//5 - Anzahl Ausgew�hlter Schnitte (Paket == alle, Schnitte == selektierte)... haben die PK des TopLevelProduktes
		pWrapperPK			= getWrapperPK();			//6 - PK des Wrappers
		
	}

	if (document.getElementById('pIsPackage')) {
		showChoiceFontDetail(pWrapperPK, true);
	} else {
		showChoiceFontDetail(pWrapperPK, false);	
	}
	
	// vorherige Fehlermeldungen tilgen
		if(pDivisionLayerId.contains('buyLayer')){
			showBuyingError('showInformationDiv'+pWrapperPK, false);
		} else if(pDivisionLayerId.contains('detailFontBox')){
			showBuyingError('showErrorDiv', false);
		}

	//alert("Lizenzen " + pAnzahlLizenzen + " - ProdPK " +  pProductPK+ " - IsPackage " + pIsPackageBuy + " - PayableWeights" + pPayabelWeights + " - Format" + pFormats + " - SelCuts " + pSelectedCuts + " - WrapperPK " +  pWrapperPK+ "" );
	
	// Wenn alle Werte vollst�ndig sind geht der Request raus!
	isValid = pAnzahlLizenzen != null && pAnzahlLizenzen != 0  && pAnzahlLizenzen != ""
		// && parseInt(pAnzahlLizenzen) <= 999 //change 06.04.09, because mul gives 0,00EUR back
				&& pProductPK != null 
				&& pIsPackageBuy != null 
				&& pPayabelWeights != null 
				&& pFormats != null 
				&& pSelectedCuts != null 
				&& pWrapperPK != null ;
	
	
	if (isValid == false && parseInt(pAnzahlLizenzen) > 999) {
		if(pDivisionLayerId.contains('buyLayer')){
			var cpuInput = $D.get('cpuValueInput'+pWrapperPK);
			if (null != cpuInput) {
				cpuInput.value = "";
			}
		} else {
			var cpuInput = $D.get("pAnzahlLizenzen");
			if (null != cpuInput) {
				cpuInput.value = "";
			}
		}
	}
	

	if(isValid){
		var transmitParams = 
					pAnzahlLizenzen					//0
					+ "#" + pProductPK				//1
				    + "#" + pIsPackageBuy			//2
				    + "#" + pPayabelWeights			//3
				    + "#" + pFormats				//4
				    + "#" + pSelectedCuts			//5
				    + "#" + pWrapperPK;				//6
	 	try {
				FontshopAjaxUtilities.getCalculatedPrice(
				  transmitParams, 
				  {					
				  	callback: handleReturnedHtml,
				  	errorHandler: handleErrors,
				  	async:false
					}
				);
				 
			} catch (x) {}

		if(pDivisionLayerId.contains('buyLayer')) {
		    var prices = new Array();
			
			prices = getReturnedHtml().split(":");
			document.getElementById('calculatedPrice'+pWrapperPK).innerHTML = prices[0];
			if(document.getElementById('purchasePrice'+pWrapperPK) != null){
			document.getElementById('purchasePrice'+pWrapperPK).innerHTML = prices[1];
			}
		} else if(pDivisionLayerId.contains('detailFontBox')){
		var prices = new Array();
			
				prices = getReturnedHtml().split(":");
			document.getElementById('calculatedPrice').innerHTML = prices[0];
			if(document.getElementById('purchasePrice') != null){
			    document.getElementById('purchasePrice').innerHTML = prices[1];
			}
		}
	
	} else {
		if(pDivisionLayerId.contains('buyLayer')){
			showBuyingError('showInformationDiv'+pWrapperPK, true);
		}else if(pDivisionLayerId.contains('detailFontBox')){
			showBuyingError('showErrorDiv', true);
		}
		
	}
	
}

function handleReturnedHtml (str) {
	returnedHtml = str;
	
}

function getReturnedHtml() {
	return returnedHtml;
}


function handleErrors(str){
	(str);
}

/** 
 * Gibt die aktuelle CPU-Anzahl zur�ck (u.a. aus getFontProductPrice(pDivisionLayerId) aufgerufen) 
 */
function getAnzahlLizenzen(id){
	if(typeof id== "undefined") {
		id = 'pAnzahlLizenzen';
	}
	var cpu = $D.get(id);
	if(cpu != null){
		var cpuAmount = cpu.value;
		if(isNaN(cpuAmount) || $U.isEmpty(cpuAmount) || cpuAmount.contains("+") || cpuAmount.contains("-")) {
			showBuyingError('showErrorDiv', true);
			return null;
		}
		return parseInt(cpuAmount);	
	}
	return null;
	 			
};
function getAnzahlLizenzenBuyLayer(wrapperPK){
	return getAnzahlLizenzen('cpuValueInput'+wrapperPK);
	/*
	if(document.getElementById('cpuValueInput'+wrapperPK)){
		var cpuAmount = document.getElementById('cpuValueInput'+wrapperPK).value;
		if(isNaN(cpuAmount) || $U.isEmpty(cpuAmount) || cpuAmount.contains("+") || cpuAmount.contains("-")) {
			showBuyingError('showErrorDiv', true);
			return null;
		}
		return parseInt(cpuAmount);	
	}
	return null;
	*/
};


function getProductPK(){
	if(document.getElementById('pProductPK')){
		return document.getElementById('pProductPK').value; 			
	}
	return null;
}
function getProductPKBuyLayer(_inputs){
	if(_inputs){
		for(var index=0; index<_inputs.length; index++) {
			if(_inputs[index].id == 'pProductPK'){
				return _inputs[index].value;
			}
		}
	}
	return null;	
}
function getIsPackage(){
	if(document.getElementById('pIsPackage') && document.getElementById('pIsPackage').checked == true){
		return true;	
	} else if(document.getElementById('pIsCut') && document.getElementById('pIsCut').checked == true){
		return false;
	}
	return null;
}

function getIsPackageBuyLayer(wrapperPK){
	if(document.getElementById('radiobuttonPackage'+wrapperPK) && document.getElementById('radiobuttonPackage'+wrapperPK).checked == true){
		return true;	
	} else if(document.getElementById('radiobuttonCuts'+wrapperPK) && document.getElementById('radiobuttonCuts'+wrapperPK).checked == true){
		return false;
	}
	return null;
}
 
function getPayableWeights(){
	if(document.getElementById('pPayableWeights')){
		return document.getElementById('pPayableWeights').value; 			
	} 
	return null;
}
function getPayableWeightsBuyLayer(_inputs){
	if(_inputs){
		for(var index=0; index<_inputs.length; index++) {
			if(_inputs[index].id == 'pPayableWeights'){
				return _inputs[index].value;
			}
		}
	}
	return null;	
}
/**
 * Liefert die ausgewaehlte Lieferart
 * @version 2009-02-10 DD
 */
 
/**
 * Sucht auswaehlbare Lieferarten (Version Detailseite)
 * @version 2009-02-10 DD
 * @return Array der moeglichen Lieferarten
 */
function getShipping(idList){
	for(var index=0; index < idList.length; index++) {
		var element = $D.get(idList[index]);
		if(element != null && element.checked){
			return element.value;
		} 
	}
	return null;
}

function getShippingBuyLayer(_inputs){
	for(var index=0; index<_inputs.length; index++) {
		if(_inputs[index].name == 'shippingPackage'+getWrapperPKBuyLayer(_inputs) && _inputs[index].disabled == false && _inputs[index].checked == true){
			return _inputs[index].value;  			
		} 
	}
	return null;
}

function getSelectedFormats(){
	if(document.getElementsByName('pFontFormat')){
		var myFormats = document.getElementsByName('pFontFormat');
		for(var index=0; index<myFormats.length; index++) {
			if(myFormats[index].checked == true){
				return myFormats[index].value;
			} 
		}
	}
	return null;
}
function getSelectedFormatsBuyLayer(_inputs){
	for(var index=0; index<_inputs.length; index++) {
		if(_inputs[index].name == 'features_buy_details_formats'+getWrapperPKBuyLayer(_inputs) && _inputs[index].disabled == false && _inputs[index].checked == true){
			return _inputs[index].value; 			
		} 
	}
	return null;
}

function getSelectedCutsAsString(_inputs){

	var checkedFontCuts = new Array();

	var myForm = document.forms['checkFontsForm'];
	if(myForm){	
		var fontCuts = myForm.elements;
		for(var i=0; i<fontCuts.length; i++) {
			if(getIsPackage()){ // Alle
				if(fontCuts[i].type == 'checkbox'){
					checkedFontCuts.push(fontCuts[i].id);
				}
			} else { // selektierte
				if(fontCuts[i].type == 'checkbox' && fontCuts[i].checked == true){
					checkedFontCuts.push(fontCuts[i].id);
				}				
			}
		}
	}
	if(checkedFontCuts.length > 0){
		return checkedFontCuts.join(',');	
	} else {
		return checkedFontCuts; // just leave empty
	}
	
	
}
function getSelectedCutsAsStringBuyLayer(_inputs){
	var checkedFontCuts = new Array();
	if(document.getElementById('fontsSelect'+getWrapperPKBuyLayer(_inputs))){
		var fontCuts =  document.getElementById('fontsSelect'+getWrapperPKBuyLayer(_inputs)).options;
		for(var i=0; i<fontCuts.length; i++) {
			if(getIsPackageBuyLayer(getWrapperPKBuyLayer(_inputs))){ // Alle
				checkedFontCuts.push(fontCuts[i].id);
			}else{ // selektierte
				if(fontCuts[i] != null && fontCuts[i].selected == true){
					checkedFontCuts.push(fontCuts[i].id);
				}				
			}
		}
	}
	if(checkedFontCuts.length > 0){
		return checkedFontCuts.join(',');	
	} else {
		return checkedFontCuts; // just leave empty
	}
	
	
}

function getWrapperPK(){
	if(document.getElementById('pWrapperPK')){
		return document.getElementById('pWrapperPK').value;
	}
	return null;	
}
function getWrapperPKBuyLayer(_Inputs){
	if(_Inputs){
		for(var index=0; index<_Inputs.length; index++) {
			if(_Inputs[index].id == 'pWrapperPK'){
				return _Inputs[index].value;
			}
		}
	}
	return null;	
}

function getPrice(){
	var calculatedPrice = document.getElementById('calculatedPrice').innerHTML;
	return trim(calculatedPrice);
}
function getPriceBuyLayer(wrapperPK){
	var calculatedPrice = document.getElementById('calculatedPrice'+wrapperPK).innerHTML;
	return trim(calculatedPrice);
}

function getPurchasePriceBuyLayer(wrapperPK){
	var purchasePrice = document.getElementById('purchasePrice'+wrapperPK).innerHTML;
	return trim(purchasePrice);
}

function getFmdbProduct4WaKo(){
	if(document.getElementById('pFMDBID')){
		return document.getElementById('pFMDBID').value;
	}
	return null;	
}
function getFmdbProduct4WaKoBuyLayer(wrapperPK){
	if(document.getElementById('pFMDBID'+wrapperPK)){
		return document.getElementById('pFMDBID'+wrapperPK).value;
	}
	return null;	
}
function getSelectableFormats(_inputs){
	
	var selectableFormats  = new Array();
	
	for(var index=0; index<_inputs.length; index++) {
		if(_inputs[index].name == 'pFontFormat' && _inputs[index].disabled == false){
			selectableFormats.push(_inputs[index].value); 			
		} 
	}
	if(selectableFormats.length > 0){
		return selectableFormats.join(',');	
	}
	return null;
	
}
function getSelectableFormatsBuyLayer(_inputs){
	
	var selectableFormats  = new Array();
	
	for(var index=0; index<_inputs.length; index++) {
		
		if(_inputs[index].name == 'features_buy_details_formats'+getWrapperPKBuyLayer(_inputs) && _inputs[index].disabled == false){
			selectableFormats.push(_inputs[index].value); 			
		} 
	}
	
	if(selectableFormats.length > 0){
		return selectableFormats.join(',');	
	}
	return null;
	
}
/**
 * Sucht auswaehlbare Lieferarten (Version Detailseite)
 * @version 2009-02-10 DD
 * @return Array der moeglichen Lieferarten
 */
function getSelectableDeliveries(idList){
	
	var selectableDeliveries  = new Array();
	
	for(var index=0; index < idList.length; index++) {
		var element = $D.get(idList[index]);
		if(element != null && element.disabled == false){
			selectableDeliveries.push(element.value); 			
		} 
	}
	if(selectableDeliveries.length > 0){
		return selectableDeliveries.join(',');	
	}
	return null;
}

function getSelectableDeliveriesBuyLayer(_inputs){
	
	var selectableDeliveries  = new Array();
	
	for(var index=0; index<_inputs.length; index++) {
		if(_inputs[index].name == 'shippingPackage'+getWrapperPKBuyLayer(_inputs) && _inputs[index].disabled == false){
			selectableDeliveries.push(_inputs[index].value); 			
		} 
	}
	if(selectableDeliveries.length > 0){
		return selectableDeliveries.join(',');	
	}
	return null;
}

/* 
 * Ende 
 * Hilfsfunktionen von getFontProductPrice(pDivisionLayerId) */
	
/*
 * F�gt die Auswahl in den Warenkorb hinzu.
 * Bisherige Verwendung nur im Detail Layer.
 * Asynchrone Ajax Request.
 */	
 function addToCart(pDivisionId) {
	 	
	 	
	 	// F�r die Cart braucht es an:
	 	//  1) Ausw�hlbaren Formaten
	 	//  2) Ausw�hlbaren Versandarten
	 	//  3) das gew�hlte Format
	 	//  4) die gew�hlte Versandart
	 	//  5) den Preis
	 	//  6) Anzahl Lizenzen
	 	//  7) FMDBID des repres. Produktes
	 	//  8) WrapperPK
	 	//  9) Paket oder Einzelschnitte
	 	// 10) die gew�hlten Schnitte
	 	// 11) ProduktPK
	 	
	 	// bilde hier die Parameter
	 	var query = '';
	 	
	 	var _inputs = YAHOO.util.Selector.query('div input', pDivisionId, false);
	 	//  1) Ausw�hlbaren Formaten
	 	var selectableFormats = null;
	 	//  2) Ausw�hlbaren Versandarten
	 	var selectableDeliveries = null;
	 	//  3) das gew�hlte Format
	 	var selectedFormat = null;
	 	//  4) die gew�hlte Versandart
	 	var selectedDelivery = null;
	 	//  5) den Preis
	 	var price = null;
	 	//  6) Anzahl Lizenzen
	 	var licenseAmount = null;
	 	//  7) FMDBID des repres. Produktes
	 	var fmdbProduct = null;
	 	//  8) WrapperPK
	 	var wrapperPK = null;
	 	//  9) Paket oder Einzelschnitte
	 	var ispackage = null;
	 	// 10) die gew�hlten Schnitte
	 	var selectedCutPKs = null;
	 	// 11) ProduktPK
		var productPK = null;
		
		// 12) purchasePrice
		var purchasePrice = null;

		if(pDivisionId.contains('buyLayer')){
		 	//  8) WrapperPK
		 	wrapperPK = getWrapperPKBuyLayer(_inputs);
		 	//  1) Ausw�hlbaren Formaten
		 	selectableFormats = getSelectableFormatsBuyLayer(_inputs);
		 	//  2) Ausw�hlbaren Versandarten
		 	selectableDeliveries = getSelectableDeliveriesBuyLayer(_inputs);
		 	//  3) das gew�hlte Format
		 	selectedFormat = getSelectedFormatsBuyLayer(_inputs);
		 	//  4) die gew�hlte Versandart
		 	selectedDelivery = getShippingBuyLayer(_inputs);
		 	//  5) den Preis
		 	price = getPriceBuyLayer(wrapperPK);
		 	//  6) Anzahl Lizenzen
		 	licenseAmount = getAnzahlLizenzenBuyLayer(wrapperPK);
		 	//  7) FMDBID des repres. Produktes
		 	fmdbProduct = getFmdbProduct4WaKoBuyLayer(wrapperPK);
		 	//  9) Paket oder Einzelschnitte
		 	ispackage = getIsPackageBuyLayer(wrapperPK);
		 	// 10) die gew�hlten Schnitte
		 	selectedCutPKs = getSelectedCutsAsStringBuyLayer(_inputs);
		 	// 11) ProduktPK
			productPK = getProductPKBuyLayer(_inputs);
			// 12) purchasePrice
			purchasePrice = getPurchasePriceBuyLayer(wrapperPK);
		}
		else if(pDivisionId.contains('detailFontBox')){		 	
		 	//  8) WrapperPK, nach vorne gesetzt, weil ben�tigt
		 	wrapperPK = getWrapperPK(_inputs);
		 	var deliveryIds = new Array('radioDownload'+wrapperPK,'radioCD'+wrapperPK);
		 	
		 	//  1) Ausw�hlbaren Formaten
		 	selectableFormats = getSelectableFormats(_inputs);
		 	//  2) Ausw�hlbaren Versandarten
		 	selectableDeliveries = getSelectableDeliveries(deliveryIds);
		 	//  3) das gew�hlte Format
		 	selectedFormat = getSelectedFormats(_inputs);
		 	//  4) die gew�hlte Versandart
		 	selectedDelivery = getShipping(deliveryIds);
		 	//  5) den Preis
		 	price = getPrice();
		 	//  6) Anzahl Lizenzen
		 	licenseAmount = getAnzahlLizenzen();
		 	//  7) FMDBID des repres. Produktes
		 	fmdbProduct = getFmdbProduct4WaKo(_inputs)
		 	//  9) Paket oder Einzelschnitte
		 	ispackage = getIsPackage(_inputs);
		 	// 10) die gew�hlten Schnitte
		 	selectedCutPKs = getSelectedCutsAsString(_inputs);
		 	// 11) ProduktPK
			productPK = getProductPK(_inputs);
		
		}

	//changed as of 16.02.2009 (mail from Arne Boenke) :: if no bezugsart is set, set selectedDelivery default to "download"
	if (null == selectedDelivery) {
		selectedDelivery = "download";
	}
	


	// Wenn alle Werte vollst�ndig sind geht der Request raus!
	isValid = licenseAmount != null && licenseAmount != 0   
		 	&& selectableFormats != null
		 	&& selectableDeliveries != null
		 	&& selectedFormat != null
		 	&& selectedDelivery != null
		 	&& price != null
		 	&& fmdbProduct != null
		 	&& wrapperPK != null
		 	&& ispackage != null
		 	&& selectedCutPKs != null
			&& productPK != null;

	if(isValid){
		query = 
	 		'selectableFormats='+selectableFormats+
	 		'&selectableDeliveries='+selectableDeliveries+
	 		'&selectedFormat='+selectedFormat+
	 		'&selectedDelivery='+selectedDelivery+
	 		'&price='+price+
	 		'&licenseAmount='+licenseAmount+
	 		'&fmdbProduct='+fmdbProduct+
	 		'&wrapperPK='+wrapperPK+
	 		'&ispackage='+ispackage+
	 		'&selectedCutPKs='+selectedCutPKs+
	 		'&productPK='+productPK+
	 		'&purchasePrice='+purchasePrice;
	 		
	 		
	 	// ajax-request in den NotepadController
	 	YAHOO.util.Connect.asyncRequest("POST", "addFontToCart.htm", 
			{ 
				success : function(resp){
					// ich glaube das ist nicht erw�nscht .... mache das nachher weg..
					YAHOO.hmmh.Accordion.reloadCart();
				    changeWaKoIcon2Green(productPK);
					YAHOO.hmmh.Accordion.wakoAufmachen();
					//window.setTimeout("YAHOO.hmmh.Accordion.acdnAufZiehen1()", 0); // not open accordion on icon click 2009-09-11 openOnClick
					}
				},query);
	}else{
		if(pDivisionId.contains('buyLayer')){
			showBuyingError('showInformationDiv'+wrapperPK, true);
		}else if(pDivisionId.contains('detailFontBox')){
			showBuyingError('showErrorDiv', true);
		}
		
	}
		 	

}

function loopSelected(selectId, returnNames)
{
  if (returnNames == null) {
  	returnNames = false;
  }
  var selectedArray = new Array();
  var selectedNamesArray = new Array();
  var selObj = document.getElementById(selectId);
  var i;
  var count = 0;
  if (selObj!=null) {
	  for (i=0; i<selObj.options.length; i++) {
	    if (selObj.options[i].selected) {
	      selectedArray[count] = selObj.options[i].value;
	      selectedNamesArray[count] = selObj.options[i].title;
	      count++;
	    }
	  }
  }
  
 if (returnNames == true && count > 0) {
 	selectedArray = selectedNamesArray;
 }
  
 return selectedArray;
}



//used for CheckBoxes AND Radios
function checkRadio(whichRadio, otherRadio2check, checkVar) {
	if (checkVar == null) {
		checkVar = true;
	}
	if (whichRadio!=null) {
		
		var radio2get = document.getElementById(whichRadio);
		var otherRadio2check = document.getElementById(otherRadio2check);
		if (radio2get!=null) {
			
			radio2get.checked = checkVar;
			if (checkVar == false) {
				//this was a "trash-call" - so try to remove the entry!
				//just call check4Values for that!
				var hiddenInputVars = new Array();
				var hiddenInput = document.getElementById("hidden"+whichRadio);
				if (hiddenInput != null) {
					hiddenInputVars = hiddenInput.name.split(",");
					if (hiddenInputVars.length > 0) {
						var prodPk = hiddenInputVars[0];
						var cutsC = hiddenInputVars[1];
						var errDiv = hiddenInputVars[2];
						var cpuV = hiddenInputVars[3];
						var wrapPk = hiddenInputVars[4];
						check4Values(null, prodPk, cutsC, errDiv, cpuV, wrapPk, 'true');
					}
				}
			} 	
			
		} else {
			if (otherRadio2check!=null) {
				otherRadio2check.checked = checkVar;
			}
		}
		
		/* webfonts - ist das Format WEB gewaehlt wir automatisch eine Preisberechnung durchgefuehrt */
		if(whichRadio.contains('radioWeb')){
			getFontProductPrice('buyLayer'+whichRadio.substring(8));
		}
		 
	}	
}


function check4PlatformAndFormats(wrapperPK) {
	var allSelectedCheckboxes = new Array();
	
	var checkOne = document.getElementById("MacPS"+wrapperPK);
	var checkTwo = document.getElementById("PCPS"+wrapperPK);
	var checkThree = document.getElementById("PCTT"+wrapperPK);
	var checkFour = document.getElementById("OT"+wrapperPK);
	var checkFive =  document.getElementById("MIX"+wrapperPK);
	
	if (checkOne!=null && checkOne.checked == true) {
		allSelectedCheckboxes.push("macps");
	}
	if (checkTwo!=null && checkTwo.checked == true) {
		allSelectedCheckboxes.push("pcps");
	}
	if (checkThree!=null && checkThree.checked == true) {
		allSelectedCheckboxes.push("pctt");
	}
	if (checkFour!=null && checkFour.checked == true) {
		allSelectedCheckboxes.push("ot");
	}
	if (checkFive!=null && checkFive.checked == true) {
		allSelectedCheckboxes.push("mix");
	}
	
	
	return allSelectedCheckboxes;
}


function showBuyingError(errorDivId, showTextBool) {
	var errorDiv = document.getElementById(errorDivId);
	var errorMsgEl = document.getElementById("text4CPUError");
	
	if (errorDiv != null && errorMsgEl!=null) {
		var errorMsg = document.getElementById("text4CPUError").value;
		if (showTextBool == true) {
			errorDiv.innerHTML = errorMsg;
		} else {
			errorDiv.innerHTML = "";	
		}
	}
}

function updateInformationDiv(messageVar, wrapperPK) {
	
	var showDivId = "showInformationDiv" + wrapperPK;
	var showInfoDiv = document.getElementById(showDivId);
	var cutsName = "Schnitte";
	
	if (messageVar == 1){
		cutsName = "Schnitt";
	} else if (messageVar == 0){
		cutsName = "1 Paket";
	}
	
	//in case there are no cuts buyable, only display "package" as info
	if (messageVar == 0){
		messageVar = cutsName;
	} else {
		messageVar = messageVar + " " + cutsName;
	}
	
	if (showInfoDiv != null && messageVar!=null) {
		var completeString = "Ihre Auswahl: <span style='font-weight: bold;'>" 
							+ messageVar 
							+ "</span></strong>."
		showInfoDiv.innerHTML = completeString;
	}

	
}


function showChoiceFontDetail(wrapPk, isPackageSaleable) {	
	
	var detailInfoRight = document.getElementById('ihreAuswahlFontDetailInfoRight');
	var detailInfo = document.getElementById('ihreAuswahlFontName');
	var isPackage = document.getElementById('pIsPackage');
	
	if(isPackage != null && isPackage.checked == true) {
		if (detailInfoRight!=null){
			detailInfoRight.innerHTML='(1 Schriftpaket)';
		} 
		if (detailInfo!=null){
			var hiddenName = document.getElementById("packageNameDetailsPage");
			detailInfo.innerHTML = hiddenName.innerHTML;
		}
	} else {
		var anzahlSchnitte = 0;
		var cutsArray = new Array();
		if (document.forms['checkFontsForm']) {
			var meine = document.forms['checkFontsForm'].elements;
			for(i = 0;i < meine.length;i++) {
	        	if(meine[i].name == 'font' && meine[i].checked == true) {
	        		anzahlSchnitte++;
					cutsArray.push(meine[i].alt);
				}
	       	}
		}
       	if (cutsArray.length > 0) {
       		//there is min one checkbox thats checked or unchecked, select the radiobutton for cuts!
			if (wrapPk!=null) {
			var getAccordingRadiobutton = document.getElementById("pIsCut");
				if (getAccordingRadiobutton!=null) {
					getAccordingRadiobutton.checked = true;
				}
			}
       	}
       	
       	if (detailInfoRight!=null){
			if (anzahlSchnitte == 1 ||  anzahlSchnitte == "1") {
				detailInfoRight.innerHTML='('+anzahlSchnitte+' Einzelschnitt)';
			} else {
				detailInfoRight.innerHTML='('+anzahlSchnitte+' Einzelschnitte)';
			}	
		}
		if (detailInfo!=null){
			detailInfo.innerHTML = cutsArray.join(""); 
			var text4Inner = "";
			if (anzahlSchnitte == 0 && isPackageSaleable == true) {
				text4Inner =  "Bitte haken Sie die gew&uuml;nschten Schnitte in der linken Auflistung an oder w&auml;hlen Sie das Paket aus.";
				if (null != document.getElementById("noSelectionPackageCuts")) {
					text4Inner = document.getElementById("noSelectionPackageCuts").value;
				}
				detailInfo.innerHTML = text4Inner;
			} else if (anzahlSchnitte == 0) {
				text4Inner = "Bitte haken Sie die gew&uuml;nschten Schnitte in der linken Auflistung an.";
				if (null != document.getElementById("noSelectionCuts")) {
					text4Inner = document.getElementById("noSelectionCuts").value;
				}
				detailInfo.innerHTML = text4Inner;
			}
		}
       
	}
       	
}

/* fontAtomPKs String Array*/
function getStyleNamesForFontAtom(fontAtomPKs)
{
	var transmitParams = fontAtomPKs.join("#");
				
		try {
			FontshopAjaxUtilities.getStyleNamesForFontAtom(
			  transmitParams, {				//params
			  callback: handleDefaultCallback,	//callback
			  errorHandler: handleErrors,
			  async:false
			});
			
			closeLayer(layerId);
			
		} catch (x) {

		}
}

function showBlueBorder(divId, el) {
	var ourSelDiv = document.getElementById(divId);
	if (el != null && el != true && el != false) {
		var ourChb = document.getElementById(el.id);
		if (ourSelDiv!=null && ourChb != null && ourChb.checked == true) {
			// style is read only in IE!
			//ourSelDiv.setAttribute("style", "width:390px;overflow:hidden;margin-left:10px;border:2px solid #016FBC;");
			ourSelDiv.style.border = "2px solid #016FBC";
		} else if (ourChb != null && ourChb.checked == false){ 
			//ourSelDiv.setAttribute("style", "width:390px;overflow:hidden;margin-left:10px;border:2px solid #fff;");
			ourSelDiv.style.border = "2px solid #FFFFFF";
		}
	} else {
		if (el == true) {
			//ourSelDiv.setAttribute("style", "width:390px;overflow:hidden;margin-left:10px;border:2px solid #016FBC;");
			ourSelDiv.style.border = "2px solid #016FBC";
		} else if (el == false) {
			// style is read only in IE!
			//ourSelDiv.setAttribute("style", "width:390px;overflow:hidden;margin-left:10px;border:2px solid #fff;");
			ourSelDiv.style.border = "2px solid #FFFFFF";
		}
	}
}

function showBlueBorder4All(field, activate) {
	for (i = 0; i < field.length; i++) {
		showBlueBorder("div4Overflow"+field[i].id, activate);
	}
}


/**
 * Function to check if the other inputs have been instantiated, and WHERE, 
 * then updating the margin for the other divs for autosuggest
 */
function check4OtherInputs(fontNameInputID, manufacturerInputID, designerInputID) {
	
	var runs = 1;
	
	//do we have multiple "same" named autosuggest inputs?
	if (inputIDcounter!=null && inputIDcounter > 0) {
		runs = inputIDcounter;
	}
	
	var parentEl = document.getElementById("kosSuchkriterien");
	var margin4FontnameInput = 0;
	var margin4ManufacturerInput = 0;
	var margin4DesignerInput = 0;
		
	//since we can have multiple "same" named inputs, check each via counter
	for(k=0;k<runs;k++) {
	
		//check against childnode-position of surrounding parent div
		if (parentEl!=null) {
		
			var fontNameInput = document.getElementById(fontNameInputID + k);
			var manufacturerInput = document.getElementById(manufacturerInputID + k);
			var designerInput = document.getElementById(designerInputID + k);
			
			var fontSuggestDivID = "suggestfontscontainer" + k;
			var manufacturerSuggestDivID = "suggestcompanycontainer" + k;
			var designerSuggestDivID = "suggestdesignercontainer" + k;
		
			try {

				var tmpElCh = parentEl.childNodes[1]; //tbody
				var parElChildNodes = tmpElCh.childNodes;
				
				for(i = 0; i < parElChildNodes.length; i++) {
					var currEl = parentEl.childNodes[1].childNodes[i];
		        	var topEl = currEl.childNodes[1];
			       
					if(topEl!=null && topEl.childNodes != null && topEl.childNodes.length >0) {
				        var subEl = topEl.childNodes[0];
				        if(subEl!=null && subEl.childNodes != null && subEl.childNodes.length >0) {
			        		var childNode2Check = subEl.childNodes[1];
				        	var addMargin = 0;
				        	//calculate the top - Margin that needs to be set for each div
				        	//*************************************************************
				        	//THIS was checked with FIREFOX!! (adapt for IE)
//				        	if (i > 0) {
//				        		if(i > 1 && i%2==0){
//				        			addMargin = (i * 38) + 3;
//				        		} else {
//				        			if (i == 1) {
//				        				addMargin = 54;
//				        			} else {
//				        				addMargin = (i * 36) - (i * 2); 
//				        			}
//				        		}
//				        		
//				        	} else {
//				        		addMargin = 30;
//				        	}
				        	//there can be a max input field amount of 5 - so just check and set!!
				        	//starts at 30px from top div, add 24px per "row"
				        	if (i == 0) {
				        		addMargin = 30;
				        	} else if (i == 1) {
				        		addMargin = 54;
				        	} else if (i == 2) {
				        		addMargin = 78;
				        	} else if (i == 3) {
				        		addMargin = 102;
				        	} else if (i == 4) {
				        		addMargin = 126;
				        	} 
				        	
				        	
				        	
				        	//*************************************************************
				        	if (childNode2Check!=null) {
								
								if (childNode2Check.id == fontSuggestDivID){
									margin4FontnameInput = addMargin;
									
								} else if (childNode2Check.id == manufacturerSuggestDivID){
									margin4ManufacturerInput = addMargin;
									
								} else if (childNode2Check.id == designerSuggestDivID){
									margin4DesignerInput = addMargin;
								
								}
							}
				        }
					}
		        }
			
			
				var fontSuggestDiv = document.getElementById(fontSuggestDivID);
				var manufacturerSuggestDiv = document.getElementById(manufacturerSuggestDivID);
				var designerSuggestDiv = document.getElementById(designerSuggestDivID);
				
				//set the top - margin 
				if (fontSuggestDiv!=null){
					fontSuggestDiv.setAttribute("style",  " position: absolute; top:"+margin4FontnameInput+"px;");
				}
				if (manufacturerSuggestDiv!=null){
					manufacturerSuggestDiv.setAttribute("style", "position: absolute;  top:"+margin4ManufacturerInput+"px;");
				}
				if (designerSuggestDiv!=null){
					designerSuggestDiv.setAttribute("style",  " position: absolute; top:"+margin4DesignerInput+"px;");
				}
				
			} catch(r) {
				
			}
		}
	
	}
	
	
}


		/**
		 *  
		 * Die erweiterte Suche ein- oder ausklappen im Suchergebnis, duerfte selbsterklaerend sein 
		 */
		function toggleFontShuffle() {
			var shuffleBox = $D.get('shuffleBox');
			if($D.hasClass(shuffleBox, 'eingeblendet')) 
			{
				$D.removeClass(shuffleBox, 'eingeblendet');
				$D.addClass(shuffleBox, 'ausgeblendet');
				document.getElementById('fontShuffle').style.height = '40px';
				document.getElementById('fontShuffleBreadCrumb').style.height = '22px';
				document.getElementById('fontShuffleBreadCrumb').style.display = 'none';
				document.getElementById('linkDiv').style.marginTop = '4px';
				document.getElementById('showFontShuffleLink').innerHTML =  document.getElementById('einblenden').value;
				/*
				if(document.getElementsByName('fontShuffleBreadCrumbBreak')){
					document.getElementsByName('fontShuffleBreadCrumbBreak')[0].style.display = '';
				}
				*/
			} 
			else 
			{
				$D.addClass(shuffleBox, 'eingeblendet');
				$D.removeClass(shuffleBox, 'ausgeblendet');
				document.getElementById('fontShuffle').style.height = '409px';
				document.getElementById('fontShuffleBreadCrumb').style.height = '28px';
				document.getElementById('fontShuffleBreadCrumb').style.display = 'block';
				document.getElementById('linkDiv').style.marginTop = '-26px';
				document.getElementById('showFontShuffleLink').innerHTML = document.getElementById('ausblenden').value;
				/*
				if(document.getElementsByName('fontShuffleBreadCrumbBreak')){
					document.getElementsByName('fontShuffleBreadCrumbBreak')[0].style.display = 'none';
				}
				*/
			}
		}


function activateFontShuffle(setTabActive, openLayer, changeDivs){
	var transmitString = setTabActive + "#" + openLayer;
	var fontShuffleForm = document.getElementById("fontShuffle");
	var shuffleBox = document.getElementById("shuffleBox");
	var shuffleLayer = document.getElementById("shuffleLayer");
	var shuffleLink = document.getElementById("showFontShuffleLink");
	var fontShuffleBreadCrumb = document.getElementById("fontShuffleBreadCrumb");
	var breadCrumbInfo = document.getElementById("breadCrumbInfo");
	var linkDiv = document.getElementById("linkDiv");
	var sucheForm = document.getElementById("kompaktsuche");
	var marginLeft4BreadCrumb = 350; // default
	
	
	//false, false, true => show search tab!
	if (setTabActive==false && openLayer == false && changeDivs == true) {
		var searchFormVar = document.getElementById("surrDiv4FontShuffleSwitch");
		if (searchFormVar!=null){
			//searchFormVar.setAttribute("style", "display: block"); // overflow: visible !important;
			searchFormVar.style.display = "block";
		}
		if (sucheForm!=null && sucheForm.getAttribute("class") == "kompaktsuchefonts") {
			//sucheForm.setAttribute("style", "display: block;"); // overflow: visible !important;
			searchFormVar.style.display = "block";
		}
		
	} else if (setTabActive==true && openLayer == true && changeDivs == true) {
		// do not do anything here (for now)
		//if (sucheForm!=null && sucheForm.getAttribute("class") == "kompaktsuchefonts") {
		//	sucheForm.setAttribute("style", "display: block; overflow: hidden !important;");
		//}
	}
	saveFontShuffleVars(transmitString);
}

function shuffle(nextCategory){
	// Die Ergebnislist ausblenden...
	if(document.getElementById('fontlisting')){
		document.getElementById('fontlisting').style.display = 'none';
	}
	// dann Shufflen ...
	YAHOO.util.Connect.asyncRequest("POST", "fontshuffle.htm", 
	{
		success: function(response)
		{
			var fontShuffle = $D.get('fontShuffle');
			if(YAHOO.env.ua.ie >0) {
				var dummy = document.createElement("div");
				dummy.innerHTML = response.responseText; 
				fontShuffle.innerHTML = dummy.firstChild.innerHTML;
				//alert("dd");
			}
			else {
				fontShuffle.innerHTML = response.responseText; 
			}
		}
		 
	 } , "nextFontShuffleStep="+nextCategory);
	
	var shuffleBox = $D.get('shuffleBox');
	if(shuffleBox != null) {
		$D.addClass(shuffleBox, 'eingeblendet');
		$D.removeClass(shuffleBox, 'ausgeblendet');
	}
	//document.getElementById('fontShuffle').style.height = '430px';
	//document.getElementById('fontShuffleBreadCrumb').style.height = '30px';
	if(document.getElementById('showFontShuffleLink')){
		document.getElementById('showFontShuffleLink').innerHTML = document.getElementById('ausblenden').value;	
	}
}

/**
 * @deprecated
 */
function changeWaKoIcon2Green(fontPK) {
	
	var prevIcon = document.getElementById("wakoIcon" + fontPK);
	if (prevIcon!=null) {
		prevIcon.src = "img/icon_wk_aktiv_schriften.png";
	} else {
		//try to replace it onload
	}	
	
}
/**
 * @deprecated
 */
function changeNotePadIcon2Green(fontPK) {
	var prevIcon = document.getElementById("notepadIcon" + fontPK);
	if (prevIcon!=null) {
		prevIcon.src = "/img/icon_lt_aktiv_schriften.png";
	} else {
		//try to replace it onload
	}	
}


function enableShippingButton(radiobuttonPrefix, wrapperPK, enableBool, otherRadio2Check, wrapperPK2){
	
	// Je nachdem, ob man im Kaufenlayer die Checkbox Paket oder Einzelschnitte
	// w�hlt, betsimmt sich hier die anzuzeigende Versandart-Auswahl-M�glichkeit
	
	// Ermittle die id des Tag �beer radioCD oder radioDownload
	var id2get = radiobuttonPrefix;
	
	if (wrapperPK != null) {
		id2get = radiobuttonPrefix + wrapperPK;
	}
	var radio2Disable = document.getElementById(id2get);
	
	if (radio2Disable!=null) {
		if (enableBool!= null && enableBool == true) {
			radio2Disable.removeAttribute("disabled");
			showShippingDiv(true, wrapperPK);
		} else {
			radio2Disable.setAttribute("disabled", "disabled");
			radio2Disable.removeAttribute("checked");
			radio2Disable.removeAttribute("selected");
			
			if (otherRadio2Check!=null) {
				var id3get = otherRadio2Check;
				if (wrapperPK2!=null) {
					id3get = otherRadio2Check + wrapperPK2;
				}
				var radio2Check = document.getElementById(id3get);
				if (radio2Check!=null) {
					radio2Check.setAttribute("checked", "checked");
				}
			}
			showShippingDiv(false, wrapperPK);
		}
	}

} 
 
function showShippingDiv(enablePackage, wrapperPK) {
	
	if (wrapperPK!= null) {
		var shippingCutsDiv = document.getElementById("bezugsartCutsDiv"+wrapperPK);
		var shippingPackageDiv = document.getElementById("bezugsartPackageDiv"+wrapperPK);
		
		if (enablePackage == true) {
			if (shippingCutsDiv!=null) {
				shippingCutsDiv.style.display = "none";
			}
			if (shippingPackageDiv!=null) {
				shippingPackageDiv.style.display = "block";
			}
		} else {
			if (shippingCutsDiv!=null) {
				shippingCutsDiv.style.display = "block";
			}
			if (shippingPackageDiv!=null) {
				shippingPackageDiv.style.display = "none";
			}
		}
	}
}

		  // trim functions
		  function leftTrim(txt)
		  {
		    //Match spaces at beginning of text and replace with a null string
		    return txt.replace(/^\s+/,'');
		  }
		  function rightTrim(txt)
		  {
		    //Match spaces at end of text and replace with a null string
		    return txt.replace(/\s+$/,'');
		  }
		  function trim(txt)
		  {
		    //Remove spaces at beginning and end of text
		    return(leftTrim(rightTrim(txt)));
		  }


if (!YAHOO.hmmh) YAHOO.namespace("hmmh.removeSelectBoxSelection");
YAHOO.hmmh.removeSelectBoxSelection = function() {
	return {
		init : function() {
			var elements = YAHOO.util.Selector.query("div.detailFontBoxContentBox input");
			YAHOO.util.Event.addListener(elements, "click", YAHOO.hmmh.removeSelectBoxSelection.removeSelection, true);
			var cpus = YAHOO.util.Selector.query("input.cpuCountFonts");
			if(cpus.length > 0) {
				YAHOO.util.Event.addListener(cpus, "focus", YAHOO.hmmh.removeSelectBoxSelection.removeClass);
				YAHOO.util.Event.addListener(cpus, "blur", YAHOO.hmmh.removeSelectBoxSelection.addClass);
			}		
		},
		
		removeClass : function(e) {
			if(this.value == "0")
				this.value = "";

			$D.removeClass(this, "empty");			
		},
		
		addClass : function(e) {
			if(this.value == "" || this.value == "0") {
				$D.addClass(this, "empty");
				this.value = ""; //= "0";
			}
		},
		
		removeSelection : function(e) {
			var select = YAHOO.util.Selector.query("div.detailFontBox select.active");
			if(select.length > 0) {
				var length = select[0].length-1;
				for(var i=length;i>=0;i--) {
					select[0].options[i].selected = false;
				}
			}
		}
	};
	
}();

function uncheckFontCutRadio(checkBoxID) {
	if(checkBoxID != null){
		if (document.getElementById(checkBoxID)!=null) {
			document.getElementById(checkBoxID).checked = false;
		}
	}
	//remove the blue border, if set...
	showBlueBorder("div4Overflow"+checkBoxID, false);	
}
/**
 * @deprecated Wird ersetzt durch YAHOO.hmmh.Util.isEmpty
 */
function isEmpty( inputStr ) { 
	return ( null == inputStr || "" == inputStr ) 
}

function resetValuesInFontBuyLayer(wrapperPK) {
	
	var shipCD = document.getElementById("radioDownload" + wrapperPK); //must be checked vor values as well!
	var shipDL = document.getElementById("radioCD" + wrapperPK); //must be checked vor values as well!
	
	var pcttRadio = document.getElementById("PCTT" + wrapperPK);
	var pcpsRadio = document.getElementById("PCPS" + wrapperPK);
	var macpsRadio = document.getElementById("MacPS" + wrapperPK);
	var otRadio = document.getElementById("OT" + wrapperPK);
	
	/*webfonts*/
	var webRadio = document.getElementById("WEB" + wrapperPK);
	
	var cpuInput = document.getElementById("cpuValueInput" + wrapperPK);
	/* webfonts abfrage erweitert */
	/* if (cpuInput!= null) { */
	if (cpuInput!= null && cpuInput.value != "500000") {
		cpuInput.value = "";
	}
	if (shipCD!= null && shipDL != null) {
		if (shipDL.value == "pDownload" && shipCD.value == "pShipping" && shipCD.getAttribute("disabled")!="") {
			shipDL.setAttribute("checked", "true");
		} else if (shipDL.value == "pDownload" && shipCD.value == "pShipping" && shipDL.getAttribute("disabled")!="") {
			shipCD.setAttribute("checked", "true");
		}
	}
/*	
	if (pcttRadio != null && !pcttRadio.getAttribute("disabled")) {
		pcttRadio.setAttribute("checked", "true");
		if (pcpsRadio != null) {
			pcpsRadio.removeAttribute("checked");
		}
		if (macpsRadio != null) {
			macpsRadio.removeAttribute("checked");
		}
		if (otRadio != null) {
			otRadio.removeAttribute("checked");
		}
	} else if (pcpsRadio != null && !pcpsRadio.getAttribute("disabled")) {
		pcpsRadio.setAttribute("checked", "true");
		if (macpsRadio != null) {
			macpsRadio.removeAttribute("checked");
		}
		if (otRadio != null) {
			otRadio.removeAttribute("checked");
		}
	} else if (macpsRadio != null && !macpsRadio.getAttribute("disabled")) {
		macpsRadio.setAttribute("checked", "true");
		if (otRadio != null) {
			otRadio.removeAttribute("checked");
		}
	} else if (otRadio != null && !otRadio.getAttribute("disabled")) {
		otRadio.setAttribute("checked", "true");
	} 
	*/
	
}

/**
 * Enable auto width of main container if no teaser present
 */
$E.onContentReady("mainColFonts", function() {
	var teaser = $D.get("teaserFloatId");
	if(teaser != null) {
		var content = teaser.innerHTML.trim();
		if(content =="") {
			$D.get("mainColFonts").style.width="auto";
		}
	}
});

$E.on(window, 'load', YAHOO.hmmh.removeSelectBoxSelection.init, YAHOO.hmmh.removeSelectBoxSelection, true);
