<%@page contentType="text/html;charset=UTF-8"%>
<%--
 ******************************************************************************* 
 * $RCSfile: CopyMoveWizard1.jsp,v $
 *
 * Description: 
 *
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
 * Use of this product is subject to license terms.
 *
 *******************************************************************************
 * Source Code Control System - Header
 *
 * $Header: /sgnome/cvsroots/jds/apoc/web/manager/jsp/profiles/CopyMoveWizard1.jsp,v 1.5 2006/01/20 11:46:47 slewis Exp $
 *******************************************************************************
--%> 
<%@ page language="java" %> 
<%@ page import="com.iplanet.jato.view.ViewBean" %>
<%@taglib uri="/jato.tld" prefix="jato"%> 
<%@taglib uri="/cc.tld" prefix="cc"%>

<!--
  // The wizard framework provides a javascript object instance
  // called WizardWindow_Wizard. This object has methods that
  // allow the pagelet to disable/enable buttons and set the
  // page's initial focus.
  //
  // References to the methods of WizardWindow_Wizard if not conditional
  // during runtime, that must result in effects when the page is displayed
  // must be placed in a Javascript function and that function name
  // must be assigned to WizardWindow_Wizard.pageInit.
  // The framework will call WizardWindow_Wizard.pageInit() after the
  // wizard tag has been rendered.
  //
  // script statements must appear within at least the first
  // <td> element since HTML validation objects to the appearance
  // of <script> betwee the <table> element and the first <tr>
  // element.
-->
<jato:pagelet>

<cc:i18nbundle id="apocBundle"
 baseName="com.sun.apoc.manager.resource" />
 
<!-- Legend: required field indicator -->
<cc:legend name="Legend" bundleID="apocBundle"/>

<%-- For now assume we're still presenting the components in a table
     which is output by the framework and components are
     in rows and cells
--%>


<tr>
    <td valign="top" align="right" rowspan="1" colspan="1">
    <script type="text/javascript" src="/apoc/js/MainWindow.js"></script>
        <script type="text/javascript">
        function wizardPageInit() {
                WizardWindow_Wizard.setFocusElementName(
                    "WizardWindow.Wizard.CopyMoveWizard1.ContextBrowseButton");
                verifyRequiredField();
        }
        function verifyRequiredField() {
            var f = WizardWindow_Wizard.formName;
            var desc = ccGetElement(
                    "WizardWindow.Wizard.CopyMoveWizard1View.NewSelectedProfile", f);

            if (desc == null) {
                WizardWindow_Wizard.setNextButtonDisabled(false, null);
            } else {
                 if (desc.value.length != 0) {
                     WizardWindow_Wizard.setNextButtonDisabled(false, null);
                 } else {
                     WizardWindow_Wizard.setNextButtonDisabled(true, null);             
                 }
             }
          }
            WizardWindow_Wizard.pageInit = wizardPageInit;

            function openProfileSearchWindow() {
                var searchContextName = document.wizWinForm['WizardWindow.Wizard.CopyMoveWizard1View.SelectedContext'].value;
                openWindow(window, null, '/apoc/manager/ProfilesSearchIndex?SearchContextName=' + searchContextName, 'searchProfileWindow', 0.6, 500);
            }
            
            function openSelectContextWindow(contextName, sessionConstant) {
                openWindow(window, null, '/apoc/manager/SelectContext?ContextName='+ contextName + '&SessionConstant=' + sessionConstant, 'selectContextWindow', 0.6, 500);
            }
            
            function profileSearchCallback(sProfileId) {
                sProfileId = sProfileId.split('&com_sun_web_ui_popup=true')[0];
                document.wizWinForm['WizardWindow.Wizard.CopyMoveWizard1View.NewSelectedProfile'].value = sProfileId;
                refreshPagelet()
            }
            
            function selectContextCallback(newContext) {
                var oldContext = document.wizWinForm['WizardWindow.Wizard.CopyMoveWizard1View.SelectedContext'].value;
                if (oldContext != newContext) {
                    document.wizWinForm['WizardWindow.Wizard.CopyMoveWizard1View.NewSelectedProfile'].value = "";
                }
                refreshPagelet()
            }
            
            function refreshPagelet() {
                var f=document.wizWinForm;
                var link = document.links['WizardWindow.Wizard.tabs.TabHref'];
                if (link != null) {
                    var href = link.href;
                    var re = /(TabHref=(\d))/;
                    var found = href.match(re);
                    re = /(=(\d))/;
                    var num = found[0].match(re);
                    
                    var tabnum = new Number(num[0].substring(1, num[0].length));
                    if (tabnum == 1) {
                        re = /(TabHref=\d)/;
                        var newHref = href.replace(re, 'TabHref=0');
                        f.action = newHref;
                        f.submit()
                    } else if (tabnum == 0) {
                        re = /(TabHref=\d)/;
                        var newHref = href.replace(re, 'TabHref=1');
                       f.action = newHref;
                        f.submit()
                    }
                }
            }
            var m_OpenerTop = top.opener;
            while (m_OpenerTop.top.opener!=null) {
                m_OpenerTop = m_OpenerTop.top.opener;
            }
            m_OpenerTop = m_OpenerTop.top;

            setInterval("setWindowHandle()", 1000);
            function setWindowHandle() {
                m_OpenerTop.m_CopyMoveWindow= top;
            }
        </script>
        <cc:hidden name="NewSelectedProfile" />
        <cc:hidden name="SelectedContext" />
        <cc:label name="SourceContextLabel" styleLevel="2"
            elementName="SourceContextLabel"
            defaultValue="APOC.wiz.copy.source.context"
            showRequired="true"
            bundleID="apocBundle"/>
    </td>
    <td valign="top" align="left" rowspan="1" colspan="1">
        <cc:text name ="SourceContext" bundleID="apocBundle" />
    </td>
    <td valign="top" align="left" rowspan="1" colspan="1">
        <cc:button  name="ContextBrowseButton"
                bundleID="apocBundle" 
                defaultValue="APOC.profilewnd.general.browse"
                type="secondary"
                />
    </td>
</tr>
<tr>
    <td valign="top" align="left" rowspan="1" colspan="1">
        <cc:label name="SourceProfileLabel" styleLevel="2"
            elementName="SourceContextLabel"
            defaultValue="APOC.wiz.copy.source.profile"
            showRequired="true"
            bundleID="apocBundle"/>
    </td>
    <td valign="top" align="left" rowspan="1" colspan="1">
        <cc:text name ="SourceProfile" bundleID="apocBundle" />
    </td>
    <td valign="top" align="left" rowspan="1" colspan="1">
        <cc:button  name="ProfileBrowseButton"
                bundleID="apocBundle" 
                defaultValue="APOC.profilewnd.general.browse"
                type="secondary"
                onClick="javascript:openProfileSearchWindow(); return false;"
     />
    </td>
</tr>
</jato:pagelet>
