function totalPrice(){
	
	var total=0;
	for (i=1 ; document.getElementById('atrb'+i) ; i++){
	
		if (document.getElementById('atrb'+i).checked || document.getElementById('atrb'+i).type=='hidden'){
			total=total+parseFloat(document.getElementById('atrb'+i).value);
			
		}
	
	
	}


	document.getElementById('total').innerHTML=number_format(total,2, ' ', ',')+' zł';
	brutto=total*123;
	//document.getElementById('brutto').innerHTML=number_format(brutto,2, ' ', ',')+'/zł brutto ';
		document.getElementById('brutto').innerHTML=Math.round(brutto,2)/100+'/zł brutto ';


}


function checkboxPrice(ID){
	total=0;
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('input');
	for (i=0; i<allHTMLTags.length; i++) {
		
		if (allHTMLTags[i].className=='atrb'+ID) {
		
		
			if (allHTMLTags[i].checked){
			
				total=total+parseFloat(allHTMLTags[i].value);
			
			}
		
		}
		
	}
	
	document.getElementById('attributePrice'+ID).innerHTML=total+' zł/<span>netto</span>';


}

function wymiary(ID){
	
	width=document.getElementById('width').value;
	height=document.getElementById('height').value;
	
	if (width=='szerokość'){
		width=0;
		
	}
		
	else
		width=parseFloat(width);
		
	if (height=='wysokość')	
		height=0;
	else
		height=parseFloat(height);
		
	
	pole=width*height/10000;
	if (pole<1)
		pole=1;
	

	
		
		
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('input');
	
	for (i=0; i<allHTMLTags.length; i++) 
		if (allHTMLTags[i].className=='choice')
			if (allHTMLTags[i].checked){
				nazwa=allHTMLTags[i].value;
				
			}
		 
		
	
	
	
		
	if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
		
	
	xmlhttp.open("GET","func/wymiary.php?pole="+pole+"&format="+nazwa,false);
	xmlhttp.send();
	price=xmlhttp.responseText;
	document.getElementById('atrb'+ID).value=price;
	totalPrice();	
	
		
		
		
	
	
	
	
	
	
	
}	
	
	
function number_format(number, decimals, dec_point, t_sep)
{
   var intstr;
   var output = '';
   
   if(typeof(decimals) == 'undefined')
      decimals = 2;
      
   if(typeof(dec_point) == 'undefined')
      dec_point = '';
      
   if(typeof(t_sep) == 'undefined')
      t_sep = '';
   
   // czesc calkowita   
   int = parseInt(number);
   
   // czesc ulamkowa
   float = parseInt((parseFloat(number)-int)*Math.pow(10, decimals));
   
   intstr = int+'';
   
   j = intstr.length;
   
   if((i = j%3) != 0)
      output += intstr.substring(0, i);
   
   while(i < j)
   {
      output += dec_point+''+intstr.substring(i, i+3);
      i += 3;
   }
   
   if(float > 0)
      output += t_sep+''+float;
   
   return(output);
}	
	

/*function ulotki(OB,I){
	
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('div');
	
	for (i=0; i<allHTMLTags.length; i++){ 
		if (allHTMLTags[i].className=='ulotkiRozwijane'+I){
			allHTMLTags[i].style.display='none';
			
			
		}
	}
	
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('input');
	
	for (i=0; i<allHTMLTags.length; i++) {
		
		if (allHTMLTags[i].className=='ulotkiNaklad'+I){
			
			if (allHTMLTags[i].name==OB){
				allHTMLTags[i].disabled=0;
				
			}
				
			else	{
				allHTMLTags[i].disabled=1;
				
			}
		}	
	}	

			
			
	if (document.getElementById(OB).style.display=='none')
		document.getElementById(OB).style.display='block';
	else
		document.getElementById(OB).style.display='none';
	
	
	totalPrice();
	
}*/


function ulotkiCalc(ID,ID2,ID3){
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('input');
	
	for (i=0; i<allHTMLTags.length; i++){ 
		if (allHTMLTags[i].className=='ulotkiHidden'){
			allHTMLTags[i].value=0;
			
			
		}
	}
	
	var allHTMLTags = new Array();
	var allHTMLTags=document.getElementsByTagName('div');
	
	for (i=0; i<allHTMLTags.length; i++){ 
		if (allHTMLTags[i].className=='ulotkiCont'){
			allHTMLTags[i].style.display='none';
			
			
		}
	}
	
	document.getElementById('ulotki'+ID).checked=true;
	str=document.getElementById('ulotki'+ID).value.split('~');
	document.getElementById('atrb'+ID3).value=str[1];
	if (document.getElementById('ulotkiCont'+ID2))
		document.getElementById('ulotkiCont'+ID2).style.display='block';
	totalPrice();
}
