function TrimString(sInString)
{
  sInString = sInString.replace(/ /g,' ');
  return sInString.replace(/(^\s+)|(\s+$)/g, "");
}

function getHexRGBColor(color)
{
  color = color.replace(/\s/g,"");
  var aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
  if(aRGB)
  {
    color = '';
    for (var i=1;  i<=3; i++)
      color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
  }
  else
    color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
  return color;
}

// функция заполнения выпадающего списка
function AddSelect(oSel,response,sel) {
	response=TrimString(response);
	ClearSelect(oSel,0);
	var a = response.split('$');
	for (var i = 0, l = a.length; i < l; i++) {
		var node = document.createElement ('option');
		var b=TrimString(a[i]);
		node.value = b;
		node.appendChild (document.createTextNode(b));
		oSel.appendChild (node);
		if (sel==b)
			oSel.selectedIndex=i;
	}
}

function BookmarkActive(name)
{
  var i=0;
  var res;
  while (document.getElementById(name+i))
  {
    var color=getHexRGBColor(document.getElementById(name+i).style.borderRightColor);
    if (color=="d1dfe0" || color=="#d1dfe0")
    {
      res=i;
      break;
    }
    i++;
  }
  return res;
}

function ChangeDescr(ind)
{
  if (ind==1)
  {
    document.getElementById("desc").style.borderBottomColor='#FFFFFF';
    document.getElementById("otz").style.borderBottomColor='#B0BCC2';
    document.getElementById("cont-o").style.display='none';
    document.getElementById("cont-de").style.display='block';
  }
  if (ind==2)
  {
    document.getElementById("desc").style.borderBottomColor='#B0BCC2';
    document.getElementById("otz").style.borderBottomColor='#FFFFFF';
    document.getElementById("cont-de").style.display='none';
    document.getElementById("cont-o").style.display='block';
  }
}
/*function trim(string)
{
  return string.replace(/(^\s+)|(\s+$)/g, "");
}   */

//var timerID //Таймер
//var closeTimeout = 500 // задержка на закрытие подменю
//function closeMenu(){
 //  clearTimeout(timerID);
 //  timerID = setTimeout('cl()', closeTimeout)
//}
//function cl()
//{ for(var i=1; i<=2; i++)//2 – число подпунктов
//     {eval('sub'+i+'.style.visibility="hidden"')     }
//}

//function show(num)
//{
//clearTimeout(timerID);
//cl();
// eval('sub'+num+'.style.visibility="visible"');
//}
//function view(url,w,h){ bag = window.open(url,'view','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,width='+ w+ ',height='+h+',resizable=yes'); bag.focus();}
//function view(url,w,h){ bag = window.open(url,'view','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,width='+ w+ ',height='+h+',resizable=yes'); bag.focus();}
function replace_string(txt,cut_str,paste_str){
  var f=0;
  var ht='';
  ht = ht + txt;
  f=ht.indexOf(cut_str);
while (f!=-1){
//цикл для вырезания всех имеющихся подстрок
f=ht.indexOf(cut_str);
if (f>0){
ht = ht.substr(0,f) + paste_str + ht.substr(f+cut_str.length);
};
};
return ht
};


function order(){
	document.getElementById('namepageh1').innerHTML = 'Оформление заказа';
	document.getElementById('fieldset').style.display = '';
	document.getElementById('issue').style.display = 'none';
	return false;
}

function GoPage(pg)
{
  document.getElementById("pg").value=pg;
  document.form2.submit();
}

function Post_resp()
{
  document.f_filt.submit();
  return false;
}

function SeasChng(pg)
{
  document.getElementById("seas").value=pg;
  document.form1.submit();
}

function ParChng(pg,gp,step)
{
  document.getElementById("prof").value=pg;
  document.getElementById("diam").value=gp;
  document.getElementById("step").value=step;
  document.form1.onsubmit();
}

function check_order(){
  var fio=TrimString(document.getElementById("f").value);
  if (fio=="")
  {
    alert('Не указано "контактное лицо".');
    return false;
  }
  var tel=TrimString(document.getElementById("t").value);
  if (tel=="")
  {
    alert('Не указан "телефон".');
    return false;
  }
  var tel=document.ord.commer.value;
  if (tel==61)
  {
    alert('Не указан "источник рекламы".');
    return false;
  }
  var pay=document.getElementById("pay").value;
  if (pay==2)
  {
    var wm=TrimString(document.getElementById("wm").value);
    if (wm=="")
    {
      alert('Не указан "WM-ID".');
      return false;
    }
  }
  return true;
}

function check_demand(tp)
{
  var element=document.getElementById("fio").value;
  if (element=="")
  {
    alert('Не указано "Имя".');
    return false;
  }
  if (tp!=4)
  {
    element=document.getElementById("telef").value;
    if (element=='')
    {
      alert('Не указан "телефон".');
      return false;
    }
  }
  if (tp==1 || tp==4)
  {
    element=document.getElementById("info").value;
    if (element=='')
    {
      if (tp==1)
        alert('Не указана "информация".');
      if (tp==4)
        alert('Не написан "отзыв".');
      return false;
    }
  }
  if (tp==2)
  {
    element=document.getElementById("tab10_idz").value;
    if (element==0)
    {
      alert('Не указан "тип диска".');
      return false;
    }
    element=document.getElementById("tab6_idz").value;
    if (element==0)
    {
      alert('Не указан "диаметр обода".');
      return false;
    }
    element=document.getElementById("tab7_idz").value;
    if (element==0)
    {
      alert('Не указано "кол-во болтов (гаек)".');
      return false;
    }
    element=document.getElementById("coun").value;
    if (element=='')
    {
      alert('Не указано "Импортные/отечественные".');
      return false;
    }
    element=document.getElementById("frm").value;
    if (element=='')
    {
      alert('Не указано "производитель авто".');
      return false;
    }
    element=document.getElementById("mod").value;
    if (element=='')
    {
      alert('Не указано "Модель авто".');
      return false;
    }
    element=document.getElementById("year").value;
    if (element=='')
    {
      alert('Не указано "год выпуска авто".');
      return false;
    }
    element=document.getElementById("volum").value;
    if (element=='')
    {
      alert('Не указано "Объем двигателя".');
      return false;
    }
  }
  if (tp==3)
  {
    element=document.getElementById("a_firm").value;
    if (element=='')
    {
      alert('Не указан "Производитель".');
      return false;
    }
    element=document.getElementById("a_mod").value;
    if (element=='')
    {
      alert('Не указана "Модель".');
      return false;
    }
    element=document.getElementById("a_info").value;
    if (element=='')
    {
      alert('Не указан "Год выпуска и др. информация".');
      return false;
    }
    document.form2.onsubmit();
    return false;
  }
  return true;
}

function check_podbor(tp){
  if (tp==1)
  {
    var seas=document.getElementById("seas").value;
    var prof=document.getElementById("prof").value;
    var diam=document.getElementById("diam").value;
    if (seas==0 && prof==0 && diam==0)
    {
      alert('Необходимо выбрать хотя бы один параметр шины.');
      return false;
    }
    else
      GoPage(1);
  }
  if (tp==2)
  {
    var tab10_id=document.getElementById("tab10_id").value;
    var tab5_id=document.getElementById("tab5_id").value;
    var tab6_id=document.getElementById("tab6_id").value;
    var tab7_id=document.getElementById("tab7_id").value;
    var tab8_id=document.getElementById("tab8_id").value;
    var from=document.getElementById("from").value;
    var till=document.getElementById("till").value;
    var tab9_id=document.getElementById("tab9_id").value;
    var reg=/\d\d\d/;
    if (tab10_id==0 && tab5_id==0 && tab6_id==0  && tab7_id==0
         && tab8_id==0 && tab9_id==0 && (till=="" || reg.test(till)) && from=="")
    {
      alert('Необходимо выбрать хотя бы один параметр диска.');
      return false;
    }
    else
      GoPage(1);
  }
  return true;
}

function getElementsByNameIE(tag, name) {
  var elem = document.getElementsByTagName(tag);
  var arr = new Array();
  for(i = 0,iarr = 0; i < elem.length; i++) {
    att = elem[i].getAttribute(name);
    if(att == name) {
      arr[iarr] = elem[i];
      iarr++;
          }
     }
     return arr;
}
function td__(fl) {
        link_in_culc_ajax();
        var b1=document.getElementById('old_diam').value*25.4;
        var b2=document.getElementById('new_diam').value*25.4;
        if (document.getElementById("amer_old").checked)
        {
          var wd_old=replace_string(document.getElementById('old_height').value,",",".")*25.4;
          var a1=(replace_string(document.getElementById('old_width').value,",",".")*25.4-b1)/2;
        }
        else
        {
          var wd_old=document.getElementById('old_width').value;
          var a1=(document.getElementById('old_width').value*
            document.getElementById('old_height').value)/100;
        }
        if (document.getElementById("amer_new").checked)
        {
          var wd_new=replace_string(document.getElementById('new_height').value,",",".")*25.4;
          var a2=(replace_string(document.getElementById('new_width').value,",",".")*25.4-b2)/2;
        }
        else
        {
          var wd_new=document.getElementById('new_width').value;
          var a2=(document.getElementById('new_width').value*
            document.getElementById('new_height').value)/100;
        }
        var tbl=document.getElementById('res');
        var row=tbl.rows[1];
        row.cells[1].innerHTML=Math.round(wd_old*10)/10;
        row.cells[2].innerHTML=Math.round(wd_new*10)/10;
        var res=Math.round((wd_new-wd_old)*10)/10;
        if (res>0)
          row.cells[3].innerHTML="+"+res;
        else
          row.cells[3].innerHTML=res;
        row=tbl.rows[2];
        row.cells[1].innerHTML=Math.round(a1*10)/10;
        row.cells[2].innerHTML=Math.round(a2*10)/10;
        res=Math.round((a2-a1)*10)/10;
        if (res>0)
          row.cells[3].innerHTML="+"+res;
        else
          row.cells[3].innerHTML=res;
        row=tbl.rows[3];
        row.cells[1].innerHTML=Math.round(b1*10)/10;
        row.cells[2].innerHTML=Math.round(b2*10)/10;
        res=Math.round((b2-b1)*10)/10;
        if (res>0)
          row.cells[3].innerHTML="+"+res;
        else
          row.cells[3].innerHTML=res;
        row=tbl.rows[4];
        var c1=a1*2+b1;
        var c2=a2*2+b2;
        row.cells[1].innerHTML=Math.round(c1*10)/10;
        row.cells[2].innerHTML=Math.round(c2*10)/10;
        res=Math.round((c2-c1)*10)/10;
        if (res>0)
          row.cells[3].innerHTML="+"+res;
        else
          row.cells[3].innerHTML=res;
        row=tbl.rows[6];
        var spd=document.getElementById('speed').value*(a2*2+b2)/(a1*2+b1);
        row.cells[1].innerHTML=Math.round(spd*10)/10;
        spd=spd-document.getElementById('speed').value;
        res=Math.round(spd*10)/10;
        if (res>0)
          row.cells[2].innerHTML="+"+res;
        else
          row.cells[2].innerHTML=res;
        row=tbl.rows[7];
        res=Math.round((((a2*2+b2)-(a1*2+b1))/2)*10)/10;
        if (res>0)
          row.cells[1].innerHTML="+"+res;
        else
          row.cells[1].innerHTML=res;
        var img=document.getElementById('imgf');
        var src="tyre_f.php?r_sm_old="+b1+"&r_sm_new="+b2+"&r_bg_old="+c1+"&r_bg_new="+c2;
        img.innerHTML="<img src=\""+src+"\" />";
        img=document.getElementById('imgp');
        src="tyre_p.php?s_old="+wd_old+"&s_new="+wd_new+"&r_bg_old="+c1+"&r_bg_new="+c2;
        img.innerHTML="<img src=\""+src+"\" />";
}



// функция отправки письма с запросом о добавлении авто
function demand_ajax()
{
  var oForm=document.form2;
  var sBody=getRequestBody(oForm);
  var oXmlHttp=zXmlHttp.createRequest();
  oXmlHttp.open("post",oForm.action,true);
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function () {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        var s=oXmlHttp.responseText;
        alert(s);
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send(sBody);
  return false;
}

function getRequestBody(oForm) // функция создает строку параметров для передачи post
{
  var aParams = new Array();
  for(var i=0;i<oForm.elements.length;i++)
  {
    var sParam=encodeURIComponent(oForm.elements[i].name);
    sParam+="=";
    sParam+=encodeURIComponent(oForm.elements[i].value);
    aParams.push(sParam);
  }
  return aParams.join("&");
}

function rel_vil(fl)
{
  if (fl==1)
  {
    document.getElementById("from").disabled="disabled";
    document.getElementById("till").disabled="disabled";
    document.getElementById("from").value="";
    document.getElementById("till").value="";
    document.getElementById("tab9_id").disabled="";
  }
  else
  {
    document.getElementById("tab9_id").disabled="disabled";
    document.getElementById("from").disabled="";
    document.getElementById("till").disabled="";
    document.getElementById("tab9_id").value=0;
  }
}

function SeasChngPod(pg,step)
{
  document.getElementById("seas").value=pg;
  document.getElementById("step").value=step;
  document.form1.onsubmit();
}
function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function layoutVis(fl)
{
  if (fl)
  {
    //var element = document.getElementById('myElement');
    var bounds = getBounds(document.getElementById('td_vil'));
    document.all['vl2'].style.left = bounds.left;
    document.all['vl2'].style.top = bounds.top;
    document.all['vl2'].style.width = bounds.width;
    document.all['vl2'].style.height = bounds.height;
    document.all['vl2'].style.visibility = 'visible';
  }
  else
    document.all['vl2'].style.visibility = 'hidden';
}

function dost()
{
  var km;
  km=document.getElementById("km").value;
  document.getElementById("mk2").value=km;
  if (km==0)
    document.getElementById("pr_dost").innerHTML="0";
  if (km>0 && km<=5)
  {
    document.getElementById("pr_dost").innerHTML="200.00";
    var i=document.getElementById("all_sm1").innerHTML;
    document.getElementById("all_sm").innerHTML=parseFloat(i)+200;
  }
  if (km>5)
  {
    var res;
    res=200;
    res+=(km-5)*30;
    document.getElementById("pr_dost").innerHTML=res;
    var i=document.getElementById("all_sm1").innerHTML;
    document.getElementById("all_sm").innerHTML=parseFloat(i)+res;
  }
  return false;
}

function dost2()
{
  var km;
  km=document.getElementById("km").value;
  if (km==0)
    document.getElementById("pr_dost").innerHTML="0 руб.";
  if (km>0 && km<=5)
    document.getElementById("pr_dost").innerHTML="200 руб.";
  if (km>5)
  {
    var res;
    res=200;
    res+=(km-5)*30;
    document.getElementById("pr_dost").innerHTML=res+" руб.";
  }
}

function focs(id)
{
  document.getElementById(id).select();
}

// функция подбора лучшего диска по размеру шины
function calculaterimsize ()
{
  culc2_ajax();
  if (document.getElementById("amer_tyre").checked)
  {
    var wid=document.getElementById("tyre_height").value*25.4;
    var heig=(document.getElementById("tyre_width").value-document.getElementById("tyre_diam").value)/2;
    heig=wid/100*heig;
  }
  else
  {
    var wid=document.getElementById("tyre_width").value;
    var heig=document.getElementById("tyre_height").value;
  }
	if(heig<50)
    var scalar=0.85;
  if(heig>=50)
    var scalar=0.7;
	var	rimwidth=(Math.round(((wid*scalar)*0.03937)*2))/2;
	var rimwidthupper=(rimwidth+1.5);
  var tbl1=document.getElementById('sec');
  tbl1.rows[2].cells[0].innerHTML="Параметры диска для шины выбранного размера: от "+rimwidth+" x "+document.getElementById("tyre_diam").value+
    "&nbsp;&nbsp;до&nbsp;&nbsp;"+rimwidthupper+" x "+document.getElementById("tyre_diam").value;
}

// функция изменения выпадающих списков в калькуляторе
function amev_ajax(rw,tp)
{
  var nmb;
  if (tp=="tyre")
    var tbl1=document.getElementById('sec');
  else
    var tbl1=document.getElementById('par');
  if (document.getElementById("amer_"+tp).checked)
  {
    nmb=2;
    tbl1.rows[rw].cells[2].innerHTML="x";
    if (tp=="tyre")
      tbl1.rows[2].cells[0].innerHTML="Параметры диска: 9 x 15&nbsp;&nbsp;до&nbsp;&nbsp;10.5 x 15";
  }
  else
  {
    nmb=1;
    tbl1.rows[rw].cells[2].innerHTML="/";
    if (tp=="tyre")
      tbl1.rows[2].cells[0].innerHTML="Параметры диска: 5.5 x 16&nbsp;&nbsp;до&nbsp;&nbsp;7 x 16";
  }
  var oXmlHttp=zXmlHttp.createRequest();
  oXmlHttp.open("post","tyre_culc_aj.php",true);
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function ()
  {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        var def;
        if (nmb==1)
          def="205";
        else
          def="31";
        AddSelect(document.getElementById(tp+'_width'),oXmlHttp.responseText,def);
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send("numb="+nmb+"&on=1");
  var oXmlHttp1=zXmlHttp.createRequest();
  oXmlHttp1.open("post","tyre_culc_aj.php",true);
  oXmlHttp1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp1.onreadystatechange = function ()
  {
    if (oXmlHttp1.readyState == 4)
    {
      if (oXmlHttp1.status==200)
      {
        var def;
        if (nmb==1)
          def="55";
        else
          def="10,5";
        AddSelect(document.getElementById(tp+'_height'),oXmlHttp1.responseText,def);
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp1.send("numb="+nmb+"&on=2");
  var oXmlHttp2=zXmlHttp.createRequest();
  oXmlHttp2.open("post","tyre_culc_aj.php",true);
  oXmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp2.onreadystatechange = function ()
  {
    if (oXmlHttp2.readyState == 4)
    {
      if (oXmlHttp2.status==200)
      {
        var def;
        if (nmb==1)
          def="16";
        else
          def="15";
        AddSelect(document.getElementById(tp+'_diam'),oXmlHttp2.responseText,def);
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp2.send("numb="+nmb+"&on=3");
}

// функция выводящяя ссылки на подбор по параметрам в калькулятор
function link_in_culc_ajax()
{
  var tbl1=document.getElementById('clc1');
  var oXmlHttp=zXmlHttp.createRequest();
  oXmlHttp.open("post","link_from_calc.php",true);
  if (document.getElementById("amer_old").checked)
    var a1=1;
  else
    var a1=0;
  if (document.getElementById("amer_new").checked)
    var a2=1;
  else
    var a2=0;
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function ()
  {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        tbl1.rows[3].cells[0].innerHTML=oXmlHttp.responseText;
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send("fn=1&w1="+document.getElementById('old_width').value+"&h1="+document.getElementById('old_height').value+
    "&d1="+document.getElementById('old_diam').value+"&a1="+a1+"&w2="+document.getElementById('new_width').value+
    "&h2="+document.getElementById('new_height').value+"&d2="+document.getElementById('new_diam').value+"&a2="+a2);
}

function culc2_ajax()
{
  if (document.getElementById("amer_old").checked)
    var a1=1;
  else
    var a1=0;
  var tbl1=document.getElementById('clc2');
  var oXmlHttp=zXmlHttp.createRequest();
  oXmlHttp.open("post","link_from_calc.php",true);
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function ()
  {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        tbl1.rows[2].cells[0].innerHTML=oXmlHttp.responseText;
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send("fn=2&w1="+document.getElementById('tyre_width').value+"&h1="+document.getElementById('tyre_height').value+
    "&d1="+document.getElementById('tyre_diam').value+"&a1="+a1);
}

function culc3_ajax(zak,id)
{
  var i=0;
  while (document.getElementById("left_zak_"+i))
  {
    if (i==zak)
      document.getElementById("left_zak_"+i).style.borderRightColor="#d1dfe0";
    else
      document.getElementById("left_zak_"+i).style.borderRightColor="#b0bcc2";
    i++;
  }
  var oXmlHttp=zXmlHttp.createRequest();
  oXmlHttp.open("post","link_from_calc.php",true);
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function ()
  {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        var str=oXmlHttp.responseText;
        var id1=str.substring(str.indexOf("<")+1,str.indexOf(">"));
        str=str.substring(str.indexOf(">")+1);
        var a = str.split('$');
        var len = a.length;
        var zaks=document.getElementById("top_zaks");
        for (var i = 0; i < len; i++)
        {
          var El=document.getElementById("top_zak_"+i);
          if (El)
            El.childNodes[0].innerHTML=a[i];
          else
          {
            var node = document.createElement('div');
            node.className="round-coners";
            node.id="top_zak_"+i;
            var nodeA=document.createElement('a');
            nodeA.href="#";
            nodeA.onclick = function() {culc3_sub(i); return false;}
            nodeA.innerHTML=a[i];
            node.appendChild(nodeA);
            nodeA=document.createElement('span');
            nodeA.className="top-right_";
            node.appendChild(nodeA);
            nodeA=document.createElement('span');
            nodeA.className="top-left_";
            node.appendChild(nodeA);
            zaks.appendChild(node);
          }
        }
        while (document.getElementById("top_zak_"+len))
        {
          zaks.removeChild(document.getElementById("top_zak_"+len));
          len++;
        }
        id1=id1*1;
        culc3_sub(id1);
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send("fn=4&id="+id);
}


function culc3_sub(zak)
{
  var usa=document.getElementById("left_zak_"+BookmarkActive("left_zak_")).childNodes[0].innerHTML;
  var euro=document.getElementById("top_zak_"+zak).childNodes[0].innerHTML;
  var i=0;
  while (document.getElementById("top_zak_"+i))
  {
    if (i==zak)
      document.getElementById("top_zak_"+i).style.borderBottomColor="#fbda97";
    else
      document.getElementById("top_zak_"+i).style.borderBottomColor="#b0bcc2";
    i++;
  }
  tbl=document.getElementById("cont");
  var euro_w=euro.substring(0,euro.indexOf("/"));
  var euro_h_prof=euro.substring(euro.indexOf("/")+1,euro.indexOf(" "));
  var euro_d=euro.substring(euro.indexOf("R")+1);
  var usa_h_all=usa.substring(0,usa.indexOf("x"));
  var usa_w=usa.substring(usa.indexOf("x")+1,usa.indexOf(" "));
  var usa_d=usa.substring(usa.indexOf("R")+1);
  var str="При замене американского размера шин <strong>"+usa+"</strong> на европейский <strong>"+euro+
    "</strong> произойдут следующие изменения:<ul><li>Ширина шины ";
  usa_w=replace_string(usa_w,",",".")*25.4;
  usa_w=Math.round(usa_w*10)/10;
  euro_w=euro_w*1;
  var delt_w=0;
  var h_delt_w=0;
  if (euro_w>usa_w)
  {
    delt_w=euro_w - usa_w;
    delt_w=Math.round(delt_w*10)/10;
    h_delt_w=Math.round((delt_w/2)*10)/10;
    str=str+"<strong>увеличится на "+delt_w+" мм</strong>, то есть расстояние от деталей подвески до внутреннего края шины <strong>увеличится на "+
      h_delt_w+"</strong> мм, а по отношению к внешней плоскости автомобиля выступ шины наружу также <strong>увеличится на "+h_delt_w+" мм</strong>.</li>";
  }
  if (euro_w<usa_w)
  {
    delt_w=usa_w-euro_w;
    delt_w=Math.round(delt_w*10)/10;
    h_delt_w=Math.round((delt_w/2)*10)/10;
    str=str+"<strong>уменьшится на "+delt_w+" мм</strong>, то есть расстояние от деталей подвески до внутреннего края шины <strong>уменьшится на "+
      h_delt_w+" мм</strong>, а по отношению к внешней плоскости автомобиля выступ шины наружу также <strong>уменьшится на "+h_delt_w+" мм</strong>.</li>";
  }
  if (euro_w==usa_w)
    str=str+"<strong>останется неизменной</strong>.</li>";

  usa_h_all=replace_string(usa_h_all,",",".")*25.4;
  euro_h_prof=Math.round(((euro_w*euro_h_prof)/100)*10)/10;
  var usa_h_prof=Math.round(((usa_h_all-(usa_d*25.4))/2)*10)/10;
  if (euro_h_prof>usa_h_prof)
  {
    delt_w=euro_h_prof-usa_h_prof;
    delt_w=Math.round(delt_w*10)/10;
    str=str+"<li>Высота профиля шины <strong>увеличится на "+delt_w+" мм</strong>.</li>";
  }
  if (euro_h_prof<usa_h_prof)
  {
    delt_w=usa_h_prof-euro_h_prof;
    delt_w=Math.round(delt_w*10)/10;
    str=str+"<li>Высота профиля шины <strong>уменьшится на "+delt_w+" мм</strong>.</li>";
  }
  if (euro_h_prof==usa_h_prof)
    str=str+"<li>Высота профиля шины <strong>останется неизменной</strong>.</li>";

  usa_d=Math.round((usa_d*25.4)*10)/10;
  euro_d=Math.round((euro_d*25.4)*10)/10;
  if (euro_d>usa_d)
  {
    delt_w=euro_d-usa_d;
    delt_w=Math.round(delt_w*10)/10;
    str=str+"<li>Внутренний диаметр шины <strong>увеличится на "+delt_w+" мм</strong>.</li>";
  }
  if (euro_d<usa_d)
  {
    delt_w=usa_d-euro_d;
    delt_w=Math.round(delt_w*10)/10;
    str=str+"<li>Внутренний диаметр шины <strong>уменьшится на "+delt_w+" мм</strong>.</li>";
  }
  if (euro_d==usa_d)
    str=str+"<li>Внутренний диаметр шины <strong>останется неизменным</strong>.</li>";

  euro_h_all=euro_h_prof*2+euro_d;
  if (euro_h_all>usa_h_all)
  {
    delt_w=euro_h_all-usa_h_all;
    delt_w=Math.round(delt_w*10)/10;
    h_delt_w=Math.round((delt_w/2)*10)/10;
    str=str+"<li>Внешний диаметр шины <strong>увеличится на "+delt_w+" мм</strong>. Расстояние от верхней точки колеса до арки автомобиля <strong>уменьшится на "+h_delt_w+
      " мм</strong>, а клиренс автомобиля будет <strong>выше на "+h_delt_w+" мм</strong>.</li>";
  }
  if (euro_h_all<usa_h_all)
  {
    delt_w=usa_h_all-euro_h_all;
    delt_w=Math.round(delt_w*10)/10;
    h_delt_w=Math.round((delt_w/2)*10)/10;
    str=str+"<li>Внешний диаметр шины <strong>уменьшится на "+delt_w+" мм</strong>. Расстояние от верхней точки колеса до арки автомобиля <strong>увеличится на "+h_delt_w+
      " мм</strong>, а клиренс автомобиля будет <strong>ниже на "+h_delt_w+" мм</strong>.</li>";
  }
  if (euro_h_all==usa_h_all)
    str=str+"<li>Внешний диаметр шины <strong>останется неизменным</strong> и клиренс <strong>не изменится</strong>.</li>";
  var spd=Math.round((100*euro_h_all/usa_h_all)*10)/10;
  str=str+"</ul>При этом, когда на спидометре будет <strong>скорость 100 км/ч</strong>, фактическая скорость Вашего автомобиля будет <strong>"+spd+" км/ч</strong>. ";
  tbl.rows[0].cells[0].innerHTML=str;
  var src="tyre_f.php?r_sm_old="+usa_d+"&r_sm_new="+euro_d+"&r_bg_old="+usa_h_all+"&r_bg_new="+euro_h_all;
  tbl.rows[0].cells[1].innerHTML="<img src=\""+src+"\" />";
  src="tyre_p.php?s_old="+usa_w+"&s_new="+euro_w+"&r_bg_old="+usa_h_all+"&r_bg_new="+euro_h_all;
  tbl.rows[0].cells[2].innerHTML="<img src=\""+src+"\" />";
  return true;
}

function payCh(oTmb)
{
  if (oTmb.value==2)
    document.ord.wm.disabled="";
  else
  {
    document.ord.wm.disabled="disabled";
    document.ord.wm.value="";
  }
  return true;
}

// #########################Подбор шин по авто##################################

function podbor_sub(step)
{
  document.form1.step.value=step;
  if (document.form1.step.value==4)
    document.form1.submit();
  else
    podbor_ajax1();
}

function podbor_ajax1()
{
  var oForm=document.form1;
  var sBody=getRequestBody(oForm);
  var oXmlHttp=zXmlHttp.createRequest();
  var url="/podbor_aj.php?"+sBody;
  oXmlHttp.open("get",url,true);
  oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  oXmlHttp.onreadystatechange = function ()
  {
    if (oXmlHttp.readyState == 4)
    {
      if (oXmlHttp.status==200)
      {
        var tbl=document.getElementById('podb');
        var st=document.getElementById('step').value;
        if (st<3)
        {
          ClearSelectPodb(document.form1.modif,1);
          if (st<2)
            ClearSelectPodb(document.form1.year,1);
        }
        if (st==1)
        {
          if (document.form1.firm.options[0].value==0)
            document.form1.firm.options[0]=null;
          if (document.form1.model.options.length>1)
            ClearSelectPodb(document.form1.model,1);
          AddSelectPodb(document.form1.model,oXmlHttp.responseText);
          document.form1.model.selectedIndex=0;
          document.form1.model.disabled="";
        }
        if (st==2)
        {
          if (document.form1.model.options[0].value==0)
            document.form1.model.options[0]=null;
          if (document.form1.year.options.length>1)
            ClearSelectPodb(document.form1.year,1);
          AddSelectPodb(document.form1.year,oXmlHttp.responseText);
          document.form1.year.selectedIndex=0;
          document.form1.year.disabled="";
        }
        if (st==3)
        {
          var tbl=document.getElementById('podb');
          if (document.form1.year.options[0].value==0)
            document.form1.year.options[0]=null;
          if (document.form1.modif.options.length>1)
            ClearSelectPodb(document.form1.modif,1);
          AddSelectPodb(document.form1.modif,oXmlHttp.responseText);
          document.form1.modif.selectedIndex=0;
          document.form1.modif.disabled="";
        }
      }
      else
        saveResult("Обнаружена ошибка "+oXmlHttp.statusText);
    }
  }
  oXmlHttp.send(sBody);
  return false;
}
// #############################################################################

// функция очистки выпадающего списка и первых n записей
function ClearSelect(oSel,n)
{
  while (oSel.options.length>n)
    oSel.options[oSel.options.length-1] = null;
}

// функция очистки выпадающего списка и первых n записей конкретно для подбора
function ClearSelectPodb(oSel,n)
{
  ClearSelect(oSel,n);
  if (oSel.options[0].value!=0)
  {
    oSel.options[0].value="0";
    oSel.options[0].text="---------";
  }
  oSel.selectedIndex=0;
  oSel.disabled="disabled";
}

// функция заполнения выпадающего списка
function AddSelectPodb(oSel,response)
{
  var a = response.split('$');
  for (var i = 0, l = a.length; i < l; i++)
  {
    var node = document.createElement ('option');
    node.value = a[i];
    node.appendChild (document.createTextNode(a[i]));
    oSel.appendChild (node);
  }
}


function ZakChangeNew(id) {
	var bObj=document.getElementById("ug");
	var item,i=0;
	while (item = bObj.childNodes[i]) {
		document.getElementById("d_"+i).style.display="none";
		i++;
	}
	document.getElementById("d_"+id).style.display="block";
	return false;
}
