<?xml version="1.0"?>
<?xml-stylesheet href="chrome://ClipperFor91Note/skin/ClipperFor91NoteOverlay.css" type="text/css"?>

<!DOCTYPE overlay SYSTEM "chrome://ClipperFor91Note/locale/ClipperFor91NoteOverlay.dtd">
<overlay id="ClipperFor91NoteOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script type="application/x-javascript">
<![CDATA[

function SaveContentTo91Note()
{
	var br = document.getElementById("content");
	var wnd = null;
	if (br == null || !br.selectedTab)
	{
		wnd = document.commandDispatcher.focusedWindow;
	}
	else
	{
		wnd = br.getBrowserForTab(br.selectedTab).docShell
                           .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                           .getInterface(Components.interfaces.nsIDOMWindow);
    }
    try
    {       
		const cid = "@91Note/FirefoxClipper;1";
		var obj = Components.classes[cid].createInstance();
		obj = obj.QueryInterface(Components.interfaces.IFirefoxClipper);
		
		return obj.SaveContent(wnd, null);
	}
	catch(e)
	{
		alert(e);
	}
	return true;
}

function SaveAllTextTo91Note()
{
	var br = document.getElementById("content");
	var wnd = null;
	if (br == null || !br.selectedTab)
	{
		wnd = document.commandDispatcher.focusedWindow;
	}
	else
	{
		wnd = br.getBrowserForTab(br.selectedTab).docShell
                           .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                           .getInterface(Components.interfaces.nsIDOMWindow);
    }
    try
    {       
		const cid = "@91Note/FirefoxClipper;1";
		var obj = Components.classes[cid].createInstance();
		obj = obj.QueryInterface(Components.interfaces.IFirefoxClipper);

		return obj.SaveAllText(wnd, null);
	}
	catch(e)
	{
		alert(e);
	}
	return true;
}

function SaveAllImgTo91Note()
{
	var br = document.getElementById("content");
	var wnd = null;
	if (br == null || !br.selectedTab)
	{
		wnd = document.commandDispatcher.focusedWindow;
	}
	else
	{
		wnd = br.getBrowserForTab(br.selectedTab).docShell
                           .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                           .getInterface(Components.interfaces.nsIDOMWindow);
    }
    try
    {       
		const cid = "@91Note/FirefoxClipper;1";
		var obj = Components.classes[cid].createInstance();
		obj = obj.QueryInterface(Components.interfaces.IFirefoxClipper);

		return obj.SaveAllImgs(wnd, null);
	}
	catch(e)
	{
		alert(e);
	}
	return true;
}

function SaveSingleImgTo91Note(popupNode)
{
	var br = document.getElementById("content");
	var wnd = null;
	if (br == null || !br.selectedTab || popupNode)
	{
		wnd = document.commandDispatcher.focusedWindow;
	}
	else
	{
		wnd = br.getBrowserForTab(br.selectedTab).docShell
                           .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                           .getInterface(Components.interfaces.nsIDOMWindow);
    }
    try
    {       
		const cid = "@91Note/FirefoxClipper;1";
		var obj = Components.classes[cid].createInstance();
		obj = obj.QueryInterface(Components.interfaces.IFirefoxClipper);
		
		return obj.SaveSingleImg(wnd, popupNode);
	}
	catch(e)
	{
		alert(e);
	}
	return true;
}

function On91NoteMenuPopupShowing()
{
	if(gContextMenu.onImage)
	{
		var subMenu = document.getElementById("AddSingleImg91Note-submenu");
		subMenu.style.visibility = "visible";
	}
	else
	{
		var subMenu = document.getElementById("AddSingleImg91Note-submenu");
		subMenu.style.visibility = "collapse";	
	}
}
window.addEventListener("popupshowing", On91NoteMenuPopupShowing, false);

]]>
</script>

<stringbundleset id="stringbundleset">
	<stringbundle id="bundle_define" src="chrome://ClipperFor91Note/locale/ClipperFor91Note.properties" />
</stringbundleset>

<!-- This is for the right click menu -->
<!-- in Firefox -->
<popup id="contentAreaContextMenu">
	<menuseparator id="ClipperFor91Note-menu-sep" />
	<menu id="ClipperFor91Note-menu" label="91Note" class="menu-iconic" image="chrome://ClipperFor91Note/skin/91Note16.png" >
		<menupopup id="ClipperFor91Note-menupopup">
			<menuitem id="AddTo91Note-submenu" label="&menu.AddContent;"  oncommand="SaveContentTo91Note();"/>
			<menuitem id="AddAllTextTo91Note-submenu" label="&menu.AddAllText;" oncommand="SaveAllTextTo91Note();"/>
			<menuitem id="AddAllImg91Note-submenu" label="&menu.AddAllImage;" oncommand="SaveAllImgTo91Note();"/>
			<menuitem id="AddSingleImg91Note-submenu" label="&menu.AddSingleImg;" oncommand="SaveSingleImgTo91Note(document.popupNode);" />  
		</menupopup>
	</menu>
</popup>

<!-- This is for the Tools menu -->
<!-- in Firefox -->
<menupopup id="menu_ToolsPopup">	
	<menuseparator id="ClipperFor91Note-menu-sep" />
	<menu id="ClipperFor91Note-menu" label="91Note" class="menu-iconic" image="chrome://ClipperFor91Note/skin/91Note16.png" >
		<menupopup>
			<menuitem id="AddTo91Note-submenu" label="&menu.AddContent;"  oncommand="SaveContentTo91Note();"/>
			<menuitem id="AddAllTextTo91Note-submenu" label="&menu.AddAllText;" oncommand="SaveAllTextTo91Note();"/>
			<menuitem id="AddAllImg91Note-submenu" label="&menu.AddAllImage;" oncommand="SaveAllImgTo91Note();"/>
		</menupopup>
	</menu>
</menupopup>

<!-- This is for the toolbar -->
<!-- in Firefox -->
<toolbarpalette id="BrowserToolbarPalette">
	<toolbarbutton id="ClipperFor91Note-button" label="&menu.AddContent;" 
	class="toolbarbutton-1 chromeclass-toolbar-additional"
	tooltiptext="&tooltiptext;"
	oncommand="SaveContentTo91Note(null);"/>
</toolbarpalette>

</overlay>
