×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

cookies and treeview

cookies and treeview

cookies and treeview

(OP)
I am trying to save the current state of a treeview to a cookie.  In other words, how ever you last left a tree (pluses and minuses for viewing data) display that next time you enter the page.  I am using http://www.dynamicdrive.com/dynamicindex1/navigate2.htm as an example.  I am having difficulty getting it to work because this is two instances of third party code that I am trying to marry.  So does anyone else have a good example on how to do this?

RE: cookies and treeview

not exactly a simple operation, but i'm bored so i wrote the whole dang thing.  

<html>
    <head>
        <title>tree</title>

        <script type="text/javascript">
            function toggle(pDiv) {
                var pDivs = getParentDivs();
                var cDivs = getChildDivs();
                var iSpans = getIndicatorSpans();
                var index = pDiv.id.split("_")[1];
                var cDiv = document.getElementById("child_" + index);
                var iSpan = document.getElementById("indicator_" + index);

                //  toggle state of pDiv's child
                cDiv.style.display =
                    (cDiv.style.display == "block") ?
                    "none" : "block";
                
                //  toggle pDiv's +- indicator
                iSpan.innerHTML = iSpan.innerHTML == "+" ? "-" : "+";
                
                //  hide all other children, set indicator to "+"
                for (var x = 0; x < pDivs.length; x++) {
                    if (pDivs[x].id != "parent_" + index) {
                        cDivs[x].style.display = "none";
                        iSpans[x].innerHTML = "+";
                    }
                }
                
                //  store the tree state
                storeTreeState(pDiv, pDivs);
            }
            
            function getParentDivs() {
                var els = document.getElementsByTagName("div");
                var ar = [];
                for (var x = 0; x < els.length; x++) {
                    if (els[x].className && els[x].className == "parent_div")
                        ar.push(els[x]);
                }
                return ar;
            }
            
            function getChildDivs() {
                var els = document.getElementsByTagName("div");
                var ar = [];
                for (var x = 0; x < els.length; x++) {
                    if (els[x].className && els[x].className == "child_div")
                        ar.push(els[x]);
                }
                return ar;
            }
            
            function getIndicatorSpans() {
                var els = document.getElementsByTagName("span");
                var ar = [];
                for (var x = 0; x < els.length; x++) {
                    if (els[x].className && els[x].className == "indicator")
                        ar.push(els[x]);
                }
                return ar;
            }
            
            function storeTreeState(pDiv, pDivs) {
                var state = "";
                
                //  store a string of zeros, with a 1 for the open branch
                for (var x = 0; x < pDivs.length; x++) {
                    state += (pDivs[x] == pDiv) ? "1" : "0"
                }
                
                var now = new Date();
                var expires = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);

                document.cookie = "treeState=" + state +
                    ";expires=" + expires;
            }
            
            window.onload = function loadTree() {
                if (document.cookie) {
                    var state = document.cookie.match(/treeState=([^;]+)/)[1];
                    var pDivs = getParentDivs();
                    
                    for (var x = 0; x < pDivs.length; x++) {
                        if (state.charAt(x) == "1") {
                            toggle(pDivs[x]);
                            break;
                        }
                    }
                }
            }
        </script>

        <style type="text/css">
            .indicator {
                font-family:monospace;
            }
            .child_div {
                display:none;
                margin-left:20px;
            }
        </style>
    </head>

    <body>
        <div id="parent_1" onclick="toggle(this);" class="parent_div">
            <span id="indicator_1" class="indicator">+</span>
            parent_1
            <div id="child_1" class="child_div">child_1</div>
        </div>

        <div id="parent_2" onclick="toggle(this);" class="parent_div">
            <span id="indicator_2" class="indicator">+</span>
            parent_2
            <div id="child_2" class="child_div">child_2</div>
        </div>

        <div id="parent_3" onclick="toggle(this);" class="parent_div">
            <span id="indicator_3" class="indicator">+</span>
            parent_3
            <div id="child_3" class="child_div">child_3</div>
        </div>
    </body>
</html>




======================================================================================

=========================================================
-jeff
www.jeffemminger.com
try { succeed(); } catch(E) { tryAgain(); }

RE: cookies and treeview

btw, it's currently configured to remember the state for just one day.  this can be changed in storeTreeState(), like

//  remember for one month
var expires = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());

additionally, the functions getParentDivs(), getChildDivs() and getIndicatorSpans() can be replaced with these optimized versions for larger trees:

function getParentDivs() {
    //  cache for efficiency
    if (!self._pdivs) {
        var els = document.getElementsByTagName("div");
        var ar = [];
        for (var x = 0; x < els.length; x++) {
            if (els[x].className && els[x].className == "parent_div")
                ar.push(els[x]);
        }
        self._pdivs = ar;
    }
    return self._pdivs;
}

function getChildDivs() {
    //  cache for efficiency
    if (!self._cdivs) {
        var els = document.getElementsByTagName("div");
        var ar = [];
        for (var x = 0; x < els.length; x++) {
            if (els[x].className && els[x].className == "child_div")
                ar.push(els[x]);
        }
        self._cdivs = ar;
    }
    return self._cdivs;
}

function getIndicatorSpans() {
    //  cache for efficiency
    if (!self._ispans) {
        var els = document.getElementsByTagName("span");
        var ar = [];
        for (var x = 0; x < els.length; x++) {
            if (els[x].className && els[x].className == "indicator")
                ar.push(els[x]);
        }
        self._ispans = ar;
    }
    return self._ispans;
}

=========================================================
-jeff
www.jeffemminger.com
try { succeed(); } catch(E) { tryAgain(); }

RE: cookies and treeview

(OP)
Your way does seem straight forward.  I am working with 3rd party code very similar to yours.  I will paste it below.  the problem is that I am unfamiliar with this 3rd party code, dhtml and javascript.  I know each just not that well.  Would you (or anyone) be able to help me integrate these two?  I am having problems writing the collapsed item to the cookie.  I know I am very close.  I will include the code from the hyperlink in my original question.  This is all in a javascript file as opposed to the actual web page.  Thank you in advance.



/* Initial Object Method Settings. */
    document.onclick    = handleClick;
    document.ondblclick    = handleDoubleClick;
    window.onload         = initMessageTreePrime;
    window.onunload        = saveswitchstate;
    window.onresize        = fixSize;
    document.onmouseover    = messageTreeOnMouseOver;
    document.onmouseout    = messageTreeOnMouseOut;fixSubPadding(5);
    document.ondragstart = function cancelDrag(){return(false);}

/* Initial Variable Declarations. */
    var lastclicked        = null;
    var objSelectedItem     = null;
    var sPageType        = null;
    var nTaskCount        = null;
    var commentWin        = null;
    var userWin        = null;
    var viewTaskWin = null;
    var newTaskWin    = null;
    var lastBG        = null;
    var lastFG        = null;
    var confirmNotify = 0;
    var confirmReissue = 0;
    var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
    var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)



/* Adjusts The Size Of The Scroll View According To Its Parent Document. */
function fixSize(){
    try
    {
        if(sPageType=="TaskViewMain") {
            scrollDiv.style.height=Math.max(document.body.clientHeight-(messageHeader.offsetHeight * 2),0);
            scrollDiv.style.width=Math.max(document.body.clientWidth,0);
            Function("messageHeader.style.marginLeft = -scrollDiv.scrollLeft");
        }
    }
    catch (exception)
    {}
}



/* Event handler for a click on the document. */
function handleClick(){
    try
    {

        //Find out if the user clicked on the plus sign by attempting to retrieve the plus SPAN element
        var plusEl    = getReal(window.event.srcElement,"className","plus");

        if(plusEl.className=="plus"&&plusEl.children.length>0){
            //If the plus SPAN was found and it has an IMG element (inserted by fixPlusSign procedure)
            //then either expand or collapse the display.
            if(plusEl.children.tags("IMG")[0].src.indexOf("minus")!= -1) {
                hideItem(plusEl);
            }
            else {
                showItem(plusEl);
                return;
            }
        }

        //If the user clicked anywhere else on the row then attempt to retrieve the A element
        var el        = getReal(window.event.srcElement,"tagName","A");
        if(el.tagName=="A"){
            if (el.taskid!=""){
                //Highlight the currently selected row and un-highlight the previously selected row
                if(lastclicked!=null){
                    lastclicked.style.backgroundColor = lastBG;
                    lastclicked.style.color = lastFG;
                }
                
                lastBG = el.currentStyle.backgroundColor;
                lastFG = "black";
                
                lastclicked = el;
                el.style.background="highlight";
                el.style.color="highlighttext";

                //Cache values of the currently selected row in an object variable so it can by acted on by menu commands

                initializeObjItem(el);
                
            }
        }
    }
    catch (exception)
    {}

}

/* Event handler for a double click on the document. */
function handleDoubleClick(){
    //Find out if the user clicked on the plus sign by attempting to retrieve the plus SPAN element
    var plusEl    = getReal(window.event.srcElement,"className","plus");
    
    if(plusEl.className=="plus"&&plusEl.children.length>0){
        //If the plus SPAN was found and it has an IMG element (inserted by fixPlusSign procedure)
        //then either expand or collapse the display.
        if(plusEl.children.tags("IMG")[0].src.indexOf("minus")!= -1) {
            hideItem(plusEl);
        }
        else {
            showItem(plusEl);
            return;
        }
    }
    
    var el        = getReal(window.event.srcElement,"tagName","A");
    
    if(el.tagName=="A") {
        if (el.taskid!="") {
            viewEntry();
        }
    }
    
}

/* Highlights The Hovered Item. */
function messageTreeOnMouseOver(){
    try
    {
        var fromEl    = getReal(window.event.fromElement,"tagName","A");
        var toEl    = getReal(window.event.toElement,"tagName","A");
        
        if(fromEl==toEl) return;
        
        if(toEl.tagName=="A"){
            if(lastclicked!=null&&lastclicked==toEl&&ieVersion()>=5){
                toEl.style.color="highlighttext";
                toEl.style.background="highlight";
            }
            else toEl.style.color="blue";
        }
    
    }
    catch (exception)
    {}
}


/* Unhighlights The Last Hovered Item. */
function messageTreeOnMouseOut(){
    try
    {
        var fromEl    = getReal(window.event.fromElement,"tagName","A");
        var toEl    = getReal(window.event.toElement,"tagName","A");
        
        if(fromEl==toEl) return;
        
        if(fromEl.tagName=="A"){
            if(document.body.selectedItem!=null&&document.body.selectedItem==fromEl&&ieVersion()>=5){
                fromEl.style.color="highlighttext";
                fromEl.style.background="highlight";
            }
            else if(fromEl==lastclicked){
                fromEl.style.background="highlight";
                fromEl.style.color="highlighttext";
            }
            else fromEl.style.color="windowtext";
        }
    }
    catch (exception)
    {
    }

}
    
function do_tree_onload()
{
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && typeof ccollect!="undefined")
        revivecontent()
}

function revivecontent()
{
    contractcontent("omitnothing")
    selectedItem=getselectedItem()
    selectedComponents=selectedItem.split("|")
    for (i=0; i<selectedComponents.length-1; i++)
    document.getElementById(selectedComponents).style.display="block"
}

function contractcontent(omit)
{
    var inc=0
    while (ccollect[inc])
    {
        if (ccollect[inc].id!=omit)
        ccollect[inc].style.display="none"
        inc++
    }
}

function getElementbyClass(classname)
{
    ccollect=new Array()
    var inc=0
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    for (i=0; i<alltags.length; i++)
    {
        if (alltags.className==classname)
        ccollect[inc++]=alltags
    }
}

function getselectedItem()
{
    if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
    }
    else
    return ""
}

function get_cookie(Name)
{
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
}
return returnvalue;
}

function saveswitchstate()
{
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
}

document.cookie=window.location.pathname+"="+selectedItem+";expires=Wednesday, 05-Jan-05 00:00:00 GMT";
 //strCookie = "tracyscookies=12345";
//document.cookie = strCookie;

}



/* Initializes The Treeview. *///
function initMessageTreePrime(){

do_tree_onload()
    try
    {
            
        if(scrollDiv) {
            sPageType = scrollDiv.getAttribute("pageType");
        }
        
        parent.treeLoaded();
        fixSize();
        numberOfChildItems();
        
        el = document.all.messageTree;
        if(el.children.length>0){
            el.tree=new Tree(el.children[0]);
            el.tree.add(buildTree(el.children[0]));
        }
        
        scrollDiv.onscroll = new Function("messageHeader.style.marginLeft = -scrollDiv.scrollLeft");
        
        fixExpandState();
        checkTopUrl();
        
        if(sPageType=="TaskViewMain" && document && document.XMLDocument && document.XMLDocument.documentElement && document.XMLDocument.documentElement.xml) {
            var xmlString         = document.XMLDocument.documentElement.xml;
            var xmlData         = new ActiveXObject("MSXML2.DOMDocument");
            
            xmlData.async  = false;
            xmlData.loadXML(xmlString);
            
            var nList         = xmlData.selectNodes("/root/task");
            
            if(!nList.length && document == parent.messageframe.document) {
                var targetDoc         = document;
                
                targetDoc.all.taskDetail.innerHTML = "";
                alert('No tasks could be found.');
            }
        }
        else if(parent.mainframe && parent.mainframe.document.all.taskAttributes) {
            initializeObjItem(parent.mainframe.document.all.taskAttributes);
        }

        fixPlusSign();            
        ExpandSearchResults();    
    }
    catch (exception)
    {
    }
}

var pluses=new Array();
/* Shows The Plus Image Next To Items With Children. */
function fixPlusSign(){
    var index        = 0;
    var spans        = document.all.tags("span");
    var spansLength        = spans.length;

    for(var i=0;i<spansLength;i++){
        if(spans.className=="plus") pluses[index++]=spans;
    }
    
    var plusesLength    = pluses.length;
    
    if(nTaskCount) plusesLength = nTaskCount;
    
    for(i=0;i<plusesLength;i++){
        if(pluses.parentElement.parentElement.children.tags("div").length>0) pluses.innerHTML=plusString;
    }
    
    if(messageTree.children.length>0){
        var topItems        = messageTree.children[0].children;
        var tpl            = topItems.length;
        
        for(var i=0;i<tpl;i++){
            if(topItems.className=="item"){}
        }
    }
}

/* Fixes The Expand State. */
function fixExpandState(){
    if(parent.tLoaded&&parent.toolframe.document.all.toggleExpandCollapseButton.value)
        expandCollapse();
}

/* Expands Or Collapses Any Subitems. */
function expandCollapse(){
    if(expandedTree){
        for(var i=0;i<pluses.length;i++){
            hideItem(pluses);
        }
    }
    else{
        for(var i=0;i<pluses.length;i++){
            showItem(pluses);
        }
    }
    expandedTree=!expandedTree;
}

/* Checks The Top Url. */
function checkTopUrl(){
    if(parent.mLoaded&&parent.tLoaded){
        if(parent.xLoaded) return;
        
        var str            = parent.location.href;
        var displayIndex    = str.indexOf("action=display");
        
        if(displayIndex!= -1) {            
            var args        = new Array();
            var as            = str.substr(displayIndex+15).split("&");
            
            for(var i=0;i<as.length;i++) {                
                var tmp            = as.split("=");
                if(tmp.length!=2)return;args[tmp[0]]=tmp[1];
            }
            
            var id            = args"id";
            var group        = args"group";
            
            if(group!=null){
                if(document.body.group!=group) {
                    parent.oeBar.loadTree(group);
                    parent.oeBar.setTimeout("selectRightItem()",100);
                }
                else {
                    var loc        = str.substring(0,displayIndex)+"action=preview&group="+group+"&id="+id;loc=loc.replace(/\/\?action/g,"/"+cgiFile+"?action");
                    var cm        = findNode(document.all.messageTree.tree,loc);
                    
                    if(cm==null) return;
                    
                    parent.toolframe.toggle(parent.toolframe.document.all.toggleExpandCollapseButton);
                    parent.toolframe.makePressed(parent.toolframe.document.all.toggleExpandCollapseButton);
                    expandCollapse();
                    cm.html.children.tags("A")[0].click();
                    parent.setXLoaded();
                }
            }
        }
    }
    else    window.setTimeout("checkTopUrl()",100);
}

/* Create The Tree Object. */
function Tree(parent){
    this.parent        = parent;
    this.children        = new Array();
    this.nextSibbling    = int_nextSibbling;
    this.add        = int_add;
    this.href        = new String();
    this.html        = null;
    this.index        = 0;
    
    var length        = 0;
    
    function int_add(t){
        this.children[length]=t;
        this.children[length].parent=this;
        this.children[length].index=length++;
    }
    
    function int_nextSibbling(){
        if(this.parent!=null) return this.parent.children[this.index+1];
    }
}

/* Builds A New Tree Object. */
function buildTree(el){
    var is            = new Array();
    var ic            = 0;
    var cs            = el.children;
    var csl            = cs.length;

    for(var i=0;i<csl;i++){
        if(cs.className=="item"){
            is[ic++]=cs;
        }
    }
    
    var nTree        = new Tree();
    
    for(var j=0;j<ic;j++){
        nTree.add(buildTree(is[j]));
        nTree.children[j].href=is[j].all.tags("A")[0].href;
        nTree.children[j].html=is[j];
    }
    
    return nTree;
}

/* Hide a specific Item. */
function hideItem(plusEl){
    var el            = plusEl.parentElement.parentElement;
    var children        = el.children;
    var childrenLength    = children.length;
    
    for(var i=0;i<childrenLength;i++){
        var child        = children.item(i);
        
        if(child.className=="item"){
            child.style.display="none";
            plusEl.innerHTML=plusString;
        }
    }
}


/* Show a specific Item. */
function showItem(plusEl){
    var el            = plusEl.parentElement.parentElement;
    var children        = el.children;
    var childrenLength    = children.length;
    
    for(var i=0;i<childrenLength;i++){
        var child        = children.item(i);
        
        if(child.className=="item"){
            child.style.display="block";
            //expandcontent(child.id)
            plusEl.innerHTML=minusString;
        }
    }
}



function expandcontent(cid)
{
    if (typeof ccollect!="undefined"){
    if (collapseprevious=="yes")
    contractcontent(cid)
    document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
    }
}


/* Fills each Item with children with the number of children in parenthesis inside of the subject line. */
function numberOfChildItems(){
    var itemDivs        = new Array();
    var index        = 0;
    var divs        = document.all.tags("div");
    var divsLength        = divs.length;
    
    for(var i=0;i<divsLength;i++){
        if(divs.className=="item") itemDivs[index++]=divs;
    }
    
    var itemsLength        = itemDivs.length;

    for(i=0;i<itemsLength;i++){
        var itemChildren    = getChildren(itemDivs);
        var atag        = itemDivs.children.tags("a")[0]
        
        for(x=0;x<atag.children.length;x++) {
            if(atag.children[x].className=="subject") {
                var subjectSpan        = atag.children[x];
                
                if(itemChildren>0&&showNumberOfReplys) {
                    subjectSpan.innerHTML+=replysStartTag+itemChildren+replysEndTag;
                }
            }
        }
    }
}

/* Return The Number Of Children The Specified Element Has. */
function getChildren(el){
    var l        = el.children.tags("DIV").length;
    
    if(l==0) return 0;
    else{
        var ec        = el.children.tags("DIV");
        var ecl        = ec.length;
        
        for(var i=0;i<ecl;i++) {
            l+=getChildren(ec);
        }
        return l;
    }
}

/* Indents Any Expanded Children Item. */
function fixSubPadding(depth) {
    var str2    = null;
    var val        = null;
    var width    = null;
    
    for(var i=0;i<depth;i++){
        str2="";
        val=0;
    
        for(var j=0;j<i;j++){
            str2+=".item "
            val+=18;
        }
        
        document.styleSheets[0].addRule(str2+".subject","width: "+(width)+"; padding-left: "+val+";");
    }
}


/**
 * Go through the xml of the document and find any nodes with the discovered tagname
 * Then select and programatically expand each of the discovered items in the html.
 */
function ExpandSearchResults() {
    if(parent.mainframe && document == parent.mainframe.document && document.XMLDocument && document.XMLDocument.documentElement) {
        var xmlString         = document.XMLDocument.documentElement.xml;
        var xmlData         = new ActiveXObject("MSXML2.DOMDocument");
        
        xmlData.async  = false;
        xmlData.loadXML(xmlString);
        
        var nList         = xmlData.selectNodes("//discovered");
        
        if(nList.length > 0) {
            var nc             = 0;
            while(nc!=nList.length) {
                if(nList[nc].getAttribute("taskid")) ExpandTreeItem(nList[nc].getAttribute("taskid"));
                nc++;
            }
        }
        //window.status = "Found " + nList.length + " tasks.";
    }
}


/**
 * Expands an indivisual tree item according to its ID.
 */
var pnArray    =    new Array();
function ExpandTreeItem(TaskID) {
    var nl             = document.getElementsByTagName("div");

    for(var i =0;i<nl.length;i++) {
        if(nl.getAttribute("id") == "tid" + TaskID) {
            var myNodes        = null;
            var d             = 1;
            var pNode         = nl;
            
            //nl.style.backgroundColor ="#FFFFF0";
            subItem = nl.childNodes;
//            subItem[1].style.backgroundColor="#FFFFF0";
            
            while(d!=0) {
                if(pNode.parentNode && pNode.parentNode.getAttribute("id")) {
                    pNode = pNode.parentNode;
                    if(pNode.getAttribute("id") && pNode.getAttribute("id").search("tid")!=-1) {
                        myNodes = pNode.childNodes;
                        if(!inside(pNode.getAttribute("id")))  {
                            myNodes[0].click();                    
                        }
                    }
                }
                else {
                    d = 0;
                }
            }
        }
    }
    
    function inside(tid) {
        for(var i=0;i<pnArray.length; i++) {
            if(pnArray == tid) return true;
        }
        pnArray.push(tid);
        return false;
    }
}


/* Displays the details of the Task inside of the messageFrame window. */
function ShowDetails(TaskID) {

    var XMLsubmit         = "<request><taskid>" + objSelectedItem.getTaskID() + "</taskid></request>";
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("POST", "GetTaskDetails.aspx", false);
    XMLpost.send(XMLsubmit);
    
    var XMLresponse     = XMLpost.ResponseXML;

    XMLresponse.async     = false;

    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//message");
        var message         = responseNode.text;
    }
    catch (e)
    {
        alert("The application could not retrieve the Message Details from the server.")
        return
    }

    if(message == "OK"){
        try
        {
            var selectedNode = XMLresponse.selectSingleNode("//task");
            var xsltSheet         = new ActiveXObject("MSXML2.DOMDocument");
            xsltSheet.async = false
            xsltSheet.load("XSL/TaskDetails.xsl");
            if(parent.messageframe) {
                var strHTML         = selectedNode.transformNode(xsltSheet);
                var targetDoc        = parent.messageframe.document
                
                targetDoc.all.taskDetail.innerHTML = strHTML
                
                window.event.cancelBubble = true;
            }
        }
        catch(e) {}
    }
    else {
        alert(message);
        }

/* Web Service Client Code Prototype
    Resulted in < , > characters replacing all < , > characters in content within the <string></string> node.
    
    if(TaskID == null) return
    
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("GET", "GetTaskDetails.asmx/GetTaskDetails?TaskID=" + TaskID, false);
    XMLpost.send();
    
    var XMLresponse     = XMLpost.ResponseXML;
    XMLresponse.async     = false;
    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//string");
alert(responseNode.xml)
        var message             = responseNode.selectSingleNode("//task");

    }
    catch (e)
    {
        alert(e)
        //alert("STACS could not retrieve the Task Details from the STACS server.")
        return
    }

    if(message == "OK"){
        var selectedNode = XMLresponse.selectSingleNode("//task");
        var xsltSheet         = new ActiveXObject("MSXML2.DOMDocument");
        xsltSheet.async = false
        xsltSheet.load("XSL/TaskDetails.xsl");
        if(parent.messageframe) {
            var strHTML         = selectedNode.transformNode(xsltSheet);
            var targetDoc        = parent.messageframe.document
            
            targetDoc.all.taskDetail.innerHTML = strHTML
            
            window.event.cancelBubble = true;
        }
    
    }
    else {
        alert(message);
        }

    */    
    
}

/* Default Values Used For Sorting And Filtering */
    var strOrder         = "ascending";
    var strField         = "@taskid";
    var strDataType        = "number";
    var strAttr         = "";
    var strValue         = "";

// Sort tasks according to the specified field
function SortTasks(sSortField)    {
    if(parent.mainframe && document == parent.mainframe.document && document.XMLDocument) {

        var xmlString         = document.XMLDocument.documentElement.xml;
        var xmlData         = new ActiveXObject("MSXML2.DOMDocument");
        
        xmlData.async  = false;
        xmlData.loadXML(xmlString);
        
        var xsltSheet         = new ActiveXObject("MSXML2.DOMDocument");
        
        xsltSheet.async = false;
        
        if (strOrder == "ascending") strOrder = "descending";
        else strOrder = "ascending";
        
        switch(sSortField) {
            case "DateCreated":
                strField = "@dateissued";
                strDataType = "number";
                break;
                
            case "Subject":  
                strField = "@subject";
                strDataType = "text";
                break;
                
            case "Status":  
                strField = "@status";
                strDataType = "text";
                break;
                
            case "Attachment":
                strField = "@attachment";
                strDataType = "number";
                break;
                
            case "TaskID":
                strField = "@taskid";
                strDataType = "number";
                break;
                
            case "SourceOffice":
                strField = "@sourceoffice";
                strDataType = "text";
                break;
                
            case "From":  
                strField = "@originator";
                strDataType = "text";
                break;
                
            case "Lead" :  
                strField = "@lead";
                strDataType = "text";
                break;
                
            case "DueDate" :
                strField = "@datedue";
                strDataType = "number";
                break;
                
            case "Support" :  
                strField = "@support";
                strDataType = "text";
                break;
                
            case "Location" :
                strField = "@location";
                strDataType = "text";
                break;
                
            default :  
                strField = "@taskid";
                strDataType = "number";
        }
        
        var strXSLFile        = "XSL/TaskViewSort.asp?field=" + strField + "&dataType=" + strDataType + "&order=" + strOrder;
        
        if(strAttr) {
            var nList         = xmlData.selectNodes("/root/task[@" + strAttr + " = '" + strValue + "']");
            var nCount         = 0;
            
            function walkChild(myNode) {
                nCount = nCount + 1;
                
                if(myNode && myNode.childNodes && myNode.childNodes.length > 0) {
                    var myNodesChildren         = myNode.childNodes;
                    
                    for(var l = 0;l<myNodesChildren.length;l++) walkChild(myNodesChildren);
                }
            }
            
            for(var i=0;i<nList.length;i++) {
                walkChild(nList);
            }
            
            nTaskCount = nCount;
            strXSLFile = strXSLFile + "&FilterID=" + strAttr + "&FilterValue=" + strValue;
            
            if(nList.length > 0 && parent.mainframe) {    
                xsltSheet.load(strXSLFile);
                if(parent.menuframe) {
                     parent.menuframe.menuDenit();
                     //parent.menuframe.LoadInit();
                }

                var strHTML         = xmlData.transformNode(xsltSheet);
                var targetDoc         = document;
                
                targetDoc.all.messageTree.innerHTML = "";
                targetDoc.all.messageTree.innerHTML = strHTML;
                
                initMessageTreePrime();
            }
            else {
                var targetDoc         = document;
                
                targetDoc.all.messageTree.innerHTML = "";    
            }
        }
        else {
            xsltSheet.load(strXSLFile);
            var strHTML         = xmlData.transformNode(xsltSheet);    
            var targetDoc         = document;
            
            targetDoc.all.messageTree.innerHTML = "";
            targetDoc.all.messageTree.innerHTML = strHTML;

            initMessageTreePrime();
        }
    }
}


/* Refresh the calling page to TaskView.aspx and refresh with server side xml data. */
function ReloadTaskView() {
    //if(parent.menuframe) parent.menuframe.LoadInit();
    location.href="TaskView.aspx";
}

/* Show all tasks from the current the xml document. */
function RefreshTaskView() {
    if(parent.mainframe && parent.mainframe.document.XMLDocument && document == parent.mainframe.document) {
        if(parent.menuframe) {
             parent.menuframe.menuDenit();
             //parent.menuframe.LoadInit();
        }

        var xmlString         = document.XMLDocument.documentElement.xml;
        var xmlData         = new ActiveXObject("MSXML2.DOMDocument");
        
        xmlData.async  = false;
        xmlData.loadXML(xmlString);
        
        var xsltSheet         = new ActiveXObject("MSXML2.DOMDocument");
        var strXSLFile         = "XSL/TaskViewRefresh.xsl";
        
        xsltSheet.async = false;        
        xsltSheet.load(strXSLFile);
        
        var strHTML         = xmlData.transformNode(xsltSheet);
        var targetDoc         = document;
        
        targetDoc.all.messageTree.innerHTML = "";
        targetDoc.all.messageTree.innerHTML = strHTML;
        strAttr = null;
        strValue = null;
        nTaskCount = null;
        
        initMessageTreePrime();
        
        window.status = "Now showing all tasks.";
    }
}



var searchWin     = null;
var sw            = 0;
/*Open a new search window. */
function startSearch()  {
    if(parent.menuframe) parent.menuframe.startSearch();
}

/*
  Object used to interact with items in the tree view
  ex:
    // This code should be set in an item onClick event function
    // objSelectedItem should be a global buffer object to hold the information of the current or last task clicked.
    objSelectedItem = new objItem();
    // sTaskId & sTaskType are passed to this function.
    objSelectedItem.setTaskID(sTaskID);
    objSelectedItme.setTaskType(sTaskType); // sTaskType should be linked to a global constant such as CONSTANT
*/

function initializeObjItem(el) {
    // This code is used in the item onClick event function to identify which is the currently selected row on the screen
    // objSelectedItem should be a global buffer object to hold the information of the current or last task clicked.
    // sTaskType should be linked to a global constant such as CONSTANT    
    objSelectedItem = new objItem();

    if(el.getAttribute("taskid")){
        objSelectedItem.setTaskID(el.getAttribute("taskid"));    
        objSelectedItem.setTaskType(el.getAttribute("tasktype"));
        objSelectedItem.setParentTaskID(el.getAttribute("parenttaskid"));
        objSelectedItem.setStatus(el.getAttribute("statusdisplay"));        
        objSelectedItem.setOriginator(el.getAttribute("isoriginator"));        
        objSelectedItem.setLead(el.getAttribute("islead"));        
        objSelectedItem.setRouteType(el.getAttribute("routetype"));                    
        objSelectedItem.setIsCurrentSection(el.getAttribute("iscurrentsection"));

        if(sPageType=="TaskViewMain") ShowDetails(el.getAttribute("taskid"), el.getAttribute("tasktype"));
    }
}

function objItem() {
    var sItemTaskID            = null;
    var sItemTaskType        = null;
    var sItemParentTaskID        = null;
    var sItemStatus            = null;
    var sItemOriginator        = null;
    var sItemLead            = null;    
    var sRouteType            = null;
    var sIsCurrentSection        = null;

    this.setTaskID = setTaskIDFunc;
    this.setTaskType = setTaskTypeFunc;
    this.setParentTaskID = setParentTaskID;
    this.setStatus = setStatusFunc;
    this.setOriginator = setOriginatorFunc;
    this.setLead = setLeadFunc;
    this.setRouteType = setRouteTypeFunc;
    this.setIsCurrentSection = setIsCurrentSectionFunc;    
    this.getTaskID = getTaskID;
    this.getTaskType = getTaskType;
    this.getParentTaskID = getParentTaskID;
    this.getStatus = getStatus;
    this.getOriginator = getOriginator;    
    this.getLead = getLead;    
    this.getRouteType = getRouteType;
    this.getIsCurrentSection = getIsCurrentSection;

    function setTaskIDFunc (sTaskID) {
        this.sItemTaskID = sTaskID;    
    }

    function setTaskTypeFunc ( sTaskType ) {
        this.sItemTaskType = sTaskType;
    }
    
    function setParentTaskID ( sParentTaskID ) {
        this.sItemParentTaskID = sParentTaskID;
    }

    function setStatusFunc (sStatus) {
        this.sItemStatus = sStatus;    
    }

    function setOriginatorFunc (sOriginator) {
        this.sItemOriginator = sOriginator;    
    }

    function setLeadFunc (sLead) {
        this.sItemLead = sLead;    
    }

    function setRouteTypeFunc (sRouteType) {
        this.sRouteType = sRouteType;    
    }
    
    function setIsCurrentSectionFunc (sIsCurrentSection) {
        this.sIsCurrentSection = sIsCurrentSection;    
    }

    function getTaskID () {
        return this.sItemTaskID;
    }

    function getTaskType () {
        return this.sItemTaskType;
    }
    
    function getParentTaskID () {
        return this.sItemParentTaskID;
    }

    function getStatus () {
        return this.sItemStatus;
    }

    function getOriginator () {
        return this.sItemOriginator;
    }

    function getLead () {
        return this.sItemLead;
    }

    function getRouteType () {
        return this.sRouteType;
    }

    function getIsCurrentSection () {
        return this.sIsCurrentSection;
    }

}

/* View Either A Comment Or A Task. */
function viewEntry() {
    if(objSelectedItem!=null) {
        if(objSelectedItem.getTaskType()=="2" || objSelectedItem.getTaskType()=="3") viewComment();
        else viewTask();
    }
    else alert("Please select a message to view");
}

/* View a particular task. */
function viewTask () {
    if(objSelectedItem!=null) {
        
        viewTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=ViewTask&xsl=ViewTask&TaskID=" + objSelectedItem.getTaskID(), 'ViewTask');
        viewTaskWin.focus();
    }
}
function createPackage() {

    newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=newpackage&xsl=newpackage", 'NewPackage');
    newTaskWin.focus();    
}

function createCoordination() {

    newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=newcoord&xsl=newcoordination", 'NewCoordination');
    newTaskWin.focus();    
}

/* Open A New Window To Create A Task */
function createTask () {

    newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=newtask&xsl=newtask", 'NewTask');
    newTaskWin.focus();
}

/* Open A New Window To Create A Comment. */
function newComment() {
    if(objSelectedItem==null || !objSelectedItem){
        alert("Please select a message to comment on.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("This task has been recalled and no further work can be done on it until it is re-issued.");
        return;
    }

        var h            = 500;
        var w            = 855;
        var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

        commentWin = window.open('Comment.aspx?Mode=CommentTask&TaskID='+objSelectedItem.getTaskID()+'&TaskType=2&ParentTaskID='+objSelectedItem.getTaskID(), 'NewComment', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
        commentWin.focus();
}

/* Open A New Window To View A Comment. */
function viewComment() {
    if(objSelectedItem!=null){
        var h            = 500;
        var w            = 855;
        var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
        
        commentWin = window.open('Comment.aspx?mode=ViewComment&TaskID='+objSelectedItem.getTaskID(), 'ViewComment', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);            
        commentWin.focus();
    }
}


/* Open A New Window To Edit A User. */
function EditUser() {
    var h            = 475;
    var w            = 650;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

    userWin = window.open('UserSectionMain.aspx?mode=EditUser', 'EditUser', config='height='+h+',width='+w+',scrollbars=no,resizable=yes,status=no,top='+TopPosition+',left='+LeftPosition);            
    userWin.focus();
}

/* Open A New Window To Amend A Task. */
function amendTask() {
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a message to amend.");
        return;                
        }

    if(objSelectedItem.getTaskType()!=1){
        alert("Only Tasks can be amended.");
        return;
        }
    
    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed messages cannot be amended.");
        return;
        }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed messages cannot be amended.");
        return;
        }
    
    if(objSelectedItem.getOriginator()!="2"){
        alert("Only the Originating Section can amend a message.");
        return;
        }

    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("To amend a recalled message use the reissue command.");
        return;
    }
    
    var sMode = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "amendtask";
            break;
        }                
            
    if(!commentWin || commentWin.closed) {
        var h            = 500;
        var w            = 855;
        var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
        
        commentWin = window.open('Comment.aspx?mode=' + sMode + '&TaskID='+objSelectedItem.getTaskID()+'&TaskType=3&ParentTaskID='+objSelectedItem.getTaskID(), 'AmendTask', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
        commentWin.focus();
    }
}

function encodeChars(strTemp) {
    strTemp = strTemp.replace(/&/g,"&");
//    strTemp = strTemp.replace("<", "<");
//    strTemp = strTemp.replace(">", ">");
//    strTemp = strTemp.replace("'", "'");
//    strTemp = strTemp.replace("\"", """);
    return strTemp;
}

/* Open A Window To Close A Task. */
function closeTask (){
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a message to close.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4 && objSelectedItem.getTaskType()!=5){
        alert("Please select a message to close.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("This message is already closed.");
        return;
    }
    
    if(objSelectedItem.getOriginator()!="2"){
        alert("Only the Originating Section can close a message.");
        return;
    }
    
    var confirmClose = confirm("Are you sure you want to close this message?")
    if(!confirmClose) {
        return;
    }

    execScript("confirmNotify = MsgBox('Do you want to Notify sections that the message has been closed?', 4, 'Close Message')", "vbscript")

    if(confirmNotify==6) {
        confirmNotify = "true"
    }
    else {
        confirmNotify = "false"
    }
    
    var sMode = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "closetask";
            break;
        case "4":
            sMode = "closepackage";
            break;
        case "5":
            sMode = "closecoord";
            break;
        }                
    
    /* subject is encoded for XSLT */
    var XMLsubmit         = "<request> <taskid>" + objSelectedItem.getTaskID() + "</taskid> <mode>" + sMode + "</mode> <routetype>" + objSelectedItem.getRouteType() + "</routetype><subject>" + encodeChars(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "subject")) + "</subject><notify>" + confirmNotify + "</notify></request>";
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("POST", "UpdateTaskStatus.aspx", false);
    XMLpost.send(XMLsubmit);
    
    var XMLresponse     = XMLpost.ResponseXML;

    XMLresponse.async     = false;

    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//message");
        var message         = responseNode.text;
    }
    catch (e)
    {
        alert("The application could not close the task.")
        return
    }

            
    if(message != "OK"){
        alert("Error closing message: " + message);
        return;
    }
    else {
        alert("Message " + objSelectedItem.getTaskID() + " Closed.");
    }
    

    if(sPageType=="TaskViewMain") {

        NavigatePage("");
    }
    else {
            parent.opener.parent.location.reload(false);
            parent.window.close();
        }
}

/* Open A Window To Return A Task. */
function returnTask() {
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a message to return.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4){
        alert("Only Tasks and Staff Packages can be Returned/Rejected.");
        return;
    }

    if(objSelectedItem.getTaskType()==1 && objSelectedItem.getRouteType()=="2"){
        alert("Only Parallel Routed tasks can be returned.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed messages cannot be returned.");
        return;
    }
    
    if(objSelectedItem.getTaskType()==1 && objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("The message has already been Returned.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("Recalled messages cannot be returned.");
        return;
    }

    if(objSelectedItem.getTaskType()==1 && objSelectedItem.getLead()!="2"){
        alert("Only the Lead Section can return a task.");
        return;
    }
    
    if(objSelectedItem.getTaskType()==4 && objSelectedItem.getIsCurrentSection()!="2"){
        alert("A staff package can only be rejected by the current approver.");
        return;
    }

    var sMode = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "returntask";
            break;
        case "4":
            sMode = "rejectpackage";
            break;
        }                
            
    if(!commentWin || commentWin.closed) {
        var h            = 500;
        var w            = 855;
        var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
        
        commentWin = window.open('Comment.aspx?mode=' + sMode + '&TaskID='+objSelectedItem.getTaskID()+'&TaskType=2&ParentTaskID='+objSelectedItem.getTaskID(), 'ReturnTask', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
        commentWin.focus();
    }
}


/* Open A New Window To Route A Task. */
function routeTask() {
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a message to route.");
        return;                
    }
    
    if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4){
        alert("Only Tasks and Staff Packages can be Routed.");
        return;
    }

    if(objSelectedItem.getTaskType()==1 && objSelectedItem.getRouteType()=="1"){
        alert("Only Serial Routed tasks can be routed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed messages cannot be routed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed messages cannot be routed.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("Recalled messages cannot be routed.");
        return;
    }
    
    if(objSelectedItem.getTaskType()==4){
        if( objSelectedItem.getIsCurrentSection()!="2"){
            alert("a staff package can only be routed by the current approver.");
            return;
        }
    
        if(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "packageapprover")==GetXMLSystemAttribute("usersectionid")){
            alert("The package cannot be forwarded by the final approving section.");
            return;
        }
    }
    
    var sMode = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "routetask";
            break;
        case "4":
            sMode = "forwardpackage";
            break;
        }                
    
    if(!commentWin || commentWin.closed) {
        var h            = 500;
        var w            = 855;
        var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
        var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
        
        commentWin = window.open('Comment.aspx?mode=' + sMode + '&TaskID='+objSelectedItem.getTaskID()+'&TaskType=2&ParentTaskID='+objSelectedItem.getTaskID(), 'RouteTask', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
        commentWin.focus();
    }
}


/* Function To Recall A Task. */
function recallTask (ValidateRequest) {
    confirmReissue = 0;

    if (ValidateRequest)
    {

        if (sPageType == "TaskViewComments")
        {
            initializeObjItem(parent.mainframe.document.all.taskAttributes);
        }

        if(objSelectedItem==null){
            alert("Please select a message to recall.");
            return;                
        }

        if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4 && objSelectedItem.getTaskType()!=5) {
            alert("Please select a message to recall.");
            return;
        }

        if(objSelectedItem.getStatus().toLowerCase()=="completed"){
            alert("Completed or Approved messages cannot be recalled.");
            return;
        }
        
        if(objSelectedItem.getStatus().toLowerCase()=="closed"){
            alert("Closed messages cannot be recalled.");
            return;
        }
        
        if(objSelectedItem.getStatus().toLowerCase()=="returned"){
            alert("Returned or Rejected messages cannot be recalled.");
            return;
        }

        if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
            alert("This message has already been recalled.");
            return;
        }
        
        if(objSelectedItem.getOriginator()!="2"){
            alert("Only the Originating Section can recall a message.");
            return;
        }
        
        var confirmClose     = confirm("Are you sure you want to recall this message?");
        
        if(!confirmClose) return;

        execScript("confirmReissue = MsgBox('Do you want to reissue the message after it is recalled?', 4, 'Recall Task')", "vbscript")
    }

    var sMode = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "recalltask";
            break;
        case "4":
            sMode = "recallpackage";
            break;
        case "5":
            sMode = "recallcoord";
            break;
        }                

    var XMLsubmit         = "<request> <taskid>" + objSelectedItem.getTaskID() + "</taskid> <mode>" + sMode + "</mode> <routetype>" + objSelectedItem.getRouteType() + "</routetype><subject>" + encodeChars(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "subject")) + "</subject><notify>false</notify></request>";
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("POST", "UpdateTaskStatus.aspx", false);
    XMLpost.send(XMLsubmit);

    var XMLresponse = XMLpost.ResponseXML;

    XMLresponse.async = false;
    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//message");
        var message         = responseNode.text;
    }
    catch (e)
    {
        alert(e)//("STACS could not recall the task.")
        return
    }

    if(message != "OK"){
        alert("Error Recalling Message: " + message);
        return;
    }
    else {
        alert("Message " + objSelectedItem.getTaskID() + " Recalled.");
    }
    

    if(confirmReissue == 6) {
        reissueTask(false);
    }

    if(ValidateRequest==true && confirmReissue!=6) {
        if(sPageType=="TaskViewMain") {

            NavigatePage("");
        }
        else {
                parent.opener.parent.location.reload(false);
                parent.window.close();
            }
    }

}

/* Function To Approve a package. */
function approvePackage () {

    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a package to approve.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=4) {
        alert("Please select a package to approve.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("This package has already been approved.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed packages cannot be approved.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("Rejected packages cannot be approved.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("Recalled packages cannot be approved.");
        return;
    }
    
    if(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "packageapprover")!=GetXMLSystemAttribute("usersectionid")){
        alert("Only the final approving section can approve a package.");
        return;
    }
    
    var confirmClose     = confirm("Are you sure you want to approve this package?");
    
    if(!confirmClose) return;

        
    var XMLsubmit         = "<request> <taskid>" + objSelectedItem.getTaskID() + "</taskid> <mode>approvepackage</mode> <routetype>" + objSelectedItem.getRouteType() + "</routetype><subject>" + encodeChars(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "subject")) + "</subject><notify>false</notify></request>";
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("POST", "UpdateTaskStatus.aspx", false);
    XMLpost.send(XMLsubmit);

    var XMLresponse = XMLpost.ResponseXML;

    XMLresponse.async = false;
    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//message");
        var message         = responseNode.text;
    }
    catch (e)
    {
        alert(e)//("STACS could not approve the task.")
        return
    }

    if(message != "OK"){
        alert("Error approving Package: " + message);
        return;
    }
    else {
        alert("Package " + objSelectedItem.getTaskID() + " Approved.");
    }
    

    if(sPageType=="TaskViewMain") {

        NavigatePage("");
    }
    else {
            parent.opener.parent.location.reload(false);
            parent.window.close();
        }
}


function answerPackage () {

    var xmlData = document.XMLDocument;
    var filterNode, filterValue, answerFunc, confirmMessage;

    filterNode = xmlData.selectSingleNode("/root/search");
    filterValue = filterNode.getAttribute("Filter");

    
    if (filterValue != "answered"){
    
        answerFunc = "answerpackage";
        confirmMessage = "to";
    }else{
    
        answerFunc = "unanswerpackage";
        confirmMessage = "from";
    }
    
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a package to mark answered.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=4){
        alert("Please select a package to mark answered.");
        return;
    }
    
    //if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        //alert("Completed tasks cannot be completed.");
        //return;
    //}
    
    if(objSelectedItem.sItemOriginator == "2"){
        alert("The issuing section cannot answer a package.\nYou must close it to remove it.");
        return;
    }
    
    var XMLsubmit         = "<request><taskid>" + objSelectedItem.getTaskID() + "</taskid><routetype>" + objSelectedItem.getRouteType() + "</routetype><subject>" + encodeChars(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "subject")) + "</subject><notify>false</notify><mode>" + answerFunc + "</mode></request>";
    var XMLpost         = new ActiveXObject("Microsoft.XMLHTTP");

    XMLpost.open("POST", "UpdateTaskStatus.aspx", false);
    XMLpost.send(XMLsubmit);

    var XMLresponse = XMLpost.ResponseXML;

    XMLresponse.async = false;
    try
    {
        var responseNode     = XMLresponse.selectSingleNode("//message");
        var message         = responseNode.text;
    }
    catch (e)
    {
        alert(e)
        return
    }

    if(message != "OK"){
        alert("Error answering package: " + message);
        return;
    }
    else {
        alert("Package " + objSelectedItem.sItemTaskID + " has been moved " + confirmMessage + " the answered list.");
    }
    

    if(sPageType=="TaskViewMain") {

        parent.location.reload(false);
    }
    else {
            parent.opener.parent.location.reload(false);
            parent.window.close();
        }
    


    /*
    if(objSelectedItem.getRouteType()=="2"){
        alert("Only Parallel Routed tasks can be completed.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed tasks cannot be completed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed tasks cannot be completed.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("Returned tasks cannot be completed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("Recalled tasks cannot be completed.");
        return;
    }


    
    var h            = 500;
    var w            = 855;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

    
    commentWin = window.open('Comment.aspx?mode=completeTask&TaskID='+objSelectedItem.getTaskID()+'&TaskType=2&ParentTaskID='+objSelectedItem.getTaskID(), 'CompleteTask', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
    commentWin.focus();
    */
}

/* ReIssue A Task. */
function reissueTask(ValidateRequest) {
    var confirmRecall = false

    if (ValidateRequest)
    {
        if (sPageType == "TaskViewComments")
        {
            initializeObjItem(parent.mainframe.document.all.taskAttributes);
        }

        if(objSelectedItem==null){
            alert("Please select a message to reissue.");
            return;                
        }
        
        if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4 && objSelectedItem.getTaskType()!=5){
            alert("Please select a message to reissue.");
            return;
        }
        
        if(objSelectedItem.getOriginator()!="2"){
            alert("Only the Originating Section can reissue a message.");
            return;
        }

        if(objSelectedItem.getStatus().toLowerCase()!="recalled" && objSelectedItem.getStatus().toLowerCase()!="returned" && objSelectedItem.getStatus().toLowerCase()!="closed"){
            var confirmRecall     = confirm("The selected message will be recalled and a new message will be issued. Do you want to continue?");
            if(confirmRecall==true){
                recallTask(false);
            }
            else {
                return
            }
        }
    }

    var sMode = ""
    var sXSL = ""
    
    switch(objSelectedItem.getTaskType()) {
        case "1":
            sMode = "reissuetask";
            sXSL = "newtask";
            break;
        case "4":
            sMode = "reissuepackage";
            sXSL = "newpackage";
            break;
        case "5":
            sMode = "reissuecoord";
            sXSL = "newcoordination";
            break;
        }                

    if(sPageType=="TaskViewMain") {
        newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=" + sMode + "&xsl=" + sXSL + "&TaskID=" + objSelectedItem.getTaskID(), 'ReissueTask');
        newTaskWin.focus();
    }
    else {
        parent.window.navigate("tasker.aspx?targetpage=taskform.aspx&mode=" + sMode + "&xsl=" + sXSL + "&TaskID=" + objSelectedItem.getTaskID())

    }
}

/* Mark A Task As Completed */
function completeTask() {
    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a task to complete.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=1){
        alert("Please select a task to complete.");
        return;
    }

    if(objSelectedItem.getRouteType()=="2"){
        alert("Only Parallel Routed tasks can be completed.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed tasks cannot be completed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed tasks cannot be completed.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("Returned tasks cannot be completed.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="recalled"){
        alert("Recalled tasks cannot be completed.");
        return;
    }

    if(objSelectedItem.getLead()!="2"){
        alert("Only the Lead Section can complete a task.");
        return;
    }
    
    var h            = 500;
    var w            = 855;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

    
    commentWin = window.open('Comment.aspx?mode=completeTask&TaskID='+objSelectedItem.getTaskID()+'&TaskType=2&ParentTaskID='+objSelectedItem.getTaskID(), 'CompleteTask', config='height='+h+',width='+w+',scrollbars=no,status=no,top='+TopPosition+',left='+LeftPosition);
    commentWin.focus();
}


/* Create new task as a copy of this task with this task as the parent */
function subTask() {

    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a task to sub-task from.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=1 && objSelectedItem.getTaskType()!=4 && objSelectedItem.getTaskType()!=5){
        alert("Only tasks, coordinations and staff packages can be sub-tasked");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Completed messages cannot be sub-tasked.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed messages cannot be sub-tasked.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("Returned/Recalled messages cannot be sub-tasked.");
        return;
    }
    
    if(objSelectedItem.getOriginator()=="2"){
        alert("The Originating Section cannot sub-task a message.");
        return;
    }
    
    var h            = 350;
    var w            = 550;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
    
    newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=subtask&xsl=newtask&TaskID=" + objSelectedItem.getTaskID(), 'SubTask');
    newTaskWin.focus();

}

/* Convert a task to a staff package */
function convertToTask() {

    if (sPageType == "TaskViewComments")
    {
        initializeObjItem(parent.mainframe.document.all.taskAttributes);
    }

    if(objSelectedItem==null){
        alert("Please select a package to convert.");
        return;                
    }

    if(objSelectedItem.getTaskType()!=4){
        alert("Only staff packages can be converted into tasks.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="completed"){
        alert("Approved packages cannot be converted.");
        return;
    }
    
    if(objSelectedItem.getStatus().toLowerCase()=="closed"){
        alert("Closed packages cannot be converted.");
        return;
    }

    if(objSelectedItem.getStatus().toLowerCase()=="returned"){
        alert("Returned/Recalled packages cannot be converted.");
        return;
    }
    
    if(objSelectedItem.getOriginator()=="2"){
        alert("The Originating Section cannot convert a package.");
        return;
    }

    if( objSelectedItem.getIsCurrentSection()!="2"){
        alert("a staff package can only be converted by the current approver.");
        return;
    }
    /* Commented out per NORTHCOM request 6-5-03
    if(GetXMLTaskAttribute(objSelectedItem.getTaskID(), "packageapprover")==GetXMLSystemAttribute("usersectionid")){
        alert("The package cannot be converted by the final approving section.");
        return;
    }
    */
    var h            = 350;
    var w            = 550;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;
    
    newTaskWin = window.open("tasker.aspx?targetpage=taskform.aspx&mode=converttotask&xsl=newtask&TaskID=" + objSelectedItem.getTaskID(), 'SubTask');
    newTaskWin.focus();

}
function HelpAbout() {
    var h            = 300;
    var w            = 300;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

    window.open('MsgHandler.aspx?Mode=information&Msg=Tasking Management System v. 2.0', 'HelpAbout', config='height='+h+',width='+w+',resizable=no,top='+TopPosition+',left='+LeftPosition);
}

function ShowPreferences() {

    var h            = 200;
    var w            = 400;
    var LeftPosition     = (screen.width) ? (screen.width-w)/2 : 0;
    var TopPosition     = (screen.height) ? (screen.height-h)/2 : 0;

    window.open('Preferences.aspx', 'winPref', config='height='+h+',width='+w+',resizable=no,top='+TopPosition+',left='+LeftPosition);

}

function OutlookExport(ExportType, ExportTaskID) {
    //window.event.cancelBubble = true;

    if(objSelectedItem==null && ExportTaskID == ""){
        alert("Please select a task to export to Outlook");
        return;                
    }

    if(objSelectedItem.getTaskType()!=1){
        alert("Please select a task to export to Outlook");
        return;
    }

    if (ExportTaskID == "")
    {
        ExportTaskID = objSelectedItem.getTaskID()
    }
    
    var strSubject = GetXMLTaskAttribute(ExportTaskID, "subject")
    var strStartDate = GetXMLTaskAttribute(ExportTaskID, "dateissued")
    var strEndDate = GetXMLTaskAttribute(ExportTaskID, "datedue")
    var strLink = GetXMLSystemAttribute("linkURL") + ExportTaskID
    var strSection = GetXMLSystemAttribute("usersectionname")
    var strOriginator = GetXMLTaskAttribute(ExportTaskID, "originator")
    var strLead = GetXMLTaskAttribute(ExportTaskID, "lead")
    var strRole = ""

    if(strOriginator.indexOf(strSection) > -1) {
        strRole = "Originator"
    }
    else {
        if(strLead.indexOf(strSection) > -1) {
            strRole = "Lead"
        }
        else {
            strRole = "Support"
        }
    }
    
    var strRouteType = GetXMLTaskAttribute(ExportTaskID, "routetype")
        if (strRouteType == "1")
        {
            strRouteType = "Parallel"
        }
        else
        {
            strRouteType = "Serial"    
        }

    var strCategories = strRole + ", " + strRouteType

    if(ExportType =="cal") {

        ExportToCalendar(strSubject, strStartDate, strEndDate, strLink, strCategories, true)

    }
    
    if(ExportType =="task") {

        ExportToTasks(strSubject, strStartDate, strEndDate, strLink, strCategories, true)

    }

}

function GetXMLTaskAttribute(TaskID, AttributeName) {
    // **** Build my xpath to identify the current node in xml
    var Xpath        = "//task[@taskid = '" + TaskID + "']";
    var selectedNode     = window.document.XMLDocument.selectSingleNode (Xpath);
    var AttributeValue     = selectedNode.getAttribute(AttributeName)
    

    return AttributeValue
}

function GetXMLSystemAttribute(AttributeName) {
    // **** Build my xpath to identify the current node in xml
    var Xpath        = "//system";
    var selectedNode     = window.document.XMLDocument.selectSingleNode (Xpath);
    var AttributeValue     = selectedNode.getAttribute(AttributeName)
    

    return AttributeValue
}

function NavigatePage(TargetPage) {
    //alert(SearchQueryString())

    if (TargetPage=="")
    {
        var Xpath        = "//pages";
        var selectedNode     = window.document.XMLDocument.selectSingleNode (Xpath);
        TargetPage = selectedNode.getAttribute("current")
    }

    parent.window.navigate("Main.aspx?TargetPage=TaskView.aspx&Page=" + TargetPage + SearchQueryString())

}


function FilterTasks(FilterType) {

    if (FilterType=="")
    {
        parent.window.navigate("Main.aspx?TargetPage=TaskView.aspx")

    }
    else {
    parent.window.navigate("Main.aspx?TargetPage=TaskView.aspx&Filter=" + FilterType)
    }
}

function SearchQueryString() {
    var Xpath        = "//search";
    var selectedNode     = window.document.XMLDocument.selectSingleNode (Xpath);

    var strQS = "&ddSearchFields=" + selectedNode.getAttribute("ddSearchFields") + "&"
    strQS += "Filter=" + selectedNode.getAttribute("Filter") + "&"
    strQS += "txtSearchString=" + selectedNode.getAttribute("txtSearchString") + "&"
    strQS += "txtDateCreatedFrom=" + selectedNode.getAttribute("txtDateCreatedFrom") + "&"
    strQS += "txtDateCreatedTo=" + selectedNode.getAttribute("txtDateCreatedTo") + "&"
    strQS += "txtDateDueTo=" + selectedNode.getAttribute("txtDateDueTo") + "&"
    strQS += "txtAuthor=" + selectedNode.getAttribute("txtAuthor") + "&"
    strQS += "txtSubject="+ selectedNode.getAttribute("txtSubject") + "&"
    strQS += "txtRemarks=" + selectedNode.getAttribute("txtRemarks") + "&"
    strQS += "txtFromSection=" + selectedNode.getAttribute("txtFromSection") + "&"
    strQS += "txtAssignedToSection=" + selectedNode.getAttribute("txtAssignedToSection") + "&"
    strQS += "txtTaskID=" + selectedNode.getAttribute("txtTaskID") + "&"
    strQS += "txtLegacyTaskID=" + selectedNode.getAttribute("txtLegacyTaskID") + "&"
    strQS += "txtAttachmentName=" + selectedNode.getAttribute("txtAttachmentName") + "&"
    strQS += "searchType=" + selectedNode.getAttribute("searchType") + "&"
    strQS += "cbSearchedClosed=" + selectedNode.getAttribute("cbSearchedClosed")     
    return strQS
    
    }

RE: cookies and treeview

(OP)
I have taken you code and implemented it instead of the other example.  I believe I am closer, but I am having difficulty because the source code uses XML instead of html.  Do you have the same example using XML?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close