Svetoslav,
I actually was checking out this site for resolves to something I had and found your question. I solved this problem simply using SharePoint.
In SP, I created a List called "Counter." To the list, I added two columns. "Count" and "Check" both are "Single line of text" types. Their default value is "y." I made "count" required. Then I went ot the view in Sharepoint and modified the view to include these two columns. In the view, chose the count verision "count (linked to item with edit menu). " The ID is autogenerating.
In InfoPath, i created a text box and through a dataconnection I told it to look to the list and tell me what the highest number is and to add one. The actual Formula that goes in the IP under the data tab for that text box is "max(@ID) + 1" Also, make sure you click the box in InfoPath "update the value when the result of the formula is recalculated.
It works for me, but if you have any issues, you can contact me. I'll walk you though it.