﻿$(document).ready(initQuoteRequest);

function initQuoteRequest() {
//    $(":range").rangeinput();
    //    $(":date").dateinput();
    $(":range").rangeinput();
    $(":date").dateinput();
    $("#btnSendQuoteRequest").click(submitRequest);
    $("#btnSendBrochureRequest").click(submitRequest);
    $(".service_selector input").click(serviceSelectorClicked);
    $("#quoteRequestModal .close").click(quoteRequestClose);
}

function serviceSelectorClicked(e) {
    if ($(e.currentTarget).is(":checked")) {
        showQuoteRequestService($(e.currentTarget).val());
    } else {
        hideQuoteRequestService($(e.currentTarget).val());
    }
}

function showQuoteRequestService(serviceName, boolClear) {

    if (boolClear) {
        $(".input_item").hide();
        $(".ii_all").show();
        $("input[name='service']").each(function () {
            $(this).removeAttr('checked');
        });
        $(".service_selector input[value='" + serviceName + "']").attr("checked", "checked");
    }
    switch (serviceName) {
        case "Floorplan":
            $(".ii_floorplan").show();
            break;
        case "EventPlanner":
            $(".ii_event_planner").show();
            break;
        case "Markout":
            $(".ii_markout").show();
            break;
        case "MediaFloorplan":
            $(".ii_media_floorplan").show();
            break;
        case "YouAreHere":
            $(".ii_you_are_here").show();
            break;
        case "Animate":
            $(".ii_animate").show();
            break;
        case "WebDesign":
            $(".ii_web_design").show();
            break;
        case "FileX":
            $(".ii_filex").show();
            break;
    }
}
function hideQuoteRequestService(serviceName) {
    switch (serviceName) {
        case "Floorplan":
            $(".ii_floorplan").hide();
            break;
        case "EventPlanner":
            $(".ii_event_planner").hide();
            break;
        case "Markout":
            $(".ii_markout").hide();
            break;
        case "MediaFloorplan":
            $(".ii_media_floorplan").hide();
            break;
        case "YouAreHere":
            $(".ii_you_are_here").hide();
            break;
        case "Animate":
            $(".ii_animate").hide();
            break;
        case "WebDesign":
            $(".ii_web_design").hide();
            break;
        case "FileX":
            $(".ii_filex").hide();
            break;
    }
}
function showQuoteRequestDialog() {
    $(".validation_error").hide();
    $(".loading").hide();
    $("#thankYouMsg").hide();
    $("#quoteRequestModal").overlay({
        // some expose tweaks suitable for modal dialogs
        expose: {
            color: '#000',
            loadSpeed: 200,
            opacity: 0.5
        },
        api: true,
        closeOnClick: false,
        fixed: false
    }).load();
}

function submitRequest(e) {
    if (!validateForm()) return false;
    //compile data to send in quote request
    $(".loading").show();
    var sendData = {};
    var interestedServices = new Array();
    $(".service_selector input").each(function(index){
        if($(this).is(":checked"))
        {
            interestedServices.push($(this).val());
        }
    });
    sendData.InterestedServices = interestedServices.join(", ");
    sendData.Name = ($("#txtName").val()!=null) ? $("#txtName").val() : "Not supplied";
    sendData.Email = ($("#txtEmail").val()!=null) ? $("#txtEmail").val() : "Not supplied";
    sendData.Company = ($("#txtCompany").val()!=null) ? $("#txtCompany").val() : "Not supplied";
    sendData.Phone = ($("#txtPhone").val()!=null) ? $("#txtPhone").val() : "Not supplied";
    sendData.ShowName = ($("#txtShowName").val()!=null) ? $("#txtShowName").val() : "Not supplied";
    sendData.ShowDate = ($("#dateShowDate").val() != null) ? $("#dateShowDate").val() : "Not supplied";
    sendData.EPOnlinePeriod = ($("#txtEPOnlineTime").val()!=null) ? $("#txtEPOnlineTime").val() : "Not supplied";
    sendData.Venue = ($("#txtVenue").val()!=null) ? $("#txtVenue").val() : "Not supplied";
    sendData.NumberOfStands = ($("#txtNumberOfStands").val()!=null) ? $("#txtNumberOfStands").val() : "Not supplied";
    sendData.NetStandSpace = ($("#txtStandSpace").val()!=null) ? $("#txtStandSpace").val() : "Not supplied";
    sendData.FloorplanUpdateFrequency = ($("#rangeUpdateFrequency").val()!=null) ? $("#rangeUpdateFrequency").val() : "Not supplied";
    sendData.YAHServiceScope = $("input[name='servicescope']:checked").val();
    sendData.YAHUnits = ($("#txtNumberOfUnits").val()!=null) ? $("#txtNumberOfUnits").val() : "Not supplied";
    sendData.MediaPlanDrawingDimension = $("input[name='drawingdimension']:checked").val();
    sendData.WebsiteCMS = $("#chkContentManagement").is(":checked");
    sendData.WebsiteExhibitorList = $("input[name='exhibitorlist']:checked").val();

    switch ($(e.currentTarget).attr("id")) {
        case "btnSendQuoteRequest":
            sendData.op = "quote";
            break;
        case "btnSendBrochureRequest":
            sendData.op = "brochure";
            break;
    }

    $.ajax({
        type: "GET", //GET or POST or PUT or DELETE verb
        url: "http://www.showplans.com/QuoteRequestBackend.aspx",
        data: sendData, //Data sent to server
        processdata: true, //True or False
        success: function (msg) {//On Successfull service call
            //alert("success");
            $(".loading").hide();
            $("#thankYouMsg").show();
        },
        error: function (msg) {// When Service call fails
            //alert("failure");
            $(".loading").hide();
        }
    });
}
function quoteRequestClose() {
    $("#quoteRequestModal").overlay().close();
    return false;
}
function validateForm() {
    var isValid = true;
    if ($("#txtEmail").val() == "") {
        isValid = false;
        $("#iiEmail").append("<span class='validation_error'>A valid email address is required</a>");
    }
    return isValid;
}
