if (!YAHOO.hmmh) YAHOO.namespace("hmmh.getPrice");

YAHOO.hmmh.getPrice = function() {
	var wakoProcess =  null;
	return {
		
		getFontProductPriceWako : function (pIsMini, pWaKoEntryPK, target){
	
		// pIsMini == true -> der kleine WaKo
		// pIsMini == false -> der große WaKo
		// pIsMini == null -> Übersichtsseite
		
		if($U.isValid(target)) {
			YAHOO.hmmh.Accordion.anzPreId = target.id;
		}
		
		var pAnzahlLizenzen  	= null;		// - Anzahl Lizenzen
		var pFormats		 	= null;		// - Ausgewählte Font Formate
		var pDeliveryMode 		= null;		// - Versand oder Download 
		var success 			= false;
		
		if(pIsMini == true){
			if(document.getElementById('cpuInputMini'+pWaKoEntryPK))
				pAnzahlLizenzen  	= document.getElementById('cpuInputMini'+pWaKoEntryPK).value;
				if(isNaN(pAnzahlLizenzen) || $U.isEmpty(pAnzahlLizenzen)) {
					pAnzahlLizenzen =  null;
				} else {
					pAnzahlLizenzen =  parseInt(pAnzahlLizenzen);	
				}
			if(document.getElementById('formatSelectionMini'+pWaKoEntryPK))
				pFormats		 	= document.getElementById('formatSelectionMini'+pWaKoEntryPK).value;
				
			if(document.getElementById('shippingSelectionMini'+pWaKoEntryPK)) {
				pDeliveryMode	 	= document.getElementById('shippingSelectionMini'+pWaKoEntryPK).value;
			}
			// Die roten Punkte löschen
			if(pAnzahlLizenzen != null && pAnzahlLizenzen > 0 && document.getElementsByName('cpuInputMini'+pWaKoEntryPK) != null && document.getElementsByName('cpuInputMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('cpuInputMini'+pWaKoEntryPK)[0].src = '';
			} else if(document.getElementsByName('cpuInputMini'+pWaKoEntryPK) != null && document.getElementsByName('cpuInputMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('cpuInputMini'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
			}
			if(pFormats != null && pFormats  != '' && document.getElementsByName('formatSelectionMini'+pWaKoEntryPK) != null && document.getElementsByName('formatSelectionMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('formatSelectionMini'+pWaKoEntryPK)[0].src = '';
			} else if(document.getElementsByName('formatSelectionMini'+pWaKoEntryPK) != null && document.getElementsByName('formatSelectionMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('formatSelectionMini'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
			}
			if(pDeliveryMode != null && pDeliveryMode != '' && document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK) != null && document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK)[0].src = '';
			} else if(document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK) != null && document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK)[0] != null){
				document.getElementsByName('shippingSelectionMini'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
			}
			
		} else if(pIsMini  == false){
			if(document.getElementById('cpuInputMaxi'+pWaKoEntryPK))
				pAnzahlLizenzen  	= document.getElementById('cpuInputMaxi'+pWaKoEntryPK).value;
				if(isNaN(pAnzahlLizenzen) || $U.isEmpty(pAnzahlLizenzen)) {
					pAnzahlLizenzen =  null;
				} else {
					pAnzahlLizenzen =  parseInt(pAnzahlLizenzen);	
				}
			if(document.getElementById('formatSelectionMaxi'+pWaKoEntryPK)) {
				var sel = $D.get('formatSelectionMaxi'+pWaKoEntryPK);
				pFormats		 	= sel.value;
			}
			if(document.getElementById('shippingSelectionMaxi'+pWaKoEntryPK))
				pDeliveryMode	 	= document.getElementById('shippingSelectionMaxi'+pWaKoEntryPK).value;
			
			// Die roten Punkte löschen
			if(pAnzahlLizenzen != null && pAnzahlLizenzen > 0 && document.getElementsByName('cpuInputMaxi'+pWaKoEntryPK) != null){
				if (document.getElementsByName('cpuInputMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('cpuInputMaxi'+pWaKoEntryPK)[0].src = '';
				}
			} else {
				if (document.getElementsByName('cpuInputMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('cpuInputMaxi'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
				}
			}
			if(pFormats != null && pFormats  != '' && document.getElementsByName('formatSelectionMaxi'+pWaKoEntryPK) != null){
				if (document.getElementsByName('formatSelectionMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('formatSelectionMaxi'+pWaKoEntryPK)[0].src = '';
				}
			} else{
				if (document.getElementsByName('formatSelectionMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('formatSelectionMaxi'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
				}
			}
			
			if(pDeliveryMode != null && pDeliveryMode != '' && document.getElementsByName('shippingSelectionMaxi'+pWaKoEntryPK) != null){
				if (document.getElementsByName('shippingSelectionMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('shippingSelectionMaxi'+pWaKoEntryPK)[0].src = '';
				}
			}else{
				if (document.getElementsByName('shippingSelectionMaxi'+pWaKoEntryPK)[0]) {
					document.getElementsByName('shippingSelectionMaxi'+pWaKoEntryPK)[0].src = 'img/icon_error_new.gif'
				}
			}
				
		} else if(pIsMini  ==  null){
			
			if(document.getElementById('cpuInputOverview'+pWaKoEntryPK))
				pAnzahlLizenzen  	= document.getElementById('cpuInputOverview'+pWaKoEntryPK).value;
				if(isNaN(pAnzahlLizenzen) || $U.isEmpty(pAnzahlLizenzen)) {
					pAnzahlLizenzen =  null;
				} else {
					pAnzahlLizenzen =  parseInt(pAnzahlLizenzen);	
				}
			if(document.getElementById('formatSelectionOverview'+pWaKoEntryPK)){
				pFormats		 	= document.getElementById('formatSelectionOverview'+pWaKoEntryPK).value;
			}
			
			if(document.getElementById('shippingSelectionOverview'+pWaKoEntryPK)){
				pDeliveryMode	 	= document.getElementById('shippingSelectionOverview'+pWaKoEntryPK).value;
			}
			
		}
		
		if(pFormats == document.getElementById("formatInputChooseText").value){
			pFormats = "";
		}
			
		if(pDeliveryMode == document.getElementById("deliveryInputChooseText").value){
			pDeliveryMode = "";
		}
		var isValid = pAnzahlLizenzen != null 
					&& pAnzahlLizenzen != 0  
					//&& parseInt(pAnzahlLizenzen) <= 999 //change 06.04.09, because mul gives 0,00EUR back
					&& pAnzahlLizenzen != "" 
					&& pAnzahlLizenzen != " "
					&& pFormats != null && pFormats != "" && pFormats != document.getElementById("formatInputChooseText").value
					&& pDeliveryMode != null && pDeliveryMode != "" && pDeliveryMode != document.getElementById("deliveryInputChooseText").value;
		
		var transmitParams = 
						pAnzahlLizenzen					//0
					    + "#" + pFormats				//1
					    + "#" + pWaKoEntryPK			//2
					    + "#" + pDeliveryMode;			//3
	
		if(isValid){
			try {
					FontshopAjaxUtilities.getCalculatedPriceWako (
					  transmitParams, 
					  {					
					  	callback: handleReturnedHtml,
					  	errorHandler: handleErrors,
					  	async:false
						}
					);
				} catch (x) {}
				
				
				
		} else {
					FontshopAjaxUtilities.checkUnspecified (
					  transmitParams, {					
					  	callback: handleReturnedHtml,
					  	errorHandler: handleErrors,
					  	async:false
						}
					);		
		}
		if(pIsMini == true){
			// kleie WaKo
			YAHOO.hmmh.Accordion.reloadCart();
		} else if(pIsMini == false){
			// große waKo
			location.href = document.URL;
		} else {
			// Aus der Übersichtsseite
			YAHOO.util.Selector.query("form #hidden-div")[0].innerHTML = '<input type="hidden" name="_target5"  value="" />';
			sendform('orderoverviewform');
		}
	},
	
	// @param target Das Event-Target von dem die aktion ausgelöst wurde
	getFontProductPriceWakoAfterWait: function (pIsMini, pWaKoEntryPK, target) {
		//window.setTimeout(getFontProductPriceWako, 1000, pIsMini, pWaKoEntryPK); NICHT IE-kompatibel	
		if(wakoProcess != null) {
			clearTimeout(wakoProcess);
		}
		wakoProcess = window.setTimeout(function(){YAHOO.hmmh.getPrice.getFontProductPriceWako(pIsMini, pWaKoEntryPK, target)}, 900);
	}
	
	
		

		
	};
}();

