function ShowHideDiv(id, visibility, display)
{ 
   
    obj = document.getElementById(id);
    obj.style.visibility = visibility;
    obj.style.display = display;
    
    //obj = document.getElementsByTagName("div"); 
    //obj[id].style.visibility = visibility;
	//obj[id].style.display = display; 
}
function ShowHideTR(id, visibility, display)
{ 
    obj = document.getElementsByTagName("tr"); 
    obj[id].style.visibility = visibility;
	obj[id].style.display = display; 
}
function showHide(elemID) 
{
 if(document.getElementById(elemID).className == "hiddenElement") {
    document.getElementById(elemID).className = "visibleElement";
  } 
 else { 
    document.getElementById(elemID).className = "hiddenElement";
  }
}
function swapImage(tdID) 
{
 if( document.getElementById(tdID).className == "expandImage" ){
      document.getElementById(tdID).className = "collapseImage";
    }
 else{
     document.getElementById(tdID).className = "expandImage";
    }
}
function hide(elemID) 
{
    document.getElementById(elemID).className = "hiddenElement";
}
function show(elemID) 
{
    document.getElementById(elemID).className = "visibleElement";
}
function swapGraph(VMGraphToShow, vebId)
{	
	var elem = document.getElementById("VM_GRAPH" + vebId);
	var hrefelem = document.getElementById("VM_GRAPH_REF" + vebId);
	var patient = "VM";
	for(var count = 0; count <= 100; count++){
		var aMouseLabelId = "graphVM" + count + "_LABEL" + vebId;
		var aMouseLabel = document.getElementById(aMouseLabelId);
		if (!aMouseLabel) {
			aMouseLabelId = "graphVP" + count + "_LABEL" + vebId;			
			aMouseLabel = document.getElementById(aMouseLabelId);
			if (!aMouseLabel) {
				continue; //no more mice
			} else {
				patient = "VP";
			}
		}
		
		if (VMGraphToShow.id == aMouseLabelId){			
			elem.src = "ViewChart.do?eid=" + vebId + "&mouse=" + patient + count;
			hrefelem.href="javascript:showChart(800, 600, " + vebId + ", '"+ patient +  count +"');";
				if(VMGraphToShow.parentNode.id == vebId + "leftSide"){
					VMGraphToShow.className = "highlightedLeft";
				}
				else {
					VMGraphToShow.className = "highlightedRight";
				}
			}
		else {
				if (aMouseLabel.parentNode.id == vebId + "leftSide"){
					aMouseLabel.className = "notHighlightedLeft";
				}
				else {
					aMouseLabel.className = "notHighlightedRight"}
				}
	}
}
function showChart(w, h, eid, mouse) {
var win = window.open("", "win", "width=" + w + ",height=" + h); // a window object
 with (win.document) {
   open("text/html", "replace");
   src = 'ViewChart.do?eid='+eid+'&mouse='+mouse+'&size=Big';
   write('<HTML><HEAD><TITLE>Chart</TITLE></HEAD><BODY><img src="' + src + '"/></BODY></HTML>');
   close();
 }
 		
		function SelectOutcomeCategory(ctrl,category) {
			var elems = document.forms[0].elements;
			for(i = 0; i < elems.length; i++) {
				if(elems[i].category) {						
					if(elems[i].category == category) 
					{											
						elems[i].checked = ctrl.checked;
					}
				}
			}				
		}
}

function setNavTabs(tabId, panelIdToShow){
	for (var count=1; count <= 4; count++){
	var activeTabId = "tab_" + count;
	var activePanelId = "panel_" + count;
	var tabsInPage = document.getElementById(activeTabId);
	var panelsInPage = document.getElementById(activePanelId);
	alert(activeTabId);
		if (!activeTabId){
		break;
		}
		if (tabId.id == activeTabId){
		tabId.className = "tabActive";
		panelIdToShow.className = "visibleElement";
		} 
		else{
		tabsInPage.className = "tabInactive";
		panelsInPage.className = "hiddenElement";
		}
	}
}

function oralInsulinNote(clickedCheckboxId) {
	//this variable sits outside the loop to initialize checkbox statuses before counting them
	var checkboxStatuses=0;
	//this outer loop looks for whether the current mouse being checked is a vm 9 - 12, 
	//if so then shows corresponding asterisk and the "no oral insulin" msg
	//if it is being unchecked, then asterisk is hidden
	for(var count = 9; count <= 12; count++){
	var vmCkboxLabelId = "VM" + count + "checkbox";
	var vmAsteriskId = "VM" + count + "Star";
	var selectedCkbox = document.getElementById(vmCkboxLabelId);
	var starToShow = document.getElementById(vmAsteriskId);
		if (!selectedCkbox) {
			continue;
		}
		//alert(vmCkboxLabelId);
		
		if(selectedCkbox.checked == true){

			if(clickedCheckboxId==vmCkboxLabelId){
				show('noOralInsulinNote');
				show(vmAsteriskId);
			}
		}
		else{hide(vmAsteriskId);}
		//on each pass of outer loop this will determine whether any vm 9 - 12 is checked
		//if not, hides the "no oral insulin" msg
		//alert(checkboxStatuses);
			if(selectedCkbox.checked == true){
			checkboxStatuses++
			}
			//alert(checkboxStatuses);
			if (checkboxStatuses == 0){
			hide('noOralInsulinNote');
			}
			else{show('noOralInsulinNote')}
	}
}

function truncateSciComments(text, len){
	if (text) {
	  if (text.length > len) {
		/* Truncate the content of the P, then go back to the end of the
		   previous word to ensure that we don't truncate in the middle of
		   a word */
		text = text.substring(0, len);
		text = text.replace(/\s\S+$/, '');
		isTruncated = true;
		}
	}
	return text;
}
function refreshParent() {
  window.opener.location.reload();
  self.close();
}