﻿function createProductTipDialog() {
    var html = "<h3>" + diaTell + " " + prodTitle + "</h3>";
    html += "<img src='/Helpers/ImageTransformer.ashx?fileName=" + productMediaPath + prodImageName + "&Width=60&Height=60&mode=crop'/>";
    html += "<hr />";
    html += "<span id='tipMessage'></span>";
    html += "<form id='productTipForm'>";
    html += "<div id='share-email'>";
    html += "<div class='editor-label'>";
    html += "<label for='emailTo'>" + diaEmail + "</label></div>";
    html += "<div class='editor-field'>";
    html += "<input id='emailTo' name='emailTo' type='text' class='textfield'/></div>";
    html += "<div class='editor-label'>";
    html += "<label for='emailfrom'>" + diaYourMail + "</label></div>";
    html += "<div class='editor-field'>";
    html += "<input id='emailFrom' name='emailFrom' type='text' class='textfield'/></div>";
    html += "<div class='editor-label'>";
    html += "<label for='message'>" + diaMessage + "</label></div>";
    html += "<div class='editor-field'>";
    html += "<textarea id='message' name='message' class='textarea'></textarea></div>";
    html += "<input id='pot' name='pot' type='hidden'/>";
    html += "<input id='productId' name='productId' value='" + productId + "' type='hidden'/>";
    html += "<div class='button-container'><button type='button' class='button-default' onclick='javascript:sendProductTip()'>" + diaSend + "</button></div>";
    html += "</div>";
    html += "</form>";
    $.facebox(html);
}

function sendProductTip() {

    var url = window.location.href;
    var token = $('input[name=__RequestVerificationToken]').val();
    var formData = $("#productTipForm");
    var emailTo = $("#emailTo").val();
    var emailFrom = $("#emailFrom").val();
    var message = $("#message").val();
    var pot = $("#pot").val();
    var productId = $("#productId").val();
    
    //formData.push({ name: '__RequestVerificationToken', value: token }, { name: 'emailTo', value: emailTo }, { name: 'emailFrom', value: emailFrom }, { name: 'message', value: message }, { name: 'productId', value: productId }, { name: "url", value: url });

    if (emailFrom != "" || emailTo != "") {
        if (pot == undefined || pot == '') {
            $.ajax({ type: "POST",
                url: "/productmailtip",
                data: "emailTo=" + emailTo + "&emailFrom=" + emailFrom + "&message=" + message + "&productId=" + productId + "&url=" + url,
                dataType: "json",
                success: function (response) {
                    if (response.result == "success") {
                        $.facebox.close();
                        displayMessage($("#userMessage"), diaMessageSent, "success");
                    }
                    else if (response.result == "valFail") {
                        $("#tipMessage").html(diaValFail);
                    }
                    else {
                        $("#tipMessage").html(diaError);
                    }
                }
            });
        }
    } else {
        $("#tipMessage").html(diaValFail);
    }
}