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

   BaseGadgetInstance bgi = (BaseGadgetInstance) request.getAttribute("BGI");
   boolean showRepeat = false;
   boolean refreshOV = false;

   if(bgi != null)
   {
      if(bgi.repeatable && bgi.getRepeatParams() != null)
      {
         showRepeat = true;
      }

      String refreshOVs = c.var("dev.refreshOV");
      if(refreshOVs.equals("true"))
      {
         refreshOV = true;
      }
   }

   c.stringTable("DevResources");
   c.stringTable("FwResources");

   if (c.var("GeneralMsg.Mode").equals("SuccessAndBack")) {
      c.set("GeneralMsg.Url", "Javascript:goBackOrClose();");
      c.set("GeneralMsg.Icon", "dev/success32.gif");
      c.set("GeneralMsg.Alt", c.string("Icon.Success.alt"));
   }

   if ( c.notdef("GeneralMsg.MsgBody")) {
      c.set("GeneralMsg.MsgBody", c.string("GeneralMsg.MsgBodyDefault"));
   }

   if (c.var("GeneralMsg.MsgTitle").equals("")) {
      c.set("GeneralMsg.MsgTitle", c.string("GeneralMsg.MsgTitleDefault"));
   }

   if (c.var("GeneralMsg.Titlebar").equals("")) {
      c.set("GeneralMsg.Titlebar", c.string("GeneralMsg.TitlebarDefault"));
   }

  /*If this is an error and its on the initial page, go back to home */
   if (c.var("GeneralMsg.Mode").equals("error") && c.var("nextState").equals("initialState")) {
      c.set("GeneralMsg.Mode", "fatal");
   }

   c.set("DefaultUrl", "webacc?NPService=fw.LaunchService&NPAction=Return&returnID=" + c.urlEncode((String) request.getAttribute("GI_ID")));

   if (c.var("GeneralMsg.Url").equals("")) {
      if (c.var("GeneralMsg.Mode").equals("success") || c.var("GeneralMsg.Mode").equals("fatal")) {
         if (c.var("GeneralMsg.Mode").equals("success")) {
            c.set("GeneralMsg.Url.default", "true");
         }
         c.set("GeneralMsg.Url", c.var("DefaultUrl"));
      } else if (c.var("GeneralMsg.Mode").equals("error")) {
         c.set("GeneralMsg.Url", "Javascript:goBackOrClose();");
      } else {
         c.set("GeneralMsg.Url", "Javascript:goBackOrClose();");
      }
   }
   if (c.var("GeneralMsg.Url").equals("webacc")) {
	   c.set("target", "target=_top");
   }

   if (c.var("GeneralMsg.Icon").equals("")) {
      if (c.var("GeneralMsg.Mode").equals("success")) {
         c.set("GeneralMsg.Icon", "dev/success32.gif");
         c.set("GeneralMsg.Alt", c.string("Icon.Success.alt"));
      } else if (c.var("GeneralMsg.Mode").equals("error") || c.var("GeneralMsg.Mode").equals("fatal")) {
         c.set("GeneralMsg.Icon", "dev/error32.gif");
         c.set("GeneralMsg.Alt", c.string("Icon.Error.alt"));
      }
   }

   if ( c.def("GeneralMsg.Error.Detail")) {
       c.set("GeneralMsg.Detail.Url", c.getModulesUrl() + "/fw/errors/en_us/" + c.var("GeneralMsg.Error.Detail"));
   } %>


<HTML>
<HEAD>
   <TITLE><%= c.var("GeneralMsg.Titlebar") %></TITLE>
   <LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
   <jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
   <SCRIPT>

   <% if(refreshOV) {%>
      function refreshOV(url)
      {
         win = parent;
         iman.debug("refreshOV called. win=parent parent.name="+parent.name);
         if(win)
         {
            win = win.ObjectView;
            if(win)
            {
               win = win.Refresh;
               if(win)
               {
                  win.location = "webacc?taskId=dev.Empty&merge=fw.OV.OVRefresh&refreshOV=true";
               }
            }else{ // not in object view
            	if(window.opener){ //if we are not in a popup window and since we already know we are not in the tree view, then don't try to refreshOV at all.
	            	iman.debug("window.opener.top.name = "+window.opener.parent.ObjectView.name);
	            	win=window.opener.parent.ObjectView;
	            	win.iman.debug("win..name="+win.name);
	            	win.refreshTV(url);
            	}
            	
            	
            }
         }
         window.location = url;
      }
   <% } %>

      function pageInit()
      {
			<% if(!c.var("GeneralMsg.suppressButtons").equals("true")){%>
            document.getElementById("okbutton").focus();
         <% } %>
      }

      function goBackOrClose()
      {
	      var len = "history.l" + "ength";
         if(eval(len) != 0)
         {
            <% if (c.var("GeneralMsg.Mode").equals("error") && c.var("nextState").equals("initialState")) { %>
               window.location = '<%= c.toScript(c.var("DefaultUrl")) %>';
            <% } else { %>
               history.back();
            <% } %>
         }
         else
         {
            window.close();
         }
      }

	<% if ( c.def("errorDetails")) { %>
		function showDetails()
		{
			var e = document.getElementById("trace");
         if (e!=null)
         {
            if (e.style.display=="block")
            {
               e.style.display="none";
            }
            else
            {
               e.style.display="block";
            }
         }
		}
	<% } %>
   </SCRIPT>
</HEAD>

<BODY TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF" onLoad="pageInit();" TOPMARGIN="10">
    <form name="form">
        <div class="head4">
            <% if (c.var("GeneralMsg.Icon").equals("") == false) { %>
                <img height="32" width="32"
                    src="<%= c.getUrl(c.var("GeneralMsg.Icon")) %>"
                    alt="<%= c.var("GeneralMsg.Alt") %>"
                    title="<%= c.var("GeneralMsg.Alt") %>"
                    align="absmiddle"><%/*--
          -- */    }   /*--

            -- */    if (c.var("GeneralMsg.Mode").equals("error") || c.var("GeneralMsg.Mode").equals("fatal")) {   /*--
                -- */%> <span class="typegold1"><% if (c.gt(c.length(c.var("GeneralMsg.MsgTitle")), "0")) { %><%= c.string("GeneralMsg.Error") %><% } else { %><%= c.string("GeneralMsg.ErrorNoTitle") %><% } %></span>
                <% if (c.var("GeneralMsg.Detail.Url").equals("") == false) { %>
                    <a href="<%= c.var("GeneralMsg.Detail.Url") %>" class="errorlink" target="errDetail"><%= c.var("GeneralMsg.MsgTitle") %></a>
                <% } else { %>
                    <span class="errorlink"><%= c.var("GeneralMsg.MsgTitle") %></span>
                <% }
               } else {   /*--
                -- */%> <FONT class="head4"><%/*--
                    -- */    if (c.var("GeneralMsg.Url.default").equals("true")) {   /*--
                        -- */%> <span class="typegold1"><%= c.string("GeneralMsg.TitlebarComplete") %></span>
                    <% } %>
                    <%= c.toDisplay(c.var("GeneralMsg.MsgTitle")) %>
                    <% if (c.var("GeneralMsg.countWarning").equals("") == false) { %>&nbsp;<A href="#" onClick="alert('<%= c.toDisplay(c.string("General.countTruncated")) %>')" style="color: #03399; text-decoration: underline;"><%= c.toDisplay(c.string("General.countWarningLink")) %></A><% } %>

                </FONT>
            <% } %>
        </div>

        <div>
        <p class="marginleft3">
            <% if ( c.def("GeneralMsg.MsgBodyPlainText") ||  c.def("GeneralMsg.UList")) {
                   c.set("GenMsg.BoldDisplay", (c.toDisplay(c.var("GeneralMsg.MsgBodyBoldText"))));
                   c.set("GenMsg.BoldMsg", c.plus(c.plus("<B>", c.var("GenMsg.BoldDisplay")), "</B>"));
                   c.set("GenMsg.PlainMsg", (c.toDisplay(c.var("GeneralMsg.MsgBodyPlainText"))));
				   if ( c.def("GeneralMsg.UList")) {
					   c.set("GenMsg.UList", "<UL class=\"marginleft4\">"); %>
					<%= c.listToArray(c.var("GeneralMsg.UList"), c.var("GeneralMsg.UListDelims"), "listItem") %>
					<% c.set("idx", "1");
					   while (c.lte(c.var("idx"), c.var("listItem.count"))) {
						   c.set("GenMsg.UList", c.plus(c.plus(c.plus(c.var("GenMsg.UList"), "<li>"), c.var("listItem."+c.var("idx"))), "</li>"));
						   c.inc("idx");
					   }
					   c.set("GenMsg.UList", c.plus(c.var("GenMsg.UList"), "</UL>"));
				   } %>
                <%= c.formatMessage(c.var("GenMsg.PlainMsg"), new String[]{c.var("GenMsg.BoldMsg"), c.var("GenMsg.UList")}) %>
            <% } else { 
                
                	String iManRewriteURLs = (String)request.getAttribute("iManRewriteURLs");
                	if(iManRewriteURLs != null && iManRewriteURLs.equalsIgnoreCase("false"))
                	{
                		out.print(c.var("GeneralMsg.MsgBody"));
                		request.removeAttribute("iManRewriteURLs");
                	}
                	else
                	{
                		%><%= c.toDisplay(c.var("GeneralMsg.MsgBody")) %><%
                	}
                %>
            <% }

               if ( c.def("GeneralMsg.MsgBodyPlainText2")) { %>
               <br>
               <br>
                <% c.set("GenMsg.BoldDisplay", (c.toDisplay(c.var("GeneralMsg.MsgBodyBoldText2"))));
                   c.set("GenMsg.BoldMsg", c.plus(c.plus("<B>", c.var("GenMsg.BoldDisplay")), "</B>"));
                   c.set("GenMsg.PlainMsg", (c.toDisplay(c.var("GeneralMsg.MsgBodyPlainText2")))); %>
                <%= c.formatMessage(c.var("GenMsg.PlainMsg"), new String[]{c.var("GenMsg.BoldMsg")}) %>
            <% }

			   if ( c.def("errorDetails")) { %>
					<br><br>
					<IMG type=image src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Details.image") %>"
						alt="<%= c.string("Button.Details.alt") %>"
						title="<%= c.string("Button.Details.alt") %>"
                  style="cursor:hand"
						id="btnDetails"
						onClick="showDetails()">
					<div id="trace" style="display:none">
                  <!-- inner html goes here -->

                  <table border=1><tr><td><code><%= c.toScript(c.var("errorDetails")) %></code></td></tr></table><br>
					</div>
			<% }
		      if (c.var("Error.name").equals("Cookie.missing")) { %>
			   <div>
				   <p class="marginleft3">

					<% c.set("GeneralMsg.MsgBody", c.formatMessage(c.string("AuthenticateFailed.SystemExplain"), new String[]{c.toDisplay(c.var("AuthenticateFailed.NoCookie"))})); %>

				   <%= c.toDisplay(c.var("GeneralMsg.MsgBody")) %>
				   <br><br>
				   <%= c.string("AuthenticateFailed.PleaseTryAgain") %>
            </div>
		   <% } %>

			<% if(!c.var("GeneralMsg.suppressButtons").equals("true")){%>

         <div id="bar" style="position;">
			<BR>
			<jsp:include page="Bar_inc.jsp" flush="true" />

			<%-- ------------------------------------------------------------------
			    GeneralMsg.Url should NOT be urlEncoded since those who pass it
			    to us should already have done so.  If we do, it causes problems
			 ------------------------------------------------------------------- --%>
			<a id=okbutton<%
            if (c.var("GeneralMsg.CloseWindow").equals("true"))
            {
               %> href="#" onClick="javascript: opener.location.href='<%= c.var("GeneralMsg.Url") %>'; window.close();"<%
            }
            else
            {
               if(!c.var("GeneralMsg.Javascript").equals(""))
               {
                  %> href="#" onClick="<%= c.var("GeneralMsg.Javascript") %>;window.location='<%= c.var("GeneralMsg.Url") %>';"<%
               }
               else if(c.var("GeneralMsg.Url.default").equals("true") && refreshOV)
               {
                  %> href="javascript:refreshOV('<%= c.var("GeneralMsg.Url") %>');" <%= c.var("target") %><%
               }
               else
               {
                  %> href="<%= c.var("GeneralMsg.Url") %>" <%= c.var("target") %><%
               }
            }
            %>><IMG alt="<%= c.string("Button.OK.alt") %>" title="<%= c.string("Button.OK.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.OK.image") %>" border=0></a><%

            if (c.var("GeneralMsg.Url.default").equals("true") && showRepeat)
            {
               %>&nbsp;<a href="webacc?realTaskId=<%= c.var("taskId") %>&taskId=fw.HandleRepeatTask"><IMG alt="<%= c.string("Button.RepeatTask.alt") %>" title="<%= c.string("Button.RepeatTask.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.RepeatTask.image") %>" border=0></a><%
            }
            if(c.var("GeneralMsg.ShowModifyObject").equals("true") && bgi.getGadgetAssignment().getJobAssignment() == null)
            {
               String taskId = c.var("GeneralMsg.ModifyObjectTaskId");
               if(taskId==null || taskId.length()==0)
               {
                  taskId = "fw.ModifyObject";
               }

               if(refreshOV)
               {
                  %>&nbsp;<a onClick="refreshOV('frameservice?eDir$target=<%= c.urlEncode(c.var("GeneralMsg.ModifyObjectName")) %>&NPService=fw.LaunchService&NPAction=Delegate&delegate=<%= taskId %>&launcher=<%= c.var("launcherId") %>&lifecycle=Recreate'); "><IMG alt="<%= c.string("Button.Modify.alt") %>" title="<%= c.string("Button.Modify.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Modify.image") %>" border=0></a><%               }
               else
               {
                  %>&nbsp;<a href="frameservice?eDir$target=<%= c.urlEncode(c.var("GeneralMsg.ModifyObjectName")) %>&NPService=fw.LaunchService&NPAction=Delegate&delegate=<%= taskId %>&launcher=<%= c.var("launcherId") %>&lifecycle=Recreate"><IMG alt="<%= c.string("Button.Modify.alt") %>" title="<%= c.string("Button.Modify.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Modify.image") %>" border=0></a><%
               }

            }

            if(c.var("GeneralMsg.ShowCancelButton").equals("true"))
            {
               %> <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" /><%
            }
            %>
         <BR>
		</div>

      <% } %>
	</div>
    </form>
</BODY></HTML>
