function displayModuleIndex(clickElement, expandClient) {
    var moduleIndexList = document.getElementById("moduleIndexList").value;
    var expandClientPar = "";
    try {        
        if (expandClient.trim().length>0)
        expandClientPar = "&expandClient=" + expandClient;
    } catch (e) {
    }
    var filterText = document.getElementById("filterText").value;
    var ajaxRequest = initialiseAJAXRequest();
    var processURL = uncacheurl("./modules/moduleIndex/AJAX/moduleIndexFO.jsp"
        + "?moduleIndexList=" + moduleIndexList
        + expandClientPar
        + "&filterText=" + filterText
        );
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                eventBuildContent("moduleIndex", ajaxRequest.responseText, clickElement);
                //changeFeedbackBox(moduleIndexList);
            } else {
                //alert("status= " + ajaxRequest.status + "\nresponseText= " + ajaxRequest.responseText);
                if (ajaxRequest.status=='500') {
                    window.location.reload(true);
                } else {
                    alert("status= " + ajaxRequest.status + "\nresponseText= " + ajaxRequest.responseText);
                }
            }
        }
    };
    ajaxRequest.open("GET", processURL, true);
    ajaxRequest.send(null);
}

function displayExpl(clickElement, explType) {
    document.getElementById(clickElement).innerHTML="<center><img src='./templates/VeteransMATES/images/ajax-loading-line.gif'></center>";
    var ajaxRequest = initialiseAJAXRequest();
    var processURL = uncacheurl("./modules/moduleIndex/AJAX/expl/all.jsp");
    if (explType == "allExpl") {
      processURL = uncacheurl("./modules/moduleIndex/AJAX/expl/all.jsp");        
    }
    if (explType == "feedbackExpl") {
      processURL = uncacheurl("./modules/moduleIndex/AJAX/expl/feedback.jsp");        
    }
    if (explType == "responseExpl") {
      processURL = uncacheurl("./modules/moduleIndex/AJAX/expl/response.jsp");        
    }
    if (explType == "shortExpl") {
      processURL = uncacheurl("./modules/moduleIndex/AJAX/expl/short.jsp");        
    }
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                document.getElementById("explDiv").innerHTML = ajaxRequest.responseText;                
            } else {
                alert("status= " + ajaxRequest.status + "\nresponseText= " + ajaxRequest.responseText);
            }
        }
    };
    ajaxRequest.open("GET", processURL, true);
    ajaxRequest.send(null);
}

function toggleExplDiv(inDiv, explType) {

    var imgReplace = "img_" + inDiv;
    var displayLink = "link_" + inDiv;
    
        if (document.getElementById(inDiv)) {

		var style2 = document.getElementById(inDiv).style;

		//if (checkIE()) { //IE
			if (style2.display=="none" ) {
				style2.display="block";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/contractIcon.gif";
                                document.getElementById(displayLink).title = "Click to hide explanation...";
                                //if (inDiv=="explDiv") displayExpl("explDiv", explType);
			} else if (style2.display=="block" ) {
				style2.display="none";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/expandIcon.gif";
                                document.getElementById(displayLink).title = "Click to show explanation...";
			}
                //}document.getElementById('feedbackDiv').style.display = 'block';
        }
    
}

function filterID(filterType, filterStr) {
    var ajaxRequest = initialiseAJAXRequest();
    var processURL = uncacheurl("./modules/moduleIndex/AJAX/getFilteredIDs.jsp"
        + "?filterType=" + filterType
        + "&filterStr=" + filterStr.value
        );
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                document.getElementById(filterType + "Select").innerHTML = ajaxRequest.responseText.trim() + "<div class=\"filterTip_2\">(Select a topic from the list above)</div>";
                //document.getElementById("moduleIndexList").size = document.getElementById("moduleIndexList").length;
                displayModuleIndex("listTab");
            } else {
                alert("status= " + ajaxRequest.status + "\nresponseText= " + ajaxRequest.responseText);
            }
        }
    };
    ajaxRequest.open("GET", processURL, true);
    ajaxRequest.send(null);
}

function hideText(inCell, inStr) {
    var doShow = true;
    var doHide = true;
    if ( inStr === undefined ) {
      // do nothing
    } else {
        if (inStr == "show") {
            doShow = true;
            doHide = false;
        } else {
            doShow = false;
            doHide = true;
        }
    }
    
    var theCell = inCell + "_1";
    var imgReplace = "img_" + inCell;
    var displayLink = "link_" + inCell;
    
    if (document.getElementById(theCell)) {

        var style2 = document.getElementById(theCell).style;
//        if (checkIE()) {
//          if (style2.color=="#ffffff" && doShow) {
//              style2.color="#000000";
            if (style2.display=="none" && doShow) {
              style2.display="block";
              document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/contractIcon.gif";
              document.getElementById(displayLink).title = "Click to hide key words...";
          } else if (doHide) {
              //style2.color="#FFFFFF";
              style2.display="none";
              document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/expandIcon.gif";
              document.getElementById(displayLink).title = "Click to show key words...";
          }
//        } else {
////          if (style2.color=="rgb(255, 255, 255)" && doShow) {
////              style2.color="#000000";
//            if (style2.color=="rgb(255, 255, 255)" && doShow) {
//              style2.color="#000000";
//              document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/contractIcon.gif";
//              document.getElementById(displayLink).title = "Click to hide key words...";
//          } else if (doHide) {
//              //style2.color="#FFFFFF";
//              style2.display="none";
//              document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/expandIcon.gif";
//              document.getElementById(displayLink).title = "Click to show key words...";
//          }
//        }
    }
    
}

function toggleAll(rowCount) {
    
    if (document.getElementById('link_all').innerHTML=="Show all") {
        actionStr = "show";
        document.getElementById('link_all').innerHTML="Hide all";
        document.getElementById('link_all').title="Click to hide ALL information..."
    } else {
        actionStr = "hide";
        document.getElementById('link_all').innerHTML="Show all";
        document.getElementById('link_all').title="Click to show ALL information..."
    }
    
    hideText("mkw", actionStr);
    for (x=0; x<=rowCount; x++) {
        toggleRow(x, 2, actionStr);
    }
}

function toggleRow(inRow, loops, inStr) {
    
    var doShow = true;
    var doHide = true;
    if ( inStr === undefined ) {
      // do nothing
    } else {
        if (inStr == "show") {
            doShow = true;
            doHide = false;
        } else {
            doShow = false;
            doHide = true;
        }
    }

    for (i=1; i<=loops; i++) {
        var theRow = inRow + "_" + i;
        var imgReplace = "img_" + inRow;
        var displayLink = "link_" + inRow;
        
        
	if (document.getElementById(theRow)) {
            
		var style2 = document.getElementById(theRow).style;

		if (checkIE()) { //IE
			if (style2.display=="none" && doShow) {
				style2.display="block";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/contractIcon.gif";
                                document.getElementById(displayLink).title = "Click to hide information...";
			} else if (style2.display=="block" && doHide) {
				style2.display="none";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/expandIcon.gif";
                                document.getElementById(displayLink).title = "Click to show information...";
			}
		} else { //other
			if (style2.display=="none" && doShow) {
				style2.display="table-row";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/contractIcon.gif";
                                document.getElementById(displayLink).title = "Click to hide information...";
				//style2.innerHTML="blah!";
			//} else if (style2.display=="table-row" && doHide) {
                        } else if ( doHide) {
				style2.display="none";
                                document.getElementById(imgReplace).src = "./templates/VeteransMATES/images/expandIcon.gif";
                                document.getElementById(displayLink).title = "Click to show information...";
			}
		}
	}
    }
        
}

function filterKeyWords(filterStr) {
    document.getElementById('filterText').value=filterStr;
    filterID('moduleIndex', document.getElementById('filterText'));
}

function checkIE() {
    if (window.ActiveXObject) {
        return true;
    } else {
        return false;
    }
}
