var maxIndex = 1;
function toggle(id, button) {
    var theObj = document.getElementById(id);
    var theToggle = document[button];
    var currentImg = theToggle.src;
    var endIndex = currentImg.lastIndexOf('images/');
    var ragStatusIndex = currentImg.lastIndexOf('-');
    //alert('RAG status index: ' + ragStatusIndex);
    var relPath = '';
    var ragStatus = '';
    if (endIndex > 0) {
        relPath = currentImg.substring(0, endIndex);
    }
    if (ragStatusIndex > 0) {
        ragStatus = currentImg.substring(endIndex + 7, ragStatusIndex + 1);
    }
    //alert('Rel path: ' + relPath);
    //alert('RAG status: ' + ragStatus);
    if (theObj.style.display == "none") {
        theToggle.src = relPath + "images/" + ragStatus + "minus.png";
        theObj.style.display = "";      
    } else {
        theToggle.src = relPath + "images/" + ragStatus + "plus.png";
        theObj.style.display = "none";      
    }
}

function toggleTee(id, button) {
    var theObj = document.getElementById(id);
    var theToggle = document[button];
    var currentImg = theToggle.src;
    var endIndex = currentImg.lastIndexOf('images/');
    var relPath = '';
    if (endIndex > 0) {
        relPath = currentImg.substring(0, endIndex);
    }
    if (theObj.style.display == "none") {
        theToggle.src = relPath + "images/tee-minus.png";
        theObj.style.display = "";		
	} else {
        theToggle.src = relPath + "images/tee-plus.png";
		theObj.style.display = "none";		
	}
}

function toggleElbow(id, button) {
	var theObj = document.getElementById(id);
	var theToggle = document[button];
	var currentImg = theToggle.src;
    var endIndex = currentImg.lastIndexOf('images/');
    var relPath = '';
    if (endIndex > 0) {
        relPath = currentImg.substring(0, endIndex);
    }
	if (theObj.style.display == "none") {
        theToggle.src = relPath + "images/elbow-minus.png";
	    theObj.style.display = "";		
	} else {
        theToggle.src = relPath + "images/elbow-plus.png";
		theObj.style.display = "none";		
	}
}

function toggleAnnotation(id, button) {
    //alert("Toggle annotation: " + id + "; " + button);
    var theObj = document.getElementById(id);
    var theToggle = document.getElementById(button);
    if (theObj.style.display == "none") {
        theObj.style.display = "";
        maxIndex = maxIndex+1;
        theToggle.style.zIndex = maxIndex;          
    } else {
        theObj.style.display = "none";   
    }
}

function shownAnnotation(id) {
    var theObj = document.getElementById(id);
    theObj.style.display = "";
    maxIndex = maxIndex+1;
    theToggle.style.zIndex = maxIndex;
}

function hideAnnotation(id) {
    var theObj = document.getElementById(id);
    theObj.style.display = "none";
}

/*
 * Attaches an event handler to the specified
 * object (obj)
 * to execute the function (fn) when the event (type)
 * fires.
 * 
 * Example usage:
 * attachEvent(document.getElementById('fred'), 'focus', myFunction);
 */
function attachEvent( obj, type, fn ) {
   try {
    if (obj.attachEvent) {
        obj['e' + type + fn] = fn;
        obj[type + fn] = function(){
            obj['e' + type + fn](window.event);
        }
        obj.attachEvent('on' + type, obj[type + fn]);
    }
    else 
        obj.addEventListener(type, fn, false);
   } catch (er) {
      alert('Could not addEvent to ' + obj + ', of type ' + type + ', for function ' + fn);
   }
}

//The following allow js hooks to be initiated on page load

function initRequirements() {
    //Do nothing - can be overriden by theme
}

function initValidationErrors() {
    //Do nothing - can be overriden by theme
}

function initActors() {
    //Do nothing - can be overriden by theme
}

function initDocument() {
    //Do nothing - can be overriden by theme
}

function initGlossary() {
    //Do nothing - can be overriden by theme
}

function initPackage() {
    //Do nothing - can be overriden by theme
}

function initIndex() {
    //Do nothing - can be overriden by theme
}

function initHeader() {
    //Do nothing - can be overriden by theme
}

function initSummaryReport() {
    //Do nothing - can be overriden by theme
}

function initNavigation() {
    //Do nothing - can be overriden by theme
}

function initStakeholders() {
    //Do nothing - can be overriden by theme
}

function initUsecase() {
    //Do nothing - can be overriden by theme
}

