/*
 * Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
Trees Navigator
*/

var openImg = new Image();
openImg.src = "extensions/core/images/tree_open.gif";
var closedImg = new Image();
closedImg.src = "extensions/core/images/tree_closed.gif";

var finallyUsedDiv;

function showTreeBranch(objMainDiv, objImg, txProtocolName) {
    if (objMainDiv == null && objImg == null && txProtocolName == null) {
        // this is used as the callback
        //custom transformation
        treeBranchTransformer(this.req.responseXML,"list_transport_info.xsl", finallyUsedDiv);

        return true;

    }
    // create new div obj

    swapFolder(objImg, objMainDiv, txProtocolName);
}

function swapFolder(objImg, objMainDiv, txProtocolName) {
    if (objImg.src.indexOf('tree_closed.gif') > -1) {
        objImg.src = openImg.src;
        var newObjDiv = document.createElement('div');
        finallyUsedDiv = newObjDiv;
        objMainDiv.appendChild(newObjDiv);
        getTransportDetails(txProtocolName);

    }
    else {
        objImg.src = closedImg.src;
        //removed the
        var genObjDiv = objMainDiv.getElementsByTagName('div')[0];
        objMainDiv.removeChild(genObjDiv);
    }
}

//Privately own method
function treeBranchTransformer(xmlObj,xsltFile, objDiv) {
//    alert('response  :  ' + xmlSerializerToString(data));
    wso2.wsf.Util.processXML(xmlObj, xsltFile, objDiv);
}

