/*********************************************************************************
Copyright (C) 2007  Ryan Bowman

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

For any questions or comments contact ryan at fiddlerelf dot com
**********************************************************************************/

function WXExplorerHandler()
{

	this.explorerControls = new Array();

	this.treeNodeClicked = FHtreeNodeClicked;
	this.listNodeDoubleClicked = FHlistNodeDoubleClicked;
	this.showToolTip = FHshowToolTip;
	this.hideToolTip = FHhideToolTip;
	this.setToolTipInfo = FHsetToolTipInfo;
	this.containerResize = FHcontainerResize;
	this.executeSearch = FHexecuteSearch;
	this.moveUpOneNode = FHmoveUpOneNode;
	this.addressBackClicked = FHaddressBackClicked;
	this.addressForwardClicked = FHaddressForwardClicked;
	this.mouseDown = FHmouseDown;
	this.mouseUp = FHmouseUp;
	this.mouseMove= FHmouseMove;

}

function FHtreeNodeClicked(nodeId, treeViewId, clickedType)
{
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getTreeViewId() == treeViewId)
		{
			this.explorerControls[i].treeNodeClicked(nodeId, clickedType);
			return;
		}
	}
}

function FHlistNodeDoubleClicked(nodeId, listViewId, clickedType)
{
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getListViewId() == listViewId)
		{
			this.explorerControls[i].listNodeDoubleClicked(nodeId, clickedType);
			return;
		}
	}
}

function FHshowToolTip(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var nodeId = targetElement.getAttribute("id");
	var componentId = nodeId.substr(0, nodeId.indexOf("_"));
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].showToolTip(e);
			return;
		}
	}
}

function FHhideToolTip(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var nodeId = targetElement.getAttribute("id");
	var componentId = nodeId.substr(0, nodeId.indexOf("_"));
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].hideToolTip();
			return;
		}
	}
}

function FHsetToolTipInfo(nodeId, componentId, componentName)
{
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getListViewId() == componentId)
		{
			this.explorerControls[i].setToolTipInfo(nodeId, componentId, componentName);
			return;
		}
	}
}

function FHcontainerResize(e)
{
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		this.explorerControls[i].containerResize(e);
	}
}

function FHexecuteSearch(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var parentElement = targetElement.parentNode;
	var componentId = parentElement.firstChild.value;
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].executeSearch();
			return;
		}
	}
}

function FHmoveUpOneNode(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var parentElement = targetElement.parentNode;
	var componentId = parentElement.firstChild.value;
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].moveUpOneNode();
			return;
		}
	}
}

function FHaddressBackClicked(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var parentElement = targetElement.parentNode;
	var componentId = parentElement.firstChild.value;
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].addressBackClicked();
			return;
		}
	}
}

function FHaddressForwardClicked(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var parentElement = targetElement.parentNode;
	var componentId = parentElement.firstChild.value;
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].addressForwardClicked();
			return;
		}
	}
}

function FHmouseDown(e)
{
	var evt = normGetEvent(e);
	var targetElement = normGetTargetElement(e);
	var nodeId = targetElement.getAttribute("id");
	var componentId = nodeId.substr(0, nodeId.indexOf("_"));
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		if (this.explorerControls[i].getComponentId() == componentId)
		{
			this.explorerControls[i].mouseDown(targetElement.getAttribute("id"));
			return;
		}
	}
}

function FHmouseUp(e)
{
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		this.explorerControls[i].mouseUp();
	}
}

function FHmouseMove(e)
{
	var evt = normGetEvent(e);
	for (var i = 0; i < this.explorerControls.length; i++)
	{
		this.explorerControls[i].mouseMove(evt);
	}
}
