<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit2, com.novell.emframe.dev.eMFrameUtils" %>
<%   JSPConduit2 c = JSPConduit2.getJSPConduit(request);

     c.stringTable("DevResources"); %>

<!-- BEGIN Simple (default) OSScripts.inc -->
<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/OSSimpleScripts.js" ></script>
<jsp:include page='<%= c.getPath("dev/XmlScripts_inc.jsp") %>' flush="true" />
<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/QueryScripts.js" ></script>
<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/exchanger.js"></SCRIPT>
<script language="JavaScript" src="<%= c.getModulesUrl() %>/fw/javascripts/AnchorPosition.js"></script>
<SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/fw/javascripts/HistoryScripts.js" ></script>
<script>
   var isReturningFromOS = ("<%= c.var("OS.ReturningToAnchor") %>"=="true");

   window.osWidth=<%= c.string("OS.Simple.WindowWidth") %>;
   window.osHeight=<%= c.string("OS.Simple.WindowHeight") %>;

   function returnFromOS(osControl, osResults, osCallBack)
   {
      var isWindowed = (arguments.length>0);
      var docState = null;

      if (!isWindowed)
      {
         // being called from the onLoad returnFromOS() call
         osCallBack = "<%= c.toScript(c.var("OS.CallBack")) %>";
         osControl  = "<%= c.toScript(c.var("OS.Control")) %>";
         osResults  = "<%= c.toScript(c.var("OS.Results")) %>";
         docState   = "<%= c.toScript(c.var("OS.AnchorDocState")) %>";
      }
      //alert("returnFromOS:\n   osControl = "+osControl+"\n   osCallBack = "+osCallBack+"\n   osResults = "+osResults+"\n   docState = "+docState+"\n   isWindowed = "+isWindowed+"\n  isReturningFromOS = "+isReturningFromOS);

      if (isWindowed || isReturningFromOS)
      {
         try
         {
            //1.  restore the document to the state it was in before calling the OS
            if (docState != null && docState.length != 0)
            {
               //extract document state values and set them
               restoreDocStateInfo(docState);
            }

            //2.  now process the os results
            if (osResults!=null && osResults.length>0)
            {
               // turn the one returned value into an array for compatibility with browser mode
               var osResultsArray = new Array(1);
               osResultsArray[0] = osResults;

               //process the os results that have been returned
               if (osCallBack.length>0)
               {
                  if (exists(osCallBack))
                  {
                     //let the callback routine process the os results
                     var command = osCallBack+"('"+toScript(osControl)+"',osResultsArray)";

                     try
                     {
                        eval( command );
                     }
                     catch(e)
                     {
                        //specified callback does not exist
                        alert("returnFromOS:  ERROR -- Specified task callback '"+osCallBack+"' failed."+
                              "\n\nCannot return the selected object(s) = "+osResults +
                              "\n\nException = "+e);
                     }
                  }
                  else
                  {
                     //specified callback does not exist
                     alert("returnFromOS:  ERROR -- Specified task callback '"+osCallBack+"' does not exist."+
                           "\n\nCannot return the selected object(s) = "+osResults);
                  }
               }
               else
               {
                  //just store the search results in the specified control
                  if (osControl != null)
                  {
                     setElementValue(osControl, osResults);
                  }
               }
            }
         }
         finally
         {
            //3.  call task's post OS function
            if (exists("postOS")) postOS(osControl);
         }
      }
   }
</script>
<!-- clear local variables used in os.inc-->
<jsp:include page='<%= c.getPath("dev/ClearFlags_inc.jsp") %>' flush="true" />
<% c.set("OS.Results", "");
   c.set("OS.AnchorDocState", "");
   c.set("OS.URLUniqueID", ""); %>
<!-- END Simple OSScripts.inc -->
