﻿// JScript File
var tree;
var currboxID=0;
var url = "";
function CreateTree(currboxID)
{
    var FolderTree = document.getElementById("FolderTree");
    if(FolderTree==null)
        return;
    
    FolderTree.innerHTML = "";          
    tree = new DHQTreeView("tree");
    tree.setIconPath("/images/Icons/EmailTreeIcons/");    
    tree.navigateurlID  = 0;
    tree.showMenu       = true;
    
    //Clear global data source.
    GlobalXmlDataSource = null;
    tree.setRemoteURL(window.location.protocol + "//" + document.domain + "/msg/emailfoldertree.aspx");

    tree.LoadXML(false);
    FolderTree.innerHTML = tree.toString();
    
    var msgboxID = currboxID;
    if(msgboxID==0)
    {
        if(FirstExpandNodeUrl=="")
        {
            tree.focus(2);
        }
        else
        {
            tree.focusByUrl(FirstExpandNodeUrl);    
            FirstExpandNodeUrl = "";
        }                
    }
    else
    {
        url="javascript:__doPostBack(\"commander\",\"MailList," + msgboxID + "\")";
        tree.focusByUrl(url); 
    }
}	
var isFirstLoad = true
function loadDefaultModule(moduleName) {
    if (!isFirstLoad) {
        return;
    }
    var hash = window.location.hash;
    if (hash != null && hash != "") {
        hash = hash.substring(1, hash.length);
    }
    if (hash == "") {
        setTimeout(function() { PostBack(moduleName); }, "100"); //wait load script. 
    }
    isFirstLoad = false;
} 

//Contact Group tree
var contGroupTree;
function CreateContGroupTree(currboxID)
{
    var FolderTree = document.getElementById("ContGroupTree");
    
    if(FolderTree==null)
        return;
    
    FolderTree.innerHTML = "";          
    contGroupTree = new DHQTreeView("contGroupTree");    
    contGroupTree.icons["ContactRoot"] = "Concact_root.gif";
    contGroupTree.icons["MyContacts"] = "MyContacts.gif";
    contGroupTree.icons["ContactShare"]  = "ContactShare.gif";
    contGroupTree.icons["ContactShareUser"]  = "ContactShareUser.gif";
    contGroupTree.icons["Contact"] = "Contact.gif";
    contGroupTree.icons["ContactBlocked"] = "Contact_Block.gif";
    contGroupTree.icons["ContactShared"] = "ContactShared.gif";
	contGroupTree.icons["SharedToMe"] = "SharedToMe.gif";
    contGroupTree.setIconPath("/images/Icons/ContGroupTreeIcons/");    
    contGroupTree.navigateurlID  = 0;
    contGroupTree.showMenu       = false;
    contGroupTree.setRemoteURL(window.location.protocol + "//" + document.domain + "/msg/ContGroupTree.aspx");
    GlobalXmlDataSource = null;
    contGroupTree.LoadXML(false);
    FolderTree.innerHTML = contGroupTree.toString();
    contGroupTree.expandSetNodes(2);
    if(currboxID==0)
    {
        if(FirstExpandNodeUrl=="")
        {
            contGroupTree.focus(2);
        }
        else
        {
            contGroupTree.focusByUrl(FirstExpandNodeUrl);    
            FirstExpandNodeUrl = "";
        }                
    }
    else
    {
        url="javascript:__doPostBack(\"commander\",\"contacts," + currboxID + "\")";
        contGroupTree.focusByUrl(url); 
    }
}