﻿//Bunch of Moneytech Utility functions - MB

//---------------- DATE TIME FORMATING ----------------------
function MtDateFormat(date) {
    if (date != null) {
        var months = new Array(12);
        months[0] = 'Jan'; months[1] = 'Feb'; months[2] = 'Mar';  months[3] = 'Apr';
        months[4] = 'May'; months[5] = 'Jun'; months[6] = 'Jul';  months[7] = 'Aug';
        months[8] = 'Sep'; months[9] = 'Oct'; months[10] = 'Nov'; months[11] = 'Dec';

        return date.getDate() + '-' + months[date.getMonth()] + '-' + (date.getYear() + 1900);
    }
    else {
        return '';
    }
}

//---------------- STRING FORMATING ----------------------
function LTrim(value) {
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}

function RTrim(value) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}

function Trim(value) {
    return LTrim(RTrim(value));
}

//---------------- BUYER ----------------------
function popupBuyerGenericTransactonDetails(TransactionProcessHistoryId) {
    var _height = 800;
    var _width = 700;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/GenericTransactions/UserFacing/Buyer/GenericTransactionDetails.aspx?id=' + TransactionProcessHistoryId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'BuyerSellerPaymentDetails' + TransactionProcessHistoryId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBuyerPreAuthDetails(AccountNumber) {
    var _height = 650;
    var _width = 880;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/GenericTransactions/UserFacing/Buyer/PreAuthDetailsPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'BuyerPreAuthDetails' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

//---------------- SELLER ----------------------
function popupSellerSellerPaymentDetails(TransactionProcessHistoryId) {
    var _height = 800;
    var _width = 610;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/GenericTransactions/UserFacing/Seller/SellerPaymentDetails.aspx?id=' + TransactionProcessHistoryId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'SellerSellerPaymentDetails' + TransactionProcessHistoryId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}


//---------------- BACKOFFICE ----------------------
function popupBackofficeGenericTransactonDetails(TransactionProcessHistoryId) {
    var _height = 800;
    var _width = 920;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/GenericTransactions/Backoffice/GenericTransactionDetails.aspx?id=' + TransactionProcessHistoryId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'GenericTransactonDetails' + TransactionProcessHistoryId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeAutomationMessageDetails(AutomationMessageId) {
    var _height = 850;
    var _width = 950;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/AutomationUI/AutomationMessagePopup.aspx?id=' + AutomationMessageId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'AutomationMessageDetails' + AutomationMessageId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMessageQueueJobDetails(MessageQueueId) {
    var _height = 480;
    var _width = 950;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/SystemTools/MessageQueuePopup.aspx?id=' + MessageQueueId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MessageQueueJobDetails' + MessageQueueId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMPayLogDetails(MPayLogId) {
    var _height = 650;
    var _width = 750;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/MPay/MPayLogDetailsPopup.aspx?id=' + MPayLogId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MPayLogDetails' + MPayLogId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMPayTransactionDetails(MPayTransactionId) {
    var _height = 500;
    var _width = 750;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/MPay/MPayTransactionDetailsPopup.aspx?id=' + MPayTransactionId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MPayTransactionId' + MPayTransactionId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMPaySmsInboundLogDetails(MPaySmsLogId) {
    var _height = 450;
    var _width = 850;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/MPay/MPaySMSInboundDetailsPopup.aspx?id=' + MPaySmsLogId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MPaySMSInboundDetails' + MPaySmsLogId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMPayMerchantDetails(MPaySN) {
    var _height = 750;
    var _width = 1080;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/MPay/MPayMerchantDetailsPopup.aspx?id=' + Trim(MPaySN);
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MPayMerchantDetails' + Trim(MPaySN), params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeMPayCustomerDetails(MPaySN) {
    var _height = 750;
    var _width = 1220;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/MPay/MPayCustomerDetailsPopup.aspx?id=' + Trim(MPaySN);
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'MPayCustomerDetails' + Trim(MPaySN), params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeFeeEngineDetails(TransactionProcessHistoryId) {
    var _height = 800;
    var _width = 880;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/FeeEngineUI/FeeEngineDetailsPopup.aspx?id=' + TransactionProcessHistoryId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'FeeEngineDetails' + TransactionProcessHistoryId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeTrackingDetails(TrackingId) {
    var _height = 800;
    var _width = 680;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/GenericTransactions/Backoffice/GenericTransactionDetails.aspx?trackingid=' + TrackingId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'TrackingDetails' + TrackingId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeAccountDetails(AccountNumber) {
    var _height = 800;
    var _width = 910;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/Popups/AccountDetailsPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'AccountDetails' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupForcastStatement(AccountNumber) {
    var _height = 500;
    var _width = 660;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/ForcastStatementUI/ForecastStatementsPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'popupForcastStatement' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeDovsAccountCharts(AccountNumber) {
    var _height = 1020;
    var _width = 1380;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/Popups/DovsAccountDetailChartPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'AccountFinancials' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficePreAuthDetails(PreauthId) {
    var _height = 600;
    var _width = 830;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/Popups/PreAuthDetailsPopup.aspx?id=' + PreauthId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'PreAuthDetails' + PreauthId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeCreditManagementDetails(AccountNumber) {
    var _height = 600;
    var _width = 1600;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/CreditCollectionManagement/CreditManagementDetailsPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CreditManagementDetails' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

/*
function popupBackofficeCollectionManagementDetails(AccountNumber) {
    var _height = 600;
    var _width = 1600;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/CreditCollectionManagement/CollectionManagementDetailsPopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CollectionManagementDetails' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}
*/

function popupBackofficeCreditCollectionNotes(AccountNumber, ViewMode, Name) {
    var _height = 640;
    var _width = 860;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/CreditCollectionManagement/CreditCollectionNotesPopup.aspx?id=' + AccountNumber+'&mode='+ViewMode+'&name='+Name;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CreditCollectionNotes' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeNewDirectEntrySchedules(AccountNumber) {
    var _height = 850;
    var _width = 900;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/DirectDebit/NewSchedulePopup.aspx?id=' + AccountNumber;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'NewDirectEntrySchedule' + AccountNumber, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeCreditCollectionEventDetailsPopupAddGtDocument(transactionProcessHistoryId) {
    var _height = 850;
    var _width = 780;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/CreditCollectionManagement/CreditCollectionEventDetailsPopup.aspx?AddDocumentGtId=' + transactionProcessHistoryId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CreditCollectionEventDetailsAddGtDocument' + transactionProcessHistoryId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

function popupBackofficeCreditCollectionEventDetailsPopup(eventId) {
    var _height = 850;
    var _width = 780;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var url = '/Mt/Forms/Sys/CreditCollectionManagement/CreditCollectionEventDetailsPopup.aspx?id=' + eventId;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CreditCollectionEventDetailsAdd' + eventId, params);
    if (win != null) {
        win.focus();
    }
    return false;
}

//---------------- CRM ----------------------
function popupCrm(url) {
    var _height = 768;
    var _width = 1024;
    var _left = (screen.width - _width) / 2;
    var _top = (screen.height - _height) / 2;
    var params = 'toolbar=no, directories=no, scrollbars=1, menubar=no, resizable=yes, location=no, width=' + _width + ', height=' + _height + ', left=' + _left + ', top=' + _top;

    var win = window.open(url, 'CRM', params);
    if (win != null) {
        win.focus();
    }
    return false;
}
