﻿if (!window.ephip)
    window.ephip = {};

window.ephip.testing = {};
window.ephip.testing.tests = {

    setupRenewOrJoin: function () {
        var fnOnSubmit = function () {
            ephip.api.membershipRenewOrJoin({
                success: function (data) {
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="color:green;font-weight:bold;">Success</div><div>Transaction ID: ' + data + '</div>'
                    }, { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                },
                error: function (xhr, status, error) {
                    var exception = null;
                    try {
                        exception = (xhr.Message) ? xhr : eval("(" + xhr.responseText + ")");
                    }
                    catch (ex) { }
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="color:red;font-weight:bold;">Failed</div><div>' + (exception.Message ? exception.Message : '') + '</div>'
                    },
                        { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                }
            });
        };
        var dtos = new ephip.data.DTOs();

        dtos.RenewOrJoin.AddressInfo.AddressLine1 = "240 Broadway";
        dtos.RenewOrJoin.AddressInfo.AddressLine2 = "5th Floor";
        dtos.RenewOrJoin.AddressInfo.AddressLine3 = "";
        dtos.RenewOrJoin.AddressInfo.CityName = "New York";
        dtos.RenewOrJoin.AddressInfo.CountrySubdivisionCode = "NY";
        dtos.RenewOrJoin.AddressInfo.PostalCode = "10010";
        dtos.RenewOrJoin.AddressInfo.CountryCode = "US";
        dtos.RenewOrJoin.AddressInfo.TelephoneAreaCode = "212";
        dtos.RenewOrJoin.AddressInfo.TelephoneExchAndNumber = "5551234";

        dtos.RenewOrJoin.PaymentInfo.CCNumber = "4111111111111111";
        dtos.RenewOrJoin.PaymentInfo.Type = "Credit Card";
        dtos.RenewOrJoin.PaymentInfo.NameOnAccount = "John Test";
        dtos.RenewOrJoin.PaymentInfo.CardCode = "345";
        dtos.RenewOrJoin.PaymentInfo.ExpMM = "08";
        dtos.RenewOrJoin.PaymentInfo.ExpYYYY = "2015";
        dtos.RenewOrJoin.PaymentInfo.Amount = 16.00;
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.AddressLine1 = "240 Broadway";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.AddressLine2 = "5th Floor";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.AddressLine3 = "";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.CityName = "New York";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.CountrySubdivisionCode = "NY";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.PostalCode = "10010";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.CountryCode = "US";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.TelephoneAreaCode = "212";
        dtos.RenewOrJoin.PaymentInfo.BillingAddress.TelephoneExchAndNumber = "5551234";

        dtos.RenewOrJoin.PrimaryPersonInfo.Title = "";
        dtos.RenewOrJoin.PrimaryPersonInfo.GivenName = "John";
        dtos.RenewOrJoin.PrimaryPersonInfo.MiddleName = "";
        dtos.RenewOrJoin.PrimaryPersonInfo.FamilyName = "Test";
        dtos.RenewOrJoin.PrimaryPersonInfo.SuffixName = "";
        dtos.RenewOrJoin.PrimaryPersonInfo.BirthDateTime = "01/01/1950";
        dtos.RenewOrJoin.PrimaryPersonInfo.Email = "t@test.com"; // "jdoe" + Math.random().toString().substr(2) + "@mydomain.com";

        var tstobj = wesreid.testing.framework.createTestingStructure(dtos.RenewOrJoin, fnOnSubmit);
        var uiform = new wesreid.testing.framework.ui.uiForm(tstobj, $('#membershipRenewOrJoin div.formContent'), 'Membership Renew or Join', null, 'membershipreneworjoin');
        $('#frmMembershipInfo_Term').blur(function () {
            switch ($(this).val()) {
                case "1":
                    $('#frmPaymentInfo_Amount').val('16.00');
                    break;
                case "2":
                    $('#frmPaymentInfo_Amount').val('43.00');
                    break;
                case "3":
                    $('#frmPaymentInfo_Amount').val('63.00');
                    break;
            }
        });
    },

    setupMembershipInquiry: function () {
        var fnOnSubmit = function () {
            ephip.api.membershipInquiry({
                success: function (data) {
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="font-weight:bold;"><span style="color:green;">Member Exists:</span><br/>' + data + '</div>'
                    }, { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                },
                error: function (xhr, status, error) {
                    var exception = null;
                    try {
                        exception = (xhr.Message) ? xhr : eval("(" + xhr.responseText + ")");
                    }
                    catch (ex) { }
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="color:red;font-weight:bold;">Error Occurred:</div><div>' + (exception.Message ? exception.Message : '') + '</div>'
                    },
                        { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                }
            });
        };
        var dtos = new ephip.data.DTOs();

        dtos.MembershipInquiry.AccountNumber = "";
        dtos.MembershipInquiry.GivenName = "";
        dtos.MembershipInquiry.FamilyName = "";
        dtos.MembershipInquiry.PostalCode = "";

        var tstobj = wesreid.testing.framework.createTestingStructure(dtos.MembershipInquiry, fnOnSubmit);
        var uiform = new wesreid.testing.framework.ui.uiForm(tstobj, $('#membershipInquiry div.formContent'), 'Membership Inquiry', null, 'membershipinquiry');
    },

    setupProductRequest: function () {
        var fnOnSubmit = function () {
            ephip.api.productRequest({
                success: function (data) {
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="font-weight:bold;"><span style="color:green;">Successful Request</span><br/>' + data + '</div>'
                    }, { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                },
                error: function (xhr, status, error) {
                    var exception = null;
                    try {
                        exception = (xhr.Message) ? xhr : eval("(" + xhr.responseText + ")");
                    }
                    catch (ex) { }
                    wesreid.util.ui.modalWindow.showModalContent({
                        html: '<div style="color:red;font-weight:bold;">Error Occurred:</div><div>' + (exception.Message ? exception.Message : '') + '</div>'
                    },
                        { width: 700, "margin-left": -350 }
                    );
                    $('html, body').animate({ scrollTop: ($(wesreid.util.ui.modalWindow.modalContentContainer).offset().top - 20) }, 1000);
                }
            });
        };
        var dtos = new ephip.data.DTOs();
        var tstobj = wesreid.testing.framework.createTestingStructure(dtos.ProductRequest, fnOnSubmit);
        var uiform = new wesreid.testing.framework.ui.uiForm(tstobj, $('#productRequest div.formContent'), 'Product Request', null, 'productrequest');
    }

};
