	function roundNumber(num, dec) {
		var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
		return result;
	}
	
	
	function total_sum_calc(){
		var total_sum = 0;
		var col1 = 0;
		var col2 = 0;
		var col3 = 0;
		var col4 = 0;
		var total_max = 20;
		if((document.getElementById('total_transp').innerHTML.lenght==0)||(document.getElementById('total_transp').innerHTML==null)){
			//alert('ads1');
			col1 = 0;
		}else{
			//alert('ads2');
			col1 = document.getElementById('total_transp').innerHTML;
		}
		if((document.getElementById('total_food').innerHTML.lenght=='undefined')||(document.getElementById('total_food').innerHTML==null)||(document.getElementById('total_food').innerHTML=='&nbsp;')){
			//alert('ads3'+document.getElementById('total_food').innerHTML.lenght + document.getElementById('total_food').innerHTML);
			col2 = 0;
		}else{
			//alert('ads4'+document.getElementById('total_food').innerHTML.lenght + document.getElementById('total_food').innerHTML);
			col2 = document.getElementById('total_food').innerHTML;
		}
		if((document.getElementById('total_house').innerHTML.lenght=='undefined')||(document.getElementById('total_house').innerHTML==null)||(document.getElementById('total_house').innerHTML=='&nbsp;')){
			//alert('ads5');
			col3 = 0;
		}else{
			//alert('ads6');
			col3 = document.getElementById('total_house').innerHTML;
		}
		if((document.getElementById('total_life').innerHTML.lenght=='undefined')||(document.getElementById('total_life').innerHTML==null)||(document.getElementById('total_life').innerHTML=='&nbsp;')){
			//alert('ads7');
			col4 = 0;
		}else{
			//alert('ads8');
			col4 = document.getElementById('total_life').innerHTML;
		}
		/*
		col1 = document.getElementById('total_transp').innerHTML;
		col2 = document.getElementById('total_food').innerHTML;
		col3 = document.getElementById('total_house').innerHTML;
		col4 = document.getElementById('total_life').innerHTML;
		*/
		total_sum = roundNumber((col1*1 + col2*1 + col3*1 + col4*1),1);
		document.calc.score.value = total_sum;
		document.getElementById('total_sum').innerHTML =  total_sum;
		if(total_sum > 12){
			total_sum=12;
		}
		
		
		document.getElementById('stripa').style.width = (total_sum/12*673)+"px"; 
		
	}
	
	
	function update_values_transp(){
		// how much km per week
		var car = 0;
		var public_transp = 0;
		var plane = 0;
		var i=0;
		// ================================
		// ==== 1 colon 1 set =============
		var kmNed = document.getElementById('kmNed').value;		
		var bcartype_alone = 1;
		var bcartype_bioval = 1;
		var transptypeval = 0;
		var bio_i = 0;
		// value getting from car type radio
		for (i=0; i < document.calc.bcartype.length; i++){
			if (document.calc.bcartype[i].checked){
				transptypeval = document.calc.bcartype[i].value;
				if(i == 4){
					bio_i=1;
				}else{
					bio_i=0;
				}
			}
		}
		if(bio_i==0){
			document.calc.bcartype_bio.disabled = false;
			if (document.calc.bcartype_bio.checked){
				bcartype_bioval = document.calc.bcartype_bio.value;
			}else{
				bcartype_bioval = 1;
				document.calc.bcartype_bio.disabled = false;
			}
			
		}else{
			bcartype_bioval = 1;
			document.calc.bcartype_bio.checked = false;
			document.calc.bcartype_bio.disabled = true;
		}
		
		
		
		
		// checkbox if you drive alone
		if (document.calc.bcartype_alone.checked){
			bcartype_alone = document.calc.bcartype_alone.value;
		}
		// checkbox if you drive with bio fuel 
		//if (document.calc.bcartype_bio.checked){
		//	bcartype_bio = document.calc.bcartype_bio.value;
		//}
		// sum and calculations of car data
		car = Math.round(transptypeval*kmNed*52*0.189*bcartype_alone*bcartype_bioval);
		
		// ================================
		// ==== 1 colon 2 set =============
		var kmTrain = 0;
		var kmBus = 0;
		var kmMoto = 0;
		kmTrain = document.getElementById('transp_train').value;
		kmBus = document.getElementById('transp_bus').value;
		//kmMoto = document.getElementById('transp_moto').value;
		// sum and calculations for train, buss and motocycle
		public_transp = Math.round(kmTrain*52*0.05 + kmBus*52*0.04);
		
		// ================================
		// ==== 1 colon 3 set =============
		var plane_1 = 0;
		var plane_2 = 0;
		var plane_3 = 0;
		var plane_4 = 0;		
		plane_1 = document.getElementById('plane_1').value;
		plane_2 = document.getElementById('plane_2').value;
		plane_3 = document.getElementById('plane_3').value;
		plane_4 = document.getElementById('plane_4').value;
		// sum and calculations for plane
		plane = Math.round(plane_1*125 + plane_2*300 + plane_3*450 + plane_4*840);
		
		// transp total 
		document.getElementById('total_transp').innerHTML =  roundNumber(((car + public_transp + plane)/1000),1);
		total_sum_calc();
	}
	function update_values_food(){
		// ================================
		// ==== 2 colon food  =============
		var food=0;
		var bfoodtype1val = 0;
		var bfoodtype2val = 0;
		var bfoodtype3val = 0;
		var bfoodtype4val = 0;
		var bfoodsizeval= 0;
		var foodstyleval= 1;
		var i=0;
		for (i=0; i < document.calc.bfoodtype1.length; i++){
			if (document.calc.bfoodtype1[i].checked){
				bfoodtype1val = document.calc.bfoodtype1[i].value;
			}
		}
		for (i=0; i < document.calc.bfoodtype2.length; i++){
			if (document.calc.bfoodtype2[i].checked){
				bfoodtype2val = document.calc.bfoodtype2[i].value;
			}
		}
		for (i=0; i < document.calc.bfoodtype3.length; i++){
			if (document.calc.bfoodtype3[i].checked){
				bfoodtype3val = document.calc.bfoodtype3[i].value;
			}
		}
		for (i=0; i < document.calc.bfoodtype4.length; i++){
			if (document.calc.bfoodtype4[i].checked){
				bfoodtype4val = document.calc.bfoodtype4[i].value;
			}
		}
		for (i=0; i < document.calc.bfoodsize.length; i++){
			if (document.calc.bfoodsize[i].checked){
				bfoodsizeval = document.calc.bfoodsize[i].value;
			}
		}
		if (document.calc.foodstyle_1.checked){
			foodstyleval = document.calc.foodstyle_1.value;
		}
		// sum and calculations for food
		food = parseFloat(bfoodtype1val)+parseFloat(bfoodtype2val)+parseFloat(bfoodtype3val)+parseFloat(bfoodtype4val) + 200;
		
		
		
		food = roundNumber(((Math.round(food*bfoodsizeval*foodstyleval))/1000),2);
		// food total 
		document.getElementById('total_food').innerHTML =  food;
		total_sum_calc();
	}
	function update_values_house(){
		// ================================
		// ==== 3 colon house =============
		var house = 0;
		var bhousetypeval = 0;
		var bheatypeval = 0;
		var bheattypeval = 1;
		var bhousewindval = 1;
		var house_sizeval = 0;
		var house_peopleval = 0;
		var itais=0;
		var i=0;
		
		for (i=0; i < document.calc.bhousetype.length; i++){
			if (document.calc.bhousetype[i].checked){
				bhousetypeval = document.calc.bhousetype[i].value;
				//alert(i);
				if(i == 3){
					itais=1;
				}else{
					itais=0;
				}
			}
		}
		
		if(itais==0){
			if (document.calc.bhousewind.checked){
				bhousewindval = document.calc.bhousewind.value;
				bheattypeval = 1;
				document.calc.bheattype.disabled = true;
			}else{
				document.calc.bheattype.disabled = false;
			}
			if (document.calc.bheattype.checked){
				bheattypeval = document.calc.bheattype.value;
				bhousewindval = 1; 
				document.calc.bhousewind.disabled = true;
			}else{
				document.calc.bhousewind.disabled = false;
			}
		}else{
			bheattypeval = 1;
			document.calc.bheattype.disabled = true;
			bhousewindval = 1; 
			document.calc.bhousewind.disabled = true;
		}
		for (i=0; i < document.calc.bheatype.length; i++){
			if (document.calc.bheatype[i].checked){
				bheatypeval = document.calc.bheatype[i].value;
			}
		}
		
		house_sizeval = document.getElementById('house_size').value;
		house_peopleval = document.getElementById('house_people').value;
		// sum and calculations for house
		
		house = roundNumber((((Math.round((house_sizeval/house_peopleval)*bhousetypeval*bhousewindval*bheattypeval)*bheatypeval)/1000)/1000),2);
		// house total 
		//house = bheattypeval;
		document.getElementById('total_house').innerHTML =  house;
		total_sum_calc();
	}
	
	function update_values_life(){
		// ================================
		// ==== 4 colon lifestyle =========
		var total_life = 0;
		var blifetypeval = 0;
		var lifestyle_1val = 200;
		var lifestyle_2val = 60;
		var lifestyle_3val = 100;
		var lifestyle_4val = 160;
		var i=0;
		
		for (i=0; i < document.calc.blifetype.length; i++){
			if (document.calc.blifetype[i].checked){
				blifetypeval = document.calc.blifetype[i].value;
			}
		}
		// checkbox if you drive alone
		if (!document.calc.lifestyle_1.checked){
			lifestyle_1val = document.calc.lifestyle_1.value;
		}else{
			lifestyle_1val = 0;
		}
		if (!document.calc.lifestyle_2.checked){
			lifestyle_2val = document.calc.lifestyle_2.value;
		}else{
			lifestyle_2val = 0;
		}
		if (!document.calc.lifestyle_3.checked){
			lifestyle_3val = document.calc.lifestyle_3.value;
		}else{
			lifestyle_3val = 0;
		}
		if (!document.calc.lifestyle_4.checked){
			lifestyle_4val = document.calc.lifestyle_4.value;
		}else{
			lifestyle_4val = 0;
		}
		// sum and calculations for lifestyle
		total_life = roundNumber((Math.round((blifetypeval*250)+(lifestyle_1val*1 + lifestyle_2val*1 + lifestyle_3val*1 + lifestyle_4val*1))/1000),2);
		// house total 
		document.getElementById('total_life').innerHTML =  total_life;
		total_sum_calc();
	}
	function setQuantity(pcID, pnOperation, pnMin, pnMax, pnInc, pnTotal, pnSum){
		var lnCurrentQuantity = parseInt(document.getElementById(pcID).value);							  
		var lnNewQuantity     = lnCurrentQuantity ; 
		switch(pnOperation)
		{				   
			case 1: // increase quantity by 1 
				lnNewQuantity = lnNewQuantity + pnInc	;
				if(lnNewQuantity > pnMax)
				{								
					lnNewQuantity = lnCurrentQuantity ;
				}
				break;
			case 2:// decrease quantity by 1
				lnNewQuantity = lnNewQuantity - pnInc ;
				if(lnNewQuantity < pnMin) 
				{
					lnNewQuantity = lnCurrentQuantity ;
				}
				break;
			default:// ensuring a typed quantity remains within the parameters defined
				if (lnCurrentQuantity > pnMax || lnCurrentQuantity < pnMin)
				{									 
					alert("Please set the quantity as a number between " + pnMin + " and " + pnMax + '\n' + "The quantity will now be set to " + pnMin) ;
					lnNewQuantity = pnMin ;
				}
				break;
		}
	
		document.getElementById(pcID).value = lnNewQuantity ;
		/*document.getElementById(pnTotal).innerHTML = lnNewQuantity ;
		document.getElementById(pnSum).innerHTML = document.getElementById(pnTotal).innerHTML * 232 ;
		document.getElementById('stripa').style.width = (lnNewQuantity*10)+"px"; */
		update_values_transp();
		update_values_food();
		update_values_house();
		update_values_life();
	}
	
	function sakums(){
		update_values_transp();
		update_values_food();
		update_values_house();
		update_values_life();
	}