function select_submit(ind, goods_id, incom, rest_full, multiplicity){

//alert(ind+" - "+goods_id+" - "+incom+" - "+rest_full+" - "+multiplicity);

var b = "bsk_" + goods_id;
var g = "g2basket_" + goods_id;
var bt = "booking_tool_" + goods_id;
var r = new Number(document.getElementById(g).value);
var i = new Number(incom);
var rf = new Number(rest_full);
var m = new Number(multiplicity);

if(r == 0){
  r = 1;
}

if(isNaN(m)){
  m = 1;
}

if(m == 0){
  m = 1;
}

//alert(g+" - "+ind+" - "+i+" - "+m+" - "+goods_id+" - "+r+" - "+r % m);
//exit();

if((r % m) != 0){
  alert("Этот товар можно купить только в количестве кратным "+m+" шт.");
  document.getElementById(g).value = "";
  return false;
}

  if(ind != ""){
      switch (ind){
      case "0":  /* купить сейчас */
        if(r > rf){
          if(i == "0"){ /* если есть приход то под приход, нету тока ДЗ */
            alert("Текущее наличие: "+rest_full+" шт.\nПредлагаем сделать заявку на ДЗ.");
          }else{
            alert("Текущее наличие: "+rest_full+" шт.\nПредлагаем сделать заявку под приход.");
          }
          break;
        }
        document.getElementById(g).name = "g2basket["+goods_id+"#0#"+ind+"]";
        document.getElementById(b).submit();
        break;
      case "1":  /* Заказать у поставщика */
        document.getElementById(g).name = "g2basket["+goods_id+"#0#"+ind+"]";
        document.getElementById(b).submit();
        break;
      case "2":  /* Заказать под приход */
        if(r > i){
             alert("Ожидаемый приход: "+incom+" шт.\nВесь товар с ближайшего прихода уже распродан!\nПредлагаем сделать заявку на ДЗ.");
          break;
        }
        document.getElementById(g).name = "g2basket["+goods_id+"#0#"+ind+"]";
        document.getElementById(b).submit();
        break;
      case "3":  /* Есть спрос */
        document.getElementById(g).name = "demand["+goods_id+"]";
        document.getElementById(b).action = "/demand/";
        document.getElementById(b).submit();
        break;
      case "4":  /* Для инструментов заказ через письмо */
//      alert(ind+" - "+goods_id+""+bt);
        document.getElementById(bt).submit();
        break;
      case "5":  /* Внешние склады */
        if(r > rf){
          alert("Текущее наличие: "+rest_full+" шт.\nИзмените пожалуйста заказ.");
          break;
        }
        document.getElementById(b).submit();
        break;
      default:
        break;
    }
  }
}


function submit_auto($goods, $brand){

var r=confirm("Сайт не торгует в розницу.\nПерейти на сайт розничной торговли автозапчастями?");

if (r==true){
  //alert($goods+" "+$brand);
  window.location.href = "http://www.autohypermarket.ru/catalog/?qText="+$goods+"&brand="+$brand;
}else{
  return false;
}


}

function select_dz(ind, dt /*дата заказа ДЗ*/){
  if(ind==1){
    if(dt=="" || !dt){
    alert("Срок поставки детали\n один месяц.");
    }else{
    alert("Ближайшая дата заказа поставщику\n"+dt);
    }
    //alert("В связи с техническими трудностями\nзаявки по ДЗ временно не принимаются\nИзвините.");
    return false;
  }
}

function select_search(elaboration){
  switch (elaboration) {
   case "articul" :
    document.getElementById("qText").value = "номер запчасти";
    document.getElementById("marka").style.display = "none";    
    return false;
   case "orig" :
    document.getElementById("qText").value = "оригинальный номер";
    document.getElementById("marka").style.display = "none";        
    return false;
   case "vin" :
    document.getElementById("qText").value = "VIN код";
    document.getElementById("marka").style.display = "";
    return false;  
   default :
    document.getElementById("qText").value = "номер запчасти";
    document.getElementById("marka").style.display = "none";        
    return false;
  } 
}

function onfocus_search(id){
var elaboration = document.getElementById('elaboration').options.value;

  if(document.getElementById(id).value == "номер запчасти" || document.getElementById(id).value == "оригинальный номер" || document.getElementById(id).value == "VIN код"){ 
  document.getElementById(id).value = "";
  return false;
  }else{
    if(document.getElementById(id).value == ""){
      switch (elaboration) {
       case "articul" :
        document.getElementById(id).value = "номер запчасти";
        document.getElementById("marka").style.display = "none";    
        return false;
       case "orig" :
        document.getElementById(id).value = "оригинальный номер";
        document.getElementById("marka").style.display = "none";        
        return false;
       case "vin" :
        document.getElementById(id).value = "VIN код";
        document.getElementById("marka").style.display = "";
        return false;  
       default :
        document.getElementById(id).value = "номер запчасти";
        document.getElementById("marka").style.display = "none";        
        return false;
      }
    }
}

}

function onkeypress_search(){
var elaboration = document.getElementById('elaboration').options.value;

    if(elaboration=="vin" && document.getElementById("select_marka").value==""){
      alert("Выберите марку авто!");
      return false;
    } 
}

function search_submit(id){
  
//var qText = document.getElementById('qText').value;
var elaboration = document.getElementById('elaboration').value;
var select_marka = document.getElementById('select_marka').value;

//alert(id);
//alert(elaboration);

  switch (elaboration) {
   case "articul" :
   case "orig" :
    document.getElementById(id).submit();
    break;
   case "vin" :
    if(select_marka==""){
      alert("Не выбрана марка авто!");
      return false;
      break;
    }
    document.getElementById('qText').name = "vin";
    document.getElementById(id).action = "http://parts.d-o-w.ru/" + select_marka + "/";   
    document.getElementById('elaboration').value = ""; 
    document.getElementById(id).submit();
    break; 
   default :
    document.getElementById(id).submit();
    break;
  } 
}

function display_action(id,id_img){

if(document.getElementById(id).style.display=="none"){
  document.getElementById(id).style.display="";
  document.getElementById(id_img).src="/i/ar2-tree/nolines_minus.gif";  
}else{
  document.getElementById(id).style.display="none";
  document.getElementById(id_img).src="/i/ar2-tree/nolines_plus.gif";   
}

  
}

function dont_diskr_price(){
  //alert("!!");
var c = document.getElementById("checked_send_pr_email").checked;
  if(c){
      alert("Подписать на рассылку может только Ваш менеджер!");
  }
  document.getElementById("checked_send_pr_email").checked = false;
}

