//*********************************************************************************************************
//	Function: siteeditresort()
//
//*********************************************************************************************************
function siteeditresort()
{
	//	Default size minimized
	listview_width	= 0;
	listview_height = 0;
	url				= '#';
	target			= 'resort';
		
	//	Open hidden window to process site edit sorting
	contentDetails( url, target, listview_width, listview_height );
	return false;
}

//*********************************************************************************************************
//	Function: selectEditAction()
//
//*********************************************************************************************************
CustomCommands = new Array();

function selectEditAction( se_id, cmd )
{
//---------------------------------------------------------------------------------------------------------
//	Get the action list information
//---------------------------------------------------------------------------------------------------------
	se_obj				= document.getElementById( se_id );
	article_id			= se_obj.getAttribute('articleid');
	article_type		= se_obj.getAttribute('articletype');
	uid					= se_obj.getAttribute('uid');
	target				= "se_details_" + article_id;
	usescrollbars		= '';
	
	//	Is the edit window already opened?
	//	If so focus it
	if ( contentDetailsFocus( target ) )
	{
		return;
	}

//---------------------------------------------------------------------------------------------------------
//	Determine if height and width needed
//---------------------------------------------------------------------------------------------------------
	switch ( cmd )
	{
		//	Edit or Copy need a details page height and width
		case 'E':
		case 'C':
			listview_height	= se_obj.getAttribute('dh');
			listview_width	= se_obj.getAttribute('dw');
		break;

		//	History
		case 'H':
			listview_width	= 600;
			listview_height	= 500;
		break; 

		//	Any other command needs nothing
		default:
			listview_width	= 0;
			listview_height = 0;
	}

//---------------------------------------------------------------------------------------------------------
//	Process the action
//---------------------------------------------------------------------------------------------------------
	//	Is the user doing an edit?
	switch( cmd )
	{
		//	Edit
		case 'E':
			//	No confirmation needed just do it
			url = "/contentmgr/article_details.php?id=" + article_id + '&uid=' + uid;
		break;

		//	History
		case 'H':
			//	No confirmation needed just do it
			url				= "/contentmgr/history_list.php?id=" + article_id;
			usescrollbars	= '1';
			target			= "ahist_" + article_id;
		break;

		//	Needs to be confirmed
		default:
			//	Otherwise, confirm action
			desc = getCmdDesc( cmd );
			if ( !confirm("Are you sure you want to " + desc.toLowerCase() + " this content?") )
			{
				return;
			}
			url = "/contentmgr/article_details.php?actions=" + cmd + "_" + article_id + "_" + article_type  + '&uid=' + uid;
		break;
	}

	//	Is there a custom command set for this action?
	if (CustomCommands[cmd])
	{
		url = CustomCommands[cmd];
	}

	//	Open the details window
	contentDetails( url, target, listview_width, listview_height, usescrollbars );
}

//*********************************************************************************************************
//	Function: contentDetailsFocus()
//
//*********************************************************************************************************
contentwindows = new Array();

function contentDetailsFocus( target )
{
	winobject = contentwindows[ target ];

	if ( winobject )
	{
		if ( !winobject.closed )
		{
			winobject.focus();
			return true;
		}
	}

	return false;
}

//*********************************************************************************************************
//	Function: contentDetails()
//
//*********************************************************************************************************
function contentDetails(content,target,sizeX,sizeY,usescrollbars,resizable)
{
	winobject = contentwindows[ target ];

	if ( winobject )
	{
		if ( !winobject.closed )
		{
			winobject.focus();
			return;
		}
	}

	if ( sizeX == 0 )
	{
		leftpos=2000;
		toppos =2000;
		
		//	Define the window size
		widthVar  = 'width=' + sizeX + ',';
		heightVar = 'height=' + sizeY + ',';
	}
	else
	{
		//	Center the window
		leftpos	= (screen.width)  ? (screen.width-sizeX)/2 : 100;
		toppos	= (screen.height) ? (screen.height-sizeY)/2 : 100;

		//	Define the window size
		widthVar  = 'width=' + sizeX + ',';
		heightVar = 'height=' + sizeY + ',';
	}

	//	Open the window
	winobject				= window.open(content,target,"menubar=0,statusbar=0,scrollbars=" + usescrollbars + ",toolbar=0,location=0," + widthVar + heightVar + "left=" + leftpos + ",top=" + toppos + ",resizable=" + resizable );
	contentwindows[target]	= winobject;
	winobject.focus();
}

//*********************************************************************************************************
//	Function: dbgDump() .. Debug function for dumping collections like styles, events
//
//*********************************************************************************************************
function dbgDump( collection, prefix )
{
	msg		= '';
	counter = 0;

	for ( var name in collection )
	{
		if ( prefix )
		{
			if ( name.substring(0, prefix.length) != prefix )
			{
				continue;
			}
		}

		msg += name + " = " +  collection[name] + "\r\n";

		if ( counter == 30 )
		{
			alert(msg );
			msg = '';
			counter = 0;
		}
		counter++;
	}

	if ( counter < 50 )
	{
		alert( msg );
	}
}

//Xpos = 0;
//Ypos = 0;
//function mousehandlerSelectEdit()
//{
//    Xpos = window.event.x + document.body.scrollLeft;
//    Ypos = window.event.y + document.body.scrollTop;	  
//}

//*********************************************************************************************************
//	Function: toggleSelectEdit()
//
//*********************************************************************************************************
var last_se_id = '';
var timeout_id = 0;

function toggleSelectEdit( event, article_id )
{
//---------------------------------------------------------------------------------------------------------
//	Get the select edit list
//---------------------------------------------------------------------------------------------------------
	se_list_obj	= document.getElementById( 'selectedit_list' );

//---------------------------------------------------------------------------------------------------------
//	
//---------------------------------------------------------------------------------------------------------
	//	No article id?
	if ( !article_id )
	{
		//	Celar any timeout if one active
		if ( timeout_id )
		{
			clearTimeout( timeout_id );
			timeout_id = 0;
		}

		//	Nope, is it being displayed?
		if ( se_list_obj.style.display == 'block' );
		{
			//	Yep, close it
			se_list_obj.style.display = 'none';
			last_se_id  = '';
		}

		//	Do not allow zero article id
		return;
	}

//---------------------------------------------------------------------------------------------------------
//	Get the select edit list object, one for all select edit links
//---------------------------------------------------------------------------------------------------------
	se_id	= 'se_' + article_id;
	se_obj	= document.getElementById( se_id );

//---------------------------------------------------------------------------------------------------------
//	Did the user click on another select edit while one was open for another article
//---------------------------------------------------------------------------------------------------------
	if ( se_id != last_se_id ) 
	{
		//	Another SE for article clicked?
		if ( se_list_obj.style.display == 'block' )
		{
			//	Yep, open it
			se_list_obj.style.display = 'none';
		}

		//	Set the last se id clicked
		last_se_id = se_id;
	}

//---------------------------------------------------------------------------------------------------------
//	Let's setup the list for the select edit
//---------------------------------------------------------------------------------------------------------
	//	Is the pick list already displayed?
	if ( se_list_obj.style.display == 'none' )
	{
		//	Nope,  then show it
		se_list_obj.style.display = 'block';

		if (document.compatMode && document.compatMode != "BackCompat")
		{
		   scroll_left = document.documentElement.scrollLeft;
		   scroll_top  = document.documentElement.scrollTop;
		}
		else
		{
		   scroll_left = document.body.scrollLeft;
		   scroll_top  = document.body.scrollTop;
		}

		//	Position for IE
		if (se_list_obj.style.pixelTop != null)
		{
			se_list_obj.style.pixelTop	= ( event.clientY ) + scroll_top ;
			se_list_obj.style.pixelLeft	= ( event.clientX - 10 ) + scroll_left;
		}

		//	Position for Mozilla/Firefox
		else
		{
			se_list_obj.style.top	= ( event.clientY ) + scroll_top ;
			se_list_obj.style.left	= ( event.clientX - 10 ) + scroll_left;
		}

		//	Create the entries in the se list
		html		= '';
		cmds_string = se_obj.getAttribute('cmds');
		cmds_array	= cmds_string.split(',');
		height		= 5;

		for ( idx in cmds_array )
		{
			cmd		= cmds_array[idx];
			desc	= getCmdDesc( cmd );			
			html	+= '<a class="selectedit-link" href="#" onclick="selectEditAction(\'' + se_id + '\',\'' + cmd + '\');return false;">' + desc + '</a>'
			height	+= 16;
		}

		//	Set the width and height
		se_list_obj.style.pixelWidth	= 100;
		se_list_obj.style.pixelHeight	= height;

		se_list_obj.innerHTML		= html;

		//	If user doesn't select something in 5 seconds
		//	Then close the list
		if ( timeout_id )
		{
			clearTimeout( timeout_id );
			timeout_id = 0;
		}
		timeout_id = setTimeout("toggleSelectEdit(0)", 5000); 
	}
	else
	{
		if ( timeout_id )
		{
			clearTimeout( timeout_id );
			timeout_id = 0;
		}
		//	Already shown so hide it.
		se_list_obj.style.display = 'none';
	}
}

//*********************************************************************************************************
//	Function: getCmdDesc()
//
//*********************************************************************************************************
function getCmdDesc( cmd )
{
	switch( cmd )
	{
		case 'C':
			desc = 'Copy';
		break;

		case 'E':
			desc = 'Edit';
		break;

		case 'R':
			desc = 'Preview';
		break;

		case 'P':
			desc = 'Publish';
		break;

		case 'U':
			desc = 'Unpublish';
		break;

		case 'D':
			desc = 'Delete';
		break;

		case 'H':
			desc = 'History';
		break;

		default:
			desc = '';
	}

	return desc;
}