<%@ page errorPage="errorPage.jsp" language="java" session="true" contentType="text/html;charset=ISO-8859-2" %>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>	
<%!
public String getQMOptions(HttpSession session) throws Exception {
	StringBuffer sb = new StringBuffer("");
	String[] pms = new String[] {"PV","EV","PEV","TV","OV"};
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("q_metric", session).equals(pms[i])) selected=" selected";	
		sb.append("<option"+selected+" value=\""+ pms[i] + "\">"+pms[i]+"</option>");
	}
	return sb.toString();
}

public String getCMOptions(HttpSession session) throws Exception {
	StringBuffer sb = new StringBuffer("");
	String[] pms = new String[] {"PV","EV","PEV","TV","OV"};
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("calc_metric", session).equals(pms[i])) selected=" selected";	
		sb.append("<option"+selected+" value=\""+ pms[i] + "\">"+pms[i]+"</option>");
	}
	return sb.toString();
}

public String getCVTOptions(HttpSession session) throws Exception {
	StringBuffer sb = new StringBuffer("");
	String[] pms = new String[] {"%","wert"};
	String[] vs = new String[] {"0","1"};
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("calc_value_type", session).equals(vs[i])) selected=" selected";	
		sb.append("<option"+selected+" value=\""+ vs[i] + "\">"+pms[i]+"</option>");
	}
	return sb.toString();
}

	
public String getVal(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("user_detail_bonus.jsp");
	if (m == null) return "";
	String[] vals = (String[])m.get(name);
	if (vals != null && vals.length>0 && vals[0] != null) return vals[0];
	return "";
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="main.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- JavaScript code hiding
var dtCh2= ".";
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var emptyString = /^\s*$/

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate2(dtStr) {
	if (dtStr.length!=6) return false

	var strMonth=dtStr.substring(4)
	var strYear=dtStr.substring(0,4)

	if (isInteger(strMonth)==false) return false;
	if (isInteger(strYear)==false) return false;

	if (parseInt(strMonth)>12) return false;
	if (parseInt(strMonth)<1) return false;

	if (parseInt(strYear)>2200) return false;
	if (parseInt(strYear)<1900) return false;

	return true

}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.forms[0].valid_to
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

function comp(from, to) {

	var fromMonth=from.substring(4)
	var fromYear=from.substring(0,4)

	var toMonth = to.substring(4)
	var toYear = to.substring(0,4)
	
	
	
	if (parseInt(fromYear)>parseInt(toYear)) return false;
	if (parseInt(fromYear)<parseInt(toYear)) return true;
	if (parseInt(fromMonth)>parseInt(toMonth)) return false;
	
	return true

}

function valid_from_check() {
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.forms[0].valid_from;
  var elem1 = document.forms[0].valid_to;
  
  if (!isDate2(elem.value)) {
      alert("Bitte geben Sie den Zeitraum im Format JJJJMM ein (gültig von)!");
      return false;  
  }

	if (emptyString.test(elem1.value)) {
		elem1.value = '210012';	
	} else {
		if (!isDate2(elem1.value)) {
	      alert("Bitte geben Sie den Zeitraum im Format JJJJMM ein (gültig bis)!");			
	      return false;
		}
	}

	if (!comp(elem.value, elem1.value)) {
		alert("Gültig bis muss grösser als gültig von sein!");
		return false;
	}

  return true;
}


	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();
		}
	}
// -->
</SCRIPT>
</head>
<body>
<div width="800" height="30" align="left" class="menu"><%=FormHelper.generateUserDataHeaderString(pageContext)%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="menu" href="process/user_selection.jsp">Anderen Vetriebspartner auswählen</a></div>
<table border="1" id="userTable" class="menu">
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="self_id" value="1260"/>
	<jsp:param name="parent_id" value="1200"/>	
</jsp:include>
</table>
<form action="process/user_detail_bonus.jsp" method="post">
<input type="hidden" name="row"/>
<input type="hidden" name="saveState"/>
<input type="hidden" name="pageAction"/>
<input type="hidden" name="link" value="process/user_detail_bonus.jsp"/>
 <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
<tr>
<td colspan="6" height="30">&nbsp;</td>
</tr>
  <tr> 
      <td height="30" width="200" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
    <% java.util.List defLevels = (java.util.List)session.getAttribute("def_discount_levels");
		int last = 0;
		for (int h = 0; h < defLevels.size(); h++) {
			DefaultDiscountLevel ddl = (DefaultDiscountLevel)defLevels.get(h);
			if (h == defLevels.size()-1) {
				last = ddl.getBorder().intValue();
			}    
     %>

		<td colspan="1" id="userTableContentFields" width="60">&lt; <%=ddl.getBorder().intValue()%></td>    
    <%
    	}
    %>
    	<td colspan="1" id="userTableContentFields" width="60">&ge; <%=last%></td>
      <td colspan="1" valign="top" id="userTableContentFields">&nbsp;</td>
  </tr>
  <tr> 
      <td height="30" width="200" valign="top" id="userTableContentTitles"><fmt:message key="DISTR_BONUS"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="db0" value="<%=getVal("db0", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="db1" value="<%=getVal("db1", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="db2" value="<%=getVal("db2", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="db3" value="<%=getVal("db3", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="db4" value="<%=getVal("db4", session)%>"></td>
      <td colspan="1" valign="top" id="userTableContentFields">0 &le; n &le; 100</td>
  </tr>
   <tr height="20"></tr>
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="TEAM_BONUS_Q"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="tbq" value="<%=getVal("tbq", session)%>"></td>
      <td colspan="5" id="userTableContentFields">&nbsp;</td>
  </tr>  
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="TEAM_BONUS_1"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t1b1" value="<%=getVal("t1b1", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t1b2" value="<%=getVal("t1b2", session)%>"></td>
      <td colspan="2" id="userTableContentFields"><input id="little" type="text" name="t1b3" value="<%=getVal("t1b3", session)%>"></td>
      <td colspan="2" valign="top" id="userTableContentFields">0 &le; n &le; 100</td>
  </tr>
  <tr height="20"></tr>
  <tr> 
      <td height="30" width="200" valign="top" id="userTableContentTitles"><fmt:message key="TEAM_BONUS_2"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t2b1" value="<%=getVal("t2b1", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t2b2" value="<%=getVal("t2b2", session)%>"></td>
      <td colspan="2" id="userTableContentFields"><input id="little" type="text" name="t2b3" value="<%=getVal("t2b3", session)%>"></td>
      <td colspan="2" valign="top" id="userTableContentFields">0 &le; n &le; 100</td>
  </tr>
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="T2_L1_CRITERIA"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t2_level1_criteria" value="<%=getVal("t2_level1_criteria", session)%>"></td>
      <td colspan="5" id="userTableContentFields">&nbsp;</td>
  </tr>
  <tr height="20"></tr>   
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="TEAM_BONUS_3"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t3b1" value="<%=getVal("t3b1", session)%>"></td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t3b2" value="<%=getVal("t3b2", session)%>"></td>
      <td colspan="2" id="userTableContentFields"><input id="little" type="text" name="t3b3" value="<%=getVal("t3b3", session)%>"></td>
      <td colspan="2" valign="top" id="userTableContentFields">0 &le; n &le; 100</td>
  </tr>
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="T3_L1_CRITERIA"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t3_level1_criteria" value="<%=getVal("t3_level1_criteria", session)%>"></td>
      <td colspan="5" id="userTableContentFields">&nbsp;</td>
  </tr> 
  <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="T3_L2_CRITERIA"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="1" id="userTableContentFields" width="60"><input id="little" type="text" name="t3_level2_criteria" value="<%=getVal("t3_level2_criteria", session)%>"></td>
      <td colspan="5" id="userTableContentFields">&nbsp;</td>
  </tr> 
  <tr height="20"></tr>
  
  <tr> 
    <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><fmt:message key="BONUS_FROM"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="4" id="userTableContentFields" ><input value="<%=getVal("valid_from", session)%>" type="text" name="valid_from" id="medium">&nbsp;<fmt:message key="YYYYMM"/></td>
	  <td colspan="2" valign="top" id="userTableContentFields">&nbsp;</td>
  </tr> 
  <tr> 
      <td height="30" width="200" valign="top" id="userTableContentTitles"><fmt:message key="BONUS_TO"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="4" id="userTableContentFields" ><input value="<%=getVal("valid_to", session)%>" type="text" name="valid_to" id="medium">&nbsp;<fmt:message key="YYYYMM"/></td>
      <td colspan="2" valign="top" id="userTableContentFields">&nbsp;</td>
  </tr>   
  <tr> 
      <td height="30" width="200" valign="top" id="userTableContentTitles"><fmt:message key="BONUS_DESCRIPTION"/>:</td>
      <td colspan="1" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="4" id="userTableContentFields" width="250"><input value="<%=getVal("descr", session)%>" type="text" name="descr" style="width: 250px"></td>
      <td colspan="2" valign="top" id="userTableContentFields">&nbsp;</td>
  </tr>
    <tr> 
      <td height="30" width="200"  valign="top" id="userTableContentTitles"><a onClick="javascript:return valid_from_check();" href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'user_add_bonus'; link('process/user_detail_bonus.jsp');">
      <%
          String logged_id = (String)session.getAttribute("USER_LOGGED_ID");
     	  boolean ro = "0".equals(logged_id);
     	  if (ro) {
      %>
      <%=FormHelper.underMod(session, "user_bonuses")?"Modifikation übernehmen":"Hinzufügen"%>
      <%
      }
      %>
      </a></td>
      <td colspan="5" width="40" valign="top" id="userTableContentFields">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields">&nbsp;</td>
  </tr>
  </table>
  <br>
<!--<div class="sortable" id="1" style="margin-left: 10px;">-->
    <table width="905px" id="mainTable" cellpadding="2">
      <col width="35"><col width="80"><col width="150"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="40"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="40"><col width="40">
      <tr>
      <td id="accountTableHeaderContent"><fmt:message key="M"/></td>
       <td id="accountTableHeaderContent"><fmt:message key="VALID"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="BONUS_DESCRIPTION"/></td>
      <td id="accountTableHeaderContent">bb0</td>
	  <td id="accountTableHeaderContent">bb1</td>
      <td id="accountTableHeaderContent">bb2</td>
      <td id="accountTableHeaderContent">bb3</td>
      <td id="accountTableHeaderContent">bb4</td>
      <td id="accountTableHeaderContent">tbq</td>
      <td id="accountTableHeaderContent">te11</td>
      <td id="accountTableHeaderContent">te12</td>
      <td id="accountTableHeaderContent">te13</td>
      <td id="accountTableHeaderContent">te21</td>
      <td id="accountTableHeaderContent">te22</td>
      <td id="accountTableHeaderContent">te23</td>
	  <td id="accountTableHeaderContent">e1b</td>      
      <td id="accountTableHeaderContent">te31</td>
      <td id="accountTableHeaderContent">te32</td>
      <td id="accountTableHeaderContent">te33</td>
      <td id="accountTableHeaderContent">e1b</td>
      <td id="accountTableHeaderContent">e2b</td>

</tr>
<!--</table>
<DIV STYLE="overflow: auto; width: 925px; height: 200px;
            border-left: 0px gray solid; border-bottom: 0px gray solid;
            padding:0px; margin: 0px;">
      <table border="0" cellpadding="0" cellspacing="0" width="925px" class="sortable" id="mainTable" cellpadding="2" >      
      <col width="35"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="40"><col width="40"><col width="40"><col width="40"><col width="40">
      <col width="80"><col width="150">-->
 <%=com.etixpert.evolution.gui.servlets.FormHelper.generateBonusTableRows2(session, "user_bonuses")%>
</table>
</DIV></DIV>  
 <form>
</body>
</html>