function FormatNumberBy3(num, decpoint, sep) 
     {
      // check for missing parameters and use defaults if so
      if (arguments.length == 2) {
        sep = ",";
      }
      if (arguments.length == 1) {
        sep = ",";
        decpoint = ".";
      }
      // need a string for operations
      num = num.toString();
      // separate the whole number and the fraction if possible
      a = num.split(decpoint);
      x = a[0]; // decimal
      y = a[1]; // fraction
      z = "";


      if (typeof(x) != "undefined") {
        // reverse the digits. regexp works from left to right.
        for (i=x.length-1;i>=0;i--)
          z += x.charAt(i);
        // add seperators. but undo the trailing one, if there
        z = z.replace(/(\d{3})/g, "$1" + sep);
        if (z.slice(-sep.length) == sep)
          z = z.slice(0, -sep.length);
        x = "";
        // reverse again to get back the number
        for (i=z.length-1;i>=0;i--)
          x += z.charAt(i);
        // add the fraction back in, if it was there
        if (typeof(y) != "undefined" && y.length > 0)
          x += decpoint + y;
      }
      return x;
    }
    
    function  ChangeC(ProductID)
     {
         if (document.getElementById("p"+ProductID).value != "")
         {
             if (!isPozNum(document.getElementById("p"+ProductID).value) || document.getElementById("p"+ProductID).value>99)  
             {
                alert("Va rugam introduceti date valide:\n - cantitatea trebuie sa fie un numar intreg pozitiv mai mic decat 99.");
                document.getElementById("p"+ProductID).value=1; 
             }
               
             result = Agora.Site.CosCumparaturi.cosCumparaturi.Change(ProductID,document.getElementById("p"+ProductID).value); 
             if(result!=null && result.value!=null)
             {
                var nr1=result.value.Price;
                nr1 = nr1.toFixed(2);
                nr1=FormatNumberBy3(nr1.toString().replace(".",","),",",".");
                document.getElementById("price"+ProductID).innerHTML=nr1+" RON";
                var nr2=result.value.PriceOld;
                nr2 = nr2.toFixed(2);
                nr2=FormatNumberBy3(nr2.toString().replace(".",","),",",".");
                document.getElementById("priceO"+ProductID).innerHTML=nr2+" RON";
                var nr=result.value.Price*document.getElementById("p"+ProductID).value;
                nr = nr.toFixed(2);
                nr=FormatNumberBy3(nr.toString().replace(".",","),",",".");
                document.getElementById("priceTp"+ProductID).innerHTML=nr+" RON";
             }         
         }
     }

     function removeProduct(ProductID)
     {
      // alert(ProductID);
       var tbody = document.getElementById("tbShoppingList").getElementsByTagName("tbody")[0];
       var r = tbody.rows.length;   
       tbody.deleteRow(document.getElementById("row"+ProductID).rowIndex);
       rows=tbody.rows.length;
//      // alert(rows);
//      // try{
//     //  var result = Agora.Site.CosCumparaturi.cosCumparaturi.RemoveProduct(ProductID.toString());
//      // }
//       catch(err)
//       {
         document.getElementById("hID").value=ProductID;
         document.getElementById("hAction").value="stergere";
         document.getElementById("frmMain").submit();
//       }
      if(rows<=5)
      {
         document.getElementById("DivMare").style.display="none";
         tbody.style.display="none";
         document.getElementById("DivMic").style.display="block";
      }
        
     }
     
   function ChangeA()
   {
      
      if(document.getElementById("hIDs")!="")
      {
           //alert(document.getElementById("hIDs").value);
           var ids=document.getElementById("hIDs").value.split(',');
           var i=0; 
           var p="p";
           document.getElementById("hSir").value="";
           var err="";
           while(i<ids.length && document.getElementById(p+ids[i]))
           {
             if(document.getElementById(p+ids[i]).value!="" && isPozNum(document.getElementById(p+ids[i]).value))
             {          document.getElementById("hSir").value+='|'+ids[i]+'&'+document.getElementById(p+ids[i]).value;}
             else { 
                       err="Cantitatile trebuie sa fie numere pozitive.";
              }
             i++;
           }
           
          // alert(document.getElementById("hSir").value);
          if(err!="")
          {
             alert(err);
          }
          else
          {document.getElementById("hAction").value="actualizare";
           document.getElementById("frmMain").submit();
           }
      }
   }  

 function Go()
 {
   document.getElementById("hGo").value="go";
   ChangeA();
  
 }
