﻿/// <reference path="jquery.js" />
/// <reference path="jquery.form.js" />

$(document).ready(function () {
    $("#moreinfoForm").ajaxForm({
        beforeSubmit: function () {
            $("#moreinfoForm #submitButton").enable(false);
            $("#moreinfoForm #loadingImage").show();
        },
        success: function (response, status) {
            $("#formNormal").slideUp(500, function () {
                $("#formDone").show();
            });
        },
        error: function (response, status) {
            $("#moreinfoForm #loadingImage").hide();
            alert("Sorry, something went wrong. Please contact us by phone or email.");
        }
    });

    var oldPriceTable = [
            { from: 1, to: 25, price: 2400 },
            { from: 26, to: 100, price: 4800 },
            { from: 101, to: 200, price: 7200 },
            { from: 201, to: 350, price: 9600 },
            { from: 351, to: 500, price: 1200 }
        ];

    $("#hostedAgencySize").keyup(function () {
        var size = parseInt($(this).val());

        if (isNaN(size))
            size = 0;

        var total = 0;

        if (size > 0) {
            for (employee = 0; employee != size; employee++) {
                var employeePrice = 36 - ((employee / (100 - 1)) * (36 - 5));

                if (employeePrice < 5)
                    employeePrice = 5;

                total += employeePrice;
            }
        }

        if (total < 500)
            total = 500;

        var onsiteTotal = Math.round(total * 3.5);

        $(oldPriceTable).each(function () {
            if (size >= this.from && size <= this.to)
                if (onsiteTotal < this.price)
                    onsiteTotal = this.price;
        });

        total = Math.round(total).toString();
        var perUser = size == 0 ? 0 : (Math.round((total / size) * 100) / 100).toString();

        $("#hostedPrice").text("$" + perUser);
        $("#hostedPricePerYear").text("$" + total);

        var onsiteAnnual = Math.round(onsiteTotal * 0.17);
        $("#onsitePrice").text("$" + onsiteTotal.toString());
        $("#onsiteAnnual").text("$" + onsiteAnnual.toString());
    })
    .trigger("keyup");

    $("#slider").easySlider({
        auto: true,
        continuous: true,
        numeric: true,
        pause: 10000
    });

});