var aMasDetail= new Array();
function TestCode(sBuf)
{
var sTestStr='1234567890';
max=sBuf.length;
var sBufNew="";
for(var i=0;i<max;i++)
{
chek=sBuf.substr(i,1);
control=0;
for(j=0;j<sTestStr.length;j++)
{
chek2=sTestStr.substr(j,1);
if(chek==chek2)
{
control=1;
j=sTestStr.length;
}
}
if(control==1)
{
sBufNew+=chek;
}
}
if(sBufNew.length>20)
sBufNew=sBufNew.substr(0,20);
return sBufNew;
}
function onTest()
{
var sBuf=$('nCol');
sBuf.value=TestCode(sBuf.value);
}
//----------------------------------------------
function SelVendor(nID)
{
var bpNode=$('node');
var bpDevice=$('device');
var nSelNode='';
for(var i=0;i<bpNode.options.length;i++)
{
if(bpNode.options[i].selected==true)
nSelNode=bpNode.options[i].value;
}
bpNode.options.length=0;
//var nCols=0;
//alert(aMasNode[0][0]);
var sFlag=0;
for(var j=0;j<aMasNode.length;j++)
for(var i=0;i<aMasDetail.length;i++)
{
if((aMasNode[j][0]==aMasDetail[i][2] && aMasDetail[i][1]==nID) || nID=="")
{
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = aMasNode[j][1];
newHouseListOption.value = aMasNode[j][0];
if(navigator.appName=="Netscape"){bpNode.add(newHouseListOption,null);}
else bpNode.add(newHouseListOption);
if(nSelNode=="" || sFlag==0){nSelNode=aMasNode[j][0];sFlag=1;}
//nCols++;
j++;
}
}
bpDevice.options.length=0;
var nCols=0;
for(var i=0;i<aMasDetail.length;i++)
{
if((aMasDetail[i][1]==nID || nID=="") && (nSelNode==aMasDetail[i][2] || nSelNode==""))
{
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = aMasDetail[i][0]+' - '+aMasDetail[i][4];
newHouseListOption.value = aMasDetail[i][0];
if(navigator.appName=="Netscape"){bpDevice.add(newHouseListOption,null);}
else bpDevice.add(newHouseListOption);
nCols++;
}
}
if(nCols==0)
{
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = "--нет устройств--";
newHouseListOption.value = "";
if(navigator.appName=="Netscape"){bpDevice.add(newHouseListOption,null);}
else bpDevice.add(newHouseListOption);
}
}
function SelNode(nID)
{
var bpVendor=$('vendor');
var bpDevice=$('device');
var nSelVendor='';
for(var i=0;i<bpVendor.options.length;i++)
{
if(bpVendor.options[i].selected==true)
nSelVendor=bpVendor.options[i].value;
}
bpDevice.options.length=0;
var nCols=0;
for(var i=0;i<aMasDetail.length;i++)
{
if((aMasDetail[i][2]==nID || nID=="") && (nSelVendor==aMasDetail[i][1] || nSelVendor==""))
{
/*var nColse=0;
nIDdet=aMasDetail[i][0];
for(var j=0;j<aMasDetail.length;j++)
if((aMasDetail[i][1]==nID || nID=="") && (nSelNode==aMasDetail[i][2] || nSelNode==""))
{nColse++;}
*/
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = aMasDetail[i][0]+' - '+aMasDetail[i][4];
newHouseListOption.value = aMasDetail[i][0];
if(navigator.appName=="Netscape"){bpDevice.add(newHouseListOption,null);}
else bpDevice.add(newHouseListOption);
nCols++;
}
}
if(nCols==0)
{
var newHouseListOption = document.createElement("OPTION");
newHouseListOption.text = "--нет устройств--";
newHouseListOption.value = "";
if(navigator.appName=="Netscape"){bpDevice.add(newHouseListOption,null);}
else bpDevice.add(newHouseListOption);
}
}
//---------------------------------------------------------------
function AddBasket()
{
var bpDevice=$('device');
var bpCol=$('nCol');
var bpPrise=$('nPrise');
var bpChesk=$('nChesk');
var nSelDevice="";
for(var i=0;i<bpDevice.options.length;i++)
{
if(bpDevice.options[i].selected==true)
nSelDevice=bpDevice.options[i].value;
}
var nMas="";
if(nSelDevice!="")
{
for(var i=0;i<aMasDetail.length;i++)
{
if(aMasDetail[i][0]==nSelDevice)nMas=i;
}
}
var sError="";
if(nSelDevice==""){sError+="Утройство не выбрано\n";}
if(bpCol.value.length<1){sError+="Количество не задано\n";}
if(nMas=="" && nSelDevice!=""){sError=sError+"Утройство не найдено\n";}
if(sError.length<1)
{
if(aMasDetail[nMas]!=null)DelUnit(aMasDetail[nMas][0]);
var nLen=aMasBasket.length;
aMasBasket[nLen]= new Array();
aMasBasket[nLen][0]=aMasDetail[nMas][0];
aMasBasket[nLen][1]=bpCol.value;
aMasBasket[nLen][2]=bpPrise.value;
aMasBasket[nLen][3]=aMasDetail[nMas][7];
var bpBase=$('basket');
var bpDiv=$ce('div');
bpDiv.setAttribute('id',aMasDetail[nMas][0]);
var sInner='<table>';
sInner+='<tr>';
sInner+=' <td width="500" bgcolor="#cccccc">'+aMasDetail[nMas][0]+' - '+aMasDetail[nMas][6]+', '+aMasDetail[nMas][5]+', '+aMasDetail[nMas][4]+' </td>';
sInner+=' <td bgcolor="#cccccc" width="75"> '+bpCol.value+' шт.</td>';
sInner+=' <td bgcolor="#cccccc" width="75"> '+bpPrise.value+' грн.</td>';
if(aMasBasket[nLen][3]=='1')sInner+=' <td bgcolor="#cccccc" width="75">с серийным номером</td>';
else sInner+=' <td bgcolor="#cccccc" width="75">без серийного номера</td>';
sInner+=' <td><input type="button" value="Удалить" onclick="DelUnit('+aMasDetail[nMas][0]+')" class="button"></td>';
sInner+='</tr></table>';
bpDiv.innerHTML=sInner;
bpBase.appendChild(bpDiv);
//alert(aMasDetail[nMas][4]);
}
else
{
alert("Ошибка (и) : \n"+sError);
}
}
function DelUnit(nID)
{
var bpBase=$('basket');
var bpDiv=$(nID);
if(bpDiv!=null)
{
bpBase.removeChild(bpDiv);
for(var i=0;i<aMasBasket.length+1;i++)
if(aMasDetail[i][0]==nID)
{
aMasBasket[i][0]=aMasBasket[aMasBasket.length][0];
aMasBasket[i][1]=aMasBasket[aMasBasket.length][1];
aMasBasket[i][2]=aMasBasket[aMasBasket.length][2];
aMasBasket[i][3]=aMasBasket[aMasBasket.length][3];
}
aMasBasket.length--;
}
}
//----------------------------------
function Save()
{
if(aMasBasket.length>0)
{
//alert(aMasBasket.length);
var sComment=$('nKoment').value;
var sURL="add_sklad_save.php?nCol="+aMasBasket.length+"&scoment="+encodeURIComponent(sComment);
for(var i=0;i<aMasBasket.length;i++)
{
sURL+='&a'+i+'='+aMasBasket[i][0];
sURL+='&b'+i+'='+aMasBasket[i][1];
sURL+='&k'+i+'='+aMasBasket[i][2];
sURL+='&s'+i+'='+aMasBasket[i][3];
}
_new.action=sURL;
_new.method="POST";
_new.submit();
}
else
{
alert('Сначала нужно добавить устройства');
}
}