function qem_process_payment_form($values)
{
    $payments = qem_get_stored_payment();
    global $post;
    $page_url = qem_current_page_url();
    $reference = $post->post_title;
    $paypalurl = 'https://www.paypal.com/cgi-bin/webscr';
    $cost = get_post_meta($post->ID, 'event_cost', true);
    $cost = preg_replace('/[^.0-9]/', '', $cost);
    $quantity = $values['yourplaces'] < 1 ? 1 : strip_tags($values['yourplaces']);
    $redirect = get_post_meta($post->ID, 'event_redirect', true);
    if (!$redirect && $register['redirectionurl']) {
        $redirect = $register['redirectionurl'];
    }
    $redirect = $redirect ? $redirect : $page_url;
    if ($payments['useprocess'] && $payments['processtype'] == 'processpercent') {
        $percent = preg_replace('/[^.,0-9]/', '', $payments['processpercent']) / 100;
        $handling = $cost * $quantity * $percent;
    }
    if ($payments['useprocess'] && $payments['processtype'] == 'processfixed') {
        $handling = preg_replace('/[^.,0-9]/', '', $payments['processfixed']);
    }
    if ($payments['usecoupon']) {
        $coupon = qem_get_stored_coupon();
        for ($i = 1; $i <= 10; $i++) {
            if ($values['couponcode'] == $coupon['code' . $i]) {
                if ($coupon['coupontype' . $i] == 'percent' . $i) {
                    $cost = $cost - $cost * $coupon['couponpercent' . $i] / 100;
                }
                if ($coupon['coupontype' . $i] == 'fixed' . $i) {
                    $cost = $cost - $coupon['couponfixed' . $i];
                }
            }
        }
    }
    $content = '<h2 id="qem_reload">' . $payments['waiting'] . '</h2>
    <form action="' . $paypalurl . '" method="post" name="qempay" id="qempay">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="item_name" value="' . $reference . '"/>
    <input type="hidden" name="business" value="' . $payments['paypalemail'] . '">
    <input type="hidden" name="return" value="' . $redirect . '">
    <input type="hidden" name="cancel_return" value="' . $page_url . '">
    <input type="hidden" name="currency_code" value="' . $payments['currency'] . '">
    <input type="hidden" name="item_number" value="' . strip_tags($values['yourname']) . '">
    <input type="hidden" name="quantity" value="' . $quantity . '">
    <input type="hidden" name="amount" value="' . $cost . '">
    <input type="hidden" name="custom" value="' . $values['ipn'] . '">';
    if ($payments['useprocess']) {
        $content .= '<input type="hidden" name="handling" value="' . $handling . '">';
    }
    $content .= '</form>
    <script language="JavaScript">document.getElementById("qempay").submit();</script>';
    return $content;
}
function qem_category_key($cal, $style, $calendar)
{
    $cat = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
    $arr = get_categories();
    $display = event_get_stored_display();
    $pageurl = qem_current_page_url();
    $parts = explode("&", $pageurl);
    $pageurl = $parts['0'];
    $link = strpos($pageurl, '?') ? '&' : '?';
    if ($style['linktocategories']) {
        $catkey = '<style>.qem-category:hover {background: #CCC !important;border-color: #343848 !important;}.qem-category a:hover {color:#383848 !important;}</style>' . "\r\n";
    }
    $catkey .= $calendar ? '<p><span class="qem-caption">' . $cal['keycaption'] . '</span>' : '<p><span class="qem-caption">' . $style['keycaption'] . '</span>';
    if ($cal['linktocategories'] && $display['back_to_url'] && $style['catallevents']) {
        $bg = $style['date_background'] == 'color' ? $style['date_backgroundhex'] : $style['date_background'];
        $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $style['date_border_colour'] . ';background:' . $bg . '"><a style="color:' . $style['date_colour'] . '" href="' . $display['back_to_url'] . '">' . $style['catalleventscaption'] . '</a></span>';
    }
    foreach ($cat as $i) {
        foreach ($arr as $option) {
            if ($cal['cat' . $i] == $option->slug) {
                $thecat = $option->name;
            }
        }
        if ($cal['cat' . $i]) {
            if ($calendar) {
                if ($cal['linktocategories']) {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $cal['cat' . $i . 'text'] . ';background:' . $cal['cat' . $i . 'back'] . '"><a style="color:' . $cal['cat' . $i . 'text'] . '" href="' . $pageurl . $link . 'category=' . $thecat . '">' . $thecat . '</a></span>';
                } else {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $cal['cat' . $i . 'text'] . ';background:' . $cal['cat' . $i . 'back'] . ';color:' . $cal['cat' . $i . 'text'] . ';">' . $thecat . '</span>';
                }
                if ($cal['showuncategorised']) {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $style['date_border_colour'] . ';">Uncategorised</span>';
                }
            } else {
                if ($style['linktocategories']) {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $cal['cat' . $i . 'back'] . ';"><a href="' . $pageurl . $link . 'category=' . $thecat . '">' . $thecat . '</a></span>';
                } else {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $cal['cat' . $i . 'back'] . ';">' . $thecat . '</span>';
                }
                if ($style['showuncategorised']) {
                    $catkey .= '<span class="qem-category" style="border:' . $style['date_border_width'] . 'px solid ' . $style['date_border_colour'] . ';">Uncategorised</span>';
                }
            }
        }
    }
    $catkey .= '</p><div style="clear:left;"></div>' . "\r\n";
    return $catkey;
}