<%@ 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 getShippingOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	Shipping[] pms = FormHelper.getShippings();
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if ("2".equals(pms[i].id)) continue;
		if (getVal("shipping_id", session).equals(pms[i].id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].id + "\">"+pms[i].value+"</option>");
	}
	return sb.toString();
}

public String getLevelOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	com.etixpert.evolution.gui.servlets.Level[] pms = FormHelperC.getLevels();
	
	for (int i = 0; i < pms.length; i++) {
		if (!pms[i].id.equals("100") && 
			!pms[i].id.equals("130") &&
			!pms[i].id.equals("160") &&
			!pms[i].id.equals("200")) 
			continue;
		String selected="";
		if (getVal("level_id", session).equals(pms[i].id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].id + "\">"+pms[i].value+"</option>");
	}
	return sb.toString();
}

public String getDistributorOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	DistributorMin[] pms = FormHelper.getDistMin_wp_od();
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("sponsor", session).equals(pms[i].id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].id + "\">"+pms[i].fullname+", "+pms[i].id+", "+pms[i].beraterArt+"</option>");
	}
	return sb.toString();
}

public String getCustomerDistributorOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	DistributorMin[] pms = FormHelperC.getDistMin_oc();
	sb.append("<option value=\"no_sel\"></option>");
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("customer_sponsor", session).equals(pms[i].id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].id + "\">"+pms[i].fullname+", "+pms[i].id+", "+pms[i].beraterArt+"</option>");
	}
	return sb.toString();
}
	
public String getVal(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("new_customer_detail_int.jsp");
	if (m == null) return "";
	String[] vals = (String[])m.get(name);
	if (vals != null && vals.length>0 && vals[0] != null) return vals[0];
	return "";
}

public String getChecked(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("new_customer_detail_int.jsp");
	if (m == null) return "";
	String[] vals = (String[])m.get(name);
	if (vals != null && vals.length>0 && vals[0] != null) return " checked";
	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
	function changeSel(which){
		window = open("leftMenu.jsp?sel="+which, "_self", "");
	}

	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 sponsor_changed() {
	dfv = document.forms[0].sponsor
	document.forms[0].sponsor_name.value = dfv.options[dfv.selectedIndex].value
}

function customer_sponsor_changed() {
	dfv = document.forms[0].customer_sponsor
	document.forms[0].customer_sponsor_name.value = dfv.options[dfv.selectedIndex].value
	if (document.forms[0].customer_sponsor_name.value == "no_sel") {
		document.forms[0].customer_sponsor_name.value = ""
	}
}

function sponsor_name_changed() {
	dfv = document.forms[0].sponsor
	for (i = 0; i < dfv.length; i++) {
		if (dfv.options[i].value == document.forms[0].sponsor_name.value) {
			dfv.selectedIndex = i
			return
		}
	}
	alert("Ung\374ltige Sponsornummer (eventuell ein VIP/Kunde)!")
	document.forms[0].sponsor_name.focus()
	document.forms[0].sponsor_name.select()
}

function customer_sponsor_name_changed() {
	dfv = document.forms[0].customer_sponsor
	if (document.forms[0].customer_sponsor_name.value == "") {
		dfv.selectedIndex = 0;
		return;
	}
	for (i = 0; i < dfv.length; i++) {
		if (dfv.options[i].value == document.forms[0].customer_sponsor_name.value) {
			dfv.selectedIndex = i
			return
		}
	}
	alert("Ung\374ltige Geworben nummer (eventuell ein Berater)!")
	document.forms[0].customer_sponsor_name.focus()
	document.forms[0].customer_sponsor_name.select()
}

// -->
</SCRIPT>
</head>
<body bgcolor="#e6e6ee">
<table border="1" id="userTable" class="menu">
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="self_id" value="2140"/>
	<jsp:param name="parent_id" value="2100"/>	
</jsp:include>
</table>
<form action="process/new_customer_detail_int.jsp" method="post">
<input type="hidden" name="saveState"/>
<input type="hidden" name="link" value="process/new_customer_detail_int.jsp"/>
  <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <!--DWLayoutTable-->
    <tr> 
      <td width="202" height="30" valign="top" id="userTableContentTitles"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="DEACTIVED"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input name="active" type="checkbox" class="checkbox" value="<%=getVal("active", session)%>"<%=getChecked("active", session)%>></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="PRINTLOCK"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input name="printlock" type="checkbox" class="checkbox" value="<%=getVal("printlock", session)%>"<%=getChecked("printlock", session)%>></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="CUSTOMER_SERVICE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input name="customer_service" type="checkbox" class="checkbox" value="<%=getVal("customer_service", session)%>"<%=getChecked("customer_service", session)%>></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="NEWSLETTER"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input name="newsletter" type="checkbox" class="checkbox" value="<%=getVal("newsletter", session)%>"<%=getChecked("newsletter", session)%>></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="UID"/>:</td>
      <td width="34">&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="vat_id" value="<%=getVal("vat_id", session)%>"></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="TRANSFER_BONUS"/> </td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input name="transferbonus" type="checkbox" class="checkbox"<%=getChecked("transferbonus", session)%>></td>
    </tr>    
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="SHIPPING_TYPE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><select name="shipping_id"><%=getShippingOptions(session)%>
        </select></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="HOMEPAGE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="homepage" value="<%=getVal("homepage", session)%>"></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="SPONSOR"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"> 
        <input type="text" name="sponsor_name" id="medium" value="<%=getVal("sponsor", session)%>" onChange="sponsor_name_changed();"/>&nbsp;&nbsp;<select name="sponsor" onChange="sponsor_changed();">
        <%=getDistributorOptions(session)%>
        </select></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="GEWORBEN"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"> 
        <input type="text" name="customer_sponsor_name" value="<%=getVal("customer_sponsor", session)%>" id="medium" onChange="customer_sponsor_name_changed();"/>&nbsp;&nbsp;<select name="customer_sponsor" onChange="customer_sponsor_changed();">
        <%=getCustomerDistributorOptions(session)%>
        </select></td>
    </tr>    
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="CUSTOMER_TYPE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><select name="level_id"><%=getLevelOptions(session)%>
        </select></td>
    </tr>
    <tr> 
      <td height="89">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
