var intervalID=null;
var Opacity=0;

function ShowHint(Data,e)
{
	if(intervalID)
		return;
		
	if(document.all) //ie
	{
		var tempX = e.clientX + document.body.scrollLeft;
		var tempY = e.clientY + document.body.scrollTop;
	} 
	else // FireFox
	{	
		var tempX = e.clientX;
		var tempY = e.clientY;
	}

	document.getElementById("HintText").innerHTML=Data;
	document.getElementById("Hint").style.left=tempX+10;
	document.getElementById("Hint").style.top=tempY+10;

	document.getElementById("Hint").style.visibility="visible";
	intervalID=setInterval("FadeIn()",50);

}

function FadeIn()
{	
	if(Opacity<9)
	{
		if(document.all) //ie
			document.getElementById("Hint").style.filter="alpha (opacity="+((Opacity+1)*10)+")";
		else
		{
			document.getElementById("Hint").style.MozOpacity=(Opacity+1.0)/10.0;
			document.getElementById("Hint").style.Opacity=(Opacity+1.0)/10.0;
		}
	}
	else
	{
		clearInterval(intervalID);
		intervalID=null;
	}
	
	Opacity+=2;
}

function FadeOut()
{	
	if(Opacity>0)
	{
		if(document.all) //ie
			document.getElementById("Hint").style.filter="alpha (opacity="+((Opacity-1)*10)+")";
		else
		{
			document.getElementById("Hint").style.MozOpacity=(Opacity-1.0)/10.0;
			document.getElementById("Hint").style.Opacity=(Opacity-1.0)/10.0;
		}
	}
	else
	{
		clearInterval(intervalID);
		intervalID=null;
	}
	
	Opacity--;
	
	if(Opacity<=1)
		document.getElementById("Hint").style.visibility="hidden";
}

function CloseHint()
{
	if(intervalID)
		return;
	//document.getElementById("Hint").style.visibility="hidden";
	//intervalID=setInterval("FadeOut()",10);
	Opacity=1;
	FadeOut();
}

//------------------------
var enablepersist="on"; //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no"; //Collapse previously open content when opening present? (yes/no)

if (document.getElementById)
{
	document.write('<style type="text/css">');
	document.write('.switchcontent{display:none;}');
	document.write('</style>');
}

function getElementbyClass(classname)
{
	ccollect=new Array();
	var inc=0;
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	for (i=0; i<alltags.length; i++)
	{
	if (alltags[i].className==classname)
		ccollect[inc++]=alltags[i];
	}
}

function contractcontent(omit)
{
	var inc=0;
	while (ccollect[inc])
	{
		if (ccollect[inc].id!=omit)
			ccollect[inc].style.display="none";
		inc++;
	}
}

function expandcontent(cid)
{
	if (typeof ccollect!="undefined")
	{
		if (collapseprevious=="yes")
			contractcontent(cid);
			
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none";
		
		if(cid.substr(0,4)=="Cell") 
			return;
			
		var ImageNumber=cid.replace("sc","");
		if (document.images)
		{
			var imgName="Img"+ImageNumber;
			if(document.images[imgName]!=null)
			{
				var imgSrc=document.images[imgName].src;
				
				if(document.getElementById(cid).style.display!="block")
					imgSrc=imgSrc.replace("minus","plus");
				else
					imgSrc=imgSrc.replace("plus","minus");
				
				document.images[imgName].src = imgSrc;
			}
		}
	}
}

function revivecontent()
{
	contractcontent("omitnothing");
	selectedItem=getselectedItem();
	selectedComponents=selectedItem.split("|");
	for (i=0; i<selectedComponents.length-1; i++)
	{
		if(document.getElementById(selectedComponents[i])!=null)
		{
			document.getElementById(selectedComponents[i]).style.display="block";
			
			if(selectedComponents[i].substr(0,4)=="Cell") 
				continue;
			
			if(document.images[imgName]==null)
				continue;
				
			var ImageNumber=selectedComponents[i].replace("sc","");
			var imgName="Img"+ImageNumber;
			var imgSrc=document.images[imgName].src;
			imgSrc=imgSrc.replace("plus","minus");
			document.images[imgName].src = imgSrc;
		}
	}
}

function get_cookie(Name) 
{ 
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1) 
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end));
		}
	}
	return returnvalue;
}

function getselectedItem()
{
	if (get_cookie(window.location.pathname) != "")
	{
		selectedItem=get_cookie(window.location.pathname.substring(window.location.pathname.indexOf("?",1)+1));
		return selectedItem;
	}
	else
		return "";
}

function saveswitchstate()
{
	var inc=0, selectedItem="";
	while (ccollect[inc])
	{
		if (ccollect[inc].style.display=="block")
			selectedItem+=ccollect[inc].id+"|";
		inc++;
	}

	document.cookie=window.location.pathname.substring(window.location.pathname.indexOf("?",1)+1)+"="+selectedItem;
}

function do_onload()
{
	uniqueidn=window.location.pathname+"firsttimeload";
	getElementbyClass("switchcontent");
	if (enablepersist=="on" && typeof ccollect!="undefined")
	{
		document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" ;
		firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0;//check if this is 1st page load
		if (!firsttimeload)
			revivecontent();
	}
}

function SelectObject(objName)
{
  ResetObjects();
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.backgroundColor = "#666666";
    obj.style.color="#FFFFFF";
  }
  document.Form1.SelectedObject.value=objName.replace("Item_","");
  //alert(document.Form1.SelectedObject.value);
}

function DeselectObject(objName)
{
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.backgroundColor = "#F3F2F1";
    obj.style.color="#666666";
  }
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false);
else if (window.attachEvent)
	window.attachEvent("onload", do_onload);
else if (document.getElementById)
	window.onload=do_onload;

if (enablepersist=="on" && document.getElementById)
	window.onunload=saveswitchstate;
	
