var goMenuPopup;
/* Atver uzlecošo menu
	tcNames		- Menu vienību nosaukumi atdalīti izsaukumu zīmi
	tcImages		- Menu vienību ikonu failu nosaukumi atdalīti izsaukumu zīmi
	tcActions	- Veicamās darbības ja izvēlēts kads no punktiem
	
	PIEMĒRS:
 	TreePopupMenu
		(
		"Viens!Divi", 
		"one.gif!two.gif", 
		"alert('odin')!alert('dva')"
		);
*/
function TreePopupMenu(tcNames, tcImages, tcActions)
{
	if( !goMenuPopup ) goMenuPopup = window.createPopup(  );
	
	var laNames		= tcNames.split("!");
	var laImages	= tcImages.split("!");
	var laActions	= tcActions.split("!");
	
	var lnHeight = 0;
	var lcContent = 
		'<div style="cursor: default; font-size: 11px; font-family: verdana">'+
		'<table width=140 cellspacing=0 cellpadding=0 border="1" style="color : MenuText; font-size: 11px; font-family: verdana">';
	for(var i = 0; i < laNames.length; i++)
	{
		if(laNames[i].length == 0)
			continue;
		lcContent = lcContent +
			ItemBody(laNames[i]	, laImages[i], laActions[i]);
		lnHeight += 23;
	}

    lcContent += '</table>';

	goMenuPopup.document.body.innerHTML = lcContent;
	goMenuPopup.show( event.clientX+2, event.clientY+2, 140, lnHeight, document.body );
	event.returnValue = false;
	event.cancelBubble = true;
}
// ================================================ ITEM Body
// Ģenerē HTML kodu vienai menu izvēlei
function ItemBody(tcName, tcImage, tcOnClick)
{
	var lcStyle = ' style="cursor: pointer; background-color: #D4D0C8;  border-top: 1px solid #FFFFFF;  border-left: 1px solid #FFFFFF;    border-right: 1px solid #808080;  border-bottom: 1px solid #808080;" ';
	var lcMouseOver		= ' onmouseover="parent.window.popup_over( this )" ';
	var lcMouseOut 		= ' onmouseout="parent.window.popup_over( this, 1)" ';
	var lcMouseOnClick 	= ' onclick="'+tcOnClick+'"';

	var lcOut = '<tr>\n'
		+ '<td ' + lcStyle + lcMouseOver + lcMouseOut + lcMouseOnClick + ' width="140" height="20">\n'
		+ '<img src="images/contextmenu/'+tcImage+'" align="absmiddle" alt="" border=0>\n'
		+ ' '+tcName
		+ '</td>\n'
		+ '</tr>\n';

	return lcOut;
}

function chapter_Manage(tnID, tcTask, tlImageAllow)
{
	var lcUrl = "popup/editChapter.php?task="+tcTask;
	if(tcTask == "add")
		lcUrl += "&parent_id="+tnID;
	else
		lcUrl += "&id="+tnID;
		
	lnWidth		= tlImageAllow ? 500 : 350;
	lnHeight 	= tlImageAllow ? 240 : 160;
	openPopup(lcUrl, lnWidth, lnHeight);
}
function chapter_Delete(tnID, tlImageAllow)
{
	chapter_Manage(tnID, "drop", tlImageAllow);
}
function chapter_Edit(tnID, tlImageAllow)
{
	chapter_Manage(tnID, "edit", tlImageAllow);
}
function chapter_Add(tnParentID, tlImageAllow)
{
	chapter_Manage(tnParentID, "add", tlImageAllow);
}


function chapter_MoveUp(tnID)
{
	document.location.href ="?id="+tnID+"&task=moveUp";
}
function chapter_MoveDown(tnID)
{
	document.location.href ="?id="+tnID+"&task=moveDown";
}
function hide(tnID)
{
	document.location.href ="?id="+tnID+"&task=hide";
}
function show(tnID)
{
	document.location.href ="?id="+tnID+"&task=show";
}

function popup_over( obj, id )
{
	if( typeof obj != 'object' ) 
		return ;
	if( !id  )
	{
		obj.style.backgroundColor = "HighLight";
		obj.style.color = "HighLightText";
		return ;
	}
	obj.style.backgroundColor = "Menu";
	obj.style.color = "MenuText";
}

//############################################

function remfr( )
{
	if( window.location.search.indexOf( 'nf=true' ) != -1 )
	{
		var el = document.getElementById( 'div1' );
		if( el )
		{
			el.style.display = 'none';
			el.style.visibility = 'hidden';
			return;
		}
	}
}
if( navigator.userAgent.indexOf( "MSIE" ) != -1 ||  navigator.userAgent.indexOf( "Opera" ) != -1 ) window.attachEvent( 'onload' ,remfr );

