function rewrite_categories2(formularz){

	formularz.category2.disabled = false;
	// skasowanie bieżących opcji i wpisanie nowych
	for(i=formularz.category2.options.length-1; i>=0; i--){
		formularz.category2.options[i] = null;
	}

	var opt = new Option('-- ' + emptycat2 + ' --', '0');
	formularz.category2.options[formularz.category2.options.length] = opt;

	for(i=0; i<document.subcategory1.length; i++){
		if(document.subcategory1.elements[i].name.substring(4,6) == formularz.category1.value.substring(4,6) && document.subcategory1.elements[i].name.substring(2,4)!='00'  && document.subcategory1.elements[i].name.substring(0,2)=='00'){
			var opt = new Option(document.subcategory1.elements[i].value, document.subcategory1.elements[i].name);
			formularz.category2.options[formularz.category2.options.length] = opt;
		}
	}
	
	if(formularz.category2.options.length==0){
		var opt = new Option('- - -', '-1');
		formularz.category2.options[formularz.category2.options.length] = opt;
		formularz.category2.disabled = true;
	} else {
		if(formularz.category1.selectedIndex > 0){
			formularz.category2.disabled = false;
			rewrite_categories3(formularz);
		}
	}

}

function rewrite_categories3(formularz){

	formularz.category3.disabled = false;
	// skasowanie bieżących opcji i wpisanie nowych
	for(i=formularz.category3.options.length-1; i>=0; i--){
		formularz.category3.options[i] = null;
	}

	var opt = new Option('-- ' + emptycat3 + ' --', '0');
	formularz.category3.options[formularz.category3.options.length] = opt;

	for(i=0; i<document.subcategory2.length; i++){
		if(document.subcategory2.elements[i].name.substring(4,6) == formularz.category1.value.substring(4,6)){
			if(document.subcategory2.elements[i].name.substring(2,4) == formularz.category2.value.substring(2,4) && document.subcategory2.elements[i].name.substring(0,2)!='00'){
				var opt = new Option(document.subcategory2.elements[i].value, document.subcategory2.elements[i].name);
				formularz.category3.options[formularz.category3.options.length] = opt;
			}
		}
	}
	
	if(formularz.category3.options.length==0){
		var opt = new Option('- - -', '-1');
		formularz.category3.options[formularz.category3.options.length] = opt;
		formularz.category3.disabled = true;
	} else {
		if(formularz.category1.selectedIndex > 0 && formularz.category2.selectedIndex > 0){
			formularz.category3.disabled = false;
		}
	}
}

function count_price(el){
	for(i=1; i<100; i++){
		if(i<10){
			discobj = eval('document.baseform.disc_0' + i);
		}else{
			discobj = eval('document.baseform.disc_' + i);
		}
		if(discobj){
			if(i<10){
				valobj = eval('document.baseform.val_' + el.name.substring(4,6) + '_0' + i)
			}else{
				valobj = eval('document.baseform.val_' + el.name.substring(4,6) + '_' + i)
			}
			if(valobj){
				valobj.value = el.value - (el.value * discobj.value / 100.0);
			}
		}
	}	
}

function sentered(urel, sizex, sizey){
 var posx = (screen.width / 2) - (sizex / 2);
 var posy = (screen.height / 2) - (sizey / 2);
 window.open(urel, 'okno', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + sizex + ',height=' + sizey + ',left=' + posx + ',top=' + posy);
 return false;
}

function sentered_named(urel, sizex, sizey, name){
 var posx = (screen.width / 2) - (sizex / 2);
 var posy = (screen.height / 2) - (sizey / 2);
 window.open(urel, name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + sizex + ',height=' + sizey + ',left=' + posx + ',top=' + posy);
 return false;
}

function sentered_noscroll(urel, sizex, sizey){
 var posx = (screen.width / 2) - (sizex / 2);
 var posy = (screen.height / 2) - (sizey / 2);
 window.open(urel, 'okno', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + sizex + ',height=' + sizey + ',left=' + posx + ',top=' + posy);
 return false;
}