iTree = {

   curId         : EMPTY,
   curImg        : EMPTY,
   isRightClicked: false,

   init : function(aCurTab) {
      curTab = aCurTab;
      var aPage, aId, isLogged, idLogin, existId, changeLoc, t;
      curKey = 236; //Initial Front Page
      aPage     = getDOM("idPage").innerHTML;
      aId       = getDOM("idId").innerHTML;
      idLogin   = getDOM("idLogin").innerHTML;
      existId   = aId != EMPTY;
      if (existId) {
         window.open("cmsTop.aspx?a=" + aId, "cmsTop");
         if (aPage == EMPTY) { iTree.setBody(); return; }
      }
      isLogged  = idLogin == "Y";
      changeLoc = isLogged && !existId;
      if (aPage == EMPTY) {
         if (isLogged) {
            if (!isIE) { 
               if (isFF) window.showModalDialog("cmsFFModalDialog.htm",null, "dialogWidth:600px; dialogHeight:550px;"); //https://addons.mozilla.org/en-US/firefox/addon/1419
               else alert("Sorry, please use Internet Explorer...");
               return;
            }
            document.location.href = "cms2M.aspx";
            return;
         }
         iTree.setBody();
         goToPage(1, "id" + curKey);
         return;
      }  //index.htm?Page=36,1 or index.htm?Page=36#1a,1

      var aPageS, ndx;
      t = "" + document.location.href;
      ndx = t.lastIndexOf("#");
      if (ndx > 0) aPage += t.substring(ndx);
      aPageS = aPage.split(COMMA);
      if (aPageS.length < 2) {  iTree.setBody(); goToPage(curTab, "id" + aPage); return; }
      if (isLogged) {
         if (!isIE) { alert("Sorry, please use Internet Explorer..."); return; }
         document.location.href = "cms2M.aspx?" + aPageS[1] + ",Show," + aPageS[0]; //curTab, curAction, curKey
         return;
      } else { iTree.setBody(); goToPage(aPageS[1], "id" + aPageS[0]); }
   },
   setBody : function() {
      var tab1, tab3, aName, aId, w, aUac;
      tab1  = getDOM("tab1");
      tab3  = getDOM("tab3");
      aName = getDOM("idName").innerHTML;
      aId   = getDOM("idId").innerHTML;
      aUac  = getDOM("idUAC").innerHTML;
      if (aUac != EMPTY) {
         var aUacS = aUac.split(DELI);
         addCSS(aUacS.length > 10 ? aUacS[2] : aUacS[0], "Target", true);
      }
      if (aName == EMPTY) {
         tab1.style.width   = "250px";
         tab1.className += "Selected";
         var aTab;
         aTab = getDOM("idTab").innerHTML;
         if (aTab == "1") {
            tab1.style.width   = "125px";
            tab3.style.width   = "125px";
            tab3.style.display = "block";
            tab3.innerHTML     = aId;
         }
      } else {//index.htm?id=allenc
         tab1.style.width   = "125px";
         tab3.style.width   = "125px";
         tab3.innerHTML     = aId;
         tab3.style.display = "block";
         tab3.className    += "Selected";
      }
      window.open("cmsBanner.htm?img/banner.jpg", "cmsBanner");
      document.body.onclick = iTree.clicked;
      w = (parseInt(getDOM("idMaxLen").innerHTML, 10) * 6 + 50);
      if (w < 260) w = 260;
      document.body.style.width = w + "px";

   },
   clickedTab : function(aTab) {
      var aPage, aId, s, w;
      if (isEnabledCookie()) {
         aPage = getCookie("cms1G_curPage");
         if (aPage != EMPTY) getDOM("idPage").innerHTML = aPage;
         setCookie("cms1G_curPage", curKey);
      }
      s = window.location.search;
      if (s != EMPTY && s != "undefined") {
         if (aTab == 3) {
            aId   = iTree.getPara("id", s);
            if (aPage == EMPTY) aPage = iTree.getPara("Page", s);
            document.location.href = "cms1G.aspx?tab=3&id=" + aId + (aPage == EMPTY ? EMPTY : "&Page=" + aPage);
            return;
         }
      }
      aId   = getDOM("idId").innerHTML;
      aPage = getDOM("idPage").innerHTML;
      document.location.href = "cms1G.aspx?tab=" + aTab + (aId == EMPTY ? EMPTY : "&id=" + aId) + (aPage == EMPTY ? EMPTY : "&Page=" + aPage);
   },
   getPara : function(p, s) {
      var t, sS;
      sS = s.substring(1).split("&");
      t = sS[0];
      if (t.indexOf(p) >= 0) return t.substring(p.length + 1);
      if (sS.length > 1) {
         t = sS[1];
         if (t.indexOf(p) >= 0) return t.substring(p.length + 1);
      }
      return EMPTY;

   },
   clicked : function(e) {
      iTree.isRightClicked = false;
      var a;
      if (isIE || isOP) a = window.event.srcElement;
      else if (isFF)    a = e.target;
      if (a.id == "undefined" || a.id == null || a.id == EMPTY) return;
      var aId = a.id;
      if (aId.indexOf("_G") >  0)      clickedTreeImg(a);
      else if (aId.indexOf("id") == 0) iTree.clickedTreeNode(a);
     
   },

   clickedTreeNode : function(a, an) {
      var b, e, t, u, aId, aUrl, aKey, ndx, aTarget, aTargetLoc, aTargetClass, aBanner, aImg, aName;
      var tS;
      iTree.setCurTreeNode(a);
      aId = a.id;
      t    = cmsTop.src;
      aImg = a.img;
      if (aImg == "undefined" || aImg == null) aImg = "img/banner.jpg";
      if (aImg != iTree.curImg) {
         u = t.substring(0, t.lastIndexOf(",") + 1);
         aName = sFirstName + " " + sLastName;
         window.open("cmsBanner.htm?" + aImg, "cmsBanner");
         iTree.curImg = aImg;
      }
      if (an != null) a.href = a.href + an;
      if (a.href) {
         if (isIE) a.click();
         else if (a.target != "_blank") window.open(a.href, a.target);
      }
      if (getDOM(aId + tagC) == null) return;
      c = getDOM(aId + tagC);
      g = getDOM(aId + tagG);
      if (c.style.display == 'none') { c.style.display = 'block'; g.src = imgOpen;  }
      //else                           { c.style.display = 'none';  g.src = imgClose; } // Toggle for hasson node

   },
   setCurTreeNode   : function(a)    {
      var aId = a.id;
      if (curId == 'undefined' || curId == null || curId == EMPTY) {
         curId = aId;
         iTree.selectTreeNode(a);
         curKey = iTree.getKey(curId);
         return;
      }
      iTree.selectTreeNode(a);
      if (aId != curId) {
         var aIdObj = getDOM(curId);
         if (aIdObj != null) iTree.deselectTreeNode(aIdObj);
         curId  = aId;
         curKey = iTree.getKey(curId);
      }
   },
   //selectTreeNode     : function(a)        { if (a == null) return; var c = a.className; if (!h[a.id + "Class"]) h[a.id + "Class"] = c; if (c.indexOf("Sel") > 0) return;  a.className = c.indexOf("admin") < 0 && c.indexOf("save") < 0 ? "treeAreaSelected" : c + "Selected"; a.style.color="#3333FF"; a.style.textDecoration="underline"; a.style.fontWeight="bolder";},
   //deselectTreeNode   : function(a)        { if (a == null) return; var c = a.className; a.className = h[a.id + "Class"]; a.style.color="#333333"; a.style.textDecoration="none"; a.style.fontWeight="normal";},
   selectTreeNode     : function(a)        { if (a == null) return; a.style.color="#3333FF"; a.style.textDecoration="underline"; a.style.fontWeight="bolder";},
   deselectTreeNode   : function(a)        { if (a == null) return; a.style.color="#333333"; a.style.textDecoration="none"; a.style.fontWeight="normal";},
   getId              : function(aId)      { return aId.substring(aId.indexOf('.') + 1); },
   getKey             : function(aId)      { return aId.substring(2); },
   mv                 : function(a)        {  }
};
