<%@ 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.*"%>
<%@ 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 (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 getPartnerOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	com.etixpert.evolution.gui.servlets.PartnerType[] pms = FormHelper.getPartnerTypes();

	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("partner_type_id", session).equals(pms[i].partner_id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].partner_id + "\">"+pms[i].partner_descr+"</option>");
	}
	return sb.toString();
}


public String getLevelOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	com.etixpert.evolution.gui.servlets.Level[] pms = FormHelper.getDistLevels();
	
	String curr_level_id = (String)session.getAttribute("original_level_id");
	
	for (int i = 0; i < pms.length; i++) {
		if ("400".equals(curr_level_id) && (pms[i].id.equals("330") || pms[i].id.equals("350") || pms[i].id.equals("370"))) continue;
		if ("300".equals(curr_level_id) && pms[i].id.equals("350")) continue;
		if ("330".equals(curr_level_id) && !pms[i].id.equals("330")) continue;
		if ("370".equals(curr_level_id) && !pms[i].id.equals("370")) continue;
		if ("350".equals(curr_level_id) && !pms[i].id.equals("350")) continue;
		String selected="";
		if (getVal("level_id", session).equals(pms[i].id + ":" + pms[i].subtype_id)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ pms[i].id + ":" + pms[i].subtype_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 getVal(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("user_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("user_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>
<%
	boolean admin = false;
	boolean distributor = false;
	boolean customer = false;
	if	(session.getAttribute("admin")!=null) admin = true;
	if	(session.getAttribute("customer")!=null) customer = true;
		if	(session.getAttribute("distributor")!=null) distributor = true;
%>
<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 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 showHidePartner() {
	//if (document.all['partner_type_id'].value==2) {
	if (1 > 2) {
		 document.all['partner_network_select'].style.display='block';
		 document.all['no_select'].style.display='none';
 	} else {
     	document.all['no_select'].style.display='block';
		document.all['partner_network_select'].style.display='none';
	}
}	

function showHideDiscount() {
	if (document.all['level_id'].value=='300:0' || document.all['level_id'].value=='300:1') {
		 document.all['dealer_select'].style.display='block';
		 document.all['dealer_gh_select'].style.display='none';
		 document.all['dealer_h_select'].style.display='none';
		 document.all['dealer_a_select'].style.display='none';
		 document.all['sconto_select'].style.display='none';
		 //document.all['no_dealer_select'].style.display='none';
		 document.forms[0].transferbonus.checked = false;
		 document.forms[0].transferbonus.disabled = true;
 	} else if (document.all['level_id'].value=='350:0') {
		 document.all['dealer_gh_select'].style.display='block';
		 document.all['dealer_select'].style.display='none';
		 document.all['dealer_h_select'].style.display='none';
		 document.all['dealer_a_select'].style.display='none';
		 document.all['sconto_select'].style.display='block';
		 //document.all['no_dealer_select'].style.display='none';
		 document.forms[0].transferbonus.checked = false;
		 document.forms[0].transferbonus.disabled = true;
 	}
 	else if (document.all['level_id'].value=='330:0') {
		 document.all['dealer_gh_select'].style.display='none';
		 document.all['dealer_select'].style.display='none';
		 document.all['dealer_h_select'].style.display='block';
		 document.all['dealer_a_select'].style.display='none';
		 document.all['sconto_select'].style.display='block';
		 //document.all['no_dealer_select'].style.display='none';
		 document.forms[0].transferbonus.checked = false;
		 document.forms[0].transferbonus.disabled = true;
	}
 	else if (document.all['level_id'].value=='370:0') {
		 document.all['dealer_gh_select'].style.display='none';
		 document.all['dealer_select'].style.display='none';
		 document.all['dealer_a_select'].style.display='block';
		 document.all['dealer_h_select'].style.display='none';
		 document.all['sconto_select'].style.display='block';
		 //document.all['no_dealer_select'].style.display='none';
		 document.forms[0].transferbonus.checked = false;
		 document.forms[0].transferbonus.disabled = true;
	}
	else {
     	//document.all['no_dealer_select'].style.display='block';
		document.all['dealer_select'].style.display='none';
		document.all['sconto_select'].style.display='none';
		document.all['dealer_gh_select'].style.display='none';
		document.all['dealer_h_select'].style.display='none';
		document.all['dealer_a_select'].style.display='none';
		document.forms[0].transferbonus.disabled = false;
	}
}
	
// -->
</SCRIPT>
</head>
<body onload="showHidePartner(); showHideDiscount();">
<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">
    <%
    	String curr_level_id = (String)session.getAttribute("original_level_id");
    	String showBonus = ("400".equals(curr_level_id)) ? "true":"false";
    %>
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="showBonus" value="<%=showBonus%>"/>
	<jsp:param name="self_id" value="1240"/>
	<jsp:param name="parent_id" value="1200"/>	
</jsp:include>
</table>
<form action="process/user_detail_int.jsp" method="post">
<input type="hidden" name="saveState"/>
<input type="hidden" name="link" value="process/user_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="LAST_STATUS"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><%=getVal("statusdate", session)%></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="LAST_BUY"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><%=getVal("last_order_date", session)%></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>
    <% if (!((String)session.getAttribute("CURRENT_DISTRIBUTOR_ID")).equals("0")) {%>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="SPONSOR"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields">
          <% 
    	String loggedID = (String)session.getAttribute("USER_LOGGED_ID");
    	if (loggedID.equals("0") || loggedID.equals("43000500")) { %>
       
        <input type="text" name="sponsor_name" value="<%=getVal("sponsor", session)%>" id="medium" onChange="sponsor_name_changed();"/>&nbsp;&nbsp;<select name="sponsor" onChange="sponsor_changed();">
        <%=getDistributorOptions(session)%>
        </select>
    <% 
		} else { %>
        <input type="text" name="sponsor_name" value="<%=getVal("sponsor", session)%>" id="medium" onChange="sponsor_name_changed();" readonly />&nbsp;&nbsp;<select name="sponsor_disabled" disabled>
        <%=getDistributorOptions(session)%>
        </select>
        <input type="hidden" name="sponsor" value="<%=getVal("sponsor", session)%>"/>
		<% } %>
        
        </td>
    </tr>
    <%}%>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="DISTRIBUTOR_TYPE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><select name="level_id" onchange="showHideDiscount();"><%=getLevelOptions(session)%>
        </select></td>
    </tr>    
    </table>
	<div id="partner_network_select" style="display:none;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <tr>
      <td width="518" height="30" valign="top" id="userTableContentTitles"><fmt:message key="ANNUAL_FEE"/>:&nbsp;&nbsp;&nbsp;<input name="annual_fee" type="checkbox" class="checkbox"<%=getChecked("annual_fee", session)%>></td>
      <td width="282" valign="top" id="userTableContentFields">&nbsp;</td>
    </tr>
    </table>	
	</div>
	<div id="no_select" style="display:none;">
	</div>    
	<div id="dealer_select" style="display:none;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <% java.util.List defLevels = (java.util.List)session.getAttribute("def_discount_levels");
         String logged_id = (String)session.getAttribute("USER_LOGGED_ID");
     	boolean ro = !"0".equals(logged_id);
		for (int h = 0; h < defLevels.size(); h++) {
			DefaultDiscountLevel ddl = (DefaultDiscountLevel)defLevels.get(h);    
     %>

    <tr>
      <td width="202" height="30" valign="top" id="userTableContentTitles"><fmt:message key="DISCOUNT_RATE"/> &#35;<%=ddl.getLevelId().intValue()%>:</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top" id="userTableContentFields"><input <%=ro?"readonly":""%> maxlength="8" id="little" type="text" name="personal_discount_<%=(h+1)%>" value="<%=getVal("personal_discount_"+(h+1), session)%>">&nbsp;&nbsp;&nbsp;<%=ddl.toString()%></td>
    </tr>
    
    <%
    	}
    %>
    </table>	
	</div>
	<div id="dealer_h_select" style="display:none;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
	     <% java.util.List defHLevels = (java.util.List)session.getAttribute("def_discount_levels_handler");
		for (int h = 0; h < defHLevels.size(); h++) {
			DefaultDiscountLevel ddl = (DefaultDiscountLevel)defHLevels.get(h);    
     %>
    <tr>
      <td width="202" height="30" valign="top" id="userTableContentTitles"><fmt:message key="DISCOUNT_RATE"/>:</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top" id="userTableContentFields"><input <%=ro?"readonly":""%> maxlength="8" id="little" type="text" name="h_personal_discount_<%=(h+1)%>" value="<%=getVal("h_personal_discount_"+(h+1), session)%>"></td>
    </tr>
    <%
    	}
    %>
    </table>	
	</div>	
	<div id="dealer_a_select" style="display:none;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
	     <% java.util.List defALevels = (java.util.List)session.getAttribute("def_discount_levels_apotheker");
		for (int h = 0; h < defALevels.size(); h++) {
			DefaultDiscountLevel ddl = (DefaultDiscountLevel)defALevels.get(h);    
     %>
    <tr>
      <td width="202" height="30" valign="top" id="userTableContentTitles"><fmt:message key="DISCOUNT_RATE"/>:</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top" id="userTableContentFields"><input <%=ro?"readonly":""%> maxlength="8" id="little" type="text" name="a_personal_discount_<%=(h+1)%>" value="<%=getVal("a_personal_discount_"+(h+1), session)%>"></td>
    </tr>
    <%
    	}
    %>
    </table>	
	</div>	
	<div id="dealer_gh_select" style="display:none;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
     <% java.util.List defGHLevels = (java.util.List)session.getAttribute("def_discount_levels_grosshandler");
		for (int h = 0; h < defGHLevels.size(); h++) {
			DefaultDiscountLevel ddl = (DefaultDiscountLevel)defGHLevels.get(h);    
     %>

    <tr>
      <td width="202" height="30" valign="top" id="userTableContentTitles"><fmt:message key="DISCOUNT_RATE"/>:</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top" id="userTableContentFields"><input <%=ro?"readonly":""%> maxlength="8" id="little" type="text" name="gh_personal_discount_<%=(h+1)%>" value="<%=getVal("gh_personal_discount_"+(h+1), session)%>">&nbsp;&nbsp;&nbsp;<%=ddl.toStringWithOnlyDefault()%></td>
    </tr>
    <%
    	}
    %>
    </table>	
	</div>
	<div id="no_dealer_select" style="display:none;">
	</div>
	<div id="sconto_select" style="display:block;">
	<table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <tr>
      <td width="202" height="30" valign="top" id="userTableContentTitles"><fmt:message key="SCONTO_DAYS"/>:</td>
      <td width="40">&nbsp;</td>
      <td width="558" valign="top" id="userTableContentFields"><input <%=ro?"readonly":""%> maxlength="8" id="little" type="text" name="sconto_days" value="<%=getVal("sconto_days", session)%>"></td>
    </tr>    
    </table>	
	</div>		
</form>
</body>
</html>