<%@ page language="java" session="true" contentType="text/html;charset=ISO-8859-2" %>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ page import="com.etixpert.evolution.app.bonus.*"%>
<%@ page import="org.apache.log4j.*"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link href="css/evolution.css" rel="stylesheet" type="text/css">
<link href="dtree.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- JavaScript code hiding
	function simpleLink(origLink) {
		parent.mainFrame.location = origLink;
	}

	function link(origLink){
		if (top.mainFrame.document.forms.length == 0) {
			simpleLink(origLink);
			return;
		}
		else {
			if (top.mainFrame.document.forms[0].saveState == null) {
				simpleLink(origLink); 
				return;
			}
			top.mainFrame.document.forms[0].saveState.value = top.mainFrame.self.location.pathname;
			top.mainFrame.document.forms[0].link.value = origLink;
			top.mainFrame.document.forms[0].submit();
		}
	}
	
	function clickhandler(id) {
		var dateval = top.mainFrame.document.forms[0].date
		open('process/bonusdetails.jsp?pageAction=bonus_details&saveState=nothing&link=process/bonusdetails.jsp&distr_id=-' + id + '&date=' + dateval.options[dateval.selectedIndex].text, '_blank', '')
	}
	
// -->
</SCRIPT>
</head>
<body>

<div align="center"><h5>GENEALOGIE</h5></div>
<%
	String userLoggeds = (String)session.getAttribute("USER_LOGGED_ID");
	Integer userLogged = new Integer(userLoggeds);
	Integer distrId    = (Integer)session.getAttribute("ORG_DISTRIBUTOR_INTEGER");
	int     dateval    = 0;
	java.util.Calendar cDate = (java.util.Calendar) session.getAttribute("ORG_DATE");
	if (cDate != null) {
		dateval = cDate.get(java.util.Calendar.YEAR) * 12 + 
		          cDate.get(java.util.Calendar.MONTH);
	}
%>
<form action="process/organization.jsp" method="post" onsubmit="top.mainFrame.link('process/organization.jsp')">

<input type="hidden" name="saveState"/>
<input type="hidden" name="link"/>
<input type="hidden" name="pageAction" value="org_count"/>

<div align="center">
  <table>
    <col width="130"/>
    <col width="100"/>
    <tr>
      <td><fmt:message key="ROOT_ID"/>:</td>
      <td><input type="text" name="distr_id" size="10" value="<%=distrId != null ? distrId : userLogged.intValue() < 1000000 ? new Integer(0) : userLogged %>"/></td>
    </tr>
    <tr>
      <td><fmt:message key="DATE"/>:</td>
      <td>
        <select name="date">
        <% 
          	java.util.Calendar cal = java.util.Calendar.getInstance();
          	int val = cal.get(java.util.Calendar.YEAR) * 12 + cal.get(java.util.Calendar.MONTH);
          	while (val > 2012 * 12 + 8) {
          		out.println("<option" + (dateval == val ? " selected" : "") + ">" +
          				   ("" + (101 + val % 12)).substring(1) + "." + val / 12 + "</option>");
          		val--;
          	}
        %>  
        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="button" style="width:100%" value="OK" onClick="top.mainFrame.link('process/organization.jsp');"/>
      </td>
    </tr>
  </table>
</div>
</form>

<%
  if (distrId != null && cDate != null) {
	out.println(BonusList.generate(distrId, userLogged, cDate.getTime(), BonusList.TYPE_ORGANIZATION, pageContext.getServletContext().getRealPath("WEB-INF")));
	session.setAttribute("ORG_DISTRIBUTOR_INTEGER", null);
} %>
</body>
</html>