﻿var pubsSelectedRow;

//////////////////////////////
///   loadTable
//////////////////////////////
function loadTable(cabID, displayName) {      
    getPubsTableDocuments(cabID);    
}

////////////////////////////////////////////////
///  selectRow(RowID, Clear)
////////////////////////////////////////////////
function pubsSelectRow(tr) {	
	pubsClearSelections();
	
	for(var i = 0; i < 4; i++) {
	    tr.cells[i].className = "pubs_cell_selected";
	}
	pubsSelectedRow = tr;
}

////////////////////////////////////////////////
///  rowClick(tr) 
////////////////////////////////////////////////
function pubsRowClick(tr) {
	if(!tr) return;		
	pubsSelectRow(tr);	
}
	
////////////////////////////////////////////////
///  clearSelections()
////////////////////////////////////////////////
function pubsClearSelections() {	
    if(pubsSelectedRow) {
        for(var i = 0; i < 4; i++) {
	        pubsSelectedRow.cells[i].className = "pubs_cell";
	    }
        pubsSelectedRow = null;
    }
}

////////////////////////////////////////////////
///  pubsOpenDocument
////////////////////////////////////////////////	
function pubsOpenDocument(tr) {
    var sID = tr.id;
    sID = sID.replace("O","");
    
    openDocument(sID);
}

////////////////////////////////////////////////
///  getPubsTableDocuments(CabinetID)
////////////////////////////////////////////////	
function getPubsTableDocuments(cabID) {
    ajax.open("POST", getAjaxUrl(), true);
            
    ajax.onreadystatechange = function() {						
		if(ajax.readyState == 4 && ajax.status == 200) {	
		    // Create the XML Document from response text 
		    var xDoc = new ActiveXObject("Microsoft.XMLDOM");
		    		    		    		    		    
		    xDoc.async = "false";		    		    
		    xDoc.loadXML(ajax.responseText);
		    
			getPubsTableDocumentsCallback(xDoc);
		}
	}
	
	ajax.send("SessionID=" + m_nSessionID + "&Action=GetTableDocList&CabinetID=" + cabID);
}

////////////////////////////////////////////////
///  getPubsTableDocumentsCallback(xDoc)
////////////////////////////////////////////////	
function getPubsTableDocumentsCallback(xDoc) {
    if(checkError(xDoc)) { 
        clearWaitCursor();            
        return;
    }

    var lst = xDoc.selectNodes("//pubsDoc");    
    var tbl = document.getElementById("omsTable");
    
    for(var i = 0; i < lst.length; i++) {
        var tr = tbl.insertRow();
        tr.id = "O" + getNodeValue(lst[i], "@id", "0");
        tr.className = "pubs_cell";
	    tr.onclick = new Function("evt", "pubsRowClick(this);"); 
	    tr.ondblclick = new Function("evt", "pubsOpenDocument(this);");
	    tr.onselectstart = new Function("evt", "return true");
	    tr.oncontextmenu = new Function("evt", "return displayDocumentContext(this);");
		
	    // Drawer Cell 
	    var td = tr.insertCell();	
	    td.className = "pubs_cell";    	    
	    td.innerText = getNodeValue(lst[i],"drwName", "&nbsp;");
		
        // Folder Cell 
	    var td = tr.insertCell();	    	    
	    td.className = "pubs_cell";
	    td.innerText = getNodeValue(lst[i],"fldName", "&nbsp;");
	    
	    // Document Name Cell 
	    var td = tr.insertCell();
	    td.className = "pubs_cell";	    
	    td.innerText = getNodeValue(lst[i],"docName", "&nbsp;");
	    
	    // Document Description Cell 
	    var td = tr.insertCell();
	    td.className = "pubs_cell";	    
	    td.innerText = getNodeValue(lst[i],"docDesc", "&nbsp;");    
    }
    
    hideRetry();
}
