<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>

<%@ taglib uri="struts-html" prefix="html"%>
<%@ taglib uri="struts-bean" prefix="bean"%>
<%@ taglib uri="struts-logic" prefix="logic"%>
<%@ taglib uri="vkc-taglib" prefix="vkc"%>
<%@ page import="vkc.view.TabId"%>
<%@ page import="org.apache.struts.Globals"%>
<vkc:checkLogin />
<vkc:init />
<html:html locale="true">
<head>
	<vkc:cssinclude />

	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
	<script type="text/javascript" src="<vkc:rewrite page='/common/calendar.js'/>"></script>
	<script type="text/javascript" src="<vkc:rewrite page='/common/tiny_mce/tiny_mce.js'/>"></script>
	

	<script type="text/javascript">
    window.name = "MAINVIEW";
	initTinyMCE("<vkc:write name='user' property='language.shortName'/>", "<vkc:rewrite page='/templates/${template.name}/tiny_mce.css'/>");

    var currentCalendar = null;
    var associatedTabId = <%=TabId.ADMIN_LICENSE_TAB%>;

    function init() {
        var tabView = getTabView();
        var tabViewForm = tabView.document.forms[0];

        if (tabView && tabView.systemviewtype == "administrationview" && tabView.selectedTabId != associatedTabId) {
            tabView.location.replace("<%=ctxPath%>/adminTabView.do?selectedTabId=<%=TabId.ADMIN_LICENSE_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }
		
		setAnchor();
	}
    	
    function setAnchor(){
    	<logic:present parameter="anchor">
			<bean:parameter id="anchor2" name="anchor"/>
			this.location.hash = '<%=anchor2%>';				
		</logic:present>
    }
       
    function unloadPage() {
        if ( currentCalendar!=null ) {
              hideCalendar();
        }
    }
    
	function toggleTinyMCEToolbar() {
        var form = document.forms[0];
    	<logic:equal name="newLicenseForm" property="showTinyMCEToolbar" value="true">
    	form.showTinyMCEToolbar.value = 'false';
    	</logic:equal>
    	<logic:equal name="newLicenseForm" property="showTinyMCEToolbar" value="false">
    	form.showTinyMCEToolbar.value = 'true';
    	</logic:equal>
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.toggle.tinymcetoolbar=true";
        } else {
          form.action = form.action + "&action.toggle.tinymcetoolbar=true";
        }
        
        form.submit();
    }
    
    function showLicense(id) {
        var form = document.forms[0];
        form.selectedId.value = id;
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.show.license=true";
        } else {
          form.action = form.action + "&action.show.license=true";
        }
        
        form.submit();
    }
    
    function hideLicense(id) {
        var form = document.forms[0];
        form.selectedId.value = id;
        
        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.hide.license=true";
        } else {
          form.action = form.action + "&action.hide.license=true";
        }
        
        form.submit();
    }
    </script>
</head>

<body onload="init();" onUnload="unloadPage();" topmargin="0" marginheight="0">
<table cellspacing="3" cellpadding="0" border="0" width="100%">
  <tr>
    <td width="1%" nowrap="nowrap"><b><vkc:message key="vkc.administration.license.newlicense" /></b></td>
    <td width="99%" align="right" nowrap="nowrap" align="right">&nbsp;<vkc:message key="mandatory.field1" />&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0" />&nbsp;<vkc:message key="mandatory.field2" /></td>
  </tr>
</table>

<vkc:hline bottomSpace="5" topSpace="5" colspan="2" lineClass="hline" lineHeight="1" />

<table width="100%" cellspacing="3" cellpadding="0" border="0">
  <html:form action="/newLicense" method="post">

  <bean:define id="form" name="newLicenseForm" scope="request" type="vkc.administration.form.NewLicenseForm" />

  <vkc:hidden name="form" property="selectedId" />

  <logic:iterate id="did" name="form" property="selectedIds" type="java.lang.Integer">
  <html:hidden property="selectedIds" name="form" value='<%=String.valueOf(did.toString())%>' />
  </logic:iterate>

  <vkc:hidden property="showTinyMCEToolbar" />

  <logic:equal name="form" property="tinyMCECompatible" value="true">
  <logic:equal name="form" property="showTinyMCEToolbar" value="false">
	<style type="text/css">
    .mceToolbar {
      display:none;
    }
    </style>
  </logic:equal>
  </logic:equal>

  <logic:present name="<%=Globals.ERROR_KEY%>">
  <tr><td align="left" nowrap="nowrap" colspan="2"><font color="red"><b><vkc:errors/></b></font></td></tr>
  </logic:present>

  <tr>
	<td width="1" nowrap="nowrap" valign="top"><b><vkc:message key="vkc.administration.license.terms" />:</b></td>
  </tr>

  <logic:iterate id="language" indexId="index" name="form" property="languages" type="vkc.db.entities.VKCLanguage">
  <tr>
    <td valign="top"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="20" height="20" border="0" alt="" /></td>
  </tr>
  <tr>
    <td valign="top"><b><vkc:message name="language" property="name_key"/>:</b>&nbsp;<vkc:img page="/templates/${template.name}/gfx/mandatoryField.gif" alt="*" border="0" /></td>
	<logic:equal name="form" property='<%= "showLicenseForLanguage[" + language.getLanguageId() + "]" %>' value="false">
    <td width="100%" colspan="15">
      <table cellspacing="3" cellpadding="0" border="0" width="100%">
        <tr>
          <td align="left" valign="top" width="46" nowrap>
            <vkc:link href='<%= "javascript:showLicense(" + language.getLanguageId() + ");" %>'>
              <vkc:img page="/templates/${template.name}/gfx/plus-big.gif" border="0" titleKey="vkc.tooltip.show.license.language" />
            </vkc:link>
          </td>
        </tr>
		<tr style="display:none;">
          <td><vkc:textarea property='<%=String.valueOf("dynaValue(languageId_" + language.getLanguageId() + ")")%>'></vkc:textarea></td>
        </tr>
      </table>
    </td>
    </logic:equal>

    <logic:equal name="form" property='<%= "showLicenseForLanguage[" + language.getLanguageId() + "]" %>' value="true">
    <td width="100%" colspan="15">
      <a name='<%= language.getLanguageId() %>'></a>
      <table cellspacing="3" cellpadding="0" border="0" width="100%">
        <tr>
          <td align="left" valign="top" width="46" nowrap>
            <vkc:link href='<%= "javascript:hideLicense(" + language.getLanguageId() + ");" %>'>
              <vkc:img page="/templates/${template.name}/gfx/minus-big.gif" border="0" titleKey="vkc.tooltip.hide.license.language" />
            </vkc:link>
          </td>
        </tr>
        <tr>
          <td width="100%">
            <logic:equal name="form" property="tinyMCECompatible" value="true">
            <logic:equal name="form" property="showTinyMCEToolbar" value="true">
              <vkc:link href="javascript:toggleTinyMCEToolbar();">
                <vkc:img page="/templates/${template.name}/gfx/minus-big.gif" border="0" titleKey="vkc.string.htmleditor" />
              </vkc:link>
            </logic:equal>
            <logic:equal name="form" property="showTinyMCEToolbar" value="false">
              <vkc:link href="javascript:toggleTinyMCEToolbar();">
                <vkc:img page="/templates/${template.name}/gfx/plus-big.gif" border="0" titleKey="vkc.string.htmleditor" />
              </vkc:link>
            </logic:equal>
            </logic:equal>
            <vkc:textarea property='<%=String.valueOf("dynaValue(languageId_" + language.getLanguageId() + ")")%>' style="width:100%;" cols="57" rows="10"></vkc:textarea>
          </td>
        </tr>
      </table>
    </td>
    </logic:equal>
  </tr>
  </logic:iterate>

  <vkc:hline bottomSpace="5" topSpace="0" colspan="2" lineClass="hline" lineHeight="1" />
  
  <tr>
    <td width="1" nowrap="nowrap"><b><vkc:message key="vkc.administration.license.validfrom" />:</b></td>
    <td width="100%">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><html:text name="form" property="validFrom" maxlength="10" size="10" styleClass="dateField" /></td>
          <td><vkc:calendarbutton buttonName="btn_validFrom" /></td>
          <td>&nbsp;<vkc:message key="vkc.date_format" /></td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td width="1" nowrap="nowrap"><b><vkc:message key="vkc.administration.license.validuntil" />:</b></td>
    <td width="100%">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><html:text name="form" property="validUntil" maxlength="10" size="10" styleClass="dateField" /></td>
          <td><vkc:calendarbutton buttonName="btn_validUntil" /></td>
          <td>&nbsp;<vkc:message key="vkc.date_format" /></td>
        </tr>
      </table>
    </td>
  </tr>

  <vkc:hline bottomSpace="5" topSpace="5" colspan="2" lineClass="hline" lineHeight="1" />

  <tr>
    <td colspan="2" align="center">
      <vkc:button property="action.save.license" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.save" /></vkc:button>
      <vkc:button property="action.back" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.back" /></vkc:button>
    </td>
  </tr>
  </html:form>
</table>
</body>
</html:html>