var expoTree = new TreeView('expoTree', 'OnTreeViewClick'); 
var tlTree = new TreeView('tlTree', 'OnTreeViewClick'); 
var ftlTree = new TreeView('ftlTree', 'OnTreeViewClick'); 
var invTree = new TreeView('invTree', 'OnTreeViewClick'); 
var compTree = new TreeView('compTree', 'OnTreeViewClick'); 
var vacTree = new TreeView('vacTree', 'OnTreeViewClick'); 

function OnLoad()
{
	expoTree.Show();
	
	if(screen.height<500 || screen.width<1000)
	{
		alert(lowRes);
	}
}

function OnMainMenuClick(path,type)
{
	OnShowTreeClick(type);
	
	ChangeQS(type);
	
	window.DataFrame.location.replace(path);

	//Change menu items
	ResetMenuItems();
	
	var leftPic = event.srcElement.previousSibling.previousSibling;			
	var rightPic = event.srcElement.nextSibling.nextSibling;
	
	leftPic.src = "images/MainMenuSeparatorOrange.gif";			
	rightPic.src = "images/MainMenuSeparatorOrange.gif";
	
	event.srcElement.style.color = "#FF861D";
}

function OnMainMenuOpenClick(path,height,width)
{
	window.open(path,'','status=no, scrollbars=yes, resizable=yes');
}

function ResetMenuItems()
{
	var topLine = document.getElementById('TopMenuLine');
	//var bottomLine = document.getElementById('BottomMenuLine');
	
	ResetNextItems(topLine.children[0]);
	//ResetNextItems(bottomLine.children[0]);
}

function ResetNextItems(node)
{
	while(node!=null)
	{
		if(node.nodeName.toUpperCase()=='IMG')
		{
			node.src = "images/MainMenuSeparatorBlue.gif";
		}
		if(node.nodeName.toUpperCase()=='A')
		{
			node.style.color = "";
		}
		node = node.nextSibling;
	}
}

function DoSearchClick(id)
{
	var key = document.getElementById('qs_'+id+'_key').value;
	var type;
	var time;
	var country;
	
	var path;

	if(id=='expo')
	{
		type = document.getElementById('qs_'+id+'_type').options(document.getElementById('qs_'+id+'_type').selectedIndex).value;
		path = 'expoSearch.aspx?key='+escape(key)+'&type='+escape(type);
	}
	else if(id=='tl')
	{
		type = document.getElementById('qs_'+id+'_type').options(document.getElementById('qs_'+id+'_type').selectedIndex).value;
		time = document.getElementById('qs_'+id+'_time').options(document.getElementById('qs_'+id+'_time').selectedIndex).value;
		path = 'tlSearch.aspx?key='+escape(key)+'&type='+escape(type)+'&time='+escape(time);
	}
	else if(id=='comp')
	{
		path = 'compSearch.aspx?key='+escape(key);
	}
	else if(id=='ftl')
	{
		type = document.getElementById('qs_'+id+'_type').options(document.getElementById('qs_'+id+'_type').selectedIndex).value;
		time = document.getElementById('qs_'+id+'_time').options(document.getElementById('qs_'+id+'_time').selectedIndex).value;
		country = document.getElementById('qs_'+id+'_country').options(document.getElementById('qs_'+id+'_country').selectedIndex).value;
		path = 'ftlSearch.aspx?key='+escape(key)+'&type='+escape(type)+'&time='+escape(time);
		if(country!="")
		{
			path+='&country='+escape(country)
		}
	}

	window.DataFrame.location.replace(path);
	
	OnShowTreeClick(null);
}

function OnShowTreeClick(type)
{
	if(type=='expo')
	{
		window.parent.expoTree.Show();
		window.parent.tlTree.Hide();
		window.parent.invTree.Hide();
		window.parent.compTree.Hide();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Hide();
	}
	else if(type=='tl')
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Show();
		window.parent.invTree.Hide();
		window.parent.compTree.Hide();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Hide();
	}
	else if(type=='ftl')
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Hide();
		window.parent.invTree.Hide();
		window.parent.compTree.Hide();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Show();
	}
	else if(type=='inv')
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Hide();
		window.parent.invTree.Show();
		window.parent.compTree.Hide();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Hide();
	}
	else if(type=='comp')
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Hide();
		window.parent.invTree.Hide();
		window.parent.compTree.Show();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Hide();
	}
	else if(type=='vac')
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Hide();
		window.parent.invTree.Hide();
		window.parent.compTree.Hide();
		window.parent.vacTree.Show();
		window.parent.ftlTree.Hide();
	}
	else
	{
		window.parent.expoTree.Hide();
		window.parent.tlTree.Hide();
		window.parent.invTree.Hide();
		window.parent.compTree.Hide();
		window.parent.vacTree.Hide();
		window.parent.ftlTree.Hide();
	}
	currentTreeType = type;
}

function ChangeQS(type)
{
	var qs = document.getElementById('qs_' + type);
	ResetNextQSs(document.getElementById('qs_expo').parentElement.children[0]);
	if(qs!=null)
	{
		qs.style.display = 'block';
	}
}

function ResetNextQSs(node)
{
	while(node!=null)
	{
		if(node.nodeName.toUpperCase()=='TR')
		{
			node.style.display = 'none';
		}
		node = node.nextSibling;
	}
}

function OnTreeViewClick(id, type)
{
	var path = '';
	if(type=='expoTree')
	{
		path = 'expoSearch.aspx?dir='+escape(id);
	}
	else if(type=='tlTree')
	{
		path = 'tlSearch.aspx?dir='+escape(id);
	}
	else if(type=='compTree')
	{
		path = 'compSearch.aspx?dir='+escape(id);
	}
	else if(type=='vacTree')
	{
		path = 'vacSearch.aspx?dir='+escape(id);
	}
	else if(type=='invTree')
	{
		path = 'invSearch.aspx?dir='+escape(id);
	}
	else if(type=='ftlTree')
	{
		path = 'ftlSearch.aspx?dir='+escape(id);
	}
	else
	{
		//alert('Click: '+ id + ',  type:' + currentTreeType);	
	}
	
	window.DataFrame.location.replace(path);
	OnShowTreeClick(null);
}

function OnRegister(data)
{
	var granted = document.getElementById('spnGranted');
	var user = document.getElementById('spnUserName');
	
	granted.style.display = 'inline';
	user.innerText = data;
}

function OnDataFrameLoad()
{
	try
	{
		window.DataFrame.frameElement.style.pixelHeight = window.DataFrame.document.body.scrollHeight+70;
		if(window.DataFrame.frameElement.style.pixelHeight<700)
		{
			window.DataFrame.frameElement.style.pixelHeight = 700;	
		}
	}
	catch(ex){}
}
