// require(["jquery", "../../dist/jquery.validate"], function($) {

//     $.validator.setDefaults({
//         submitHandler: function() { alert("submitted!"); }
//     });

//     // validate the comment form when it is submitted
//     $("#commentForm").validate();
// });

$('body').on('hide.bs.modal', function() {
    // $('form input[type="text"], input[type="password"]').tooltipster('hide');
    $('form').find("input").val("");
    $('form fieldset div').removeClass('has-error');
    $('form').validate();
});

$('#shareForm').on("submit", function(e) {
    e.preventDefault();

    var toNameval = $('#toName').val();
    var toEmailval = $('#toEmail').val();
    var fromNameval = $('#fromName').val();
    var fromEmailval = $('#fromEmail').val();
    var imgURL = $('#imageURL').val();
    var prodDesc = $('#prodDesc').val();
    var prodURL = $('#prodURL').val();

    tracker.track("Email From Name", fromNameval, productID, appView, userID);
    tracker.track("Email To Name", toNameval, productID, appView, userID);
    tracker.track("Email From Addr", fromEmailval, productID, appView, userID);
    tracker.track("Share Email", toEmailval, productID, appView, userID);

    $('.spinner').show();

    $.ajax({
        type: 'POST',
        url: '//www-dev.facecake.com/nars-test/sendmessage.php',
        data: {
            toName: toNameval,
            toEmail: toEmailval,
            fromName: fromNameval,
            fromEmail: fromEmailval,
            imgURL: imgURL,
            prodDesc: prodDesc,
            prodURL: prodURL,
        },
        success: function(data) {
            localStorage.setItem("user email", fromEmailval);

            $('.spinner').hide();

            $('#response').html("<p style='color: #03c816'>SUCCESS: Your message was sent!</p>").promise().done(function() {
                setTimeout(function() {
                    $('#emailModal').foundation('reveal', 'close');
                }, 2000);

                tracker.track("Share Email", "Share Email", productID, appView, userID);
            });
        },
        error: function(xhr, type, data) {
            $('.spinner').hide();

            $('#response').html("<p style='color: red'>ERROR: There was a problem sending your message.  Please try again later.</p>").promise().done(function() {
                setTimeout(function() {
                    $('#emailModal').foundation('reveal', 'close');
                }, 2000);
            });
        }
    });
});



function fbPost(imgURL) {
    var redirectURI = "https://www.facebook.com/connect/login_success.html";
    // var imgShareURL;

    var postTitle = 'NARS - Integrated Try-On';
    var prodDesc = "Check out my new lipstick from NARS Cosmetics";

    var leftPosition, topPosition;
    //Allow for borders.
    var width = 500;
    var height = 300;

    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 150);
    var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=no,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";

    window.open('https://www.facebook.com/dialog/feed?app_id=301956396641648&link=http://dev05.web.narscosmetics.demandware.net/s/US/USA/love/0607845010289.html&picture=' + imgURL + '&name=' + postTitle + '&description=' + prodDesc + '&redirect_uri=' + redirectURI + '&display=popup', 'facebook-share-dialog', windowFeatures);

    tracker.track("Share Facebook", "Share Facebook", productID, appView, userID);
}

//  function emailShare(imgShareURL) {
//     $('#data').html('<img src="' + imgShareURL +'" alt="share your pic" class="img-thumbnail">');
//     $('#image').val(imgShareURL);
//     $('#shareEmailModal').modal('show');
// }
