﻿$(document).ready(function () {
    $("a[href='#isi']").each(function () {
        this.href = "javascript:scrollToISI();";
    });
    $("a[class='external']").each(function () {
        $(this).click(function () {
            return confirm('You are about to leave Fosrenol.com. This link will take you to a Web site maintained by a third party who is responsible for its content and privacy policy. Shire privacy policy does not apply to this site. We encourage you to read the privacy policy of every Web site you visit. Click Cancel to return to Fosrenol.com or OK to continue.');
        });
    });
});

function scrollToISI() {
    jQuery.scrollBodyTo('#isi', { speed: 500, easing: 'easeInOutCubic' });
}

var tracker = {
    trackRegComplete: function () {
        _gaq.push(['_trackEvent', 'Forms', 'Receive Updates', 'Registered']);
    },
    trackShareColleague: function () {
        _gaq.push(['_trackEvent', 'Forms', 'Send to a Colleague', 'Shared']);
    }
};

var formValidation = {
    fieldFocusID: null,
    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;
                        if (this.fieldFocusID == null) {
                            this.fieldFocusID = validator.controltovalidate;
                        }
                        break;
                    }
                }
            }
        }
        if (mapIDs != undefined) {
            if (mapIDs.checkID != undefined) {
                if (isValid) {
                    $("#" + mapIDs.checkID).removeClass("error");
                } else {
                    $("#" + mapIDs.checkID).addClass("error");
                }
            }
        }
        return isValid;
    },
    validate: function (mapValidator) {
        var isValid = true;
        this.fieldFocusID = null;
        for (var memName in mapValidator) {
            var memObj = mapValidator[memName];
            if (typeof (memObj) == "function") {
                var flag = memObj();
                if (flag == false)
                    isValid = false;
            }
        }
        if (!isValid) {
            $("#" + this.fieldFocusID).focus();
        }
        return isValid;
    },
    enableValidators: function (validatorArray, flag) {
        for (var i = 0; i < validatorArray.length; i++) {
            document.getElementById(validatorArray[i]).enabled = flag;
        }
    }
};
