var oldCSS, total_cost=0, total_rur,ps;
var fe, fp;

function doUpdateTotalCost(){
  total_rur = total_cost;
  //alert(total_cost);
  total_rur = total_rur.toString();
  total_rur = total_rur.replace(".", ",");
  ps = total_rur.indexOf(",");
  if(ps>0&&ps<total_rur.length-1) total_rur = total_rur+"0";
  else if (ps<0) total_rur = total_rur+",00";
  document.forms['orderFrm'].elements['cost_total'].value = total_rur.toString()+" р.";  
}

function decrease(what) {
  fe = document.forms['orderFrm'].elements['qty'+what];
  fp = document.forms['orderFrm'].elements['price'+what];
  td = document.all['qtytd'];
  if(fe.value!="0") {
    fe.value = parseInt(fe.value)-1;
    td.innerHTML = fe.value.toString();
    total_cost = total_cost-parseFloat(fp.value);
  }
  doUpdateTotalCost();
}

function increase(what) {
  fe = document.forms['orderFrm'].elements['qty'+what];
  fp = document.forms['orderFrm'].elements['price'+what];
  td = document.all['qtytd'];
  fe.value = parseInt(fe.value)+1;
  total_cost = total_cost+parseFloat(fp.value);
  td.innerHTML = fe.value.toString();
  doUpdateTotalCost();
}

function doHighlight(what, color){
  oldCSS = what.style.cssText;
  what.style.cssText = "background-color: "+color;
}

function doBlur(what){
  what.style.cssText = oldCSS;
}

function openCartWindow(url){ 
  if(url=="") url = dp+'cart/';
  if(url=="!") url = "";
  window.open(url, 'cart', 'width=650, height=350, scrollbars=yes, resizable=yes');
}

function doAddToCart(id, params){
  doUpdateTotalCost();
  if(total_cost==0) alert("Пожалуйста выберите хотя бы одну позицию для добавления в корзину!");
  else {
    document.forms['orderFrm'].elements['a1'].value = "add";
    openCartWindow("!");
    document.forms['orderFrm'].submit();
  }
}
