$BID = '';
    $bid_sql = "  ";
}
if ($_REQUEST['action'] == 'refund') {
    $t_id = $_REQUEST['transaction_id'];
    $sql = "SELECT * from transactions, orders, users where transactions.order_id=orders.order_id AND orders.user_id=users.ID and transactions.transaction_id={$t_id}";
    $result = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_array($result);
    if ($row[status] != 'completed') {
        // check that there's no other refund...
        $sql = "SELECT * FROM transactions where txn_id='" . $row['txn_id'] . "' AND type='CREDIT' ";
        $r = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($r) == 0) {
            // do the refund
            cancel_order($row[order_id]);
            credit_transaction($row[order_id], $row[price], $row[currency], $row[txn_id], 'Refund', 'Admin');
        } else {
            echo "<b>Error: A refund was already found on this system for this order..</b><br>";
        }
    } else {
        echo $row[status];
        echo "<b>Error: The system can only refund orders that are completed, please cancel the order first</b><br>";
    }
    // can only refund completed orders..
}
?>
<script language="JavaScript" type="text/javascript">

	function confirmLink(theLink, theConfirmMsg) {
       
       if (theConfirmMsg == '' || typeof(window.opera) != 'undefined') {
                    case "Pending":
                        $sql = "select user_id FROM orders where order_id='" . $invoice_id . "'";
                        $result = mysql_query($sql) or pp_mail_error(mysql_error() . $sql);
                        $row = mysql_fetch_array($result);
                        pend_order($row['user_id'], $invoice_id);
                        // pending_reason : 'address', 'echeck', 'intl', 'multi_currency', 'unilateral', 'upgrade', 'verify', 'other'
                        break;
                    case "Refunded":
                        // reason_code : 'buyer_complaint', 'chargeback', 'guarantee', 'refund', 'other'
                        cancel_order($invoice_id);
                        credit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal');
                        break;
                    case "Reversed":
                        // reason_code : 'buyer_complaint', 'chargeback', 'guarantee', 'refund', 'other'
                        cancel_order($invoice_id);
                        credit_transaction($invoice_id, $mc_gross, $mc_currency, $txn_id, $reason_code, 'PayPal');
                        break;
                    default:
                        break;
                }
                // end switch
            }
            // end web payment
        }
        // end if VERIFIED == true
    }
    // end if !$fp
}
// end IPN routine
###########################################################################
# Payment Object