<%@ page errorPage="errorPage.jsp" language="java" session="true" contentType="text/html;charset=ISO-8859-2" %>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>
<%
	response.setLocale(Locale.GERMAN);
	response.setContentType("text/html; charset=iso-8859-2");
	request.setCharacterEncoding("ISO-8859-2");
%>
<%!
	public String getArticleGroupOptions(HttpSession session) throws Exception{
		StringBuffer sb = new StringBuffer("");
		ArticleGroup[] ag = FormHelper.getArticleGroups();
		
		for (int i = 0; i < ag.length; i++) {
			String selected="";
			if (getVal("art_group_id", session).equals(ag[i].id)) selected=" selected";
			sb.append("<option"+selected+" value=\""+ ag[i].id + "\">"+ag[i].value+"</option>");
			
		}
		return sb.toString();
	}
	
	public String getVatOptions(HttpSession session) throws Exception{
		StringBuffer sb = new StringBuffer("");
	
		for (int i = 1; i < 6; i++) {
			String selected="";
			if (getVal("vat_id", session).equals(String.valueOf(i))) selected=" selected";
			sb.append("<option"+selected+" value=\""+ String.valueOf(i) + "\">"+String.valueOf(i)+"</option>");		
		}
		return sb.toString();
	}
	
	
	public String getArticleIDOptions(HttpSession session) throws Exception{
		StringBuffer sb = new StringBuffer("");
		String[] ids = FormHelper.getArticleIDs();
		
		for (int i = 0; i < ids.length; i++) {
			String selected="";
			String ff = ids[i].substring(0, ids[i].indexOf(","));
			if (getVal("art_id", session).equals(ff)) selected=" selected";
			sb.append("<option"+selected+" value=\""+ ff + "\">"+ids[i]+"</option>");
			
		}
		return sb.toString();
	}
	
	
	public String getChecked(String name, HttpSession session) {
		Map m = (Map)session.getAttribute("article_detail.jsp");
		if (m == null) return "";
		String[] vals = (String[])m.get(name);
		if (vals != null && vals.length>0 && vals[0] != null) return " checked";
		return "";
	}
	
	public String getVal(String name, HttpSession session) {
		Map m = (Map)session.getAttribute("article_detail.jsp");
		if (m == null) return "";
		String[] vals = (String[])m.get(name);
		if (vals != null && vals.length>0 && vals[0] != null) return vals[0];
		return "";
	}
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link href="main.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- JavaScript code hiding
	function simpleLink(origLink) {
		window = open(origLink, "mainFrame", "");
	}
	
		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 rlink(origLink, aid){
		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].artId.value = aid;
		top.mainFrame.document.forms[0].pageAction.value = 'load_article';
		top.mainFrame.document.forms[0].submit();
	}
		
	function comma(s){
		var i;
	    for (i = 0; i < s.length; i++){ 
		    var c = s.charAt(i);  
			if (c == ",") return true;
	    }
	    return false;
	}

	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 checkDate(dtStr) {
		if (dtStr.length==0) return true;
		var dtCh = "."
		if (dtStr.length!=10) return false
	
		var pos1=dtStr.indexOf(dtCh)
		if (pos1==-1){
			return false
		}
	
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		
		if (pos2==-1){
			return false
		}
		
		
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
	
		if (isInteger(strDay)==false) return false;
		if (isInteger(strMonth)==false) return false;
		if (isInteger(strYear)==false) return false;
	
		var intDay   = parseInt(strDay, 10);
		var intMonth = parseInt(strMonth, 10);
		var intYear  = parseInt(strYear, 10);
		
		if (intDay>31) return false;
		if (intDay<1) return false;
		
		if (intMonth>12) return false;
		if (intMonth<1) return false;
	
		if (intYear>2100) return false;
		if (intYear<1900) return false;
	
		var today = new Date();
		var thisDay   = today.getDate();
		var thisMonth = today.getMonth() + 1;
		var thisYear  = today.getFullYear();
		
		if (intYear > thisYear) return true;
		if (intYear < thisYear) return false;
		if (intMonth > thisMonth) return true;
		if (intMonth < thisMonth) return false;
		if (intDay >= thisDay) return true;
	
		return false;
	}


	function valid_check() {
	
	  if (!document.getElementById) 
	    return true;  // not available on this browser - leave validation to the server
	  var elem = document.forms[0].netto;
	  var elem1 = document.forms[0].netto_customer;
	  var elem2 = document.forms[0].netto_vip_customer;
	  var elem3 = document.forms[0].netto_handler;
	  var elem4 = document.forms[0].bonus;
	  var elem5 = document.forms[0].order_price;
	  var elem6 = document.forms[0].netto_silver_customer;
	  var elem7 = document.forms[0].netto_gold_customer;
	  var elem8 = document.forms[0].valid_to;
	
	  if (comma(elem.value)) {
	      alert("Zahlenformat ist nicht korrekt: Netto. Komma bitte als Punkt eingeben!");
	      return false;  
	  }
	
	  if (comma(elem1.value)) {
	      alert("Zahlenformat ist nicht korrekt: Netto Kunde. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	  if (comma(elem2.value)) {
	      alert("Zahlenformat ist nicht korrekt: Netto VIP Kunde. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	
	  if (comma(elem3.value)) {
	      alert("Zahlenformat ist nicht korrekt: Bonus. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	
	  if (comma(elem4.value)) {
	      alert("Zahlenformat ist nicht korrekt: Bonus. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	  if (comma(elem5.value)) {
	      alert("Zahlenformat ist nicht korrekt: Einkaufspreis. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	  
	  if (comma(elem6.value)) {
	      alert("Zahlenformat ist nicht korrekt: Netto Silber Kunde. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	
	  if (comma(elem7.value)) {
	      alert("Zahlenformat ist nicht korrekt: Netto Gold Kunde. Komma bitte als Punkt eingeben!");
	      return false;
	  }
	  
		if (!checkDate(elem8.value)) {
			alert("Bitte geben Sie den Zeitraum im Format TT.MM.JJJJ ein (Date bis)! Das Datum muss grösser gleich heute sein, maximal 31.12.2100!");
			return false;
		}
	
	  return true;
	}

// -->
</SCRIPT>
</head>
<%
	boolean admin = false;
	boolean distributor = false;
	boolean customer = false;
	boolean ordp = "0".equals((String)session.getAttribute("USER_LOGGED_ID"));
	if	(session.getAttribute("admin")!=null) admin = true;
	if	(session.getAttribute("customer")!=null) customer = true;
		if	(session.getAttribute("distributor")!=null) distributor = true;
	boolean combi = true;

	String focusBoolean = "false";
	String checkStr = getChecked("combi", session);
	if (checkStr.equals("")) {
		focusBoolean = "true";
		combi = false;
	}
%>

<body>
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="self_id" value="none"/>
	<jsp:param name="parent_id" value="4300"/>	
</jsp:include>
<form action="process/article_detail.jsp" method="post">
<input type="hidden" name="saveState"/>
<input type="hidden" name="artId"/>
<input type="hidden" name="id" value="<%=session.getAttribute("CURRENT_ARTICLE_ID")%>"/>
<input type="hidden" name="link" value="process/article_detail.jsp"/>
<input type="hidden" name="pageAction"/>
<input type="hidden" name="row"/>
<div width="900" height="30" align="left" class="menu">&nbsp;&nbsp;&nbsp;<a class="menu" href="process/article_selection.jsp">Anderen Artikel auswählen</a></div>
  <table width="900" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <tr> 
      <td height="30" colspan="2" valign="top" id="userTableContentTitles"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td width="40">&nbsp;</td>
      <td colspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="ART_ID"/>:</td>
      <td></td>
      <td colspan="5" valign="top" id="userTableContentFields"><%=session.getAttribute("CURRENT_ARTICLE_ID")%></td>
      <input type="hidden" name="art_id" value="<%=session.getAttribute("CURRENT_ARTICLE_ID")%>"/>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="ARTICLE_DESCRIPTION"/>:</td>
      <td></td>
      <td colspan="5" valign="top" id="userTableContentFields"><input type="text" maxlength="50" id="comment" name="descr" value="<%=getVal("descr", session)%>"></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="GROUP"/>:</td>
      <td>&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><select name="art_group_id"><%=getArticleGroupOptions(session)%>
        </select></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input type="netto" id="medium" maxlength="8" name="netto" value="<%=getVal("netto", session)%>"></td>
      <td valign="top" id="userTableContentTitles"><fmt:message key="VAT"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><select name="vat_id"><%=getVatOptions(session)%></select></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_CUSTOMER"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input id="medium" name="netto_customer" maxlength="8" type="text" value="<%=getVal("netto_customer", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>  </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_SILVER_CUSTOMER"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input id="medium" name="netto_silver_customer" maxlength="8" type="text" value="<%=getVal("netto_silver_customer", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_GOLD_CUSTOMER"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input id="medium" name="netto_gold_customer" maxlength="8" type="text" value="<%=getVal("netto_gold_customer", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_VIP_CUSTOMER"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input id="medium" name="netto_vip_customer" maxlength="8" type="text" value="<%=getVal("netto_vip_customer", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>    </tr>
   <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_HANDLER"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input maxlength="8" id="medium" type="text" name="netto_handler" value="<%=getVal("netto_handler", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>
    </tr>    
   <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="NETTO_GROSS_HANDLER"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input maxlength="8" id="medium" type="text" name="netto_grosshandler" value="<%=getVal("netto_grosshandler", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields">&nbsp;</td>
    </tr>    
   <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="BONUS"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input type="text" id="medium" maxlength="8" name="bonus" value="<%=getVal("bonus", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields"></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="INVENTORY"/>:</td>
      <td>&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input type="text" id="medium" maxlength="8" name="inventory" value="<%=getVal("inventory", session)%>"></td>
      <td valign="top" id="userTableContentTitles"><fmt:message key="MINIMUM_INVENTORY"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" id="medium" maxlength="8" name="minimum_inventory" value="<%=getVal("minimum_inventory", session)%>"></td>
    </tr>
    <%
    	if (ordp) {
    %>
   <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="ORDER_PRICE"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input type="text" id="medium" maxlength="8" name="order_price" value="<%=getVal("order_price", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields"></td>
    </tr>
    <%
    	}
    %> 
    <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="VALID_TO"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="2" valign="top" id="userTableContentFields"><input type="text" id="medium" maxlength="10" title="31.12.2100 ist der Standardwert!" name="valid_to" value="<%=getVal("valid_to", session)%>"></td>
      <td width="116" valign="top" id="userTableContentTitles">&nbsp;</td>
      <td width="26">&nbsp;</td>
      <td width="363" valign="top" id="userTableContentFields"></td>
    </tr>
	<tr>
      <td width="172" height="110" valign="top" id="userTableContentTitles">Lieferant:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="400" name="supplier" rows="6" cols="80"><%=getVal("supplier", session)%></textarea></td>
	</tr>
	<tr>
      <td width="172" height="110" valign="top" id="userTableContentTitles">Alternativer Lieferant:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="400" name="supplier_alt" rows="6" cols="80"><%=getVal("supplier_alt", session)%></textarea></td>
	</tr>
	<tr>
      <td width="172" height="110" valign="top" id="userTableContentTitles">Gebinde:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="400" name="supplier_container" rows="6" cols="80"><%=getVal("supplier_container", session)%></textarea></td>
	</tr>
	<tr>
      <td width="172" height="50" valign="top" id="userTableContentTitles">Etiketten:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="150" name="supplier_labels" rows="2" cols="80"><%=getVal("supplier_labels", session)%></textarea></td>
	</tr>
	<tr>
      <td width="172" height="50" valign="top" id="userTableContentTitles"><fmt:message key="SUPPLIER_OVER_CARTON"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="150" name="supplier_over_carton" rows="2" cols="80"><%=getVal("supplier_over_carton", session)%></textarea></td>
	</tr>
	<tr>
      <td width="172" height="60" valign="top" id="userTableContentTitles">Sonstiges:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><textarea maxlength="400" name="supplier_other" rows="3" cols="80"><%=getVal("supplier_other", session)%></textarea></td>
	</tr>
    <tr>
    <td colspan="7" height="30">&nbsp</td>
    </tr>   
  <!--   <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="COMBI_ARTICLE"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><input value="yes" onFocus="top.mainFrame.document.forms[0].combi.checked=<%=focusBoolean%>;top.mainFrame.document.forms[0].saveState.value='process/article_detail.jsp';top.mainFrame.document.forms[0].submit();" class="checkbox" type="checkbox" name="combi" <%=checkStr%> value="<%=getVal("combi", session)%>"></td>
    </tr> -->
    <tr>
<% if (false) { %>
    </tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="ARTICLE"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan="5" valign="top" id="userTableContentFields"><select name="cart_id"><%=getArticleIDOptions(session)%>
        </select></td>
    </tr>
    <tr>
      <td width="172" height="30" valign="top" id="userTableContentTitles"><fmt:message key="QUANTITY"/>:</td>
      <td width="30">&nbsp;</td>
      <td colspan=5><input type="text" id="little" maxlength="4" name="quantity" value="<%=getVal("quantity", session)%>"></td>
    </tr>
    <tr>
    <td height="30">&nbsp</td>
    <td>&nbsp;</td>
    <td colspan="5" id="userTableContentFields"><a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'add_combi_content'; link('process/article_detail.jsp');">
      <%=FormHelper.underMod(session, "combi_articles")?"Modifikation übernehmen":"Hinzufügen"%>
      </a></td>
    </tr>
    <% } %>    
  </table>
<% if (false) { %>
<div class="sortable" id="1" style="margin-left: 10px;">
    <table width="500px" id="mainTable">
      <col width="30"><col width="30"><col width="80"><col width="270"><col width="80">
      <tr>
	      <td id="accountTableHeaderContent"><fmt:message key="M"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="L"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="ARTICLE"/></td>      
		  <td id="accountTableHeaderContent"><fmt:message key="ARTICLE_DESCRIPTION"/></td>
		  <td id="accountTableHeaderContent"><fmt:message key="QUANTITY"/></td>		  
</tr>
</table>
<DIV STYLE="overflow: none; width: 500px; border-left: 0px gray solid; border-bottom: 0px gray solid;
            padding:0px; margin: 0px;">
      <table border="0" cellpadding="0" cellspacing="0" width="500px" class="sortable" id="mainTable">      
      <col width="30"><col width="30"><col width="80"><col width="270"><col width="80">
       <%=com.etixpert.evolution.gui.servlets.FormHelper.generateCombiTableRows(session, "combi_articles")%>
</table>
</DIV></DIV>
<br>
<% } %>
<table width="800" id="userDetailsTable" class="normal">
<tr>
<td height="50" id="userTableContentFields">
&nbsp;&nbsp;&nbsp;<a onClick="javascript:return valid_check();" href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'article_modify'; link('process/article_detail.jsp');">
<fmt:message key="SAVE_MOD"/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="javascript:rlink('process/article_detail.jsp', '<%=session.getAttribute("CURRENT_ARTICLE_ID")%>');">
<fmt:message key="ARTICLE_REVERT"/>
</a></td>
</tr>
<tr>
<td id="userTableContentFields">&nbsp;&nbsp;&nbsp;
<%
	if (session.getAttribute("ARTICLE_MODIFIED")!=null) {
		out.print(" Änderung wurde erfolgreich durchgeführt!");
		session.setAttribute("ARTICLE_MODIFIED", null);
	}
%>
</td>
</tr>
</table>
</form>
</body>
</html>
