﻿   /* This file is for EquipmentList.aspx screen 
    created by Lily on May 26, 2009 */

var myRequest = getXMLHttpRequest();
          
    function getXMLHttpRequest(){
        var request = new XMLHttpRequest();
        return request;
    }
    
    function getCategoryNodePath(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll){
        var CurrentNode = CateogryTreeViewID.FindNodeById(id);
        var ParentNode = CurrentNode.GetParentNode();
        var path='';
        var PathText = document.getElementById("ctl00_Middle_path");
        while (ParentNode!=null){
            if (path==''){
                path = '<a href="" onclick="return DisplayCategoryList('+CateogryTreeViewID+','+ IndustryTreeViewID+','+ ParentNode.ID+','+ OpenAll+');>'+ParentNode.Text+'</a> >> '+ CurrentNode.Text;
                alert(ParentNode.ID);
            }
            else{
                path = '<a href="" onclick="return DisplayCategoryList('+CateogryTreeViewID+','+ IndustryTreeViewID+','+ ParentNode.ID+','+ OpenAll+');">'+ParentNode.Text+'</a> >> ' + path;
                alert(ParentNode.ID);
            }
            ParentNode = ParentNode.GetParentNode();
            }
        if (id!=1){
            PathText.style.display = 'block';
            PathText.style.visibility = 'visible';
            PathText.innerHTML = path;
        }
        else {
             PathText.style.display = 'none';
             PathText.style.visibility = 'hidden';
             //PathText.innerHTML ='';
        }
    }
    
    /* for back button on this page*/
    
   
    
    /* end for back button on this page*/
        
    function DisplayCategoryList(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll){
        //close Industry Tree
        OpenCloseAll(IndustryTreeViewID, OpenAll);
        var CurrentNode = CateogryTreeViewID.FindNodeById(id);
        var CurrentNodeName = CurrentNode.Text;
       
         //check current node if it has child node
        var LastLevelNode = IsLastChild(CateogryTreeViewID, id);
         // expand all of node when selected except for root node
        if (id!=1){
         CurrentNode.ExpandAll();
        }
         //display a equipment list base on categoryID
        DisplayList(id, 'category', CurrentNodeName,LastLevelNode);
        //getCategoryNodePath(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll);
     }
      
    function DisplayIndustryList(IndustryTreeViewID, CateogryTreeViewID, id, OpenAll){
       //close Category Tree
       OpenCloseAll(CateogryTreeViewID, OpenAll);
       var CurrentNode = IndustryTreeViewID.FindNodeById(id);
       var CurrentNodeName = CurrentNode.Text;
       //check current node if it has child node
       var LastLevelNode = IsLastChild(IndustryTreeViewID, id);
       // expand all of node when selected except for root node
        //if (id!=1){
         CurrentNode.ExpandAll();
        //}
       //display a equipment list base on IndustryID
       DisplayList(id, 'industry', CurrentNodeName,LastLevelNode);
     }
     
     /*this function is for back to list link, open node and display equipment list */
     function CategoryList(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll){
         //Open Category Tree branch based on nodeID
        OpenBranch (CateogryTreeViewID, id);
        //DisplayCategoryList(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll)
     }
     
   /*this function is for back to list link, open node and display equipment list */
    function IndustryList(IndustryTreeViewID, CateogryTreeViewID, id, OpenAll){
       //Open Industry Tree branch based on nodeID
       OpenBranch (IndustryTreeViewID, id);
        //display a equipment list base on IndustryID
       //DisplayIndustryList(IndustryTreeViewID, CateogryTreeViewID, id, OpenAll)
     }
     
     /* function for equipment overview page, default tree to it's correct node */
     function OpenCategoryTree(CateogryTreeViewID, IndustryTreeViewID, id, OpenAll){
        //close Industry Tree
        OpenCloseAll(IndustryTreeViewID, OpenAll);
        //Open Category Tree branch based on nodeID
        OpenBranchOverivew (CateogryTreeViewID, id);
       
     }
     
    /* function for equipment overview page, default tree to it's correct node */
    function OpenIndustryTree(IndustryTreeViewID, CateogryTreeViewID, id, OpenAll){
       //close Category Tree
       OpenCloseAll(CateogryTreeViewID, OpenAll);
       //Open Industry Tree branch based on nodeID
       OpenBranchOverivew (IndustryTreeViewID, id);
     }
        
        
     
   function DisplayList(id, type, CurrentNodeName,LastLevelNode){
        var defaultText = document.getElementById("ctl00_Middle_default");
        if (id!=1){
            if (defaultText){
                defaultText.style.display = 'none';
                defaultText.style.visibility = 'hidden';
                }
            myRequest.open("POST", 'DisplayEquipmentList.aspx', true);
            myRequest.onreadystatechange = handleEquipmentResponse;
            myRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            myRequest.send ('value1=' + id +'&type='+type+'&NodeName='+ escape(CurrentNodeName)+'&LastNode='+LastLevelNode); 
         }  
        else {
             if (defaultText){
                defaultText.style.display = 'block';
                defaultText.style.visibility = 'visible';
              }
              var content = document.getElementById("ctl00_Middle_List");
                if (content){
                    content.innerHTML = '';
                    return false;
                } 
        }                         
    }
            
    function handleEquipmentResponse(){  
        if (myRequest.readyState == 4){
            if (myRequest.status == 200){
                var content = document.getElementById("ctl00_Middle_List");
                if (content){
                    content.innerHTML = myRequest.responseText;
                    //window.scrollTo(0,0); 
                    backToTop();
                    return false;
                } 
                                                         
            } 
            else {
                   //alert("Fail to load Equipment List.");
                    return false;
                } 
        }
    }
            
   function DisplayOverview(equipmentid, typeID, type){
        var defaultText = document.getElementById("ctl00_Middle_default");
        dhtmlHistory.add('eid'+equipmentid, 'e');
        if (defaultText){
            defaultText.style.display = 'none';
            defaultText.style.visibility = 'hidden';
            }
        myRequest.open("POST", 'DisplayEquipmentOverview.aspx', true);
        myRequest.onreadystatechange = handleOverviewResponse;
        myRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        myRequest.send ('id=' + equipmentid +'&typeid='+typeID+'&type='+type);                            
    }
            
    function handleOverviewResponse(){  
        if (myRequest.readyState == 4){
            if (myRequest.status == 200){
                var content = document.getElementById("ctl00_Middle_List");
                if (content){
                    content.innerHTML = myRequest.responseText;
                    //window.scrollTo(0,0); 
                    backToTop();
                    return false;
                } 
                                                         
            } 
            else {
                   //alert("Fail to load Equipment Overiview.");
                    return false;
                } 
            }
        }            
       
  
  
   
   
  
    