﻿var bvc = new Object();
var impounds;

bvc.showMessage = function (obj, id) {
    // Dialog			
    $('#messageDiv').dialog({
        title: 'BorrowersViewCentral.com - Message Detail',
        autoOpen: false,
        width: 600,
        height: 300,
        modal: true,
        resizable: false,
        buttons: {
            "Print": function () {
                bvc.printEmail();
            },
            "Reply": function () {
                $(this).dialog("destroy");
                bvc.showMessageReply(id);
            },
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $('#messageDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#messageDiv').dialog("open");

    $('#messageDiv').load("MessageDetail.aspx?RecID=" + id + "&r=" + new Date().getTime(), function () {
        //$('#messageDiv').dialog("open");
        //alert(obj);
    });
}

bvc.showMessageReply = function (id) {
    // Dialog			
    $('#messageDiv').dialog({
        title: 'BorrowersViewCentral.com - Message Reply',
        autoOpen: false,
        width: 600,
        height: 300,
        modal: true,
        resizable: false,
        buttons: {
            "Send": function () {
                $(this).dialog("destroy");
                bvc.sendReply(id, $('textarea#replyMessage').val());
            },
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $('#messageDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#messageDiv').dialog("open");

    $('#messageDiv').load("MessageReply.aspx?RecID=" + id + "&r=" + new Date().getTime(), function () {
       // $('#messageDiv').dialog("open");
    });
}

bvc.sendReply = function (id, message) {
    // Dialog			
    $('#messageDiv').dialog({
        title: 'BorrowersViewCentral.com - Message Sent',
        autoOpen: false,
        width: 600,
        height: 300,
        modal: true,
        resizable: false,
        buttons: {
            "Close": function () {
                window.location = "Messages.aspx";
            }
        }
    });

    var replyMessage = $('textarea#replyMessage').serialize();

    $('#messageDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#messageDiv').dialog("open");

    $.ajax({
        url: "SendReply.aspx?RecID=" + id + "&r=" + new Date().getTime(),
        data: replyMessage,
        success: function () {
            alert('Message sent successfully');
            $('#messageDiv').dialog("destroy");
            document.location = 'Messages.aspx';
        }
    });

    //$('#messageDiv').load("SendReply.aspx?RecID=" + id + "&r=" + new Date().getTime(), replyMessage, function () {
    //});
}


bvc.showARM = function () {
    // Dialog			
    $('#armDiv').dialog({
        title: 'BorrowersViewCentral.com - ARM Information',
        autoOpen: false,
        width: 600,
        height: 300,
        modal: true,
        resizable: false,
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $('#armDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#armDiv').dialog("open");

    $('#armDiv').load("ARMDetail.aspx?r=" + new Date().getTime(), function () {
        //$('#armDiv').dialog("open");
    });
}

bvc.showImpounds = function (sort) {
    // Dialog			
    $('#impoundsDiv').dialog({
        title: 'BorrowersViewCentral.com - Impound Account',
        autoOpen: false,
        width: '90%',
        height: 400,
        modal: true,
        minWidth: 400,
        resizable: false,
        close: function () {
            $(this).dialog("destroy");
        },
        buttons: {
            "Export to Excel": function () {
                window.open("Impounds.aspx?export=1&r=" + new Date().getTime());
            },
            "Close": function () {
                $(this).dialog("destroy");
            }
        }
    });

    $('#impoundsDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#impoundsDiv').dialog("open");

    $('#impoundsDiv').load("Impounds.aspx?sort=" + sort + "&r=" + new Date().getTime(), function () {
        //$('#impoundsDiv').dialog("open");
    });
}

bvc.showReserves = function (sort) {
    // Dialog			
    $('#reservesDiv').dialog({
        title: 'BorrowersViewCentral.com - Reserve Account',
        autoOpen: false,
        width: '90%',
        height: 400,
        modal: true,
        minWidth: 400,
        resizable: false,
        close: function () {
            $(this).dialog("destroy");
        },
        buttons: {
            "Export to Excel": function () {
                window.open("Reserves.aspx?export=1&r=" + new Date().getTime());
            },
            "Close": function () {
                $(this).dialog("destroy");
            }
        }
    });

    $('#reservesDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#reservesDiv').dialog("open");

    $('#reservesDiv').load("Reserves.aspx?sort=" + sort + "&r=" + new Date().getTime(), function () {
       // $('#reservesDiv').dialog("open");
    });

}

bvc.sortImpounds = function (sort) {
    $('#impoundsDiv').load("Impounds.aspx?sort=" + sort + "&r=" + new Date().getTime());
}

bvc.sortReserves = function (sort) {
    $('#reservesDiv').load("Reserves.aspx?sort=" + sort + "&r=" + new Date().getTime());
}

bvc.showConstructionTrust = function (sort) {
    // Dialog			
    $('#constructionTrustDiv').dialog({
        title: 'BorrowersViewCentral.com - Construction Trust Account',
        autoOpen: false,
        width: '90%',
        height: 400,
        modal: true,
        minWidth: 400,
        resizable: false,
        close: function () {
            $(this).dialog("destroy");
        },
        buttons: {
            "Export All to Excel": function () {
                window.open("ConstructionTrust.aspx?export=1&r=" + new Date().getTime());
            },
            "Close": function () {
                $(this).dialog("destroy");
            }
        }
    });

    $('#constructionTrustDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#constructionTrustDiv').dialog("open");

    $('#constructionTrustDiv').load("ConstructionTrust.aspx?sort=" + sort + "&r=" + new Date().getTime(), function () {
       // $('#constructionTrustDiv').dialog("open");
    });

}

bvc.sortConImpounds = function (sort) {
    $('#constructionTrustDiv').load("ConstructionTrust.aspx?impoundSort=" + sort + "&r=" + new Date().getTime());
}

bvc.sortConReserves = function (sort) {
    $('#constructionTrustDiv').load("ConstructionTrust.aspx?reserveSort=" + sort + "&r=" + new Date().getTime());
}

bvc.sortConAll = function (sort) {
    $('#constructionTrustDiv').load("ConstructionTrust.aspx?allSort=" + sort + "&r=" + new Date().getTime());
}

bvc.sortHistory = function (sort) {
    document.location = "AcctOverview.aspx?historySort=" + sort + "&r=" + new Date().getTime();
}

bvc.toggleCheckAll = function (master, grid) {
    var master = document.getElementById(master);
    var div = document.getElementById(grid);
    var inputs = div.getElementsByTagName("input");

    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "checkbox" && inputs[i].id != master) {
            inputs[i].checked = master.checked;
        }
    }
}

bvc.forogtPin = function (companyId) {
    // Dialog			
    $('#forgotDiv').dialog({
        title: 'BorrowersViewCentral.com - Request for PIN',
        autoOpen: false,
        width: 400,
        height: 270,
        modal: true,
        minWidth: 400,
        resizable: false,
        close: function () {
            $(this).dialog("destroy");
        },
        buttons: {
            "Send": function () {
                $.post("SendUserInfo.aspx", { "companyId": $('#ForgotCompanyId').val(), "userId": $('#ForgotUserId').val() }, function (data) {
                    if (data.length == 0) {
                        $('#forgotDiv').dialog("destroy");
                        alert('Your PIN has been sent to your email address.');
                    } else {
                        alert(data);
                    }
                })
            },
            "Close": function () {
                $(this).dialog("destroy");
            }
        }
    });

    $('#forgotDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#forgotDiv').dialog("open");

    $('#forgotDiv').load("forgot.aspx?r=" + new Date().getTime(), function () {
        document.getElementById('ForgotCompanyId').value = companyId;
        if (companyId.length > 0) {
            document.getElementById('ForgotCompanyRow').style.display = 'none';
        }
        //$('#forgotDiv').dialog("open");
    });

}

bvc.showSystemRequirements = function (sort) {
    // Dialog			
    $('#systemRequirements').dialog({
        title: 'System Requirements',
        autoOpen: false,
        width: 300,
        height: 300,
        modal: true,
        minWidth: 400,
        resizable: false,
        close: function () {
            $(this).dialog("destroy");
        },
        buttons: {
            "Close": function () {
                $(this).dialog("destroy");
            }
        }
    });

    $('#systemRequirements').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#systemRequirements').dialog("open");
    $('#systemRequirements').load("SystemRequirements.aspx?r=" + new Date().getTime());
}

bvc.sortInbox = function (sort) {
    document.location = "Messages.aspx?inboxSort=" + sort + "&r=" + new Date().getTime();
}

bvc.sortSent = function (sort) {
    document.location = "Messages.aspx?sentSort=" + sort + "&r=" + new Date().getTime();
}

bvc.showNewRelease = function () {
    // Dialog			
    $('#newReleaseDiv').dialog({
        title: 'Borrowers View Central',
        autoOpen: false,
        width: 400,
        height: 400,
        modal: true,
        resizable: false,
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        }
    });

    $('#newReleaseDiv').html("<table width='100%' height='100%'><tr><td valign='middle' align='center'><img src='/graphics/ajax-loader.gif'/></td></tr></table>");
    $('#newReleaseDiv').dialog("open");

    $('#newReleaseDiv').load("NewFeatures.aspx?r=" + new Date().getTime(), function () {
    });
}

bvc.printEmail = function () {
    frames["Printable"].focus();
    frames["Printable"].print();
}
