﻿jQuery(document).ready(function($) {
    $("#authDonate").submit(function(e) {
        //set x amount and x description
        if ($("#x_fp_hash").attr("value") == "") {


            var pricing = Array();
            pricing["Waikiki To Airport"] = 11;
            pricing["Airport to Waikiki"] = 11;
            pricing["Airport - Waikiki (RT)"] = 21;
            pricing["Cruise Ship Shuttle"] = 11;
            pricing["Waikiki to Aloha Tower"] = 11;
            pricing["Waikiki to Aloha Stadium"] = 10;
            pricing["Aloha Stadium to Waikiki"] = 10;
            pricing["Aloha Stadium (RT)"] = 14;
            pricing["Waikiki to Arizona Memorial"] = 10
            pricing["Arizona Memorial to Waikiki"] = 10
            pricing["Arizona Memorial (RT)"] = 14
            pricing["Flea Market Shuttle One Way"] = 10;
            pricing["Flea Market Shuttle (RT)"] = 14;
            
            service = $('#Type_Of_Service').val();
            
            if (service != '"Circle the Island" Tour' && (service == null || isNaN(pricing[service]))) {
                alert("You must specify a service");
                return false;
            }


            date = $('#Pickup_Date').val();
            date = parseDate(date);
            if (date == null) {
                alert("Pickup Date must be a valid Date");
                return false;
            }


            time = $('#Pickup_Time').val();
            if (time == '0:00 AM') {
                alert("Pickup Time must be valid");
                return false;
            }

            time = '1/1/1970 ' + time;
            time = Date.parse(time);


            adult = parseFloat($('#Adult_Passengers').val());
            if (isNaN(adult)) {
                alert("Number of Adults Must be a Valid Number");
                return false;
            }

            child = parseFloat($('#Child_Passengers').val());
            if (isNaN(child)) {
                alert("Number of Children Must be a Valid Number");
                return false;
            }

            golfbags = parseFloat($('#Golf_Bags').val());
            if (isNaN(golfbags)) {
                alert("Golf Bags Must be a Valid Number");
                return false;
            }

            leis = parseFloat($('#Leis').val());
            if (isNaN(leis)) {
                alert("Golf Bags Must be a Valid Number");
                return false;
            }

            surf = parseFloat($('#Surf').val());
            if (isNaN(surf)) {
                alert("Golf Bags Must be a Valid Number");
                return false;
            }
            price = pricing[service]
            var amount = 0;

            //passed data validation now the crazy date time rules
            switch (service) {
                case 'Airport - Waikiki (RT)':
                    amount = child * 4;
                case 'Waikiki To Airport':
                case 'Airport to Waikiki':
                    starttime = Date.parse('1/1/1970 5:45 AM');
                    endtime = Date.parse('1/1/1970 8:45 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 5:45AM and 8:45PM");
                        return false;
                    }
                    amount += child * 5;
                    amount += adult * price;
                    break;
                case 'Cruise Ship Shuttle':
                    starttime = Date.parse('1/1/1970 11:45 AM');
                    endtime = Date.parse('1/1/1970 4:45 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 11:45AM and 5:45PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case 'Waikiki to Aloha Tower':
                    starttime = Date.parse('1/1/1970 6:00 AM');
                    endtime = Date.parse('1/1/1970 4:45 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 5:45AM and 4:45PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case "Aloha Stadium to Waikiki":
                    starttime = Date.parse('1/1/1970 6:30 AM');
                    endtime = Date.parse('1/1/1970 3:30 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 6:30AM and 3:30PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case 'Waikiki to Aloha Stadium':
                case 'Aloha Stadium (RT)':
                    starttime = Date.parse('1/1/1970 6:00 AM');
                    endtime = Date.parse('1/1/1970 1:00 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 5:45AM and 1:00PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case "Waikiki to Arizona Memorial":
                case "Arizona Memorial (RT)":
                    starttime = Date.parse('1/1/1970 5:45 AM');
                    endtime = Date.parse('1/1/1970 11:45 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 5:45AM and 11:45PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case "Arizona Memorial to Waikiki":
                    starttime = Date.parse('1/1/1970 6:30 AM');
                    endtime = Date.parse('1/1/1970 3:30 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 6:30AM and 3:30PM");
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
                case "Flea Market Shuttle One Way":
                case "Flea Market Shuttle (RT)":
                    starttime = Date.parse('1/1/1970 6:00 AM');
                    endtime = Date.parse('1/1/1970 12:00 PM');
                    if (time < starttime || time > endtime) {
                        alert("Pickup Times must be between 6:00AM and Noon");
                        return false;
                    }
                    if (date.getDay() != 4 && date.getDay() != 6 && date.getDay() != 1) {
                        alert('Shuttle only runs on Wednesday, Saturday, or Sunday');
                        return false;
                    }
                    amount = (child + adult) * price;
                    break;
            }

            amount += leis * 11
            amount += golfbags * 3
            amount += surf * 5
            new_description = child + adult;
            $('#x_description').val('' + new_description + ' '  + service + ' on ' + date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear());

            //generates unique authnet values
            $.getJSON("auth_net_hash.asp?amount=" + amount + "&callback=?", function(data) {
                $("#x_login").attr("value", data.x_login);
                $("#x_invoice_num").attr("value", data.x_invoice_num);
                $("#x_fp_sequence").attr("value", data.x_fp_sequence);
                $("#x_fp_timestamp").attr("value", data.x_fp_timestamp);
                $("#x_fp_hash").attr("value", data.x_fp_hash);
                $("#x_amount").attr("value", data.x_amount);
                //json returned now submit form
                $("#authDonate").submit();
            });
            return false;
        } else {
            //value set by jsoncallback allow form submit
            return true;
        }

    });
});

/* Complicated Rules for services below
Airport Shuttle

    * (to and from the Waikiki vicinity only) 5:45AM-8:45PM
    * One Way: $11.00 per adult & $5.00 for kids (11 years and under) - Round Trip: $21
    * Pickups from Waikiki begin at: 545AM and ends @ 8:45PM each pickup time is 45 minutes after the hour (545, 645, 745, etc.) --- Pickups from the Airport are based on a call-in base only. Have the customer call 808.944.1879 upon arrival at the airport).

Cruise Ship Shuttle

    * all cruise ships that dock in Piers 10&11
    * One Way: $11 - Round Trip: N/A
    * Pickup times from Waikiki to the ships begin @ 11:45AM to 4:45PM, and every 45 minutes on the hour there after. For example: (1145AM, 1245PM, 145PM, 245PM, etc.)

Waikiki to Aloha Tower Marketplace

    * Pickup times from Waikiki to ATM begins @ 545AM and the last returning time from ATM is 445PM. Again, each pick-up time is 45 after the hour – 545AM, 645AM, 745AM, etc.
    * One Way: $11 - Round Trip: N/A

Aloha Stadium

    * Only for Special Events: Concerts / Football Games
    * Pickup times from Waikiki to the stadium begins at: 545AM to 1PM. (each pickup time is 45minutes after the hour). The last pickup from the stadium is at 330PM.
    * One Way: $10 - Round Trip: $14

Arizona Memorial Shuttle (USS Missouri Battleship, Submarine)

    * Pickups from Waikiki to the Arizona Memorial begins at: 545AM to 1145AM---Returning shuttles from Arizona Memorial to Waikiki are 30 minutes after the hour .. and the last shuttle is @ 330PM. For example: 1030, 1130, 1230, 130, 230, 330, etc).
    * One Way: $10 - Round Trip: $14

Flea Market Shuttle (Wednesday, Saturday, Sunday, 6:00AM-3:30PM)

    * Bookings limited to: Wednesdays, Saturdays, and Sundays ONLY --- PICKUP reservations: 6AM to 12PM---Last returning shuttle is 3:30PM
    * One Way: $10 - Round Trip: $14

"Circle the Island" Tour

    * Option should only be a quote request.. If the customer wants a quote, they can check off this option and it will be submitted for discussion on our end
    * $85.00 / an hour - (10 Passenger Van) - $90.00 / an hour - (14 Passenger Van)

Lei Greeting Service

    * Once this option is selected.. it should be +$11.00 [per lei] added to the subtotal.

Skis / Surfboards / Bicycles (must be in case)

    * If added to to the subtotal.. it should show up as +$5.00 [per item] added to the subtotal

Golf Bags

    * If added to to the subtotal.. it should show up as +$3.00 [per item] added to the subtotal
    
    Can build itemized list like this
    <INPUT TYPE="HIDDEN" name="x_line_item" VALUE="item1<|>golf balls<|><|>2<|>18.95<|>Y">

<INPUT TYPE="HIDDEN" name="x_line_item" VALUE="item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y">

<INPUT TYPE="HIDDEN" name="x_line_item"  VALUE="item3<|>book

<|>Golf for Dummies<|>1<|>21.99<|>Y">
    
    
*/