var LCO = null;

// class definition
function DocumentLC()
{
}

// member function prototypes
DocumentLC.prototype = new EventController();
DocumentLC.prototype.docoptionsTile;
DocumentLC.prototype.referenceTile;
DocumentLC.prototype.saveTile;

function DocumentLCInit()
{
	LCO = new DocumentLC();
    LCO.docoptionsTile = new DocoptionsTC(docoptions_callback);
    LCO.referenceTile = new ReferenceTC(docoptions_callback);
	LCO.saveTile = new SaveTC(save_callback);
}

function docoptions_callback(tile)
{
	if (tile.getEvent() == "E_SYNC_TO_TOC")
	{
		LCO.setEvent(tile.getEvent());
		LCO.handleEvent(LCO);
	}
	else if (tile.getEvent() == "E_SET_TOCDOC")
	{
		LCO.setEvent(tile.getEvent());
		if (!LCO.handleEvent(LCO))
		{
			window.location.href = "template.htm?view=document&doc_action=setDoc&doc_keytype=tocid&doc_key=" + tile.getElement();
		}
	}
	else if (tile.getEvent() == "E_SET_HITTOCDOC")
	{
		LCO.setEvent(tile.getEvent());
		if (!LCO.handleEvent(LCO))
		{
			window.location.href = "template.htm?view=document&doc_action=setHitDoc&doc_keytype=tocid&doc_key=" + tile.getElement();
		}
	}
	else if (tile.getEvent() == "E_SET_HITDOC")
	{
		LCO.setEvent(tile.getEvent());
		if(!LCO.handleEvent(LCO))
		{
			window.location.href = "template.htm?view=document&doc_action=setHitDoc&doc_hit=" + tile.getElement();
		}
	}
	else if (tile.getEvent() == "E_EMAIL_DOC")
	{
		LCO.setEvent(tile.getEvent());
		if(!LCO.handleEvent(LCO))
		{
			window.location.href = "template.htm?view=emailform";
		}
	}
	else if (tile.getEvent() == "E_BOOKMARK_DOC")
	{
		LCO.setEvent(tile.getEvent());
		if(!LCO.handleEvent(LCO))
		{
			LCO.saveTile.saveBookmark(tile.getElement());
		}
	}
	else if (tile.getEvent() == "E_SET_LEAFDOC")
	{
		LCO.setEvent(tile.getEvent());
		if(!LCO.handleEvent(LCO))
		{
			window.location.href = "template.htm?view=document&doc_action=setLeafDoc&doc_leaf=" + tile.getElement();
		}
	}
	else if (tile.getEvent() == "E_SET_PDFDOC")
	{
		LCO.setEvent(tile.getEvent());
		if(!LCO.handleEvent(LCO))
		{
			var targetFrame = document.getElementById("docFrame");
			targetFrame.contentWindow.location.href = tile.getElement();
		}
	}
	else if (tile.getEvent() == "E_MULTI_PRINT")
	{
		LCO.setEvent(tile.getEvent());
		return LCO.handleEvent(LCO);
	}
}

function save_callback(tile)
{
	if (tile.getEvent() == "E_SAVE_BOOKMARK_ADDED" )
	{
		LCO.setEvent(tile.getEvent());
		if (!LCO.handleEvent(LCO))
		{
			alert(SAVE_BOOKMARK_SUCCESS);
		}
	}
}