/**
 * @author Jesse
 */

 
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

$(document).ready(function () {


    $("form").each(function (i) {
        var required = $(this).find("input[name='required']");

        if (required && required.val()) {

            $(this).validate();

            var fields = $(required).val().split('|');

            for (var i = 0; i < fields.length; i++) {
                var obj = $("[name='" + fields[i] + "']");
                obj.addClass('required');
            }

        }
    });
    
    $('.jtree').treeview({
        collapsed:true,
        unique:true
    });

    var ct = document.getElementById('CallTodayFlash');
    var params = { flashvars: "pagename=" + PageName + "&" + "bgcolor=0x" + BackgroundColor + "&textcolor=0x" + ForegroundColor + "&text1coloron=0x" + Text1ColorOn + "&arrowcolor=0x" + ArrowColor + "&text2coloroff=0x" + Text2ColorOff + "&alt1textcolor=0x" + Alt1TextColor + "&phone=" + PhoneNumber + "&featureImage=" + FeatureImage + "&featureLink=" + FeatureLink, wmode: "transparent" };

    if (ct) {
        swfobject.embedSWF("/images/cm/201042010274762127001/ensign-calltodayBar.swf", "CallTodayFlash", "558", "60", "9.0.0", "expressInstall.swf", false, params, { id: "callToday", name: "callToday" });
    }

    var mt = document.getElementById('MainTitleFlash');
    if (mt) {

        swfobject.embedSWF("/images/cm/201042010274762127001/ensign-titlebar_WH.swf", "MainTitleFlash", "540", "34", "9.0.0", "expressInstall.swf", false, params, { id: "titleBar", name: "titleBar" });
    }

    var nav = document.getElementById('FlashMenu');
    if(nav) {
        swfobject.embedSWF(TopNav, "FlashMenuHolder", (iscorp ? "647" : "760"), "65", "9.0.0", "expressInstall.swf", false, params, { id: "menu", name: "menu" });
    }

    var wideHome = document.getElementById('WideFlash');

    if (wideHome) {
        swfobject.embedSWF("/images/cm/201042010274762127001/ensign-homeB-v3.swf", "WideFlashHolder", "1016", "500", "9.0.0", "expressInstall.swf", false, params, { id: "widehome", name: "widehome" });
    }
});

