﻿var enableKeys = false;
var index_Timer = null;

function selectAction(mo) {
    var url = "/" + dojo.attr( mo, "action" ) + "/PageContent/";
    dijit.byId("mainContent").set("href", url);    
}

function contactSalesman() {

    var node = dojo.query("#bodyPane > div .dlcs")[0];
    if (node != null) {        
        var docId = dojo.attr(node, "docId");

        dojo.byId("contactForm_docId").value = docId;
        dojo.byId("contactForm_message").value = "";

        var docType = dojo.attr("bodyPane", "docType");
        var docCaption = "";
        switch( docType ) {
            case "Enquiries": docCaption = "Enquiry"; break;
            case "Quotes": docCaption = "Quote"; break;
            case "SalesOrders": docCaption = "Order"; break;
            case "Shipments": docCaption = "Shipment"; break;
            case "Invoices": docCaption = "Invoice"; break;

        }
        dojo.attr( dijit.byId("contactDlg"), "title",  "RE: " + docCaption + " #" +node.cells[0].children[0].innerHTML );        
        dijit.byId("contactDlg").show();
    }
}

function contactSalesmanEditor() {

    var editorPane = dojo.byId("editorPane");
    if (editorPane != null) {
        var docId = dojo.attr(editorPane, "docId");

        dojo.byId("contactForm_docId").value = docId;
        dojo.byId("contactForm_message").value = "";

        dojo.attr(dijit.byId("contactDlg"), "title", "RE: " + dojo.byId("editorTitle").innerHTML);
        dijit.byId("contactDlg").show();
    }
}

function contactSalesman_sendMessage() {

    dijit.byId('contactDlg').hide();

    var docType = dojo.attr("bodyPane", "docType");
    var submitToUrl = "/" + docType + "/ContactSalesman";

    // Using dojo.xhrGet, as very little information is being sent
    dojo.xhrPost({
        // The URL of the request
        url: submitToUrl,
        // Form to send
        form: dojo.byId("contactForm"),
        // The success callback with result from server
        load: function (newContent) {
            alert(newContent);
        },
        // The error handler
        error: function () {
            alert("Error - Your message could not not be sent at this time");
        }
    });

}


function exportList() {

    var docType = dojo.attr("bodyPane", "docType");
    var filter = dojo.attr("bodyPane", "filter");
    var all = (dojo.attr("bodyPane", "mydocs") == false);
    var closed = (dojo.attr("bodyPane", "closed") == true);
    var archive = (dojo.attr("bodyPane", "archive") == true);
    var srchValue = "";
    try
    {
       srchValue = dojo.byId("searchFor").value;
    }
    catch (e)
    {
       srchValue = "";
    }
    var srchField = dojo.attr("bodyPane", "searchField");
    var companyId = dojo.attr("bodyPane", "companyId");
    var extra = "";
    if (srchValue != "")
        extra = "&searchFor=" + srchValue;
    if (docType == "Catalogs")
        extra = extra + "&searchField=" + srchField + "&companyID=" + companyId;

    var action = "/" + docType + "/List";
    dojo.attr("bodyPane", "action", action);

    window.open("/" + docType + "/ExportList?filter=" + filter + "&all=" + all + extra );    
}

function hookupButtons() {

    dojo.query(".ebtn")
             .connect("onmouseover", function (evt) {
                 if (!dojo.hasClass(this, "ebtnd")) {
                     dojo.removeClass(this, "ebtnu");
                     dojo.addClass(this, "ebtns");
                 }
             })
             .connect("onmouseout", function (evt) {
                 if (!dojo.hasClass(this, "ebtnd")) {
                     dojo.addClass(this, "ebtnu");
                     dojo.removeClass(this, "ebtns");
                 }
             });

}

function initializeContentPane() {

    if (dojo.query(".listContent", dojo.byId("bodyPane")).length != 0)
        initializeList();
    if (dojo.query(".editorContent", dojo.byId("bodyPane")).length != 0)
        initializeEditor();
    if (dojo.query(".companyListContent", dojo.byId("bodyPane")).length != 0)
        initializeCompanyList();

    if (dojo.attr("bodyPane", "docType") == "Catalogs") {
        dojo.query(".categoryLink")
                .connect("onclick", function (evt) {
                    dojo.attr("bodyPane", "categoryID", dojo.attr( evt.srcElement, "categoryid"));
                    openDocumentList();
                });
    }
    hookupButtons();
   
}

function initializeEditor() {

    dojo.query("#btll").connect("onclick", function (evt) {
        openDocumentList();
    });
    dojo.query("#btld").connect("onclick", function (evt) {
        openDocument(this);
    });
}

function initializeFilterList() {

     try{
        if (dojo.query("#filsel > .n2filops")[0] != null) {
            dojo.style(dojo.byId("filtersPane"), "display", "block");
            dojo.query("#filsel > .n2filop")
                .connect("onmouseover", function (evt) {
                    if (!dojo.hasClass(this, "n2filops"))
                        dojo.addClass(this, "n2filoph");
                })
                .connect("onmouseout", function (evt) {
                    if (!dojo.hasClass(this, "n2filops"))
                        dojo.removeClass(this, "n2filoph");
                })
                .connect("onclick", function (evt) {
                    dojo.query("#filsel > .n2filops").removeClass("n2filops");
                    selectFilter(this);
                });
                var initialFilter = dojo.attr("filsel", "initialFilter");
                if (initialFilter == "") {
                    var selected = dojo.query("#filsel > .n2filops")[0];
                    selectFilter(selected);
                }
                else {
                    dojo.query("#filsel > .n2filops").removeClass("n2filops");
                    var selected = dojo.byId(initialFilter);
                    selectFilter(selected);
                }
        }
        else
            dojo.style(dojo.byId("filtersPane"), "display", "none");
    }
    catch(e)
    {
        dojo.style(dojo.byId("filtersPane"), "display", "none");
    }
    SetFilSelHeight(null);
   
}

function selectFilter(node) {
   
    var index = 0;
    if (node != null) {
        if (!dojo.hasClass(node, "n2filops"))
            dojo.addClass(node, "n2filops");
        
        if (dojo.hasClass(node, "n2filoph"))
            dojo.removeClass(node, "n2filoph");

        index = dojo.attr(node, 'index');
    }
    dojo.attr("bodyPane", "page", "1");
    dojo.attr("bodyPane", "filter", index);
    dojo.attr("bodyPane", "categoryID", "");

    openDocumentList();
}

function setFilterList(initialFilter, doclistviewnodeid) {
    dojo.attr("filsel", "initialFilter", initialFilter)
    var node = dojo.byId(doclistviewnodeid);
    openDocumentListView(node);

}

function initializeReportsList() {
   
   dojo.query("#repsel > .n2navop")
    .connect("onclick", function (evt) {
        openReport(this);
    })
    .connect("onmouseover", function (evt) {
        if (!dojo.hasClass(this, "n2navops"))
            dojo.addClass(this, "n2navoph");
    })
    .connect("onmouseout", function (evt) {
        if (!dojo.hasClass(this, "n2navops"))
            dojo.removeClass(this, "n2navoph");
    });
}

function openReport(node) {
    dojo.attr("bodyPane", "docType", "Reports");

    var action = "/Reports/OpenReport";
    dojo.attr("bodyPane", "action", action );

    dojo.style(dojo.byId("filtersPane"), "display", "none");
    
    selectNavNode(node);
    dojo.addClass(node, "n2filops");

    dijit.byId("bodyPane").set("href", action + "?view=" + dojo.attr(node, "viewName"));
}

function initializeList() {

    try {

        layoutDocList();

        if (enableKeys) {
            dojo.create("div", { id: "dlf", tabIndex: 0, style: "position:absolute;z-Index:9;background:transparent;display:none" }, dojo.byId("dlic"));
            dojo.query("#dlf").connect("onkeyup", function (evt) {
                switch (evt.keyCode) {
                    case dojo.keys.DOWN_ARROW:
                        try {
                            var currNode = dojo.query("#bodyPane > div .dlcs")[0];
                            if (currNode != null && currNode.nextElementSibling != null) {
                                ListItem(currNode.nextElementSibling);
                            }
                        }
                        catch (e) { }
                        break;
                    case dojo.keys.UP_ARROW:
                        try {
                            var currNode = dojo.query("#bodyPane > div .dlcs")[0];
                            if (currNode != null && currNode.previousElementSibling != null) {
                                selectDocListItem(currNode.previousElementSibling);
                            }
                        }
                        catch (e) { }
                        break;
                }
                evt.preventDefault();
                evt.stopPropagation();
            });
        }

        dojo.query("#dlic").connect("onscroll", function () {
            $('#dlhc').scrollLeft($('#dlic').scrollLeft());
        });

        dojo.query("#bodyPane > div .lnavlink")
             .connect("onclick", function (evt) {
                 dojo.attr("bodyPane", "page", dojo.attr( this, "page" ));
                 openDocumentList();
             });

        dojo.query("#bodyPane > div #dli tr")
              .connect("onclick", function (evt) {
                  selectDocListItem(this);
                  if (dojo.hasClass(evt.srcElement, "dlcp"))
                      openDocument(this);
              })
              .connect("onmouseover", function (evt) {
                  if (!dojo.hasClass(this, "dlch") &&
                       !dojo.hasClass(this, "dlcs"))
                      dojo.addClass(this, "dlch");
                  if (dojo.hasClass(evt.srcElement, "dlcp")) {
                      dojo.addClass(evt.srcElement, "dlcph");
                      dojo.connect(evt.srcElement, "onmouseout", function (evt) {
                          dojo.removeClass(this, "dlcph");
                          dojo.disconnect(this, "onmouseout");
                      });
                  }
              })
              .connect("onmouseout", function (evt) {
                  if (dojo.hasClass(this, "dlch"))
                      dojo.query("#bodyPane > div .dlch").removeClass("dlch");
              });
        selectDocListItem(dojo.query("#bodyPane > div #dli")[0].rows[0]);
    }
    catch (e) { }
}

function OpenSelectCustomer(callingDocType){

    dojo.attr("bodyPane", "callingDocType", callingDocType);
    if (dojo.byId("searchFor") != null)
        dojo.attr("bodyPane", "callingSearchFor", escape(dojo.byId("searchFor").value));

    if ( dojo.byId("searchFor")!=null )
         dojo.byId("searchFor").value = "";

    dojo.attr("bodyPane", "docType", "Companies");

    var docType = dojo.attr("bodyPane", "docType");
    var filter = dojo.attr("bodyPane", "filter");
    var page = dojo.attr("bodyPane", "page");
    var all = (dojo.attr("bodyPane", "mydocs") == false);
    var closed = (dojo.attr("bodyPane", "closed") == true);
    var archive = (dojo.attr("bodyPane", "archive") == true);
    var srchValue = "";

    if (dojo.byId("searchFor") != null)
        srchValue = escape(dojo.byId("searchFor").value);
    var srchField = dojo.attr("bodyPane", "searchField");
    var extra = "";
    if (srchValue != "")
        extra = "&searchFor=" + srchValue;
    if (docType == "Catalogs")
        extra = extra + "&searchField=" + srchField;

    var action = "/" + docType + "/List";
    dojo.attr("bodyPane", "action", action);

    dijit.byId("bodyPane").set("href", action + "?filter=" + filter + "&page=" + page + "&all=" + all + extra);
}

function initializeCompanyList() {
    dojo.query("#bodyPane > div #dli tr")
        .connect("onclick", function (evt) {
            selectDocListItem(this);
            if (dojo.hasClass(evt.srcElement, "dlcp"))
                selectCompany(this);
        })
        .connect("onmouseover", function (evt) {
            if (!dojo.hasClass(this, "dlch") &&
                !dojo.hasClass(this, "dlcs"))
                dojo.addClass(this, "dlch");
            if (dojo.hasClass(evt.srcElement, "dlcp")) {
                dojo.addClass(evt.srcElement, "dlcph");
                dojo.connect(evt.srcElement, "onmouseout", function (evt) {
                    dojo.removeClass(this, "dlcph");
                    dojo.disconnect(this, "onmouseout");
                });
            }
        })
        .connect("onmouseout", function (evt) {
            if (dojo.hasClass(this, "dlch"))
                dojo.query("#bodyPane > div .dlch").removeClass("dlch");
        });
    }
    

function selectCompany(node) {

    var docId = dojo.attr(node, "docId");
    var docType = dojo.attr("bodyPane", "callingDocType");

    dojo.byId("searchFor").value = unescape(dojo.attr("bodyPane", "callingSearchFor"));  

    dojo.attr("bodyPane", "docType", docType);

    var docType = dojo.attr("bodyPane", "docType");

    dojo.attr("bodyPane", "companyId", docId);

    if (docType == "Catalogs") {
        var action = "/catalogs/ListFilters?companyID=" + docId;
        //dojo.attr("bodyPane", "action", action);
        dijit.byId("filsel").set("href", action);
    }
    if (docType == "CatalogsSetup") {

        var action = "/" + docType + "/OpenEditor";
        dojo.attr("bodyPane", "action", action);
        dijit.byId("bodyPane").set("href", action + "?companyID=" + docId);

    }
    if (docType != "CatalogsSetup")
        openDocumentList();
}

function openAttachment(node) {

   var docType = dojo.attr( node, "docType" );
   var filename = dojo.attr(node, "fileName")
   var docRef = dojo.attr(node, "docRef")

   var extra = "";
   if (dojo.hasAttr(node, "dropShip"))
       extra = "&dropShip=" + dojo.attr(node, "dropShip");

    window.open(  "/" + docType + "/OpenAttachment?docRef=" + docRef + "&att=" + filename + extra );    
}

function openDocument(node) {

    var docId = dojo.attr(node, "docId");
    var docType = dojo.attr(node, "docType") == null ? dojo.attr("bodyPane", "docType") : dojo.attr(node, "docType");
    var companyId = dojo.attr("bodyPane", "companyId");

    var action = "";

    var pAttr = dojo.attr(node, "pAttr");
    var extra = "";
    
    if ( pAttr!=null && pAttr !="")
        extra = "&" + pAttr;

    if (docType == "Catalogs")
    {
        action = "/" + docType + "/OpenCatalogItemPricesModel";
        dojo.attr("bodyPane", "action", action );
        dijit.byId("bodyPane").set("href", action + "?docId=" + docId + "&companyID=" + companyId);
    }
    else if (docType == "Basket") {
        action = "/" + docType + "/OpenBasket";
        dojo.attr("bodyPane", "action", action);
        dijit.byId("bodyPane").set("href", action);
    }
    else
    {
        action = "/" + docType + "/OpenEditor";
        dojo.attr("bodyPane", "action", action );
        dijit.byId("bodyPane").set("href", action + "?docId=" + docId + extra);
    }
    
}

function setBodyPaneFilter(filter) {
    dojo.attr("bodyPane", "searchField", filter);
}

function openDocumentList() {
    var docType = dojo.attr("bodyPane", "docType");
    var filter = dojo.attr("bodyPane", "filter");
    var page = dojo.attr("bodyPane", "page");
    var all = ( dojo.attr("bodyPane", "mydocs") == false );
    var closed = ( dojo.attr("bodyPane", "closed") == true );
    var archive = (dojo.attr("bodyPane", "archive") == true);
    var srchValue = "";
    try
    {
       srchValue = dojo.byId("searchFor").value;
    }
    catch (e) {
        srchValue = "";
    }
    var srchField = dojo.attr("bodyPane", "searchField");
    var companyId = dojo.attr("bodyPane", "companyId");
    var extra = "";
    extra = "&searchFor=" + srchValue;

    if (docType == "Catalogs") {
        extra = extra + "&searchField=" + srchField + "&companyID=" + companyId;
        if (dojo.attr("bodyPane", "categoryID") != "") {
            extra = extra + "&categoryID=" + dojo.attr("bodyPane", "categoryID");
        }
    }

    var action = "/" + docType + "/List";
    dojo.attr("bodyPane", "action", action );

    dijit.byId("bodyPane").set("href", action + "?filter=" + filter + "&page=" + page + "&all=" + all + "&closed=" + closed + "&archive=" + archive + extra);

}

function selectDocumentItem(node) {

    var docType = dojo.attr("bodyPane", "docType");
    var index = dojo.attr(node, "index");
    var pAttr = dojo.attr("editorPane", "pAttr");
    
    dijit.byId("dlid").set("href",  docType + "/ItemDetails?" + pAttr + "&index=" + index );
}

function selectDocListItem(node) {

    if (node != null) {
        dojo.query("#bodyPane > div .dlcs").removeClass("dlcs");
        dojo.addClass(node, "dlcs");
        dojo.query("#bodyPane > div #contactBtn").removeClass("ebtnd");
        if (enableKeys) {
            var _dlf = dojo.byId("dlf");
            dojo.style(_dlf, "pixelTop", node.offsetTop);
            dojo.style(_dlf, "pixelHeight", node.offsetHeight);
            dojo.style(_dlf, "pixelWidth", node.offsetWidth);
            dojo.style(_dlf, "pixelLeft", node.offsetLeft);
            dojo.style(_dlf, "display", "block");
            _dlf.focus();
        }
    }
    else {
        dojo.query("#bodyPane > div #contactBtn").addClass("ebtnd")
    }

}

function selectNavNode(node) {

    var selected = dojo.query(".n2navops")[0];
    if (selected != null) {
        dojo.removeClass(selected, "n2navops");
        dojo.removeClass(selected, "n2filops");
    }
    dojo.removeClass(node, "n2navoph")
    dojo.addClass(node, "n2navops");
}

function openSummaryView(node) {

    dojo.attr("bodyPane", "docType", "none");
    selectNavLink(node);
//    hideListOptions();
    
    var all = ( dojo.attr("bodyPane", "mydocs") == false );
    var closed = ( dojo.attr("bodyPane", "closed") == true );
    var archive = (dojo.attr("bodyPane", "archive") == true);
    
    var action = "/Home/Summary";
    dojo.attr("bodyPane", "action", action );
    dojo.attr("bodyPane", "hasSearchBar", "false"); 

    dijit.byId("bodyPane").set("href", action + "?all=" + all + "&archive=" + archive + "&closed=" + closed);
      
}

function selectNavLink(node) {

    var docType = dojo.attr(node, "docType")
    var currDocType = dojo.attr("bodyPane", "docType");

    if (docType != currDocType) {
        dojo.style(dojo.byId("docListContextPane"), "display", "block");
        dojo.style(dojo.byId("filtersPane"), "display", "none");
        selectNavNode(node);
        dojo.attr("bodyPane", "docType", docType);
        dojo.attr("bodyPane", "filter", "0");
        dojo.attr("bodyPane", "page", "1");
        try {
           dojo.byId("searchFor").value = "";       
        } 
        catch(e) {
        
        }
    }
}


function openDocumentListView(node) {

    selectNavLink(node);
    dojo.byId("filCap").innerText = dojo.attr(node, "filCap");

    var docType = dojo.attr("bodyPane", "docType")
    dojo.attr("bodyPane", "hasSearchBar", "true");

    var action = "/" + docType + "/ListFilters";
    dojo.attr("bodyPane", "action", action );

    dijit.byId("filsel").set("href", action );
    //showSearchBar( docType );
    showListOptions();
}

function showListOptions() {
    dojo.query("#optsel").style( "display", "block");
}

function hideListOptions() {
    dojo.query("#optsel").style("display", "none");
}

function hideSearchBar() {
    dojo.style(dojo.byId("searchBarContainer"), "display", "none");
}

function showSearchBar( controller ) {

    var url =  "/" + controller + "/SearchBar";
    if ( dijit.byId("searchBarContainer").get("href") == "" ||
          dijit.byId("searchBarContainer").get("href") != url) {
        dijit.byId("searchBarContainer").set("href", url);
    }
    dojo.style(dojo.byId("searchBarContainer"), "display", "block");

  /*  if (controller == "Catalogs")
        dojo.byId("searchForText").innerText = ""; 
    else
        dojo.byId("searchForText").innerText = ""; */
}


function layoutDocList() {
    /*
    var itemCells = dojo.query("#bodyPane > div #dli tr");
    var headCells = dojo.query("#bodyPane > div #dlh tr");

    if (itemCells != null && headCells != null) {
       var nn = "";
       var paddingLeft = 0;
       var paddingRight = 0;
       if (dojo.isIE) {
           nn = "width";
       }
       else {
           nn = "pixelWidth";
       }
       if (itemCells != null && headCells != null) {
           for (var i = 0; i < itemCells[0].cells.length; i++) {
               var paddingLeft = dojo.number.parse(dojo.style(itemCells[0].cells[i].children[0], "padding-left"));
               var paddingRight = dojo.number.parse(dojo.style(itemCells[0].cells[i].children[0], "padding-right"));
               var newWidth = dojo.number.parse(dojo.style(itemCells[0].cells[i], nn));
               dojo.style(headCells[0].cells[i].children[0], nn, newWidth);
               dojo.style(headCells[0].cells[i].children[0], "padding-left", paddingLeft);
               dojo.style(headCells[0].cells[i].children[0], "padding-right", paddingRight);
           }
       }
      
    }
     
    var srchForm = dojo.byId("searchForm");
    var bodyWidth = dojo.number.parse(dojo.style(dojo.doc.body, "pixelWidth"));
    var searchWidth = dojo.number.parse(dojo.style(srchForm, "pixelWidth"));

    var pos = dojo.number.format((bodyWidth - searchWidth) / 2, { places: 0 }) -
                       (bodyWidth - dojo.number.parse(dojo.style(srchForm.parentElement.parentElement, "pixelWidth")));

    dojo.style(srchForm.parentElement, "margin-left", ((pos < 10 || (bodyWidth < searchWidth)) ? 10 : pos) + "px");
    */

}

function toggleListOption(node) {

    var listOption = dojo.attr(node, "attr");
    var oldValue = (dojo.attr(dojo.byId("bodyPane"), listOption) == true);
    var newValue = !oldValue;

    if ((node.id == "allFilesOpt") || (node.id == "myFilesOpt"))
    {
        if (oldValue) {
            if (dojo.hasClass(dojo.byId("myFilesOpt").children[1], "n2opimgsel"))
                dojo.removeClass(dojo.byId("myFilesOpt").children[1], "n2opimgsel");
            if (!dojo.hasClass(dojo.byId("myFilesOpt"), "n2navopl"))
                dojo.addClass(dojo.byId("myFilesOpt"), "n2navopl");

            if (!dojo.hasClass(dojo.byId("allFilesOpt").children[1], "n2opimgsel"))
                dojo.addClass(dojo.byId("allFilesOpt").children[1], "n2opimgsel");
            if (dojo.hasClass(dojo.byId("allFilesOpt"), "n2navopl"))
                dojo.removeClass(dojo.byId("allFilesOpt"), "n2navopl");
        
        }
        else {
            if (dojo.hasClass(dojo.byId("allFilesOpt").children[1], "n2opimgsel"))
                dojo.removeClass(dojo.byId("allFilesOpt").children[1], "n2opimgsel");
            if (!dojo.hasClass(dojo.byId("allFilesOpt"), "n2navopl"))
                dojo.addClass(dojo.byId("allFilesOpt"), "n2navopl");

            if (!dojo.hasClass(dojo.byId("myFilesOpt").children[1], "n2opimgsel"))
                dojo.addClass(dojo.byId("myFilesOpt").children[1], "n2opimgsel");
            if (dojo.hasClass(dojo.byId("myFilesOpt"), "n2navopl"))
                dojo.removeClass(dojo.byId("myFilesOpt"), "n2navopl");
        }
    }
    else {
        if (newValue)
        {
            if (!dojo.hasClass(node.children[1], "n2opimgsel"))
                dojo.addClass(node.children[1], "n2opimgsel");
            if (dojo.hasClass(node, "n2navopl"))
                dojo.removeClass(node, "n2navopl");
        }
        else {
            if (dojo.hasClass(node.children[1], "n2opimgsel"))
                dojo.removeClass(node.children[1], "n2opimgsel");
            if (!dojo.hasClass(node, "n2navopl"))
                dojo.addClass(node, "n2navopl");
        }
    }

    dojo.attr(dojo.byId("bodyPane"), listOption, newValue);
    var action = dojo.attr("bodyPane", "action");
    var bodyPane = dijit.byId("bodyPane");
    var href = bodyPane.get("href");
    if ((node.id == "myFilesOpt") || (node.id == "allFilesOpt"))
        bodyPane.set("href", href.replace("all=" + newValue, "all=" + oldValue));   
    else
        bodyPane.set("href", href.replace(listOption + "=" + oldValue, listOption + "=" + newValue));    
  
}

function initializeWindow() {
    
    dojo.connect(window, "resize", function (evt) {
        layoutDocList();
    });    
    dojo.query("#optsel > .n2navop")
    .connect("onclick", function (evt) {
        toggleListOption(this);
    });

    dojo.attr("bodyPane", "mydocs", true );
    dojo.attr("bodyPane", "closed", false );
    dojo.attr("bodyPane", "archive", false);

    dojo.query(".n2navop")
    .connect("onmouseover", function (evt) {
        if (!dojo.attr("mainContent", "resizing")) {
            if (!dojo.hasClass(this, "n2navops"))
                dojo.addClass(this, "n2navoph");
        }
    })
    .connect("onmouseout", function (evt) {
        if (!dojo.hasClass(this, "n2navops"))
            dojo.removeClass(this, "n2navoph");
    });

    var activeOp = dojo.query("#docsel > .n2navops")[0];
    if (activeOp != null) {
        activeOp.onclick()
    }

}

function DisplayProductImages(ImageFileNames) {

    var dialog = new dojox.image.LightboxDialog({});
    dialog.startup();

    var SplitImageFileNames = ImageFileNames.split(',');
    var i = 0;
    if (SplitImageFileNames.length <= 2) {
        setTimeout(dojo.hitch(dialog, "show", {  title: "Product Image",
            href: 'Need2Base/ProductImage?path=' + SplitImageFileNames[0]
        }), 1);
    }
    else {
        for (i = 0; i < SplitImageFileNames.length - 1; i++) {
            dialog.addImage({ title: "Product Image " + (i + 1).toString(),
                href: 'Need2Base/ProductImage?path=' + SplitImageFileNames[i]
            }, "group1");
        }

        setTimeout(dojo.hitch(dialog, "show", { group: "group1", title: "Product Image 1",
            href: 'Need2Base/ProductImage?path=' + SplitImageFileNames[0]
        }), 1);

    }

}
window.onresize = SetFilSelHeight;


function SetFilSelHeight(event) {
    var filsel = dojo.byId("filsel");
    if (filsel != null) {
        var leftPaneHeight = dojo.style("leftPane", "height");
        var height = parseInt(leftPaneHeight);
        //height = Math.min(510, height);
        dojo.style(filsel, "height", (height - 132) + "px");
    }
}


