﻿var Onclick = true;
var IE = document.all ? true : false
if (!IE) document.captureEvents(Event.MOUSEDOWN)
document.onmousedown = HideAllDropDown;
function SupressOnClick() {
    Onclick = false;
}
function HideAllDropDown() {
    try {
        if (Onclick) {
            document.getElementById("linkListing").style.display = "none";
            document.getElementById("divRateDropdown").style.display = "none";
            document.getElementById("embedListing").style.display = "none";
            document.getElementById("overlay").style.display = "none";
        }
        Onclick = true;
    }
    catch (e) {
    }
}


function ImageInfo() {
    this.ImageURL = "";
    this.ImageTitle = "";
}

function ProfileSaveActionCode(ActionCode, ActionCodeValue) {
    try
    {
        var sXml = '<PFRequestData BypassLogServiceStats="Yes" PageExecutionGuid="' + PageExecutionGuid + '" ActionCode="' + ActionCode + '" ActionCodeValue="' + ActionCodeValue + '"></PFRequestData>';
        document.getElementById('ifMap').contentWindow.RemoteAJAXCall(null, '/xNet/MainSite/WebServices/WebStatistics/RequestInfo.asmx', sXml, 'UpdateActionCode', 'http://www.loopnet.com/WebServices', -1);
        return true;
    }
    catch(eX){}
}

function ProfileCheckAttachmentPassword(AttchmentID, Password) {

    var sXml = '<PFRequestData   AttachmentID="' + AttchmentID + '" PasswordConfidential="' + Password + '" SlideShow="false" />';
    var sReturn = document.getElementById('ifMap').contentWindow.RemoteScriptingCall('/xNet/MainSite/WebServices/Attachments/Attachment.asmx', sXml, 'SetSiteUserAttachmentPasswordForProfile', 'http://www.loopnet.com/WebServices', 'PFResponseInfo', -1);
    if (sReturn.getAttribute("ReturnCode") != "0") {
        return null;
    }
    else {

        var Data = sReturn.firstChild.data;
        var StartIndex = Data.indexOf("ImagePath=") + 10;
        var EndIndex = Data.indexOf("&ImageTitle=");
        var ImageURL = Data.substring(StartIndex, EndIndex);
        var ImageTitle = Data.substring(EndIndex + 12, Data.indexOf("'", EndIndex));
        var oImageInfo = new ImageInfo();
        oImageInfo.ImageURL = ImageURL;
        oImageInfo.ImageTitle = ImageTitle;
        return oImageInfo;
    }
}

function AttachAccessCheck(AttachmentID, description, filesize, cssClass)
{
    var attachment = null;
    
    toggle('checkingButton' + AttachmentID); 
    toggle('submitButton' + AttachmentID); 
         
    if(document.getElementById('Password'+AttachmentID) && document.getElementById('Password'+AttachmentID).value + '' != '')
        attachment = ProfileCheckAttachmentPassword(AttachmentID, document.getElementById('Password'+AttachmentID).value);

    toggle('checkingButton' + AttachmentID); 
    toggle('submitButton' + AttachmentID); 
                    
    if(attachment != null)
    {
        var unlockedLI = '<a href="' + attachment.ImageURL + '" title="' + attachment.ImageTitle +
                          '" target="_blank">' + description + '</a><em>(' + filesize + ')</em>';
                          
        if(document.getElementById('liConfidential'+AttachmentID))
        {
            document.getElementById('liConfidential'+AttachmentID).className = cssClass;
            document.getElementById('liConfidential'+AttachmentID).innerHTML = unlockedLI;
        }
     }
     else
     {
        if(document.getElementById('confidentialValidation' + AttachmentID))
            document.getElementById('confidentialValidation' + AttachmentID).style.display = '';
     }
}
        
            
 function toggle(id) {
                var e = document.getElementById(id);                
                if(e.style.display == 'none')
                    e.style.display = '';
                else
                    e.style.display = 'none';
            }


 function AttachAccessInput(AttachmentID, gotFocus) 
 {
    if (document.getElementById('Password' + AttachmentID) && document.getElementById('Password' + AttachmentID).value == '') 
    {
        //just recieved focus so clear the background image, else leaving focus with empty text, put image back.
        if (gotFocus != null || gotFocus == 'true')
            document.getElementById('Password' + AttachmentID).style.backgroundImage = 'url(\'\')';
        else
            document.getElementById('Password' + AttachmentID).style.backgroundImage = 'url(\'/images/profile/enterPasswordToUnlock.gif\')';
    }
 }

 function AttachAccessInputEnter(event, AttachmentID, description, filesize, cssClass) 
 {
     //PW text field has focus, minimize browser, go back to browser still has focus as you type in pw background image is still there.  
     AttachAccessInput(AttachmentID, 'true');
     
     //function to check for enter key and call check password
     if (window.event && window.event.keyCode == 13)
     { AttachAccessCheck(AttachmentID, description, filesize, cssClass); return false; }
     else if (event && event.which == 13)
     { AttachAccessCheck(AttachmentID, description, filesize, cssClass); return false; }
 }
 
 function InPageRegEmailListingClick(sRedirectURL,aObj)
{
    sRedirectURL = aObj.href;
    sModURL = sRedirectURL.replace(/PgCxtDir=/,"");
    if(ForLeaseNotLogin || ForSaleNotLogin)
    {
        try{aObj.href = "javascript:DoNothing()";}catch(HrefEx){}
        
        if(typeof getCookie != 'undefined' && (getCookie("UserInfo_AssociateID") != null && getCookie("UserInfo_AssociateID") > 0))
        {
            //changed to login per ICP 5248
            InpagePopupLogin("","","/images/titles/openLease/ToEmailThisListing.gif","/images/buttons/openLease/btn_continueToEmailListing.gif","/images/titles/openLease/ToEmailThisListingLogin.gif",sModURL,'true');
            //Fire ActionCode
	        LNSaveActionCode(POPUP_LOGIN_ACTIONCODE);
        }
        else
        {
            InpagePopupReg("","","/images/titles/openLease/ToEmailThisListing.gif","/images/buttons/openLease/btn_continueToEmailListing.gif","/images/titles/openLease/ToEmailThisListingLogin.gif",sModURL,PPOLEmailListingClick);
        }
        
        try{aObj.href = sRedirectURL;}catch(HrefEx){}
        return false;
    }
    else
        return true;
}


function InPageSavePropertyClickSEO(m_sRedirectURL, aObj)
{
    if(!IsUserLoggedOn)
    {
        try{aObj.href = "javascript:DoNothing()";}catch(HrefEx){}
        
        if(typeof getCookie != 'undefined' && (getCookie("UserInfo_AssociateID") != null && getCookie("UserInfo_AssociateID") > 0))
        {
            //changed to login per ICP 5248
            InpagePopupLogin("Click “Watch this Property” again to watch this property.","","/images/titles/openLease/ToSaveProperties.gif","/images/buttons/openLease/btn_continueToSaveProperty.gif","/images/titles/openLease/ToSavePropertiesLogin.gif",m_sRedirectURL,"true");
            //Fire ActionCode
	        LNSaveActionCode(POPUP_LOGIN_ACTIONCODE);
        }
        else
        {
            InpagePopupReg("Click “Watch this Property” again to watch this property.","","/images/titles/openLease/ToSaveProperties.gif","/images/buttons/openLease/btn_continueToSaveProperty.gif","/images/titles/openLease/ToSavePropertiesLogin.gif",m_sRedirectURL,PPOLSavePropertyClick);
        }
        
        return;
    }
}
	
function InPageSavePropertyClick(aObj)
{
    if(!IsUserLoggedOn)
    {
        try{aObj.href = "javascript:DoNothing()";}catch(HrefEx){}
        
        if(typeof getCookie != 'undefined' && (getCookie("UserInfo_AssociateID") != null && getCookie("UserInfo_AssociateID") > 0))
        {
            //changed to login per ICP 5248
            InpagePopupLogin("Click “Watch this Property” again to watch this property.","","/images/titles/openLease/ToSaveProperties.gif","/images/buttons/openLease/btn_continueToSaveProperty.gif","/images/titles/openLease/ToSavePropertiesLogin.gif","","true");
            //Fire ActionCode
	        LNSaveActionCode(POPUP_LOGIN_ACTIONCODE);
        }
        else
        {
            InpagePopupReg("Click “Watch this Property” again to watch this property.","","/images/titles/openLease/ToSaveProperties.gif","/images/buttons/openLease/btn_continueToSaveProperty.gif","/images/titles/openLease/ToSavePropertiesLogin.gif","",PPOLSavePropertyClick);
        }
        
        return;
    }
}
		
function InPageRegContactBrokerClick(m_sRedirectURL,aObj)
{
    sRedirectURL = aObj.href;
    if((sRedirectURL.indexOf('javascript') >= 0 || sRedirectURL == '') && typeof(aObj.id) != 'undefined' && aObj.id != '' && eval(aObj.id +'_href')){
		sRedirectURL = eval(aObj.id +'_href');
    }
    try{
    sModURL = sRedirectURL.replace(/PgCxtDir=/,"");
    }catch(e){sModURL = '';}

    if(!IsUserLoggedOn)
    {
        try{aObj.href = "javascript:DoNothing()";}catch(HrefEx){}
        if(typeof getCookie != 'undefined' && (getCookie("UserInfo_AssociateID") != null && getCookie("UserInfo_AssociateID") > 0))
        {
	        //changed to login per ICP 5248
	        if(ForLeaseBasicListing)
	            InpagePopupLogin("", "", "/images/titles/openLease/ToInquireAboutListing.gif", "/images/buttons/openLease/btn_continueToInquireListing.gif", "/images/titles/openLease/ToInquireAboutListingLogin.gif", sModURL, "true");
	        else
	            InpagePopupLogin("", "", "/images/titles/openLease/ToEmailTheListingBrokerLoginFS.gif", "/images/buttons/openLease/btn_continueToEmailBrokerFS.gif", "/images/titles/openLease/ToEmailTheListingBrokerLogin.gif", sModURL, "true");
	        //Fire ActionCode
	        LNSaveActionCode(POPUP_LOGIN_ACTIONCODE);
	    }
	    else
	    {
            if(ForLeaseBasicListing)
	            InpagePopupReg("","","/images/titles/openLease/ToInquireAboutListing.gif","/images/buttons/openLease/btn_continueToInquireListing.gif","/images/titles/openLease/ToInquireAboutListingLogin.gif",sModURL,PPOLContactBrokerClick);
	        else
	            InpagePopupReg("","","/images/titles/openLease/ToEmailTheListingBrokerLoginFS.gif","/images/buttons/openLease/btn_continueToEmailBrokerFS.gif","/images/titles/openLease/ToEmailTheListingBrokerLogin.gif",sModURL,PPOSContactBrokerClick);
	    }
        try{aObj.href = sRedirectURL;}catch(HrefEx){}
        return false;
    }
    else
    {
        return true;
    }
}
		
function makePopupProfile(h, fixedsize) {

    var AdditionalVars = "";
    try {
        if (document.getElementById("ifMap").style.display == "none")
            AdditionalVars = "&HideMap=Y";
    } catch (e) { }
    
    
    var w_height = 0;	
    var w_width = 800;
    var top = 30;
    var left = 30;
	
    if(fixedsize)
    {
        w_height = 436;
        w_width = 626;
        top = 250;
        left = 350;
    }
    else
    {
        w_height = (screen.height ? screen.height : 620);	
        w_height = (w_height > 620 ? w_height : 620)
    }

    h += AdditionalVars;
    popup = window.open(h,"popup1","width=" + w_width + ",height=" + w_height + ",top=" + top + ",left=" + left + ",toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=no,screenX=200,screenY=200");
    // URL of popup window
    popup.location.href = h;
    if (popup.opener == null) popup.opener = window;
    //popup.opener.name = "main";
}


function makePopupProfileImage(h, ht, wi){
   var popupstr = "width=" + wi + ",height=" + ht + ",top=30,left=30,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,menubar=no,screenX=200,screenY=200";
	popup = window.open(h,"popupImage",popupstr);
	// URL of popup window
	popup.location.href = h;
	if (popup.opener == null) popup.opener = window;
	//popup.opener.name = "main";
}
        
function DoNothing()
{}


function toggleSummary() {
    var printFull = document.getElementById('listingProfilePrintSummary');
    var printAdditionalPhotos = document.getElementById('listingProfilePrintAdditionalPhotos');
    var dateCreated = document.getElementById('dateCreated');
    var printShort = document.getElementById('printOption1');

    if (printShort.checked == true) {
        printFull.style.display = 'none';
        printAdditionalPhotos.style.display = 'none';
        dateCreated.style.display = 'none';
    }
    else {
        printFull.style.display = '';
        printAdditionalPhotos.style.display = '';
        dateCreated.style.display = '';
    }
}

function profileLoad() {
    //if we don't have the profile navigation then change the body class.
    if (document.getElementById("profileNavigation") == null) {
        
        var sClassName = document.body.className.replace(/ruledpage/,'');
        document.body.className = "homepage " + sClassName;
        //alert(document.body.className);
    }
}
