When the judgment or order is reversed or modified, the reviewing court may direct that the parties be returned so far as possible to the positions they occupied before the enforcement of or execution on the judgment or order. In doing so, the reviewing court may order restitution on reasonable terms and conditions of all property and rights lost by the erroneous judgment or order, so far as such restitution is consistent with rights of third parties and may direct the entry of a money judgment sufficient to compensate for property or rights not restored. The reviewing court may take evidence and make findings concerning such matters or may, by order, refer such matters to the trial court for determination.