function AjaxSeeAll()
{
}

AjaxSeeAll.BuildContainer=function(sCtrl, ctrl)
{
	// Given
	var ctrlWidth=700;
	var ctrlDisp=2; //Ctrl Displacement Left or Right.
			
	// Constant.
	var ContainerLeft=findPosNew($('MainTable').rows[0])[0];
	var ContainerWidth=$('MainTable').rows[0].offsetWidth;
	var SeeAllLeft=findPosNew(sCtrl)[0];
	var SeeAllWidth=sCtrl.offsetWidth;
	
	// Calculations.
	var isFlip=false;
	if(SeeAllLeft < (ContainerWidth/2))
		isFlip=false;
	else
		isFlip=true;
	// Left 
	var ctrlLeft=ContainerLeft;
	if(isFlip==false)
		ctrlLeft+=ctrlDisp;
	else
		ctrlLeft+=(ContainerWidth-ctrlWidth)-ctrlDisp;
	
	// FirstCellWidth
	var FirstCellWidth=SeeAllLeft;
	FirstCellWidth-=ctrlLeft;
	
	// SecondCellWidth
	var SecondCellWidth=SeeAllWidth;
	
	// ThirdCellWidth
	var ThirdCellWidth=ctrlWidth-(FirstCellWidth+SecondCellWidth);
	// Building Control.
	
	ctrl.style.left=ctrlLeft+'px';
	ctrl.innerHTML="";
	var objTbl=document.createElement("table");
	with (objTbl)
	{
		cellPadding="0";cellSpacing="0";
	}
	with (objTbl.style)
	{
		borderBottom="1px solid #CCCCCC";
		borderLeft="1px solid #CCCCCC";
		borderRight="1px solid #CCCCCC";
		width=ctrlWidth+"px";
	}
	var objTr=objTbl.insertRow(0);
	
	var objCell=document.createElement("td");
	objCell.innerHTML="&nbsp;";
	with (objCell.style)
	{
		borderTop="1px solid #CCCCCC";
		width=FirstCellWidth+"px";
		fontSize="1px";
	}
	objTr.appendChild(objCell);
	
	objCell=document.createElement("td");
	objCell.innerHTML="&nbsp;";
	with (objCell.style)
	{
		borderTopStyle="none";
		width=(SecondCellWidth-1)+"px";
		fontSize="1px";
	}
	objTr.appendChild(objCell);
	
	objCell=document.createElement("td");
	objCell.innerHTML="&nbsp;";
	with (objCell.style)
	{
		borderTop="1px solid #CCCCCC";
		width=(ThirdCellWidth+1)+"px";
		fontSize="1px";
	}
	objTr.appendChild(objCell);
	
	objTr=objTbl.insertRow(1);
	objCell=objTr.insertCell(0);
	objCell.colSpan="3";
	objCell.id="tbl"+ctrl.id;
	var targetCtrl=objCell;
	objCell.innerHTML="";
	objTr.appendChild(objCell);
	ctrl.appendChild(objTbl);
	return targetCtrl;
}
AjaxSeeAll.getArgs=function(ctrl)
{
	var args=ctrl.attributes["args"].nodeValue;
	eval("var obj="+args);
	return obj;
}
AjaxSeeAll.getSeeAllControl=function(e)
{
	var ctrl=null;
	ctrl=e.srcElement?e.srcElement:e.target?e.target:ctrl;
	while(!ctrl.attributes["args"])
	{
		ctrl=ctrl.parentNode;
		if(!ctrl)
			break;
	}
	return ctrl;
}
AjaxSeeAll.visible=function(ctrl)
{
	var obj=AjaxSeeAll.getArgs(ctrl);
	var bVisible=false;
	if(Element.visible(obj.targetId))
		bVisible=true;
		obj.height="50px";
	obj=null;
	return bVisible;
}
AjaxSeeAll.onSeeAllClick=function(e)
{
	if(!e)
		e=window.event;
	var ctrl=AjaxSeeAll.getSeeAllControl(e);
	if (AjaxSeeAll.visible(ctrl))
	{
		AjaxSeeAll.HideSeeAll(ctrl);
	}
	else
	{
		AjaxSeeAll.ShowSeeAll(ctrl);
	}
}
AjaxSeeAll.ShowSeeAll=function(ctrl)
{
	var args=AjaxSeeAll.getArgs(ctrl);
	var tgt=$(args.targetId);
	var Stgt=$(args.StargetId);
	var Root=args.RootCat;
	ctrl.parentNode.style.borderBottomStyle="none";
	// For Current Element.
	if(!Element.visible(tgt))
	{		
		Stgt.style.left=(findPosNew(ctrl.parentNode)[0])+"px";
		Element.show(Stgt);		
		Element.show(tgt);
		ctrl.ctrlTarget=AjaxSeeAll.BuildContainer(ctrl.parentNode,$(args.targetId));
		$(Stgt).style.height=(ctrl.parentNode).offsetHeight+"px";
		$(Stgt).style.width="75px";
		var tgtTop=(findPosNew(ctrl.parentNode)[1])+((ctrl.parentNode).offsetHeight)+(($(Stgt)).offsetHeight);
		$(args.targetId).style.top=tgtTop+"px";
		if(ctrl.onShow && typeof ctrl.onShow=='function')
		{
			ctrl.onShow(ctrl,args);
		}
	}
	// For Other Elements.
	var ctrls=document.getElementsByClassName("SeeAllSource");
	for(var i=0;i<ctrls.length;i++)
	{
		if(ctrls[i]!=ctrl)
		{
			if(AjaxSeeAll.visible(ctrls[i]))
			{
				AjaxSeeAll.HideSeeAll(ctrls[i]);
			}
		}
	}
}
AjaxSeeAll.HideSeeAll=function(ctrl)
{
	if(AjaxSeeAll.visible(ctrl))
	{
		var args=AjaxSeeAll.getArgs(ctrl);
		var tgt=$(args.targetId);
		var Stgt=$(args.StargetId);
		Element.hide(Stgt);
		Element.hide(tgt);
		ctrl.parentNode.style.borderBottom="2px solid #B0B0B0";
		if(ctrl.onHide && typeof ctrl.onHide=='function')
		{
			ctrl.onHide(ctrl,args);
		}
	}
}
AjaxSeeAll.HideAllSeeAll=function()
{
	var Anchors=document.getElementsByTagName("A");
	for(var i=0;i<Anchors.length;i++)
	{
		if(Anchors[i].className.indexOf("SeeAllSource")!=-1)
		{
			AjaxSeeAll.HideSeeAll(Anchors[i]);
		}
	}
}
AjaxSeeAll.isInSeeAll=function(obj)
{
	while(obj)
	{
		if(obj.className && obj.className.indexOf("SeeAll")!=-1)
		{
			return true;
		}
		obj=obj.parentNode;
	}
	return false;
}
AjaxSeeAll.getAllSeeAlls=function()
{
	var Anchors=document.getElementsByTagName("A");
	var SeeAlls=new Array();
	for(var i=0;i<Anchors.length;i++)
	{
		if(Anchors[i].className.indexOf("SeeAllSource")!=-1)
		{
			SeeAlls.push(Anchors[i]);
		}
	}
	return SeeAlls;
}

AjaxSeeAll.onBodyClick=function(e)
{
	if(!e)
		e=window.event;
	var tgt;
	if(e.srcElement)
		tgt=e.srcElement;
	else
		tgt=e.target;
	if (!AjaxSeeAll.isInSeeAll(tgt))
	{
		AjaxSeeAll.HideAllSeeAll();
	}
	else
	{
		if(tgt.tagName!="A" && tgt.parentNode.tagName!="A" && tgt.tagName!="INPUT")
		{
			AjaxSeeAll.HideAllSeeAll();
		}
	}
}

// Binding Events.

AjaxSeeAll.BindEvents=function()
{
	var Anchors=document.getElementsByTagName("A");
	for(var i=0;i<Anchors.length;i++)
	{
		if(Anchors[i].className.indexOf("SeeAllSource")!=-1)
		{
			Anchors[i].onclick=AjaxSeeAll.onSeeAllClick;	
		}
	}
	document.body.onclick=AjaxSeeAll.onBodyClick;
}

oldOnLoad = window.onload;
if (typeof window.onload != 'function') 
{
    window.onload = function() { AjaxSeeAll.BindEvents(); };
} 
else 
{
    window.onload = function() { oldOnLoad(); AjaxSeeAll.BindEvents(); };
}

function findPosNew(obj)
{
	var curLeft = curTop = 0;
	if (obj.offsetParent)
	{
		curLeft = obj.offsetLeft;
		curTop = obj.offsetTop;
		while (obj = obj.offsetParent)
		{
			curLeft += obj.offsetLeft;
			curTop += obj.offsetTop;
		}
	}
	return [curLeft,curTop];
}
