﻿//the functions in this file require the jQuery javascript library
//jQuery.noConflict();

if (typeof Lennar == "undefined") { Lennar = {}; }

//breadcrumb class
Lennar.Breadcrumb = {
    syncUI: function syncBreadcrumb() {
        //if (Lennar.Global.getActorStatus() == 0) {
        $j('.breadCrumbHome').html("Home");
        $j('.breadCrumbHome').attr("href", "/");

        $j('.breadCrumbHome_st').html("Home");
        $j('.breadCrumbHome_st').attr("href", "/");
        //}
        //else {
        //    $j('.breadCrumbHome_st').html("myLennar");
        //    $j('.breadCrumbHome_st').html("myLennar");

        //    if (Lennar.Global.dashUrl != "undefined" && Lennar.Global.dashUrl != "") {
        //        $j('.breadCrumbHome').attr("href", Lennar.Global.dashUrl);
        //        $j('.breadCrumbHome_st').attr("href", Lennar.Global.dashUrl);
        //    }           
        //}
    }
};


//global class
Lennar.Global = {
    ie7ModalWidths: { "generic": 1024, "signIn": 407, "changePassword": 404, "addUpdateContact": 482, "exportContacts": 482, "deleteContact": 482, "editDocument": 464, "deleteDocument": 464, "downloadPhoto": 400, "deletePhoto": 400, "photoList": 723, "sendECard": 400, "clearECard": 400, "sendRefer": 400, "clearRefer": 400, "submitProfileChanges": 400, "deleteMessage": 400, "floorPlan": 446, "share": 504, "rfi": 662, "compare": 710, "compareError": 402, "createAccount": 639, "planCalc": 494, "photoTour": 744, "QMI": 684, "sendDDEmail": 360, "sendDDGarmin": 360 },
    ie7ModalHeights: { "generic": 768, "signIn": 315, "changePassword": 352, "addUpdateContact": 652, "exportContacts": 198, "deleteContact": 164, "editDocument": 328, "deleteDocument": 155, "downloadPhoto": 141, "deletePhoto": 141, "photoList": 492, "sendECard": 138, "clearECard": 128, "sendRefer": 138, "clearRefer": 128, "submitProfileChanges": 128, "deleteMessage": 151, "floorPlan": 1084, "share": 175, "rfi": 620, "compare": 1200, "compareError": 209, "createAccount": 562, "planCalc": 585, "photoTour": 636, "QMI": 526, "sendDDEmail": 180, "sendDDGarmin": 180 },
    modalWidth: function modalWidth(ie7ModalType) {
        //test and catch undefined state
        if (!ie7ModalType) {
            //comment alert before going to production
            //alert("Error ie7ModalType not defined, using generic modal size");
            ie7ModalType = "generic";
        }
        //ie7ModalType is the hash key for which type of modal we are opening. this will lookup and return to a height width.
        return navigator.userAgent.indexOf("MSIE 7") != -1 ? Lennar.Global.ie7ModalWidths[ie7ModalType] + 20 + "px" : "1px";
    },
    modalHeight: function modalHeight(ie7ModalType) {
        //test and catch undefined state
        if (!ie7ModalType) {
            //comment alert before going to production
            //alert("Error ie7ModalType not defined, using generic modal size");
            ie7ModalType = "generic";
        }
        //ie7ModalType is the hash key for which type of modal we are opening. this will lookup and return to a height width.
        return navigator.userAgent.indexOf("MSIE 7") != -1 ? Lennar.Global.ie7ModalHeights[ie7ModalType] + 20 + "px" : "1px";
    },
    actorStatus: 0,
    callBack_OnLogin: null,
    syncUI: function syncGlobalNavigation() {
        Lennar.Global.initLoginBox();
        Lennar.Global.initLogo();
        Lennar.Breadcrumb.syncUI();
    },
    reloadPage: function reloadIt() {
        window.location.reload();
    },
    openSignInModal: function openSignInModal(callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": "/MyLennar/MyAccount/LoginModal.aspx", "width": Lennar.Global.modalWidth("signIn"), "height": Lennar.Global.modalHeight("signIn"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": "/MyLennar/MyAccount/LoginModal.aspx", "width": Lennar.Global.modalWidth("signIn"), "height": Lennar.Global.modalHeight("signIn"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openAccountModal: function openAccountModal(callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": "/MyLennar/MyAccount/CreateAccountModal.aspx", "width": Lennar.Global.modalWidth("createAccount"), "height": Lennar.Global.modalHeight("createAccount"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Create a myLennar Account", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": "/MyLennar/MyAccount/CreateAccountModal.aspx", "width": Lennar.Global.modalWidth("createAccount"), "height": Lennar.Global.modalHeight("createAccount"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Create a myLennar Account" });
        }
    },
    openFloorPlanModal: function openFloorPlanModal(planID, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/floorplanmodal.aspx?planid={0}', planID), "width": Lennar.Global.modalWidth("floorPlan"), "height": Lennar.Global.modalHeight("floorPlan"), "iframe": true, "scrolling": false, "opacity": .6, "title": "FLOOR PLAN", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/floorplanmodal.aspx?planid={0}', planID), "width": Lennar.Global.modalWidth("floorPlan"), "height": Lennar.Global.modalHeight("floorPlan"), "iframe": true, "scrolling": false, "opacity": .6, "title": "FLOOR PLAN" });
        }
    },
    openPlanCalcModal: function openPlanCalcModal(planID, calcType, callback_onClosed) {
        if (calcType == undefined) {
            calcType = 1;
        }
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/calculatormodal.aspx?planid={0}&calcType={1}', planID, calcType), "width": Lennar.Global.modalWidth("planCalc"), "innerHight": Lennar.Global.modalHeight("planCalc"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "close": "Close", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/calculatormodal.aspx?planid={0}&calcType={1}', planID, calcType), "width": Lennar.Global.modalWidth("planCalc"), "innerHight": Lennar.Global.modalHeight("planCalc"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "close": "Close" });
        }
    },
    openInvCalcModal: function openInvCalcModal(invID, calcType, callback_onClosed) {
        if (calcType == undefined) {
            calcType = 1;
        }
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "", "href": String.format('/findhome/calculatormodal.aspx?availid={0}&calcType={1}', invID, calcType), "width": Lennar.Global.modalWidth("planCalc"), "innerHight": Lennar.Global.modalHeight("planCalc"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "close": "Close", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "", "href": String.format('/findhome/calculatormodal.aspx?availid={0}&calcType={1}', invID, calcType), "width": Lennar.Global.modalWidth("planCalc"), "innerHight": Lennar.Global.modalHeight("planCalc"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "close": "Close" });
        }
    },

    openPhotoTourModal: function openPhotoTourModal(photoTourUrl, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": photoTourUrl, "width": Lennar.Global.modalWidth("photoTour"), "innerHight": Lennar.Global.modalHeight("photoTour"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Photo Tour", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": photoTourUrl, "width": Lennar.Global.modalWidth("photoTour"), "innerHight": Lennar.Global.modalHeight("photoTour"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Photo Tour" });
        }

    },
    openUsMapModal: function openUsMapModal(preSelectedState, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/UsMapModal'), "width": "650px", "height": "450px", "iframe": true, "scrolling": false, "opacity": .8, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/UsMapModal'), "width": "650px", "height": "450px", "iframe": true, "scrolling": false, "opacity": .8, "title": " ", "onClosed": function() { window.location.hash = ''; removeWebSessionValues('mapStateCode'); } });
        }
    },
    openQMIModal: function openQMIModal(communityId, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/QuickMoveInModal?comid={0}', communityId), "width": Lennar.Global.modalWidth("QMI"), "innerHight": Lennar.Global.modalHeight("QMI"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/QuickMoveInModal?comid={0}', communityId), "width": Lennar.Global.modalWidth("QMI"), "innerHight": Lennar.Global.modalHeight("QMI"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openSendEcardModal: function openSendEcardModal(homeNumber, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "", "href": String.format('/findhome/ecardmodal?homeNumber={0}', homeNumber), "width": "462px", "height": "760px", "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "", "href": String.format('/findhome/ecardmodal?homeNumber={0}', homeNumber), "width": "462px", "height": "760px", "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openChangePasswordModal: function openChangePasswordModal(callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/MyAccount/changepasswordmodal', "width": Lennar.Global.modalWidth("changePassword"), "height": Lennar.Global.modalHeight("changePassword"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Change Password", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/MyAccount/changepasswordmodal', "width": Lennar.Global.modalWidth("changePassword"), "height": Lennar.Global.modalHeight("changePassword"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Change Password" });
        }
    },
    openEditDocumentModal: function openEditDocumentModal(documentID, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/EditDocumentModal?documentid=' + documentID, "width": Lennar.Global.modalWidth("editDocument"), "height": Lennar.Global.modalHeight("editDocument"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Edit Document", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/EditDocumentModal?documentid=' + documentID, "width": Lennar.Global.modalWidth("editDocument"), "height": Lennar.Global.modalHeight("editDocument"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Edit Document" });
        }
    },
    openDeleteDocumentModal: function openDeleteDocumentModal(documentID, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DeleteDocumentModal?documentid=' + documentID, "width": Lennar.Global.modalWidth("deleteDocument"), "height": Lennar.Global.modalHeight("deleteDocument"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Verify Delete", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DeleteDocumentModal?documentid=' + documentID, "width": Lennar.Global.modalWidth("deleteDocument"), "height": Lennar.Global.modalHeight("deleteDocument"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Verify Delete" });
        }
    },
    openDownloadPhotoModal: function openDownloadPhotoModal(callback_onClosed) {

        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DownloadPhotoModal', "width": Lennar.Global.modalWidth("downloadPhoto"), "height": Lennar.Global.modalHeight("downloadPhoto"), "iframe": true, "scrolling": false, "opacity": .6, "title": "No Photos Were Selected to Download", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DownloadPhotoModal', "width": Lennar.Global.modalWidth("downloadPhoto"), "height": Lennar.Global.modalHeight("downloadPhoto"), "iframe": true, "scrolling": false, "opacity": .6, "title": "No Photos Were Selected to Download" });
        }
    },
    openDeletePhotoModal: function openDeletePhotoModal(callback_onClosed) {

        photoIds = $j("input:checked", "#MyHomePhotos").map(function(i, elem) { // Find active images
            return elem.parentNode.getAttribute('name'); // Convert elements to their IDs
        }).get().join(); // Retrieve the ID array and concatenate them

        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DeletePhotoModal?photoIDs=' + photoIds, "width": Lennar.Global.modalWidth("deletePhoto"), "height": Lennar.Global.modalHeight("deletePhoto"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/DeletePhotoModal?photoIDs=' + photoIds, "width": Lennar.Global.modalWidth("deletePhoto"), "height": Lennar.Global.modalHeight("deletePhoto"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openHomePhotoListModal: function openHomePhotoListModal(photoID, callback_onClosed) {

        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/HomePhotoList?photoID=' + photoID, "width": Lennar.Global.modalWidth("photoList"), "height": Lennar.Global.modalHeight("photoList"), "iframe": true, "scrolling": false, "opacity": .6, "title": "My Home Photos", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/Documents/HomePhotoList?photoID=' + photoID, "width": Lennar.Global.modalWidth("photoList"), "height": Lennar.Global.modalHeight("photoList"), "iframe": true, "scrolling": false, "opacity": .6, "title": "My Home Photos" });
        }
    },
    openSubmitProfileChangesModal: function openSubmitProfileChangesModal(changeId, callback_onClosed) {

        acceptedChanges = $j("input[type='radio'][id$='Accept']:checked").map(function(i, elem) { return this.value; }).get().join();

        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/MyAccount/SubmitProfileChangesModal?ID=' + changeId + '&AC=' + acceptedChanges, "width": Lennar.Global.modalWidth("submitProfileChanges"), "height": Lennar.Global.modalHeight("submitProfileChanges"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Submit Profile Changes", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": '/MyLennar/MyAccount/SubmitProfileChangesModal?ID=' + changeId + '&AC=' + acceptedChanges, "width": Lennar.Global.modalWidth("submitProfileChanges"), "height": Lennar.Global.modalHeight("submitProfileChanges"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Submit Profile Changes" });
        }
    },
    logoutUser: function logoutUser(callback_onSuccess, callback_onFailed) {
        //call method to sign out user
        $j.ajax(
                {
                    type: "POST",
                    //data: "{ userName:'" + un + "', password:'" + pw + "'}",
                    url: "/Services/profile.asmx/LogoutUser",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    success: function(e) {
                        Lennar.Global.logoutUser_onSuccess(e, callback_onSuccess);
                    },
                    error: function(e) {
                        Lennar.Global.logoutUser_onFailed(e, callback_onFailed);
                    }
                }
                );
    },
    loginUser: function loginUser(un, pw, rm, callback_onSuccess, callback_onFailed) {
        $j.ajax(
                {
                    type: "POST",
                    data: "{ userName:'" + un + "', password:'" + pw + "', rememberMe:" + rm + "}",
                    url: "/Services/profile.asmx/LoginUser",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    success: function(e) {
                        Lennar.Global.loginUser_onSuccess(e, callback_onSuccess);
                    },
                    error: function(e) {
                        Lennar.Global.loginUser_onFailed(e, callback_onFailed);
                    }
                }
                );
    },

    openRFIModal: function(commId, planId, inventoryId, controlId, actorStatus) {
        lpSendData('page', 'PageName', 'request for more information');
        lpSendData('session', 'ConversionAction', 'request info');

        var url = String.format("/contact/contactusmodal?comid={0}&planid={1}&availid={2}&ctrlID={3}&authSt={4}", commId, planId, inventoryId, controlId, actorStatus);

        parent.$j.colorbox({
            "open": true,
            "close": "Close",
            "href": url,
            "width": "662px",
            "height": "720px",
            "iframe": true,
            "scrolling": false,
            "opacity": .6,
            "title": "Request Info"
        });
        return false;
    },
    openVideoTourWindow: function VideoTourWindow(URL) {
        window.open(URL, "", "toolbar=0,location=0,menubar=0, alwaysRaised=yes, resizable");
    },
    openRFIQuestionAboutYourHome: function RFIQuestionsAboutYourHome() {
        window.location.href = "/contact/askabouthome.aspx";
    },
    openRFISubmitCustomerCareRequest: function RFISubmitCustomerCareRequest() {
        window.location.href = "/contact/warranty.aspx";
    },
    openRFISubmitCorpCustomerCareRequest: function RFISubmitCorpCustomerCareRequest() {
        window.location.href = "/contact/CorpCustomerCare.aspx";
    },
    openRFIFindANewHome: function RFIFindANewHome() {
        window.location.href = "/contact/findHome.aspx";
    },
    openRFIStayUpToDate: function RFIFindANewHome() {
        window.location.href = "/contact/findHome.aspx?EmailUpdate=1";
    },
    openRFICareers: function RFICareers() {
        window.location.href = "/contact/careers";
    },
    openRFIMortgageQuestions: function RFIMortgageQuestions() {
        window.open("https://www.uamc.com/");
    },
    openRFIRealtor: function RFIRealtor() {
        window.location.href = "/contact/realtors.aspx";
    },
    openRFIInvestors: function RFIInvestors() {
        window.location.href = "/contact/investorrelations.aspx";
    },
    openRFILandForSale: function RFILandForSale() {
        window.location.href = "/contact/landforsale.aspx";
    },
    openRFIPartners: function RFIPartners() {
        window.location.href = "/contact/businesspartners.aspx";
    },
    openRFIWebmaster: function RFIContactOurWebmaster() {
        window.location.href = "/contact/webmaster.aspx";
    },
    logoutUser_onSuccess: function logoutUser_onSuccess(e, callback) {

        window.location = "/";

        //call success method for method that initially invoked logout
        if (typeof callback == 'function') { callback(e) };
    },
    logoutUser_onFailed: function logoutUser_onFailed(e, callback) {
        //add global logic here if needed
        //        
        //call success method for method that initially invoked logout
        if (typeof callback == 'function') { callback(e) };
    },
    loginUser_onSuccess: function logoutUser_onSuccess(e, callback) {
        //call success method for method that initially invoked logout
        if (typeof callback == 'function') { callback(e) };
    },
    loginUser_onFailed: function logoutUser_onFailed(e, callback) {
        //add global logic here if needed
        //
        //call success method for method that initially invoked logout
        if (typeof callback == 'function') { callback(e) };
    },
    getActorStatus: function getActorStatus() {
        return Lennar.Global.actorStatus;
    },
    setActorStatus: function setActorStatus(actorStatus) {
        Lennar.Global.actorStatus = actorStatus;
    },
    initLogo: function initLogo() {
        //if (Lennar.Global.actorStatus == 0) { //guest
        $j('#myLogo').hide();
        $j('#lennarLogo').show();
        //}
        //else if (Lennar.Global.actorStatus == 1 || Lennar.Global.actorStatus == 2) { //passive or active
        //    $j('#myLogo').show();
        //    $j('#lennarLogo').hide();
        //}
    },
    initLoginBox: function initLoginBox() {
        if (Lennar.Global.actorStatus == 0) { //guest

            $j('#divGlobalGuestUser').show();
            $j('#divGlobalAuthUser').hide();
            $j('#topnaviholder').show();
            $j('#lnkSignOut').hide();
        }
        else if (Lennar.Global.actorStatus == 1 || Lennar.Global.actorStatus == 2) { //passive or active
            $j('#divGlobalGuestUser').hide();
            $j('#divGlobalAuthUser').show();
            $j('#topnaviholder').show();
            $j('a[href="/myLennar/Dashboard"]>img').hover(ShowSignOut, HideSignOut);
            $j('#lnkSignOut').mouseout(function() {
                $j('#lnkSignOut').hide();
            }).mouseover(function() {
                $j('#lnkSignOut').show();
            });

            $j('#lnkSignOut').hide();
        }
    },
    openShareModal: function openShareModal(options) {
        var urlString;
        if (options.urlParams) {
            urlString = "/findhome/share" + options.urlParams;
        } else {
            if (options.element) {
                var el;
                if (options.element.nodeName === "SPAN") {
                    el = options.element.parentNode
                } else {
                    el = options.element;
                }
                var _euc = encodeURIComponent,
                href = _euc(absoluteUrl(trim(el.attributes.getNamedItem("href").value))),
                title = _euc(trim(el.attributes.getNamedItem("title").value));
                urlString = "/findhome/share?url=" + href + "&title=" + title;
            } else {
                urlString = "/findhome/share" + urlParams();
            }
        }
        if (options.onClosed && typeof options.onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "width": Lennar.Global.modalWidth("share"), "height": Lennar.Global.modalHeight("share"), "href": urlString, "iframe": true, "scrolling": false, "opacity": .6, "title": "SHARE THIS VIA:", "onClosed": options.onClosed });
        } else {
            parent.$j.colorbox({ "open": true, "close": "Close", "width": Lennar.Global.modalWidth("share"), "height": Lennar.Global.modalHeight("share"), "href": urlString, "iframe": true, "scrolling": false, "opacity": .6, "title": "SHARE THIS VIA:" });
        }
    },
    openEmailFriendModal: function openEmailFriendModal(options) {
        var urlString;
        if (options.urlParams) {
            urlString = "/findhome/share" + options.urlParams;
        } else {
            if (options.element) {
                var el;
                if (options.element.nodeName === "SPAN") {
                    el = options.element.parentNode
                } else {
                    el = options.element;
                }
                var _euc = encodeURIComponent, href = _euc(absoluteUrl(trim(el.attributes.getNamedItem("href").value))),
                title = _euc(trim(el.attributes.getNamedItem("title").value));
                urlString = "/findhome/share?url=" + href + "&title=" + title;
            } else {
                urlString = "/findhome/share" + urlParams();
            }
        }
        if (options.onClosed && typeof options.onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "", "href": urlString, "width": Lennar.Global.modalWidth("share"), "height": Lennar.Global.modalHeight("share"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": options.onClosed });
        } else {
            parent.$j.colorbox({ "open": true, "close": "", "href": urlString, "width": Lennar.Global.modalWidth("share"), "height": Lennar.Global.modalHeight("share"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openAddUpdatePersonalContact: function openAddUpdatePersonalContact(action, id, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/AddUpdateYourContact?action={0}&id={1}', action, id), "width": Lennar.Global.modalWidth("addUpdateContact"), "height": Lennar.Global.modalHeight("addUpdateContact"), "iframe": true, "scrolling": false, "opacity": .6, "title": " ", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/AddUpdateYourContact?action={0}&id={1}', action, id), "width": Lennar.Global.modalWidth("addUpdateContact"), "height": Lennar.Global.modalHeight("addUpdateContact"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openDeletePersonalContact: function openDeletePersonalContact(action, id, callback_onClosed) {
        if (typeof callback_onClosed == 'function') {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/AddUpdateYourContact?action={0}&id={1}', action, id), "width": Lennar.Global.modalWidth("deleteContact"), "height": Lennar.Global.modalHeight("deleteContact"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Verify Delete", "onClosed": function() { callback_onClosed(); } });
        }
        else {
            parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/AddUpdateYourContact?action={0}&id={1}', action, id), "width": Lennar.Global.modalWidth("deleteContact"), "height": Lennar.Global.modalHeight("deleteContact"), "iframe": true, "scrolling": false, "opacity": .6, "title": " " });
        }
    },
    openSendDDEmail: function openSendDDEmail(myComid) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": '/contact/sendDDemail.aspx?comid=' + myComid, "width": Lennar.Global.modalWidth("sendDDEmail"), "height": Lennar.Global.modalHeight("sendDDEmail"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Email Directions" });
    },
    openSendDDGarmin: function openSendDDGarmin(myComid) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": '/contact/sendDDGarmin.aspx?comid=' + myComid, "width": "360px", "height": "330px", "iframe": true, "scrolling": false, "opacity": .6, "title": "Send My Garmin Directions" });
    },
    openYourContactsExport: function openYourContactsExport() {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": '/myLennar/ExportYourContactsModal', "width": Lennar.Global.modalWidth("exportContacts"), "height": Lennar.Global.modalHeight("exportContacts"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Select Export Format" });
    },
    openReferFriendModalClear: function openReferFriendModalClear(contactIDs) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/ReferFriendModals?action={0}', 'CLEAR'), "width": Lennar.Global.modalWidth("clearRefer"), "height": Lennar.Global.modalHeight("clearRefer"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Confirm Action" });
    },
    openReferFriendModalSend: function openReferFriendModalSend(emailAddress) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/myLennar/ReferFriendModals?action={0}&address={1}', 'SEND', emailAddress), "width": Lennar.Global.modalWidth("sendRefer"), "height": Lennar.Global.modalHeight("sendRefer"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Refer a Friend" });
    },
    openECardSendModalClear: function openECardSendModalClear(contactIDs) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/ECardSendModal?action={0}', 'CLEAR'), "width": Lennar.Global.modalWidth("clearECard"), "height": Lennar.Global.modalHeight("clearECard"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Confirm Action" });
    },
    openECardSendModalSend: function openECardSendModalSend(emailAddress) {
        parent.$j.colorbox({ "open": true, "close": "Close", "href": String.format('/findhome/ECardSendModal?action={0}&address={1}', 'SEND', emailAddress), "width": Lennar.Global.modalWidth("sendECard"), "height": Lennar.Global.modalHeight("sendECard"), "iframe": true, "scrolling": false, "opacity": .6, "title": "Send E-Card" });
    },
    //stringify modifier for use with JSON2.js when prototype is also included, such as when a sitecore user is using the page editor
    stringifyHandler: function stringifyHandler(key, value) {
        if ((typeof this[key] == 'object' && Object.prototype.toString.apply(this[key]) === '[object Array]') ||
         (typeof this[key] == 'function' && Object.prototype.toString.apply(this[key]) === '[object Function]')) {
            return this[key];
        } else {
            return value;
        }
    },
    autoResizeModal: function autoResizeModal(switchDiv) {
        var $frameBody = $j(document);
        var targetHeight = $frameBody.height();
        var targetWidth = $frameBody.width();

        if (switchDiv == true) {
            topDiv = ".std-modal-template";
            $frameBody = $j(topDiv);
            targetHeight = $frameBody.height();
            targetWidth = $frameBody.width();
        }

        if (!targetHeight) {
            $frameBody = $j(document);
            targetHeight = $frameBody.height();
            targetWidth = $frameBody.width();
        }
        parent.$j.colorbox.resize({ innerHeight: targetHeight, innerWidth: targetWidth });

        //alert("resized to height: " + targetHeight + "\nresized to width: " + targetWidth);
    },
    styleInputs: function styleInputs() {
        //Added divs and spans to forms to help with styling
        //if you have a an input select or text area you don't want styled add the class="ns"
        //you can assign multiple classes to an item class="oneClass twoClass"

        $j("input[type=text]").not(".ns,.sa").wrap('<div class="txtbox" />').addClass("sa");
        $j("input[type=password]").not(".ns,.sa").wrap('<div class="txtbox" />').addClass("sa");
        $j("select").not(".ns,.sa").wrap('<div class="selectbox" />').addClass("sa");
        $j("textarea").not(".ns,.sa").wrap('<div class="txareabox" />').addClass("sa");
        $j(".txtbox").not(".ns,.sa").append("<span />").addClass("sa");
        $j(".txareabox").not(".ns,.sa").append("<span />").addClass("sa");

    }
};

function absoluteUrl(url) {
    if (url.search(/(ht|f)tps?:/i) == -1)
        return 'http://' + document.domain + url;
    return url;
}
function trim(a) { return ("" + a).replace(/(^\s+|\s+$)/g, ""); }
function urlParams() {
    var _euc = encodeURIComponent, M = document, L = M.location, T = M.title, H = L ? L.href : null;
    return "?url=" + _euc(absoluteUrl(trim(H))) + "&title=" + _euc(trim(T));
}

function SwapImage(senderElem, newImageSrc) {
    $j(senderElem).attr('src', newImageSrc);
}

function GetOpenRFIScript(commNbr, planNbr, invNbr, itemID) {
    return "Lennar.Global.openRFIModal('" + commNbr + "','" + planNbr + "','" + invNbr + "','fav" + itemID + "','" + Lennar.Global.actorStatus + "')";
}

function ShowSignOut() {
    var sender = $j(this);
    var pos = sender.offset();
    var height = sender.height();

    //show the menu directly over the placeholder
    $j(".signout-hldr").css({ "left": pos.left + "px", "top": (pos.top + height - 11) + "px" }).show();
    $j('#lnkSignOut').show();
}

function HideSignOut() {
    $j('#lnkSignOut').hide();
}


Lennar.Calculator = {
    isDirty: false,
    closeModal: function closeModal() {
        parent.$j.colorbox.close = Lennar.Calculator.originalClose;
        Lennar.Calculator.originalClose();
    },
    openSavePreferencesModal: function openSavePreferencesModal() {
        if (!Lennar.Calculator.isDirty) {
            Lennar.Calculator.closeModal();
        }

        else if (Page_IsValid) {
            $j('#divSavePreferences').show();
        }
    },
    showMessage: function showMessage(messageElementId) {
        $j("#" + messageElementId).show();
    },
    hideMessage: function hideMessage(messageElementId) {
        $j("#" + messageElementId).hide();
    },
    refreshParent: function refreshParent() {
        if (typeof parent.Lennar.Global.callBack_OnSavePreferences == 'function') {
            parent.Lennar.Global.callBack_OnSavePreferences();
        }
        else {
            parent.Lennar.Global.reloadPage();
        }
    }
};

function InitializeUI() {
    if (typeof Lennar == "undefined") {
        Lennar = {};
    }

    //initialize namespace if it is undefined
    if (typeof Lennar.Compare == "undefined") {
        Lennar.Compare = {};
    }

    Lennar.Global.styleInputs();

    Lennar.Global.syncUI();

    //intercept microsoftValidator
    if (window.ValidatorUpdateIsValid) {
        //alert("page with validator");
        var myValidator = ValidatorUpdateIsValid;
        ValidatorUpdateIsValid = function() {
            //alert("before");
            if (myValidator) {
                myValidator();
                Lennar.Global.autoResizeModal();
                //                if (Page_IsValid) {
                //                    alert("Passed Validation");
                //                } else {
                //                    alert("Failed Validation");
                //                }
            }
            //            alert("after");
        }
    }
}

$j(document).ready(function() {
    InitializeUI();
});


