function purchase (id,code,descrip,price)
  {
  this.nid=id;
  this.scode=code;
  this.sdescription = descrip;
  this.nprice=price;
  this.ncount=1;
  }


function delElement (lista,pos)
  {
  var lista2=new Array();
  if (isNaN(lista.length))
      {totallista=0;}
  else
      {totallista=lista.length;}
  var y=0;
  for (varx=0;x<totallista;x++)
      {
      if (x!=pos)
          {
          lista2[y]=lista[x];
          y++;
          }
      }
  return lista2;
  }

function givemePositionforPurchase (objpur)
  {
  var totalP=this.totalPurchases();
  var x=(this.lstbas[0]) ? 0:totalP;
  var found=false;
  while (x<totalP && !found)
      {
      if (this.lstbas[x])
          {
          if (objpur.nid!=this.lstbas[x].nid)
              {
              x++;

              }
          else
              {found=true;}
          }
      }
  return x;
  }
function addPurchase(objpur)
  {
  var totalP=this.totalPurchases();
  var posp;
  if (totalP>0)
      {
      posp=this.purchasePos (objpur);
      if (posp<totalP)
          {
          objpur.ncount=this.lstbas[posp].ncount+1;
          totalP=posp;
          }
      }
  this.lstbas[totalP]=objpur;
  this.lastModified=totalP;
      }

function modPurchase(objpur)
  {
  var totalP=this.totalPurchases();
  var posp;
  if (totalP>0)
      {
      posp=this.purchasePos (objpur);
      if (posp<totalP)
          {
          totalP=posp;
          }
      }
  this.lstbas[totalP]=objpur;
  this.lastModified=totalP;
      }

function delPurchase(objpur)
  {
  this.lstbas=delElement (this.lstbas,this.purchasePos (objpur));
  }

function givemeTotalPurchases ()
  {
  if (isNaN (this.lstbas.length))
      {
      return 0;
      }
  else
      {
      return this.lstbas.length;
      }
  }
function getElement (pos)
  {
  if (this.totalPurchases()>pos)
      {
      return this.lstbas[pos];
      }

  }
function clearList ()
  {
  this.lstbas=new Array();
  }
function basket () {
  this.add = addPurchase;
  this.del = delPurchase;
  this.totalPurchases=givemeTotalPurchases;
  this.purchasePos=givemePositionforPurchase;
  this.get=getElement;
  this.clear=clearList;
  this.lastModified=0
  this.clear();
}
