﻿if (typeof pages == 'undefined' || !pages) {
    var pages = {};
}

if (typeof pages.association == 'undefined' || !pages.association) {
    pages.association = {};
}


pages.association.educatorLiability = (function () {
    var validation = (function () {
        return {
            checkZipCode: function (source, args) {
                if ($('#txtZipCode2').val().length > 0) {
                    $.ajax({
                        type: 'POST',
                        url: '/Default.aspx/IsValidZipCode',
                        data: '{zip: "' + $('#txtZipCode2').val() + '" }',
                        contentType: 'application/json; charset=utf-8',
                        context: this,
                        dataType: 'json',
                        async: false,
                        success: function (msg) {
                            args.IsValid = msg.d;
                        },
                        failure: function (msg) {
                            args.IsValid = false;
                        }
                    });
                } else {
                    args.IsValid = false;
                }
            }
        };
    })();

    var footerLoad = function () {
        $('#StandardFooter').hide();
        $('#TieFooter').css('display', 'block');
    };

    var hasAssocParam = function () {
        var segment1 = jQuery.url.setUrl(window.location).segment(1)
        if (segment1 == "PG-L") return true;
        return (segment1 != null) && (segment1 != "PG-L");
    };

    var hasStateParam = function () {
        var segment2 = jQuery.url.setUrl(window.location).segment(2);
        return (segment2 != null) && (segment2 != "BN");
    };

    var initHeader = function () {
        if (!hasAssocParam() && !hasStateParam()) {
            $('.assoclogo').prepend('<img src="/App_Themes/Default/Images/ProLiability/Tie_Logo.gif" />');
        }
    };

    var initPlaceholders = function () {
        $('input:text').placeholder();
    };

    var bindMemberInsuredTip = function () {
        $('.imgshadow').qtip({
            content: {
                text: $('#rollover')
            },
            position: {
                my: 'top left',  // Position my top left...
                at: 'bottom left', // at the bottom right of...
                target: $('.dummy') // my target
            },
            show: {
                effect: { type: 'fade' }
            },
            hide: {
                effect: { type: 'fade' }
            },
            style: {
                padding: 5,
                border: {
                    width: 1,
                    radius: 5,
                    color: '#12679B'
                },
                background: '#FFFFFF',
                width: { min: 268, max: 268 },
                tip: 'topMiddle'
            }
        });
    };    

    var copyRelToHref = function () {
        $('.popup').attr('href', $('.popup').attr('rel'));
    };

    return {
        init: function () {
            initHeader();
            copyRelToHref();
            footerLoad();
            initPlaceholders();
            bindMemberInsuredTip();
        },
        checkZipCode: function (source, args) {
            return validation.checkZipCode(source, args);
        }
    }
})();
