function ClickSmlFltr(i){
  $('.pgs').children().toggleClass('sel');
  $('.c > [name = "filtr"]').toggle();
  return false;
}

function showbutton(btnid){
  var btn = document.getElementById(btnid);

  if( btn.style.visibility == 'hidden' )
     btn.style.visibility = 'visible';
  else
    btn.style.visibility = 'hidden';

  return false;
}

function incvoicecount(){
  var etotchuvakgolosoval = document.getElementById('etotchuvakgolosoval').value;

  if( etotchuvakgolosoval == 1 ){
    alert('Вы уже голосовали. Голос не засчитан');
    return(0);
  }

  var count = document.getElementById('countvoice').innerHTML;
  count++;
  document.getElementById('countvoice').innerHTML = count;
  document.getElementById('etotchuvakgolosoval').value = 1;

  return false;
}

function TrashHref(count){
  if ( count > 0 ){
  	location.href = 'tyres.html#trash';
  } else {
    alert( 'Корзина пуста' );
  }
  return false;
}

function RecalcTrash(){
    var res = 0;
    var i = 0;
    var priceid = '';
    var countid = '';
    var price;
    var count;

    while( document.getElementById('posprice_t'+i) && document.getElementById('poscount_t'+i) )	{
        priceid = 'posprice_t'+i;
        countid = 'poscount_t'+i;

	    price = document.getElementById(priceid).innerHTML;
	    count = document.getElementById(countid).value;
	    document.getElementById(countid).value = Math.round(count);
	    count = document.getElementById(countid).value;

	    res = res + ( price * count );
	    i++;
	}

	i = 0;

    while( document.getElementById('posprice_d'+i) && document.getElementById('poscount_d'+i) )
	{
        priceid = 'posprice_d'+i;
        countid = 'poscount_d'+i;

	    price = document.getElementById(priceid).innerHTML;
	    count = document.getElementById(countid).value;
	    document.getElementById(countid).value = Math.round(count);
	    count = document.getElementById(countid).value;

	    res = res + ( price * count );

	    i++;
	}

	i = 0;

    while( document.getElementById('posprice_k'+i) && document.getElementById('poscount_k'+i) )
	{
        priceid = 'posprice_k'+i;
        countid = 'poscount_k'+i;

	    price = document.getElementById(priceid).innerHTML;
	    count = document.getElementById(countid).value;
	    document.getElementById(countid).value = Math.round(count);
	    count = document.getElementById(countid).value;

	    res = res + ( price * count );

	    i++;
	}

    res = Math.round( res );
    document.getElementById('zakprice').value = res+'.00';

	return false;
}

function fastzakaz(){
    if(document.getElementById('idfi').value == ''){
	   alert('Пожалйста укажите Ваше Имя и фамилию');
	   return false;
	}else

    if(document.getElementById('idtel').value == ''){
	   alert('Пожалйста укажите телефон');
	   return false;
	}else submitform('anketaform');
    
}

// Новая проверка на заполненность полей заказа =================================================

/*   function text (str) { return /[0-9_;:!~?=+<|>]/g.test(str); }

   function numeric (str) { return /^[0-9-\+\(\)\s]+z/.test(str + "z"); }

   function checkForm ()
      {
      var title;
      var elem;
      var dutyField = "Не заполнено поле ";
      var wrongField = "Неверное значение поля ";
      var check = true;

      function checkError (field, str)
         {
         document.getElementById("alert").innerHTML = str;
         document.getElementById(field).focus();
         check = false;
         }

      document.getElementById("alert").innerHTML = "";

      if (check)
         {
         title = '"Фамилия, Имя"';
         elem = document.getElementById("idfi").value;
         if (elem.length == 0) checkError('idfi', dutyField + title);
         else if (text(elem)) checkError('idfi', wrongField + title);
         }

      if (check)
         {
         title = '"Телефон"';
         elem = document.getElementById("idtel").value;
         if (elem.length == 0) checkError('idtel', dutyField + title);
         else if (!numeric(elem)) checkError('idtel', wrongField + title);
         }       
         
      if (check){ document.getElementById("anketaform").submit(); }

      return check;
      } */

// ======================================================================================

function submitform(formid){
	var form=document.getElementById(formid);
	form.submit();
}

function bodyload(){

    if( !document.getElementById('anketapoint') ) return 0;
    var cb = document.getElementById('center_block');
	p_cb = getPosition(cb);
	var step2div = document.getElementById('step2div');
	var step3div = document.getElementById('step3div');
	var anketapoint = document.getElementById('anketapoint');
	p_a = getPosition(anketapoint);
	var h = p_a.y - p_cb.y - 820; //вот именно столько
	step2div.style.height = h + 'px';
	step3div.style.height = '323px';
}

function inctrashcount(url){
  if( !parent ) return 0;
  parent.location.pathname = url;
}

function DelConfirm( delurl ){
  confirmres = confirm("Удалить запись?");
  if ( confirmres ) location.href=delurl;
}

function showLoginForm() {
  var logDiv = document.getElementById('loginFrm');
  var enterA = document.getElementById('enter_a');
  if ( (!logDiv) || (!enterA) ) return false;

  if ( logDiv.style.display=='block' ) {
    logDiv.style.display='none';
    return false
  }

  p = getPosition( enterA );
  logDiv.style.left = p.x + 'px';
  logDiv.style.top = p.y + 20 + 'px';
  logDiv.style.display='block';
  return false
}

function getPosition(el)	{
	var p = { x: el.offsetLeft, y: el.offsetTop };
	while (el.offsetParent)	{
		el = el.offsetParent;
		p.x += el.offsetLeft;
		p.y += el.offsetTop;
		if (el != document.body && el != document.documentElement) {
			p.x -= el.scrollLeft;
			p.y -= el.scrollTop;
		}
	}
	return p;
}

function MoveMenuClick() {

  if ( ( parseInt( document.getElementById('MoveMenuR').style.height ) < 178 ) || ( !document.getElementById('MoveMenuR').style.height ) ) {
    document.getElementById('MoveMenuR').style.height = '178px';
  } else {
    document.getElementById('MoveMenuR').style.height = '0px';
  }

}

function cityBtnClick(sender, event) {
  var CL = document.getElementById('cityList');
  if ( sender == 0 ) {
    CL.style.display = 'none';
  }
  else {
    $('#cityList').slideToggle("fast");
    event.stopPropagation ? event.stopPropagation() : event.cancelBubble=true;
  }
  return false;
}

function SetOprosPoint(id){
  var oldset_pointid = document.getElementById('setpointid').value;
  if ( oldset_pointid != "" ){
	document.getElementById('oprospointimg' + oldset_pointid).src = '/img/point0.gif'
  }

  var elementid = 'oprospointimg' + id;
  document.getElementById(elementid).src = '/img/point1.gif'
  document.getElementById('setpointid').value = id;
}

function AddOtvetVar(){
  var count = document.getElementById('idvoproscount').value;
  var res = '';
  for( i=1; i<= count; i++){
    val = document.getElementById('idotvet' + i).value;
	res += '<font color="silver">'+i+'.</font> <input id="idotvet'+i+'" type="text" name="otvet[]" value="'+val+'"  class="edtotvinp"><br/>';
  }
  val='';
  res += '<font color="silver">'+i+'.</font> <input id="idotvet'+i+'" type="text" name="otvet[]" value="'+val+'"  class="edtotvinp"><br/>';
  count++;
  document.getElementById('idvoproscount').value = count;
  document.getElementById('otvetlist').innerHTML = res;

}

