﻿/* HELP JS FILE
 * CREATED: 28 Oct 2008
 * AUTHOR: Jako van Rensburg
 */

var help = {
    /* HELP SECTION */
    alreadyShownTooltips: '',
    helpTipShowing: false,
    /* POPUP HELP TOOLTIP ON ELEMENT */
    showTooltip: function(toolTipName, attachObj, content, options, closeOnClick) {
        $d('JS Function', 'showTooltip: toolTipName: '+toolTipName+'<br />attachObj: '+attachObj.id);
        if (help.helpTipShowing == false) {
            //CREATE THE TOOLTIP
            if (!options.width) {
                options.width = 200;
            }
            if (!$('helpTooltip')) {
                var tool = $ce('div',
                {
                    'id':'helpTooltip'
                },
                {
                    'position':'absolute',
                    'zIndex':'200000'
                },document.body);

                var toolInside = $ce('div',
                {
                    'id':'helpTooltipInside'
                },
                {
                    'backgroundColor':'#FFF7BC',
                    'border':'solid 1px #D6B475',
                    'padding':'5px',
                    'backgroundImage':'url(images/toolBack.jpg)',
                    'backgroundRepeat':'repeat-x',
                    'textAlign':'left'
                },$('helpTooltip'));

                var arrowBottom = $ce('div',
                {
                    'id':'helpArrowBottom',
                    'innerHTML':'<img src="images/tooltipArr.gif" alt="" title="" />'
                },
                {
                    'marginTop':'-1px',
                    'display':'none'
                },$('helpTooltip'));

                var arrowLeft = $ce('div',
                {
                    'id':'helpArrowLeft',
                    'innerHTML':'<img src="images/tooltipArrLeft.gif" alt="" title="" />'
                },
                {
                    'marginTop':'-1px',
                    'display':'none',
                    'position':'absolute',
                    'top':'5px',
                    'left':'-12px'
                },$('helpTooltip'));

                var arrowRight = $ce('div',
                {
                    'id':'helpArrowRight',
                    'innerHTML':'<img src="images/tooltipArrRight.gif" alt="" title="" />'
                },
                {
                    'marginTop':'-1px',
                    'display':'none',
                    'position':'absolute',
                    'top':'5px',
                    'right':'-12px'
                },$('helpTooltip'));

                var arrowTop = $ce('div',
                {
                    'id':'helpArrowTop',
                    'innerHTML':'<img src="images/tooltipArrTop.gif" alt="" title="" />'
                },
                {
                    'marginTop':'0px',
                    'display':'none',
                    'position':'absolute',
                    'top':'-12px'
                },$('helpTooltip'));
            }
            //SET TOOLTIP PROPERTIES
            if (options.arrowPos == 'bottom') {
                $('helpArrowBottom').style.display = '';
                $('helpArrowLeft').style.display = 'none';
                $('helpArrowRight').style.display = 'none';
                $('helpArrowTop').style.display = 'none';
            }
            else {
                if (options.arrowPos == 'left') {
                    $('helpArrowBottom').style.display = 'none';
                    $('helpArrowLeft').style.display = '';
                    $('helpArrowRight').style.display = 'none';
                    $('helpArrowTop').style.display = 'none';
                }
                else {
                    if (options.arrowPos == 'right') {
                        $('helpArrowBottom').style.display = 'none';
                        $('helpArrowLeft').style.display = 'none';
                        $('helpArrowRight').style.display = '';
                        $('helpArrowTop').style.display = 'none';
                    }
                    else {
                        if (options.arrowPos == 'top') {
                            $('helpArrowBottom').style.display = 'none';
                            $('helpArrowLeft').style.display = 'none';
                            $('helpArrowRight').style.display = 'none';
                            $('helpArrowTop').style.display = '';
                        }
                        else {
                            $('helpArrowBottom').style.display = '';
                            $('helpArrowLeft').style.display = 'none';
                            $('helpArrowRight').style.display = 'none';
                            $('helpArrowTop').style.display = 'none';
                        }
                    }
                }
            }
            var toolbarHTML = '';
            if (options.enableHeading) {
                toolbarHTML = '<table cellspacing="0" cellpadding="0" style="width:100%;margin-bottom:5px;"><tr><td style="width:100%;" class="genericForeColor"><strong>Help?</strong></td><td style="color:#D6B475;font-weight:bold;padding-top:2px;"><img id="imgCloseHelpTooltip" style="cursor:pointer;" onmouseover="this.src=&quot;images/icons/helpClose_over.jpg&quot;" onmouseout="this.src=&quot;images/icons/helpClose.jpg&quot;" src="images/icons/helpClose.jpg" alt="Close" title="Close" /></td></tr></table>';
                $('helpTooltipInside').style.paddingTop = '';
                if (options.arrowPos == 'left') {
                    $('helpArrowLeft').style.top = '5px';
                }
            }
            else {
                toolbarHTML = '<div id="divCloseHelp" style="float:right;position:absolute;right:5px;top:4px;"><img id="imgCloseHelpTooltip" style="cursor:pointer;" onmouseover="this.src=&quot;images/icons/helpClose_over.jpg&quot;" onmouseout="this.src=&quot;images/icons/helpClose.jpg&quot;" src="images/icons/helpClose.jpg" alt="Close" title="Close" /></div>';
                $('helpTooltipInside').style.paddingTop = '5px';
                if (options.arrowPos == 'left') {
                    $('helpArrowLeft').style.top = '1px';
                }
            }
            $('helpTooltip').style.display = '';
            if (options.arrowPos == 'left') {
                if (options.enableHeading) {
                    $('helpTooltipInside').innerHTML = toolbarHTML + content;
                }
                else {
                    if (options.hideClose) {
                        $('helpTooltipInside').innerHTML = content;
                    }
                    else {
                        $('helpTooltipInside').innerHTML = content + toolbarHTML;
                    }
                }
            }
            else {
                if (options.hideClose) {
                    $('helpTooltipInside').innerHTML = content;
                }
                else {
                    $('helpTooltipInside').innerHTML = toolbarHTML + content;
                }
            }
            $('helpTooltip').style.width = options.width + 'px';
            if (options.left) {
                $('helpTooltip').style.left = (options.left + options.offsetX)+'px';
            }
            else {
                $('helpTooltip').style.left = (general.findElementPosX(attachObj) + options.offsetX)+'px';
            }
            if (options.top) {
                $('helpTooltip').style.top = (options.top + options.offsetY)+'px';
            }
            else {
                if (options.arrowPos == 'bottom') {
                    $('helpTooltip').style.top = (general.findElementPosY(attachObj) - $('helpTooltipInside').offsetHeight - options.offsetY)+'px';
                }
                else {
                    $('helpTooltip').style.top = (general.findElementPosY(attachObj) - options.offsetY)+'px';
                }
            }
            help.helpTipShowing = true;
            animate.fadeObject($('helpTooltip'), 0, 100, 5);
            //SET CLOSE IMAGE ONCLICK
            if ($('imgCloseHelpTooltip')) {
                if (closeOnClick) {
                    $('imgCloseHelpTooltip').onclick = closeOnClick;
                }
                else {
                    $('imgCloseHelpTooltip').onclick = function(){help.hideTooltip();};
                }
            }
            if (options.canShowAgain == false) {
                help.addTooltipToCookie(toolTipName, false);
            }
        }
    },

    /* HIDE SHOWING TOOLTIP */
    hideTooltip: function() {
        $d('JS Function', 'hideTooltip');
        if (help.helpTipShowing == true) {
            $('helpTooltip').style.display = 'none';
            help.helpTipShowing = false;
        }
    },

    /* STORE ALREADY VIEWED HELP TOOLTIPS */
    addTooltipToCookie: function(tooltipName, showAgain) {
        $d('JS Function', 'addTooltipToCookie: tooltipName: '+tooltipName+'<br />showAgain: '+showAgain.toString());
        if (showAgain == false) {
            var currentCookie = '';
            currentCookie = getCookieValue(general.queryString('Token')+'TooltipStore');
            deleteCookie(general.queryString('Token')+'TooltipStore');
            writeSessionCookie(general.queryString('Token')+'TooltipStore', currentCookie+tooltipName+' | ');
        }
    },

    /* HELP WORDING */
    helpWording:
    {
        webMail: 'Hovering over a Web Mail item allows you to:<ul><li>View the Matter History</li><li>Mark the Mail as Read</li><li>View the Mail</li><li>Forward the Mail to an external e-mail address</li></ul>',
        recipients: 'Please select the users who should also receive notifications on your matters.<br /><br /><strong><u>Please Note:</u></strong> This can be used when you are on leave.<br /><br />',
        notifications: 'Please tick the statuses for which you would like to receive an <u>external</u> e-mail notification (i.e. to your e-mail address) in addition to the normal webmail notifications found under the Webmail Menu and on your Dashboard.',
        matterSummary: 'When you click on a Status, you will be redirected to the Matters section.',
        matterScanning: 'Please select one of these options to perform an action on the matter(s) you&#39;ve just selected.',
        minInactivity: '<ul style="margin-left:15px;padding:0px;">' +
                        '<li style="margin:0px;padding:0px;"><strong>15 Min Inactivity Timer</strong><br />' +
                        '<p style="margin-top:0px;padding-top:2px;">If you enable this option, no-one will be able to login to the system using your login details until you have been inactive on the system for 15 minutes.</p>' +
                        '</li>' +
                        '</ul>',
        collaborations: '<ul style="margin-left:15px;padding:0px;">' +
                        '<li style="margin:0px;padding:0px;"><strong>Firm Collaborations</strong><br />' +
                        '<p style="margin-top:0px;padding-top:2px;">If you enable this feature, a button will show under the Matters Menu (for each matter) and a section will also display on the Create Matters page. The function of Collabs is to allow you to add information on the matter and firm you are simultaneously lodging with (i.e. collaborating attorneys).</p>' +
                        '</li>' +
                        '</ul>',
        lodgmentsinprogress: '<ul style="margin-left:15px;padding:0px;">' +
                        '<li style="margin:0px;padding:0px;"><strong>Lodgement in Progress (LIPS)</strong><br />' +
                        '<p style="margin-top:0px;padding-top:2px;">If you enabled this feature, a section will display on the Create Matters page which will allow you to add information on linked matters that you are still awaiting an instruction. The LIP information could be the same instructing attorney that is set on the matter or it could be another firm altogether. However, once you add LIP information, an e-mail will be automatically sent to the instructing paralegal on the matter informing them that you are unable to lodge as you are still awaiting instructions from "*** firm (add under the LIP section)".</p>' +
                        '</li>' +
                        '</ul>',
        remindersystem: '<ul style="margin-left:15px;padding:0px;">' +
                        '<li style="margin:0px;padding:0px;"><strong>Reminder System</strong><br />' +
                        '<p style="margin-top:0px;padding-top:2px;">The reminder system works similarly to a diary and enables you to add reminder notes to matters. The reminders for the current day will display on your Dashboard (Home Menu).</p>' +
                        '</li>' +
                        '</ul>',
        attachments: '<ul style="margin-left:15px;padding:0px;">' +
                        '<li style="margin:0px;padding:0px;"><strong>Attachments</strong><br />' +
                        '<p style="margin-top:0px;padding-top:2px;">If you enable this feature, a button will display under the Matters Menu (for each matter) which will allow you to add attachments to the matter. The attachments can be viewed by all parties who are able to see the matter in the system.</p>' +
                        '</li>' +
                        '</ul>',
        defaults: 'Defaults can be setup per Deeds Office and will affect what information will populate the relevant fields when creating a manual matter. The first setting that is created will become the default information that will display automatically on the Create Matters menu. However, the defaults will change on the Create Matters page when a different Deeds Office is selected, based on what has been setup here.',
        defaultsEdit: 'Once defaults have been setup the following icons can be used to:<br />' + 
                        '<table>' +
                            '<tr>' +
                                '<td><img src="images/icons/checkBox.gif" alt="" title="" /></td>' +
                                '<td>Set the default default. If this box is ticked, this is the information that will display by default on the Create Matters page.</td>' +
                            '</tr>' +
                            '<tr>' +
                                '<td><img src="images/icons/text_list_numbers_edit.gif" alt="" title="" /></td>' +
                                '<td>Edit the settings for this default.</td>' +
                            '</tr>' +
                            '<tr>' +
                                '<td><img src="images/icons/cross.gif" alt="" title="" /></td>' +
                                '<td>Delete this setting.</td>' +
                            '</tr>' +
                        '</table>',
        requiredField: 'This is a required field.',
        barcodeClick: 'You can scan the matter to a different status by clicking on the barcode image.',
        reminders: '<table><tr><td style="color:#FF0000;font-weight:bold;">Please Note:</td></tr><tr><td>You have reminders for today!</td></tr></table>',
        downloadAttachments: 'Click here to download.'
    },

    /* HELP SECTIONS */
    webMailHelp: function(tblObj) {
        $d('JS Function', 'webMailHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('webMailHelp') == -1) {
            help.showTooltip('webMailHelp',tblObj,help.helpWording.webMail,{width:300,offsetX:100,offsetY:-22,enableHeading:true,arrowPos:'bottom',canShowAgain:true}, function(){help.hideTooltip();});
        }
    },

    /* MATTER SUMMARY HELP */
    matterSummaryHelp: function(tblObj) {
        $d('JS Function', 'matterSummaryHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('matterSummaryHelp') == -1) {
            help.showTooltip('matterSummaryHelp',tblObj,help.helpWording.matterSummary,{width:200,offsetX:100,offsetY:-22,enableHeading:true,arrowPos:'bottom',canShowAgain:true}, function(){help.hideTooltip();});
        }
    },

    /* MATTER BARCODE IMAGE HELP */
    matterBarcodeImageHelp: function(tblObj) {
        $d('JS Function', 'matterBarcodeImageHelp: tblObj: '+tblObj.id);
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('matterBarcodeImageHelp') == -1) {
                help.showTooltip('matterBarcodeImageHelp',tblObj,help.helpWording.barcodeClick,{width:150,offsetX:-165,offsetY:0,enableHeading:false,arrowPos:'right',canShowAgain:true,hideClose:true}, function(){help.hideTooltip();});
            }
        }
    },

    /* MATTER SCANNING HELP */
    matterScanningHelp: function(tblObj) {
        $d('JS Function', 'matterScanningHelp: tblObj: '+tblObj.id);
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('matterScanningHelp') == -1) {
                help.showTooltip('matterScanningHelp',tblObj,help.helpWording.matterScanning,{width:200,offsetX:tblObj.offsetWidth+15,offsetY:-3,enableHeading:false,arrowPos:'left',canShowAgain:true}, function(){help.hideTooltip();});
            }
        }
    },

    /* SYSTEM SETTINGS HELP */
    collaborationsHelp: function(tblObj) {
        $d('JS Function', 'collaborationsHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('collaborationsHelp') == -1) {
                help.showTooltip('collaborationsHelp',tblObj,help.helpWording.collaborations,{width:220,offsetX:(tblObj.offsetWidth+75),offsetY:4,enableHeading:true,arrowPos:'left',canShowAgain:true}, function(){help.lodgmentsinprogressHelp($('tdLipsHelp'));});
            }
        }
    },
    lodgmentsinprogressHelp: function(tblObj) {
        $d('JS Function', 'lodgmentsinprogressHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('lodgmentsinprogressHelp') == -1) {
                help.showTooltip('lodgmentsinprogressHelp',tblObj,help.helpWording.lodgmentsinprogress,{width:220,offsetX:(tblObj.offsetWidth+75),offsetY:4,enableHeading:true,arrowPos:'left',canShowAgain:true}, function(){help.remindersystemHelp($('tdReminderHelp'));});
            }
        }
    },
    remindersystemHelp: function(tblObj) {
        $d('JS Function', 'remindersystemHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('remindersystemHelp') == -1) {
                help.showTooltip('remindersystemHelp',tblObj,help.helpWording.remindersystem,{width:220,offsetX:(tblObj.offsetWidth+75),offsetY:4,enableHeading:true,arrowPos:'left',canShowAgain:true}, function(){help.attachmentsHelp($('tdAttachmentHelp'));});
            }
        }
    },
    attachmentsHelp: function(tblObj) {
        $d('JS Function', 'attachmentsHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (help.helpTipShowing == false) {
            if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('attachmentsHelp') == -1) {
                help.showTooltip('attachmentsHelp',tblObj,help.helpWording.attachments,{width:220,offsetX:(tblObj.offsetWidth+75),offsetY:4,enableHeading:true,arrowPos:'left',canShowAgain:true}, function(){help.hideTooltip();});
            }
        }
    },

    /* DEFAULTS HELP */
    systemDefaultsHelp: function(tblObj) {
        $d('JS Function', 'systemDefaultsHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('systemSettingsHelp') == -1) {
            help.showTooltip('systemSettingsHelp',tblObj,help.helpWording.defaults,{width:200,offsetX:(tblObj.offsetWidth+20),offsetY:8,enableHeading:true,arrowPos:'left',canShowAgain:true}, function(){help.systemDefaultsEditHelp($('tdMyDefaultsList'));});
        }
    },

    /* DEFAULTS EDIT HELP */
    systemDefaultsEditHelp: function(tblObj) {
        $d('JS Function', 'systemDefaultsEditHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('systemDefaultsEditHelp') == -1) {
            help.showTooltip('systemDefaultsEditHelp',tblObj,help.helpWording.defaultsEdit,{width:350,offsetX:(tblObj.offsetWidth-55),offsetY:-10,enableHeading:true,arrowPos:'bottom',canShowAgain:true}, function(){help.hideTooltip();});
        }
    },

    /* NOTIFICATION STATUSES HELP */
    notificationHelp: function(tblObj) {
        $d('JS Function', 'notificationHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('notificationHelp') == -1) {
            help.showTooltip('notificationHelp',tblObj,help.helpWording.notifications,{width:350,offsetX:2,offsetY:10,enableHeading:true,arrowPos:'bottom',canShowAgain:true}, function(){help.hideTooltip();});
        }
    },

    /* EMAIL RECIPIENTS HELP */
    recipientsHelp: function(tblObj) {
        $d('JS Function', 'recipientsHelp: tblObj: '+tblObj.id);
        help.hideTooltip();
        if (getCookieValue(general.queryString('Token')+'TooltipStore').toString().indexOf('recipientsHelp') == -1) {
            help.showTooltip('recipientsHelp',tblObj,help.helpWording.recipients,{width:300,offsetX:50,offsetY:10,enableHeading:true,arrowPos:'bottom',canShowAgain:true}, function(){help.hideTooltip();});
        }
    }
};
