function filter(type, wh) {
	var filter = '';

	if (wh)	var form = $('filter_form2');
	else var form = $('filter_form');
	switch (type) {
		case 'tyres':
			var fields = ['att_t_zavod', 'att_t_type', 'att_t_size1', 'att_t_size2', 'att_t_size3'];
			var link = '/tyres.html';
			break;
		case 'wheels':
			var fields = ['att_d_zavod', 'att_d_otv', 'att_d_size1', 'att_d_size2', 'att_d_size3'];
			var link = '/wheels.html';
			break;
		default:
			return;
	}

	fields.each(function(item){
		filter += form.elements[item].value+';';
	});
	filter = filter.substr(0, filter.length-1);

	if (filter != ';;;;')
		location.href = link+'?f='+filter+"#results";
}

function t_calc(form)
{
      var form = $('calc_form');
      $('Tw').innerHTML = form.Wd.options[form.Wd.selectedIndex].value;
      $('Tw1').innerHTML = form.Wdn.options[form.Wdn.selectedIndex].value;
      $('Tw2').innerHTML = form.Wdn.options[form.Wdn.selectedIndex].value-form.Wd.options[form.Wd.selectedIndex].value;

      $('Tr').innerHTML = Math.round(form.Rd.options[form.Rd.selectedIndex].value*25.4);
      $('Tr1').innerHTML = Math.round(form.Rdn.options[form.Rdn.selectedIndex].value*25.4);
      $('Tr2').innerHTML = Math.round(form.Rdn.options[form.Rdn.selectedIndex].value*25.4)-Math.round(form.Rd.options[form.Rd.selectedIndex].value*25.4);

      $('Th').innerHTML = Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4);
      $('Th1').innerHTML = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4);
      $('Th2').innerHTML = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4);

      $('Kl').innerHTML = (Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4))/2;

      $('Sp1').innerHTML = Math.round((Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
      +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
      /Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
      +form.Rd.options[form.Rd.selectedIndex].value*25.4))*$('Sp').innerHTML*100)/100;

      $('Sp2').innerHTML = Math.round(($('Sp1').innerHTML-$('Sp').innerHTML)*100)/100
}

function MM_swapImgRestore() {
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	function MM_preloadImages() {
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	function MM_findObj(n, d) {
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	function MM_swapImage() {
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	emptyFrame="";
	function calc() {
	var currentOffset="";
	var currentWidth,newWidth,newOffset,currentInsideWidth,newInsideWidth,currentOutsideWidth,newOutsideWidth;
		with (document.wheeloffsetcalc) {

			currentWidth=CWW.value*25.4;
			newWidth=NWW.value*25.4;

			currentOffset=CWO.value;
			newOffset=NWO.value;
		}

		currentInsideWidth =(currentWidth/2) + parseInt(currentOffset);
		currentOutsideWidth=(currentWidth/2) - parseInt(currentOffset);

		newInsideWidth =(newWidth/2) + parseInt(newOffset);
		newOutsideWidth=(newWidth/2) - parseInt(newOffset);
		distance= (currentInsideWidth-newInsideWidth);

		if (Math.round(distance)<0) {
			out = Math.round(Math.abs(distance)) + "мм. Увеличивается";
		}
		else if (Math.round(distance)>0) {
			out = Math.round(Math.abs(distance)) + "мм. Уменьшается";
		}
		else {
			out ="Отсутствует";
		}

		if (Math.round(newOutsideWidth-currentOutsideWidth)>0) {
			out2 = "Увеличивается на ";
			out2 +=Math.round(Math.abs(newOutsideWidth-currentOutsideWidth));
			out2 +="мм.";
		}
		else if (Math.round(newOutsideWidth-currentOutsideWidth)<0) {
			out2 = "Уменьшается на ";
			out2 +=Math.round(Math.abs(newOutsideWidth-currentOutsideWidth));
			out2 +="мм.";
		}
		else {
			out2 = "Отсутствует";
		}

		with (document) {
			document.wheeloffsetcalc.strut.value = out;
			document.wheeloffsetcalc.wheeloutside.value = out2;
		}

	}

	function COL() {
		with (document.wheeloffsetcalc) {
			CWO.value=CWO.value-1;
		}
		calc();
	}

	function COR() {

		with (document.wheeloffsetcalc) {
			CWO.value=parseInt(CWO.value)+1;
		}
		calc();
	}


	function NOL() {
		with (document.wheeloffsetcalc) {
			NWO.value=NWO.value-1;
		}
		calc();
	}

	function NOR() {

		with (document.wheeloffsetcalc) {
			NWO.value=parseInt(NWO.value)+1;
		}
		calc();
	}
	
function addToCart(form, link) {
	if (form.products_qty.value > 0)
		doAddProduct(form);
	//form.products_qty.value = 0;
}
