The productdetailform.asp page is posted to with the id for the item posted as 'search' according to the rsVersionBuy recordset.
The add to cart server behavior is making use of this same rsVersionBuy recordset. From what I can tell when you add to the cart you are submitting the add to cart form, but there is no search form element with the id in it.
So I think that you are not correctly filtering this rsVersionBuy recordset after the add to cart button is submitted. I think that if you added a form element with the name of search and set it to the id of the item it would work correctly. You could do this by copying the ysl_1_ID_Add element that is on line 598 and update the name.