function CalculateDiscountPrice($price, $discountprice, $categoryid, $seriesid)
{
    //Added by Simha for onsale addition
    $Rules = GetRuleModuleInfo();
    foreach ($Rules as $Rule) {
        if (isset($Rule['catids'])) {
            $discountprice = CalculateCatBasedDiscount($Rule, $price, $discountprice, $categoryid);
        } elseif (isset($Rule['seriesids'])) {
            $discountprice = CalculateSeriesBasedDiscount($Rule, $price, $discountprice, $seriesid);
        }
        /*if($discountprice < $price)    {
               return $discountprice;
          } */
    }
    return $discountprice;
}
function CalculateDiscountPrice($price, $discountprice, $categoryid, $seriesid, &$discountpolicy = 0)
{
    //Added by Simha for onsale addition
    $Rules = $GLOBALS['DiscountRules'];
    foreach ($Rules as $Rule) {
        if ((double) $price >= (double) $Rule['minprice']) {
            if (isset($Rule['catids'])) {
                $discountprice = CalculateCatBasedDiscount($Rule, $price, $discountprice, $categoryid, $discountpolicy);
            } elseif (isset($Rule['seriesids'])) {
                $discountprice = CalculateSeriesBasedDiscount($Rule, $price, $discountprice, $seriesid, $discountpolicy);
            }
            if ($discountprice < $price) {
                return $discountprice;
            }
        }
    }
    return $discountprice;
}