﻿// JScript File
    var TimeOut=-1;
    var TOCMOUSEOVERTIMEDELAY=1000;
    var DPPTIMEDELAY=1000;
    var CallServer=false;
    var xmlHttp=null;
    var TreeIsfor;
    if (document.URL.indexOf("/Search.aspx") != -1)
        var tree=new NlsTree("tSearch")
    else
        var tree=new NlsTree("tree1");
    tree.add(-1,-2,'','','',true,'','','','','','','','',-1);
    //tree.opt.enbScroll = true;  // Test code only!
    tree.opt.showExpdr = true;    
    tree.opt.oneClick = true;
    tree.opt.hideRoot=true;
    tree.opt.check=true;
    //below two statements should be as they are to run search feature.
    tree.opt.checkParents=true;
    tree.opt.checkIncSub=true;
    //tree.opt.mntState=true;
    //tree.chUrl="/rs2/Pages/DWPTree.aspx";
    tree.opt.height="400px";
    tree.treeOnClick=fnShowTOCButton; 
    var flag=0;
    var xmlDoc=fnCreateXMLDOMObjectandLoad();
    var nodeid,pid,text,filename,prodCode,productshortname,description,ishierarchyexits,batchprint,fromsectionhierarchy,istoc,dbNodeId,isleafnode;
    var divid,licenseKey
    try
    {
        licenseKey=fnGetCookieValue('lic');
    }
    catch(ex){}
    var docURL="/cgi-bin/rsget.cgi";
    var nodeurl='';    
    var mouseX;
    var mouseY;
    
//    function fireEvent(element,event){  
//        if (document.createEventObject){  
//            // dispatch for IE  
//            var evt = document.createEventObject();  
//            return element.fireEvent('on'+event,evt)  
//        }  
//        else{  
//            // dispatch for firefox + others  
//            var evt = document.createEvent("HTMLEvents");  
//            evt.initEvent(event, true, true ); // event type,bubbling,cancelable  
//            return !element.dispatchEvent(evt);  
//        }  
//    }                 
    
    function FetchServerData(divstring,treefor)
    {
        divid=divstring;
        TreeIsfor=treefor;
        
        if(TreeIsfor=='Hierarchy')
        {
            tree.opt.check=false;
            tree.opt.evMouseMove=true;
            tree.opt.evMouseOver=true;
            tree.opt.evMouseOut=true;            
            tree.treeOnMouseMove=getmusecoordinates;
            tree.treeOnMouseOver=fnShowDocPreview;
            tree.treeOnMouseOut=fnClearTimeOut;            
        }
        if(TreeIsfor=='NavigationTree')
        {
            tree.opt.check=false;
        }
        if(TreeIsfor=='BatchPrint')
        {
   	        tree.opt.checkParents=false;
        }
        
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            alert ("Your browser does not support AJAX!");
            return;
        }
        var url="DWPTree.aspx";
        xmlHttp.onreadystatechange=function (stateChanged){
            if (xmlHttp.readyState==4)
            {                
                if (xmlHttp.responseXML)
                    BuildTree(xmlHttp.responseXML)
                else
                    window.document.getElementById(divid).innerHTML = xmlHttp.responseText; // Display error message rather than a blank frame.
                xmlHttp=null;                   
                   
                // Automatically expand recalled search nodes.
//                var sSelectedNodeIds = "";
//                if (
//                     (window.document.getElementById('hdnSelectedNodeIds') != null) && 
//                     (window.document.getElementById('hdnSelectedNodeIds').value != "")
//                   )
//                {
//                    sSelectedNodeIds = window.document.getElementById('hdnSelectedNodeIds').value;
//                    var arsSelectedNodeIds = sSelectedNodeIds.split(',');
//                    var iNodeId;
//                    for (iNodeId in arsSelectedNodeIds)
//                    {   
//                        if (arsSelectedNodeIds[iNodeId] != "")
//                        {
//                            var obj;
//                            obj = window.document.getElementById("cb_tSearch" + arsSelectedNodeIds[iNodeId]);
//                            if ((obj != null) && (obj.checked))
//                            {
//                                obj = window.document.getElementById("a_tSearch" + arsSelectedNodeIds[iNodeId]);
//                                if (obj != null) 
//                                    fireEvent(obj, 'click');
//                            }
//                        }
//                    }
//                }
                   
            }
        };
        xmlHttp.open("GET",url,true);
        xmlHttp.setRequestHeader("TreeFor", TreeIsfor);
        xmlHttp.send(null);
    }
    
    
    ///Following function is to build the TREE
    var enableCheck=false;
    function BuildTree(xmldoc)
    {
        var treeelement=xmldoc.documentElement;
        for(i=1;i<treeelement.childNodes.length;i++)
        {
            nodeid= treeelement.childNodes[i].attributes[0].nodeValue;  //nodeid
            pid= treeelement.childNodes[i].attributes[1].nodeValue;     //parentid
            text=treeelement.childNodes[i].attributes[2].nodeValue;     //Text
            filename=treeelement.childNodes[i].attributes[3].nodeValue; //filename
            description=treeelement.childNodes[i].attributes[4].nodeValue; //filename
            productCode=treeelement.childNodes[i].attributes[5].nodeValue;  //Productcode
            ishierarchyexits=treeelement.childNodes[i].attributes[6].nodeValue;  //HierarchyExits
            batchprint=treeelement.childNodes[i].attributes[7].nodeValue;   // BatchPrint
            productshortname=treeelement.childNodes[i].attributes[8].nodeValue; //Product Short Name
            fromsectionhierarchy=treeelement.childNodes[i].attributes[9].nodeValue; //FromSectionHierarchy
            istoc=treeelement.childNodes[i].attributes[10].nodeValue;       //TOC
            dbNodeId=treeelement.childNodes[i].attributes[0].nodeValue;     //NodeID from DataBase                        
            if(TreeIsfor=="Search")
                fnCheckNodeForRecallSearch(nodeid);                                                            
                
            if(ishierarchyexits=="True")
            {
                try
                {
                    if(tree.getNodeById(nodeid)!=null)
                        nid=nodeid + '.' + productCode + '.' +pid;
                     else
                     {
                        nid=nodeid;    
                        dbNodeId=nid;
                     }
                }
                catch(ex){nid=nodeid;}                    
                if(productCode=='')
                {
                    tree.add(nid,-1,text,"javascript:AddNodes('"+nid + "','" + productCode + "','"+ filename +"','"+ fromsectionhierarchy +"',null,'"+ dbNodeId +"')","", false,enableCheck,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                    tree.add(nid+'_'+pid,nid,"Loading...","REFRESH","../nlstree/img/loading.gif",false,false,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);                    
                }
                else
                {
                    filename=filename.substring(filename.indexOf('?')+1,filename.length);
                    tree.add(nid,-1,text,docURL +"?lic=" + licenseKey + "&" + filename,"", false,enableCheck,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                    tree.setNodeTarget(nid, "ContentFrame");                        
                }
                if(TreeIsfor=="BatchPrint")
                {
                    try
                    {
                        tree.enableCheckbox(nid,false);
                        tree.enableCheckbox(nid+'_'+pid,false);
                    }
                    catch(ex){}
                }
            }
        }
        tree.render(divid);
    }    
    function AddNodes(parentid,prodcode,filename,fromsectionhierarchy)
    {    
        try
        {
            if (xmlHttp)
            {
                return;
            }
            var currentNode=tree.getNodeById(parentid);
            if(currentNode.fc!=null && currentNode.fc.url!="REFRESH")
            {                
              return;
            }
            
            xmlHttp=GetXmlHttpObject();
            if (xmlHttp==null)
            {
                alert ("Your browser does not support AJAX!");
                return;
            }
            //Creating input xml object
            //here dbNodeId is the attribute of currently selected node (Parentid) 
            //which we are passing to DataBase...
            var input="<nodes><ParentID>" + currentNode.dbNodeId + "</ParentID>";
            input=input+ "<ProductCode>" + prodcode + "</ProductCode>";        
            if(filename.indexOf('&doc=')!=-1)
                filename=filename.substring(filename.lastIndexOf('=')+1,filename.length);        
            input=input +"<FileName>" + filename + "</FileName>";
            input=input +"<FromSectionHierarchy>" + fromsectionhierarchy + "</FromSectionHierarchy></nodes>";
            xmlDoc=fnCreateXMLDOMObjectandLoad(input);
            
            var url="DWPTree.aspx";
            xmlHttp.onreadystatechange=function (stateChanged){
                if (xmlHttp.readyState==4)
                {
                    AddChilds(xmlHttp.responseXML,parentid);
                    xmlHttp=null;
                    
                }
            };            
            xmlHttp.open("POST",url,true);
            xmlHttp.setRequestHeader("TreeFor", TreeIsfor);        
            xmlHttp.send(xmlDoc);
      }
         catch(ex){}
    }

    function AddChilds(xmldoc,parentid)
    {
        var newExpandChecked = false;
        try
        {
            var nodeelement=xmldoc.documentElement;
            if(nodeelement!=null)
            {
                for(i=1;i<nodeelement.childNodes.length;i++)
                {
                    nodeid= nodeelement.childNodes[i].attributes[0].nodeValue;  //nodeid
                    pid= nodeelement.childNodes[i].attributes[1].nodeValue;     //parentid
                    text=nodeelement.childNodes[i].attributes[2].nodeValue;     //Text
                    if(text.indexOf('"')>0){
                        text=ReplaceSpecialCharacters(text,'"','&quot;');
                    }
                    filename=nodeelement.childNodes[i].attributes[3].nodeValue; //filename
                    description=nodeelement.childNodes[i].attributes[4].nodeValue; //filename
                    productCode=nodeelement.childNodes[i].attributes[5].nodeValue;  //Productcode
                    ishierarchyexits=nodeelement.childNodes[i].attributes[6].nodeValue;  //HierarchyExits
                    batchprint=nodeelement.childNodes[i].attributes[7].nodeValue;   // BatchPrint
                    productshortname=nodeelement.childNodes[i].attributes[8].nodeValue; //Product Short Name
                    fromsectionhierarchy=nodeelement.childNodes[i].attributes[9].nodeValue; //FromSectionHierarchy
                    istoc=nodeelement.childNodes[i].attributes[10].nodeValue;           //TOC
                    dbNodeId=nodeelement.childNodes[i].attributes[0].nodeValue;         //NodeID from DataBase
                    isleafnode=nodeelement.childNodes[i].attributes[11].nodeValue       //IsLeafNode
                    if(TreeIsfor=="Search")
                    {
                        fnCheckNodeForRecallSearch(nodeid);                                                               
                    }

                    if (
                        ((document.getElementById('cb_tSearch' + pid) != null) && (document.getElementById('cb_tSearch' + pid).checked == true)) &&
                        ( 
                         (document.getElementById('hdnSelectedNodeIds')==null) ||
                         ((document.getElementById('hdnSelectedNodeIds') != null && document.getElementById('hdnSelectedNodeIds').value.indexOf("," + pid + ",") == -1))
                        )
                       )
                            newExpandChecked = true;
                    
                    try
                    {
                        if(tree.getNodeById(nodeid)!=null)
                            nid=nodeid + '.' + productCode + '.' + pid;
                         else
                            nid=nodeid;    
                    }
                    catch(ex){nid=nodeid;}
                    if(nodeelement.childNodes[i].attributes[6].nodeValue=="True")
                    {                                         
                       tree.add(nid,parentid,text,"javascript:AddNodes('"+nid+"','" + productCode + "','"+filename+"','"+ fromsectionhierarchy +"',null,'"+dbNodeId+"')","", false,enableCheck || newExpandChecked,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                       if(isleafnode=="False")
                            tree.add(nid+'_'+parentid,nid,"Loading...","REFRESH","../nlstree/img/loading.gif",false,false,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                       if(TreeIsfor=="BatchPrint")
                       {                    
                       //Commented because, for BATCHPrint we need checkbox enable only for leaf nodes.
                           try
                           {
                               if(fromsectionhierarchy=="True" || istoc=="True")
                               {
                                   tree.enableCheckbox(nid,true);
                                   tree.enableCheckbox(nid+'_'+parentid,true);                            
                               }
                               else
                               {
                                   tree.enableCheckbox(nid,false);
                                   tree.enableCheckbox(nid+'_'+parentid,false);
                               }
                           }
                          catch(ex){}
                       }
                    }
                    else
                    {  //Following condition is, if the tree is for BatchPrint or Search
                       //because, no need of URL for leaf nodes.
                       if(TreeIsfor=='BatchPrint' || TreeIsfor=='Search' )
                       {
                           tree.add(nid,parentid,text,"","", false,enableCheck || newExpandChecked,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                       }
                       else
                       {
                           tree.add(nid,parentid,text,docURL+"?lic="+ licenseKey +"&db=" + productshortname + "&doc="+filename,"", false,enableCheck || newExpandChecked,null,"",productCode,filename,fromsectionhierarchy,productshortname,istoc,dbNodeId);
                           tree.setNodeTarget(nid, "ContentFrame");
                       }
                    }
                    tree.getNodeById(parentid).istoc=nodeelement.childNodes[0].attributes[0].nodeValue;               
                }            
                var currentid=tree.getNodeById(parentid);
                if(currentid.fc!=null && currentid.fc.url=="REFRESH")
                {                
                    tree.remove(currentid.fc.orgId);
                }
                tree.reloadNode(parentid);
            }
        }
        catch(ex){}
    }

function fnCheckNodeForRecallSearch(nodeid)
{
    var bCheckNodeForRecallSearch = false;
    if(document.getElementById('hdnSelectedNodeIds')!=null && document.getElementById('hdnSelectedNodeIds').value!="")
    {
        var searchNodeid="," + nodeid + ",";
        if(document.getElementById('hdnSelectedNodeIds').value.indexOf(searchNodeid)!=-1)
        {
            enableCheck=true;
            bCheckNodeForRecallSearch = true;
        }
        else
        {
            enableCheck=false;
        }
    }    
    return bCheckNodeForRecallSearch;
}
//Following function is to Create the Browser Independent XMLDocument Object and loads XML in to xmlDoc.......
function fnCreateXMLDOMObjectandLoad(input)
{    
    if(input==null)
    {
        input='';
    }    
    if (window.ActiveXObject)
    {
        //IE...
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async="false";
        xmlDoc.loadXML(input);
    }
    else
    {
        //Firefox,Opera...
        parser=new DOMParser();
        xmlDoc=parser.parseFromString(input,"text/xml");
        xmlDoc.async="false";
    }
    return xmlDoc;
}



            //.................TOC..................//
            
function fnShowTOCButton(e,id)
{
    try
    {
        if(TreeIsfor=='Hierarchy')
        {
            //Following condtion is to change the url of ContentFrame, if Clicked node has filename...
            var _productshortname=tree.getNodeById(id).prodShortName;
            var _filename=tree.getNodeById(id).filename;
            var _istoc=tree.getNodeById(id).pr.istoc;
            if(_filename!=null && _filename!='')
            {            
                if(_productshortname!=null && _productshortname!='')
                {
                    nodeurl=docURL+"?lic="+ licenseKey +"&db=" + _productshortname + "&doc="+_filename;
                    window.frames[0].frames['ContentFrame'].location.href=nodeurl;
                    nodeurl=nodeurl  + "&istoc=" + _istoc;
                }
            }

            // this object is not defined (??) so use target/srcElement method to get originating <a> tag.
            var targ;
            if (!e) var e = window.event;
            if (e.target) targ = e.target;
	        else if (e.srcElement) targ = e.srcElement;
	        if (targ.nodeType == 3) // defeat Safari bug
		        targ = targ.parentNode;
            
            if (targ.href && isLeafNode(targ.href))
            {
                fnHideDocPreview();
                fnCloseDrillDown();
            }            
        }
        if(TreeIsfor=='NavigationTree')
        {
            var _pshortname=tree.getNodeById(id).prodShortName;
            var _fname=tree.getNodeById(id).filename;
            if(_fname!=null && _fname!='')
            {
                if(_fname.indexOf('?')!=-1)
                {
                    _fname=_fname.substring(_fname.indexOf('?')+1,_fname.length);
                    nodeurl=docURL+"?lic="+ licenseKey + "&" + _fname                    
                    window.frames.parent.frames['ContentFrame'].location.href=nodeurl;
                }
                else
                {
                    nodeurl=docURL+"?lic="+ licenseKey +"&db=" + _pshortname + "&doc="+_fname;
                    window.frames.parent.frames['ContentFrame'].location.href=nodeurl;
                }
            }            
        }
    }
    catch(ex){}
}
//This function is added to add delay in TOCMouseOver feature.
function CheckToCallTOCMouseOver()
{
    CallServer=true;
    TimeOut=setTimeout("ShowTOC('toconmouseover')",TOCMOUSEOVERTIMEDELAY);
}

function fnCancelTOCPOPUP()
{
    try
    {
        window.status="";
        clearTimeout(TimeOut);
        CallServer=false;    
        
    }
    catch(ex){}
}

//Following function is to show the TOC Pop-Up Links and after clicking on any Link 
//that corresponding HTML page will be displayed on Content Frame......
function ShowTOC(toctype)
{
    try
    {   
        if(toctype=='toconmouseover')
        {   
            //cancels the immediate server call.
            if(!CallServer)         
            return "";
        }
        if(document.getElementById('imgTOC').disabled)
            return;
        try
        {
            //The below line is used before when we depend on ContentFrame document URL to show TOC
            //nodeurl=window.frames.parent.frames['ContentFrame'].location.href;
	    nodeurl='';
	    if (window.frames.parent.frames['ContentFrame'].document.citation_form)
	       try
	       {
	            //if you want to revert to old version at any time comment below line and enable above line.
                nodeurl=window.frames.parent.frames['ContentFrame'].document.citation_form.address.value
	       }
	       catch(ex){
		        alert('Information to get TOC popup is not available in the loaded document\n(ContentFrame --> Document --> citation_form.address.value) is not available');
		        window.status='Information to get TOC popup is not available in the loaded document\n(ContentFrame --> Document --> citation_form.address.value) is not available';
	       }
            if(nodeurl.indexOf('?')!=-1)
                nodeurl=nodeurl.substring(nodeurl.indexOf('?'),nodeurl.length);
            else
                nodeurl='';
        }
        catch(ex)
        {
            nodeurl='';
        }

        if(nodeurl!='' && nodeurl.indexOf('SPLASH')==-1)
        {
            if(toctype=='toconclick')
            {
                // Traverse the breadcrumbs found in the current document.
                // If no breadcrumbs exist, load the tocURL.
                var contentFrame = window.frames.parent.frames['ContentFrame'];
                if (contentFrame)
                {
                    if (contentFrame.document.getElementById('parentURL0'))
                        contentFrame.location.href = contentFrame.document.getElementById('parentURL0').href
                    else if (contentFrame.document.citation_form.tocURL)
                    {
                        if (contentFrame.document.citation_form.tocURL.value != '')
                            contentFrame.location.href = contentFrame.document.citation_form.tocURL.value;
                    }
                }
            }
            else
            {        
                var xmlHttpTOC;
                var divdata='';//<div align=right><input type="button" value="Close" onclick=HideTOC() /></div>';
                if (xmlHttpTOC)
                {
                    return;
                }
                xmlHttpTOC=GetXmlHttpObject();
                if (xmlHttpTOC==null)
                {
                    alert ("Your browser does not support AJAX!");
                    return;
                }
                var url="TOCLinks.aspx" + nodeurl + "&toctype=" + toctype;
                xmlHttpTOC.onreadystatechange=function (stateChanged)
                {
                    if (xmlHttpTOC.readyState==4)
                    {                    
                        if(xmlHttpTOC.getResponseHeader("haslinksinTOC")=="True" || xmlHttpTOC.getResponseHeader("haslinksinTOC")=="False")
                        {
                            if(toctype=='toconmouseover')
                            {
                                GetDivFrameWindow().divframe.document.all.divmaintoc.style.left=mouseX - 50;
                                GetDivFrameWindow().divframe.document.all.divmaintoc.style.top=mouseY + 0;
                            }
                            divdata=divdata + xmlHttpTOC.responseText;
                            if(xmlHttpTOC.getResponseHeader("haslinksinTOC")=="False")
                                divdata="<center><font color='red'>No data found in the database to display</font></center>";
                            GetDivFrameWindow().divframe.document.all.divtoc.innerHTML=divdata;                        
                            GetDivFrameWindow().divframe.document.all.divmaintoc.style.visibility='visible';
                        }
                        xmlHttpTOC=null;
                    }
                };
                xmlHttpTOC.open("POST",url,true);
                xmlHttpTOC.send(null);                
            }
        }
    }
    catch(ex){alert(ex.message);}
}

function SelectNode(nodeid)
{
    GetDivFrameWindow().divframe.SelectTreeNode(nodeid);
}

function HideTOC()
{
    GetDivFrameWindow().divframe.document.all.divmaintoc.style.visibility='hidden';  
}

//Following Function is to get the Mouse Pointer Co-Ordinates when we are moving the mouse
//on the particular Document...
function getmusecoordinates(evt)
{       
    var e = (window.event) ? window.event : evt;
    // Why is DWP subtracting 4?
    mouseX=e.clientX-4;
    mouseY=e.clientY-4;    
}

//This function will nullifies all the objects used 
function CloseAllObjects()
{
  try
  {
    if(xmlHttp)
    xmlHttp=null;
    if(xmlDoc)
    xmlDoc=null;
    if(ajaxxmlHttp)
    ajaxxmlHttp=null;
    if(xmlHttpForBatchPrint)
    xmlHttpForBatchPrint=null;
  }
  catch(ex){}
}
    
                //.................DOCUMENT PREVIEW popup...............//

function fnShowDocPreview(e,id)
{
    var w=window, d=document.body, de=document.documentElement;
    var scrOffX = w.scrollX||d.scrollLeft||de.scrollLeft;
    var scrOffY = w.scrollY||d.scrollTop||de.scrollTop;
    x=e.clientX-scrOffX+5+"px";
    y=e.clientY-scrOffY+5+"px";
    CallServer=true;
    //CallDocPreview(x,y,id);
    TimeOut=setTimeout("CheckToCallDocPreview('"+ x + "','" + y + "','" + id + "')",DPPTIMEDELAY);
}
var xmlHttpDocPreview;
function fnHideDocPreview()
{
    clearTimeout(TimeOut);
    CallServer=false;    
    if(window.opener!=null)
    {
        document.getElementById('divdoc').style.visibility='hidden';
    }
    else
    {
        GetDivFrameWindow().divframe.document.all.divDocPreview.style.visibility='hidden'; 
    }
}

//Following Function will called when mouse out of node.

function fnClearTimeOut()
{
    clearTimeout(TimeOut);
    CallServer=false; 
}
function CheckToCallDocPreview(x,y,TreeNodeID)
{
    if(CallServer)
    {
        clearTimeout(TimeOut);
        CallDocPreview(x,y,TreeNodeID);
    }
}

function CallDocPreview(x,y,TreeNodeID)
{
    try
    {      
        var divFrameDoc = GetDivFrameWindow().divframe.document;
        var divDocPreview;
        if (document.all)
            divDocPreview=divFrameDoc.all.divDocPreview
        else
            divDocPreview=divFrameDoc.getElementById('divDocPreview');
        divDocPreview.style.visibility='hidden';
        fnGetDiveCoordinates();
        divDocPreview.style.zIndex=2;
        var currentnode=tree.getNodeById(TreeNodeID);
        var xml;        
        if(currentnode.url!=null && currentnode.url!='')
        {
            if(isLeafNode(currentnode.url))
            {                               
                xml = tree.nodeXML(currentnode); 
                                       
                //This function fetches document preview data
                xmlHttpDocPreview=GetXmlHttpObject();
                if (xmlHttpDocPreview==null)
                {
                    alert ("Your browser does not support AJAX!");
                    return;
                }                
                xml="<nodes>"+ xml + "</nodes>";
                var url="DocPreviewPopUp.aspx";
                xmlHttpDocPreview.onreadystatechange=function (stateChanged)
                {
                    if (xmlHttpDocPreview.readyState==4)
                    {                    
                        var response=xmlHttpDocPreview.responseText;                        
                        var divPopupData;
                        if (document.all)
                            divPopupData = divFrameDoc.all.divdppdata
                        else
                            divPopupData = divFrameDoc.getElementById('divdppdata');
                        try
                        {
                            //var btnclose="<input type='button' value='Close' onclick='fnHideDocPreview()'/>";
                            divPopupData.innerHTML= "<table><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>" + response + "</td><td>&nbsp;</td></tr></table>";
                            divPopupData.scrollTop=0;
                            divPopupData.scrollLeft=0;
                            divDocPreview.style.visibility='visible';
                        }
                        catch(ex){}
                        finally
                        {
                            xmlHttpDocPreview=null;
                        }
                    }
                };
                xmlHttpDocPreview.open("POST",url,true);
                xmlHttpDocPreview.setRequestHeader("TreeFor", TreeIsfor);            
                xmlHttpDocPreview.send(xml);                
            }            
        }
    }
    catch(ex){}
}

function fnGetDiveCoordinates()
{
}


//...........DRILL DOWN Tree............//

function ShowDrillDownTree()
{
    try
    {
        var docDivFrame = GetDivFrameWindow().divframe.document;
	    FetchServerData(docDivFrame.all.divDrillDownTree.id,'Hierarchy')
        docDivFrame.all.divMainDrillDown.style.visibility='visible';    
    }
    catch(ex){}
}
function fnCloseDrillDown()
{ 
    GetDivFrameWindow().divframe.document.all.divMainDrillDown.style.visibility='hidden';
}
function fnToggleDrillDown(drilldowntype)
{
    var divctrl=GetDivFrameWindow().divframe.document.all.divDrillDownTree;
    var divht=parseInt(divctrl.style.height.substring(0,divctrl.style.height.indexOf('px')));
    if(drilldowntype=='min')
    {
        if(divht>10)
        {
            divctrl.style.height=divht-10 + "px";
            setTimeout("fnToggleDrillDown('min')",2);
        }
        else
            GetDivFrameWindow().divframe.document.all.divMainDrillDown.style.visibility='hidden';
        
    }
    else if(drilldowntype=='max')
    {
        GetDivFrameWindow().divframe.document.all.divMainDrillDown.style.visibility='visible';
        if(divht<=400)
        {
            divctrl.style.height=divht + 10 + "px";
            setTimeout("fnToggleDrillDown('max')",2);
        }
    }
}

function isLeafNode(docurl)
{     
     try
     {
         if(docurl.indexOf('?')!=-1)
         {
             var strparameters=docurl.substring(docurl.indexOf('?')+1,docurl.length);
             var parameters=strparameters.split("&");
             var paramKey=new Array();
             var paramValue=new Array();
             var i;
             for(i=0; i<parameters.length; i++)
             {
                paramKey[i]=parameters[i].split("=")[0];
                paramValue[i]=parameters[i].split("=")[1];
                if(paramKey[i]=='doc')
                {
                    return true;
                }            
             }
             
         }    
         else
         {
             return false;
         }
     }
     catch(ex){}
}
function FmouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function FmouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}