collEl = document.getElementsByTagName('DIV');

function iGetIndex(el) {
	ind=null;
	for (i=0; i<collEl.length; i++) {
		whichEl = collEl[i]
		if (whichEl.id==el) {
			ind=i;
			break;
		}	
	}
	return ind
}

function iInitialize(open,close) {
	for (i=0; i<collEl.length; i++) {
		whichEl = collEl[i]
		if (whichEl.className == 'iChild') {
			if (whichEl.id == 'el_root_iChild') {
				whichEl.style.display='block';
				whichEl.isExpanded=true;	
			} else {
				whichEl.style.display='none';
				whichEl.isExpanded=false;	
			}
			whichIm=document.getElementById(replaceSubstring(whichEl.id,'iChild','iParent')).getElementsByTagName('IMG')[0];	
			whichIm.src=(whichEl.isExpanded)?open:close;
		}
	}
}

function iExpandCollapse(el,open,close) {
	whichEl=document.getElementById(el+'iChild');
	if (whichEl.style.display == 'none') {
		whichEl.style.display='block';
		whichEl.isExpanded=true;
	} else { 
		whichEl.style.display='none';
		whichEl.isExpanded=false;
	}
	whichIm=document.getElementById(el+'iParent').getElementsByTagName('IMG')[0];
	whichIm.src=(whichEl.isExpanded)?replaceSubstring(whichIm.src,close,open):replaceSubstring(whichIm.src,open,close);
}

function iExpandAll(open,close) {
	for (i=0; i<collEl.length; i++) {
		whichEl = collEl[i];
		if (whichEl.className == 'iChild') {
			whichEl.style.display='block';
			whichEl.isExpanded=true;	
			whichIm=document.getElementById(replaceSubstring(whichEl.id,'iChild','iParent')).getElementsByTagName('IMG')[0];	
			whichIm.src=replaceSubstring(whichIm.src,open,close);
		}
	}
}

function iCollapseAll(open,close) {
	for (i=0; i<collEl.length; i++) {
		whichEl = collEl[i];
		if (whichEl.className == 'iChild') {
			whichEl.style.display='none';
			whichEl.isExpanded=false;	
			whichIm=document.getElementById(replaceSubstring(whichEl.id,'iChild','iParent')).getElementsByTagName('IMG')[0];	
			whichIm.src=replaceSubstring(whichIm.src,close,open);
		}
	}
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == '') {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like '+' being replaced with '++') - prevent an infinite loop
      var midStrings = new Array('~','`','_','^','#');
      var midStringLen = 1;
      var midString = '';
      // Find a string that doesn't exist in the inputString to be used
      // as an 'inbetween' string
      while (midString == '') {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = '';
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an 'inbetween' string that doesn't exist
      // Now go through and do two replaces - first, replace the 'fromString' with the 'inbetween' string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the 'inbetween' string with the 'toString'
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the 'replaceSubstring' function