
//--------------------------------------------------------------

var disStyle=0
var dom=document.getElementById||document.all

function getItem(id) {
return document.getElementById&&document.getElementById(id)? document.getElementById(id) : document.all&&document.all[id]? document.all[id] : null;
}

if(dom)
document.write('<style type="text/css" id="dummy">\
.tlink{\
display:none;\
}\
<\/style>')

if(dom&&typeof getItem('dummy').disabled=='boolean'){
document.write('<style type="text/css" id="showhide">\
.showhide{\
display:none;\
}\
#cdiv0 {\
display:block;\
}\
<\/style>');
disStyle=1;
}

function displayOne(idPrefix, idNum){
var i=0;
while (getItem(idPrefix+i)!==null){
getItem(idPrefix+i).style.display='none';
i++;
}
if (typeof idNum!=='undefined')
getItem(idPrefix+idNum).style.display='block';
}


//---------------------------------------------------------------------------
var ids = new Array();

function gel (id)
{
  if (document.getElementById)
    return document.getElementById(id);
  else if (document.all)
    return document.all[id];
  return null;
}
//---------------------------------------------------------------------------
function gel2 (id)
{
  return ids[id];
}
//---------------------------------------------------------------------------
function gtag (ctl, tag)
{
  return ctl.getElementsByTagName(tag);
}
//---------------------------------------------------------------------------
function nprod (n, d)
{
  var el = gel('prod'+n),
      val = parseInt(el.value);
  if (isNaN(val)) val = 0;
  val += d;
  if (val > 99)   val = 99;
  if (val < 0)    val = 0;
  el.value = val;
  el.style.background = el.value > 0 ? "#9aa4a6" : "#9aa4a6";
  recalc();
}
//---------------------------------------------------------------------------
function chk (n)
{
  var el = gel('prod'+n);
  if (isNaN(parseInt(el.value)))
    el.value = "0";
  el.style.background = el.value > 0 ? "#9aa4a6" : "#9aa4a6";
  recalc();
}
//---------------------------------------------------------------------------
function recalc ()
{
  var priceall = 0,
      numall = 0,
      lst = "",
      edt = gtag(document, 'input'),
      prevsec = "";
  for (var i=0; i<edt.length; ++i) {
    if (edt[i].id.substring(0, 4) == 'prod') {
      var price = parseInt(gel2(edt[i].id.replace(/prod(\d+)/, 'pr$1')).innerHTML),
          num = parseInt(edt[i].value),
          sec = gel2(edt[i].className.replace(/sum sid/, 'sec')).innerHTML;
      if (num > 0) {
        priceall += price * num;
        numall += num;
        if (sec != prevsec) {
          prevsec = sec;
          lst += "<tr><td><b>" + sec + "</b><td><td>";
        }
        lst += "<tr><td>" + edt[i].name.replace(/^\d+\|/, '') + "<td  align='center'>" + num + "л<td  align='center'><font color='#d81f2a'>" + price + "</font>";
      }
    }
  }
  gel('price').innerHTML = priceall;
  if (priceall)
    lst += "<tr><td class='order_bottom' colspan='3'>Итого: <font color='#d81f2a'>" + priceall + "</font> р. + доставка <font color='#d81f2a'>250</font> р.";
  gel('list').innerHTML = lst == "" ? "<p align='center'><b>Вы еще ничего не заказали</b>" :
      "<table width='100%' cellpadding='0' cellspacing='0'><tr><td class='order_top'>Ваш заказ<td  align='center' class='order_top'>Кол-во<td  align='center' class='order_top'>Цена" +
      lst +
      "<\/table>";
}
//---------------------------------------------------------------------------

function approve_order ()
{

  var code = parseInt(gel('phone_code').value).toString();
  var num  = parseInt(gel('phone_num').value).toString();
  var price = parseInt(gel('price').innerHTML);
  var err = "";

  if (price == 0) {
    err += "\nВы ничего не заказали.";
  }
  else if (num == "" || isNaN(parseInt(num)) || num.length < 7) {
    err += "\nВы не указали или ввели неверно номер телефона.";
  }
   if (err != "") {
    alert(err.substring(1));
   }
  return err == "";
}
//---------------------------------------------------------------------------
function reset_order ()
{
  if (confirm('Вы уверены что хотите отменить заказ?')) {
    var edt = gtag(document, 'input');
    for (var i=0; i<edt.length; ++i)
      if (edt[i].id.substring(0, 4) == 'prod')
        edt[i].value = "0";
  }
  recalc();
  return false;
}
//---------------------------------------------------------------------------
function init ()




{

displayOne('cdiv', 0);
if (disStyle)
getItem('showhide').disabled=true;


  var edt = gtag(document, 'input');
  for (var i=0; i<edt.length; ++i) {
    if (edt[i].id.substring(0, 4) == 'prod') {
      ids[edt[i].id.replace(/prod(\d+)/, 'pr$1')] = gel(edt[i].id.replace(/prod(\d+)/, 'pr$1'));
      ids[edt[i].className.replace(/sum sid/, 'sec')] = gel(edt[i].className.replace(/sum sid/, 'sec'));
    }
  }

  var b = gel('wrapper'),
      b1 = gel('header'), b2 = gel('content'), b3 = gel('footer');
  var h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
//-  if (b.offsetHeight < h)
//-  {
//-    b.style.height = h+'px';
//-    b2.style.height = (b.offsetHeight-b1.offsetHeight-b3.offsetHeight-20)+'px';
//-  }
//-  document.body.style.fontSize = 'medium';
//-  document.body.style.fontSize = '';
}




//---------------------------------------------------------------------------

