//Used to expand and collapse sections in a view
//It traverses through all the div tags of the document and 
//changes the style attribute's display value of div tag between "none" and "block" 
//to collapse and expand the sections.Each section is included in a div tag.
//id - The id given to each section or div tag of each section.
//track_click-This function is called whenever each section is toggled to expand and collapse.
//track_all-This function is called when "Collapse All" is toggled.

	
  function getInnerText(xStr)
  {
		var regExp = /<\/?[^>]+>/gi;
        xStr = xStr.replace(regExp,"");
        return xStr;
  }
    

function ylib_getObj(id,d)
 {

  var i,x;  if(!d) d=document;
  if(!(x=d[id])&&d.all) x=d.all[id];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][id];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ylib_getObj(id,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(id);
  return x;
 }

function track_click(id)
{
 var aDIVs = ylib_getObj(id + "_div");
 var aImg = ylib_getObj(id);
 var sText;

 
 if(aDIVs)
 {
	if(aDIVs.style.display != 'none')
	 {	
		aDIVs.style.display = "none";
		
		if(aImg)
		{
			if (id.indexOf("tree") != -1)
			{
				aImg.src="graphics/fold.gif";
			}
			else
			{
				aImg.src="graphics/rightblack.gif";
			}
        
			aImg.title="Show Section";
		}
	}
	else
	{
		aDIVs.style.display = "block";
		
		if(aImg)
		{
			if (id.indexOf("tree") != -1)
			{
				aImg.src="graphics/open.gif";
			}
			else
			{
				aImg.src="graphics/downblack.gif";
			}
			
			aImg.title="Hide Section";
		}
	}

	track_all_header();
 }

 return false;
}

function track_all_header()
{

 var is_expanded = false;

 for (i=1; i < 20; i++)
 {
   var aDIVs = ylib_getObj("instancetoggle" + i + "_div");
   
   if (!aDIVs)
    continue;


   if(aDIVs.style.display != 'none')
   {
	 is_expanded = true;
	 continue;
   }
   
 }

 for (i=0; i < 20; i++)
 {
  var aDIVs = ylib_getObj("relatedtoggle" + i + "_div");

  if (!aDIVs)
   continue;

  if(aDIVs.style.display != 'none')
  {
	is_expanded = true;
	continue;
  }
  
 }


 var allSpan = ylib_getObj("trackall_span");
 var allImg = ylib_getObj("trackall");
 if(allSpan && allImg)
 {
	 if(!is_expanded)
	  {
	   allImg.src="graphics/rightblack.gif";
	   allImg.title="Show All Sections";
	   allSpan.innerHTML="<span>Expand All</span>";
	  }
	 else
	  {
	   allImg.src="graphics/downblack.gif";
	   allImg.title="Hide All Sections";
	   allSpan.innerHTML="<span>Collapse All</span>";
	  }
 }


 return false;





}

function track_all()
{

 var is_expanded = false;

 var allSpan = ylib_getObj("trackall_span");
 var allImg = ylib_getObj("trackall");

 var sHTML=allSpan.innerHTML;
 var sText = getInnerText(sHTML);
 
 
 for (i=1; i < 20; i++)
 {
  var aDIVs = ylib_getObj("instancetoggle" + i + "_div");
  var aImg = ylib_getObj("instancetoggle" + i);

  if (!aDIVs)
   continue;


  if(sText == 'Collapse All' && aDIVs.style.display != 'none')
  {
   aDIVs.style.display = "none";
   aImg.src="graphics/rightblack.gif";
   aImg.title="Show Section";
   is_expanded = true;
  }
  if(sText== 'Expand All' && aDIVs.style.display != 'block')
  {
   aDIVs.style.display = "block";
   aImg.src="graphics/downblack.gif";
   aImg.title="Hide Section";
  }
 }

 for (i=0; i < 20; i++)
 {
  var aDIVs = ylib_getObj("relatedtoggle" + i + "_div");
  var aImg = ylib_getObj("relatedtoggle" + i);

  if (!aDIVs)
   continue;

  if(sText== 'Collapse All' && aDIVs.style.display != 'none')
  {
   aDIVs.style.display = "none";
   aImg.src="graphics/rightblack.gif";
   aImg.title="Show Section";
   is_expanded = true;
  }
  if(sText== 'Expand All' && aDIVs.style.display != 'block')
  {
   aDIVs.style.display = "block";
   aImg.src="graphics/downblack.gif";
   aImg.title="Hide Section";
  }
 }


 var allSpan = ylib_getObj("trackall_span");
 var allImg = ylib_getObj("trackall");
 if(is_expanded)
  {
   allImg.src="graphics/rightblack.gif";
   allImg.title="Show All Sections";
   allSpan.innerHTML="<span>Expand All</span>";
  }
 else
  {
   allImg.src="graphics/downblack.gif";
   allImg.title="Hide All Sections";
   allSpan.innerHTML="<span>Collapse All</span>";
  }


 return false;
}