var animate=0;

$(document).ready(
  function()
  {
    $('.open_map').click(function (e) {
	  e.preventDefault();
	  $('#basic-modal-content').modal();
	});
	
	$(".cart_table input").focusout(function(){
	  var id=$(this).attr("rel");
	  var col=$(this).val(); 
	  var cost=$("#cost"+id).html();
	  cost=cost.replace(/( )+/g,"");
	  
	  if(col!=parseInt(col)) col=1;
	  if(col<=0) col=1;
	  if(col>9999) col=9999;
	  
	  var su=cost*col;
    su=su+"";
    su=su.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
	  
	  $("#sum"+id).html(su);
	  $(this).val(col);
	  
	   $.post("/ajax/cart.php",{item:id,act:'col',col:col},function(data){
       if(data!=""){
           data=data.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
           $("#cart_sum").html(data);
	       RefreshCart();
	     }
	   });
	});
	
	var type=$(".livesearch").attr('rel');
	$(".livesearch").autocomplete("/ajax/qsearch.php",{
	  delay:1,
      minChars:1,
      matchSubset:false,
      autoFill:false,
      cacheLength:1,
      extraParams:{type:type}
	}).result(function(e,data,formatted){
      location.href=data[1];
	});
	  

  }
);

$(function(){
  $(".live_input").keypress(function(e){
    if (e.which == 13){
      document.getElementById('moreSearch').submit();
    }
  });

  if(document.getElementById('razd1')){
    mr1 = document.getElementById('razd1').offsetHeight;
    
    $(".hid").animate( { top:"37"}, 1, function(){animate=0;});
    $(".mt1_2").addClass("shw");
    $(".mt1_2").animate( { top:"-37"}, 1, function(){animate=0;});
    $(".main_block_sc").animate( { height: mr1}, 1); $(".main_block2").animate( { top:"0"}, 1500);
    }
});

function AddToCart(id){
  $.post("/ajax/cart.php",{item:id,act:'add'},function(data){
    if(data!=""){
      $(".cart_text").html(data);
      $('#cart_added').modal({containerCss:{height:200,width:350}});
    }
  })
}

function RefreshCart(){
  $.post("/ajax/cart.php",{act:'refresh'},function(data){
    if(data!=""){
      $(".cart_text").html(data);
    }
  })
}

function DelFromCart(id){
  $.post("/ajax/cart.php",{item:id,act:'del'},function(data){
    if(data!=""){
      data=data.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
      $("#cart_sum").html(data);
      $("#tr"+id).remove();
      
      var tr=$(".cart_table tr");
      if(tr.length<2){
        document.location="/user/cart/";
      }
      RefreshCart();
    }
  });
}

function Login(id){
  var login=$("#login_input").val();
  var passwd=$("#passwd_input").val();
  
  if(login!=""&&passwd!=""){
  
    $.post("/ajax/login.php",{login:login,passwd:passwd},function(data){
      if(data=="0"){
        $('#login_false').modal({containerCss:{height:200,width:350}});
      }else{
        document.location="/user/";
      }
    })
  }
}

function Logout(){
  $.post("/ajax/logout.php",{},function(){
    document.location="/"; 
  })
}

function None(){}


  function open_wind(){
    var h;
    var h2;
    $("select").css("visibility","hidden");
    h = document.getElementById('wrap').offsetHeight;
    h2 = document.body.clientHeight;
    if (h > h2) {
       document.getElementById('alles').style.height = h+ 'px';
    } else {
       document.getElementById('alles').style.height = h2+ 'px';
    }

    document.getElementById('alles').style.display = 'block';
    document.getElementById('popup').style.display = 'block';
    $(".of_select").css("visibility","hidden");

  }

  function close_wind(){
     $("select").css("visibility","visible");        
    document.getElementById('alles').style.display = 'none';
    document.getElementById('popup').style.display = 'none';
    $(".of_select").css("visibility","visible");
  }

$(document).ready(function(){

    $(".footer_input").click(function () {
      $(".footer_input").val("");
    });
    
	  $(".form_menu > li").click(function(){
	    var el=$(this).attr("attr");
	    var n=$(this).attr('title');
	    var url=$(this).attr('rel');
	    
	    $("#razdel"+el+"_menu > li").removeClass("act");
	    $(this).addClass("act");

	    $("#mainForme"+el).attr({'action':url});
	    
	    $(".icons"+el).hide();
	    $(".img_razdel"+el+"_"+n).show();
	
	  });

});

function checkeds() {

if ($("#yur_l").is(':checked'))    {
     $(".yur_l2").show();
   }
 else {
     $(".yur_l2").hide();
   }

}




function marka(n)  {
    var color;
    color = document.getElementById("marka_avto_razdel"+n).value;
    if (color == null)
      return;
      document.getElementById("model_avto_razdel"+n).disabled = false
}
function proizvoditel(n)  {
    var color;
    color = document.getElementById("proizvoditel_razdel"+n).value;
    if (color == null)
      return;
      document.getElementById("proizvoditel_model_razdel"+n).disabled = false
}
function seazon(n)  {
    var color;
    color = document.getElementById("seazon_razdel"+n).value;
    if (color == null)
      return;
      document.getElementById("seazon2_razdel"+n).disabled = false
}




function scrbl(m) {
   r1 = document.getElementById('razd1').offsetHeight;
   r2 = document.getElementById('razd2').offsetHeight;
   r3 = document.getElementById('razd3').offsetHeight;
   r4 = document.getElementById('razd4').offsetHeight;
   r3i =  r1 + r2;
   r4i = r1 + r2 + r3;

     if(animate==0){

    animate=1;

   if (m == 1) {
     $(".action_ul").hide();
     $(".action_razdel"+m).show();
     $(".shw").animate( { top:"0"}, 1500);
     $(".shw").removeClass("shw");
     $(".hid").animate( { top:"0"}, 1500);
     $(".hid").removeClass("hid");
     $(".mt1_1").animate( { top:"37"}, 1500);
     $(".mt1_1").addClass("hid");
     $(".mt1_2").addClass("shw");
     $(".mt1_2").animate( { top:"-37"}, 1500);

     $(".main_block_sc").animate( { height: r1}, 1500); $(".main_block2").animate( { top:"0"}, 1500, function(){animate=0;});


   } else if(m == 2) {
     $(".action_ul").hide();
     $(".action_razdel"+m).show();
     $(".shw").animate( { top:"0"}, 1500);
     $(".shw").removeClass("shw");
     $(".hid").animate( { top:"0"}, 1500);
     $(".hid").removeClass("hid");
     $(".mt2_1").animate( { top:"37"}, 1500);
     $(".mt2_1").addClass("hid");
     $(".mt2_2").addClass("shw");
     $(".mt2_2").animate( { top:"-37"}, 1500);
     $(".main_block_sc").animate( { height: r2}, 1500);$(".main_block2").animate( { top:"-" +r1}, 1500, function(){animate=0;});

   } else if(m == 3) {
     $(".action_ul").hide();
     $(".action_razdel"+m).show();
     $(".shw").animate( { top:"0"}, 1500);
     $(".shw").removeClass("shw");
     $(".hid").animate( { top:"0"}, 1500);
     $(".hid").removeClass("hid");
     $(".mt3_1").animate( { top:"37"}, 1500);
     $(".mt3_1").addClass("hid");
     $(".mt3_2").addClass("shw");
     $(".mt3_2").animate( { top:"-37"}, 1500);
     $(".main_block_sc").animate( { height: r3}, 1500);  $(".main_block2").animate( { top:"-" +r3i}, 1500, function(){animate=0;});

   }
     else if (m == 4) {
       $(".action_ul").hide();
     $(".action_razdel"+m).show();
     $(".shw").animate( { top:"0"}, 1500);
     $(".shw").removeClass("shw");
     $(".hid").animate( { top:"0"}, 1500);
     $(".hid").removeClass("hid");
     $(".mt4_1").animate( { top:"37"}, 1500);
     $(".mt4_1").addClass("hid");
     $(".mt4_2").addClass("shw");
     $(".mt4_2").animate( { top:"-37"}, 1500);
     $(".main_block_sc").animate( { height: r4}, 1500); $(".main_block2").animate( { top:"-" +r4i}, 1500, function(){animate=0;} )
     }

}


}



$(document).ready(function(){

  $("li").click(function(){
        $("#d1").hide();

    });

});


function faq_form() {$(".faq_form").toggle();}
