﻿    var m_ShowPopupRegConfirmation = false;
    var HiddenItem = new Array();
    var m_AjaxURL = "";
    var redirectBack = false;
    var LogInType = "";


	function InPageLogValidationError(ErrorMsg)
	{
	    LogValidationError("100","3780",ErrorMsg,SessionFarmGuid,SiteString,ScriptName,PageExecutionGuid,"OpenSearchRegistration","OpenSearchRegistration");
	}
    function InPageSaveActionCode(ActionCode)
    {
        AjaxSaveActionCode(ActionCode,PageExecutionGuid);
    }
    function OpenLNPrivacy()
    {
        window.open('/xNet/MainSite/Marketing/About/Privacy.aspx?LinkCode=830&DisableTopBottomNav=true','Privacy','locationbar=no,scrollbars=yes,resizable=yes,locationbar=no');
    }
    
    function OpenTerms()
    {
        window.open('/xNet/MainSite/Marketing/About/TermsAndConditions.aspx?LinkCode=13760&DisableTopBottomNav=true','TermsAndCondition','locationbar=no,scrollbars=yes,resizable=yes,locationbar=no')
    }
    
    function ClearErrMsg()
    {
        var ErrMsgDiv = document.getElementById("ErrMsgDiv");ErrMsgDiv.innerHTML = "";
        var ErrMsgDivLogin = document.getElementById("ErrMsgDivLogin");ErrMsgDivLogin.innerHTML = "";       
    }
    function InPageCloseIt()
    {
        try{closeit()}catch(e){}
        ToggleSeeThruItems("hidden");
    }
    
    function DoPost_SearchResult(sURL)
    {   
        var SavedSearchCriteria1_PropAlertFrequencyDA = document.getElementById('PropAlertFrequencyDA');        
        if(SavedSearchCriteria1_PropAlertFrequencyDA != null)
        {
            var SaveSearchOption = "";
        
            var SavedSearchCriteria1_PropAlertFrequencyWK = document.getElementById('PropAlertFrequencyWK');
            var SavedSearchCriteria1_PropAlertFrequencyOFF = document.getElementById('PropAlertFrequencyOFF');
            if(SavedSearchCriteria1_PropAlertFrequencyDA.checked)
                SaveSearchOption = "DA"
            else if(SavedSearchCriteria1_PropAlertFrequencyWK.checked)
                SaveSearchOption = "WK"
            else if(SavedSearchCriteria1_PropAlertFrequencyOFF.checked)
                SaveSearchOption = "OFF"
            AddHiddenInputs('SavedSearchCriteria1_0_SavedSearchCriteriaName',document.getElementById('SavedSearchCriteriaName').value,true,HiddenPageFormName);
            AddHiddenInputs('SavedSearchCriteria1_0_PropAlertFrequency',SaveSearchOption,true,HiddenPageFormName); 
            HiddenField = $('SearchCriteriaXml');
            if (HiddenField)
                AddHiddenInputs("SearchCriteriaXml", HiddenField.value, true, HiddenPageFormName);
        }
        
        PostlnfProfileAndReports(sURL);
    }
    
    function DoPost_RecentSales(sURL)
    {
        var HiddenField = $('SelectedComparables');
        if (HiddenField)
            AddHiddenInputs("SelectedComparables", HiddenField.value, true, HiddenPageFormName);
        HiddenField = $('SelectedComparablesCount');
        if (HiddenField)
            AddHiddenInputs("SelectedComparablesCount", HiddenField.value, true, HiddenPageFormName);
        HiddenField = $('SelectedComparablesTotal');
        if (HiddenField)
            AddHiddenInputs("SelectedComparablesTotal", HiddenField.value, true, HiddenPageFormName);
        HiddenField = $('SearchCriteriaXml');
        if (HiddenField)
            AddHiddenInputs("SearchCriteriaXml", HiddenField.value, true, HiddenPageFormName);
        HiddenField = $('hidchkListingID');
        if (HiddenField)
            AddHiddenInputs("hidchkListingID", HiddenField.value, true, HiddenPageFormName);
        HiddenField = $('hidchkListingIDItemsOnThisPage');
        if (HiddenField)
            AddHiddenInputs("hidchkListingIDItemsOnThisPage", HiddenField.value, true, HiddenPageFormName);
            
        PostlnfProfileAndReports(sURL);
    }
    
    function DoPost_Profile(sURL) {
        PageForm.action = sURL + "&LID=" + InPageListingID + "&" + ProfileAdditionalParams;
        if (redirectBack === true)
            PageForm.action += "&DoRedirectAndNotPost=yes&RedirectURL=" + escape(window.location);
        PageForm.submit();
    }
    
    function DoPost_Report(sURL)
    {
        AddHiddenInputs("UseOriginalRedirectURL","Y",true,HiddenPageFormName); 
        PageForm.action = sURL;
        PageForm.submit();
    }
    
    function DoPost_Map(sURL)
    {
        AddHiddenInputs("UseOriginalRedirectURL","Y",true,HiddenPageFormName); 
        PageForm.action = sURL;
        PageForm.submit();
    }
    
    function DoPost(sURL) {

        PageForm.action = sURL;
        PageForm.submit();
    }
    
    function PopupReg()
    {
        var sURL = "/xnet/mainsite/user/InPageReg.aspx?PgCxtDir=Down";
        var sAltURL = AltRedirectURL.value;
        var sPopupRegConfirmation = PopupRegConfirmation_TF.value;
        AddHiddenInputs("EmailAddress",EmailAddress_TF.value,true,HiddenPageFormName);        
        AddHiddenInputs("Password",Password_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("FirstName",FirstName_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("LastName",LastName_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("Country",CountryList.options[CountryList.selectedIndex].value,true,HiddenPageFormName);
        AddHiddenInputs("PostalZipCode",PostalZipCode.value,true,HiddenPageFormName);
        AddHiddenInputs("IntPhone",IntPhone_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("AreaCode",AreaCode_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("Prefix",Prefix_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("Suffix",Suffix_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("Extension",Ext_TF.value,true,HiddenPageFormName);
        AddHiddenInputs("InpageActionType","Registration",true,HiddenPageFormName);
        AddHiddenInputs("RedirectURL",sAltURL,true,HiddenPageFormName);
        AddHiddenInputs("OriginalRedirectURL",sOriginalURL,true,HiddenPageFormName);
        AddHiddenInputs("PopupRegConfirmation", sPopupRegConfirmation, true, HiddenPageFormName);
        AddHiddenInputs("RememberMe", "false", true, HiddenPageFormName);
        AddHiddenInputs("LoopNewsOpt", LoopNews_CB.checked + "", true, HiddenPageFormName);
        
        ClearFormInput("embedProfile",HiddenPageFormName);
        switch(PageName)
		{
			case "SearchResults":
				DoPost_SearchResult(sURL);
				break;
			case "Map":
				DoPost_Map(sURL);
				break;
			case "Report":
			    DoPost_Report(sURL)
			    break;
		    case "RSSearchResults":
                DoPost_RecentSales(sURL);
                break;
            case "Profile":
                if(document.getElementById("embedProfile") != null)
                    document.getElementById("embedProfile").value = "";
				DoPost_Profile(sURL);
				break;
			default: 
			    DoPost(sURL);
				break;
		}
    }
    
    function PopupLogin() {

        ToggleLoginLink(false);
        
        var sURL = "/xnet/mainsite/user/InPageReg.aspx?PgCxtDir=Down";
        var sAltURL = AltRedirectURL.value;
        var sPopupRegConfirmation = PopupRegConfirmation_TF.value;
        var sEmailAddress = LoginUserName_TF.value;
        var sPassword = LoginPassword_TF.value;
        var sRememberMe = chkRememberMe.checked + "";
        if(sOriginalURL.toLowerCase().indexOf("reportcustomization.aspx") >= 0)
        {
            try
            {
            RemoveHiddenInputs("VIEWSTATEID",HiddenPageFormName);
            RemoveHiddenInputs("__VIEWSTATE",HiddenPageFormName);
            RemoveHiddenInputs("__EVENTTARGET",HiddenPageFormName);
            RemoveHiddenInputs("__EVENTARGUMENT",HiddenPageFormName);
            }
            catch(err)
            {}
            AddHiddenInputs("PgCxtGuid",ParentPageExecutionGuid,true,HiddenPageFormName);
            AddHiddenInputs("PgCxtFLKey","",true,HiddenPageFormName);
            //AddHiddenInputs("PgCxtCurFLKey","reportcustomization",true,HiddenPageFormName);
            AddHiddenInputs("PgCxtCurFLKey","SearchResults",true,HiddenPageFormName);
            AddHiddenInputs("PgCxtDir","Down",true,HiddenPageFormName);
            AddHiddenInputs("PageDataContextUpdateFromRequestOnNextPage","true",true,HiddenPageFormName);
            AddHiddenInputs("UseOriginalRedirectURL","Y",true,HiddenPageFormName);
        } 
        ClearFormInput("embedProfile",HiddenPageFormName);
        AddHiddenInputs("InpageActionType","Login",true,HiddenPageFormName);
        AddHiddenInputs("RedirectURL",sAltURL,true,HiddenPageFormName);
        AddHiddenInputs("OriginalRedirectURL",sOriginalURL,true,HiddenPageFormName);
        AddHiddenInputs("PopupRegConfirmation",sPopupRegConfirmation,true,HiddenPageFormName);
        AddHiddenInputs("EmailAddress",sEmailAddress,true,HiddenPageFormName);
        AddHiddenInputs("Password",sPassword,true,HiddenPageFormName);
        AddHiddenInputs("RememberMe",sRememberMe,true,HiddenPageFormName);

        m_AjaxURL = sURL;

        var sInput = '<PFRequestData Email="' + sEmailAddress + '" RememberUser="' + sRememberMe + '" Password="' + sPassword + '" DisableIntercept="true"></PFRequestData>';
        var sOutput = null;

        sOutput = RemoteScriptingCall('/xNet/MainSite/WebServices/SiteUser/SiteUser.asmx', sInput, 'Authenticate', 'http://www.loopnet.com/WebServices', 'PFResponseInfo', -1);
        //checking for getAttribute is erratic across browsers
        //try checking if attributes exist, assume that getAttribute will be there
        if (sOutput.attributes && sOutput.attributes.length > 0) {
            InPage_LogonCallback(sOutput.getAttribute("ReturnCode"));
        }
        else {
            InPage_LogonCallback(sOutput.childNodes[0].getAttribute("ReturnCode"));
        }
    }


    function InPage_LogonCallback(ReturnCode) {
        var sURL = m_AjaxURL;
        var bDisplayError = false;        
        if ( ReturnCode == '0') 
        {

            if (PageName == "SearchResults") {
                if (typeof (ShowSpecialPopUpForOldPMUsers) != "undefined" && ShowSpecialPopUpForOldPMUsers() && LogInType == "FS_PM_BOB") {
                    InPageSaveActionCode(295);
                }
                DoPost_SearchResult(sURL);

            }
            else if (PageName == "Profile") {
                if (document.getElementById("embedProfile") != null)
                    document.getElementById("embedProfile").value = "";
                DoPost_Profile(sURL);
            }
            else if (PageName == "Report") {
                DoPost_Report(sURL)
            }
            else if (PageName == "Map")
                DoPost_Map(sURL);
            else if (PageName == "RSSearchResults")
                DoPost_RecentSales(sURL);
            else
                DoPost(sURL);

            bDisplayError = false;
        }
        else
        {
            bDisplayError = true;
        }
        if (bDisplayError) 
        {
            var ErrMsgDivLogin = document.getElementById("ErrMsgDivLogin");
            ErrMsgDivLogin.innerHTML = "<div id=\"regError\"><img src=\"/images/icons/alert_icon.gif\"/><ul><li>The email and password combination you entered is invalid.</li></ul></div>";

            ToggleLoginLink(true);
        }
    }

    function ToggleLoginLink(bool) {

        var LoginLnk = document.getElementById("aLogin");
        var LoginImg = document.getElementById("aLoginImg");


        if (bool) { //enable
            if (LoginLnk) {
                LoginLnk.href = 'javascript:PopupLogin()';
                LoginLnk.disable = 0;
            }
            
            if (LoginImg) {
                LoginImg.src = "/images/buttons/openLease/btn_olLogIn.gif";
            }
            
        }
        else { //disable
            if (LoginLnk) {
                LoginLnk.href = 'javascript:void(0)';
                LoginLnk.disable = 1;
            }
            
            if (LoginImg) {
                LoginImg.src = "/images/buttons/openLease/btn_olLogInWait.gif";
            }
        }

    }

    function ToggleRegLink(bool) {

        if (bool) { //enable
            RegContinueImage.src = getCookie("RegContinueImage");
        }
        else { //disable
            RegContinueImage.src = "/images/buttons/openSale/btn_createFreeMembershipWait.gif";
        }

    }

    function PopupPurchase()
    {
        if(PageName == "SearchResults")
            DoPost_SearchResult(AltRedirectURL.value);
        else
            DoPost(AltRedirectURL.value);
                   
    }

    function CheckLoginSetFocus() {
    	try
    	{
    		if (InPageGetCookie("LastUserEmail") != '' &&
                LoginUserName_TF &&
                LoginUserName_TF.value != '' &&
                LoginPassword_TF &&
                LoginPassword_TF.value == '')
    		{
    			setTimeout(function()
    			{
    				//queue for focus
    				LoginPassword_TF.focus();    				
    			}, 1);
    		}
    	}
    	catch (err)
    	{
    		console.log(err);
    	}

    }
 
     
    function ToggleReg(Tag)
    {
        LoginDiv.style.display = "none";
        RegDiv.style.display = "none";
        UpSellDiv.style.display = "none";
        ReportUpSellDiv.style.display = "none";
        BasicListingUpSellDiv.style.display = "none";
        MapUpSellDiv.style.display = "none";
        var SavedSearchDiv = null;
        if (typeof (SavedSearchDivID) != 'undefined' && SavedSearchDivID)
			SavedSearchDiv = document.getElementById(SavedSearchDivID);
        if(SavedSearchDiv)
			SavedSearchDiv.style.display = "none";
		if (Tag == 1) 
		{
			RegDiv.style.display = "block";
			try {
				pageTracker._trackPageview('/virtual/registration/');
			}
			catch (e) {}
		} 
		else if (Tag == 0) {
			LoginDiv.style.display = "block";
			FocusFirstTextbox("divLoginInput");
			CheckLoginSetFocus();
		}
		else if (Tag == 2)
			UpSellDiv.style.display = "block";
		else if (Tag == 3)
			ReportUpSellDiv.style.display = "block";
		else if (Tag == 4)
			BasicListingUpSellDiv.style.display = "block";
		else if (Tag == 5)
			MapUpSellDiv.style.display = "block";
		else if (Tag == 6 && SavedSearchDiv)
			SavedSearchDiv.style.display = "block";
    }

    function GetValidateFromIFrame() {

        ToggleRegLink(false);
        
        var URL = "/xNet/MainSite/User/RegValidation.aspx?EmailAddress=" + EmailAddress_TF.value + "&PostalZipCode=" + PostalZipCode.value + "&CountryCode=" +CountryList.options[CountryList.selectedIndex].value + "&Rand=" + rand();
        RegValidationIFrame.src = URL;
    }
               
    function ValidateFields(FrameErrorMsg)
	{
	    var ErrMsg = FrameErrorMsg;
	    if(Password_TF.value.length <= 0)
	        ErrMsg += "<li>Password is required.</li>";
//	    else
//	    {
//	        if(Password_TF.value != ReEnteredPassword_TF.value)
//	            ErrMsg += "<li>Re-Enter password does not match password.</li>";
//	    }
	    if(FirstName_TF.value.length <= 0)
	        ErrMsg += "<li>First name is required.</li>";
	    if(LastName_TF.value.length <= 0)
	        ErrMsg += "<li>Last name is required.</li>";
	    if(CountryList.options[CountryList.selectedIndex].value =="")
	        ErrMsg += "<li>Country is required.</li>";
	    if(PhoneDiv.style.display == "none")
	    {
	        if(!IsValidPhone(IntPhone_TF.value))
	            ErrMsg += "<li>Invalid Phone Number.</li>";
	    }
	    else
	    {
	        if(!IsValidPhone(AreaCode_TF.value + Prefix_TF.value + Suffix_TF.value))
	            ErrMsg += "<li>Invalid Phone Number.</li>";
	    }

	    if (ErrMsg == "") {
	       
	        PopupReg();
	    }
	    else {
	        ToggleRegLink(true);
	        InPageLogValidationError(ErrMsg);
	        ErrMsg = "<div id=\"regError\"><img src=\"/images/icons/alert_icon.gif\" /><ul>" + ErrMsg;
	        ErrMsg = ErrMsg + "</ul></div>";
	        ErrMsgDiv.innerHTML = ErrMsg;
	        ErrMsgDiv.style.display = "block";
	    }
	}
	
	function TogglePhoneDisplay(DropDownObj)
	{
	    if(DropDownObj.options[DropDownObj.selectedIndex].value == "US" || DropDownObj.options[DropDownObj.selectedIndex].value == "CA")
        {
             PhoneDiv.style.display = "block";
             IntPhoneDiv.style.display = "none";    
        }
        else
        {
             PhoneDiv.style.display = "none";
             IntPhoneDiv.style.display = "block";   
        }
	}
	
    function ToggleSeeThruItems(Visibility)
    {
        try
        {
            if(Visibility == "hidden")
            {
                for(i=0; i<PageForm.elements.length; i++)
                {
                    try
                    {
                        if(PageForm.elements[i].type.indexOf("select") >= 0 && PageForm.elements[i].id.indexOf("InPageReg") < 0 && PageForm.elements[i].style.visibility != "hidden")
                        {
	                        PageForm.elements[i].style.visibility = Visibility;
	                        HiddenItem.push(PageForm.elements[i]);
	                    }
                    }
                    catch(e)
                    {} 
                }
            }
            else
            {
                for(i=0;i<HiddenItem.length; i++)
                {
                    HiddenItem[i].style.visibility = Visibility;
                }
                HiddenItem.length = 0;
            }
        }
        catch(ex)
        {
        } 
    }
    
    
    function InPageHandleCookie(sRegHeaderImage,sRegContinueImage,sLoginHeaderImage)
    {    
        if((sRegHeaderImage + "").indexOf(".gif") >=0)
        {
            RegHeaderImage.src = sRegHeaderImage;
            InPageSetCookie("RegHeaderImage",sRegHeaderImage);
        }
        else
            RegHeaderImage.src = getCookie("RegHeaderImage");
            
        if((sRegContinueImage + "").indexOf(".gif") >=0)
        {
            RegContinueImage.src = sRegContinueImage;
            InPageSetCookie("RegContinueImage",sRegContinueImage);
        }
        else
            RegContinueImage.src = getCookie("RegContinueImage");
            
        
        if((sLoginHeaderImage + "").indexOf(".gif") >=0)
        {
            LoginHeaderImage.src = sLoginHeaderImage;
            InPageSetCookie("LoginHeaderImage",sLoginHeaderImage);
        }
        else
            LoginHeaderImage.src = getCookie("LoginHeaderImage");
    }

    function InPageHandleCookieWithTextHeader(sRegHeaderText,sRegContinueImage,sLoginHeaderText,sLoginSubHeaderText)
    {
        if(sRegHeaderText != undefined && sRegHeaderText + "" != "")
        {
            RegHeaderText.innerText = sRegHeaderText;
            InPageSetCookie("RegHeaderText",sRegHeaderText);
        }
        else
            RegHeaderText.innerText = getCookie("RegHeaderText");
            
        if((sRegContinueImage + "").indexOf(".gif") >=0)
        {
            RegContinueImage.src = sRegContinueImage;
            InPageSetCookie("RegContinueImage",sRegContinueImage);
        }
        else
            RegContinueImage.src = getCookie("RegContinueImage");
            
        
        if(sLoginHeaderText != undefined && sLoginHeaderText + ""  != "")
        {
            LoginHeaderText.innerText = sLoginHeaderText;
            InPageSetCookie("LoginHeaderText",sLoginHeaderText);
        }
        else
            LoginHeaderText.innerText = getCookie("LoginHeaderText");
            
        if(sLoginSubHeaderText != undefined && sLoginSubHeaderText + "" != "")
        {
            LoginSubHeaderText.innerText = sLoginSubHeaderText;
            InPageSetCookie("LoginSubHeaderText", sLoginSubHeaderText);
        }
        else
            LoginSubHeaderText.innerText = getCookie("LoginSubHeaderText");

            
    }
    
    function ShowInPageReg()
    {
        GetBlackDivHeight();
        var scrOfY = 0;
        if( typeof( window.pageYOffset ) == 'number' ) 
        {
            //Netscape compliant
            scrOfY = window.pageYOffset;
        } 
        else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
        {
            //DOM compliant
            scrOfY = document.body.scrollTop;
        } 
        else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
        {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
        }
        
        document.getElementById("InPageDiv1").style.display = "block";
        var oInPageDiv2 = document.getElementById("InPageDiv2");
        oInPageDiv2.style.top = scrOfY + 100 + "px";
        oInPageDiv2.style.display = "block";
        ToggleSeeThruItems("hidden");
        
        try
        {
            nd();
        }
        catch(e)
        {
        }
        try
        {
            Page_ValidationActive = false;
	        document.getElementById("ValSum").style.visibility="hidden";
        }
        catch(e){}
        setCookie('InPageRegByPassBackButton', 'false', null, '/', null, null);
        setTimeout("InPageCloseIt()",10);
    }


    
    function HideInPageReg() {
        LogInType = "";
        ClearErrMsg();ToggleReg(-1);
        document.getElementById("InPageDiv1").style.display = "none";
        document.getElementById("InPageDiv2").style.display = "none";
        ToggleSeeThruItems("visible");
        try
        {
            Page_ValidationActive = true;
            document.getElementById("ValSum").style.visibility="visible";
        }
        catch(e){}
    }
    
    function keyHandler (evt) 
    {
        if(evt.which == 13)
        {
            return false;
        }
        else
            return true;
    }
    
    function GetBlackDivHeight()
    {
        var InPageDivObj = document.getElementById("InPageDiv1");
        if(InPageDivObj.style.height < 100)
        {
            InPageDivObj.style.height = findObjPos(document.getElementById("LowerRightCornerDiv"),"Y");	 
            if(document.body.clientWidth < 800)
                InPageDivObj.style.width = 800;
            else
                InPageDivObj.style.width =  document.body.clientWidth;
         }
    }
    
    function OnWinLoad()
    {
        try
        {
            
            if (document.layers)
                window.captureEvents(Event.KEYPRESS);    
            window.onkeypress = keyHandler;
            
            GetBlackDivHeight();
            
	         if(InpageActionType == "Login" && InpagePopupError != "") {

	             /*
	             
	             //Per Justin - The regbox should always be visible
	             var RegHeaderImage = "" + getCookie("RegHeaderImage");
	             if(RegHeaderImage.indexOf("alreadyAPremiumMember") >= 0)
	             {
	             var BuyBox_Div = document.getElementById("BuyBox");
	             var RegBox_Div = document.getElementById("RegBox");
	             BuyBox_Div.style.display = 'block';
	             RegBox_Div.style.display = 'none';
	                
	             }
	             */
	            
	            var Msg =  "<div id=\"regError\"><img src=\"/images/icons/alert_icon.gif\" /><ul><li>" + InpagePopupError + "</li></ul></div>";	

                //InpagePopupLoginWithTextHeader(PopupRegConfirmation, Msg);   
                InpagePopupLogin(PopupRegConfirmation, Msg);   
	            
	         }
	         else if(InpagePopupError != "")
	         {
	            var Msg =  "<div id=\"regError\"><img src=\"/images/icons/alert_icon.gif\" /><ul><li>" + InpagePopupError + "</li></ul></div>";

                //InpagePopupLoginWithTextHeader(PopupRegConfirmation, Msg);   
                InpagePopupLogin(PopupRegConfirmation, Msg);   
	         }
	         if(PopupRegConfirmation != "" && InpagePopupError == "")
	         {
	            var alertMsg = "Congratulations! You are now logged in as a LoopNet Member. A confirmation email has been sent to you. ";
	            if(InpageActionType == "Login")
	            {
	                if(PopupRegConfirmation.indexOf("@@") == 0)
	                {
	                    PopupRegConfirmation = PopupRegConfirmation.replace(/@@/, "");
	                    alertMsg = "";
	                }
	                else
    	                alertMsg = "You are now logged in. ";
	            }
	            alertMsg += PopupRegConfirmation;
    	        if(InPageGetCookie("ShowPopupRegConfirmation") != "true" && alertMsg != "")
    	        {
    	            if(!m_ShowPopupRegConfirmation)
    	            {
    	                alert(alertMsg);  
    	                m_ShowPopupRegConfirmation = true;
    	                //Save a cookie to tell me that I show this already
    	                InPageSetCookie("ShowPopupRegConfirmation","true");
    	            }
    	         }
	         }
	         InPageSetCookie("AutoRedirect","true");
	        
	    }
	    catch(ex)
	    {
	    
	    }
    }

	window.onresize=function()
	{
	   var InPageDivObj = document.getElementById("InPageDiv1");
	   if(document.body.clientWidth < 800)
	        InPageDivObj.style.width = 800;
	   else
	        InPageDivObj.style.width = document.body.clientWidth;
	}	
	   
    
    
    function ResetAltRedirectURL()
    {
        AltRedirectURL.value = "";
    }
    
   
    
    
    //Click Upsell Buttons
    function BuyPM()
    {
        var LinkCode = SRBuyPMSaveSearchDaily;
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPMSaveSearchDaily;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=1200&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx";
        PopupPurchase();
        
    }
    
    function Buy24Hr()
    {
        var LinkCode = SRBuy24HRPSMSaveSearchDaily;
        if(ForSaleNotLogin)
            LinkCode = SROSBuy24HRPSMSaveSearchDaily;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=500&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx";
        PopupPurchase();
    }
    
    function BarBuyPM(analytics)
    {
		analytics=analytics||'';
        var LinkCode = "18860";
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPMBar;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=200&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx"+'&'+analytics;
        setTimeout("PopupPurchase()",200);
        
    }
    
    function BarBuyPSM(analytics)
    {
		analytics=analytics||'';
        var LinkCode = "18870";
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPSMBar;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=1200&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx"+'&'+analytics;
        setTimeout("PopupPurchase()",200);
    }
    
    function ReportBuyPM()
    {
        var LinkCode = SRBuyPMReport;
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPMReport;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=1200&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Report/ReportCustomization.aspx";
        PopupPurchase();
        
    }
    
    function ReportBuy24Hr()
    {
        var LinkCode = SRBuy24HRSPSMReport;
        if(ForSaleNotLogin)
            LinkCode = SROSBuy24HRSPSMReport;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=500&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Report/ReportCustomization.aspx";
        PopupPurchase();
    }
    
     function BasicListingBuyPM()
    {
        var LinkCode = SRBuyPMBaslicListing;
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPMBaslicListing;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=1200&linkcode=" + LinkCode  + "&redirecturl=/xNet/MainSite/Listing/Profile/Profile.aspx?LID=" + ListingID;
        PopupPurchase();
        
    }
    
    function BasicListingBuy24Hr()
    {
        var LinkCode = SRBuy24HRSPSMBasicListing;
        if(ForSaleNotLogin)
            LinkCode = SROSBuy24HRSPSMBasicListing;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=500&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Profile/Profile.aspx?LID=" + ListingID;
        PopupPurchase();
    }
    
    
    function MapBuyPM()
    {
        var LinkCode = SRBuyPMReport;
        if(ForSaleNotLogin)
            LinkCode = SROSBuyPMReport;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=1200&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx";
        setTimeout("PopupPurchase()",200);
    }
    
    function MapBuy24Hr()
    {
        var LinkCode = SRBuy24HRSPSMReport;
        if(ForSaleNotLogin)
            LinkCode = SROSBuy24HRSPSMReport;
        AltRedirectURL.value = "/xNet/MainSite/Product/Product.aspx?UsePgCxt=Y&PgCxtDir=Down&FromOpenLease=Y&CategoryID=500&linkcode=" + LinkCode + "&redirecturl=/xNet/MainSite/Listing/Search/SearchResults.aspx";
        PopupPurchase();
    }
    
    //Show Upsells function
    function InpageMapPopupUpSell(ActionCode)
    {
        ShowInPageReg();
        ToggleReg(5);
        InPageSaveActionCode(ActionCode);
    }
    
    function InpageBasicListingPopupUpSell(ActionCode)
    {
        document.getElementById("BasicListingTitle").innerHTML = PropertyType;
        document.getElementById("BasicListingLoc").innerHTML = CityState;
        ShowInPageReg();
        ToggleReg(4);
        InPageSaveActionCode(ActionCode);
    }
    
    function InpageReportPopupUpSell(ActionCode)
    {
        ShowInPageReg();
        ToggleReg(3);
        InPageSaveActionCode(ActionCode);
    }
    function InpagePopupUpSell(ActionCode,Msg)
    {
        PopupRegConfirmation_TF.value = Msg + "";
        ShowInPageReg();
        ToggleReg(2);
        InPageSaveActionCode(ActionCode);
    }
    
    //so if i pass in this: '.' you are telling me that is a valid url???
    //this function should be called: ContainsDot();
    function IsValidURL(sURL)
    {
        if(sURL == null)
            return false;
        if(sURL.indexOf(".") >= 0)
            return true;
        else
            return false;
    }
   
       //Actioncode Related function
    function InpagePopupLogin(sMsg, sError, sRegHeaderImage, sRegContinueImage, sLoginHeaderImage, sAltRedirectURL, sValidateMembership) {
        return InpagePopupLoginWithFooter(sMsg, sError, sRegHeaderImage, sRegContinueImage, sLoginHeaderImage, "", sAltRedirectURL, sValidateMembership);
    }

    var defaultFooterSection = "";
    
    //Actioncode Related function
    function InpagePopupLoginWithFooter(sMsg, sError, sRegHeaderImage, sRegContinueImage, sLoginHeaderImage, footerHtml, sAltRedirectURL, sValidateMembership)
    {
        try
        {
            InPageHandleCookie(sRegHeaderImage,sRegContinueImage,sLoginHeaderImage);
            PopupRegConfirmation_TF.value = sMsg + "";
            if(IsValidURL(sAltRedirectURL))
                AltRedirectURL.value = sAltRedirectURL;
            try
            {
                if(sValidateMembership != null && sValidateMembership != "")
                {
                    ValidateMembership.value = sValidateMembership;
                }
            }
            catch(ex1){}
            if(sError != null)
            {
                var ErrMsgDivLogin = document.getElementById("ErrMsgDivLogin");
                ErrMsgDivLogin.innerHTML = sError;
            }

            //Per Otto - There’s one scenario where it was removed on purpose, on Report customization.  
            //Registering via that page was resulting in an error and so the agreed upon solution was to remove overlay registration in that instance only.
            if (sLoginHeaderImage.indexOf("ToCreateAReportLogIn") >= 0 || sLoginHeaderImage.indexOf("alreadyASubscriber") >= 0)
                document.getElementById("RegBox").style.display = "none";

            /* 
            //Per Justin - The regbox should always be visible
            if(sValidateMembership == "true")
            document.getElementById("RegBox").style.display="none";
                
            if(typeof(NoBecomeFreeMember) != "undefined")
            document.getElementById("RegBox").style.display="none";                
            */

            if (footerHtml != "" && footerHtml != null) {
                var footerSection = document.getElementById('RegBox');
                defaultFooterSection = footerSection.innerHTML;
                footerSection.innerHTML = footerHtml;
            }
            else {
                if (defaultFooterSection != "") {
                    document.getElementById('RegBox').innerHTML = defaultFooterSection;
                }
            }
            
            ShowInPageReg();
            ToggleReg(0);
        }
        catch(ex)
    	{
    	}
    }
    
    function InpagePopupLoginWithTextHeader(sMsg, sError,sRegHeaderText,sRegContinueImage,sLoginHeaderText, sLoginSubHeaderText, sAltRedirectURL,sValidateMembership,sActionCode)
    {
        try
        {
            
            InPageHandleCookieWithTextHeader(sRegHeaderText,sRegContinueImage,sLoginHeaderText,sLoginSubHeaderText);
            PopupRegConfirmation_TF.value = sMsg + "";
            if(IsValidURL(sAltRedirectURL))
                AltRedirectURL.value = sAltRedirectURL;
            try
            {
                if(sValidateMembership != null && sValidateMembership != "")
                {
                    ValidateMembership.value = sValidateMembership;
                }
            }
            catch(ex1){}
            if(sError != null)
            {
                var ErrMsgDivLogin = document.getElementById("ErrMsgDivLogin");
                ErrMsgDivLogin.innerHTML = sError;
            }

            /*
            //Per Justin - The regbox should always be visible
            if(sValidateMembership == "true")
                document.getElementById("RegBox").style.display="none";
            */
            
            ShowInPageReg();
            ToggleReg(0);
            if(sActionCode != undefined && isInteger(sActionCode))
            {
                InPageSaveActionCode(sActionCode);
            }
        }
        catch(ex) {}
    }
    
    function InpagePopupRegWithTextHeader(sMsg, sError,sRegHeaderText,sRegContinueImage,sLoginHeaderText, sLoginSubHeaderText,sAltRedirectURL,sValidateMembership,sActionCode)
    {
        try
        {
            
            InPageHandleCookieWithTextHeader(sRegHeaderText,sRegContinueImage,sLoginHeaderText, sLoginSubHeaderText);
            PopupRegConfirmation_TF.value = sMsg + "";
            AltRedirectURL.value = sAltRedirectURL;
            if(sError != null)
            {
                var ErrMsgDiv = document.getElementById("ErrMsgDiv");
                ErrMsgDiv.innerHTML = sError;
            }
            ShowInPageReg();
            ToggleReg(1);
            
            if(sActionCode != undefined && isInteger(sActionCode))
            {
                InPageSaveActionCode(sActionCode);
            }
         }
         catch(ex)
         {
         
         }
    }
    
    function InpagePopupReg(sMsg, sError,sRegHeaderImage,sRegContinueImage,sLoginHeaderImage,sAltRedirectURL,sActionCode)
    {
        try 
        {
            if (typeof getCookie != 'undefined' && (getCookie("UserInfo_AssociateID") != null && getCookie("UserInfo_AssociateID") > 0)) 
            {
                InpagePopupLogin("", "", sRegHeaderImage, sRegContinueImage, sLoginHeaderImage, sAltRedirectURL, "true");
            }
            else
            {
                InPageHandleCookie(sRegHeaderImage,sRegContinueImage,sLoginHeaderImage);
                PopupRegConfirmation_TF.value = sMsg + "";
                AltRedirectURL.value = sAltRedirectURL;
                if(sError != null)
                {
                    var ErrMsgDiv = document.getElementById("ErrMsgDiv");
                    ErrMsgDiv.innerHTML = sError;
                }
                ShowInPageReg();
                ToggleReg(1);
                if(sActionCode != '')
                    InPageSaveActionCode(sActionCode);
             }
         }
         catch(ex)
         {
         
         }
    }
    
    function FocusFirstTextbox(divWrapper)
    {    
        // Set focus to first TextBox, icp#
        var sTag;
        var divRegInput = document.getElementById(divWrapper);
        if(divRegInput != null)
        {
            for(var i=0; i<divRegInput.childNodes.length; i++)
            {
                sTag = new String(divRegInput.childNodes[i].tagName);
                if(sTag.toUpperCase() == "INPUT")
                {
                    divRegInput.childNodes[i].focus();
                    break;
                }
            }
        }
    }
        
    function triggerLogin(evt)
    {
        var keynum;
        if(window.event)
            keynum = window.event.keyCode;
        else if(evt.which)
            keynum = evt.which;
        
        if(keynum == 13)
        {
            //if user pressed the enter key, do login...
            PopupLogin();
            return false;
        } 
       
        return true;
    }    


