
function SetBigger(curval,targ_obj)
{
	//alert(curval);
	var
	 $adds=0;
	if  (tyreform._realsize.checked) { $adds=1;};
	if (targ_obj.selectedIndex<curval) { targ_obj.selectedIndex=curval+$adds;};

};

function chfp()
{
var	ut=1;

	if (tyreform._munit[1].checked) {ut=2;};

	if (ut==2)
	{		convert_size('cm');
		document.all["cm_real"].style.display = "inline";
		document.all["inch_real"].style.display = "none";
	}
	else
	{		convert_size('inch');
		document.all["inch_real"].style.display = "inline";
		document.all["cm_real"].style.display = "none";
	};
};



function indexOf_select(obj,val2)
{	tmp=0;
	min_diff=3;
	gindex=-1;

	for (i = 0;i < obj.options.length;i++)
	{

        tmp=Math.round(Math.abs(obj.options[i].value-val2));

		if (tmp<min_diff)
		{
			min_diff=tmp;
			gindex=obj.options[i].index;

		};

	};
	return gindex;}


function  convert_size(direction)
{
	var    	curr_form=tyreform;
			inch=25.4;
			diametr=curr_form.diametr.value/1;
	if (direction=='inch')
	{
//	alert("AAA");
// From cm to inches
  		if (curr_form.cm_width1.selectedIndex>0)
		{
//	Setting the width
			inch_ind=indexOf_select(curr_form.width1,curr_form.cm_width1.value/inch);
			if (inch_ind >-1) { curr_form.width1.selectedIndex=inch_ind; }
			else
			{
			};

//	Setting the heigth
		    if ((curr_form.cm_heigth1.selectedIndex>0) && (diametr>0))
			{
//                alert ("diametrX"+diametr);
				inch_sz=(2*curr_form.cm_width1.value*(curr_form.cm_heigth1.value/100))/inch+diametr;
				inch_ind=indexOf_select(curr_form.heigth1,inch_sz);
//                alert("size="+inch_sz);
				if (inch_ind >-1) { curr_form.heigth1.selectedIndex=inch_ind; }
				else {	};

			}
			else { };

		};



		if (curr_form.cm_width2.selectedIndex>0)
		{
			inch_ind=indexOf_select(curr_form.width2,curr_form.cm_width2.value/inch);
			if (inch_ind >-1) { curr_form.width2.selectedIndex=inch_ind; }
			else {		};

		    if ((curr_form.cm_heigth2.selectedIndex>0) && (diametr>0))
			{
				inch_sz=(2*curr_form.cm_width2.value*(curr_form.cm_heigth2.value/100))/inch+diametr;
				inch_ind=indexOf_select(curr_form.heigth2,inch_sz);
				if (inch_ind >-1) { curr_form.heigth2.selectedIndex=inch_ind; }
				else {		};
			}
			else {};
		};
	}
	else
	{// form inches to cm
	//alert("TTT");
		if (curr_form.width1.selectedIndex>0)
		{
//	Setting the width
        	cm_ind=indexOf_select(curr_form.cm_width1,curr_form.width1.value*inch);
			if (cm_ind >-1) { curr_form.cm_width1.selectedIndex=cm_ind; }
			else {	};

			//	Setting the heigth
			 //alert ("diametrA"+diametr);
		    if ((curr_form.heigth1.selectedIndex>0) && (diametr>0))
			{				sm_sz=100*(((curr_form.heigth1.value-diametr)/2)/curr_form.width1.value);
				//alert ("CMS"+sm_sz);
				cm_ind=indexOf_select(curr_form.cm_heigth1,sm_sz);
				if (cm_ind >-1) { curr_form.cm_heigth1.selectedIndex=cm_ind; }
				else { 	 };

			};
		};

		if (curr_form.width2.selectedIndex>0)
		{
//	Setting the width2
        	cm_ind=indexOf_select(curr_form.cm_width2,curr_form.width2.value*inch);
			if (cm_ind >-1) { curr_form.cm_width2.selectedIndex=cm_ind; }
			else {	};

			//	Setting the heigth
		    if ((curr_form.heigth2.selectedIndex>0) && (diametr>0))
			{
				sm_sz=100*(((curr_form.heigth2.value-diametr)/2)/curr_form.width2.value);
				cm_ind=indexOf_select(curr_form.cm_heigth2,sm_sz);
				if (cm_ind >-1) { curr_form.cm_heigth2.selectedIndex=cm_ind; }
				else { 	 };
			};
		};

	};
};


