﻿//dependent on EvokeScriptResource.axd?evokeUtility

if (top.location != location) {
    top.location.href = document.location.href;
}

jQuery.fn.extend({
    scrollTo: function(y, func) {
        return this.each(function() {
            var targetOffset = 0;
            if (y == undefined || y == null) {
                targetOffset = $(this).offset().top / 2;
            }
            else {
                targetOffset = y;
            }
            $('html,body').animate({ scrollTop: targetOffset }, "normal", func);
        });
    },
    scrollToMiddle: function(func) {
        return this.each(function() {
            var middle = ($(this).offset().top) - ($(window).height()/2)+60;
            $('html,body').animate({ scrollTop: middle }, "normal", func);
        });
    }
});

var textSize = (function() {
    var container = "pageContent";
    var currentSize = "1em";
    function persist(size) {
        currentSize = size;
        evokeUtility.setCookie("textSize", size, null);
    }
    function _this() { }
    _this.setFontSize = function(size) {
        document.getElementById(container).style.fontSize = size;
        persist(size);
    };
    _this.small = function() {
        _this.setFontSize("1em");
    };
    _this.medium = function() {
        _this.setFontSize("1.1em");
    };
    _this.large = function() {
        _this.setFontSize("1.2em");
    };
    _this.change = function() {
        if (currentSize == "1em")
            textSize.medium();
        else if (currentSize == "1.1em")
            textSize.large();
        else
            textSize.small();
    }
    return _this;
})();

evokeUtility.addWindowEvent("load", function() {
    var cookie = evokeUtility.getCookie("textSize");
    if (cookie != null) {
        textSize.setFontSize(cookie);
    }
});

function toggleShare() {
    if ($("#pageShare").css("display") == "none") {
        $("#pageShare").scrollTo(200);
        $("#pageShare").fadeIn("fast");
    } else {
        $("#pageShare").fadeOut("fast");
    }
}

function getStyle(el, style) {
    if (!document.getElementById)
        return;
    var value = el.style[style];
    if (!value) {
        if (el.currentStyle)
            value = el.currentStyle[style];
        else if (document.defaultView)
            value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
    }
    return value;
}

var videoStartDate = null;
var currentVideo = null;
function closeFlashVideo() {
    var endDate = new Date();
    var time = Math.round((endDate.getTime() - videoStartDate.getTime()) / 1000);
    evokeAnalytics.Google.trackVideoViewTime(currentVideo, time);
    evokeModalDialog.hide();
    evokeModalDialog.detachClickEvent(closeFlashVideo);
    document.getElementById("flashMoviePopupVideo").stopVideo();
}
function showMenopause101Video() {
    videoStartDate = new Date();
    currentVideo = "Menopause 101 " + document.location.pathname;
    evokeAnalytics.Google.trackVideoPlay(currentVideo);
    var flashvars = {
        dataRoot: commonProps.appRoot + "/flash/menopause-101/data",
        piURL: commonProps.appRoot + "/documents/vivelle-dot-prescribing-information.pdf",
        urlTalkDoctor: commonProps.appRoot + "/consumer/next-steps/talk-to-your-doctor.aspx",
        urlSamplePatch: commonProps.appRoot + "/consumer/about-vivelle-dot/request-a-non-medicated-sample/default.aspx",
        urlFreeTrial: commonProps.appRoot + "/consumer/about-vivelle-dot/one-month-free/default.aspx",
        urlHome: commonProps.appRoot + "/consumer/default.aspx"
    };
    var params = {
        wmode: "transparent",
        allowscriptaccess: "sameDomain"
    };
    swfobject.embedSWF(commonProps.appRoot + "/flash/menopause-101/player-v2_CS3.swf", "flashMoviePopupVideo", "800", "600", "9.0.0", commonProps.appRoot + "/flash/expressInstall.swf", flashvars, params);
    evokeModalDialog.attachClickEvent(closeFlashVideo);
    evokeModalDialog.show("flashMoviePopup");
}
function showHysterectomyVideo() {
    videoStartDate = new Date();
    currentVideo = "Hysterectomy " + document.location.pathname;
    evokeAnalytics.Google.trackVideoPlay(currentVideo);
    var flashvars = {
        dataRoot: commonProps.appRoot + "/flash/hysterectomy/videos",
        piURL: commonProps.appRoot + "/documents/vivelle-dot-prescribing-information.pdf"
    };
    var params = {
        wmode: "transparent",
        allowscriptaccess: "sameDomain"
    };
    swfobject.embedSWF(commonProps.appRoot + "/flash/hysterectomy/hysterectomy_player.swf", "flashMoviePopupVideo", "800", "600", "9.0.0", commonProps.appRoot + "/flash/expressInstall.swf", flashvars, params);
    evokeModalDialog.attachClickEvent(closeFlashVideo);
    evokeModalDialog.show("flashMoviePopup");
}




var mouse = { X: 0, Y: 0 };
var termTimeout = 0;
function showTerm(termID) {
    window.clearTimeout(termTimeout);
    getMouseXY();
    $("#glossaryTerm").html("Loading...");
    var padLeft = parseInt($("#pageContent").css("padding-left"));
    var padTop = parseInt($("#pageContent").css("padding-top"));
    if (termTimeout == 0) {
        $("#glossaryTerm").css({
            "top": (mouse.Y + 5) + "px",
            "left": (mouse.X + 5) + "px"
        });
    }
    $("#glossaryTerm").fadeIn("fast");
    $.getJSON(commonProps.glossaryTerm, {id: termID}, 
        function(json) { 
            var html = "<b>" + json.title + "</b><br />" + json.definition;
            $("#glossaryTerm").html(html);
        }
    );
}
function hideTerm() {
    termTimeout = window.setTimeout(function() { $("#glossaryTerm").fadeOut("fast"); termTimeout = 0; }, 50);
}
function getMouseXY() {
    if (evokeUtility.browser.isIE()) {
        mouse.X = window.event.clientX + document.documentElement.scrollLeft;
        mouse.Y = window.event.clientY + document.documentElement.scrollTop;
    } 
}
if (!evokeUtility.browser.isIE()) {
    window.addEventListener("mousemove", function(e) { mouse.X = e.pageX; mouse.Y = e.pageY; }, false);
}


function validateFormFields(fieldPropsArray) {
    var flag = true;
    var obj = null;
    for (var i in fieldPropsArray) {
        checkFieldValid(fieldPropsArray[i]);
        if (!fieldPropsArray[i].isValid) {
            flag = false;
            if (obj == null) obj = document.getElementById(fieldPropsArray[i].inputID);
        }
    }
    if (obj != null) {
        obj.focus();
    }
    return flag;
}
function checkFieldValid(props) {
    var flag = true;
    var validatorID = null;
    for (var i=0; i<props.validatorIDs.length; i++) {
        validator = document.getElementById(props.validatorIDs[i]);
        if (validator.enabled == undefined || validator.enabled) {
            ValidatorValidate(validator);
            if (!validator.isvalid) {
                flag = false;
                break;
            }
        }
    }
    if (flag && props.additional != undefined) {
        var newFlag = props.additional();
        if (newFlag != undefined)
            flag = newFlag;
    }
    var objField = document.getElementById(props.fieldID);
    var objCheck = document.getElementById(props.checkID);
    if (flag) {
        if (objField != null) objField.className = "fieldOK";
        if (objCheck != null) objCheck.style.display = "inline";
    } else {
        if (objField != null) objField.className = "fieldError";
        if (objCheck != null) objCheck.style.display = "none";
    }
    props.isValid = flag;
}
function checkRegEmailExists(url, propsAsString) {
    var data = {
        email: document.getElementById(eval(propsAsString).inputID).value,
        propsArrayString: propsAsString
    };
    $.getJSON(url, data, function(json) {
        var props = eval(json.propsArrayString);
        if (json.exists) {
            var objField = document.getElementById(props.fieldID);
            var objCheck = document.getElementById(props.checkID);
            var objValidator = document.getElementById(props.validatorIDs[0]);
            if (objField != null) objField.className = "fieldError";
            if (objCheck != null) objCheck.style.display = "none";
            if (objValidator != null) {
                objValidator.innerHTML = "The email address entered already exists.";
                objValidator.style.display = "inline";
            }
            props.isValid = flag;
        }
    });
}



function inputOnFocus(obj) {
    obj.className = "txtInputFocus";
}
function inputOnBlur(obj) {
    obj.className = "txtInput";
}

var msgLeavingExternal = "You are now leaving the Vivelle-Dot Web site and moving to an external Web site independently operated and not managed by Novogyne Pharmaceuticals. Novogyne assumes no responsibility for the site.";

var msgLeavingNoven = "You are now leaving the Vivelle-Dot Web site and moving to an external Web site operated by Noven Pharmaceuticals, Inc., a partner with Novartis Pharmaceuticals Corporation in the joint venture Novogyne Pharmaceuticals.";

var msgLeavingNovartis = "You are now leaving the Vivelle-Dot Web site and moving to an external Web site operated by Novartis Pharmaceuticals Corporation, a partner with Noven Pharmaceuticals, Inc. in the joint venture Novogyne Pharmaceuticals.";

function warnExternal(url) {
    document.getElementById("warnLeavingMsg").innerHTML = msgLeavingExternal;
    document.getElementById("warnLeavingURL").href = url;
    evokeModalDialog.show("warnLeaving");
}
function warnExternalNoven(url) {
    document.getElementById("warnLeavingMsg").innerHTML = msgLeavingNoven;
    document.getElementById("warnLeavingURL").href = url;
    evokeModalDialog.show("warnLeaving");
}
function warnExternalNovartis(url) {
    document.getElementById("warnLeavingMsg").innerHTML = msgLeavingNovartis;
    document.getElementById("warnLeavingURL").href = url;
    evokeModalDialog.show("warnLeaving");
}


function showPopupContent(contentDivID) {
    $("#popupContentText").html($("#"+contentDivID).html());
    evokeModalDialog.show("popupContent");
}

function openVivelleHcpPI() {
    openVivellePI();
}
function openVivellePI() {
    openAndTrackPDF("Vivelle-Dot PI", commonProps.vivellePI);
}
function openCombiPatchPI() {
    openAndTrackPDF("CombiPatch PI", commonProps.combiPatchPI);
}

var tracker = {
    trackVivellePI: function() {
        evokeAnalytics.Google.trackPDF("Vivelle-Dot PI");
    }
};

function openAndTrackPDF(pdfName, pdfPath) {
    evokeAnalytics.Google.trackPDF(pdfName);
    window.open(pdfPath);
}

var evokeAnalytics = {
    Google: {
        trackPDF: function(pdf) {
            pageTracker._trackEvent("PDFs", "Download", pdf, null);
        },
        trackVideoPlay: function(video) {
            pageTracker._trackEvent("Videos", "Play", video, null);
        },
        trackVideoViewTime: function(video, time) {
            pageTracker._trackEvent("Videos", "View Time", video, time);
        },
        trackSQ: function(page) {
            pageTracker._trackEvent("Symptom Questionnaire", "View", page, null);
        },
        trackSocial: function(networkName) {
            pageTracker._trackEvent("Social Networks", networkName, document.location.pathname, null);
        },
        trackShare: function(shareType) {
            pageTracker._trackEvent("Sharing", shareType, document.location.pathname, null);
        }
    }
};