﻿var manualId = 0;
var hardwareId = 0;
var instructionId = 0;
var problemId = 0;
var manufacturerId = 0;
var productType = 0;
var chapterId = 0;
var subchapterId = 0;
var keywords = "";
var rawUrl = "";
var showDatacards = false;

// Global
// ---------------------------------------------------------
function SubmitClosestForm(object) {
    //$(object).closest("form").submit();
}
// Send via email
// ---------------------------------------------------------
$("#SendViaEmailLink").bind("click", function (event) {
    event.stopPropagation();
    ToggleSendEmail();
});

function ToggleSendEmail() {
    $("#SendSmsPopup").hide();
    $("#SendSmsLink").removeClass("active");
    $("#LinkToThisPagePopup").hide();
    $("#LinkToThisPageLink").removeClass("active");
    $("#SendEmailPopup").toggle();
    $("#SendViaEmailLink").toggleClass("active");
    $("#SendEmail_Form").show();
    $("#SendEmail_Confirm").hide();
    $("#SendEmail_Cancel").show();
    $("#SendEmail_Send").show();
    $("#SendEmail_Close").hide();
};

function SendEmail() {
    var recipient = $("#SendEmail_Recipient").val();
    var comment = $("#SendEmail_Comment").val();
    var name = $("#SendEmail_Name").val();
    var sendCurrentManual = $("#SendEmail_radio_manualStartPage").is(":checked");

    $.jmsajax({
        type: "POST",
        url: "/Web/AjaxWebService.asmx/SendEmail",
        dataType: "msjson",
        data: { "recipient": recipient,
            "name": name,
            "comment": comment,
            "manualId": manualId,
            "instructionId": instructionId,
            "problemId": problemId,
            "manufacturerId": manufacturerId,
            "productType": productType,
            "keywords": keywords,
            "rawUrl": rawUrl,
            "comparisonId1": 0,
            "comparisonId2": 0,
            "comparisonId3": 0,
            "comparisonDatacard": false,
            "chapterId": chapterId,
            "subchapterId": subchapterId,
            "sendCurrentManual": sendCurrentManual,
            "isCca": isCca,
            "hardwareId": hardwareId,
            "showDatacards": showDatacards
        },
        success: ShowSendEmailConfirm
    });
};

function ShowSendEmailConfirm(result) {
    if (result == "ok") {
        var recipient = $("#SendEmail_Recipient").val();
        $("#SendEmail_Confirm_Recipient").text(recipient);
        $("#SendEmail_Recipient").val("");
        $("#SendEmail_Comment").val("");
        $("#SendEmail_Name").val("");
        $("#SendEmail_Form").hide();
        $("#SendEmail_Confirm").show();
        $("#SendEmail_Cancel").hide();
        $("#SendEmail_Send").hide();
        $("#SendEmail_Close").show();
    }
    else {
        alert(result);
    };
}

// Link to this page
// ---------------------------------------------------------
$("#LinkToThisPageLink").bind("click", function (event) {
    event.stopPropagation();
    ToggleLinkToThisPage();
});

function ToggleLinkToThisPage() {
    $("#SendSmsPopup").hide();
    $("#SendSmsLink").removeClass("active");
    $("#SendEmailPopup").hide();
    $("#SendViaEmailLink").removeClass("active");
    $("#LinkToThisPagePopup").toggle();
    $("#LinkToThisPageLink").toggleClass("active");
};

// Send via SMS
// ---------------------------------------------------------
$("#SendSmsLink").bind("click", function (event) {
    event.stopPropagation();
    ToggleSendSms();
});

function ToggleSendSms() {
    $("#SendEmailPopup").hide();
    $("#SendViaEmailLink").removeClass("active");
    $("#LinkToThisPagePopup").hide();
    $("#LinkToThisPageLink").removeClass("active");
    $("#SendSmsPopup").toggle();
    $("#SendSmsLink").toggleClass("active");

    $("#SendSms_Recipient").val("");
    $("#SendSms_Form").show();
    $("#SendSms_Confirm").hide();
    $("#SendSms_Cancel").show();
    $("#SendSms_Send").show();
    $("#SendSms_Close").hide();
};
