<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" isELIgnored ="false" import="com.novell.webaccess.common.JSPConduit2, com.novell.emframe.dev.eMFrameUtils" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%--@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" --%>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<iman:stringtable bundle="DevResources"/>
<iman:stringtable bundle="FwResources"/>

<HTML>
<HEAD>
<TITLE>OVTitle</TITLE>
<LINK href="<iman:moduleUrl/>/fw/css/osStyles.css" rel="styleSheet" type="text/css">
<iman:eMFrameScripts />
<SCRIPT language="JavaScript" src="<iman:moduleUrl/>/dev/javascripts/OVBrowserScripts.js"></script>

<c:set var="OV_modUrl"><iman:moduleUrl/></c:set>      
<script>

   //------------- find OVTop ----------------
   var OVTop=top.Mainscreen.ObjectView;

   //---------------- local constants ----------------------
   var SEARCH_MODE =             "search";
   var BROWSE_MODE =             "browse";
   var TREE_MODE =             "tree";
   var ACTIVE_TREE =           "${OV_modUrl}/fw/images/<iman:toScript><iman:string key="OV.Browser.TreeTabActive" /></iman:toScript>";
   var ACTIVE_SEARCH =           "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.SearchTabActive" /></iman:toScript>";
   var ACTIVE_BROWSE =           "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.BrowseTabActive" /></iman:toScript>";
   var INACTIVE_TREE =         "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.TreeTabInactive" /></iman:toScript>";
   var INACTIVE_SEARCH =         "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.SearchTabInactive" /></iman:toScript>";
   var INACTIVE_BROWSE =         "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.BrowseTabInactive" /></iman:toScript>";
   var TABS_BROWSE =          "<iman:moduleUrl/>/fw/images/<iman:toScript><iman:string key="OV.Browser.BrowseTab" /></iman:toScript>";
   var SWITCH_TO_TREE_HINT =   "<iman:toScript><iman:string key="OV.Browser.TreeActivation" /></iman:toScript>";
   var SWITCH_TO_BROWSE_HINT =   "<iman:toScript><iman:string key="OV.Browser.BrowseActivation" /></iman:toScript>";
   var SWITCH_TO_SEARCH_HINT =   "<iman:toScript><iman:string key="OV.Browser.SearchActivation" /></iman:toScript>";

    //------------- dynamic GUI methods --------------------
   function switchMode(newMode)
   {
      if (OVTop.SelectedObjectsButtons!=null)
      {
         OVTop.SelectedObjectsButtons.doResetHint();  //clear an enhanced hint
      }
   
      var currentMode = OVTop.m_mode.toLowerCase();
      var browseTopRowSize = ((MS55)?"100":"120");
      if (newMode==currentMode)
      {
         //nothing to do
         return;
      }
      
      //update global variables
      if (newMode==BROWSE_MODE)
      {
         //switch to browse mode
         if(OVTop.m_mode==SEARCH_MODE) 
         {
	         // Save data from search mode query for browse mode query
	         OVTop.m_container = OVTop.Query.document.SearchQuery.SQContext.value;
	         OVTop.m_nameFilter = OVTop.Query.document.SearchQuery.SQNameFilter.value;
	         OVTop.m_searchSubContainers = ((OVTop.Query.document.SearchQuery.SQSubContainer.checked)?"true":"false");
//		}else{
<%--			iman.debugOV("in OVTitle.switchMode(\'browse\') after being in tree.  About to completely refresh parent witch I guess is Nav/ObjectView frame. parent.name="+parent.name);--%>
<%--			//window.alert("About to launch fw.ObjectView-fw.OV.ObjectViewStart from OVTitle.switchMode(newMode==BROWSE_MODE && OVTop.m_mode!=SearchMode");--%>
<%--			 parent.location="webacc?taskId=fw.ObjectView&merge=fw.OV.ObjectViewStart&error=fw.OV.ObjectViewNotAllowed&User.context=${requestScope['User.context']}&OV.Start=true&OV.Mode=browse&fw_from=OVTitle-switchMode-browse";--%>
<%-- 		 	 return;--%>
		}
         OVTop.m_mode=BROWSE_MODE;
         if (OVTop.m_multiSelect=="true"){
				OVTop.document.getElementById("OVFrames").rows=(browseTopRowSize+",30,50%,30,30,20%,30,5");
		 }else{
				OVTop.document.getElementById("OVFrames").rows=(browseTopRowSize+",30,100%,30,5");
		 }
      }
      else if (newMode==SEARCH_MODE)
      {
         //switch to search mode
         if(OVTop.m_mode==BROWSE_MODE)
         {
	         // Save data from browse mode query for search mode query
	         if(OVTop.Query.document.BrowseQuery){
	         	OVTop.m_container = OVTop.Query.document.BrowseQuery.BQContext.value;
	         	OVTop.m_nameFilter = OVTop.Query.document.BrowseQuery.BQNameFilter.value;
	         }
		}else{
//			 parent.location="webacc?taskId=fw.ObjectView&merge=fw.OV.ObjectViewStart&error=fw.OV.ObjectViewNotAllowed&User.context=${requestScope['User.context']}&OV.Start=true&OV.Mode=search&fw_from=OVTitle-switchMode-search";
// 		 	 return;
			OVTop.resultsFrame=OVTop.Results;
		}
         OVTop.m_mode=SEARCH_MODE;
         if (OVTop.m_multiSelect=="true")
				OVTop.document.getElementById("OVFrames").rows="120,30,50%,30,30,20%,30,5";
			else
				OVTop.document.getElementById("OVFrames").rows="120,30,100%,30,5";
      }
      else // tree mode
      {
         iman.debugOV("Entering tree mode");
 		 if(OVTop.m_mode==BROWSE_MODE)
 		 {
 		 	if(OVTop.Query.document.BrowseQuery){
	         	// Save data from browse mode query for search mode query
	         	OVTop.m_container = OVTop.Query.document.BrowseQuery.BQContext.value;
	         	OVTop.m_nameFilter = OVTop.Query.document.BrowseQuery.BQNameFilter.value;
	         }
         }else{
	         // Save data from search mode query for browse mode query
 	         OVTop.m_container = OVTop.Query.document.SearchQuery.SQContext.value;
	         OVTop.m_nameFilter = OVTop.Query.document.SearchQuery.SQNameFilter.value;
	         OVTop.m_searchSubContainers = ((OVTop.Query.document.SearchQuery.SQSubContainer.checked)?"true":"false");
         }
         OVTop.m_mode=TREE_MODE;
 		 OVTop.document.getElementById("OVFrames").rows="0,0,100%,0,0";
      }
      
      //setup local variables
      var strURL="";
      var strHTML="";
      var modeName="Search";
      if(newMode==BROWSE_MODE){
      	modeName ="Browse";
      }else if(newMode == TREE_MODE){
      	modeName = "Tree";
      }else{
      	modeName ="Search";
      }
      modeName = ((newMode==TREE_MODE)?"Tree":modeName);
      var sm = ((OVTop.m_multiSelect=="true")?((newMode==TREE_MODE)?"SS":"MS"):"SS");
      OVTop.processDisplayCountChange();
      
      //update Title frame
      setupTabs(newMode);
      
      //clear query, results title, and results frames
      OVTop.Query.document.open();
      OVTop.Query.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="'+OVTop.OV_BGCOLOR+'"><form name=PostData method=post></form></BODY>');
      OVTop.Query.document.close();
            iman.debugOV("OVTitle.switchMode() after clear Query frame, OVTop.Query.document.close.");
      
      OVTop.ResultsTitle.document.open();
      OVTop.ResultsTitle.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="'+OVTop.OV_BGCOLOR+'"><form name=PostData method=post></form></BODY>');
      OVTop.ResultsTitle.document.close();
            iman.debugOV("OVTitle.switchMode() after clear ResultsTitle frame, OVTop.ResultsTitle.document.close.");
      
      if(OVTop.ResultButtons && OVTop.ResultButtons.document){
      iman.debugOV("OVTitle.switchMode() before clear ResultButtons frame.");
      	OVTop.ResultButtons.document.open();
      	if (MS55)
        	 OVTop.ResultButtons.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="#EFEEE9" style="border-style:solid; border-width:1; border-color:#BFBBB2;"><form name=PostData method=post></form></BODY>');
      	else
        	 OVTop.ResultButtons.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="#EFEEE9"><form name=PostData method=post></form></BODY>');
      	OVTop.ResultButtons.document.close();
      iman.debugOV("OVTitle.switchMode() after clear ResultButtons frame, OVTop.ResultButtons.document.close.");
      }
      
      if(OVTop.Results && OVTop.Results.document){
       iman.debugOV("OVTitle.switchMode() before clear Results frame.");
       OVTop.Results.document.open();
       if (MS55)
         OVTop.Results.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="#FFFFFF" style="border-style:solid; border-width:1; border-bottom-width:0; border-color:#BFBBB2;"><form name=PostData method=post action="webacc?fw_from='+fw_respId+'" ><span id=FormData><!-- switchMode will use innerHTML to dynamically create the input fields here --></span></form></BODY>');
       else
         OVTop.Results.document.writeln('<HTML><HEAD></HEAD><BODY bgcolor="#FFFFFF"><form name=PostData method=post action="webacc" ><span id=FormData><!-- switchMode will use innerHTML to dynamically create the input fields here --></span></form></BODY>');
       OVTop.Results.document.close();
       iman.debugOV("OVTitle.switchMode() after clear Results frame, OVTop.Results.document.close.");
      }
      
      //update Query frame
      	OVTop.resultsLoaded = false;
      strURL="webacc?taskId=dev.Empty&merge=fw.OV."+modeName+"Query&User.context="+OVTop.m_container+"&fw_from=OVTitle-switchMode&fw_fromRespId="+fw_respId;
      OVTop.Query.document.PostData.action=strURL;
      iman.debugOV("in OVTitle.switchMode() calling OVTop.Query.document.PostData.submit() on "+OVTop.Query.document.title+"  with query: "+strURL); 
      OVTop.Query.document.PostData.submit();
      
      //update ResultsTitle frame
      strURL="webacc?taskId=dev.Empty&merge=fw.OV."+modeName+"ResultsTitle"+sm+"&User.context="+OVTop.m_container+"&fw_from=OVTitle-switchMode&fw_fromRespId="+fw_respId;
      if(OVTop.ResultsTitle.document.PostData){
      OVTop.ResultsTitle.document.PostData.action=strURL;
      iman.debugOV("in OVTitle.switchMode() calling OVTop.ResultsTitle.document.PostData.submit() on "+OVTop.ResultsTitle.document.title+"  with query: "+strURL); 
      OVTop.ResultsTitle.document.PostData.submit();
      }
      //update ResultButtons frame
	  if(OVTop.ResultButtons){      
      	OVTop.resultButtonsLoaded=false;
      	strURL="webacc?taskId=dev.Empty&merge=fw.OV."+modeName+"ResultButtons&User.context="+OVTop.m_container+"&fw_from=OVTitle-switchMode&fw_fromRespId="+fw_respId;
      	OVTop.ResultButtons.document.PostData.action=strURL;
      	iman.debugOV("in OVTitle.switchMode() calling OVTop.ResultButtons.document.PostData.submit() on "+OVTop.ResultButtons.document.title+"  with query: "+strURL); 
      	OVTop.ResultButtons.document.PostData.submit();
      }

      //update Results frame   
      strURL   = "webacc?taskId=fw.ObjectView&error=dev.GenErr&merge=fw.OV."+modeName+"Results"+sm+"&User.context="+OVTop.m_container+"&SearchToken=SearchTokenRestart&fw_from=OVTitle-switchMode-updateResultFrame&fw_fromRespId="+fw_respId;
      strHTML += '<input type=hidden name="Search.ContextId" value="'      +toTag(OVTop.m_searchContextId)+'">\n';
      strHTML += '<input type=hidden name="OV.AdvancedSelection" value="'  +OVTop.m_advSel+'">\n';
      strHTML += '<input type=hidden name="OV.Container" value="'          +toTag(OVTop.m_container)+'">\n';
      strHTML += '<input type=hidden name="OV.Mode" value="'               +OVTop.m_mode+'">\n';
      strHTML += '<input type=hidden name="OV.ResultsPerPage" value="'     +OVTop.m_resultsPerPage+'">\n';
      
      if (newMode==BROWSE_MODE)
      {
         //no subcontainer searching in browse mode
         strHTML += '<input type=hidden name="OV.SearchSubContainers" value="false">\n';
//         OVTop.resultsLoaded=true;
//         return;
      }
      else
      {
         //possible subcontainer searching in search mode
         strHTML += '<input type=hidden name="OV.SearchSubContainers" value="'+OVTop.m_searchSubContainers+'">\n';
         strHTML += '<input type=hidden name="OV.SearchOnStartup" value="'    +OVTop.m_searchOnStartup+'">\n';
      }
      
      var bAdvanced = OVTop.isAdvSelMode();
      strHTML += '<input type=hidden name="OV.TypeFilter" value="'         +toTag(OVTop.getSelectedTypes(bAdvanced))+'">\n';
      if (bAdvanced)
      {
         strHTML += '<input type=hidden name="OV.NameFilter" value="">\n';
      }
      else
      {
         strHTML += '<input type=hidden name="OV.NameFilter" value="'         +toTag(OVTop.m_nameFilter)+'">\n';
      }
      
      iman.debugOV("in OVTitle.switchMode() Before document.PostData.target='Results' in document with title="+document.title);
      document.PostData.target="Results";
      iman.debugOV("in OVTitle.switchMode() After setting target = Results: document.PostData.target = "+document.PostData.target); 
      iman.debugOV("OVTitle::switchMode: URL="+strURL);
//      window.alert("Waiting to launch results window.")
      iman.debugOV("OVTitle::switchMode: HTML="+strHTML);
//      window.alert("Waiting to launch results window. html="+strHTML);
      var postDataForm = OVTop.Results.PostData;
      if(!postDataForm){
       postDataForm = document.PostData;
      }
      postDataForm.action=strURL;
      var formDataDiv =  document.getElementById("FormData");
      formDataDiv.innerHTML = strHTML;
	  postDataForm.submit();
      iman.debugOV("OVTitle::switchMode: After Results=postDataForm");
   }
   
   function setupTabs(newMode)
   {
      iman.debugOV("in OVTitle.setupTabs(newMode=\""+newMode+"\"");
      //set up tab images
      document.getElementById("searchGif").src=((newMode==SEARCH_MODE)?ACTIVE_SEARCH:INACTIVE_SEARCH);
      document.getElementById("browseGif").src=((newMode==BROWSE_MODE)?ACTIVE_BROWSE:INACTIVE_BROWSE);
      document.getElementById("treeGif").src=((newMode==TREE_MODE)?ACTIVE_TREE:INACTIVE_TREE);
      
      //set up tab hints
      document.getElementById("searchGif").alt=((newMode==SEARCH_MODE)?"":SWITCH_TO_SEARCH_HINT);
      document.getElementById("browseGif").alt=((newMode==BROWSE_MODE)?"":SWITCH_TO_BROWSE_HINT);
      document.getElementById("treeGif").alt=((newMode==TREE_MODE)?"":SWITCH_TO_TREE_HINT);
   }
   
   function titleOnLoad()
   {
   	iman.debug("OVTitle: OVTop.m_mode="+OVTop.m_mode);
      setupTabs(OVTop.m_mode.toLowerCase());
	if(OVTop.m_mode=="tree")
	{
		OVTop.m_mode="browse";
		switchMode("tree");
	}else{
		switchMode(OVTop.m_mode);
	}
   }
   
   function showHint()
   {
      OVTop.Results.resetHint();
      alert("<iman:toScript><iman:string key="OS.Browser.ClickToSelectRange" /></iman:toScript>");
   }

</script>
</HEAD>

<body id=BodyData bgcolor="#EFEEEC" onLoad="javascript:OVTop.titleLoaded=true;titleOnLoad()" style="background: #efeeec url('<iman:moduleUrl/>/fw/images/1px_tab_bg.gif') repeat-x; background-position: 0 0;" >
<bgsound id="sound">
<div style="position:absolute;top:0;left:0">
<table align=bottom align=left cellspacing=0 cellpadding=0 border=0>
   <tr>
   <script>
   	  document.writeln('<td><a href="javascript:switchMode(TREE_MODE)"><img id="browseGifFile"  style="display:none" src="'+TABS_BROWSE+'" border=0></a></td>');
      document.writeln('<td><a href="javascript:switchMode(TREE_MODE)"><img id="treeGif" src="'+INACTIVE_TREE+'" border=0></a></td>');
      document.writeln('<td><a href="javascript:switchMode(BROWSE_MODE)"><img id="browseGif" src="'+INACTIVE_BROWSE+'" border=0></a></td>');
      document.writeln('<td><a href="javascript:switchMode(SEARCH_MODE)"><img id="searchGif" src="'+INACTIVE_SEARCH+'" border=0></a></td>');
   </script>
      <td width=16 align=right valign=middle onclick="showHint();">
         <c:set var="hintImage"><iman:moduleUrl/>/dev/images/<iman:string key="Icon.Bulb16.image" /></c:set>
         <c:set var="hintMsg"><iman:string key="OS.Browser.ClickToSelectRange" /></c:set>
         <span id="multiselectHint" style="display:none"><img src="${hintImage}" alt="${hintMsg}" title="${hintMsg}" border=0></span>
      </td>
   </tr>
</table>
</div>

<form name=PostData method=post action="webacc?fw_fromRespId="+fw_respId target="">
<span id=FormData>
   <!-- switchMode will use innerHTML to dynamically create the input fields here -->
</span>
</form>
</body>  
</HTML>
