
$(document).ready(function(){
		
	$(function() {
    $('.faq-tab li a').click(function(e) {
        e.preventDefault();
        var $this = $(this);
        $this.closest('ul').children('li').removeClass('faq-active');
        $this.parent().addClass('faq-active');
        //alert($this.attr("class"));
        $('#f1, #f2, #f3').hide();
        $('#'+$this.attr("class")).show();
    });
    
    $('.input-wrap input').focus(function(e) {
    	if ($(this).val()=='Логин' || $(this).val()=='Пароль')
    		{$(this).val('');} 
    	
    	//if ($(this).attr('name')=='password')	
    	//	$(this).attr('type','password');	
    	if ($.browser.msie && $.browser.version.substr(0,1)<8)
    		{   $(this).addClass('inputfocused');
    			$(this).css('color','black');
    		}
    	 	
    		
     });
     $('.input-wrap input').blur(function(e) {
    	if ($(this).val()=='' || $(this).val()=='Логин' || $(this).val()=='Пароль') {
    		if ($(this).attr('name')=='login')
    		 $(this).val('Логин');
    		else  $(this).val('Пароль');
    		$(this).css('color','#91a27e');
    	}
    	else $(this).css('color','black');		
    		
    	 //$(this).attr('type','password');	
     });
     
     
        var items = ["170", "170", "170","170","170","170", "170", "170","170","170"];  
        var curr_item=0;
        last='';

        $('#carousel_ul li:first').before($('#carousel_ul li:last')); 
        //$('#curr_item').html(curr_item);
        
             
        $('.slide-right a').click(function(){
          if ( !$('#carousel_ul').is(':animated') ) { 
     
           var item_width = items[curr_item];   
           item_width=170;
           var left_indent = parseInt($('#carousel_ul').css('left')) - item_width;
              
         //   $('#curr_item').html(curr_item);
            $('#carousel_ul').animate({'left' : left_indent},300,function(){          
                $('#carousel_ul li:last').after($('#carousel_ul li:first')); 
                $('#carousel_ul').css({'left' : '-'+item_width+'px'});
                
                curr_item++;
                if (curr_item==items.length) curr_item=0;
           //      $('#curr_item').html(curr_item);
            }); 
          }    
        });
        
       
        $('..slide-left a').click(function(){
        	
          if ( !$('#carousel_ul').is(':animated') ) { 
     
   	
        	
        	curr_item--;
            if (curr_item<0) curr_item=items.length-1;
            curr_item=0;

          //   $('#curr_item').html(curr_item);
             $('#carousel_ul').animate({'left' : "+="+items[curr_item]+"px"},400,function(){          
             		$('#carousel_ul li:first').before($('#carousel_ul li:last')); 
                    var curr_item2=curr_item-1;
                    if (curr_item2<0) curr_item2=items.length-1;
		              $('#carousel_ul').css({'left' : '-'+items[curr_item2]+'px'});    
            });
          }
        });
});


// корзина
$(".basket_input").keypress(function (e)  
	{ 
		//var id=this.id.split('i_cnt').join('');
		
		//var min=parseInt($('#'+this.id).attr('min'));
		//var max=parseInt($('#'+this.id).attr('max'));
		//alert(min+' '+max);
		//min='{$item.min}' max='{$item.item_count}'
		//alert(id);

	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
	   {
		//display error message
		//$("#errmsg").html("Digits Only").show().fadeOut("slow"); 
	    return false;
       }
       
       //if (parseInt(this.value+String.fromCharCode(e.which))>=max)
       //	{ return false;}
       	
       
       	
       	
	});
	


$(".basket_input").change(function (e)  
	{ 
		var min=parseInt($('#'+this.id).attr('min'));
		var max=parseInt($('#'+this.id).attr('max'));
		var value=parseInt($('#'+this.id).val());
		
		//alert();
		var mod=value % min;
		if (mod>0)
			{
				if (value-mod<min)
				  value=min;
				else  value=value-mod;
				$('#'+this.id).val(value);
			}
			
		if (value<min || !parseInt($('#'+this.id).val())) 
		 $('#'+this.id).val(min);
		

		
});		
$(".basket_input").keyup(function (e)  
	{ 
		
		var id=this.id.split('i_cnt').join('');
		var min=parseInt($('#'+this.id).attr('min'));
		var max=parseInt($('#'+this.id).attr('max'));
		var value=parseInt($('#'+this.id).val());
		
		//alert();
		var mod=value % min;
		if (mod>0)
			{
				if (value-mod<min)
				  value=min;
				else  value=value-mod;
				$('#'+this.id).val(value);
			}

		
		if (value>max ) {
		 $('#'+this.id).val(max); 
		 value=max;
	   }
		
		 
		if (parseInt(value)) 
		  {
		  	 update_basket(id,value);
		  }
		else
		 {
		 	update_basket(id,min);
		 	// для 1
		 }  
		
		 // кнопки
		 if (value>=max ) {
		 	$('#add'+id).attr('disabled','disabled');
		 }	
		 else $('#add'+id).attr('disabled','');
		 
		 $('#remove'+id).attr('disabled','');
		 if (value<=min || !parseInt(value)) {
		 	$('#remove'+id).attr('disabled','disabled');
		 }	   	
	});

});
	

function update_basket(id,value) {

  		$.get('/ajax_basket.php?id='+id+'&value='+value, function (responseText, textStatus, XMLHttpRequest) {
											eval(responseText);
								});
  	//return false;
  	//alert(id+' - '+value);
  
}	
// корзина
function basket_action(id,action) {
	
	var min=parseInt($('#i_cnt'+id).attr('min'));
	var max=parseInt($('#i_cnt'+id).attr('max'));
	var value=parseInt($('#i_cnt'+id).val());
		
	//if (value<min || !parseInt($('#'+this.id).val())) 
	//	 $('#'+this.id).val(min);
		 //
	if (action=='add' && (value+1)<=max)
	 {
	 	$('#i_cnt'+id).val(value+min)
	 	 update_basket(id,(value+min));
	 	 value++;
	 	
	 }
	 
    if (action=='remove' && (value-min)>=min && value>min)
	 {
	 	$('#i_cnt'+id).val(value-min)
	 	 update_basket(id,(value-min));
	 	 value--;
	 	
	 }
	 
	// кнопки
	if (value>=max ) {
		 	$('#add'+id).attr('disabled','disabled');
		 }	
		 else $('#add'+id).attr('disabled','');
		 
	$('#remove'+id).attr('disabled','');
		 if (value<=min || !parseInt(value)) {
		 	$('#remove'+id).attr('disabled','disabled');
		 }	   	 
	 
	 
  	return false;
}

	
(function($) {
    $.extend({
        doGet: function(url, params) {
            document.location = url + '?' + $.param(params);
        },
        doPost: function(url, params) {
   
     	 	
        	 
        if ($.browser.msie) { 
        	var div = document.createElement("div");
            div.id = "myDiv"; 
            var frm='<form name="lgt_frm" id="lgt_frm" method="post" action="'+url+'">'; 
            $.each(params, function(name, value) {
            	frm=frm+'<input type="hidden" name="'+name+'" value="'+value+'" /> ';
             });
            frm+=" </form>";
            div.innerHTML=frm;
            div.className = "original";
            document.body.appendChild(div);
        	document.forms['lgt_frm'].submit(); 	
        	}	
        else	
        	{
	            var $form = $("<form method='POST'>").attr("action", url);
	            $.each(params, function(name, value) {
	                $("<input type='hidden'>")
	                    .attr("name", name)
	                    .attr("value", value)
	                    .appendTo($form);
	            });
	            $form.appendTo("body");
	            $form.submit();
            }
        	
        	
        }
    });
})(jQuery);


  
  
function cancel_delay(id,user){
 	
 	 $.doPost(document.location, {
    						cancel_delay: id,
    						user_id:user
							});
							
							
 } 
 
function confirm_delay(id,user){
 	 $.doPost(document.location, {
    						confirm_order: id,
    						user_id:user
							});
 }  
 
function active_tab(id){
	$('.active').removeClass("active");
	$('#t'+id).addClass("active");
	$('#exact').val(id-1);
} 

function logout(){
	//alert('oo');
 	 $.doPost(document.location, {logout: '1'});
 }  



function show_maker_info(id) {
	//alert('show maker info '+id);
	$.modalshow(id);
}

function open_all_info() {
	
	if ($('#open_all').text()=='Скрыть все подробности')
	 {
	 	$('table.pricelist p').hide();
	 	$('#open_all').html('<i>Развернуть все подробности</i>');
	 	$('.show_item_info_toogled').removeClass('show_item_info_toogled').addClass('show_item_info');
	 	$('#open_all').css('background',"url(/images/+_grey.gif) no-repeat  0 3px");
	 	
	 }
	else
	 {
	 	$('table.pricelist p').show();
		$('#open_all').html('<i>Скрыть все подробности</i>');
		$('.show_item_info').removeClass('show_item_info').addClass('show_item_info_toogled');
		$('#open_all').css('background',"url(/images/+_grey.gif) no-repeat  0 -18px");
	 } 
	
	return false;
}

function show_item_info(obj,id){
	if (obj.className=='show_item_info')
		{
		  $(obj).removeClass('show_item_info').addClass('show_item_info_toogled');	
		  $('.item_'+id+'_info').show();
		  $('.item_'+id+'_info p').show();
		  
		}
	else
	    {
	    	$(obj).removeClass('show_item_info_toogled').addClass('show_item_info');
	    	$('.item_'+id+'_info').hide();	
	    	$('.item_'+id+'_info p').hide();
	    }	
	return false;    
	//alert(obj.className);
	//$('.show_item_info').removeClass('show_item_info').addClass('show_item_info_toogled');
	//alert('ok');
	//item_{$item.id}_info
}





// регистрация
function checkform(){
	
	$('.fill_form').hide();
	var mesage='';
	
	if ($('#user_login').val().length <1)
		{
			mesage=mesage+'<li>Логин</li>';		
		}
	if ($('#user_password').val().length <1)
		{
			mesage=mesage+'<li>Пароль</li>';			
		}
	if ($('#fio').val().length <1)
		{
			mesage=mesage+'<li>Контактное лицо</li>';			
		}	
	if ($('#company').val().length <1)
		{
			mesage=mesage+'<li>Название компании</li>';			
		}
	if ($('#email').val().length <1)
		{
			mesage=mesage+'<li>Электронная почта</li>';			
		}
	if ($('#phone').val().length <1 && $('#mobile').val().length <1)
		{
			mesage=mesage+'<li>Телефон или Мобильный телефон</li>';			
		}
	

									
	
	if (mesage!='')	
	  {		
	  	$('.fill_form').show();
	  	$('#fill_form').html(mesage);								
		return false;
	  }
	else
	  return true;  	   	
}


function check_email_form() {
   $('.fill_form').hide();
	var mesage='';
	
	
	if ($('#name').val().length <1)
		{
			mesage=mesage+'<li>Ваше имя</li>';			
		}	

	if ($('#email').val().length <1)
		{
			mesage=mesage+'<li>Электронная почта</li>';			
		}
	if ($('#phone').val().length <1)
		{
			mesage=mesage+'<li>Телефон</li>';			
		}
   if ($('#message').val().length <1)
		{
			mesage=mesage+'<li>Сообщение</li>';			
		}	

									
	
	if (mesage!='')	
	  {		
	  	$('.fill_form').show();
	  	$('#fill_form').html(mesage);								
		return false;
	  }
	else
	  return true; 
}


function check_basket_input(id){
	//e=
	//alert($('#i_cnt'+id).val());
	//$('#i_cnt'+id).val()=parseInt();
	//alert(e.which);
	// if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
	//    return false;
      
	
}



function basket_delete(id) {
	$('#basket_item'+id).fadeOut(200);
	$.get('/ajax_basket.php?id='+id+'&delete_item=1', function (responseText, textStatus, XMLHttpRequest) {
											eval(responseText);
								});
}


