Light Up Alberni

This node isUnpublished
<?php
if (isset($_GET['return'])) {
  $return= $_GET['return'];
    if ($return == 'vote') {
      drupal_set_message(t("Thank you! Your vote is being processed."));
   }
}

    $month = format_date( time(), 'custom', 'M');
    if ($month === 'Nov' || $month === 'Dec') {
       $webform= module_invoke('webform', 'block_view', 'client-block-3171');
    }
?>

    <div class="accordion">
        <a href="javascript:void(0)" class="button" for="paypal-form">
    Register My Place
    <span class="money">($20 Fee)</span>
  </a>

        <?php if (isset($webform)): ?>
            <a href="javascript:void(0)" class="button" for="vote">
                <div>Vote for My Favorities <span style="font-weight: normal;"></span></div>
            </a>
        <?php endif; ?>
        <div class="content-wrapper">
            <?php if (isset($webform)): ?>
                <div class="content" id="vote">
                    <?php  echo render($webform['content']); ?>
                </div>
            <?php endif; ?>
            <div class="content" id="paypal-form">
                <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" class="register-form" onsubmit="autoFill(this)">

                    <!-- Identify your business so that you can collect the payments. -->
                    <input type="hidden" name="business" value="info@albernichamber.ca">

                    <!-- Specify a Buy Now button. -->
                    <input type="hidden" name="cmd" value="_xclick">

                    <input type="hidden" name="item_name" value='"Light Up" Registration Fee'>
                    <input type="hidden" name="amount" value="20">
                    <input type="hidden" name="currency_code" value="CAD">

                    <div class="form-item name">
                        <label>
                            <input type="hidden" name="on0" value="Name">Full Name:</label>
                        <input type="text" name="os0" maxlength="60" required>
                    </div>

                    <div class="form-item email">
                        <label>
                            <input type="hidden" name="on1" value="Email">Email:</label>
                        <input type="email" name="os1" maxlength="60" required>
                    </div>

                    <div class="form-item phone">
                        <label>
                            <input type="hidden" name="on2" value="Phone">Phone Number:</label>
                        <input type="text" name="os2" maxlength="60" oninput="return telMask(this)" required>
                    </div>

                    <div class="form-item address">
                        <label>
                            <input type="hidden" name="on3" value="Street Address">Street Address:</label>
                        <input type="text" name="os3" maxlength="60" required>
                    </div>

                    <!-- Not used -->
                    <div class="form-item readonly">
                        <label>City:</label>
                        <input type="text" disabled value="Port Alberni, BC" required>
                    </div>

                    <div class="form-item postal">
                        <label>
                            <input type="hidden" name="on4" value="Postal Code">Postal Code:</label>
                        <input type="text" name="os4" maxlength="60" required>
                    </div>

                    <div class="form-item type">
                        <label>
                            <input type="hidden" name="on5" value="Type">Type:</label>
                        <select name="os5">
                            <option value="Business">Business</option>
                            <option value="Home">Home</option>
                        </select>
                    </div>

                    <!-- Auto Fill -->
                    <input type="hidden" name="first_name" value="">
                    <input type="hidden" name="last_name" value="">
                    <input type="hidden" name="email" value="">

                    <input type="hidden" name="night_phone_a" value="">
                    <input type="hidden" name="night_phone_b" value="">

                    <input type="hidden" name="address1" value="">
                    <input type="hidden" name="city" value="Port Alberni">
                    <input type="hidden" name="state" value="BC">
                    <input type="hidden" name="country" value="CA">
                    <input type="hidden" name="zip" value="">

                    <!-- Set various options. -->
                    <input type="hidden" name="no_shipping" value="1">
                    <input type="hidden" name="notify_url" value="https://www.albernichamber.ca/ipn-process/light-up">
                    <input type="hidden" name="return" value="https://www.albernichamber.ca/node/3185?return='paid">
                    <input type="hidden" name="image_url" value="https://www.albernichamber.ca/sites/all/themes/albernichamber_new/logo.png">

                    <!-- Display the payment button. -->
                    <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_paynow_107x26.png" alt="Pay Now">
                    <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif">

                </form>
            </div>
        </div>


        <script>
            function telMask(element) {
                var x = element.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
                element.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
            }

            function autoFill(form) {
                var name = form.os0.value,
                    email = form.os1.value,
                    phone = form.os2.value,
                    address = form.os3.value,
                    postal = form.os4.value;

                // Name
                var nameSplit = name.split(' ');
                form.first_name.value = nameSplit[0];
                form.last_name.value = nameSplit[1];

                // Email 
                form.email.value = email;

                // Phone
                var phoneSplit = phone.match(/\((\d{0,3})\) (\d{0,3}-\d{0,4})/);
                form.night_phone_a.value = phoneSplit[1];
                form.night_phone_b.value = phoneSplit[2];

                // Address
                form.address1.value = address;
                form.zip.value = postal;
            }

            (function($) {

		var $content = $('.accordion .content').hide();
	
                $('.accordion .button').click(function() {
                    var $this = $(this),
                    	$for = $('#' + $this.attr('for'))
                    $('.show').removeClass('show')
                    $this.addClass('show');
                    $content.not($for).hide(400, function() {
                    	$for.addClass('show').show(500);
                    });

                    // In case there is only one button
                    $for.addClass('show').show(500);
                });

                /* Webform checkboxes */
                var limit = 3,
                      $checkGroups = $('.max-3');

                $checkGroups.each(function() {
                    var $checkboxes = $(this).find('input.form-checkbox');
                    $checkboxes.each(function() {
                        var html = $('.views-row.sync-id-' + this.value).find('span[type]').text();
                        $(this).next().text(html);
                    }).on('change', function(evt) {
                        if ($checkboxes.filter(':checked').length > limit) {
                            this.checked = false;
                            alert('Sorry, please only choose up to three.');
                        }
                    });
                });
            })(jQuery);
console.log('run');

        </script>

    </div>
<br /><br />
<h3>Bus Tour of "Light Up" Locations</h3>
<p>Cost: $10/person (incl. GST)</p>
<p>Only a few spaces available. Please call the Chamber office 250-724-6535 for info and reservations.</p>
<br /><br />
<h3>Photos from last year's Light Up Alberni Contest:</h3>