function send_call_info(){
  
  if ($("#call_form_name").val()=='' || $("#call_form_phone").val()=='' || $("#call_form_captcha").val()==''){
    alert("Заполните все поля");
    return;
  }
  
  
  $("#call_form_name").val();
        $.ajax({
            url: '/ajax/send_call.php',             // указываем URL
            type: "POST",
            data: "name="+$("#call_form_name").val()+"&phone="+$("#call_form_phone").val()+"&captcha="+$("#call_form_captcha").val(),
            success: function (data, textStatus) {
              hideform(); 
              alert(data);   
            }
        }); //ajax

}

function callme(){
  $(".b-popup__rama").show();

}//showme
function hideform(){
  $(".b-popup__rama").hide();

}//showme

$(document).ready(function(){
/*	
  $('.js_login_search').keyup(function () {     //shdiv_3 em  
    var parameters = new Object();                    
    parameters['cmd']  = 'login';
    parameters['login'] = $(this).val();                              
	  $.post('/ajax/check_login.php',parameters,function(response,ans_code){
	    $('#shdiv_30 em').html(response);    
	    if(response != ''){
	      $('#shdiv_30').show();    
	      $('FORM.office').attr('not_submit_login','true');
		}else{
		  $('#shdiv_30').hide();
		  $('FORM.office').attr('not_submit_login','false');         
		} 
	  });
  });
	
  $('.js_email_search').keyup(function () {     
    var parameters = new Object();
    parameters['cmd']  = 'mail';
    parameters['login'] = $(this).val();   
	  $.post('/ajax/check_login.php',parameters,function(response,ans_code){
	    $('#shdiv_80 em').html(response);
	    if(response != ''){
			$('#shdiv_80').show();    
	    	$('FORM.office').attr('not_submit_email','true');
		}else{
		  	$('FORM.office').attr('not_submit_email','false');   
		} 
	  });
  });	
*/	
	
	
    $('div.bar-big, div.bar-mini').pngFix();
	
    $('form.find span').toggle(
        function(){
            $(this).toggleText('↓', '↑');
            $('div.find-select').css('display', 'block');        	
        },
        function(){
            $(this).toggleText('↓', '↑');
            $('div.find-select').css('display', 'none');
        }
    ).hover(
        function(){
        	$(this).attr('class', 'hover');
        },
        function(){
            $(this).removeAttr('class');
        }
    );
    
    if ($.browser.msie && $.browser.version == '6.0'){
        $('ul.plan-link span').each(function(){
            $(this).width($(this).width() * 0.07 + 'em');
        });
    }
    
    $('div.fixed').each(function(){
        $(this).css('margin-top', -$(this).height() / 2);
    });

    $('img.fixed-close').click(function(){
        $('div.fixed').css('display', 'none');
    });
    

});

jQuery.fn.toggleText = function(a, b){
    return this.html(this.html().replace(new RegExp('('+ a +'|'+ b +')', 'g'), function(x){return(x == a) ? b : a;}));
}

$.extend($.expr[':'], {  
    smallstring: function(a) {  
    
        return $(a).val().length < 5;
		  
    }  
});  

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

function fill_the_input(){

    //alert('Заполните поле "'+this.title+'"')
    $(this).parent().children('.shdiv').show();

} // function fill_the_input

function ajax_layar_fnc(){       
   if($('.hide_answer_basket').size()){ 
	    var data = new Object();
	    data['ajax_id'] = $('#auth_menu_id').attr('ajax_id_c');
	    $.post('/ajax/ajax.php',data,function(response,ans_code){  
		  $('#auth_menu_id').html(response);    
	    }); 
		$("#first_basket_form_w").hide();
		   
   }

}

// счетчик форм
var forms_cnt = 0;
// ajax обертывалка
function set_form_submit( ajax_id ){

  //ajax_layar_fnc(); 
  
  var parent_selector = ajax_id ? '[id='+ajax_id+']' : '[id^=ajax_]';
  // обработка обычных ссылок 

  $(parent_selector+' a:not([onClick][href^=javascript][href^=http://])').not('[noajax]').each(
  function(){

      var current = this;

      $(current).unbind('click.ajax');
      $(current).bind('click.ajax',function(){

          // массив параметров
          var href_arr = new Array();

          // параметры в ссылке
          href = current.href.replace('http://','');          
          a_href = href.split('?');
          if ( a_href[1] )
              href_arr.push(a_href[1]);

          // внутренний идентификатор объекта
          href_arr.push('ajax_id='+$(current).parents(parent_selector).attr('id').substr(5));

          // параметры, измененные url_rewriter'ом
          href_arr.push('ajax_request_uri='+a_href[0].substr(href.search('/')));
          
          $.get('/ajax/ajax.php?'+href_arr.join('&'),'',function(resp){
              set_form_submit( $(current).parents(parent_selector).html(resp).attr('id') );
          });
          
          return false;
      });
      
  }
  );

  // обработка форм
  $((ajax_id?parent_selector:'')+' form:not([onSubmit]):not([action])').each(function(){

      var current_form = this;

      forms_cnt++;
      
      $(current_form).attr('id','ajaxform_'+forms_cnt);

      // если форма лежит в контейнере с зарезервированным id, то
      // дописать в нее скрытое поле с номером объекта 
      $(current_form).parents(parent_selector).each(
          function(){
              $('<input type="hidden" name="ajax_id">').val(this.id.substr(5)).appendTo(current_form);
          }
      );
      
      $(current_form).unbind('submit.ajax');
      // подключение обработчика отправки формы
      $(current_form).bind('submit.ajax',function(){

          $('.shdiv, .shdiv_email, .shdiv_pass').hide();
          
          var ok = true;
          
          // проверка е-mail адресов
          var email_field = $('#'+current_form.id+' input[name=_email]').filter(':first');
          if ( $(email_field).size() ){
          
              mailString = $(email_field).val(); 
              re1 = /([\.\-_@][\.\-_@])|(^[\.])|(^[\-])|(^[\@])/;
              re2 = /^[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4}$/;
  
              if ( !re1.test(mailString) && re2.test(mailString) ){
                  //alert('ok email');
              } else { 
                  //show_message_form('неверно введен email');
                  $('.shdiv_email').show();
                  $(email_field).focus();
                  ok = false;
              }
  
          } // if email
          
          // проверка соответствия паролей
          if ( $('#'+current_form.id+' :input[name=_password]').val() !== $('#'+current_form.id+' :input[name=_password2]').val() ){
              $('.shdiv_pass').show();
              $('#'+current_form.id+' :input[name=_password2]').focus();
              ok = false;
          } // if  '=' password
          
//           if ( $('#'+form_id+' [name=passwd]').val().length < 6 ){
//               show_message_form('пароль не может быть меньше 6 символов');
//               $('#'+form_id+' [name=passwd]').focus();
//               return false;
//           } // if  password.l < 6        
             /*
			// проверка на совпадение логинa			  
			    var parameters = new Object();                    
			    parameters['cmd']  = 'login';
			    parameters['login'] = $('.js_login_search').val();                              
				  $.post('/ajax/check_login.php',parameters,function(response,ans_code){
				    $('#shdiv_30 em').html(response); 
					$('#shdiv_30').show();   
				    if(response != ''){ ok = false; alert(response);   }
				  });
			// проверка на совпадение мейла
			    var parameters = new Object();
			    parameters['cmd']  = 'mail';
			    parameters['login'] = $(this).val();   
				  $.post('/ajax/check_login.php',parameters,function(response,ans_code){
				    $('#shdiv_80 em').html(response);
				    $('#shdiv_80').show();
				    if(response != ''){ ok = false; alert(response); }
				  });
               */
               
               ////////////////////////////////////////
		if($(this).attr('not_submit_login'))return false;
		if($(this).attr('not_submit_email'))return false;
					
          if (!$('#'+current_form.id+' :input[id^=wfrm_]').filter(':smallstring').each( fill_the_input ).filter(':first').focus().end().size() && !$('#'+current_form.id+' :input[name^=_]').filter('[value=""]').each( fill_the_input ).filter(':first').focus().end().size()){

              if ( !ok ) return false;
                    
              var parameters = new Object();
              
              $('#'+current_form.id+' :input[name]').each(function(){
                  current = this;
                  if ( $(this).is('[name^=_]') ) 
                      $(this).attr('name',current.name.substr(1));
                  parameters[current.name] = current.value;
              });
             
              $.post('/ajax/ajax.php',parameters,function(response,ans_code){

                  var replace = $(current_form).attr('replace');
                  
                  switch( replace ){
                    case undefined:
                        if(response == 'captcha_error'){
                            alert ('captcha_error');
                        }
                        else {
                           set_form_submit( $(current_form).parents(parent_selector).html(response).attr('id') );
                        }
                        break;
                    case '':
                        break;
                    default:
                        if(response == 'captcha_error'){
                            alert ('captcha_error');
                        }
                        else {
                            $('#'+replace).html(response);
                        }
                        break;
                  } // switch

              });
      
          } // if
          
        
          return false;

      });

  });

} // function set_form_submit

$( function(){set_form_submit();} );

function view_comp(){
    $.get('/ajax/ajax.php?ajax_event=view_comp_art','',function(resp){ 
    // alert(resp);  
    $('.fixed').html(resp);
    $('.fixed').css('display','block');                                         
    });
}
function next_advice(ajax_event){
    var data = new Object;
    data['ajax_event'] = ajax_event;
    $.post('/ajax/ajax.php',data,function(response,ans_code){
    document.getElementById('my_container').innerHTML =  response;   
    });
} // function

var compare_win_q;
function compare_win(){
  compare_win_q = window.open('/compare/','','scrollbars=yes,width=1100,height=800');
}

//     length    alert($('INPUT[name=login]').attr('value'));
//if($('#frm_login_id').attr('value').length < 4) alert(123);
  function find_err(){    
    var flag = true;
    $('.shdiv').hide();
    if($('INPUT[name=password]').attr('value') != $('INPUT[name=password2]').attr('value')){ $('#shdiv_1').show(); flag = false; };
    if($('INPUT[name=password]').attr('value') == ''){ $('#shdiv_2').show(); flag = false; };
    if($('INPUT[name=login]').attr('value') == ''){ $('#shdiv_3').show(); flag = false; };
    //if(($('#frm_login_id').attr('value')).length < 4){ $('#shdiv_21').show(); flag = false;};
    if($('INPUT[name=frm_name]').attr('value') == ''){ $('#shdiv_4').show(); flag = false; };
    if($('INPUT[name=frm_surname]').attr('value') == ''){ $('#shdiv_5').show(); flag = false; };
    if($('INPUT[name=email]').attr('value') == ''){ $('#shdiv_6').show(); flag = false; };
    if($('INPUT[name=frm_phone]').attr('value') == ''){ $('#shdiv_7').show(); flag = false; };
    $('.js_login_search').keyup(); $('.js_email_search').keyup();
    if($('FORM.office').attr('not_submit')) flag = false;
      alert(flag);
    mailString = $('INPUT[name=email]').attr('value');
    re = /([\.\-_@][\.\-_@])|(^[\.])|(^[\-])|(^[\@])/;
    result = re.test(mailString);
    if(!result)     
    {
        re = /^[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4}$/;
        result = re.test(mailString);
        
        if(!result){ 
          $('#shdiv_8').show(); flag = false; 
        }
           
    } // if 
    else {
      $('#shdiv_8').show(); flag = false; 
    } // else     
    
    
    return flag;
  }

function add_to_bask(object_id){
          $.get('/ajax/ajax.php?ajax_event=bay_art&sec_id=<!--[sec_id]-->&tovar_id='+object_id,'',function(resp){
            if(resp){              
              $('.fixed').html(resp);
              $('.fixed').css('display','block');
            }       
          });
          
}

function add_to_comp(object_id){
          $.get('/ajax/ajax.php?ajax_event=add_comp_art&sec_id=<!--[sec_id]-->&tovar_id='+object_id,'',function(resp){                     
              //alert(1);
              $('#comp_add_span').html("Добавить в сравнение ("+resp+")");    
              $('#comp_view_span').html("Сравнение ("+resp+") <input type='submit' value='Сравнение ("+resp+")'  onClick='view_comp()'/>");
              $('#id_li_left_menu_'+object_id).toggleClass("menu-compare");                           
          });
}

/////////////////////////shopping_cart_api////////////////////////

function show_cart_list(folder, container){
  data = new Object;
  data['ajax_event'] = "show_cart_list";
  data['folder'] = folder;
  $.post('/ajax/ajax.php',data,function(response,ans_code){
		$('#'+container).html(response);
	});
}

function send_order(folder){
  data = new Object;
  data['ajax_event'] = "mail_cart_order";
  data['folder'] = folder;
  $.post('/ajax/ajax.php',data,function(response,ans_code){
		$('#_cart_list_f_'+folder).html(response);
	});
}

function order(folder){
  data = new Object;
	data['ajax_event'] = "cart_order";
	data['folder'] = folder;
	$.post('/ajax/ajax.php',data,function(response,ans_code){
	$('#_cart_list_f_'+folder).html(response);
	});
}

function add_card_item(item_id,count,folder){
	data = new Object;
	data['ajax_event'] = "add_cart_item";
	data['item_id'] = item_id;
	data['count'] = count;
	data['folder'] = folder;
	$.post('/ajax/ajax.php',data,function(response,ans_code){
	$('.fixed').html(response).show();
	});
}

function del_card_item(item_id,folder){
	data = new Object;
	data['ajax_event'] = "del_cart_item";
	data['item_id'] = item_id;
	data['folder'] = folder;
	$.post('/ajax/ajax.php',data,function(response,ans_code){
	window.setTimeout('show_cart_list("'+folder+'", "_cart_list_f_'+folder+'")', 1);
	});
}

function recount_card_item(item_id,count,folder){
	data = new Object;
	data['ajax_event'] = "recount_card_item";
	data['item_id'] = item_id;
	data['count'] = count;
	data['folder'] = folder;
	$.post('/ajax/ajax.php',data,function(response,ans_code){
	window.setTimeout('show_cart_list("'+folder+'", "_cart_list_f_'+folder+'")', 1);
	});
}

function location_parent(href){
  window.opener.location = href.href; 
  window.close();
}
/////////////////////////shopping_cart_api////////////////////////

  function reload_right_menu(){
    var data = new Object();
    data['ajax_id'] = $('#auth_menu_id').attr('ajax_id_c');
    $.post('/ajax/ajax.php',data,function(response,ans_code){   
      $('#auth_menu_id').html(response);
    });   
  }
  
function check(_this,template){    //input content checker
    switch(template){
    case 'numeric':   var reg = /[^0-9\ ]/; break;
    case 'cyrilic':   var reg = /[^а-яёА-ЯЁ\ ]/; break;
    case 'cyrilic_numeric_symbols':   var reg = /[^0-9а-яёА-ЯЁ\ \-\.\,\"\']/; break;
    case 'phone':   var reg = /[^0-9\-\+\(\)\ ]/; break;
    case 'cyrilic_numeric':   var reg = /[^0-9а-яёА-ЯЁ\ ]/; break;
    case 'latin':   var reg = /[^0-9a-zA-Z\$\"\ \-]/; break;
    case 'cyrilic_latin':   var reg = /[^а-яёА-ЯЁa-zA-Z\ ]/; break;
    case 'cyrilic_latin_numeric':   var reg = /[^0-9а-яёА-ЯЁa-zA-Z\ ]/; break;
    }
    var col=$(_this).val();
    if  (col.search(reg)==-1 || col==''){  //проверяем введенное значение
      }//if 
    else  {
    _this.value="";
    alert("Неверное значение поля "+$(_this).attr('title'))
    $(_this).focus();
    };
    
}//function

  function culc_res_price(){
    var tot_price  = parseInt($("#resprice_label").attr("tot_price"));
    var deliv_cost = parseInt ($("#resprice_label").attr("deliv_cost"));
    if($('#deliv_check:checked').size() == 1){   
      var res_price = tot_price + deliv_cost;
      $("#inp_deliv_cost").attr("value",deliv_cost);
      $("#resprice_label").html( res_price + " руб.");
    }else{   
      $("#inp_deliv_cost").attr("value","0");               
      $("#resprice_label").html( tot_price + " руб.");
    }
    
                                         
  }
  

 
