var curval = 0;
var inputs = 'price';
var maxprice = 0;
var doit = 0;
var mywidth = ''

function ChVal(etot)
{

  curval = etot.value; //document.getElementById("valuta").value;
//  document.getElementById("valuta").style.background='#ffaaaa'
  doit=1;
  PricesLoad(mywidth);
}


//-----------------------загрузка формочек ДАТА  ----------------
function PricesLoad( width)
{
  if (mywidth=='')mywidth=width;
  data = inputs; 
 // $("#test1").hide();
  datas = data.split(',');
  for (x in datas)
  {
    i = '';

    while(document.getElementById(datas[x]+i))
    {
      //document.getElementById(datas[x]+i).style.display='none';
      ids = "#"+datas[x]+i;
      idss = datas[x]+i;  
     // vals = document.getElementById(idss).value;
     vals = $(ids).val();

//alert(document.getElementById(idss).value);
      ddd = vals.split(',');

      //       mybtn = '<input type="text" value="" id="label'+datas[x]+i+'" readonly><input type="image" src="images/calendar.gif"  value=" ... " onclick="return showCalendar(\''+datas[x]+i+'\', \''+dateformat+'\', \'24\', true);">';
//alert(idss+','+ddd[1]);
     //alert(idss+' '+vals);
    $.get("cars_srv.php?car="+ddd[0]+"&price="+ddd[1]+"&ids="+idss+"&val="+curval+"&i="+i, function(cpr){
    // document.getElementById("domontazh").innerHTML=datas;;
    dt = cpr.split(',');

             //   alert(cpr);
      //       GoToDoc("index.php?page=documents&id="+datas);

      //if (browser=='mozilla')title='Для поиска наберите текст'; else title ='';
      //datas = '<input type="text" name="'+datas[x]+i+'fnd" id="'+datas[x]+i+'fnd"  value=\'\' onKeyDown=\'FindIt(this,"'+idss+'","")\' title="'+title+'">';
      //$(ids).after(datas);

  
      if (document.getElementById(dt[1]))
      {
      $("#label_"+dt[1]).remove();  
      }
        if ((dt[2]==(maxprice-1)) )document.getElementById("valuta").style.background='#ffffff';

     // mybtn = '<input type="text" value="'+dt[0]+'" id="label_'+dt[1]+'" name="price" class="cars" style="">';
        mybtn = '<span id="label_'+dt[1]+'" >'+dt[0]+'</span>';


      $("#"+dt[1]).after(mybtn);
      //---------------------------------
      //document.getElementById("label"+datas[x]+i).value=timetmp;
             }
            );

      if ((i=='')&&(i!='0'))i=-1;
      i++;
    }
   maxprice=i;
  }
}
