﻿
//*** ON PAGE LOAD
$(document).ready(function() {
    var cookie = evokeUtility.getCookie("textSize");
    if (cookie != null) {
        textSize.setFontSize(cookie);
    }
    $("a[href='#isi']").attr("href", "javascript:jQuery.scrollBodyTo('#isi');");
    $("a[href='#vdotISI']").attr("href", "javascript:jQuery.scrollBodyTo('#vdotISI');");
    $("a[href='#top']").attr("href", "javascript:jQuery.scrollBodyTo('#wrapper');");
});
//**********

var textSize = (function() {
    var container = "wrapper";
    var currentSize = "1em";
    function persist(size) {
        currentSize = size;
        evokeUtility.setCookie("textSize", size, null);
    }

    function getIsiSize() {
        if (currentSize == "1.1em")
            return "2";
        else if (currentSize == "1.2em")
            return "3";
        else
            return "1";
    }
    function setISI() {

        $('div.hdrSingle').removeClass('hdrSingle1').removeClass('hdrSingle2').removeClass('hdrSingle3');
        $('div.hdrDual').removeClass('hdrDual1').removeClass('hdrDual2').removeClass('hdrDual3');
        $('div.hdrSingle').addClass('hdrSingle' + getIsiSize());
        $('div.hdrDual').addClass('hdrDual' + getIsiSize());

        //if($('.isiVDot:visible').length > 0) {
        $('img.isiVDot').each(function() {
            if ($(this).hasClass('isiVDot' + getIsiSize())) {
                $(this).removeClass('hide');
            } else {
                $(this).addClass('hide');
            }
        });
        //}

        $('img.isiCB').each(function() {
            if ($(this).hasClass('isiCombiPatch' + getIsiSize())) {
                $(this).removeClass('hide');
            } else {
                $(this).addClass('hide');
            }
        });

    }
    var resized = null;

    function _this() { }
    _this.setFontSize = function(size) {
        document.getElementById(container).style.fontSize = size;
        persist(size);
        setISI();
        if (resized != null && typeof(resized) == "function")
            resized();
    };
    _this.small = function() {
        _this.setFontSize("1em");
    };
    _this.medium = function() {
        _this.setFontSize("1.1em");
    };
    _this.large = function() {
        _this.setFontSize("1.2em");
    };
    _this.change = function(size) {
        if (size == "1.1em")
            textSize.medium();
        else if (size == "1.2em")
            textSize.large();
        else
            textSize.small();
        setISI();
    }
    _this.onResize = function(func) {
        if (resized == null) {
            resized = func;
        } else {
            var origResize = resized;
            resized = function() {
                origResize();
                func();
            }
        }
    }
    return _this;

})();

var tracker = {
    trackFreeTrialVoucher: function() {
        tracker.ga.trackEvent("PDFs", "Download", "CombiPatch Free Trial Voucher");
    },
    trackCombiPatchInfoSheet: function() {
        tracker.ga.trackEvent("PDFs", "View", "CombiPatch Info Sheet");
    },
    trackCombiPatchPI: function() {
        tracker.ga.trackEvent("PDFs", "View", "CombiPatch PI");
    },
    trackVivelleDotPI: function() {
        tracker.ga.trackEvent("PDFs", "View", "Vivelle-Dot PI");
    },
    ga: {
        trackEvent: function(category, action, label, value) {
            try {
                _gaq.push(['_trackEvent', category, action, label, value]);
            } catch (err) { }
        }
    }
};

var formValidation = {
    validateField: function(arrValidatorIDs, mapIDs) {
        var isValid = true;
        if (arrValidatorIDs != undefined) {
            for (var i = 0; i < arrValidatorIDs.length; i++) {
                var validator = document.getElementById(arrValidatorIDs[i]);
                if (validator.enabled == undefined || validator.enabled == true) {
                    ValidatorValidate(validator);
                    if (validator.isvalid == false) {
                        isValid = false;
                        break;
                    }
                }
            }
        }
        if (mapIDs != undefined) {
            if (mapIDs.titleID != undefined) {
                if (isValid) {
                    $("#" + mapIDs.titleID).attr("class", "tdTitle");
                } else {
                    $("#" + mapIDs.titleID).attr("class", "tdTitleError");
                }
            }
            if (mapIDs.inputID != undefined) {
                if (isValid) {
                    $("#" + mapIDs.inputID).attr("class", "tdInput");
                } else {
                    $("#" + mapIDs.inputID).attr("class", "tdInputError");
                }
            }
            if (mapIDs.messageID != undefined) {
                if (isValid) {
                    $("#" + mapIDs.messageID).attr("class", "tdMsgOK");
                } else {
                    $("#" + mapIDs.messageID).attr("class", "tdMsgError");
                }
            }
        }
        return isValid;
    },
    validate: function(mapValidator) {
        var isValid = true;
        for (var memName in mapValidator) {
            var memObj = mapValidator[memName];
            if (typeof memObj == "function") {
                var flag = memObj();
                if (flag == false)
                    isValid = false;
            }
        }
        return isValid;
    }
};

function warnExternal(url) {
    var btnOK = document.getElementById("warnExternalContinue");
    btnOK.href = url;
    btnOK.onclick = function() {
        evokeModalDialog.hide();
    };
    evokeModalDialog.show("warnExternal");
}

function warnNovenExternal(url) {
    var btnOK = document.getElementById("warnNovenExternalContinue");
    btnOK.href = url;
    btnOK.onclick = function() {
        evokeModalDialog.hide();
    };
    evokeModalDialog.show("warnNovenExternal");
}

function warnNovartisExternal(url) {
    var btnOK = document.getElementById("warnNovartisExternalContinue");
    btnOK.href = url;
    btnOK.onclick = function() {
        evokeModalDialog.hide();
    };
    evokeModalDialog.show("warnNovartisExternal");
}

jQuery.scrollBodyTo = function(expression, fn, extraY) {
    var b = window.navigator.userAgent.toLowerCase();
    var jBody = this("html,body");
    var bodyOffset = 0;
    if (/applewebkit/.test(b)) {
        bodyOffset = document.body.scrollTop;
    } else if (/opera/.test(b)) {
        bodyOffset = 0;
    } else {
        bodyOffset = document.documentElement.scrollTop;
    }
    var elOffset = jBody.find(expression).offset().top;
    var y = elOffset - bodyOffset;

    var pageHeight = jQuery(document).height();
    var winHeight = jQuery(window).height();

    if (elOffset + winHeight > pageHeight) {
        y -= (winHeight - (pageHeight-elOffset));
    }

    if (extraY != undefined && extraY != null)
        y += extraY;
    jBody.animate({ scrollTop: '+=' + y + "px" }, "slow", "easeInOutExpo", fn);
};
