//-----------------------------------------------------------------------------
// docMenu.js :: used by /kbase
// 2004.11.23 - written by rk7138 for SBC Internet Services
//-----------------------------------------------------------------------------
// -- assumes previewHTML.js is available
// -- assumes switchMenu.js is available
//-----------------------------------------------------------------------------
// getDocMenuHTML(docObj, strShowCheckBox)
//-----------------------------------------------------------------------------
// docObj is an array of objects as follows:
// { id:ID, title:String, keywords:Array of String, topics:Array of String, filename:String, filepath:path or ID}
//
// strShowCheckBox if not empty will create checkboxes which
// appears before each entry named per strShowCheckBox.
//
// bShowModify if true will make available a button that - when clicked - will
// allow either the document to edited, or keyword or topic to be re/assigned
//-----------------------------------------------------------------------------
function getDocMenuHTML(docObj, strShowCheckBox, bShowModify){
	var html = "";
	var instructions = "<div class='BlackSideText'>Description<br/><div class='DefaultGrayText' style='font-weight:normal;'>Documents represent knowledge base entries with one or more keywords, one or more associated topics and possibly an actual file.  If a document is associated with a file, and icon will appear next to the document entry.  Click upon a document link to manage or delete that document.  Click upon a link for a file in order to download it.</div></div><br/>"; 
	
	if(docObj == ''){ return $empty(); }
	
	html += instructions;
	html += "<div>\n";
	
	for (var i = 0; i < docObj.length; i++){
		itemCount ++;
		
		var elObj = docObj[i];		
		var id = elObj.id;
		var title = elObj.title;
		var keywords = elObj.keywords;
		var topics = elObj.topics;
		var filename = elObj.filename;
		var filepath = elObj.filepath;

		var nodeId = kbase_delete_doc + id;
		var nodeId_keywords = kbase_assign_keywords + id;
		var nodeId_topics = kbase_assign_topics + id;	
			
		var show_keywords = (keywords.length > 0) 
			? "keywords [ <a class='info' href='#'><b>" + keywords.length + "</b><span><b>KEYWORDS:</b>" + keywords + "</span></a> ]"
			: "keywords: <i>none</i>";
		
		var show_topics = (topics.length > 0)
			? "topics [ <a class='info' href='#'><b>" + topics.length + "</b><span><b>TOPICS:</b>" + topics + "</span></a> ]"
			: "topics: <i>none</i>";	
		
		var show_file = kbase_download + filepath;		

		var foldId = docPrefix + itemCount;				
		var headerId = headerPrefix + foldId;
		var buttonId = buttonPrefix + foldId;
		var listId = listPrefix + foldId;

		var checkBoxTag = '';
		var checkBoxSpacer = '';
		if (strShowCheckBox != null && strShowCheckBox.length > 0){
			var styleClass = 'topicMenuCheckBox';
			if (i == 0){ styleClass = 'topicMenuCheckBoxFirst'; }
			checkBoxTag = "<input class='" + styleClass + "' type='checkbox' name='" + strShowCheckBox + "' value='" + id + "' />";	
			checkBoxSpacer = "<img class='topicMenuCheckBoxSpacer' src='" + spacerGIF + "' border='0'/>";
		}
	
		var clickCode = "style='cursor: hand;' onclick='toggleList(this);'"; 
		
		if (filepath > 0){ checkBoxTag += "<img src='" + hasdocGIF + "' alt='a downloadable file is associated with this document entry'/>"; }
		else { checkBoxTag += "<img src='" + docspacerGIF + "'/>"; }
		
		html += "	<div id='" + headerId + "'>" + checkBoxTag + "<img id='" + buttonId + "' src='" + foldGIF + "' border='0' class='topicMenuImg' " + clickCode + "><span class='topicMenuTitle'><a class='BlueSectionLink' href='" + nodeId + "'>" + title + "</a></span></div>\n";
		html += "	<div><span>\n";
		html += "		<div id='" + listId + "' style='display:none;'>\n";
		html += "			<div><span>" + checkBoxSpacer + "<img src='" + docspacerGIF + "'/><img src='" + linkSrc_mid + "'/></span><span><img src='" + nodocGIF + "'/></span><span>" + show_keywords + "</span></div>\n";
		
		var linkSrc = linkSrc_end;		
		if (filepath > 0){ linkSrc = linkSrc_mid; }
		html += "			<div><span>" + checkBoxSpacer + "<img src='" + docspacerGIF + "'/><img src='" + linkSrc + "'/></span><span><img src='" + nodocGIF + "'/></span><span>" + show_topics + "</span></div>\n";
			
		if (filepath > 0){
			html += "			<div><span>" + checkBoxSpacer + "<img src='" + docspacerGIF + "'/><img src='" + linkSrc_end + "'/></span><span><img src='" + hasdocGIF + "' alt='click on this link to download associated file'/></span><span><a href='" + show_file + "' target='_blank'>" + filename + "</a></span></div>\n";
		}
		html += "		</div>\n";
		html += "	</span></div>\n";
	}
	html += "</div>\n";		
		
	return html;
}

function $empty (){
	return ("<div><span>NO RECORDS FOUND</span></div>");		
}