/* ##########################################################################################################################

Namespace : NRT.MySite
Classes   : UI
Summary	  : Contains all the scripts to handle the entire client side functionality for the
NRT MySite User-Interface functionality. 
Copyright : (c) 2006 NRT Inc. All rights reserved.

RevisionHistory: 
-------------------------------------------------------------------------------------------------------------------------
Date		Name		    Description
-------------------------------------------------------------------------------------------------------------------------
08/10/2006	Dale Lawless	Initial Creation

###########################################################################################################################*/

NRT.MySite.UI = function () {
  var resultPhotoElements = new Array();
  return {
    /*******************************************************************************************************************
    *									P U B L I C   M E T H O D S
    *******************************************************************************************************************/
    /*==================================================================================
    Method		: clear
    Summary		: Clear the Textbox to allow data entry
    Author		: Dale Lawless
    Create Date	: 08/10/2006
    ====================================================================================*/
    clear: function (element) {
      try {
        element.style.display = 'inline';
        element.value = '';
        _oUtility.setFocus(element);
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.clear', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: clearAgentInfo
    Summary		: Clears out the agent information on the calling window.
    Author		: Dale Lawless
    Create Date	: 01/11/2007
    ====================================================================================*/
    clearAgentInfo: function () {
      var oAgentID = null;
      var oAgentName = null;
      var oDisplayAgent = null;
      var oClearAgent = null;
      var oDisplayAgentParent = null;
      var oDisplayAgentTeamParent = null;

      try {
        // Agent ID
        oAgentID = _oUtility.getElementByTagNameAndID('hdnAgentID', 'INPUT');
        if (oAgentID !== null) {
          oAgentID.value = 0;
        } else {
          oAgentID = window.opener._oUtility.getElementByTagNameAndID('hdnAgentID', 'INPUT');
          if (oAgentID !== null) { oAgentID.value = 0; }
        }

        // Agent name
        oAgentName = _oUtility.getElementByTagNameAndID('hdnAgentName', 'INPUT');
        if (oAgentName !== null) {
          oAgentName.value = '';
        } else {
          oAgentName = window.opener._oUtility.getElementByTagNameAndID('hdnAgentName', 'INPUT');
          if (oAgentName !== null) { oAgentName.value = ''; }
        }

        // Display Agent
        oDisplayAgent = document.getElementById('spnDisplayAgent');
        if (oDisplayAgent !== null) {
          oDisplayAgent.innerHTML = '';
        } else {
          if (window.opener !== null && typeof window.opener !== 'undefined') {
            oDisplayAgent = window.opener.document.getElementById('spnDisplayAgent', 'INPUT');
            if (oDisplayAgent !== null) { oDisplayAgent.innerHTML = ''; }
          }
        }

        // AgentTeamText selector
        oSelAgentText = document.getElementById('spnSelectAgentText');
        if (oSelAgentText === null && window.opener !== null && typeof window.opener !== 'undefined') {
          oSelAgentText = window.opener.document.getElementById('spnSelectAgentText');
        }
        // AgentTeamText selector
        oSelAgentTeamText = document.getElementById('spnSelectAgentTeamText');
        if (oSelAgentTeamText === null && window.opener !== null && typeof window.opener !== 'undefined') {
          oSelAgentTeamText = window.opener.document.getElementById('spnSelectAgentTeamText');
        }

        //Display the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        oDisplayAgentParent = oSelAgentText.parentElement;
        if (oDisplayAgentParent !== null && typeof oDisplayAgentParent !== 'undefined') {
          var parentId = oDisplayAgentParent.id;
          if (parentId.indexOf("_divSelectAgent") > 0) {
            oDisplayAgentParent.style.display = 'inline';
          }
        }

        //Display the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        if (oSelAgentTeamText != null) {
          oDisplayAgentTeamParent = oSelAgentTeamText.parentElement;
          if (oDisplayAgentTeamParent !== null && typeof oDisplayAgentTeamParent !== 'undefined') {
            var parentId = oDisplayAgentTeamParent.id;
            if (parentId.indexOf("_divSelectAgentTeam") > 0) {
              oDisplayAgentTeamParent.style.display = 'inline';
            }
          }
        }
        // Clear Agent
        oClearAgent = document.getElementById('spnClearAgent');
        if (oClearAgent !== null) {
          oClearAgent.style.display = 'none';
          oSelAgentText.style.display = '';
        } else {
          if (window.opener !== null && typeof window.opener !== 'undefined') {
            oClearAgent = window.opener.document.getElementById('spnClearAgent', 'INPUT');
            if (oClearAgent !== null) {
              oClearAgent.style.display = 'none';
              oSelAgentText.style.display = '';
            }
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.clearAgentInfo', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: clearTeamInfo
    Summary		: Clears out the team information on the calling window.
    Author		: Dale Lawless
    Create Date	: 10/26/2007
    ====================================================================================*/
    clearTeamInfo: function () {
      var oTeamID = null;
      var oTeamName = null;
      var oDisplayTeam = null;
      var oClearTeam = null;
      var oDisplayAgentParent = null;
      var oDisplayAgentTeamParent = null;

      try {
        // Team ID
        oTeamID = _oUtility.getElementByTagNameAndID('hdnTeamID', 'INPUT');
        if (oTeamID !== null) {
          oTeamID.value = 0;
        } else {
          oTeamID = window.opener._oUtility.getElementByTagNameAndID('hdnTeamID', 'INPUT');
          if (oTeamID !== null) { oTeamID.value = 0; }
        }

        // Team name
        oTeamName = _oUtility.getElementByTagNameAndID('hdnTeamName', 'INPUT');
        if (oTeamName !== null) {
          oTeamName.value = '';
        } else {
          oTeamName = window.opener._oUtility.getElementByTagNameAndID('hdnTeamName', 'INPUT');
          if (oTeamName !== null) { oTeamName.value = ''; }
        }

        // Display Team
        oDisplayTeam = document.getElementById('spnDisplayTeam', 'INPUT');
        if (oDisplayTeam !== null) {
          oDisplayTeam.innerHTML = '';
        } else {
          if (window.opener !== null && typeof window.opener !== 'undefined') {
            oDisplayTeam = window.opener.document.getElementById('spnDisplayTeam', 'INPUT');
            if (oDisplayTeam !== null) { oDisplayTeam.innerHTML = ''; }
          }
        }

        // AgentTeamText selector
        oSelAgentText = document.getElementById('spnSelectAgentText');
        if (oSelAgentText === null && window.opener !== null && typeof window.opener !== 'undefined') {
          oSelAgentText = window.opener.document.getElementById('spnSelectAgentText');
        }
        // AgentTeamText selector
        oSelAgentTeamText = document.getElementById('spnSelectAgentTeamText');
        if (oSelAgentTeamText === null && window.opener !== null && typeof window.opener !== 'undefined') {
          oSelAgentTeamText = window.opener.document.getElementById('spnSelectAgentTeamText');
        }

        //Display the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        oDisplayAgentParent = oSelAgentText.parentElement;
        if (oDisplayAgentParent !== null && typeof oDisplayAgentParent !== 'undefined') {
          var parentId = oDisplayAgentParent.id;
          if (parentId.indexOf("_divSelectAgent") > 0) {
            oDisplayAgentParent.style.display = 'inline';
          }
        }

        //Display the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        if (oSelAgentTeamText != null) {
          oDisplayAgentTeamParent = oSelAgentTeamText.parentElement;
          if (oDisplayAgentTeamParent !== null && typeof oDisplayAgentTeamParent !== 'undefined') {
            var parentId = oDisplayAgentTeamParent.id;
            if (parentId.indexOf("_divSelectAgentTeam") > 0) {
              oDisplayAgentTeamParent.style.display = 'inline';
            }
          }
        }
        // Clear Team
        oClearTeam = document.getElementById('spnClearTeam');
        if (oClearTeam !== null) {
          oClearTeam.style.display = 'none';
          oSelAgentText.style.display = '';
        } else {
          if (window.opener !== null && typeof window.opener !== 'undefined') {
            oClearTeam = window.opener.document.getElementById('spnClearTeam', 'INPUT');
            if (oClearTeam !== null) {
              oClearTeam.style.display = 'none';
              oSelAgentText.style.display = '';
            }
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.clearTeamInfo', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: getSelectedCheckBoxes
    Summary		: Returns an array of all selected check boxes.
    Author		: Dale Lawless
    Create Date	: 01/05/2007
    ====================================================================================*/
    getSelectedCheckBoxes: function (checkboxName) {
      var aSelectedCheckBoxes = [];
      var allInputs = null;
      var x = 0;

      try {
        allInputs = _oUtility.getElementsByTagNameAndID(checkboxName, 'INPUT');

        // Set all check boxes to disabled
        for (x = 0; x < allInputs.length; x += 1) {
          // Make sure it's a checkbox box
          if (allInputs[x].type === 'checkbox') {
            // Make sure it was checked
            if (allInputs[x].checked === true) {
              // Add the checkbox to the array
              aSelectedCheckBoxes.push(allInputs[x]);
            }
          }
        }
        return aSelectedCheckBoxes;
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.getSelectedCheckBoxes', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: initialize
    Summary		: Initialization script to set variables throughout MySite user-interface.
    Author		: Dale Lawless
    Create Date	: 02/06/2007
    ====================================================================================*/
    initialize: function (Settings) {
      var sArray = null;

      try {
        // Set MySite Configuration Settings
        sArray = Settings.split("|");

        if (sArray.length > 0) {
          // Sets the MySite javascript variables from Config settings 
          _WebsiteID = sArray[0];
          _MetroMySiteName = sArray[1];
          _CookieExpireDays = sArray[2];
          _CookieLoginExpireMin = sArray[3];
          _MaxSavedProperties = sArray[4];
          _MaxSavedSearches = sArray[5];
          _SavedSearchXSLTPath = sArray[6];
          _SavedSearchDetailsXSLTPath = sArray[7];
          _ShowGlobalAlerts = sArray[8];
          _ShowEmailAlerts = sArray[9];
          _ShowFreq = sArray[10];
          _ShowAdditionalEmail = sArray[11];
          _ShowSendToAgent = sArray[12];
          _AllowDisableAccount = sArray[13];
          _EmailFrom = sArray[14];
          _AltEmailTo = sArray[15];
          _AgentLinkURL = sArray[16];
          _WebsiteHasTeams = sArray[17];
        }

        // Prefill Email Address on Login Window
        if (NRT.MySite.UI.pageIsMySiteLogin()) {
          NRT.MySite.Login.prefillEmailAddress();
        }

        // Prefill Email Address on Authentication Panel
        if (NRT.MySite.UI.pageIsPropertySearch() || NRT.MySite.UI.pageIsPropertyResults() || NRT.MySite.UI.pageIsPropertyDetails()) {
          NRT.MySite.Authentication.prefillEmailAddress();
        }

        // Set Forms Authentication Cookie for pages that fetch the consumer id
        NRT.MySite.Authentication.setFormsAuthCookie();
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.initialize', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: initTab
    Summary		: Initializes the tab on my saved home page when it is first loaded.
    Author		: Dale Lawless
    Create Date	: 12/06/2006
    ====================================================================================*/
    initTab: function () {
      var aTabs = null;

      try {
        NRT.MySite.TabCaptions.init();
        aTabs = NRT.MySite.TabCaptions.getTabCaptions();
        if (aTabs !== null) {
          _oTab.setTabs(aTabs);
          _oTab.setTabAlign('LEFT');
          _oTab.load();
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.initTab', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsMySiteHome
    Summary		: Determines if the current page is the login page.
    Author		: Dale Lawless
    Create Date	: 01/26/2007
    ====================================================================================*/
    pageIsMySiteHome: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/MYSITEHOME.ASPX/);
        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsMySiteHome', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsMySiteLogin
    Summary		: Determines if the current page is the login page.
    Author		: Dale Lawless
    Create Date	: 01/26/2007
    ====================================================================================*/
    pageIsMySiteLogin: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/MYSITELOGIN.ASPX/);
        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsMySiteLogin', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsMySiteMain
    Summary		: Determines if the current page is the mysite main page.
    Author		: Dale Lawless
    Create Date	: 02/17/2007
    ====================================================================================*/
    pageIsMySiteMain: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/MYSITEMAIN.ASPX/);
        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsMySiteMain', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsMySiteRegister
    Summary		: Determines if the current page is the register page.
    Author		: Dale Lawless
    Create Date	: 11/08/2007
    ====================================================================================*/
    pageIsMySiteRegister: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/MYSITEREGISTER.ASPX/);
        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsMySiteRegister', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsPropertyDetails
    Summary		: Determines if the current page is the Property Details page.
    Author		: Dale Lawless
    Create Date	: 01/26/2007
    ====================================================================================*/
    pageIsPropertyDetails: function () {
      var sSearchString = '';
      var sPageName = -1;

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/PROPERTYDETAILS.ASPX/);
        if (sPageName > -1) {
          return true;
        }
        else {
          sPageName = sSearchString.search(/\/PROPERTY\/DETAILS\//);

          if (sPageName > -1)
            return true;

          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsPropertyDetails', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsPropertySearch
    Summary		: Determines if the current page is the Property Search page.
    Author		: Dale Lawless
    Create Date	: 01/26/2007
    ====================================================================================*/
    pageIsPropertySearch: function () {
      var sSearchString = "";

      try {
        sSearchString = window.location.pathname.toLowerCase();
        if ((sSearchString.search(/propertysearch.aspx/) > -1) ||
					(sSearchString.search(/architecturalsearch.aspx/) > -1) ||
					(sSearchString.search(/reosearch.aspx/) > -1) ||
					(sSearchString.search(/seasonalrentalsearch.aspx/) > -1)) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error("NRT.MySite.UI.pageIsPropertySearch", _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageHasAuthentication
    Summary		: Determines if the current page contains an authentication panel.
    Author		: Dale Lawless
    Create Date	: 10/30/2007
    ====================================================================================*/
    pageHasAuthentication: function () {
      var oDivAuthSavedSearchLogin = document.getElementById('divAuthSavedSearchLogin');

      try {
        if (oDivAuthSavedSearchLogin !== null && typeof oDivAuthSavedSearchLogin !== 'undefined') {
          if (oDivAuthSavedSearchLogin.style.visibility !== "hidden" || oDivAuthSavedSearchLogin.style.display !== "none" || oDivAuthSavedSearchLogin.disabled !== true) {
            return true;
          } else {
            return false;
          }
        }
      } catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageHasAuthentication', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsHomePage
    Summary		: Determines if the current page is the Property Search page.
    Author		: Uma Chandrasekar
    Create Date	: 03/13/2007
    ====================================================================================*/
    pageIsHomePage: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        if (sSearchString.search(/.ASPX/) <= 0) {
          sPageName = 1
        } else {
          sPageName = sSearchString.search(/DEFAULT.ASPX/);
        }

        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsHomePage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: pageIsPropertyResults
    Summary		: Determines if the current page is the Property Results page.
    Author		: Dale Lawless
    Create Date	: 01/26/2007
    ====================================================================================*/
    pageIsPropertyResults: function () {
      var sSearchString = '';
      var sPageName = '';

      try {
        sSearchString = window.location.pathname.toUpperCase();
        sPageName = sSearchString.search(/PROPERTYRESULTS.ASPX/);
        if (sPageName > 0) {
          return true;
        } else {
          return false;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.pageIsPropertyResults', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },


    /*==================================================================================
    Method		: redirectToHomePage
    Summary		: Redirect the user to the home page.
    Author		: Dale Lawless
    Create Date	: 01/17/2007
    ====================================================================================*/
    redirectToHomePage: function () {
      try {
        window.location = _oUtility.getAppPath() + _HomePageURL;
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToHomePage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToLoginPage
    Summary		: Redirect the user to the login page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToLoginPage: function (tabID) {
      try {
        //           var qs = window.location.search;  NO NO NO YOU ADD BRANDING 2 with this
        if (_LoginPageURL.lastIndexOf('?') > -1) {
          //            qs = qs.replace("?","&");                 
          window.location = _oUtility.getAppPath() + _LoginPageURL; // + qs;
        } else {
          window.location = _oUtility.getAppPath() + _LoginPageURL; // + qs;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToLoginPage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToMyAccount
    Summary		: Redirect the user to the My Account page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToMyAccount: function () {
      try {
        if (NRT.MySite.UI.pageIsMySiteHome()) {
          NRT.MySite.UI.tabClick(2);
        } else {
          var qs = window.location.search;
          qs = qs.toLowerCase();
          window.location = _oUtility.getAppPath() + _MyAccountURL;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToMyAccount', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToMySavedProperties
    Summary		: Redirect the user to the My Saved Properties page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToMySavedProperties: function () {
      try {
        if (NRT.MySite.UI.pageIsMySiteHome()) {
          NRT.MySite.UI.tabClick(1);
        } else {
          if (!NRT.MySite.UI.pageIsHomePage()) {
            Progress.fn.show('', true, 'Loading Saved Properties');
          }

          var qs = window.location.search;
          qs = qs.toLowerCase();
          window.location = _oUtility.getAppPath() + _MySavedPropertiesURL;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToMySavedProperties', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToMySavedSearches
    Summary		: Redirect the user to the My Saved Searches page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToMySavedSearches: function () {
      try {
        if (NRT.MySite.UI.pageIsMySiteHome()) {
          NRT.MySite.UI.tabClick(0);
        } else {
          if (!NRT.MySite.UI.pageIsHomePage()) {
            Progress.fn.show('', true, 'Loading Saved Searches');
          }

          var qs = window.location.search;
          qs = qs.toLowerCase();
          window.location = _oUtility.getAppPath() + _MySavedSearchesURL;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToMySavedSearches', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToRegistrationPage
    Summary		: Redirect the user to the registration page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToRegistrationPage: function () {
      try {
        // See if we required user to log in first to view property details
        if (NRT.Utility.getQueryStringParam('RedirectURL') !== null) {
          window.location = _oUtility.getAppPath() + _RegisterPageURL + '?RedirectURL=' + _oUtility.decodeURL(NRT.Utility.getQueryStringParam('RedirectURL'));
        }
        else {
          window.location = _oUtility.getAppPath() + _RegisterPageURL; // + window.location.search;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToRegistrationPage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToPropertyResultsPage
    Summary		: Redirect the user to the property results page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToPropertyResultsPage: function (ConsumerSearchID, SearchOptionID) {
      var DTSince = null;
      var dtToday = null;
      var dtMonth = null;
      var dtDay = null;
      var dtYear = null;
      var iConsumerId = 0;
      var oLastLoginDate = null;
      var sURL = '';

      try {
        switch (SearchOptionID) {
          case 0:
            // All Matches
            DTSince = null;
            break;
          case 1:
            // Today's matches
            dtToday = new Date();
            dtMonth = dtToday.getMonth() + 1;
            dtDay = dtToday.getDate();
            dtYear = dtToday.getFullYear();
            DTSince = dtMonth + '/' + dtDay + '/' + dtYear;
            break;
          case 2:
            // Since Last Login
            //Make AJAX call to get the last login date
            iConsumerId = NRT.MySite.Authentication.getConsumerID();
            oLastLoginDate = MySiteProvider.GetLastLoginDate(_WebsiteID, iConsumerId);
            if (oLastLoginDate !== null && typeof oLastLoginDate !== 'undefined') {
              DTSince = oLastLoginDate.value;
            }
            break;
        }

        sURL = _oUtility.getAppPath() + _PropertyResultsURL;

        if (sURL.indexOf('?') > -1) {
          sURL += '&ConsumerSearchID=' + ConsumerSearchID + '&CallingPage=7' + '&SearchOption=' + SearchOptionID;
        } else {
          sURL += '?ConsumerSearchID=' + ConsumerSearchID + '&CallingPage=7' + '&SearchOption=' + SearchOptionID;
        }

        if (DTSince !== null && typeof DTSince !== 'undefined') {
          sURL += '&DTSince=' + DTSince;
        }
        window.location = sURL;

      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToPropertyResultsPage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToPropertySearchPage
    Summary		: Redirect the user to the login page.
    Author		: Dale Lawless
    Create Date	: 01/24/2007
    ====================================================================================*/
    redirectToPropertySearchPage: function () {
      var sURL = '';

      try {
        sessvars.$.clearMem();
        window.location = _oUtility.getAppPath() + _PropertySearchURL;
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToPropertySearchPage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: redirectToPropertySearchPageWithSearchCriteria
    Summary		: Redirect the user to theProperty Search page along with Search Criteria
    Author		: Rajesh Kalidindi
    Create Date	: 10/10/2011
    ====================================================================================*/
    redirectToPropertySearchPageWithSearchCriteria: function (consumerSearchID) {
      try {
        sessvars.$.clearMem();

        sURL = _oUtility.getAppPath() + _PropertySearchWithSearchCriteriaURL;

        if (sURL.indexOf('?') > -1) {
          sURL += '&SearchID=0&ConsumerSearchID=' + consumerSearchID;
        } else {
          sURL += '?SearchID=0&ConsumerSearchID=' + consumerSearchID;
        }

        window.location = sURL;

      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.redirectToPropertySearchPageWithSearchCriteria', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: setAgentInfo
    Summary		: Displays the agent information on the calling window
    This is updated after the user elects to use the Agent Lookup 
    functionality.
    Author		: Dale Lawless
    Create Date	: 01/11/2007
    ====================================================================================*/
    setAgentInfo: function (personnelID, agentName) {
      var oAgentID = null;
      var oAgentName = null;
      var oDisplayAgent = null;
      var oClearAgent = null;
      var oDisplayAgentParent = null;
      var oDisplayAgentTeamParent = null;
      try {
        // Clear out any previously selected Teams
        NRT.MySite.UI.clearTeamInfo();

        // Agent ID
        oAgentID = _oUtility.getElementByTagNameAndID('hdnAgentID', 'INPUT');
        if (oAgentID !== null) {
          oAgentID.value = personnelID;
        } else {
          oAgentID = window.opener._oUtility.getElementByTagNameAndID('hdnAgentID', 'INPUT');
          if (oAgentID !== null) {
            oAgentID.value = personnelID;
          }
        }

        // Agent name
        oAgentName = _oUtility.getElementByTagNameAndID('hdnAgentName', 'INPUT');
        if (oAgentName !== null) {
          oAgentName.value = agentName;
        } else {
          oAgentName = window.opener._oUtility.getElementByTagNameAndID('hdnAgentName', 'INPUT');
          if (oAgentName !== null) {
            oAgentName.value = agentName;
          }
        }

        // AgentTeamText selector
        oSelAgentText = document.getElementById('spnSelectAgentText');
        if (oSelAgentText === null && (window.opener !== null && typeof window.opener != 'undefined')) {
          oSelAgentText = window.opener.document.getElementById('spnSelectAgentText');
        }
        // AgentTeamText selector
        oSelAgentTeamText = document.getElementById('spnSelectAgentTeamText');
        if (oSelAgentTeamText === null && (window.opener !== null && typeof window.opener != 'undefined')) {
          oSelAgentTeamText = window.opener.document.getElementById('spnSelectAgentTeamText');
        }

        //Clear the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        oDisplayAgentParent = oSelAgentText.parentElement;
        if (oDisplayAgentParent !== null && typeof oDisplayAgentParent !== 'undefined') {
          var parentId = oDisplayAgentParent.id;
          if (parentId.indexOf("_divSelectAgent") > 0) {
            oDisplayAgentParent.style.display = 'none';
          }
        }
        //Clear the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        if (oSelAgentTeamText != null) {
          oDisplayAgentTeamParent = oSelAgentTeamText.parentElement;
          if (oDisplayAgentTeamParent !== null && typeof oDisplayAgentTeamParent !== 'undefined') {
            var parentId = oDisplayAgentTeamParent.id;
            if (parentId.indexOf("_divSelectAgentTeam") > 0) {
              oDisplayAgentTeamParent.style.display = 'none';
            }
          }
        }

        // Display Agent
        oDisplayAgent = document.getElementById('spnDisplayAgent');
        if (oDisplayAgent !== null) {
          oDisplayAgent.innerHTML = agentName;
          oSelAgentText.style.display = 'none';
        } else {
          oDisplayAgent = window.opener.document.getElementById('spnDisplayAgent');
          if (oDisplayAgent !== null) {
            oDisplayAgent.innerHTML = agentName;
            oSelAgentText.style.display = 'none';
          } else {
            oSelAgentText.style.display = '';
          }
        }

        // Clear Agent
        oClearAgent = document.getElementById('spnClearAgent');
        if (oClearAgent !== null) {
          oClearAgent.style.display = 'inline';
        } else {
          oClearAgent = window.opener.document.getElementById('spnClearAgent');
          if (oClearAgent !== null) {
            oClearAgent.style.display = 'inline';
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.setAgentInfo', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: setTeamInfo
    Summary		: Displays the team information on the calling window
    This is updated after the user elects to use the Team Lookup 
    functionality.
    Author		: Dale Lawless
    Create Date	: 10/26/2007
    ====================================================================================*/
    setTeamInfo: function (TeamID, TeamName) {
      var oTeamID = null;
      var oTeamName = null;
      var oDisplayTeam = null;
      var oClearTeam = null;
      try {
        // Clear out any previously selected Agents
        NRT.MySite.UI.clearAgentInfo();

        // Team ID
        oTeamID = _oUtility.getElementByTagNameAndID('hdnTeamID', 'INPUT');
        if (oTeamID !== null) {
          oTeamID.value = TeamID;
        } else {
          oTeamID = window.opener._oUtility.getElementByTagNameAndID('hdnTeamID', 'INPUT');
          if (oTeamID !== null) {
            oTeamID.value = TeamID;
          }
        }

        // Team name
        oTeamName = _oUtility.getElementByTagNameAndID('hdnTeamName', 'INPUT');
        if (oTeamName !== null) {
          oTeamName.value = TeamName;
        } else {
          oTeamName = window.opener._oUtility.getElementByTagNameAndID('hdnTeamName', 'INPUT');
          if (oTeamName !== null) {
            oTeamName.value = TeamName;
          }
        }

        // AgentTeamText selector
        oSelAgentText = document.getElementById('spnSelectAgentText');
        if (oSelAgentText === null && (window.opener !== null && typeof window.opener != 'undefined')) {
          oSelAgentText = window.opener.document.getElementById('spnSelectAgentText');
        }
        // AgentTeamText selector
        oSelAgentTeamText = document.getElementById('spnSelectAgentTeamText');
        if (oSelAgentTeamText === null && (window.opener !== null && typeof window.opener != 'undefined')) {
          oSelAgentTeamText = window.opener.document.getElementById('spnSelectAgentTeamText');
        }

        //Clear the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        oDisplayAgentParent = oSelAgentText.parentElement;
        if (oDisplayAgentParent !== null && typeof oDisplayAgentParent !== 'undefined') {
          var parentId = oDisplayAgentParent.id;
          if (parentId.indexOf("_divSelectAgent") > 0) {
            oDisplayAgentParent.style.display = 'none';
          }
        }
        //Clear the parentElement if it is a DIV, do nothing if the parentElement is a PANEL
        if (oSelAgentTeamText != null) {
          oDisplayAgentTeamParent = oSelAgentTeamText.parentElement;
          if (oDisplayAgentTeamParent !== null && typeof oDisplayAgentTeamParent !== 'undefined') {
            var parentId = oDisplayAgentTeamParent.id;
            if (parentId.indexOf("_divSelectAgentTeam") > 0) {
              oDisplayAgentTeamParent.style.display = 'none';
            }
          }
        }


        // Display Team
        oDisplayTeam = document.getElementById('spnDisplayTeam');
        if (oDisplayTeam !== null) {
          oDisplayTeam.innerHTML = TeamName;
          oSelAgentText.style.display = 'none';
        } else {
          oDisplayTeam = window.opener.document.getElementById('spnDisplayTeam');
          if (oDisplayTeam !== null) {
            oDisplayTeam.innerHTML = TeamName;
            oSelAgentText.style.display = 'none';
          } else {
            oSelAgentText.style.display = '';
          }

        }

        // Clear Team
        oClearTeam = document.getElementById('spnClearTeam');
        if (oClearTeam !== null) {
          oClearTeam.style.display = 'inline';
        } else {
          oClearTeam = window.opener.document.getElementById('spnClearTeam');
          if (oClearTeam !== null) {
            oClearTeam.style.display = 'inline';
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.setTeamInfo', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: setCheckBoxTextStyle
    Summary		: Called when a checkbox is clicked. Will bold or remove 
    the bolding of the text.
    Author		: Dale Lawless
    Create Date	: 01/05/2007
    ====================================================================================*/
    setCheckBoxTextStyle: function (control) {
      var divTextControl = null;

      try {
        divTextControl = control.parentNode;

        // Determine how do display the text
        if (control.checked) {
          divTextControl.style.fontWeight = 'bold';
        } else {
          divTextControl.style.fontWeight = '';
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.setCheckBoxTextStyle', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /*==================================================================================
    Method		: showAgentLookupWindow 
    Summary		: Opens a new window for the Agent Lookup functionality.
    Author		: Dale Lawless
    Create Date	: 01/11/2007
    ====================================================================================*/
    showAgentLookupWindow: function () {
      var sURL = '';

      try {
        sURL = '/MySite/AgentSearch.aspx' + NRT.Utility.Branding.getBranding('?');
        _oUtility.showNewWindow(sURL, '', _WinW_AgentLookup, _WinH_AgentLookup);
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showAgentLookupWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: showAgentTeamSearchWindow
    Summary		: Opens a new window for the Search Agent or Team Lookup functionality.
    Author		: Dale Lawless
    Create Date	: 10/26/2007
    ====================================================================================*/
    showAgentTeamSearchWindow: function (searchtype) {
      var sURL = '';

      try {
        if (searchtype === 'agent') {
          sURL = '/MySite/AgentSearch.aspx?st=a' + NRT.Utility.getBranding('?');
          _oUtility.showNewWindow(sURL, '', _WinW_AgentLookup, _WinW_AgentLookup);
        } else if (searchtype === 'team') {
          sURL = '/MySite/AgentSearch.aspx?st=t' + NRT.Utility.getBranding('?');
          _oUtility.showNewWindow(sURL, '', _WinW_TeamLookup, _WinH_TeamLookup);
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showAgentTeamSearchWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: showConfirmationLayeredWindow
    Summary		: Displays a confirmation layered window.
    Author		: Dale Lawless
    Create Date	: 01/20/2007
    ====================================================================================*/
    showConfirmationLayeredWindow: function (ConfirmType, ConsumerID) {
      var sQueryString = null;

      try {
        switch (ConfirmType) {
          case _ConfirmationType_SavedSearches:
            sQueryString = 'controlType=SaveSearchConfirmation&ConsumerID=' + ConsumerID;
            _oUtility.showLayeredPage(sQueryString, _WinW_Confirmation, _WinTitle_Confirmation_SS, _DefFocusItemID_Confirmation, _DefFocusItemType_Confirmation);
            break;
          case _ConfirmationType_SavedProperties:
            sQueryString = 'controlType=SavePropertyConfirmation';
            _oUtility.showLayeredPage(sQueryString, _WinW_Confirmation, _WinTitle_Confirmation_SP, _DefFocusItemID_Confirmation, _DefFocusItemType_Confirmation);
            break;
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showConfirmationLayeredWindow', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },


    /*==================================================================================
    Method		: showConfirmationLayeredWindowForSearchResultsPage
    Summary		: Displays a confirmation layered window for Saving from Details Page/Search Results Page.
    Author		: Rajesh Kalidindi
    Create Date	: 12/12/2011
    ====================================================================================*/
    showConfirmationLayeredWindowForSearchResultsPage: function (ConsumerPropertyID, PropertyID, SaveListingIndex) {
      var sQueryString = null;

      try {

        sQueryString = 'controlType=SavePropertyFromDetailPage&ConsumerPropertyID=' + ConsumerID + '&PropertyID=' + PropertyID + '&SaveListingIndex=' + SaveListingIndex;
        _oUtility.showLayeredPage(sQueryString, _WinW_Confirmation, _WinTitle_Confirmation_SS, _DefFocusItemID_Confirmation, _DefFocusItemType_Confirmation);
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showConfirmationLayeredWindowForSearchResultsPage', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },


    /*==================================================================================
    Method		: showLayeredWindow
    Summary		: Displays the Window as a Layered Window
    Author		: Dale Lawless
    Create Date	: 08/10/2006
    ====================================================================================*/
    showLayeredWindow: function (control, title, width, defaultfocusitemid, defaultfocusitemtype) {
      var sQueryString = null;

      try {
        // Show the layered page              
        qs = location.search.length > 0 ? '&' + location.search.substr(1) : '';
        sQueryString = 'controlType=' + control + qs;

        if (width === null) {
          _oUtility.showLayeredPage(sQueryString, _defWidth, title.toUpperCase(), defaultfocusitemid, defaultfocusitemtype);
        } else {
          _oUtility.showLayeredPage(sQueryString, width, title.toUpperCase(), defaultfocusitemid, defaultfocusitemtype);
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showLayeredWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: showRememberMeAlertWindow
    Summary		: Displays the Remember Me as a Layered Alert Window
    Author		: TSA
    Create Date	: 2007.04.04
    ====================================================================================*/
    showRememberMeAlertWindow: function (title) {
      var sHTML = "";

      try {
        //contents
        sHTML += "<table style='border:0px; padding:0px; WIDTH:" + (_WinW_RememberMe - 10) + "px;'>";
        sHTML += "<tr>";
        sHTML += "<td class='text'>";
        sHTML += "By selecting the \"Remember Me\" checkbox,";
        sHTML += " <label class='textbold'>" + window.location.host + "</label>";
        sHTML += " will place a cookie on your computer that will";
        sHTML += " automatically log you in when you return to the Web site.";
        sHTML += "</td>";
        sHTML += "</tr>";
        sHTML += "<tr>";
        sHTML += "<td class='text'>";
        sHTML += "If you are using a shared or public computer,";
        sHTML += " we recommend that you do not use this feature.";
        sHTML += "</td>";
        sHTML += "</tr>";
        sHTML += "<tr>";
        sHTML += "<td>";
        sHTML += "<TABLE style='padding:0px; border:0px; width:100%;'>";
        sHTML += "<TR>";
        sHTML += "<td style='height:9px;' class=''>";
        sHTML += "<img src='/NRTProducts/include/images/common_spacer.gif' border='0' width='100%' height='9'>";
        sHTML += "</td>";
        sHTML += "</TR>";
        sHTML += "</TABLE>";
        sHTML += "</td>";
        sHTML += "</tr>";
        sHTML += "<tr>";
        sHTML += "<td style='text-align:center;'>";
        sHTML += "<div style=\"width: 52px; margin: 0px auto;\"><a id='" + _DefFocusItemID_RememberMe + "' class=\"button-ok-med\" href=\"javascript:NRT.Utility.closeLayeredPage('CHILD_LAYER');\"></a></div>";
        sHTML += "</td>";
        sHTML += "</tr>";
        sHTML += "</table>";
        //end of content

        _oUtility.showInfo(sHTML, _WinW_RememberMe, title.toUpperCase(), _DefFocusItemID_RememberMe);
        return;

      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showRememberMeAlertWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: showRememberMePopupWindow
    Summary		: Opens the Remember Me page in a new window from a layered window.
    Author		: Dale Lawless
    Create Date	: 01/11/2007
    ====================================================================================*/
    showRememberMePopupWindow: function () {
      var sQueryString = null;

      try {
        sQueryString = 'controlType=RememberMe';
        _oUtility.showNewHostWindow(sQueryString, _WinW_RememberMe, _WinH_RememberMe, '');
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showRememberMePopupWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },

    /*==================================================================================
    Method		: showRegistrationPage
    Summary		: Opens Registration page either in a page or in a layered window.
    Author		: Dale Lawless
    Create Date	: 01/19/2007
    ====================================================================================*/
    showRegistrationPage: function () {
      var sQueryString = null;

      try {
        if (NRT.MySite.UI.pageIsMySiteLogin()) {
          // In-Page
          NRT.MySite.UI.redirectToRegistrationPage();
        } else if (NRT.MySite.UI.pageIsMySiteHome()) {
          // New Window
          sQueryString = 'controlType=Registration';
          _oUtility.showNewHostWindow(sQueryString, _WinW_Registration, _WinH_Registration, _WinTitle_Registration);
        } else {
          // Layered Window
          NRT.MySite.UI.showLayeredWindow("Registration", _WinTitle_Registration, _WinW_Registration, _DefFocusItemID_Registration, _DefFocusItemType_Registration);
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showRememberMePopupWindow', _oErrorHandler.ERRORTYPE_JS, err);
      }
    },


    /*==================================================================================
    Method		: tabClick
    Summary		: Tab click event for the My Save Home page.
    Author		: Dale Lawless
    Create Date	: 09/15/2006
    ====================================================================================*/
    tabClick: function (tabId) {
      var oLblMSS = null;
      var oLblMSP = null;
      var oLblMA = null;
      var sBranding = '';
      var sAbrand = '';
      var sTbrand = '';
      var bLoggedIn = false;

      try {
        // Check if the user has been authenticated
        bLoggedIn = NRT.MySite.Authentication.checkCookieExpiration();
        if (bLoggedIn === false) {
          NRT.MySite.UI.redirectToLoginPage(tabId);
          return;
        }

        if (NRT.MySite.Authentication.checkCookieExpiration()) {
          // Disables links
          oLblMSS = _oUtility.getElementByTagNameAndID('lblMySavedSearches', 'A');
          oLblMSP = _oUtility.getElementByTagNameAndID('lblMySavedProperties', 'A');
          oLblMA = _oUtility.getElementByTagNameAndID('lblMyAccount', 'A');
          _oUtility.disableAnchor(oLblMSS, true);
          _oUtility.disableAnchor(oLblMSP, true);
          _oUtility.disableAnchor(oLblMA, true);

          //Show the correct tab
          _oTab.tabClick(tabId);

          switch (tabId) {
            case 0:
              //My Saved Searched Tab
              _oUtility.disableAnchor(oLblMSP, false);
              _oUtility.disableAnchor(oLblMA, false);
              Progress.fn.show(null, true, 'Loading Saved Searches');

              MySiteUIController.GetMySavedSearchesHTML(this._getMySavedSearchesHTML_Callback);
              return;

            case 1:
              //My Saved Properties Tab
              _oUtility.disableAnchor(oLblMSS, false);
              _oUtility.disableAnchor(oLblMA, false);

              sAbrand = _oUtility.getQueryStringParam('abrand');
              if (sAbrand !== null && typeof sAbrand !== 'undefined') {
                sBranding = 'a' + sAbrand;
              }

              sAbrand = _oUtility.getQueryStringParam('AgentID');
              if (sAbrand !== null && typeof sAbrand !== 'undefined') {
                sBranding = 'a' + sAbrand;
              }

              sTbrand = _oUtility.getQueryStringParam('tbrand');
              if (sTbrand !== null && typeof sTbrand !== 'undefined') {
                sBranding = 't' + sTbrand;
              }

              sTbrand = _oUtility.getQueryStringParam('AgentTeamID');
              if (sTbrand !== null && typeof sTbrand !== 'undefined') {
                sBranding = 't' + sTbrand;
              }

              //setTimeout("Progress.fn.show('',true,'Loading Saved Properties');",50);
              Progress.fn.show(null, true, 'Loading Saved Properties');
              MySiteUIController.GetMySavedPropertiesHTML(sBranding, this._getMySavedPropertiesHTML_Callback);
              return;

            case 2:
              //My Account Tab
              _oUtility.disableAnchor(oLblMSS, false);
              _oUtility.disableAnchor(oLblMSP, false);
              MySiteUIController.GetMyAccountHTML(this._getMyAccountHTML_Callback);
              return;

            default:
              // Should never happen
              return;
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.tabClick', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    /******************************************************************************************************************
    *									A J A X   M E T H O D S
    *******************************************************************************************************************/
    /*==================================================================================
    Method		: _getMySavedSearchesHTML_Callback
    Summary		: Ajax callback method to display the My Saved Searches in the 
    tab contents div control on the MySite home page.
    Author		: Dale Lawless
    Create Date	: 02/15/2007
    ====================================================================================*/
    _getMySavedSearchesHTML_Callback: function (response) {
      var sMySavedSearchesHTML = null;
      var oDivTabContents = null;

      try {
        if (response.error !== null) {
          Progress.fn.hide();
          _oErrorHandler.ResponseError('NRT.MySite.UI._getMySavedSearchesHTML_Callback', response);
          return;
        } else {
          if (response !== null && response.value !== null) {
            sMySavedSearchesHTML = response.value;
            if (sMySavedSearchesHTML !== null && typeof sMySavedSearchesHTML !== 'undefined') {
              // Fill the tab contents div
              oDivTabContents = document.getElementById('div_MainControl_TabContents');
              if (oDivTabContents !== null && typeof oDivTabContents !== 'undefined') {
                oDivTabContents.innerHTML = sMySavedSearchesHTML;
              }
            }
          }
        }
        Progress.fn.hide();
      }
      catch (err) {
        Progress.fn.hide();
        _oErrorHandler.Error('NRT.MySite.UI._getMySavedSearchesHTML_Callback', _oErrorHandler.ERRORTYPE_AJAX, err);
      }
    },

    /*==================================================================================
    Method		: _getMySavedPropertiesHTML_Callback
    Summary		: Ajax callback method to display the My Saved Properties in the 
    tab contents div control on the MySite home page.
    Author		: Dale Lawless
    Create Date	: 02/15/2007
    ====================================================================================*/
    _getMySavedPropertiesHTML_Callback: function (response) {
      var sMySavedPropertiesHTML = null;
      var oDivTabContents = null;

      try {
        if (response.error !== null) {
          Progress.fn.hide();
          _oErrorHandler.ResponseError('NRT.MySite.UI._getMySavedPropertiesHTML_Callback', response);
          return;
        } else {
          if (response !== null && response.value !== null) {
            sMySavedPropertiesHTML = response.value;
            if (sMySavedPropertiesHTML !== null && typeof sMySavedPropertiesHTML !== 'undefined') {
              // Fill the tab contents div
              oDivTabContents = document.getElementById('div_MainControl_TabContents');
              if (oDivTabContents !== null && typeof oDivTabContents !== 'undefined') {
                oDivTabContents.innerHTML = sMySavedPropertiesHTML;
                eval(_oUtility.getElementByTagNameAndID('hdnScript', 'INPUT').value);
              }
            }
          }
        }
        Progress.fn.hide();
      }
      catch (err) {
        Progress.fn.hide();
        _oErrorHandler.Error('NRT.MySite.UI._getMySavedPropertiesHTML_Callback', _oErrorHandler.ERRORTYPE_AJAX, err);
      }
    },

    /*==================================================================================
    Method		: _getMyAccountHTML_Callback
    Summary		: Ajax callback method to display the My Account in the 
    tab contents div control on the MySite home page.
    Author		: Dale Lawless
    Create Date	: 02/15/2007
    ====================================================================================*/
    _getMyAccountHTML_Callback: function (response) {
      var sMyAccountHTML = null;
      var oDivTabContents = null;

      try {
        if (response.error !== null) {
          _oErrorHandler.ResponseError('NRT.MySite.UI._getMyAccountHTML_Callback', response);
          return;
        } else {
          if (response !== null && response.value !== null) {
            sMyAccountHTML = response.value;
            if (sMyAccountHTML !== null && typeof sMyAccountHTML !== 'undefined') {
              // Fill the tab contents div
              oDivTabContents = document.getElementById('div_MainControl_TabContents');
              if (oDivTabContents !== null && typeof oDivTabContents !== 'undefined') {
                oDivTabContents.innerHTML = sMyAccountHTML;
              }
            }
          }
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI._getMyAccountHTML_Callback', _oErrorHandler.ERRORTYPE_AJAX, err);
      }
    },

    setAlertTextStyle: function (control) {
      var oParent = null;

      try {
        oParent = control.parentNode;

        if (control.checked) {
          oParent.className = 'smallbold';
        } else {
          oParent.className = 'small';
        }
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.setAlertTextStyle', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    },

    onKeyDown: function (e) {
      var key = window.event ? e.keyCode : e.which;

      try {
        //window.event.keyCode
        if (key === 13) {
          var target = e.target ? e.target : e.srcElement;

          if (target.tagName == 'A') {
            return true;
          }

          return false;
        }

        return true;
      }
      catch (err) {
      }
    },
    setupThumbnails: function (p1) {

      resultPhotoElements.push(p1);
      $('#featured').attr('id', 'featured_' + p1.propertyID);
      $('#featured-prev').attr('id', 'featured-prev_' + p1.propertyID);
      $('#featured-next').attr('id', 'featured-next_' + p1.propertyID);

      if (p1.photoElements.length < 2) {
        $('#featured-next_' + p1.propertyID).hide();
        $('#featured-prev_' + p1.propertyID).hide();
        $('div[id$="divPhotosPager_' + p1.propertyID + '"]').hide();
      }
      $('#imgThumbnail').attr('id', 'imgThumbnail_' + p1.propertyID);
      $('#currentPhoto').attr('id', 'currentPhoto_' + p1.propertyID);
      $('#totalPhotos').attr('id', 'totalPhotos_' + p1.propertyID);

      $('#imgThumbnail_' + p1.propertyID).show();
      $('#imgThumbnail_' + p1.propertyID).attr('src', p1.photoElements[0]);

      //now, inspect the length of the array, insert a slide if necessary
      if (p1.photoElements.length > 1) {

        if (p1.photoElements.length == 2) {

          var newSlide = $('#imgThumbnail_' + p1.propertyID).parent().parent().clone();
          newSlide.find('a').attr('id', 'hlPropertyImage1_' + p1.propertyID);
          var image = newSlide.find('img');

          image.attr('id', 'imgThumbnail1_' + p1.propertyID);
          image.attr('src', p1.photoElements[1]);

          $('#imgThumbnail_' + p1.propertyID).parent().parent().parent()[0].appendChild(newSlide[0]);
        } else {
          //need 3 slides
          $('#imgThumbnail_' + p1.propertyID).attr('src', p1.photoElements[1]);

          var newSlide = $('#imgThumbnail_' + p1.propertyID).parent().parent().clone();
          newSlide.find('a').attr('id', 'hlPropertyImage1_' + p1.propertyID);
          var image = newSlide.find('img');

          image.attr('id', 'imgThumbnail1_' + p1.propertyID);
          image.attr('src', p1.photoElements[2]);

          $('#imgThumbnail_' + p1.propertyID).parent().parent().parent()[0].appendChild(newSlide[0]);

          newSlide = $('#imgThumbnail_' + p1.propertyID).parent().parent().clone();
          newSlide.find('a').attr('id', 'hlPropertyImage0_' + p1.propertyID);
          image = newSlide.find('img');

          image.attr('id', 'imgThumbnail0_' + p1.propertyID);
          image.attr('src', p1.photoElements[0]);

          $('#imgThumbnail_' + p1.propertyID).parent().parent().parent()[0].insertBefore(newSlide[0],
					$('#imgThumbnail_' + p1.propertyID).parent().parent().parent()[0].firstChild);
        }

        $('#currentPhoto_' + p1.propertyID).text('1 of ');
        $('#totalPhotos_' + p1.propertyID).text(p1.photoElements.length.toString());

      }
      else {
        $('#currentPhoto_' + p1.propertyID).text('');
        $('#totalPhotos_' + p1.propertyID).text('');
      }

      $('#featured_' + p1.propertyID).cycle({
        fx: 'scrollHorz',
        timeout: 0,
        prev: '#featured-prev_' + p1.propertyID,
        next: '#featured-next_' + p1.propertyID,
        onPrevNextEvent: NRT.MySite.UI.onPrevNextSlide
      });
    },

    onPrevNextSlide: function (isNext, zeroBasedSlideIndex, slideElement) {
      var p0 = null;
      var propid = $(slideElement).find('img').attr('id');
      propid = propid.substring(propid.lastIndexOf('_') + 1);

      for (var i = 0; i < resultPhotoElements.length; i++) {
        if (resultPhotoElements[i].propertyID == propid) {
          p0 = resultPhotoElements[i];
          break;
        }
      }

      if (p0 == null) return;

      if (isNext)
        p0.currentImageIndex >= p0.photoElements.length - 1 ? p0.currentImageIndex = 0 : p0.currentImageIndex += 1;
      else
        p0.currentImageIndex == 0 ? p0.currentImageIndex = p0.photoElements.length - 1 : p0.currentImageIndex -= 1;

      $(slideElement).find('img').attr('src', p0.photoElements[p0.currentImageIndex]);
      $('#currentPhoto_' + p0.propertyID).text((p0.currentImageIndex + 1).toString() + ' of ');

      if (p0.photoElements.length > 2) {
        //if we're going forward, get the next slide, adjust its index
        var nextImageIndex = p0.currentImageIndex == p0.photoElements.length - 1 ? 0 : p0.currentImageIndex + 1;
        var prevImageIndex = p0.currentImageIndex == 0 ? p0.photoElements.length - 1 : p0.currentImageIndex - 1;

        //now load the other two slide's images with the correct src 
        var nextImageSlide = null;
        var prevImageSlide = null;

        switch (zeroBasedSlideIndex) {
          case 0:
            nextImageSlide = $(slideElement).parent().find('#imgThumbnail_' + p0.propertyID);
            prevImageSlide = $(slideElement).parent().find('#imgThumbnail1_' + p0.propertyID);
            break;
          case 1:
            nextImageSlide = $(slideElement).parent().find('#imgThumbnail1_' + p0.propertyID);
            prevImageSlide = $(slideElement).parent().find('#imgThumbnail0_' + p0.propertyID);
            break;
          case 2:
            nextImageSlide = $(slideElement).parent().find('#imgThumbnail0_' + p0.propertyID);
            prevImageSlide = $(slideElement).parent().find('#imgThumbnail_' + p0.propertyID);
            break;
        }

        nextImageSlide[0].src = p0.photoElements[nextImageIndex];
        prevImageSlide[0].src = p0.photoElements[prevImageIndex];
      }
    },

    /*==================================================================================
    Method		: showMoreFlickerPhotos
    Summary		: Opens flicker photos page from landing page.
    Author		: Rajendran
    Create Date	: 09/08/2010
    ====================================================================================*/
    showMoreFlickerPhotos: function (tags, title) {
      var sQueryString = null;

      try {
        NRT.MySite.UI.openLayeredWindow("/landing/MoreFlickrPhotos.aspx?Paging=true&Tags=" + tags, title, _WinW_Flicker_Photos, _WinH_Flicker_Photos, _DefFocusItemID_Flicker_Photos, _DefFocusItemType_Flicker_Photos);
      }
      catch (err) {
        _oErrorHandler.Error('NRT.MySite.UI.showMoreFlickerPhotos', _oErrorHandler.ERRORTYPE_JS, err);
      }

    },

    /*==================================================================================
    Method		: openLayeredWindow
    Summary		: This method will show an aspx page on a layered window.
    Author		: Rajendran
    Create Date	: 09/08/2010
    ====================================================================================*/
    openLayeredWindow: function (urlQueryString, title, width, height, sDefFocusItemID, sDefFocusItemType, preShowCallback) {
      var defWidth = width !== null ? width : 540;
      var defHeight = height !== null ? height : 440;
      var defTitle = title !== null ? title : "&nbsp;";
      var k_d_ent = null;
      var DialogID = "Dialog_" + title.replace(" ", "_");

      try {
        var url = urlQueryString + '&WIDTH=' + defWidth + '';

        $.get(url, {}, function (content) {

          var modalPopupBehaviorCtrl = $find('modalPopup');
          var obj = {};
          obj.url = url;
          obj.title = title;
          obj.content = content;

          if (preShowCallback !== 'undefined' && preShowCallback != null)
            obj = preShowCallback(obj);


          $("#modalPopupHeader").html(obj.title);
          $("#modalBody").html(obj.content);

          defWidth = defWidth + 50;
          document.getElementById('modalContainer').style.width = defWidth + 'px';
          document.getElementById('modalContainer').style.height = defHeight + 'px';
          document.getElementById('modalBody').style.display = 'block';
          document.getElementById('modalContainer').style.display = 'block';

          // Setting the width and height inorder to centre the Layered window in PS width and height.
          if (modalPopupBehaviorCtrl) {
            if (!$.browser.safari) {
              if (typeof (document.activeElement.id) !== 'undefined') {
                if (title !== 'Did You Mean?') {
                  modalPopupBehaviorCtrl.restoreOnFocus = document.activeElement.id;
                  document.getElementById('modalBody').style.margin = '10px';
                }
                else {
                  document.getElementById('modalBody').style.margin = '0px';

                  if (NRT.Property.Search.GlobalObject.getSelectedCtrlSourceName() !== 'TypeIn') {
                    modalPopupBehaviorCtrl.restoreOnFocus = document.activeElement.id;
                  }
                }
              }
            }
            modalPopupBehaviorCtrl.show();
            NRT.Utility.setActiveLayeredWindow(true);

            //IE6 hack
            if ($.browser.msie && parseInt($.browser.version) < 7) {
              document.getElementById('modalContainer').style.top = '-300px';
              document.getElementById('modalContainer').style.left = '-600px';
              return;
            }

            var top = (document.documentElement.clientHeight / 2) - (document.getElementById('modalContainer').offsetHeight / 2);
            document.getElementById('modalContainer').style.top = top + 'px';
            var left = (document.documentElement.clientWidth / 2) - (defWidth / 2);
            document.getElementById('modalContainer').style.left = left + 'px';
          }
        });
      }
      catch (err) {
        _oErrorHandler.Error('NRT.Utility.openLayeredWindow', _oErrorHandler.ERRORTYPE_JS, err);
        return;
      }
    }

  };
} ();

