<%@ page language="java" session="true" contentType="text/html;charset=ISO-8859-2" %>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ page import="java.util.*"%>
<%@ page pageEncoding="UTF-8"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>
<%!
public String getPMOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	PM[] pms = FormHelper.getPMs();
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("pay_method_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 getVal(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("new_interessent_detail_add.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_interessent_detail_add.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 sWait() {
		 document.all['showWait'].style.display='block';
 		 document.all['noShowWait'].style.display='none';
	}
	
	function hWait() {
		 document.all['noShowWait'].style.display='block';
  		 document.all['showWait'].style.display='none';
	}
// -->
</SCRIPT>
</head>
<body bgcolor="#e6eee6" onLoad="hWait();">
<table border="1" id="userTable" class="menu">
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="self_id" value="2640"/>
	<jsp:param name="parent_id" value="2600"/>	
</jsp:include>
</table>
<form action="process/new_interessent_detail_add.jsp" method="post">
<input type="hidden" name="saveState"/>
<input type="hidden" name="pageAction"/>
<input type="hidden" name="link" value="process/new_interessent_detail_add.jsp"/>
  <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <!--DWLayoutTable-->
    <tr> 
      <td width="293" height="60" valign="top" id="userTableContentMainTitles"><fmt:message key="SELECT_OPTION"/>: </td>
      <td width="76">&nbsp;</td>
      <td width="431">&nbsp;</td>
    </tr>
    <tr>
      <td height="30">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <%
	   	boolean similar = false;
    	if (session.getAttribute("SIMILAR_INTERESSENTS")!=null) similar = true;    
    	boolean user_added = false;
    	if (session.getAttribute("NEW_INTERESSENT_ID")!=null) user_added = true;
    %>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles">
		<% if (user_added) {%>
		&nbsp;
		<% } 
		else if (similar) {%>
			<a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'new_interessent_add_anyway'; link('process/new_interessent_detail_add.jsp');" onClick="javascript:sWait();"><fmt:message key="ADD2"/></a>		
		<% }
		else { %>
	      <a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'new_interessent_add'; link('process/new_interessent_detail_add.jsp');" onClick="javascript:sWait();"><fmt:message key="ADD2"/></a>
	      <%}%>
      </td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'new_interessent_cancel'; link('process/new_interessent_detail_personal.jsp');">
		<% if (user_added) {%><fmt:message key="NEW"/><%} else {%>
      <fmt:message key="CANCEL"/><%}%>
      </a></td>
    </tr>
    
      <%
	boolean admin = session.getAttribute("admin")!=null;

    //if (admin && !user_added) {    
    %>
        
    
    <tr> 
      <td id="userTableContentMainTitles2" height="329" colspan="3"><%
      	if (session.getAttribute("NEW_INTERESSENT_ID")!=null) {
      		int id = ((Integer)session.getAttribute("NEW_INTERESSENT_ID")).intValue();
      		out.println("Neuer Interessent erfolgreich angelegt!<br>");
      		out.print("Nummer: "+String.valueOf(id)+"<br>");
      		//out.print("Passwort: "+(String)session.getAttribute("LAST_GENERATED_CUSTOMER_PASSWORD"));
			FormHelper.cancelNewUser(session);      	
			session.setAttribute("NEW_INTERESSENT_ID", null);
	      	//session.setAttribute("LAST_GENERATED_CUSTOMER_PASSWORD", null);		
      	} else if (session.getAttribute("CANNOT_ADD_INTERESSENT")!=null) {
      		out.println(session.getAttribute("CANNOT_ADD_INTERESSENT"));
      		session.setAttribute("CANNOT_ADD_INTERESSENT", null);
      	} else if (session.getAttribute("SIMILAR_INTERESSENTS")!=null) {
      		out.println(LocaleSupport.getLocalizedMessage(pageContext, "SIMILAR_C")+" <br><br>");
      		java.util.ArrayList m = (java.util.ArrayList)session.getAttribute("SIMILAR_INTERESSENTS");
      		for (int kkk = 0; kkk<m.size(); kkk++) {
      			java.util.Map act = (java.util.Map)m.get(kkk);
      			String lastname = (String)act.get("lastname");
      			Integer id = (Integer)act.get("id");
      					String birthdate = (String)act.get("birthdate");
      			String postcode = (String)act.get("postcode");
      			String street = (String)act.get("street");
      			out.println(id + ", " + lastname + ", " + birthdate + ", " + postcode + ", " + street + "<br>");
      		}
      		out.println("<br>"+LocaleSupport.getLocalizedMessage(pageContext, "SAVE_ANYWAY"));
      	}
      %></td>
    </tr>
    <tr>
      <td colspan="3" id="userTableContentFields" height="30"><div id="showWait" style="display:none;">&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key="PLEASE_WAIT"/></div><div id="noShowWait" style="display:none;">&nbsp;</div></td>
    </tr>   
  </table>
</form>
</body>
</html>
