﻿/* ENL Utils Start*/
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	for (i = 0, j = 0; i < elsLen; i++) {
		if (  els[i].className.indexOf(searchClass) > -1 ) {
			classElements[j] = els[i];
			j++;
		} 
	}
	return classElements;
}

// Get URL Parameter
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

// add commas to a number
var formatNumber = function(number){
    number += "";
    var parts = number.split('.');
    var integer = parts[0];
    var decimal = parts.length > 1 ? '.' + parts[1] : '';
    var regex = /(\d+)(\d{3})/;
    while (regex.test(integer)){
        integer = integer.replace(regex, '$1' + ',' + '$2');
    }
    return integer + decimal;
}; 

function siteSearch(link, element) {
    var searchInput = document.getElementById(element).getElementsByTagName('input')[0];
    var regEx = /[^a-z0-9\s.,-]/gi;
    var query = searchInput.value.replace(/^\s*|\s*$/,"");
    if(searchInput.value == "Enter Keywords" || searchInput.value == "" || searchInput.value == " ") {                       
         alert('Please enter keywords.'); 
         searchInput.focus();
    }
    else if (regEx.test(query)) {
        alert('Please use only alpha-numeric characters');
        searchInput.focus();
    } 
    else {        
            // Trim white space from both ends of query
            query = query.replace(/^\s+|\s+$/g, '');
            
            query=query.replace('=','%3D');
            query=query.replace('&','%26');
            query=query.replace('?','%3F');
            query=query.replace('#','%23');
            
            window.location = link + "?q=" + query + "&filter=0";
        }
    }
    
function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
         }
      }
   return IsNumber;
}
  
///// The following functions contain some CBC-specific code /////////

function conditionalClear(current, field) {
    if (current == "Enter Keywords" || current == "Enter City or ZIP" || current == "Enter name") {                       
        field.value = " ";                           
    }
}

function submitEnter(e, link, element){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13 || keycode == 3) {
        siteSearch(link, element);
        return false;
    }
    else {
     return true;
 }
}

function submitEnterDirections(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13 || keycode == 3) {
        validateDirectionsInput();
        return false;
    }
    else {
        return true;
    }
}

function openCenteredWindow(mypage, w, h, scroll, resizable, menubar, toolbar) {   
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar+',location=0,status=0';
    window.open(mypage,'',winprops)
} 

function openWindow(url, width, height) {
    window.open(url, 'printFriendly', 'width=' + width + ',height=' + height + ',resizable=1,menubar=0,toolbar=0,scrollbars=1,location=no,status=no');
}

function openOffsiteLink(url) {
    window.open("warning.aspx?url="+url, '', 'width=600,height=400,resizable=1,menubar=1,toolbar=1,scrollbars=1,location=1,status=1');
}

// Photo Gallery Controls
function initGallery() {
    $('.controls a').click(function(e) { 
        var galleryIndex = this.id.replace("galleryBtn", "");
        FetchItemHtml(xmlPath, xslt, galleryIndex);
        e.preventDefault();
    });
}

function validateZIP(field) {
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length!=5 && field.length!=10) {
        alert("Please enter your 5 digit or 5 digit+4 zip code.");
        return false;
    }
    for (var i=0; i < field.length; i++) {
        temp = "" + field.substring(i, i+1);
        if (temp == "-") hyphencount++;
        if (valid.indexOf(temp) == "-1") {
            alert("Invalid characters in your zip code.  Please try again.");
            return false;
        }
        if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
            alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
            return false;
        }
    }
    return true;
}

function setCookie(c_name,value){    
    document.cookie=c_name + "=" + value+"; path=/";    
}

function getCookie(c_name){
    if (document.cookie.length>0) {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1) {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

//Region Selector functions and variables
var regionSelectorHref;
var regionSelectorZip;
var regionSelectorRadius;
var isFyh; 
var isHomeowners;
var isRealtorSubNav;
var isSiteMap;
var selectorLeft = 0;
var selectorTop = 0;


// checks profile for state and region... if none, then show the region selector drop-down
function initRegionSelector() {
    $("a.navFindYourHome, #secondaryNav a.realtors, #secondaryNav a.homeowners, #fyhCrumbLink, .realtorRegion a, a.smFyh, a.smRealtors, a.smHomeowners").click(function(e) {
        regionSelectorHref = $(this).attr("href");
        isFyh = $(this).hasClass("navFindYourHome");
        isHomeowners = $(this).hasClass("homeowners");
        isRealtorSubNav = $(this).hasClass("realtorSubnav");
        isSiteMap = $(this).hasClass("smRealtors") | $(this).hasClass("smFyh") | $(this).hasClass("smHomeowners");

        if (isSiteMap) {
            if ($.browser.msie & $.browser.version < 8) {
                selectorLeft = $(this).offset().left - 134;
                selectorTop = $(this).offset().top + 19;
            }
            else {
                selectorLeft = this.offsetLeft - 4;
                selectorTop = this.offsetTop + 126;
            }
        }

        e.preventDefault();
        retValue = Consumer.portfolioWebservice.GetProfileStateAndRegion(onGetUserRegionSuccess, onWSFailure);
        return (retValue);
    });     
    
    $("#globalRegionSelector .closeButton a").click(function() {
        $("#globalRegionSelector").hide();   
        $("#globalRegionSelector").removeAttr("css");
        
    });
    
    if(document.getElementById("realtorNoRegion")) {
        isRealtorSubNav = true;
        onGetUserRegionSuccess("|||");
    }
}

function onGetUserRegionSuccess(args){
    var locationParams = "";
    var state = "";
    var region = "";
    if(args != "|||" && args!="" && args !=null) {
        locationParams = "&state=" + args.substring(0, args.indexOf("|||")) +"&region=" + args.substring(args.indexOf("|||")+3);
    }    
    
    if(locationParams == "" | locationParams == null | isRealtorSubNav) {                      
        if(isFyh) {
            $("#globalRegionSelector").removeClass("realtorSelector");
            $("#globalRegionSelector").addClass("fyhSelector");            
            $("a.navFindYourHome").addClass("selectedR");
            $("#secondaryNav a.realtors, #secondaryNav a.homeowners").removeClass("selectedR");
            $("#globalRegionSelector").removeAttr("style");             
        }
        else if(isHomeowners) {
            $("#globalRegionSelector").removeClass("realtorSelector");
            $("#globalRegionSelector").removeClass("fyhSelector");
            $("#globalRegionSelector").removeClass("realtorSubNavSelector"); 
            $("#globalRegionSelector").addClass("homeownersSelector");                
            $("#secondaryNav a.homeowners").addClass("selectedR");
            $("#secondaryNav a.realtors, a.navFindYourHome").removeClass("selectedR");   
            $("#globalRegionSelector").removeAttr("style");
        }
        else if(isRealtorSubNav) {
            $("#globalRegionSelector").removeClass("realtorSelector");
            $("#globalRegionSelector").removeClass("fyhSelector");
            $("#globalRegionSelector").removeClass("homeownersSelector");
            $("#globalRegionSelector").addClass("realtorSubNavSelector");                
            $("#secondaryNav a.realtors, a.navFindYourHome").removeClass("selectedR"); 
            $("#globalRegionSelector").removeAttr("style"); 
        }
        else if (isSiteMap) {
            $("#globalRegionSelector").css("left", selectorLeft + "px");
            $("#globalRegionSelector").css("top", selectorTop + "px");     
            $("#globalRegionSelector").addClass("realtorSelector");
            $("#globalRegionSelector").removeClass("fyhSelector");
            $("#globalRegionSelector").removeClass("homeownersSelector");
            $("#globalRegionSelector").removeClass("realtorSubNavSelector")
            $("#globalRegionSelector").show();
        }
        else {
            $("#globalRegionSelector").removeClass("fyhSelector");
            $("#globalRegionSelector").removeClass("homeownersSelector");
            $("#globalRegionSelector").removeClass("realtorSubNavSelector"); 
            $("#globalRegionSelector").addClass("realtorSelector");
            $("#secondaryNav a.realtors").addClass("selectedR"); 
            $("a.navFindYourHome, #secondaryNav a.homeowners").removeClass("selectedR");  
            $("#globalRegionSelector").removeAttr("style");  
   
        }            
        $("#comparePanel, #ctaOptions, #signInPanel").slideUp();
        $("#portfolioNav").removeClass("open");
        $("#globalRegionSelector").show();
                               
    } 
    else {
        if(regionSelectorHref.indexOf("?") > -1) {
            window.location = regionSelectorHref + locationParams;
        }
        else {
            window.location = regionSelectorHref;
        }
    }
}

function activateDropDowns() {
    $('.stateListHolder li').mousedown(function() {
        regionSelectorState = $(this).attr("id");
        regionSelectorState= regionSelectorState.replace("stateDropDown2_input_", "");
        regionSelectorState= regionSelectorState.replace("stateDropDown_input_", "");
        regionSelectorRegion = "";
        FetchRegionsByStateXml(regionSelectorState, xslt);        
    });
    if(document.getElementById("zipRadiusSelect")) {
        regionSelectorRadius =  $('#zipRadiusSelect li').attr("id");
        regionSelectorRadius = regionSelectorRadius.replace("zipRadius_input_", "");    
        activateRegionDropDown();  
        $('#zipRadiusSelect li').mousedown(function() {
            regionSelectorRadius = $(this).attr("id");
            regionSelectorRadius = regionSelectorRadius.replace("zipRadius_input_", "");
        }); 
    }  
    if($("#stateDropDown").val() != ""){activateRegionDropDown();}   
}

function onWSFailure(args) {
    alert("Error calling onGetUserRegionSuccess web service method.");
}

function onWSFailure2(args) {
    alert("Error calling web service SetProfileStateAndRegion method.");
}    

function activateRegionDropDown() {    
    $('.regionListHolder li').mousedown(function() {
        regionSelectorRegion = $(this).attr("id");
        regionSelectorRegion = regionSelectorRegion.replace("regionDropDown2_input_", "");
        regionSelectorRegion = regionSelectorRegion.replace("regionDropDown_input_", "");    
    });
    $('#globalRegionSelector .regionListHolder li').mousedown(function() {        
        if (regionSelectorState != "" && regionSelectorRegion != "") {
            var locationParams = "&state=" + regionSelectorState + "&region=" + regionSelectorRegion;
            if (Consumer) {
                retValue = Consumer.portfolioWebservice.SetProfileStateAndRegion(regionSelectorState, regionSelectorRegion, onSetProfileStateAndRegionSuccess, onWSFailure2);
            }
            return (retValue);
        }
    });         
}

function onSetProfileStateAndRegionSuccess(args) {
    if(isRealtorSubNav) {        
        var theUrl = window.location.href;        
        if(gup("state") && gup("region")) {
            theUrl = theUrl.replace(gup("state"), regionSelectorState);
            theUrl = theUrl.replace(gup("region"), regionSelectorRegion);        
        }
        else if(theUrl.indexOf("?") > -1) {
            theUrl = theUrl + "&state=" + regionSelectorState + "&region=" + regionSelectorRegion;
        }
        else {
            theUrl = theUrl + "?state=" + regionSelectorState + "&region=" + regionSelectorRegion;
        }
        
        window.location.href=theUrl;
    }
    else if(regionSelectorHref.indexOf("?") > -1 & isFyh) {
        window.location = regionSelectorHref + "&state=" + regionSelectorState + "&region=" + regionSelectorRegion;    
    }
    else {
        window.location = regionSelectorHref;
    }
}

// End Region Selector functions and variables

//Expand/Collapse
function initExpand() {       
    var open = [];
    var div = [];    
    var anchor = [];
    
    $('.expand').each(function (i) {                   
        open[i] = false;
        div[i] = '#' + this.id;
        var linkClass = 'link' + i;
        anchor[i] = div[i] + ' a';
        
        if($(div[i]).hasClass('expandOpened')) {
            open[i] = true;
        }
        
        $(anchor[i]).addClass(linkClass);     
       
    });
     
    $('.expand h3 a').focus(function(e) { $(this).addClass("highlight");});
    $('.expand h3 a').mouseover(function(e) { $(this).addClass("highlight"); });
    $('.expand h3 a').blur(function(e) { $(this).removeClass("highlight"); });
    $('.expand h3 a').mouseout(function(e) { $(this).removeClass("highlight"); });

    $('.expand h3 a').click(function(e) {
        var j = this.className.substr(this.className.indexOf("link") + 4, 1);
        if (open[j]) {
            $(div[j] + ' .expandInner .wrapper').css("visibility", "hidden");
            $(div[j] + ' .expandInner').slideUp('480');
            $(div[j]).removeClass('expandOpened');
            open[j] = false;
        }
        else {
           
            $(div[j] + ' .expandInner').slideDown('480');
            $(div[j]).addClass('expandOpened');
            setTimeout(
                function() {
                    $(div[j] + ' .expandInner .wrapper').css('visibility', 'visible');
                },
                500
            );
            open[j] = true;
        }
        e.preventDefault();
    });        
}

function appendQueryStringParameter(theUrl, paramName, paramValue) {
    var newUrl = theUrl.replace(/#/, "");
    if (theUrl.indexOf("?") < 0){
        newUrl = newUrl + "?" + paramName + "=" + paramValue;
    } else {
        newUrl = newUrl + "&" + paramName + "=" + paramValue;
    } 
    return newUrl;
}

function printThisPage(thePageUrl) {
    if (thePageUrl.indexOf("Estimate-Payments") > -1 || thePageUrl.indexOf("Map-Directions") > -1) {
        window.print();
    } else {
        var thePrintUrl = appendQueryStringParameter(thePageUrl, "print", "yes");
        openWindow(thePrintUrl, '672', '700');
    }
}
function popupThisPage(thePageUrl) {
    var thePopupUrl = appendQueryStringParameter(thePageUrl,"print","yes");
  //  openWindow(thePopupUrl, "672", "700");
    openCenteredWindow(thePopupUrl, "672", "500","yes","yes","yes","yes");
}
function openPrintBrochureWindow() {
    openWindow('Community-Brochure.aspx', '672', '700');
}

function closeAllPanels() {
    $("#comparePanel, #ctaOptions,#globalRegionSelector, #signInPanel").slideUp(); 
    $("#secondaryNav a.realtors, a.navFindYourHome, a.navFindYourHome").removeClass("selectedR"); 
}

function resolveLink(theHref) {
    if(window.location.toString().indexOf("localhost") > -1 && theHref.indexOf("/consumer") < 0)
    {
        return(localpath + theHref);        
    } 
    else {
        return(theHref);
    }
}

function emailFriend(list) {
    window.parent.hidePortfolioPanel();
    var thePage = resolveLink("/Forms/Email-A-Friend.aspx?list=" + list);
    window.parent.lightbox.showPanel(thePage);
}

function RealtorSignUpButtonClick(a) {
    pageRefresh(9);
}

function FixPngsAfterDelay() {
    setTimeout("DD_belatedPNG.fix('.png')", 1000);
}

// inital load function
$(document).ready(function() {
    $("#printPageLink").click(function(e) {
        printThisPage(location.href);
        e.preventDefault();

        //Only ping omniture for home, communities and portfolio
        var thePath = location.href;
        if (thePath.indexOf("/Find-Your-Home/") > -1) {
            s.cstm_link({ pageName: s.pageName + "/Print_Complete",
                prop25: "Print_Complete",
                prop26: "Save-Email-Print"
            });
        } else if (thePath.indexOf("Forms/Portfolio") > -1) {
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/Print_Complete",
                prop25: "Print_Complete",
                prop26: "Save-Email-Print"
            });
        }
    });
    $("#brochurePrintLink, #printLink a").click(function(e) {
        window.print();
        e.preventDefault();
    });
    var isPrintPreview = (gup("print") == "true" || gup("print") == "yes");
    var isLightbox = false;
    if (document.getElementsByTagName("body")[0].className == "lightboxPage") { isLightbox = true }

    if (!isPrintPreview) {
        initExpand();
        if (document.getElementById("globalHeader")) { // Patch: Skip this call if in Form Master page.
            var t = setTimeout("activateDropDowns(); initRegionSelector();", 500);
        }
        if ($.browser.msie && $.browser.version < 7 && !document.getElementById("mapList") && !document.getElementById("formContainer") && !isLightbox) {
            DD_belatedPNG.fix('.png, .png img, .selectbox, .selectbox-wrapper ul, .selectbox-wrapper div, #portfolioNav');
        }
    }

    $("a.New-Window-Large, .New-Window-Large a").click(function(e) {
        var theHref = $(this).attr("href");
        openCenteredWindow(theHref, 800, 575, "yes", "yes", "yes", "yes");
        // or, to open it in the printable view:
        // popupThisPage(theHref);
        e.preventDefault();
    });

    //checkChatImg();
});

/* Original ENL Utils End*/
/* Overlay Panels */
// Call to Action Component
var cta = {    

    init : function() {

        $("#ctaPanelClose,#ctaLink").click(function(e) {
            if(okayToClose()) {                
                e.preventDefault();
                cta.closePanel();                                  
            }            
        } );
        
        $("#ctaLink").click(function(e) {
            cta.openOptions();
            e.preventDefault();
        });
    
        $("a.CTA-Component").click(function(e) {                                 
            var theHref = resolveLink($(this).attr("href"));     
            if($('#ctaOptions').is(":hidden")) {
                cta.openOptions();
            }
            cta.openPanel(theHref);
            e.preventDefault();
        });          
    },
    
    closePanel : function() {
        $("#globalHeader").removeClass("lowZ");
        $("#ctaFormPanel").hide();
        $("#ctaFormPanel iframe").attr("height",0);
        $("#ctaFormPanel iframe").attr("src", "");              
        $("#overlayGray").hide();
        $("#ctaFormPanel").removeClass("open");
    },
    
    openPanel : function(theHref) {
        
        if(document.getElementById("comIdField")) {
          theHref = theHref + "&comId=" + $("#comIdField").val();
        }
        
        
        $("#ctaFormPanel").addClass("open");
        if((theHref.indexOf("Customer-Service-Request") > -1) | (theHref.indexOf("Land-Acquisition") > -1) | (theHref.indexOf("Request-Refinancing-Information") > -1)) { 
            $("#ctaFormPanel").addClass("wide");
            $("#ctaFormPanel iframe").attr("width", 627);   
        }
        else {
            $("#ctaFormPanel").removeClass("wide");
            $("#ctaFormPanel iframe").attr("width", 346);           
        }            
        
        $("#ctaFormPanel").slideDown();                    
        $("#ctaFormPanel iframe").attr("src", theHref);            
        $("#globalHeader").addClass("lowZ");        
        $("#overlayGray").show();  
    }, 
    
    openOptions : function() {
        $("#comparePanel, #globalRegionSelector").slideUp();
        $("#secondaryNav a.realtors, a.navFindYourHome, a.navFindYourHome").removeClass("selectedR"); 
        $('#ctaOptions').slideToggle();    
    }   
}

// Lightbox functions

var lightbox = {

    init: function() {

        $("#comingSoonTeaserContent a").click(function(e) {
            
            var theHref = "/forms/Short-RMI-Join-Interest.aspx";
            
            if(document.getElementById("comIdField")) {
              theHref = theHref + "?comId=" + $("#comIdField").val();
            }
            
            if (window.location.toString().indexOf("localhost") > -1) {
                theHref = localpath + theHref;
            }            
            
            lightbox.showPanel(theHref);            
            
            e.preventDefault();
        });

        $(".submitStory a").click(function(e) {
            if (window.location.toString().indexOf("localhost") > -1) {
                lightbox.showPanel(localpath + "/Forms/Submit-Story.aspx");
            }
            else {
                lightbox.showPanel("/Forms/Submit-Story.aspx");
            }
            e.preventDefault();
        });

        $(".galleryTourTeaser a").click(function(e) {
            var lightboxUrl = "/Discover-Home-Gallery/Home-Gallery-Tour/Lightbox-Flash-Page.aspx";
            var callingPage = location.href;
            var movieContainer = "RICHContainer";
            if (window.location.toString().indexOf("localhost") > -1) {
                lightbox.showPanel(localpath + lightboxUrl);
                //openCenteredWindow(localpath + lightboxUrl, 737, 598, "no", "no", "no", "no");
            }
            else {
                lightbox.showPanel(lightboxUrl);
                //openCenteredWindow(localpath + lightboxUrl, 737, 598, "no", "no", "no", "no");
           }
            
            
            sendToActionScript(movieContainer, 'stop');
            e.preventDefault();
        });

        $(".guideTeaser a").click(function(e) {
            var theHref = $(this).attr("href");

            if ($(this).hasClass("pdfGuideLink")) {

                if (window.location.toString().indexOf("localhost") > -1) {
                    window.open(localpath + "/Guide-Redirect.aspx?pdf=" + theHref);
                }
                else {
                    window.open("/Guide-Redirect.aspx?pdf=" + theHref);
                }
            }
            else {

                if (window.location.toString().indexOf("localhost") > -1) {
                    lightbox.showPanel(localpath + "/forms/Guide-Access.aspx?pdf=" + theHref);
                }
                else {
                    lightbox.showPanel("/forms/Guide-Access.aspx?pdf=" + theHref);
                }


            }
            e.preventDefault();
        });

        $(".ePostcardTeaser a").click(function(e) {
            if (window.location.toString().indexOf("localhost") > -1) {
                lightbox.showPanel(localpath + "/Forms/ePostcard.aspx");
            }
            else {
                lightbox.showPanel("/Forms/ePostcard.aspx");
            }
            e.preventDefault();
        });


        $("a.Lightbox").click(function(e) {
            var lightboxURL = "";
            var parentURL = document.location.href;
            if ($(this).attr("href").indexOf("?") > -1) {
                lightboxURL = $(this).attr("href") + "&parentURL=" + escape(parentURL);
            } else {
                parentURL = parentURL.replace("/consumer", "");
                lightboxURL = $(this).attr("href") + "?parentURL=" + escape(parentURL);
            }
            thePage = resolveLink(lightboxURL);
            lightbox.showPanel(thePage);
            e.preventDefault();
        });

        $(".lbTeaser a, .launcherTeaser a, .successTeaser a").click(function(e) {
            var teaserDivId = $(this).parents(".teaser").attr('id');
            var lightboxContentDiv = document.getElementById(teaserDivId.replace("teaser", "lb"));
            lightbox.showInlinePanel(lightboxContentDiv);
            e.preventDefault();
        });

        $("#financePromoContent a").click(function(e) {
            var lightboxContentDiv = document.getElementById("lb_financePromoContent");
            lightbox.showInlinePanel(lightboxContentDiv);
            e.preventDefault();
        });

        $(".closeLightboxLink").click(function(e) {            
            lightbox.hidePanel();
            e.preventDefault();
        });
    },

    showPanel: function(pageURL) {
        if ($.browser.msie && $.browser.version < 7) {
            window.scroll(0, 0);
        }
        closeAllPanels();

        var theIframe = document.getElementById("lightboxPanel").getElementsByTagName("iframe")[0];

        //show and initiate the overlay
        if (pageURL.indexOf("Home-Gallery-Tour") > -1) {
            $("#lightboxPanel").removeClass("wide");
            $("#lightboxPanel").addClass("hgTour");
            theIframe.width = 737;
            theIframe.height = 598;
        }
        else if (((pageURL.indexOf("Customer-Service-Request") > -1) | (pageURL.indexOf("ePostcard") > -1) | (pageURL.indexOf("Land-Acquisition") > -1) | (pageURL.indexOf("Request-Refinancing-Information") > -1)) | (pageURL.indexOf("/forms/") < 0 & pageURL.indexOf("/Forms/") < 0)) {
            $("#lightboxPanel").addClass("wide");
            $("#lightboxPanel").removeClass("hgTour");
            theIframe.width = 627;
        }
        else {
            $("#lightboxPanel").removeClass("wide");
            $("#lightboxPanel").removeClass("hgTour");
            theIframe.width = 346;
        }

        theIframe.src = pageURL;

        $("#globalHeader, #crumbWrapper, #headerToolsHolder").addClass("lowZ");
        document.getElementById("overlayGray").style.display = "block";

        // add event to close button
        $("#overlayGray").click(function() {
            lightbox.hidePanel();
        });

        if ($.browser.msie) {
            $("#lightboxPanel").show();
        }
        else {
            $("#lightboxPanel").fadeIn();
        }
    },

    showInlinePanel: function(lightboxContentDiv) {
    
        if ($.browser.msie && $.browser.version < 7) {
            window.scroll(0, 0);
        }
    
        if ($.browser.msie && $.browser.version < 8) {
                $("#lightboxPanel").css("background","none");
            }        
        
        $("#lightboxPanel").addClass("wide");
        var theContainer = document.getElementById("lightboxPanel");
        var contentsHeight = lightboxContentDiv.scrollHeight;
      
        $("#lightboxContentDiv").html(lightboxContentDiv.innerHTML);
      
        var maxHeight;
        if (!$.browser.msie) {
            maxHeight = window.parent.innerHeight - 170;
        }
        else {
            maxHeight = window.parent.document.documentElement.clientHeight - 170;
        }       
        if (maxHeight > (contentsHeight - 52)) {
            $("#lightboxContent, .lightboxContent").css("height", contentsHeight - 52 + "px");
            theContainer.style.marginTop = (0 - (contentsHeight + 60) / 2) + "px";
         }
        else {
            $("#lightboxContent, .lightboxContent").css("height", maxHeight + "px");
            theContainer.style.marginTop = (0 - (maxHeight + 60) / 2) + "px";
        }

        $("#globalHeader, #crumbWrapper, #headerToolsHolder").addClass("lowZ");
        document.getElementById("overlayGray").style.display = "block";        

        if ($.browser.msie) {
            $("#lightboxPanel").show();
        }
        else {
            $("#lightboxPanel").fadeIn();
        }

        if (lightboxContentDiv.className.indexOf("successStory") > -1) {
            story.idVal = lightboxContentDiv.id;
            story.initSteps();
        }
    },

    hidePanel: function() {
        if ($.browser.msie) {
            $("#lightboxPanel").hide();
        }
        else {
            $("#lightboxPanel").fadeOut();
        }
        $("#lightboxControls").hide();

        var theIframe = document.getElementById("lightboxPanel").getElementsByTagName("iframe")[0];
        theIframe.src = "";
        theIframe.height = "0";

        var theContainer = document.getElementById("lightboxPanel");

        document.getElementById("overlayGray").style.display = "none";
        theContainer.style.marginTop = "";
        $("#lightboxContent, .lightboxContent").css("height", "auto");

        $("#lightboxContentDiv").html("");
        $("#globalHeader, #crumbWrapper, #headerToolsHolder").removeClass("lowZ");

        $("#lightboxPanel").removeClass("wide");

        if ($("#lightboxPanel").hasClass("hgTour")) {
            var movieContainer = "RICHContainer";
            sendToActionScript(movieContainer, 'resume');
            $("#lightboxPanel").removeClass("hgTour");
        }
    }
}
$(document).ready(function() {
    if (typeof cta !== "undefined") {
        cta.init();
    }
    if (document.getElementById("globalHeader")) {
        lightbox.init();
    }
    
});
/* Overlay Panels End*/
/* Compare */
var compare = {

    height: null,

    pageHref: null,

    queue: "Catalog",

    init: function() {

        //determine if we are working with the portfolio queue
        if ($(".homesArea").is(':visible') || $("#portfolioCompareHeading").is(':visible')) {
            compare.queue = "Portfolio";
        }

        $(".compareTest").click(function(e) {
            compare.showWidget();
            e.preventDefault();
        });

        $("#comparePanelClose").click(function(e) {
            compare.hideWidget();
            e.preventDefault();
        });

        $(".compare input").click(function() {
            var theVal = $(this).val();
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
            }
            if ($(this).is(':checked')) {
                compare.addHome(communityID, homeID, itemPath);
            }
            else {
                compare.removeHome(communityID, homeID);
            }
        });

        $("#container .compareCol a").click(function(e) {
            compare.pageHref = $(this).attr("href");
            compare.goToComparePage();
            e.preventDefault();
        });

        $(".porfolioCompareLink").click(function(e) {
            compare.pageHref = $(this).attr("href").replace("Forms/", "");
            compare.goToComparePageFromPortfolio();
            e.preventDefault();
        });

        $(".comparePageRemoveBtn").click(function(e) {        
            if ($(".compareTable .thumbRow td").size() >= 2) {
                $('.compareTable').removeCol($(".comparePageRemoveBtn").index(this) + 2);
            }
            if ($(".compareTable .thumbRow td").size() == 2) {
                $(".comparePageRemoveBtn").each(function(i) {                        
                    $(this).remove();
                });
            }

            var theVal = $(this).attr("name");
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4);
            compare.removeHome(communityID, homeID);
        });

        if (compare.queue == "Portfolio") {
            retValue = Consumer.portfolioWebservice.GetComparisonHomeCount(guid, compare.queue, compare.onCheckCountForPortfolioComplete, compare.onFailure);
            return (retValue);
        }
         if(document.getElementById("compareTableHeading")){
                
            compare.preCheckBoxes();        
        }    

    },

    showWidget: function() {
        //hide other overlay panels and show the compare panel
        $("#ctaOptions, #globalRegionSelector,#signInPanel").slideUp();
        $("#portfolioNav").removeClass("open");
        $("#secondaryNav a.realtors, a.navFindYourHome, a.navFindYourHome").removeClass("selectedR");

        // set the height of the compare panel
        compare.height = $(window).height();
        if ($.browser.msie && $.browser.version < 7 && document.getElementById("comparePanel")) {
            $("#comparePanel").show();
            var comparePanel = document.getElementById("comparePanel");
            var compareFormArea = document.getElementById("compareFormArea");
            comparePanel.style.height = (comparePanel.clientHeight > ((compare.height - 30) - 1)) ? (compare.height - 30) + "px" : "auto";
            compareFormArea.style.height = (compareFormArea.clientHeight > ((compare.height - 85) - 1)) ? (compare.height - 85) + "px" : "auto";
            comparePanel.style.top = (document.documentElement.scrollTop + 10) + 'px';

        }
        else {
            $("#comparePanel").css("max-height", (compare.height - 30) + "px");
            $("#comparePanel .formArea").css("max-height", (compare.height - 85) + "px");
            $("#comparePanel").slideDown();
        }

        // add click event to remove all link
        $("#compareWidgetRemoveAllLink").click(function(e) {
            compare.removeAllHomes();
            e.preventDefault();
        });

        // add click event to the individual remove links
        $(".compareWidgetRemoveLink").click(function(e) {
            var theVal = $(this).attr("id");
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4);
            compare.removeHome(communityID, homeID);
        });

        if ($("#compareListTable .thumbnailCol").size() >= 5) {
            $("#summaryListTable .compare input:not(:checked)").attr("disabled", "disabled");
        }
        else {
            $("#summaryListTable .compare input").removeAttr('disabled');
        }
        
    },
    
    preCheckBoxes: function() {
        retValue = Consumer.portfolioWebservice.GetComparisonHomesAsString(guid, "~/xslt/CompareBoxesToCheck.xslt", compare.queue, compare.preCheckBoxesComplete, compare.onFailure);
        return (retValue);
    },

    hideWidget: function() {
        $("#comparePanel").slideUp();
    },

    addHome: function(communityID, homeID, itemPath) {
        retValue = Consumer.portfolioWebservice.AddComparisonHome(guid, communityID, homeID, itemPath, compare.queue, compare.onAddComplete, compare.onFailure);
        return (retValue);
    },

    removeAllHomes: function() {
        $(".compare input").removeAttr("checked");
        retValue = Consumer.portfolioWebservice.DeleteAllComparisonHomes(guid, compare.queue, compare.onDeleteAllHomesComplete, compare.onFailure);
        return (retValue);
    },

    removeHome: function(communityID, homeID) {
        if (document.getElementById(homeID)) {
            document.getElementById(homeID).checked = false;
        };
        retValue = Consumer.portfolioWebservice.DeleteComparisonHome(guid, communityID, homeID, compare.queue, compare.onRemoveHomeComplete, compare.onFailure);
        return (retValue);
    },

    getHomes: function() {
        retValue = Consumer.portfolioWebservice.GetComparisonHomesAsString(guid, "~/xslt/CompareWidget.xslt", compare.queue, compare.onGetHomesComplete, compare.onFailure);
        return (retValue);
    },

    goToComparePage: function() {
        retValue = Consumer.portfolioWebservice.GetComparisonHomeCount(guid, compare.queue, compare.onGoToComparePageComplete, compare.onFailure);
        return (retValue);
    },

    goToComparePageFromPortfolio: function() {
        retValue = Consumer.portfolioWebservice.GetComparisonHomeCount(guid, compare.queue, compare.onGoToComparePageFromPortfolioComplete, compare.onFailure);
        return (retValue);
    },
    
    preCheckBoxesComplete: function(args) {           
        $(".compare input").each(function(i){
            if(args.indexOf($(this).attr("id") + "|||") > -1) {
                $(this).attr("checked","checked");
            }
            else {
                $(this).removeAttr("checked");    
            }        
        });
        if(args.split("|||").length >= 6) {
            $(".compare input:not(:checked)").attr("disabled", "disabled");
        }
        else {
            $(".compare input").removeAttr('disabled');
        }
        
        
        
    },

    onAddComplete: function(args) {
        if (compare.queue == "Portfolio") {
            retValue = Consumer.portfolioWebservice.GetComparisonHomeCount(guid, compare.queue, compare.onCheckCountForPortfolioComplete, compare.onFailure);
            return (retValue);
        }
        else {
            compare.getHomes();
        }
    },

    onRemoveHomeComplete: function(args) {
        if (!document.getElementById("compareTable")) {
            if (compare.queue == "Portfolio") {
                retValue = Consumer.portfolioWebservice.GetComparisonHomeCount(guid, compare.queue, compare.onCheckCountForPortfolioComplete, compare.onFailure);
                return (retValue);
            }
            else {
                compare.getHomes();
            }
        }
    },

    onGoToComparePageComplete: function(args) {
        if (args > 0) {
            window.location = compare.pageHref;
        }
        else {
            compare.showWidget();
        }
    },

    onGoToComparePageFromPortfolioComplete: function(args) {
        if (args >= 2) {
            window.parent.window.location = compare.pageHref;
        }
        else {
            $(".noCompareHomes").show();
        }
    },

    onGetHomesComplete: function(args) {
        if (window.parent.document.getElementById("comparePanelRepeat")) {
            window.parent.document.getElementById("comparePanelRepeat").innerHTML = args;
        };
        $("#comparePanel .repeat").html(args);
        compare.showWidget();
    },

    onCheckCountForPortfolioComplete: function(args) {
        if (args >= 5) {
            $(".maxCompareHomes").show();
            $(".compare input:not(:checked)").attr("disabled", "disabled");
        }
        else {
            $(".maxCompareHomes").hide();
            $(".compare input").removeAttr('disabled');
        }
    },

    onDeleteAllHomesComplete: function(args) {
        compare.getHomes();
    },

    onFailure: function(args) {
        alert("Error calling compare service method.");
    }

}

$(document).ready(function(){
    compare.init();
});


$.fn.removeCol = function(col){
    // Make sure col has value
    if(!col){ col = 1; }
    $('tr td:nth-child('+col+'), tr th:nth-child('+col+')', this).remove();
};
/* Compare End */
/* Portfolio  */
var portfolio = {

    homeIDHolder: null,

    communityIDHolder: null,

    pathHolder: null,

    buttonHolder: null,

    init: function() {

        $(".saveHome").click(function() {
            var kids = $(this).parent().parent().parent().children();
            var kids2 = $(kids[0]).children();
            var theVal = $(kids2[0]).val();
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
            }
            if (authenticated == "true") {
                buttonHolder = $(this);
                portfolio.saveHome(communityID, homeID, itemPath);
            } else {
                portfolio.saveHomeAnonymous(communityID, homeID, itemPath);
            }
            return false;
        });

        $(".saveCommunity").click(function() {
            if (authenticated == "true") {
                portfolio.saveCommunity(communityTCMID, communityPath);
                buttonHolder = $(this);
            } else {
                portfolio.saveCommunityAnonymous(communityTCMID, communityPath);
            }
            return false;
        });

        $(".saveHomePortfolio").click(function() {
            var localhost = 0;
            var kids = $(this).parent().parent().parent().children();
            var kids2 = $(kids[0]).children();
            var theVal = $(kids2[0]).val();
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
                localhost = 1;
            }
            if (authenticated == "true") {
                portfolio.saveHomePortfolio(communityID, homeID, itemPath);
            } else {
                portfolio.saveHomePortfolioAnonymous(communityID, homeID, itemPath, localhost);
            }
        });

        $(".removeHomePortfolio").click(function() {
            var kids = $(this).parent().parent().parent().children();
            var kids2 = $(kids[0]).children();
            var theVal = $(kids2[0]).val();
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
            }
            portfolio.removeHomePortfolio(communityID, homeID);
        });

        $(".saveCommunityPortfolio").click(function() {
            var localhost = 0;
            var kids = $(this).parent().siblings(".thisID");
            var communityID = $(kids[0]).html();
            var kids2 = $(this).parent().siblings(".thisPath");
            var itemPath = $(kids2[0]).html();
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
                localhost = 1;
            }
            if (authenticated == "true") {
                portfolio.saveCommunityPortfolio(communityID, itemPath);
            } else {
                portfolio.saveCommunityPortfolioAnonymous(communityID, itemPath, localhost);
            }
        });
        $(".removeCommunityPortfolio").click(function() {
            var kids = $(this).parent().siblings(".thisID");
            var communityID = $(kids[0]).html();
            portfolio.removeCommunityPortfolio(communityID);
        });


        $(".saveHomeCompare").click(function(e) {
            var theVal = $(this).attr("name");
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (itemPath.indexOf("consumer") > -1) {
                itemPath = itemPath.substring(9);
                localhost = 1;
            }
            if (authenticated == "true") {
                buttonHolder = $(this);
                portfolio.saveHome(communityID, homeID, itemPath);
            } else {
                portfolio.saveHomeAnonymous(communityID, homeID, itemPath);
            }
            e.preventDefault();
            return false;
        });

        $(".saveBtn a").click(function() {
            var theVal = this.id;
            var homeID = theVal.substring(0, theVal.indexOf("cID="));
            var communityID = theVal.substring(theVal.indexOf("cID=") + 4, theVal.indexOf("iPa="));
            var itemPath = theVal.substring(theVal.indexOf("iPa=") + 4);
            if (homeID == "NONE") { // Do community save
                if (authenticated == "true") {
                    buttonHolder = $(this);
                    portfolio.saveCommunity(communityID, itemPath);
                } else {
                    portfolio.saveCommunityAnonymous(communityID, itemPath);
                }
            }
            else { // Do Home save
                if (authenticated == "true") {
                    buttonHolder = $(this);
                    portfolio.saveHome(communityID, homeID, itemPath);
                } else {
                    portfolio.saveHomeAnonymous(communityID, homeID, itemPath);
                }
            }
            return false;
        });
    },

    // Save Home from FYH Results.

    saveHome: function(communityID, homeID, itemPath) {
        if (authenticated == "true") {
            communityIDHolder = communityID;
            homeIDHolder = homeID;
            pathHolder = itemPath;
            //First let's make sure we haven't hit the limit.
            theCount = Consumer.portfolioWebservice.GetSavedHomesCount(guid, portfolio.onSavedHomesCountComplete, portfolio.onFailure);
            return (false);
        }
    },

    onSavedHomesCountComplete: function(args) {
        if (args == 20) {
            // Limit exceeded, don't save, show error
            showPortfolioPanel("portfolioHomes", "maxLimit");
        } else {
            //Save!
            if (buttonHolder.text() != "") {
                buttonHolder.text("SAVED");
            }
            else {
                buttonHolder.attr("value", "SAVED");
            }
            buttonHolder.addClass("savedHome");
            Consumer.portfolioWebservice.AddSavedHome(guid, communityIDHolder, homeIDHolder, pathHolder, portfolio.onSaveHomeComplete, portfolio.onFailure);
        }
        return (false);
    },


    onSaveHomeComplete: function() {
        s.cstm_link({ pageName: s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
    },


    // Save Home for Anonymous user from FYH Results.

    saveHomeAnonymous: function(communityID, homeID, itemPath) {
        $.get("~/AnonymousSaveSession.aspx", { communityID: communityID, homeID: homeID, itemPath: itemPath }, portfolio.onSaveHomeAnonymousComplete());
        return (false);
    },

    onSaveHomeAnonymousComplete: function() {
        window.parent.scroll(0, 0);
        hidePortfolioPanel();
        showSignInPanel("anon");
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
    },


    // Save Community from community landing page

    saveCommunity: function(communityID, itemPath) {
        if (authenticated == "true") {
            communityIDHolder = communityID;
            pathHolder = itemPath;

            //First let's make sure we haven't hit the limit.
            retValue = Consumer.portfolioWebservice.GetSavedCommunitiesCount(guid, portfolio.onSavedCommunitiesCountComplete, portfolio.onFailure);
            return (false);
        }
    },
    onSavedCommunitiesCountComplete: function(args) {
        if (args == 20) {
            // Limit exceeded, don't save, show error
            showPortfolioPanel("portfolioCommunities", "maxLimit");
        } else {
            //Save!
            buttonHolder.text("SAVED");
            buttonHolder.addClass("savedCommunity");
            Consumer.portfolioWebservice.AddSavedCommunity(guid, communityIDHolder, pathHolder, portfolio.onSaveCommunityComplete, portfolio.onFailure);
        }
    },

    onSaveCommunityComplete: function() {
        s.cstm_link({ pageName: s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
    },

    // Save Community for Anonymous user from community landing page

    saveCommunityAnonymous: function(communityID, itemPath) {
        $.get("~/AnonymousSaveSession.aspx", { communityID: communityID, homeID: "none", itemPath: itemPath }, portfolio.onSaveCommunityAnonymousComplete());
        return (false);
    },

    onSaveCommunityAnonymousComplete: function() {
        hidePortfolioPanel();
        showSignInPanel("anon");
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
    },


    // Save Home from within portfolio

    saveHomePortfolio: function(communityID, homeID, itemPath) {
        communityIDHolder = communityID;
        homeIDHolder = homeID;
        pathHolder = itemPath;
        //First let's make sure we haven't hit the limit.
        theCount = Consumer.portfolioWebservice.GetSavedHomesCount(guid, portfolio.onSavedHomesCountFromPortfolioComplete, portfolio.onFailure);
        return (false);
    },

    onSavedHomesCountFromPortfolioComplete: function(args) {
        if (args == 20) {
            // Limit exceeded, don't save, show error
            window.location = "Portfolio-Homes.aspx?maxLimit=1";
        } else {
            //Save!
            Consumer.portfolioWebservice.AddSavedHome(guid, communityIDHolder, homeIDHolder, pathHolder, portfolio.onSaveHomePortfolioComplete, portfolio.onFailure);
        }
        return (false);
    },

    onSaveHomePortfolioComplete: function() {
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
        location.reload(true);
    },


    // Save Home for anonymous user from within portfolio

    saveHomePortfolioAnonymous: function(communityID, homeID, itemPath, localhost) {
        if (localhost == 1) {
            $.get(localpath + "/AnonymousSaveSession.aspx", { communityID: communityID, homeID: homeID, itemPath: itemPath }, portfolio.onSaveHomePortfolioAnonymousComplete());
        } else {
            $.get("/AnonymousSaveSession.aspx", { communityID: communityID, homeID: homeID, itemPath: itemPath }, portfolio.onSaveHomePortfolioAnonymousComplete());
        }
        return (false);
    },

    onSaveHomePortfolioAnonymousComplete: function() {
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
        parent.hidePortfolioPanel();
        parent.showSignInPanel("anon");
    },


    // Save Community from within portfolio

    saveCommunityPortfolio: function(communityID, itemPath) {
        communityIDHolder = communityID;
        pathHolder = itemPath;
        //First let's make sure we haven't hit the limit.
        retValue = Consumer.portfolioWebservice.GetSavedCommunitiesCount(guid, portfolio.onSavedCommunitiesCountFromPortfolioComplete, portfolio.onFailure);
        return (false);
    },

    onSavedCommunitiesCountFromPortfolioComplete: function(args) {
        if (args == 20) {
            // Limit exceeded, don't save, show error
            window.location = "Portfolio-Communities.aspx?maxLimit=1";
        } else {
            //Save!
            Consumer.portfolioWebservice.AddSavedCommunity(guid, communityIDHolder, pathHolder, portfolio.onSaveCommunityPortfolioComplete, portfolio.onFailure);
        }
    },

    onSaveCommunityPortfolioComplete: function() {
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
        window.location = "Portfolio-Communities.aspx";
    },


    // Save Community for Anonymous user from within portfolio

    saveCommunityPortfolioAnonymous: function(communityID, itemPath, localhost) {
        if (localhost == 1) {
            $.get(localpath + "/AnonymousSaveSession.aspx", { communityID: communityID, homeID: "none", itemPath: itemPath }, portfolio.onSaveCommunityPortfolioAnonymousComplete());
        } else {
            $.get("/AnonymousSaveSession.aspx", { communityID: communityID, homeID: "none", itemPath: itemPath }, portfolio.onSaveCommunityPortfolioAnonymousComplete());
        }
        return (false);
    },

    onSaveCommunityPortfolioAnonymousComplete: function() {
        parent.hidePortfolioPanel();
        parent.showSignInPanel("anon");
        window.parent.s.cstm_link({ pageName: window.parent.s.pageName + "/SaveToPortfolio_Complete",
            prop25: "SaveToPortfolio_Complete",
            prop26: "Save-Email-Print"
        });
    },


    // Remove Home from within portfolio

    removeHomePortfolio: function(communityID, homeID) {
        retValue = Consumer.portfolioWebservice.DeleteSavedHome(guid, communityID, homeID, portfolio.onRemoveHomePortfolioComplete, portfolio.onFailure);
        return (retValue);
    },

    onRemoveHomePortfolioComplete: function() {
        portfolio.savedCommunitiesCount--;
        location.reload(true);
    },


    // Remove Community from within portfolio

    removeCommunityPortfolio: function(communityID, homeID) {
        retValue = Consumer.portfolioWebservice.DeleteSavedCommunity(guid, communityID, portfolio.onRemoveCommunityPortfolioComplete, portfolio.onFailure);
        return (retValue);
    },

    onRemoveCommunityPortfolioComplete: function() {
        portfolio.savedCommunitiesCount--;
        location.reload(true);
    }
}

$(document).ready(function(){
    portfolio.init();
});
/* Portfolio End*/
/* JS - AS Connection */
var isFlashReady	= false;

 function sendToActionScript(SWFID, value) {
	
	if(isFlashReady)
	{
        var obj = swfobject.getObjectById(SWFID);
          if (obj) {
           obj.toggleMovie(value);
          }
	}
 }

function flashReady(value) {
	isFlashReady	= value;
 } 
/* JS - AS Connection End*/

/* JS from Master Page Start*/
 $(document).ready(function() {
     if (document.getElementById("globalHeader")) {
         setTimeout("checkChatImg()", 1000);

         //  DIRTY FLAG  //
         var isDirty = false;
         setDirty = function() {
             isDirty = true;
         }
         clearDirty = function() {
             isDirty = false;
         }
         okayToClose = function() {
             if (isDirty) {
                 if (confirm("You have unsaved changes that will be lost if you continue. Are you sure you want to leave this page?")) {
                     clearDirty();
                     return true;
                 } else {
                     return false;
                 }
             } else {
                 return true;
             }
         }
     }
     // Any button or link OUTSIDE of a form iframe that closes the form overlay
     // needs to call okayToClose() to check the flag before closing
     // example: 
     //      if (okayToClose()) {
     //          hidePortfolioPanel();
     //      }
 });        
/* JS from Master Page End*/