var processTotal=true;	
	myVal=new Array();
	myVal[0]=new Array();
	myVal[0][0]=new Array();
	myHeader=new Array();
	myHeader[0]=new Array();
	myHeader[0][0]=new Array();
	defaultCurrency='Euro';
	switchtype="visibility";
	
	
	function suppressTotal(){
		processTotal=false;
	}
	
	function titleDetailed(selName,priceList) {
		// this function writes the usage into hidden varible
		// it is used if price has a synonym
		curSelect=document.getElementsByName('idNo_'+selName)[0];
		curValue=curSelect.options[curSelect.selectedIndex].text;
		//
		curHidden=document.getElementsByName('titleDetailed_'+selName)[0];
		curHidden.value=curValue;
	
		selHeaders(selName,priceList);

	}
	
	function selHeaders(selName,priceList) {
		//x_ füllen
		mySel=document.getElementsByName('x_'+selName)[0];
		mySel.length=0;
		j=0;
		for (i=0; i<myHeader[priceList].length; i++){
			if (myHeader[priceList][i][1] != '') {
				mySel.options[j] = new Option(myHeader[priceList][i][1],i,false,true);
				j++;
				}
			}
		mySel.selectedIndex=0;
		//y_ füllen
		mySel=document.getElementsByName('y_'+selName)[0];
		mySel.length=0;
		j=0;
		for (i=0; i<myHeader[priceList][1].length; i++){
			if (myHeader[priceList][1][i] != '') {
				mySel.options[j] = new Option(myHeader[priceList][1][i],i,false,true);
				j++;
				}
			}
		mySel.selectedIndex=0;
	
		//
		// clear all surcharges
		//
		for (var i=1; i <= maxAmountSurcharges; i++){
			mySur='surText_'+selName+'_'+i;
			mySurCheck=document.getElementsByName('sur_'+selName+'_'+i)[0];
			mySurCheck.value="";
			mySurCheck.checked=false;
			mySurId='surId_'+selName+'_'+i;
			mySurHid=document.getElementsByName(mySurId)[0];
			mySurHid.value="0";
			//mySurDiv=document.getElementsByName('surDiv_'+selName+'_'+i)[0];
			mySurDiv=document.getElementById('surDiv_'+selName+'_'+i);
			if (switchtype=="display"){				
				mySurDiv.style.display="none";
			}else{				
				mySurDiv.style.visibility="hidden";
			}
			mySurText=document.getElementById('surText_'+selName+'_'+i);
			mySurText.style.visibility="hidden";			

			if(DHTML) {
				if(NS) setCont("id",mySur,null," ");
				else   setCont("id",mySur,null," ");
			}
		
		}
		// check if table has surcharge, if yes display
		if (surcharges[priceList]) {
			for (i=0; i<surcharges[priceList].length; i++){
				mySur='surText_'+selName+'_'+(i+1);
				mySurCheck=document.getElementsByName('sur_'+selName+'_'+(i+1))[0];
				mySurCheck.value=surcharges[priceList][i][1];
				
				if (SA) mySurCheck.setAttribute("value",surcharges[priceList][i][1]);
				else mySurCheck.value=surcharges[priceList][i][1];
				
				// surchages table id
				mySurId='surId_'+selName+'_'+(i+1);
				mySurHid=document.getElementsByName(mySurId)[0];
				mySurHid.value=surcharges[priceList][i][2];
				//mySurDiv=document.getElementsByName('surDiv_'+selName+'_'+(i+1))[0];
				mySurDiv=document.getElementById('surDiv_'+selName+'_'+(i+1));
				if (switchtype=="display"){					
					mySurDiv.style.display="block";
				}else{					
					mySurDiv.style.visibility="visible";
				}
				mySurText=document.getElementById('surText_'+selName+'_'+(i+1));
				mySurText.style.visibility="visible";			

				if(DHTML) {
					if(NS) setCont("id",mySur,null,surcharges[priceList][i][0]);
				 	else   setCont("id",mySur,null,surcharges[priceList][i][0]);
				}
			
			}
		}
		calculatePrice(selName);
	}
	
	function switchNutzung(checkBox,imgNo){
		myPriceLists=document.getElementById('priceLists_'+imgNo);
		choosenPriceList=document.getElementsByName('idNo_'+imgNo)[0];
		priceList=choosenPriceList.options[choosenPriceList.selectedIndex].value;
		if (checkBox.checked == true){					
			myPriceLists.style.visibility="visible";			
			if (surcharges[priceList]) {
				numberOfSurcharges=surcharges[priceList].length;
				for (var i=1; i <= numberOfSurcharges; i++){
					mySurDiv=document.getElementById('surDiv_'+imgNo+'_'+i);
					if (switchtype=="display"){						
						mySurDiv.style.display="block";
					}else{						
						mySurDiv.style.visibility="visible";
					}
					mySurText=document.getElementById('surText_'+imgNo+'_'+i);
					mySurText.style.visibility="visible";			
				}
			}
			calculatePrice(imgNo);			
		}else{
			myPriceLists.style.visibility="hidden";			
			for (var i=1; i <= maxAmountSurcharges; i++){
				mySurDiv=document.getElementById('surDiv_'+imgNo+'_'+i);
				if (switchtype=="display"){					
					mySurDiv.style.display="none";
				}else{					
					mySurDiv.style.visibility="hidden";
				}
				mySurText=document.getElementById('surText_'+imgNo+'_'+i);
				mySurText.style.visibility="hidden";			
			}			
			resetPrice(imgNo);
		}					
	}

	function calculatePrice(imgNo) {
		myId="price_"+imgNo;
		posX=document.getElementsByName('x_'+imgNo)[0];
		posY=document.getElementsByName('y_'+imgNo)[0];
		priceObj=document.getElementsByName('idNo_'+imgNo)[0];
		priceList=priceObj.options[priceObj.selectedIndex].value;
		myX=posX.options[posX.selectedIndex].value;
		myY=posY.options[posY.selectedIndex].value;
		myPrice=parseFloat(myVal[priceList][myX][myY]);

		priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imgNo)[0];
		// HOTFIX ..
		if(typeof(priceHiddenObj)=='undefined') priceHiddenObj=document.getElementsByName('priceHiddenForTotal__'+imgNo)[0];
		
		// add surcharges
		savePrice=myPrice;
		for (var i=1; i <= maxAmountSurcharges; i++){
			mySurCheck=document.getElementsByName('sur_'+imgNo+'_'+i)[0];
			if(mySurCheck.checked) {
				myPrice=myPrice+(savePrice/100)*parseFloat(mySurCheck.value);
			}
		}
		myPrice=round(myPrice,2);
		if(typeof(priceHiddenObj)!='undefined')	priceHiddenObj.value=myPrice;

		priceHiddenObj1=document.getElementsByName('priceHidden_'+imgNo)[0];
		// HOTFIX ..
		if(typeof(priceHiddenObj1)=='undefined') priceHiddenObj1=document.getElementsByName('priceHidden__'+imgNo)[0];
		priceHiddenObj1.value=myPrice;

		if(DHTML) {
		   if(NS) setCont("id",myId,null,myPrice+" "+defaultCurrency);
		   else   setCont("id",myId,null,myPrice+" "+defaultCurrency);
		 }

		if (processTotal){
			// show total
			myPriceTotal=0;
			for(i=0; i<imagesInBasket.length; i++) {
				priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imagesInBasket[i])[0];
				if(typeof(priceHiddenObj)=='undefined') {
					// HOTFIX medical!
					priceHiddenObj=document.getElementsByName('priceHidden_'+imagesInBasket[i])[0];
				}
				myPriceTotal=myPriceTotal+parseFloat(priceHiddenObj.value);
			}
	
			if(DHTML) {
			   if(NS) setCont("id","priceSum",null,myPriceTotal.toFixed(2)+" "+defaultCurrency);
			   else   setCont("id","priceSum",null,myPriceTotal.toFixed(2)+" "+defaultCurrency);
			}
		}		
	}

	function updateTotal(priceInit) {
		
		if (arguments.length == 0) priceInit=false; 
		
		// show total
		myPriceTotal=0;
		for(i=0; i<imagesInBasket.length; i++) {
			priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imagesInBasket[i])[0];
			if(typeof(priceHiddenObj)=='undefined') {
			// HOTFIX medical!
				priceHiddenObj=document.getElementsByName('priceHidden_'+imagesInBasket[i])[0];
			}
			myPriceTotal=myPriceTotal+parseFloat(priceHiddenObj.value);
		}

		// check if bonus is defined (may be for f1online)
		if (document.getElementById('bonus')) myPriceTotal=myPriceTotal+parseFloat(document.getElementById('bonus').value);
		//bcz of bonus sometimes price can be < 0. in this case show 0
		if (myPriceTotal < 0) myPriceTotal=0;
			
		if(DHTML) {
			if (!priceInit && getCont("id","priceSum",null) != myPriceTotal.toFixed(2)+" "+defaultCurrency && typeof f1_checkoutStep1 != 'undefined') {
				// we are in f1online application and if total price has benn changed force to reload checkout page.
				//basketTotalChanged();
			}
		   if(NS) setCont("id","priceSum",null,myPriceTotal.toFixed(2)+" "+defaultCurrency);
		   else   setCont("id","priceSum",null,myPriceTotal.toFixed(2)+" "+defaultCurrency);
		}
	}

	function updateRadioNew(imgNo,setPrice) {
		priceHiddenObj=document.getElementsByName('priceHidden_'+imgNo)[0];
		priceHiddenObj.value=setPrice;
	}
	
	function updateRadio(imgNo,setPrice) {
		myId="price_"+imgNo;
		//priceHiddenObj=document.getElementsByName('priceHidden_'+imgNo)[0];
		//priceHiddenObj.value=setPrice;
		priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imgNo)[0];
		priceHiddenObj.value=setPrice;

		if(DHTML) {
		   if(NS) setCont("id","price_"+imgNo,null,setPrice+" "+defaultCurrency);
		   else   setCont("id","price_"+imgNo,null,setPrice+" "+defaultCurrency);
		}
	}
	
	function updateRadioInit(imgNo) {
		priceTableArray=document.getElementsByName('rf_'+imgNo);
		// if not found it is CD
		namePart='rf_';
		if (priceTableArray.length == 0) {
			priceTableArray=document.getElementsByName('cd_'+imgNo);
			namePart='cd_';
		}
		
		for (i=0;i<priceTableArray.length;i++){
			if(priceTableArray[i].checked){
				price=document.getElementsByName(namePart+imgNo)[i].value;
				updateRadio(imgNo,price);
			}
		}	
	}

	
	function resetPrice(imgNo) {
		myPrice=0;
		myId="price_"+imgNo;
		priceHiddenObj=document.getElementsByName('priceHidden_'+imgNo)[0];
		priceHiddenObj.value=myPrice;
		priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imgNo)[0];
		priceHiddenObj.value=myPrice;
		if(DHTML) {
		   if(NS) setCont("id",myId,null,myPrice+" "+defaultCurrency);
		   else   setCont("id",myId,null,myPrice+" "+defaultCurrency);
		 }

		// show total
		myPriceTotal=0;
		for(i=0; i<imagesInBasket.length; i++) {
			priceHiddenObj=document.getElementsByName('priceHiddenForTotal_'+imagesInBasket[i])[0];
			myPriceTotal=myPriceTotal+parseFloat(priceHiddenObj.value);
		}

		if(DHTML) {
		   if(NS) setCont("id","priceSum",null,myPriceTotal);
		   else   setCont("id","priceSum",null,myPriceTotal);
		}
		
	}

	function getSumForAllImages() {				
		for(i=0; i<imagesInBasket.length; i++) {
			if(document.getElementsByName('idNo_'+imagesInBasket[i])[0]){ //fix for RF
				posHeader=document.getElementsByName('idNo_'+imagesInBasket[i])[0];	
				selHeaders(imagesInBasket[i],posHeader.options[posHeader.selectedIndex].value);					
			}
		}
	}

	function deselectAllImages() {				
		for(ii=0; ii<imagesInBasket.length; ii++) {
			if(document.getElementsByName('idNo_'+imagesInBasket[ii])[0]){ //fix for RF
				myCheckbox=document.getElementById('nutzAng_'+imagesInBasket[ii]);
				myCheckbox.checked=false;
				switchNutzung(myCheckbox,imagesInBasket[ii]);
			}
		}
	}
	
	function deselectCheckboxesByName(name){
		checkboxes=document.getElementsByName(name);
		for(ii=0; ii<checkboxes.length; ii++) {
			checkboxes[ii].checked=false;
		}
	}
	
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}


function updateArrows(sel1Id,sel2Id,sel3Id){
	if ($('#'+sel1Id).val()==0) $('#'+sel1Id+'_arrow').show(); else $('#'+sel1Id+'_arrow').hide();	
	if ($('#'+sel2Id).val()==0) $('#'+sel2Id+'_arrow').show(); else $('#'+sel2Id+'_arrow').hide();	
	if ($('#'+sel3Id).val()==0) $('#'+sel3Id+'_arrow').show(); else $('#'+sel3Id+'_arrow').hide();	
}