﻿PAT.ResultPanel = Class.create({
    resultContent: null,
    toolContainer: null,
    first: null,
    previous: null,
    next: null,
    last: null,
    data: null,
    sortBy: null,
    layerSelector: null,
    objectSelector: null,
    clientName: null,
    lastMasterFields: null,
    lastMasterMenuId: null,
    searchResult: null,
    initialize: function(searchResult)
    {
        this.domObj = new Element('div', { 'id': 'resultContainer' });
        this.toolContainer = new Element('div', { 'id': 'resultToolContainer' });
        this.domObj.insert(this.toolContainer);
        this.domObj.observe("PAT.ResultPanel:queryFromMap", this.updateResultPanelFromMap.bind(this));
        this.domObj.observe("PAT.ResultPanel:queryFromQuery", this.updateResultPanelFromQuery.bind(this));
        this.domObj.observe("PAT.ResultPanel:editPoint", this.editPoint.bind(this));
        this.domObj.observe("PAT.ResultPanel:printMailout", this.printMailout.bind(this));
        this.domObj.observe("PAT.ResultPanel:onUpdateData", this.onUpdateData.bind(this));
        this.domObj.observe("PAT.ResultPanel:onResultColumnSort", this.onResultColumnSort.bind(this));

        this.searchResult = searchResult;

        //gis key
        this.domObj.gisKeys = [];
        //key
        this.domObj.keys = [];
        //index of each item
        this.domObj.selectedIds = [];

        this.resultContent = new Element('div', { 'id': 'resultContent' }).addClassName("resultContainer");
        this.domObj.insert(this.resultContent);

        //TEMP:fix resizing problem of resultPanel
        this.domObj.setStyle("overflow:hidden;");
        this.resultContent.setStyle("overflow:auto");

        var title = "";
        var message = "";
        //zoom to
        var imgZoomto = new Element('img', { "src": "Images/Icons/ZoomTo.gif" });
        this.toolContainer.zoomto = imgZoomto;
        if (null != PAT.helpTextMessages.Locate)
        {
            imgZoomto.tooltipTitle = PAT.helpTextMessages.Locate.title;
            imgZoomto.message = PAT.helpTextMessages.Locate.message;
        }
        imgZoomto.setStyle("width:26px;height:26px");
        imgZoomto.observe('mouseover', function()
        {
            imgZoomto.src = "Images/Icons/ZoomToOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgZoomto.tooltipTitle, "message": imgZoomto.message });
        });
        imgZoomto.observe('mouseout', function()
        {
            imgZoomto.src = "Images/Icons/ZoomTo.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgZoomto.observe("click", this.zoomgoto.bind(this));

        imgZoomto.hide()
        if (showTooltip && imgZoomto.message != null)
        {
            imgZoomto.title = imgZoomto.message;
        }
        //mail out
        title = "";
        message = "";

        var imgMailout = new Element('img', { 'src': "Images/Icons/Mailout.gif" });
        this.toolContainer.mailout = imgMailout;
        if (null != PAT.helpTextMessages.MailingLabels)
        {
            imgMailout.tooltipTitle = PAT.helpTextMessages.MailingLabels.title;
            imgMailout.message = PAT.helpTextMessages.MailingLabels.message;
        }
        imgMailout.observe('mouseover', function()
        {
            imgMailout.src = "Images/Icons/MailoutOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgMailout.tooltipTitle, "message": imgMailout.message });
        });

        imgMailout.setStyle("width:26px;height:26px");
        imgMailout.observe('mouseout', function()
        {
            imgMailout.src = "Images/Icons/Mailout.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
            //added by Stanley to hide popup panel when the mouse cursor is no longer on the mail label image
            if (null != report.mailoutSelection)
            {
                if (null != report.mailoutSelection.domObj && report.mailoutSelection.domObj.style.display !== "none")
                    report.mailoutSelection.domObj.style.display = "none";
            }
        });
        imgMailout.observe("click", this.mailout.bind(this));

        imgMailout.hide();
        if (showTooltip && imgMailout.message != null)
            imgMailout.title = imgMailout.message;
        //csv
        title = "";
        message = "";

        var imgCsv = new Element('img', { 'src': "Images/Icons/CSV.gif" });
        this.toolContainer.csv = imgCsv;
        if (null != PAT.helpTextMessages.Export)
        {
            imgCsv.tooltipTitle = PAT.helpTextMessages.Export.title;
            imgCsv.message = PAT.helpTextMessages.Export.message;
        }
        imgCsv.setStyle("width:26px;height:26px");
        imgCsv.observe('mouseover', function()
        {
            imgCsv.src = "Images/Icons/CSVOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgCsv.tooltipTitle, "message": imgCsv.message });
        });
        imgCsv.observe('mouseout', function()
        {
            imgCsv.src = "Images/Icons/CSV.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgCsv.observe("click", this.csv.bind(this));

        imgCsv.hide();
        if (showTooltip && imgCsv.message != null)
            imgCsv.title = imgCsv.message;
        //detail report
        title = "";
        message = "";

        var imgReport = new Element('img', { 'src': "Images/Icons/PrintVer.gif" });
        this.toolContainer.detailReport = imgReport;
        if (null != PAT.helpTextMessages.DefaultReport)
        {
            imgReport.tooltipTitle = PAT.helpTextMessages.DefaultReport.title;
            imgReport.message = PAT.helpTextMessages.DefaultReport.message;
        }
        imgReport.setStyle("width:26px;height:26px");
        imgReport.observe('mouseover', function()
        {
            imgReport.src = "Images/Icons/PrintVerOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgReport.tooltipTitle, "message": imgReport.message });
        });
        imgReport.observe('mouseout', function()
        {
            imgReport.src = "Images/Icons/PrintVer.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgReport.observe("click", this.printVersion.bind(this));

        imgReport.hide();
        if (showTooltip && imgReport.message != null)
            imgReport.title = imgReport.message;

        //grid view
        title = "";
        message = "";

        var imgGrid = new Element('img', { 'src': "Images/Icons/Grid.gif" });
        this.toolContainer.gridview = imgGrid;
        if (null != PAT.helpTextMessages.GridView)
        {
            imgGrid.tooltipTitle = PAT.helpTextMessages.GridView.title;
            imgGrid.message = PAT.helpTextMessages.GridView.message;
        }
        imgGrid.setStyle("width:26px;height:26px");
        imgGrid.observe('mouseover', function()
        {
            imgGrid.src = "Images/Icons/GridOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgGrid.tooltipTitle, "message": imgGrid.message });
        });
        imgGrid.observe('mouseout', function()
        {
            imgGrid.src = "Images/Icons/Grid.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgGrid.observe("click", this.gridView.bind(this));

        imgGrid.hide();
        if (showTooltip && imgGrid.message != null)
            imgGrid.title = imgGrid.message;
        //custom image report
        title = "";
        message = "";

        var imgCustomImageReport = new Element('img', { 'src': "Images/Icons/CustImgReport.gif" });
        this.toolContainer.customImageReport = imgCustomImageReport;
        if (null != PAT.helpTextMessages.ImageReport)
        {
            imgCustomImageReport.tooltipTitle = PAT.helpTextMessages.ImageReport.title;
            imgCustomImageReport.message = PAT.helpTextMessages.ImageReport.message;
        }

        imgCustomImageReport.setStyle("width:26px;height:26px");
        imgCustomImageReport.observe('mouseover', function()
        {
            imgCustomImageReport.src = "Images/Icons/CustImgReportOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgCustomImageReport.tooltipTitle, "message": imgCustomImageReport.message });
        });
        imgCustomImageReport.observe('mouseout', function()
        {
            imgCustomImageReport.src = "Images/Icons/CustImgReport.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgCustomImageReport.observe("click", this.customImageReport.bind(this));

        imgCustomImageReport.hide();
        if (showTooltip && imgCustomImageReport.message != null)
            imgCustomImageReport.title = imgCustomImageReport.message;

        //custom report
        title = "";
        message = "";

        var imgCustomReport = new Element('img', { 'src': "Images/Icons/CustReport.gif" });
        this.toolContainer.customReport = imgCustomReport;
        if (null != PAT.helpTextMessages.CustomReport)
        {
            imgCustomReport.tooltipTitle = PAT.helpTextMessages.CustomReport.title;
            imgCustomReport.message = PAT.helpTextMessages.CustomReport.message;
        }
        imgCustomReport.setStyle("width:26px;height:26px");
        imgCustomReport.observe('mouseover', function()
        {
            imgCustomReport.src = "Images/Icons/CustReportOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgCustomReport.tooltipTitle, "message": imgCustomReport.message });
        });
        imgCustomReport.observe('mouseout', function()
        {
            imgCustomReport.src = "Images/Icons/CustReport.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgCustomReport.observe("click", this.customReport.bind(this));

        imgCustomReport.hide();
        if (showTooltip && imgCustomReport.message != null)
            imgCustomReport.title = imgCustomReport.message;

        //file manager
        title = "";
        message = "";

        var imgFileManager = new Element('img', { 'src': 'Images/Icons/FileManager.gif' });
        this.toolContainer.fileManager = imgFileManager;
        if (null != PAT.helpTextMessages.FileManager)
        {
            imgFileManager.tooltipTitle = PAT.helpTextMessages.FileManager.title;
            imgFileManager.message = PAT.helpTextMessages.FileManager.message;
        }
        imgFileManager.setStyle("width:26px;height:26px");
        imgFileManager.observe('mouseover', function()
        {
            imgFileManager.src = "Images/Icons/FileManagerOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgFileManager.tooltipTitle, "message": imgFileManager.message });
        });
        imgFileManager.observe('mouseout', function()
        {
            imgFileManager.src = "Images/Icons/FileManager.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgFileManager.observe("click", this.fileManager.bind(this));

        imgFileManager.hide();

        //config.showEdit
        var imgEidtRecord = new Element('img', { 'src': 'Images/Icons/EditRecord.gif' });
        this.toolContainer.editRecord = imgEidtRecord;
        if (null != PAT.helpTextMessages.EidtRecord)
        {
            imgFileManager.tooltipTitle = PAT.helpTextMessages.EidtRecord.title;
            imgFileManager.message = PAT.helpTextMessages.EidtRecord.message;
        }
        imgEidtRecord.setStyle("width:26px;height:26px");
        imgEidtRecord.observe('mouseover', function()
        {
            imgEidtRecord.src = "Images/Icons/EditRecordOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgEidtRecord.tooltipTitle, "message": imgEidtRecord.message });
        });
        imgEidtRecord.observe('mouseout', function()
        {
            imgEidtRecord.src = "Images/Icons/EditRecord.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        });
        imgEidtRecord.observe("click", this.editRecord.bind(this));
        imgEidtRecord.hide();

        //*****************************************************
        //Diamond Icon
        //*******************************************************
        var imgDiamond = new Element('img', { 'src': 'Images/Icons/Diamond.png' });
        this.toolContainer.diamond = imgDiamond;
        imgDiamond.setStyle("width:26px;height:26px");
        imgDiamond.observe('mouseover', function()
        {
            imgDiamond.src = "Images/Icons/DiamondOver.png";
        });
        imgDiamond.observe('mouseout', function()
        {
            imgDiamond.src = "Images/Icons/Diamond.png";
        });
        imgDiamond.observe("click", this.openDiamond.bind(this));
        imgDiamond.hide();
        //**********************************************************

        if (showTooltip && imgFileManager.message != null)
            imgFileManager.title = imgFileManager.message;

        if (this.searchResult)
            this.toolContainer.insert(new Element('hr', { "id": "reportToolseaprator" }));

        this.toolContainer.appendChild(imgZoomto);
        this.toolContainer.appendChild(new Element('span', { 'id': 'zoomToSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgMailout);
        this.toolContainer.appendChild(new Element('span', { 'id': 'mailOutSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgCsv);
        this.toolContainer.appendChild(new Element('span', { 'id': 'csvSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgReport);
        this.toolContainer.appendChild(new Element('span', { 'id': 'reportSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgGrid);
        this.toolContainer.appendChild(new Element('span', { 'id': 'gridSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgCustomImageReport);
        this.toolContainer.appendChild(new Element('span', { 'id': 'customImageReportSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgCustomReport);
        this.toolContainer.appendChild(new Element('span', { 'id': 'customReportSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgFileManager);
        this.toolContainer.appendChild(new Element('span', { 'id': 'fileManagerSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgEidtRecord);
        this.toolContainer.appendChild(new Element('span', { 'id': 'editRecordSpan' }).update("&nbsp;"));
        this.toolContainer.appendChild(imgDiamond);
        this.toolContainer.appendChild(new Element('span', { 'id': 'diamondSpan' }).update("&nbsp;"));
        if (workTech != null)
        {
            var imgWorkTechList = new Element('img', { 'src': 'Images/Icons/WTList.png' });
            this.toolContainer.workTechList = imgWorkTechList;
            if (null != PAT.helpTextMessages.WorkTechList)
            {
                imgWorkTechList.tooltipTitle = PAT.helpTextMessages.WorkTechList.title;
                imgWorkTechList.message = PAT.helpTextMessages.WorkTechList.message;
            }
            imgWorkTechList.setStyle("width:26px;height:26px");
            imgWorkTechList.observe('mouseover', function()
            {
                imgWorkTechList.src = "Images/Icons/WTListOver.png";
                messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgWorkTechList.tooltipTitle, "message": imgWorkTechList.message });
            });
            imgWorkTechList.observe('mouseout', function()
            {
                imgWorkTechList.src = "Images/Icons/WTList.png";
                messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
            });
            imgWorkTechList.observe("click", workTech.listWorkOrderMultiple);

            imgWorkTechList.hide();

            var imgWorkTechAdd = new Element('img', { 'src': 'Images/Icons/WTAdd.png' });
            this.toolContainer.workTechAdd = imgWorkTechAdd;
            if (null != PAT.helpTextMessages.WorkTechAdd)
            {
                imgWorkTechAdd.tooltipTitle = PAT.helpTextMessages.WorkTechAdd.title;
                imgWorkTechAdd.message = PAT.helpTextMessages.WorkTechAdd.message;
            }
            imgWorkTechAdd.setStyle("width:26px;height:26px");
            imgWorkTechAdd.observe('mouseover', function()
            {
                imgWorkTechAdd.src = "Images/Icons/WTAddOver.png";
                messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": imgWorkTechAdd.tooltipTitle, "message": imgWorkTechAdd.message });
            });
            imgWorkTechAdd.observe('mouseout', function()
            {
                imgWorkTechAdd.src = "Images/Icons/WTAdd.png";
                messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
            });
            imgWorkTechAdd.observe("click", workTech.addWorkOrder.bindAsEventListener(workTech, imgWorkTechAdd));
            imgWorkTechAdd.hide();
            this.toolContainer.appendChild(imgWorkTechList);
            this.toolContainer.appendChild(new Element('span', { 'id': 'workTechListSpan' }).update("&nbsp;"));
            this.toolContainer.appendChild(imgWorkTechAdd);
            this.toolContainer.appendChild(new Element('span', { 'id': 'workTechAddSpan' }).update("&nbsp;"));
        }

        var nav = new Element('div', { id: "navPage" });
        this.toolContainer.insert(nav);

        this.first = new Element('img', { 'src': "Images/Icons/first.gif" });
        this.first.observe('mouseover', this.firstMouseover.bind(this));
        this.first.observe('mouseout', this.firstMouseout.bind(this));

        this.previous = new Element('img', { 'src': "Images/Icons/previous.gif" });
        this.previous.observe('mouseover', this.previousMouseover.bind(this));
        this.previous.observe('mouseout', this.previousMouseout.bind(this));

        this.next = new Element('img', { 'src': "Images/Icons/next.gif" });
        this.next.observe('mouseover', this.nextMouseover.bind(this));
        this.next.observe('mouseout', this.nextMouseout.bind(this));

        this.last = new Element('img', { 'src': "Images/Icons/last.gif" });
        this.last.observe('mouseover', this.lastMouseover.bind(this));
        this.last.observe('mouseout', this.lastMouseout.bind(this));

        if (showTooltip)
        {
            this.first.title = null != PAT.helpTextMessages.First ? PAT.helpTextMessages.First.message : "";
            this.last.title = null != PAT.helpTextMessages.Last ? PAT.helpTextMessages.Last.message : "";
            this.next.title = null != PAT.helpTextMessages.Next ? PAT.helpTextMessages.Next.message : "";
            this.previous.title = null != PAT.helpTextMessages.Previous ? PAT.helpTextMessages.Previous.message : "";
        }

        this.first.observe("click", this.firstPage.bind(this));
        this.previous.observe("click", this.previousPage.bind(this));
        this.next.observe("click", this.nextPage.bind(this));
        this.last.observe("click", this.lastPage.bind(this));
        nav.insert(this.first);
        nav.insert(new Element('span').update("&nbsp;&nbsp;"));
        nav.insert(this.previous);
        nav.insert(new Element('span').update("&nbsp;&nbsp;"));
        nav.insert(this.next);
        nav.insert(new Element('span').update("&nbsp;&nbsp;"));
        nav.insert(this.last);

        //show search result title if search from menu
        var searchTitleContainer = new Element('div', { "id": "searchTitleContainer" });
        var searchTitle = new Element('span', { "id": "searchTitle", "class": "normal" })

        searchTitleContainer.appendChild(searchTitle);
        this.toolContainer.appendChild(searchTitleContainer);

        // Select all
        var checkBlock = new Element("span");
        this.toolContainer.insert(checkBlock);

        var chkAll = new Element('input', { "type": "checkbox", "id": "chkAll" });
        chkAll.setStyle("position:relative;top:5px;height:30px;padding:0px;border:1px");
        chkAll.observe('click', this.checkAll.bind(this));

        var chkCurrentPageAll = new Element('input', { "type": "checkbox", "id": "chkCurrentPageAll" });
        chkCurrentPageAll.setStyle("position:relative;top:5px; height:30px;border:1px;padding:0px");
        chkCurrentPageAll.observe('click', this.checkAllCurrentPage.bind(this));

        //NOTE: we are hiding chkAll checkbox for now as we still don't know what to do with this option yet
        checkBlock.appendChild(chkCurrentPageAll);

        checkBlock.appendChild(new Element('span', { "class": "normal" }).update(getText("SelectAllOnPage")));
        checkBlock.appendChild(new Element('span').update("&nbsp;&nbsp;"));

        checkBlock.appendChild(chkAll);
        if (enableCheckAll == "true")
        {
            checkBlock.appendChild(new Element('span', { "class": "normal" }).update(getText("SelectAll")));
            checkBlock.appendChild(new Element('span').update("&nbsp;&nbsp;"));
        }
        else
            chkAll.hide();

        this.toolContainer.chkAll = checkBlock;
        checkBlock.hide();

        var layerHolder = new Element('div').update(getText("SelectLayer")).addClassName("normal");
        this.layerSelector = new Element('select').addClassName("resultToolSelect");
        this.toolContainer.insert(layerHolder);
        layerHolder.insert(this.layerSelector);

        var objectHolder = new Element('div', { "id": "subReport" }).update(getText("SelectSubReport")).addClassName("normal");
        this.objectSelector = new Element('select').addClassName("resultToolSelect");
        this.toolContainer.insert(objectHolder);
        objectHolder.insert(this.objectSelector);

        this.toolContainer.insert(new Element('hr', { "id": "reportToolseaprator" }));
        this.layerSelector.hide();
        layerHolder.hide();
        this.objectSelector.hide();
        objectHolder.hide();
        this.toolContainer.hide();
        this.layerSelector.observe('change', this.changeResultLayer.bind(this));
        this.objectSelector.observe('change', this.changeObject.bind(this));
    },
    lastMouseover: function()
    {
        if (!this.last.disabled)
        {
            var title = "";
            var message = "";
            if (null != PAT.helpTextMessages.Last)
            {
                title = PAT.helpTextMessages.Last.title;
                message = PAT.helpTextMessages.Last.message;
            }
            this.last.src = "Images/Icons/lastOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": title, "message": message });
        }
    },
    lastMouseout: function()
    {
        this.last.src = "Images/Icons/last.gif";
        messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
    },
    previousMouseover: function()
    {
        if (!this.previous.disabled)
        {
            var title = "";
            var message = "";
            if (null != PAT.helpTextMessages.Previous)
            {
                title = PAT.helpTextMessages.Previous.title;
                message = PAT.helpTextMessages.Previous.message;
            }
            this.previous.src = "Images/Icons/previousOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": title, "message": message });
        }
    },
    previousMouseout: function()
    {
        this.previous.src = "Images/Icons/previous.gif";
        messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
    },
    firstMouseover: function()
    {
        if (!this.first.disabled)
        {
            var title = "";
            var message = "";
            if (null != PAT.helpTextMessages.First)
            {
                title = PAT.helpTextMessages.First.title;
                message = PAT.helpTextMessages.First.message;
            }
            this.first.src = "Images/Icons/firstOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": title, "message": message });
        }
    },
    firstMouseout: function()
    {
        this.first.src = "Images/Icons/first.gif";
        messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
    },
    nextMouseover: function()
    {
        if (!this.next.disabled)
        {
            var title = "";
            var message = "";
            if (null != PAT.helpTextMessages.Next)
            {
                title = PAT.helpTextMessages.Next.title;
                message = PAT.helpTextMessages.Next.message;
            }
            this.next.src = "Images/Icons/nextOver.gif";
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": title, "message": message });
        }
    },
    nextMouseout: function()
    {
        this.next.src = "Images/Icons/next.gif";
        messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
    },
    resetPageInfo: function()
    {
        this.currentPage = 1;
    },
    firstPage: function()
    {
        if (!this.first.disabled)
        {
            this.data.config.currentPage = 1;
            this.loadData();
        }
    },
    previousPage: function()
    {
        if (!this.previous.disabled)
        {
            this.data.config.currentPage -= 1;
            this.loadData();
        }
    },
    nextPage: function()
    {
        if (!this.next.disabled)
        {
            this.data.config.currentPage += 1;
            this.loadData();
        }
    },
    lastPage: function()
    {
        if (!this.last.disabled)
        {
            this.data.config.currentPage = Math.ceil(this.data.config.totalResults / this.data.config.pageSize);
            this.loadData();
        }
    },
    resetPage: function()
    {
        this.first = null; ;
        this.next = null;
        this.previous = null;
        this.last = null;
    },
    manageKeys: function(items, checked)
    {
        var gisKeys = [];
        var keys = [];
        if (null != items)
        {
            for (var i = 0; i < items.length; i++)
            {
                var item = items[i];
                item.checked = checked;
                if (checked)
                {
                    if (this.domObj.gisKeys.indexOf(item.value) < 0)
                        this.domObj.gisKeys.push(item.value);
                    if (this.domObj.keys.indexOf(item.title) < 0)
                        this.domObj.keys.push(item.title);
                }
                else
                {
                    gisKeys.push(item.value);
                    keys.push(item.title);
                }
            }

            //if unchecked, remove gisKeys and keys from the collection
            if (!checked)
            {
                if (!checked)
                {
                    for (var i = 0; i < keys.length; i++)
                    {
                        this.domObj.keys = this.domObj.keys.without(keys[i]);
                    }
                    for (var x = 0; x < gisKeys.length; x++)
                    {
                        this.domObj.gisKeys = this.domObj.gisKeys.without(gisKeys[i]);
                    }
                }
            }
        }
    },
    checkAll: function(event)
    {
        var configParms;
        var url;
        var parms;
        //get whether the checkAll checkbox is checked
        var checked = event.element().checked;
        //uncheck "check all records in current page" check box if "check all" checkbox is checked
        if (checked)
            $('chkCurrentPageAll').checked = false;

        if (this.data.config.menuId < 0)
        {
            if (this.sortBy == null)
            //change page size  to the total results as we want to load all data
                configParms = { "currentPage": 1, "totalResults": this.data.config.totalResults, "pageSize": this.data.config.totalResults };
            else configParms = { "currentPage": 1, "totalResults": this.data.config.totalResults, "pageSize": this.data.config.totalResults, "sortedBy": this.sortBy };

            url = 'result/SelectAllRecords.aspx';
            parms = { "config": Object.toJSON(configParms), "dbObjectId": this.data.config.dbObjectId };
        }
        else
        {
            if (this.sortBy == null)
                configParms = { "menuId": this.data.config.menuId, "currentPage": 1, "totalResults": this.data.config.totalResults, "pageSize": this.data.config.totalResults };
            else configParms = { "menuId": this.data.config.menuId, "currentPage": 1, "totalResults": this.data.config.totalResults, "pageSize": this.data.config.totalResults, "sortedBy": this.sortBy };

            url = 'result/SelectAllRecords.aspx';
            parms = { "config": Object.toJSON(configParms), "dbObjectId": this.objectSelector.options[this.objectSelector.selectedIndex].value };
        }
        //set sorting to default
        new Ajax.Request(currLocation.getDirectory() + url, {
            method: 'post',

            parameters: parms, //{"config":Object.toJSON(configParms), "selectedLayers": this.data.selectedLayers},
            onSuccess: function(transport)
            {
                var data = eval('(' + transport.responseText + ')');

                //dummy item array with only title and value field as we need them for adding gisKey and key to the collections
                var items = [];
                //index of the gisKey and key from the fields item collection
                var gisIndex = -1;
                var keyIndex = -1;
                for (var i = 0; i < data.items.length; i++)
                {
                    var dummyItem = {};
                    var item = data.items[i];
                    var gisValue;
                    var keyValue;
                    //we only need to find the index of giskey and key from the field item collection for the first time, once we have the index we can access giskey and key directly
                    if (i == 0)
                    {
                        for (var j = 0; j < item.length; j++)
                        {
                            var it = item[j];
                            if (it.name == data.config.gisKey)
                                gisIndex = j;

                            if (it.name == data.config.key)
                                keyIndex = j;
                        }
                    }
                    //get the giskey and key value 
                    if (gisIndex >= 0)
                        gisValue = item[gisIndex].value;
                    if (keyIndex >= 0)
                        keyValue = item[keyIndex].value;
                    //assign giskey and key value to the dummy item
                    dummyItem.value = gisValue != null ? gisValue.toString() : "";
                    dummyItem.title = keyValue != null ? keyValue.toString() : "";
                    items.push(dummyItem);
                }

                //we need to check or uncheck all the individual checkboxes for each record.
                var checkItems = $$("input.checkItem");
                //alert(checkItems.length);

                for (var i = 0; i < checkItems.length; i++)
                {
                    checkItems[i].checked = checked;
                }
                //now we pass in the dummy items to add keys to the collection 
                report.manageKeys(items, checked);
            },
            onFailure: function()
            {
                alert(getText("SelectAllRecordFailed"))
            }
        });
    },
    checkAllCurrentPage: function(event)
    {
        var items = $$("input.checkItem");
        var count = items.size(); //this.resultContent.descendants().size();
        var checked = (event.element()).checked;
        if (checked)
            $('chkAll').checked = false;

        //clear current key collections first
        this.domObj.gisKeys = [];
        this.domObj.keys = [];
        this.manageKeys(items, checked);
    },
    zoomgoto: function(event)
    {
        if (this.domObj.gisKeys.length > 0) //&& this.domObj.keys.length > 0)
        {
            var name = this.data.config.gisKey;
            var objectID = this.data.config.currentZoomObjectID == null ? this.data.config.dbObjectId : this.data.config.currentZoomObjectID;
            mapguide.domObj.fire("PAT.Mapguide:selectionByXML", { "dbObjectId": objectID, "gisKey": name, "jsIdList": this.domObj.gisKeys });
        }
        else
            alert(getText("RecordRequired"));
    },
    loadData: function() //change page or sort
    {
        var caller = null;
        if (arguments.caller != null)
        {
            if (arguments.caller.length > 0)
                caller = arguments.caller[0].srcElement.tagName;
        }
        var configParms;
        var url;
        var parms;
        if (this.data.config.menuId < 0)
        {
            if (this.sortBy == null)
                configParms = { "currentPage": this.data.config.currentPage, "totalResults": this.data.config.totalResults };
            else configParms = { "currentPage": this.data.config.currentPage, "totalResults": this.data.config.totalResults, "sortedBy": this.sortBy };

            url = 'result/ChangePageOrSorting.aspx';
            parms = { "mgSessionId": PAT.sessionId, "config": Object.toJSON(configParms), "selectionXML": escape(this.domObj.selectionXML), "selectedLayer": this.layerSelector.options[this.layerSelector.selectedIndex].value, "dbObjectId": this.data.config.dbObjectId, "isGuestUser": isGuestUser };
        }
        else
        {
            if (this.sortBy == null)
                configParms = { "menuId": this.data.config.menuId, "currentPage": this.data.config.currentPage, "totalResults": this.data.config.totalResults };
            else configParms = { "menuId": this.data.config.menuId, "currentPage": this.data.config.currentPage, "totalResults": this.data.config.totalResults, "sortedBy": this.sortBy };

            parms = { "config": Object.toJSON(configParms), "dbObjectId": this.objectSelector.options[this.objectSelector.selectedIndex].value };
            if ((PAT.resultUrl || null) != null)
            {
                fileUrl = PAT.resultUrl;
                url = 'result/ChangePageOrSorting.aspx';
                if (url.toUpperCase() != fileUrl.toUpperCase())
                {
                    parms.masterFields = this.lastMasterFields;
                    parms.masterMenuId = this.lastMasterMenuId;
                }
            }
            else
                url = 'result/ChangePageOrSorting.aspx';

        }
        //set sorting to default
        new Ajax.Request(currLocation.getDirectory() + url, {
            method: 'post',
            parameters: parms, //{"config":Object.toJSON(configParms), "selectedLayers": this.data.selectedLayers},
            onSuccess: this.updateResultPanel.bind(this),
            onFailure: function()
            {
                alert(getText("PAT.Text.LoadDataFailed"))
            }
        });
    },
    //****************************************************************
    // if select more than 1 layers from map, then layer select will show
    // this function will be fired when change layer selection
    //****************************************************************
    changeResultLayer: function(event)
    {
        var config = { "currentPage": 1, "totalResults": -1 };
        var parms = { "mgSessionId": PAT.sessionId, "selectedLayer": this.layerSelector.options[this.layerSelector.selectedIndex].value, "selectionXML": escape(this.domObj.selectionXML), "config": Object.toJSON(config), "isGuestUser": isGuestUser };
        new Ajax.Request(currLocation.getDirectory() + 'result/resultFromMap.aspx', {
            method: 'post',
            parameters: parms,
            onSuccess: this.updateResultPanel.bind(this),
            onFailure: function()
            {
                alert(getText("ChangeResultLayerFailed"))
            }
        });
    },
    //****************************************************************
    // If selected layer associated with more than 1 object,
    // then object selctor will be displayed.
    // This function will be fired when change object selection
    //****************************************************************
    changeObject: function(event)
    {
        var parentObjId = this.data.config.objectId;
        var currentObjId = this.objectSelector.options[this.objectSelector.selectedIndex].value;
        if (this.domObj.keys.length <= 0)
        {
            alert(getText("RecordRequired"));
            var lastIndex = this.objectSelector.selectedIndex;
            var i = 0;
            for (i = 0; i < this.objectSelector.options.length; i++)
            {
                if (this.objectSelector.options[i].value == parentObjId)
                {
                    this.objectSelector.selectedIndex = i;
                    break;
                }
            }
            return;
        }
        url = 'result/resultfromchangeobject.aspx';
        var config;
        var parms;

        if (parentObjId != currentObjId)
        {
            if (this.data.config.menuId > 0)
            {
                config = { "currentPage": 1, "totalResults": -1, "menuId": this.data.config.menuId };
                parms = { "mgSessionid": PAT.sessionId, "parentObjectId": parentObjId, "dbObjectId": currentObjId, "config": Object.toJSON(config), "keys": this.domObj.keys.toJSON() }; //, "fields": this.data.queryFields.toJSON() };
            }
            else
            {
                config = { "currentPage": 1, "totalResults": -1 };
                parms = { "mgSessionId": PAT.sessionId, "parentObjectId": parentObjId, "dbObjectId": currentObjId, "config": Object.toJSON(config), "keys": this.domObj.keys.toJSON(), "selectionXML": escape(this.domObj.selectionXML), "selectedLayer": this.layerSelector.options[this.layerSelector.selectedIndex].value };
            }
            new Ajax.Request(currLocation.getDirectory() + url, {
                method: 'post',
                parameters: parms,
                onSuccess: this.updateResultPanel.bind(this),
                onFailure: function(e)
                {
                    //alert(e.responseText + " ! ");
                    alert(gettext("ChangeObjectFromMapFailed"))
                }
            });
        }
    },
    //*************************************************
    // When click map then fire this function
    //
    //*************************************************
    updateResultPanelFromMap: function(event)
    {
        this.resize(null, true);
        //if searchResult panel is used, adjust the position of report panel
        if (!this.domObj.visible())
        {
            this.domObj.show();
            report.domObj.setStyle("position:absolute;left:0px;top:" + (parseInt(query.domObj.getElementsByTagName("button")[0].style.top.substring(0, query.domObj.getElementsByTagName("button")[0].style.top.length - 2)) + 35) + "px;");
        }

        //clean keys
        this.domObj.keys = [];
        this.domObj.gisKeys = [];
        this.domObj.selectedIds = [];

        var selectedLayers = event.memo.selectedLayers;
        this.domObj.selectionXML = event.memo.selectionXML;
        if (selectedLayers.length <= 1)
        {
            this.layerSelector.hide();
            this.layerSelector.up().hide();
        }
        else
        {
            this.layerSelector.show();
            this.layerSelector.up().show();
        }

        this.layerSelector.options.length = 0;
        for (var i = 0; i < selectedLayers.length; i++)
        {
            var op = new Element('option');
            op.value = selectedLayers[i].name;
            op.innerHTML = selectedLayers[i].legend;
            this.layerSelector.insert(op);
        }

        //we don't want to display search title if we are querying from map
        $('searchTitle').hide();

        var config = { "currentPage": 1, "totalResults": -1 };
        var parms = { "mgSessionId": PAT.sessionId, "selectedLayer": this.layerSelector.options[this.layerSelector.selectedIndex].value, "selectionXML": escape(this.domObj.selectionXML), "config": Object.toJSON(config), "isGuestUser": isGuestUser };

        new Ajax.Request(currLocation.getDirectory() + 'result/resultFromMap.aspx', {
            method: 'post',
            parameters: parms,
            onSuccess: this.updateResultPanel.bind(this),
            onFailure: function()
            {
                alert(GetResultFromMapFailed);
            }
        });
    },
    loadResultForLayerSelection: function()
    {
    },
    //*********************************************
    // This function will be fired when menu clicked
    //
    //*********************************************
    updateResultPanelFromQuery: function(event)
    {
        this.resize(null, true);
        //if searchResult panel is used, adjust the position of report panel
        if (!this.domObj.visible())
        {
            this.domObj.show();
            report.domObj.setStyle("position:absolute;left:0px;top:" + (parseInt(query.domObj.getElementsByTagName("button")[0].style.top.substring(0, query.domObj.getElementsByTagName("button")[0].style.top.length - 2)) + 35) + "px;");
        }
        //clean keys
        if (this.layerSelector != null)
        {
            this.layerSelector.hide();
            this.layerSelector.up().hide();
        }
        this.domObj.keys = [];
        this.domObj.gisKeys = [];
        this.domObj.selectedIds = [];

        var queryFields = event.memo.queryFields;
        var menuId = event.memo.menuId;
        var master = event.memo.isMaster;
        var action = event.memo.action;
        var config = { "currentPage": 1, "totalResults": -1, "menuId": menuId };

        //if field value is same as autocomplete watermark, we need to clear it
        for (var i = 0; i < queryFields.length; i++)
        {
            if (queryFields[i].value == getText("AutoCompleteWatermark"))
                queryFields[i].value = "";
        }
        var parms;
        if (action != null) // the presence of action flag will determine if the item data will be returned from resultFromQuery instead of html tags
            parms = { "fields": queryFields.toJSON(), "config": Object.toJSON(config), "action": action };
        else
            parms = { "fields": queryFields.toJSON(), "config": Object.toJSON(config) };

        var fileUrl = 'Result/resultFromQuery.aspx';
        if ((PAT.resultUrl || null) != null)
        {
            var file = PAT.resultUrl;
            if (file.toUpperCase() != fileUrl.toUpperCase())
            {
                parms.masterFields = event.memo.masterField.toJSON();
                parms.masterMenuId = event.memo.masterMenuId;
                this.lastMasterFields = parms.masterFields;
                this.lastMasterMenuId = parms.masterMenuId;
            }

            fileUrl = file;
        }
        else
        {
            this.lastMasterFields = null;
            this.lastMasterMenuId = null;
        }
        //we want to display search title if we are querying from menu
        if (searchMenuText != null)
        {
            $('searchTitle').show();
            $('searchTitle').update(searchMenuText + "&nbsp;" + getText("SearchResults"));
        }

        new Ajax.Request(top.currLocation.getDirectory() + fileUrl, {  //top.currLocation.getDirectory()
            method: 'put',
            parameters: parms, //{"menuId":this.currentMenuId , "currentPage":1, "totalResults":0, "data":this.callbackObj.toJSON()}, //{"name": nameStr, "value":valueStr},
            onSuccess: this.updateResultPanel.bind(this), //function(transport){ alert(transport.responseText);}, //
            onFailure: function()
            {
                alert(getText("GetResultFromQueryFailed"))
            }
        });

    },
    onUpdateData: function(event)
    {
        //update report code here
    },
    //************************************************************************
    // write query result
    //
    //***********************************************************************
    updateResultPanel: function(transport)
    {
        if (PAT.measureFeatureMode)
        {
            taskbarContainer.domObj.fire("PAT.Taskbar:onActiveTaskbar", { target: "other" });
            taskbarContainer.domObj.fire("PAT.Taskbar:onMeasureFeature", { target: "other" });
        }
        else if (currentTaskSrc.toLowerCase() == "bufferfactory.aspx")
        {
            taskbarContainer.domObj.fire("PAT.Taskbar:onActiveTaskbar", { target: "other" });
        }
        else
        {
            var tabSize = PAT.layout.taskbar.tabs.size();
            for (var k = 0; k < tabSize; k++)
            {
                var tab = PAT.layout.taskbar.tabs[k];
                if (tab.result)
                {
                    taskbarContainer.domObj.fire("PAT.Taskbar:onActiveTaskbar", { target: tab.name });
                    break;
                }
            }
        }
        //activeTask('result');            
        //data contains
        //1. items           -- field/value/gisKey/key
        //2. configuration
        //or selectionRestricted
        this.data = eval('(' + transport.responseText + ')');
        //if the user is a guest and selectSingleParcel restriction is enabled, and also the user select more than a parcel, an error msg will be displayed and no result will be shown.
        if (this.data.selectionRestricted)
        {
            //clean up the result panel 
            this.resultContent.innerHtml = "";
            //$('navPage').hide();
            $('resultContent').hide();
            $('resultToolContainer').hide();
            alert(getText("SingleParcelRestriction"));
            return;
        }
        else
        {
            $('resultToolContainer').show();
            $('resultContent').show();
        }

        if (workTech != null)
        {
            workTech.selectedLayer = this.data.selectedLayer;
            if (workTech.selectedLayer.toLowerCase() != "workorders")
            {
                $('workTechListSpan').show();
                this.toolContainer.workTechList.show();
            }
            else
            {
                $('workTechListSpan').hide();
                this.toolContainer.workTechList.hide();
            }

            this.toolContainer.workTechAdd.show();
            $('workTechAddSpan').show();
        }
        this.resultContent.innerHTML = "";
        var config = this.data.config;
        var items = this.data.items;
        var objectList = config.objectList;

        var totalPages = Math.ceil(config.totalResults / config.pageSize);
        if (totalPages <= 1)
        {
            document.getElementById("navPage").hide();
        }
        else
        {
            document.getElementById("navPage").show();
            if (config.currentPage - 1 > 0)
            {
                this.previous.disabled = false;
                this.first.disabled = false;
            }
            else
            {
                this.previous.disabled = true;
                this.first.disabled = true;
                this.previous.src = "images/icons/previous.gif";
                this.first.src = "images/icons/first.gif";
            }

            if (config.currentPage + 1 <= totalPages)
            {
                this.next.disabled = false;
                this.last.disabled = false;
            }
            else
            {
                this.next.disabled = true;
                this.last.disabled = true;
                this.next.src = "images/icons/next.gif";
                this.last.src = "images/icons/last.gif";
            }
        }

        //showAction -- if has report or zoom to this will set to true; 
        var showAction = false;
        var size = this.data.resultCount;
        if (objectList.size() > 0)
        {
            this.objectSelector.innerHTML = "";
            for (var i = 0; i < objectList.length; i++)
            {
                var op = new Element('option');
                op.value = objectList[i].dbObjectId;
                op.innerHTML = objectList[i].objectTitle;
                this.objectSelector.insert(op);

                if (objectList[i].dbObjectId == config.dbObjectId)
                    op.selected = true;
            }
            if (objectList.size() > 1)
            {
                this.objectSelector.show();
                this.objectSelector.up().show();
            }
            else
            {
                this.objectSelector.hide();
                this.objectSelector.up().hide();
            }
        }
        else
        {
            this.objectSelector.hide();
            this.objectSelector.up().hide();
        }

        if (config.showSubReport)
            $('subReport').show()
        else
            $('subReport').hide();

        this.toolContainer.show();
        if (config.gisKey || config.key)
        {
            if (config.showCsv && size > 0)
            {
                this.toolContainer.csv.show();
                $('csvSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.csv.hide();
                $('csvSpan').hide();
            }
            if (config.showZoomto && size > 0)
            {
                this.toolContainer.zoomto.show();
                $('zoomToSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.zoomto.hide();
                $('zoomToSpan').hide();
            }
            if (config.showDetailReport && size > 0)
            {
                this.toolContainer.detailReport.show();
                $('reportSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.detailReport.hide();
                $('reportSpan').hide();
            }
            if (config.gisKey)
            {
                if (config.showGridview && size > 0 && !alwaysHideGridView)
                {
                    this.toolContainer.gridview.show();
                    $('gridSpan').show();
                    showAction = true;
                }
                else
                {
                    this.toolContainer.gridview.hide();
                    $('gridSpan').hide();
                }
            }
            else
            {
                this.toolContainer.gridview.hide();
                $('gridSpan').hide();
            }

            if (config.showMailout && size > 0)
            {
                this.toolContainer.mailout.show();
                $('mailOutSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.mailout.hide();
                $('mailOutSpan').hide();
            }
            //custom reports    
            if (config.showCustomReport && size > 0)
            {
                this.toolContainer.customReport.show();
                $('customReportSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.customReport.hide();
                $('customReportSpan').hide();
            }
            if (config.showCustomImageReport && size > 0)
            {
                this.toolContainer.customImageReport.show();
                $('customImageReportSpan').show();
            }
            else
            {
                this.toolContainer.customImageReport.hide();
                $('customImageReportSpan').hide();
            }

            if (config.showFileManager && size > 0)
            {
                this.toolContainer.fileManager.show();
                showAction = true;
            }
            else
            {
                this.toolContainer.fileManager.hide();
                $('fileManagerSpan').hide();
            }

            if (config.showAddPoint && size > 0)
            {
                //if (PAT.editFeaturesEnabled.EnableEditRoleDataAccess)
                if (PAT.editFeaturesEnabled == "true")
                {
                    this.toolContainer.editRecord.show();
                    showAction = true;
                }
            }
            else
                this.toolContainer.editRecord.hide();

            //*************
            //Diamond
            if (PAT.enableDiamond)
            {
                this.toolContainer.diamond.show();
                $('diamondSpan').show();
                showAction = true;
            }
            else
            {
                this.toolContainer.diamond.hide();
                $('diamondSpan').hide();
            }
        }
        if (showAction && size > 0)
        {
            if (!hideMultiSelectForResult)
                this.toolContainer.chkAll.show();
            else
            {
                //this is purposely hidden for sydney as they don't want to shwo detail report when multiple select is disabled
                this.toolContainer.detailReport.hide();
                $('reportSpan').hide();
            }
        }
        else
            this.toolContainer.chkAll.hide();

        this.resize(null, true);
        this.toolContainer.getElementsBySelector('[type="checkbox"]').each(function(item)
        {
            item.checked = false;
        });

        if (size <= 0)
        {
            this.resultContent.innerHTML = PAT.messages.noData;
            return;
        }

        var container = this.resultContent; //$("resultContent");
        var str;
        var t = new Date();
        var a = t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
        var str = [];
        var startNum = (config.currentPage - 1) * config.pageSize;
        var currPage = config.currentPage//Math.round((size + startNum)/config.pageSize);           
        var totalPage = Math.round(config.totalResults / config.pageSize);

        if ((totalPage * config.pageSize - config.totalResults) < 0)
            totalPage++;

        this.resultContent.innerHTML = this.data.html;
        var tt = new Date();
        var b = tt.getHours() + ":" + tt.getMinutes() + ":" + tt.getSeconds();

        var checks = $$("input.checkItem");
        var count = checks.size();
        this.domObj.gisKeys = [];
        this.domObj.keys = [];
        for (var i = 0; i < count; i++)
        {
            var chk = checks[i];
            if (count == 1)
            {
                chk.checked = true;
                if (config.gisKey != null) this.domObj.gisKeys.push(chk.value);
                if (config.key != null) this.domObj.keys.push(chk.title);
            }
            chk.observe('click', this.onRecordCheckChanged.bind(this));
        }

        var ttt = new Date();
        var c = ttt.getHours() + ":" + ttt.getMinutes() + ":" + ttt.getSeconds();

        if (size == 1 && config.autoZoomto && (this.data.config.menuId > 0))
        {
            if (config.noParent)
            {
                //auto zoomto
                this.toolContainer.getElementsBySelector('[type="checkbox"]').each(function(item)
                {
                    item.checked = true;
                });
                this.checkAll.checked = true;
                $('chkAll').checked = false;
                this.zoomgoto();
            }
        }
    },
    openDiamond: function()
    {
        var diamondURL = PAT.diamondURL + this.domObj.gisKeys.join(',');
        window.open(diamondURL, "", "toolbar, menubar,top=0,left=0,resizable=0, scrollbars=1, height=" + (screen.height - 10) + ", width=" + (screen.width - 10));
    },
    onResultColumnSort: function(event)
    {
        var column = event.memo.column;
        this.sortBy = column;
        this.loadData();
    },
    editPoint: function(event)
    {
        var key = event.memo.key;
        var keyValue = event.memo.keyValue;
        var dbObjectId = event.memo.dbObjectId;
        var who = $(event.memo.who);
        var action = event.memo.action;

        var divEditHolder = (who == null) ? null : (who.editHolder || null);
        if (divEditHolder == null)
        {
            var addPointDiv = null; ;
            var divID = null;
            if (action == "workTech")
                divID = "workTechDiv";
            else if (action != "edit")
                divID = "addNewPointDiv";

            addPointDiv = $(divID);
            if (action != "edit" && (addPointDiv || null) != null)
            {
                divEditHolder = addPointDiv;
                divEditHolder.show();
                var items = divEditHolder.getElementsByTagName('input');
                var divChildSize = items.length;
                var i = 0;
                for (; i < divChildSize; i++)
                {
                    var item = items[i];

                    if (((item.type || null) != null) && item.type.toUpperCase() == 'TEXT')
                        item.value = "";
                }
                return;
            }
            else
            {
                divEditHolder = new Element('div');
                if (action != "edit")
                {
                    divEditHolder.id = divID;
                }
            }

            var resultContentDimension = Element.getContentBoxSize(this.resultContent);
            divEditHolder.setStyle("background-color:gray");
            if (who == null)
                var width = Element.getContentBoxSize(this.resultContent.firstDescendant()).width
            else
            {
                var parentHolder = $(who).up();
                var parenHolderSize = Element.getContentBoxSize(parentHolder);
            }

            divEditHolder.setStyle("z-index:999");
            if (action == "edit")
                Element.insert($(who).up(), { after: divEditHolder });
            else
            {
                var firstChild = $("resultContent").firstDescendant()
                Element.insert(firstChild, { before: divEditHolder });
            }

            new PAT.EditPoint(divEditHolder, dbObjectId, key, keyValue, action, this.data.config.menuId);

            if (who != null)
                who.editHolder = divEditHolder;
        }
        else
            divEditHolder.show();
    },


    onRecordCheckChanged: function(event)
    {
        var checked = event.element().checked;
        var gisKey = event.element().value;
        var key = event.element().title;
        var id = event.element().id;

        if (this.domObj.gisKeys.indexOf(gisKey) < 0)
        {
            if (checked)
                this.domObj.gisKeys.push(gisKey);
        }
        else
        {
            if (!checked)
                this.domObj.gisKeys = this.domObj.gisKeys.without(gisKey);
        }

        if (this.domObj.keys.indexOf(key) < 0)
        {
            if (checked)
                this.domObj.keys.push(key);
        }
        else
        {
            if (!checked)
                this.domObj.keys = this.domObj.keys.without(key);
        }
    },
    resize: function(size, loaded)
    {
        if (size == null)
        {
            var parentHolder = this.domObj.up('div');
            //added by Stanley to deal with IE6 sizing problem for the content container
            //if (is_ie6)
            //{
            //taskbarContainer size seems to be correct in ie6 so we use that as the base instead of getting the size from the parent container
            var taskbarHolder = $('taskbarContainer');
            //somehow when leaving the separator bar height out when evaluating resultContent height, it seems to look right
            var resultContentHeight = taskbarHolder.getHeight() - $('tabContainer').getHeight();

            if (this.searchResult && loaded)
            {
                resultContentHeight -= parseInt(query.domObj.getElementsByTagName("button")[0].style.top.substring(0, query.domObj.getElementsByTagName("button")[0].style.top.length - 2)) + 37;
                //query.resize(null, true);
            }
            size = { "width": parentHolder.getWidth(), "height": resultContentHeight };
        }
        Element.setBorderBoxSize(this.domObj, size);
        var toolOffsetDimension = Element.getBorderBoxSize(this.toolContainer);
        Element.setBorderBoxSize(this.resultContent, { "width": size.width, "height": (size.height - toolOffsetDimension.height - 10) });
    },
    sort: function()
    {
    },
    zoom: function()
    {
    },
    mailout: function(event)
    {
        //if we are mailing exclusively to either owner or resident only, we don't need the popup panel, just do mailout when mailout button is clicked
        if ((report.data.config.mailoutOwner != null && report.data.config.mailoutResident == null) || (report.data.config.mailoutOwner == null && report.data.config.mailoutResident != null))
        {
            //dummy variable to hold owner and resident info
            var temp = {};
            temp.memo = {};
            if (report.data.config.mailoutOwner == null)
            {
                temp.memo.owner = false;
                temp.memo.resident = true;
            }
            else
            {
                temp.memo.owner = true;
                temp.memo.resident = false;
            }
            this.printMailout(temp);
        }
        else
        {
            if (this.mailoutSelection == null)
            {

                var btnMailout = event.element();
                //if we are mailing exclusively to either owner or resident only, we don't need the popup panel, just do mailout when mailout button is clicked
                var posStyle = btnMailout.getStyle("position");
                Element.absolutize(btnMailout);
                this.mailoutSelection = new PAT.PopupPanel(this.toolContainer);
                this.mailoutSelection.checkOwner(this.data.config.ownerDefault);
                this.mailoutSelection.checkResident(this.data.config.residentDefault);
                var btnTop = btnMailout.getStyle("top");
                var btnLeft = btnMailout.getStyle("left");
                var btnOffsetDimension = Element.getBorderBoxSize(btnMailout);
                var pos = { "top": (parseInt(btnTop) + btnOffsetDimension.height), "left": parseInt(btnLeft) };
                this.mailoutSelection.setPosition(pos);
                btnMailout.setStyle("position:" + posStyle);
            }
            else
            {
                this.mailoutSelection.resetOwnerResident(this);
                this.mailoutSelection.checkOwner(this.data.config.ownerDefault);
                this.mailoutSelection.checkResident(this.data.config.residentDefault);
                this.mailoutSelection.domObj.show();
            }
        }
    },
    printMailout: function(event)
    {
        var owner = event.memo.owner;
        var resident = event.memo.resident;

        if (this.domObj.gisKeys.length > 0 && this.domObj.keys.length > 0)
        {
            $("keys").value = this.domObj.keys.toJSON();
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            //resident/owner mailing labels
            if (owner)
                $("objectId").value = this.data.config.mailoutOwner;

            if (resident)
            {
                if (owner)
                    $("objectId").value += "&" + this.data.config.mailoutResident;
                else $("objectId").value = "0&" + this.data.config.mailoutResident;
            }
            else $("objectId").value += "&0";

            if (PAT.mailoutFunction != null)
                $("ReportFactory").action = PAT.mailoutFunction;
            else
                $("ReportFactory").action = "Result/Mailout.aspx";

            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    csv: function()
    {
        if (this.domObj.keys.length > 0)
        {
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "Result/csv.aspx";
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    printVersion: function()
    {
        if (this.domObj.keys.length > 0)
        {
            if (this.domObj.keys.length > PAT.printReportLimit)
                alert(getText("detailReportLimit"));

            $("mgSessionId").value = PAT.sessionId;
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "Result/print.aspx";
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    zoomToSingle: function(objID, gisKeyName, gisKey)
    {
        var keyArray = new Array(1);
        keyArray[0] = gisKey.toString();
        mapguide.domObj.fire("PAT.Mapguide:selectionByXML", { "dbObjectId": objID, "gisKey": gisKeyName, "jsIdList": keyArray });
    },
    printVersionSingle: function(objID, gisKey, key)
    {
        $("mgSessionId").value = PAT.sessionId;
        $("objectId").value = objID;
        if (key == null)
            key = "null";

        if (gisKey == null)
            gisKey = "null";

        $("keys").value = key.toJSON();
        $("gisKeys").value = gisKey.toJSON();
        $("roleId").value = PAT.loadedRoleId;
        $("ReportFactory").action = "Result/print.aspx";
        $("ReportFactory").target = "_blank";
        $("ReportFactory").submit();
    },
    showSortTooltip: function(fieldName)
    {
        if (fieldName == null)
            messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "message": "" });
        else
        {
            if (null != PAT.helpTextMessages.SortTooltip)
                messageCenter.domObj.fire("PAT.MessageBox:onMessage", { "title": PAT.helpTextMessages.SortTooltip.title, "message": PAT.helpTextMessages.SortTooltip.message + " " + fieldName })
        }
    },
    customImageReport: function()
    {
        if (this.domObj.gisKeys.length > 0 && this.domObj.keys.length > 0)
        {
            $("mgSessionId").value = PAT.sessionId;
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "CustomFunction/" + PAT.customFolderName + "/Report/" + this.data.config.customImageReportP;
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    customReport: function()
    {
        if (this.domObj.gisKeys.length > 0 && this.domObj.keys.length > 0)
        {
            $("mgSessionId").value = PAT.sessionId;
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "CustomFunction/" + PAT.customFolderName + "/Report/" + this.data.config.customReportP;
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    gridView: function()
    {
        if (this.domObj.gisKeys.length > 0 && this.domObj.keys.length > 0)
        {
            $("mgSessionId").value = PAT.sessionId;
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "Result/DetailReportGrid.aspx?customFolder=" + PAT.customFolderName;
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    fileManager: function()
    {
        //alert("fire file");
        if (this.domObj.keys.length > 0)
        {
            var client = this.data.config.fileManagerPath;
            $("mgSessionId").value = PAT.sessionId;
            $("objectId").value = this.data.config.dbObjectId;
            $("keys").value = this.domObj.keys.toJSON();
            $("roleId").value = PAT.loadedRoleId;
            //addd gis key
            $("gisKeys").value = this.domObj.gisKeys.toJSON();
            $("ReportFactory").action = "CustomFunction/" + PAT.customFolderName + "/Class/FileManager/DocumentManager.aspx";
            $("ReportFactory").target = "_blank";
            $("ReportFactory").submit();
        }
        else
            alert(getText("RecordRequired"));
    },
    editRecord: function()
    {
        var config = this.data.config;
        report.domObj.fire("PAT.ResultPanel:editPoint", { "action": "add", "key": config.key, "keyValue": null, "dbObjectId": config.dbObjectId, who: null });
    }
});
