
function get_lhash() {
  var str = window.location.hash.substr(1);
  if ( str.substr(-2,1) == 'p') {
      str = str.substr(0,str.length-2);
  }
  return str;
}

function get_lhashp() {
  var str = window.location.hash.substr(1);
  var cpage = 0;
  if ( str.substr(-2,1) == 'p') {
      cpage = str.substr(-1,1);
  }
  return cpage;
}

function re_cat(id_gr,id_t) {
    jQuery("#ttd22").html('Загрузка...');

    jQuery('#prev_id').val(get_lhash());

    if (jQuery("#fsorth").val() == '0') {
       $('#div_fltr_cat21').css('background', 'url(../img/cat_t1a.png) no-repeat' );
       $('#div_fltr_cat22').css('background', 'url(../img/cat_t2.png) no-repeat' );
    } else {
       $('#div_fltr_cat21').css('background', 'url(../img/cat_t1.png) no-repeat' );
       $('#div_fltr_cat22').css('background', 'url(../img/cat_t2a.png) no-repeat' );
    }
    
    jQuery.ajax({ 
        type: "POST",
        url: "ajax/jcat.php",
        data: "id_gr="+id_gr+"&id_t="+id_t+"&selsort="+jQuery("#selsort").val()+"&manuf="+jQuery("#manuf").val()+"&isearch="+jQuery("#isearch").val()+"&fsorth="+jQuery("#fsorth").val()+"&mrnew="+jQuery("#mrnew").val()+"&pp="+jQuery("#cur_pg").val(),
        cache: false,
        success: function(html){   
            jQuery("#ttd22").html(html);
            
            if(id_t != 0) {
              window.scroll(0,0);
            }

            if (jQuery("#totl_items").val() == '1') {
              jQuery('.a_nextp').css('visibility', 'visible' );
            } else {
              jQuery('.a_nextp').css('visibility', 'hidden' );
            }
            
            if (get_lhashp() != '0') {
              jQuery('#cur_pg').val(get_lhashp());
              jQuery('.a_prevp').css('visibility', 'visible' );
              window.scroll(0,0);
            } else {
              jQuery("#cur_pg").val(0);
              jQuery('.a_prevp').css('visibility', 'hidden' );
            }
        }
    }); 
}
//==============================================================================
function cat_next(pp) {
  if (get_lhash() > '') {

    jQuery("#ttd22").html('Загрузка...');

    var id_gr  = get_lhash();
    var cur_pg = pp+ parseInt(jQuery("#cur_pg").val());
     
    jQuery("#cur_pg").val(cur_pg);
    
    jQuery.ajax({ 
        type: "POST",
        url: "ajax/jcat.php",
        data: "id_gr="+id_gr+"&id_t=0&selsort="+jQuery("#selsort").val()+"&manuf="+jQuery("#manuf").val()+"&isearch="+jQuery("#isearch").val()+"&fsorth="+jQuery("#fsorth").val()+"&mrnew="+jQuery("#mrnew").val()+"&pp="+cur_pg,
        cache: false,
        success: function(html){   
            jQuery("#ttd22").html(html);
            window.scroll(0,0);
            
            if (jQuery("#totl_items").val() != '1') {
              jQuery('.a_nextp').css('visibility', 'hidden' );
            } else {
              jQuery('.a_nextp').css('visibility', 'visible' );
            }

            if (cur_pg > 0) {
               jQuery('.a_prevp').css('visibility', 'visible' );
               window.location.hash = '#'+get_lhash()+'p'+cur_pg;
            } else {
               jQuery('.a_prevp').css('visibility', 'hidden' );
            }
        }
    }); 
  }
}

//----------------------------------------------
function put_d_pr_name(id_gr) {
  if(id_gr > 0) {
    jQuery.ajax({ 
        type: "POST",
        url: "ajax/ajax.php",
        data: "put_d_pr_name=ok&id_gr="+id_gr,
        cache: false,
        success: function(html){
            var oldtext = jQuery("#d_pr_name").html();
            jQuery("#d_pr_name").html(oldtext+html);
        }
    });
  }
}
//----------------------------------------------
function get_man() {
    jQuery("#man_list").html('поиск '+jQuery("#nameman").val()+'...');
    jQuery.ajax({ 
        type: "POST",
        url: "ajax/ajax.php",
        data: "get_man=ok&name="+jQuery("#nameman").val(),
        cache: false,
        success: function(html){   
            jQuery("#man_list").html(html);
        }
    }); 
}
//----------------------------------------------
function del_agn(tpp, id, fld) {
   var x=window.confirm("Удалить?");
   flds = '';
   if (fld > ' ') flds = fld;
   if (x) jQuery.ajax({ 
        type: "POST", url: "ajax/ajax.php", data: "del_ag=ok&bdd="+tpp+"&ida="+id+"&fld="+flds,
        cache: false,
        success: function(){   
           location.reload();
        }   
    });      
}
//----------------------------------------------
function chhn_tb(tb,fl,vl,id) {
    jQuery.ajax({ 
        type: "POST", url: "ajax/ajax.php",
        data: "chhn_tb=ok&tb="+tb+"&fl="+fl+"&vl="+vl+"&id="+id,
        cache: false,
        success: function(){   }   
    });      
}
//----------------------------------------------
function re_catm(id_gr,id_top,id_t) {
   if (id_top == 0) {
      jQuery("#dcatm").html('Загрузка...');
   } else {
     $('#isearch').val(' поиск');
   }
   
   $('#prev_id').val(get_lhash());
   jQuery("#cur_pg").val(0);
   
    jQuery.ajax({ 
        type: "POST",
        url: "ajax/jcatm.php",
        data: "id_gr="+id_gr+"&id_top="+id_top,
        cache: false,
        success: function(html){
            if (id_top == 0) {
              jQuery("#dcatm").html(html);
            } else {
              if ((id_gr == id_top) && (jQuery("#ddv"+id_top).html() != '') ) {
                jQuery("#ddv"+id_top).html('');
              } else {
                jQuery("#ddv"+id_top).html(html);
              }
            }
        }
    }); 
    
   re_cat(id_gr,id_t);
}
//----------------------------------------------
function re_akc(nn) {
 var current = jQuery("#h_val_akc").val();
 if ((current == 0) && (nn == -1)) { 
  alert('выбрана последняя акция');
 } else {
  jQuery.ajax({ 
     type: "POST",
     url: "ajax/jmain_a.php",
     data: "nn="+nn+"&nom=0"+"&val="+current,
     cache: false,
     success: function(html){   
         jQuery("#h_val_akc").val(html);
         current = html;
         
     if (current > 0) {
       jQuery.ajax({ 
          type: "POST",
          url: "ajax/jmain_a.php",
          data: "nn="+nn+"&nom=1"+"&val="+current,
          cache: false,
          success: function(html){   
            jQuery("#div_akc1").html(html);
          }
       }); 
     } else {
        jQuery("#div_akc1").html('');
     }
     jQuery.ajax({ 
        type: "POST",
        url: "ajax/jmain_a.php",
        data: "nn="+nn+"&nom=2"+"&val="+current,
        cache: false,
        success: function(html){   
            jQuery("#dmakc").html(html);
        }
     }); 
     jQuery.ajax({ 
        type: "POST",
        url: "ajax/jmain_a.php",
        data: "nn="+nn+"&nom=3"+"&val="+current,
        cache: false,
        success: function(html){   
            jQuery("#div_akc3").html(html);
        }
     }); 
    }
  }); 
 }
}
//-------------------------------------------------------------------------------------------------
function put_zak(idz) {
    jQuery.ajax({ 
        type: "POST", url: "ajax/ajax.php",
        data: "put_zak=ok&idz="+idz,
        cache: false,
        success: function(){   
          location.reload();
        }   
    });
}
//-------------------------------------------------------------------------------------------------
function put_email(idz,idus) {
    jQuery.ajax({ 
        type: "POST", url: "ajax/ajax.php",
        data: "put_email=ok&idz="+idz+"&idus="+idus,
        cache: false,
        success: function(html){   
           alert('email ok!');
        }   
    });
}
//-------------------------------------------------------------------------------------------------
function put_zaka(idz,tp) {
    jQuery.ajax({ 
        type: "POST", url: "ajax/ajax.php",
        data: "put_zaka=ok&idz="+idz+"&tp="+tp,
        cache: false,
        success: function(){   
           location.reload();
        }   
    });
}
//-------------------------------------------------------------------------------------------------
function chbsk(idt) {
    if (jQuery("#btbsk"+idt).hasClass("btbsk0")) {
      jQuery("#btbsk"+idt).removeClass('btbsk0') 
      jQuery("#btbsk"+idt).addClass('btbsk1')
        jQuery.ajax({ 
            type: "POST", url: "ajax/ajax.php",
            data: "chbsk=ok&idt="+idt+"&a=1",
            cache: false,
            success: function(){   
            }    
        }); 
    } else {
      var x=window.confirm("Удалить из корзины?");
      if (x) {
        jQuery("#btbsk"+idt).removeClass('btbsk1') 
        jQuery("#btbsk"+idt).addClass('btbsk0')
        jQuery.ajax({ 
            type: "POST",
            url: "ajax/ajax.php",
            data: "chbsk=ok&idt="+idt+"&a=0",
            cache: false,
            success: function(){   
            }    
        }); 
      }
    }
}
