function useSubPrice(id,g,n){	//disabled связанных цен
 var obj,objO,objI;
 obj=document.getElementById("RadioPrice["+id+"]"+(g!="" ? "["+g+"]" : ""));
 if(obj && obj!=undefined && obj!=''){
  var ds=obj.checked ? 0 : 1;
  if(n>0){	//checkbox
   for(i=0;i<n;i++){
    objO=document.getElementById("subPrice["+id+"]"+(g!="" ? "["+g+"]" : "")+"["+i+"]");
    if(objO && objO!=undefined && objO!='')
     objO.disabled = ds==1 ? true : false;
   }//for
  }else{	//other
   objO=document.getElementsByName("subPrice["+id+"]"+(g!="" ? "["+g+"]" : ""));
   if(objO && objO!=undefined && objO!=''){
    var l=objO.length;
    if(l>1){
     for(i=0;i<l;i++)
      objO[i].disabled = ds==1 ? true : false;
    }else{
     objI=document.getElementById("subPrice["+id+"]"+(g!="" ? "["+g+"]" : ""));
     if(objI && objI!=undefined && objI!='')
      objI.disabled = ds==1 ? true : false;
    }
   }
  }//n
 }//obj
}

function HOLevel(id){
var objO=document.getElementById("OpenLevel"+id);
if(objO!=undefined && objO!='')
if(objO.style.display=='none')
objO.style.display='';
else
objO.style.display='none';

var objH=document.getElementById("HiddenLevel"+id);
if(objH!=undefined && objH!='')
if(objH.style.display=='none')
objH.style.display='';
else
objH.style.display='none';
return false;
}

function CalcPriceGroup(listG,gr,name){
var priceV,j,sz,arr,o;
priceV=0;
if(listG!=undefined && listG!=""){
 s=listG.value;
 if(s!=undefined && s!=""){
  arr=s.split(",");
  sz=arr.length;
  for(j=0;j<sz;j++){
   o=document.getElementById(name+"["+gr+"]["+arr[j]+"]");
   if(o!=undefined && o!=""){
    priceV+=o.value*1;
   }
  }//for
 }
}
return priceV;
}

//Поверка на допустимость ввода значения в поле. Оно д.б. не больше установленного значения
function CheckMultiply(field,val,cnst){
 val=val*1;
 if(val==undefined || val>cnst){
  field.value=cnst;
  field.focus();
 }
 return false;
}

//Подсчет количества заказанных позиций
function calcAmount(){
 var n=0;
 var gr=document.getElementById("GroupInPrice");
 if(gr!="" && gr!=undefined){
  var e=gr.value.split(",");
  var l=e.length;
  for(i=0;i<l;i++){
   var gr1=document.getElementById("ListGroup["+e[i]+"]");
   if(gr1!="" && gr1!=undefined){
    var e1=gr1.value.split(",");
    var l1=e1.length;
    for(j=0;j<l1;j++){
     var v=document.getElementById("SumLine["+e[i]+"]["+e1[j]+"]");
     if(v!="" && v!=undefined){
      if(v.value>0) n++;
     }
    }
   }
  }//for i
 }
 return n;
}


//Пересчет сумм прайса
function HOCalcSum(gr,obj,prandm,field,disc){
//prandm - список идентификаторов цен и множителей (цена1 . множитель1 ; ... ; ценаN . множительN)
var l,fld,o,s,arr,p,objG,pS,oSp,oSs;
var priceO=0;
var pr=prandm.split(';');
var lpr=pr.length;
var l1,o1,s2;
for(i=0;i<lpr;i++){
 l1=pr[i].split('.');
 l2=0;
 if(l1[0]!=""){
  o1=document.getElementsByName('RadioPrice['+obj+']['+l1[0]+']');
  if(o1!=undefined && o1!='' && o1[0]!=undefined){
   if(o1[0].checked && o1[0].value>0){
    l2=o1[0].value;
   }
   l2=l2*1;
  }//o1
 }//l1

if(l2>0){	//цена установлена

 if(l1[1]!=""){
  o1=document.getElementsByName('MultiplyPR['+obj+']['+l1[1]+']');
  if(o1!=undefined && o1!='' && o1[0]!=undefined){
   if(o1[0].value>0){

  if(l1[2] && l1[2]!=undefined && l1[2]!=""){
    oSp=document.getElementById("subPrice["+obj+"]["+l1[0]+"]");
    if(oSp!=undefined && oSp!=""){	//select, radio
     if(oSp.type=="radio")
      oSp=document.getElementsByName("subPrice["+obj+"]["+l1[0]+"]");

     if(oSp.length>0){
      for(k=0;k<oSp.length;k++){
       if((oSp[k].selected || oSp[k].checked) && oSp[k].value!=""){
        oSs=oSp[k].value.split("-");
        if(oSs[1] && oSs[1]!=undefined && oSs[1]!="")
         priceO+=oSs[1]*1*o1[0].value;	//каждая связ.цена * на множитель
       }
      }//for
     }
    }else{	//checkbox
     for(k=0;k<20;k++){
      oSp=document.getElementsByName("subPrice["+obj+"]["+l1[0]+"]["+k+"]");
      if(oSp!=undefined && oSp!="" && oSp[0]!=undefined && oSp[0]!=""){
       if(oSp[0].checked && oSp[0].value!=""){
        oSs=oSp[0].value.split("-");
        if(oSs[1] && oSs[1]!=undefined && oSs[1]!="")
         priceO+=oSs[1]*1*o1[0].value;	//каждая связ.цена * на множитель
       }
      }
     }//for
    }

  }else
    priceO+=l2*o1[0].value;
   }
  }//o1
 }else{

  if(l1[2] && l1[2]!=undefined && l1[2]!=""){
    oSp=document.getElementById("subPrice["+obj+"]["+l1[0]+"]");
    if(oSp!=undefined && oSp!=""){
     if(oSp.type=="radio")
      oSp=document.getElementsByName("subPrice["+obj+"]["+l1[0]+"]");

     if(oSp.length>0){
      for(k=0;k<oSp.length;k++){
       if((oSp[k].selected || oSp[k].checked) && oSp[k].value!=""){
        oSs=oSp[k].value.split("-");
        if(oSs[1] && oSs[1]!=undefined && oSs[1]!="")
         priceO+=oSs[1]*1;
       }
      }//for
     }
    }else{	//checkbox
     for(k=0;k<20;k++){
      oSp=document.getElementsByName("subPrice["+obj+"]["+l1[0]+"]["+k+"]");
      if(oSp!=undefined && oSp!="" && oSp[0]!=undefined && oSp[0]!=""){
       if(oSp[0].checked && oSp[0].value!=""){
        oSs=oSp[0].value.split("-");
        if(oSs[1] && oSs[1]!=undefined && oSs[1]!="")
         priceO+=oSs[1]*1;
       }
      }
     }//for
    }

  }else
   priceO+=l2*1;
 }//l1

}//l2

}//for

var sumO=document.getElementById("CellLine"+obj);
var sumH=document.getElementsByName("SumLine["+gr+"]["+obj+"]");

//множители
 if(field!=""){
  fld=field.split(',');
  l=fld.length;
 }else
  l=0;
 var priceV=priceO;
 if(priceV!=undefined && priceV>0){
  if(l>0){
   for(i=0;i<l;i++){
    o=document.getElementsByName(fld[i]);
    if(o!=undefined && o!=""){
     priceV*=o[0].value;
    }
   }//for
  }//l
 }//priceV

//Сумма без скидки
if(priceV==undefined || priceV=='' || priceV<=0)
 priceV=0;
else{
 priceV=priceV.toFixed(0);
 priceV*=1;
}

if(sumH!=undefined && sumH!='' && sumH[0]!=undefined && sumH[0]!='')
 sumH[0].value=priceV;
if(sumO!=undefined && sumO!='')
 sumO.innerHTML=priceV;


if(gr>0){
//Сумма со скидкой
if(disc>0 && disc<1)
 priceV*=disc;
if(priceV>0){
 priceV=priceV.toFixed(0);
 priceV*=1;
}

var sumD=document.getElementsByName("SumLineWTH["+gr+"]["+obj+"]");
var sumOD=document.getElementById("CellLineWTH"+obj);
if(sumD!=undefined && sumD!='' && sumD[0]!=undefined && sumD[0]!=''){
 sumD[0].value=priceV;
 sumOD.innerHTML=priceV;
}

//список ID элементов текущей группы
var listG=document.getElementById("ListGroup["+gr+"]");
priceV=0;
priceV=CalcPriceGroup(listG,gr,'SumLine');
var celG=document.getElementById("CellGroup"+gr);
if(celG!=undefined && celG!=""){
 if(priceV>0)
  priceV=priceV.toFixed(0);
 celG.innerHTML=priceV;
}

//Установка сумм СО СКИДКОЙ для текущей группы объектов
//var listG=document.getElementById("ListGroupWTH["+gr+"]");
priceV=0;
priceV=CalcPriceGroup(listG,gr,'SumLineWTH');
var celG=document.getElementById("CellGroupWTH"+gr);
if(celG!=undefined && celG!=""){
 if(priceV>0)
  priceV=priceV.toFixed(0);
 celG.innerHTML=priceV;
}

//Установка сумм для Прайса в целом
priceV=0;
priceD=0;
var listT=document.getElementById("GroupInPrice");
if(listT!=undefined && listT!=""){
 s=listT.value;
 if(s!=undefined && s!=""){
  arr=s.split(",");
  l=arr.length;
  for(i=0;i<l;i++){
   objG=document.getElementById("ListGroup["+arr[i]+"]");
   p=CalcPriceGroup(objG,arr[i],'SumLine');
   priceV+=p;

   p=CalcPriceGroup(objG,arr[i],'SumLineWTH');
   priceD+=p;

  }//for
 }
}
//Установка сумм СО СКИДКОЙ для Прайса в целом
var celP=document.getElementById("CellPriceWTH");
if(celP!=undefined && celP!="")
 celP.innerHTML=priceD.toFixed(0);

}//gr

//кол-во заказанных позиций
var n=0;
var celN=document.getElementById("CellItems");
if(celN!=undefined && celN!=""){
 n=calcAmount();
 celN.innerHTML=n;
}

var celP=document.getElementById("CellPrice");
if(celP!=undefined && celP!=""){
 celP.innerHTML=priceV.toFixed(0);
 if(n<=0 && priceV>0) celN.innerHTML=1;
}


return false;
}

//Блокировка полей ввода множителей цен
function DisabledOnOff(i,j,v){
 var o=document.getElementsByName('MultiplyPR['+i+']['+j+']');
 if(o!=undefined && o[0]!=undefined){
  if(v){
   o[0].disabled=false;
   o[0].focus();
  }else{
   o[0].value='';
   o[0].disabled=true;
  }
 }
}



//Подсчет суммы множителей
function SumMultiply(id,num,name,par){
var vl,p,s,arr,arr2,sz,l,o;
vl=0;
var listT=document.getElementById("GroupInPrice");
if(listT!=undefined && listT!=""){
 s=listT.value;
 if(s!=undefined && s!=""){
  arr=s.split(",");
  l=arr.length;
  for(i=0;i<l;i++){
   objG=document.getElementById("ListGroup["+arr[i]+"]");
   if(objG!=undefined && objG!=""){
    s=objG.value;
    if(s!=undefined && s!=""){
     arr2=s.split(",");
     sz=arr2.length;
     for(j=0;j<sz;j++){
      if(par==1)
       o=document.getElementById("MultiplyPR["+arr2[j]+"]["+num+"]");
      else
      o=document.getElementById("MultiplyPrice["+arr2[j]+"]["+num+"]");
      if(o!=undefined && o!="")
       vl+=o.value*1;
     }//for
    }
   }//objG
  }//for
 }
}
var celP=document.getElementById("Cell_"+name);
if(celP!=undefined && celP!="")
 celP.innerHTML=vl;

return false;
}


