
function renderCategoryDropDownlist (arrCategory, strDocID, strFieldName, intDefaultTopicID, strDefaultLabel) {
	strOut = "<select name=\"" + strFieldName + "\" id=\"" + strFieldName.replace ("[]", "") + "\" size=1>\n";
	if (strDefaultLabel.length > 0) {
		strOut = strOut + "<option value=\"\">"+ strDefaultLabel + "</option>\n";
	}
	strOut = strOut + showCategoryDropDownlist (arrCategory, 0, "", intDefaultTopicID);
	strOut = strOut + "</select>\n";

	document.getElementById(strDocID).innerHTML = strOut;
}


function showCategoryDropDownlist (arrCategory, depth, parentName, intDefaultValue) {
	strOut = "";
	if (!depth) {
		for ( i in arrCategory ) {
			strOut = strOut + "<optgroup label=\""+arrCategory[i].categoryname+ "\">\n";
			strOut = strOut + showCategoryDropDownlist (arrCategory[i].categories, depth+1, "", intDefaultValue);
			strOut = strOut + "</optgroup>\n";
		}
	} else if (depth == 1) {  //middle layer category
		for ( i in arrCategory ) {
			strOut = strOut + showCategoryDropDownlist (arrCategory[i].categories, depth+1, arrCategory[i].categoryname, intDefaultValue);
		}
	} else if (depth == 2) {  // node category
		strOut = "";
		for ( i in arrCategory ) {
			if (intDefaultValue == arrCategory[i].categoryid) {
				strOut = strOut + "<option value=\""+arrCategory[i].categoryid+ "\" selected>"+parentName+' --&gt; '+arrCategory[i].categoryname+"</option>\n";
			} else {
				strOut = strOut + "<option value=\""+arrCategory[i].categoryid+ "\">"+parentName+' --&gt; '+arrCategory[i].categoryname+"</option>\n";
			}
		
		}
		
	}
	return strOut;
}

