$(function () {

    $("#imgAdvancedOptions").click(function () {
        $("#frmRequestOnlineQuote").submit();
    });

    $("#imgSubmit").click(function (event) {
        event.preventDefault();
    });

    $("#imgUpload").click(function (event) {
        event.preventDefault();
    });
});

function handleSignUp(){
        $.ajax({
            type: 'POST',
            url: '/bridged_service/SnRService.svc/SaveNewsLetter',
            data: '{"emailAddress": "' + $("#receiveEmailUpdates").val() + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, textStatus, xhr) {
                //alert('Email address registered.');
                $("#receiveEmailUpdates").val($('#receiveEmailUpdates').attr('title'));
                $("#signUp").removeAttr("disabled");
                customErrorPopup('Thank You!', '');
            },
            error: function (xhr, textStatus, error) {
                //alert(error);
                customErrorPopup("Error occurred while processing your request.");
                $("#signUp").removeAttr("disabled");
            }
        });

        $("#signUp").attr("disabled", "disabled");
}

function handleSubmitRequest() {
    var objContact = { "customerInfo": { "firstName": $("#firstName").val(),
        "lastName": $("#surName").val(),
        "email": $("#yourEmail").val(),
        "phoneNumber": $("#yourPhone").val(),
        "itemType": $("#item_type").val(),
        "futureUpdates": $("#receiveUpdates").attr("checked"),
        "itemTypeName": $(".jquery-selectbox-currentItem").text()
    }};

    // omniture code
            trackThankLink('event2', 'Request Quote Complete');
    // end omniture code


    $.ajax({
        type: 'POST',
        url: '/bridged_service/SnRService.svc/SaveRequest?requestQuote=true',
        data: $.toJSON(objContact),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data, textStatus, xhr) {
            $("#imgSubmit").removeAttr("disabled");
            customErrorPopup('Thank You!', 'A representative from Suttons &amp; Robertsons<br/> will promptly contact you within 24 hours.');
            //alert('Success');
        },
        error: function (xhr, textStatus, error) {
            $("#imgSubmit").removeAttr("disabled");
            customErrorPopup("Error occurred while processing your request.");
            //alert('Error: ' + error);
        }
    });

    $("#imgSubmit").attr("disabled", "disabled");
}
