SetupNamespaces("EZLandlordForms.Controls");

EZLandlordForms.Controls.FileDownloadInfo = {
    preloadedImages: ["/images/ajax-loader.gif", 
        "/images/layout2009/forms/builder-wizard/collapse_right_dark.gif", 
        "/images/layout2009/forms/builder-wizard/expand_dark_up.gif", 
        "/images/layout2009/forms/builder-wizard/collapse_right_light.gif", 
        "/images/layout2009/forms/builder-wizard/expand_light_up.gif"], 
    selectionCheckboxIDs: [],
    
    ShowSelectionCheckboxes: function() {
        for (var c=0; c < EZLandlordForms.Controls.FileDownloadInfo.selectionCheckboxIDs.length; c++)
            Get(EZLandlordForms.Controls.FileDownloadInfo.selectionCheckboxIDs[c]).parentNode.style.display = "block";
    },

    ExpandDetails: function(sourceElem, arrowImgElemID, expandArrowImgSrc, collapseArrowImgSrc, builtID, documentID, leaseID, propertyID, documentHasBeenEmailed, legacyIsEmailRead, legacyReadReceiptTime, customFieldsData, detailsElemID) { 
        Get(arrowImgElemID).src = collapseArrowImgSrc;
    
        var detailsElem = Get(detailsElemID);
        ClearElem(detailsElem);
        detailsElem.style.display = "block";
        
        detailsElem.style.textAlign = "center";
        detailsElem.style.fontSize = "18px";
        detailsElem.style.fontWeight = "bold";
        detailsElem.style.color = "#171553";
        
        var loadingImgElem = Elem("img");
        loadingImgElem.src = "/images/ajax-loader.gif";
        loadingImgElem.width = 32;
        loadingImgElem.height = 32;
        loadingImgElem.alt = "Loading...";
        loadingImgElem.align = "absmiddle";
        detailsElem.appendChild(loadingImgElem);
        detailsElem.appendChild(Text(" Loading..."));
        
        sourceElem.onclick = function() {
                EZLandlordForms.Controls.FileDownloadInfo.CollapseDetails(sourceElem, arrowImgElemID, expandArrowImgSrc, collapseArrowImgSrc, builtID, documentID, leaseID, propertyID, documentHasBeenEmailed, legacyIsEmailRead, legacyReadReceiptTime, customFieldsData, detailsElemID);
                return false;
            };
        
        var msg = new Pliner.Util.Ajax.Message("/members/documents/getdetails.aspx", 0);
        msg.AddPostDataKey("builtID", builtID);
        msg.AddPostDataKey("documentID", documentID);
        msg.AddPostDataKey("leaseID", leaseID);
        msg.AddPostDataKey("propertyID", propertyID);
        msg.AddPostDataKey("documentHasBeenEmailed", documentHasBeenEmailed);
        msg.AddPostDataKey("legacyIsEmailRead", legacyIsEmailRead);
        msg.AddPostDataKey("legacyReadReceiptTime", legacyReadReceiptTime);
        msg.AddPostDataKey("customFieldsData", customFieldsData);
        msg.AddOnCompletedEvent(function(msg) { 
                detailsElem = Get(detailsElemID);
                detailsElem.style.textAlign = "left";
                detailsElem.style.fontSize = "11px";
                detailsElem.style.fontWeight = "normal";
                detailsElem.style.color = "#000000";
                detailsElem.innerHTML = msg.responseText;
                detailsElem = null;
            });
        msg.AddOnErrorEvent(function(msg) { 
                alert("Details could not be loaded.  Please try again.");
                EZLandlordForms.Controls.FileDownloadInfo.CollapseDetails(sourceElem, arrowImgElemID, expandArrowImgSrc, collapseArrowImgSrc, builtID, documentID, leaseID, propertyID, documentHasBeenEmailed, legacyIsEmailRead, legacyReadReceiptTime, customFieldsData, detailsElemID);
            });
            
        detailsElem = null;
        ajaxConnection.AddToQueue(msg);
    }, 
    
    CollapseDetails: function(sourceElem, arrowImgElemID, expandArrowImgSrc, collapseArrowImgSrc, builtID, documentID, leaseID, propertyID, documentHasBeenEmailed, legacyIsEmailRead, legacyReadReceiptTime, customFieldsData, detailsElemID) { 
        Get(arrowImgElemID).src = expandArrowImgSrc;
    
        var detailsElem = Get(detailsElemID);
        detailsElem.style.display = "none";
        detailsElem = null;
        
        sourceElem.onclick = function() {
                EZLandlordForms.Controls.FileDownloadInfo.ExpandDetails(sourceElem, arrowImgElemID, expandArrowImgSrc, collapseArrowImgSrc, builtID, documentID, leaseID, propertyID, documentHasBeenEmailed, legacyIsEmailRead, legacyReadReceiptTime, customFieldsData, detailsElemID);
                return false;
            };
    }, 
    
    DeleteHistory: function(builtID, fileDownloadInfoElemID) { 
        var fileDownloadInfoElem = Get(fileDownloadInfoElemID);
        fileDownloadInfoElem.style.background = "#F8C8C8 none no-repeat scroll left top";
        
        var msg = new Pliner.Util.Ajax.Message("/members/documents/deletehistory.aspx", 0);
        msg.AddPostDataKey("builtID", builtID);
        msg.AddOnCompletedEvent(function(msg) {
                fileDownloadInfoElem = Get(fileDownloadInfoElemID);
                
                FadeOpacity(fileDownloadInfoElemID, 100, 0, 1000, 12);
                
                setTimeout(function() {
                        fileDownloadInfoElem.style.display = "none";
                        fileDownloadInfoElem = null;
                    }, 1250);
            });
        msg.AddOnErrorEvent(function(msg) { alert("This document could not be deleted. Please try again."); });
        
        fileDownloadInfoElem = null;
        ajaxConnection.AddToQueue(msg);
    }
};

Pliner.Util.Display.PreloadImages(EZLandlordForms.Controls.FileDownloadInfo.preloadedImages);