<%@ 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 getPMOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	PM[] pms = FormHelper.getPMs();
	
	if (getChecked("payment_slip", session).equals(" checked")) pms = FormHelper.getPMsAll();

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

public String getCCCOptions(HttpSession session) throws Exception {
	StringBuffer sb = new StringBuffer("");
	CCC[] pms = FormHelperC.getCCCs();
	
	for (int i = 0; i < pms.length; i++) {
		String selected="";
		if (getVal("cc_org_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("customer_detail_payment.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("customer_detail_payment.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-2">
<link href="main.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- JavaScript code hiding

var emptyString = /^\s*$/

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh2= ".";
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 test() {
		var cb = document.forms[0].payment_slip;
		if (!cb.checked) {
			var optionObject = new Option("Erlagschein","6");
			var rank = document.forms[0].pay_method_id.options.length;
			document.forms[0].pay_method_id.options[rank] = optionObject;
		} else {
			var rank = document.forms[0].pay_method_id.options.length;
			document.forms[0].pay_method_id.options[rank-1].selected = false;
			document.forms[0].pay_method_id.options[0].selected = true;
	
			document.forms[0].pay_method_id.options[rank-1] = null;		
		}		
	}


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!=5) return false

	var pos1=dtStr.indexOf(dtCh)
	if (pos1==-1){
		return false
	}
	var strMonth=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos1+1)

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

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

	return true

}


function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh2)
	var pos2=dtStr.indexOf(dtCh2,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=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, 10)
	day=parseInt(strDay, 10)
	year=parseInt(strYr, 10)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd.mm.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(dtCh2,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh2))==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 bankCheck() {
	  if (!document.getElementById)
	    return true;  // not available on this browser - leave validation to the server
	  var elem1 = document.forms[0].bank;
	  var elem2 = document.forms[0].account_number;
	  var elem3 = document.forms[0].bank_code;
	  var elem4 = document.forms[0].debit_date;
	  var elem5 = document.forms[0].iban;

	/*  if (emptyString.test(elem1.value)) {
	      alert("Bank darf nicht leer sein!");
	      return false;
	  }
	  if (emptyString.test(elem2.value)) {
	      alert("Kontonummer darf nicht leer sein!");
	      return false;
	  }
	  if (emptyString.test(elem3.value)) {
	      alert("Blz darf nicht leer sein!");
	      return false;
	  }
	 */ 
	  if (!emptyString.test(elem4.value)) {
	  	if (isDate(elem4.value)==false) {
		  	return false;
	  	}
	  }
	  if (emptyString.test(elem5.value)) {
	      alert("Iban darf nicht leer sein!");
	      return false; 
	  }

	  return true;
	}

function bankCheck_old() {
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem1 = document.forms[0].bank;
  var elem2 = document.forms[0].account_number;
  var elem3 = document.forms[0].bank_code;
  var elem4 = document.forms[0].debit_date;
  
  if (emptyString.test(elem1.value)) {
      alert("Bank darf nicht leer sein!");
      return false;  
  }
  if (emptyString.test(elem2.value)) {
      alert("Kontonummer darf nicht leer sein!");
      return false; 
  }
  if (emptyString.test(elem3.value)) {
      alert("Blz darf nicht leer sein!");
      return false;  
  }
  if (!emptyString.test(elem4.value)) {
	  	if (isDate(elem4.value)==false) {
		  	return false;
	  	}
	  }
  
  return true;
}

function creditCheck() {
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem2 = document.forms[0].cc_number;
  var elem3 = document.forms[0].valid_from;
  var elem4 = document.forms[0].valid_to;
  
  if (emptyString.test(elem2.value)) {
      alert("Karten nr. darf nicht leer sein!");
      return false; 
  }

  if (emptyString.test(elem4.value)) {
      alert("Gultig bis darf nicht leer sein!");
      return false;  
  }
  
  	if (!emptyString.test(elem3.value))
  	if (isDate2(elem3.value)==false) {
      alert("Gültig von muss im format mm/yy sein!");
      return false;    		
  	}
  	if (isDate2(elem4.value)==false) {
      alert("Gültig bis muss im format mm/yy 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();
		}
	}
	
	function cc() {
		alert("Die Kontonummer kann nicht gelöscht werden, weil es noch eine Bestellung im Status 10, 20 oder ein Abo mit dieser Kontonummer gibt! ")
	}
	
	function bc() {
		alert("Die Kontonummer kann nicht gelöscht werden, weil es noch eine Bestellung im Status 10, 20 oder ein Abo mit dieser Kontonummer gibt! ")
	}
// -->
</SCRIPT>
</head>
<%if (session.getAttribute("CREDITCARD_CANNOT_BE_DELETED")!=null) {%>
	<body onLoad="cc();" bgcolor="#e6e6ee">
<%
	session.removeAttribute("CREDITCARD_CANNOT_BE_DELETED");
	} else if (session.getAttribute("BANK_ACCOUNT_CANNOT_BE_DELETED")!=null) { %>
		<body onLoad="bc();">
	<%
	session.removeAttribute("BANK_ACCOUNT_CANNOT_BE_DELETED");
	} else
	{%>
	<body  bgcolor="#e6e6ee">
<%}%>
<div width="800" height="30" align="left" class="menu"><%=FormHelperC.generateCustomerDataHeaderString(pageContext)%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="menu" href="process/customer_selection.jsp">Anderen Kunde auswählen</a></div>
<table border="1" id="userTable" class="menu">
<jsp:include page="MenuHelper.jsp">
	<jsp:param name="self_id" value="2230"/>
	<jsp:param name="parent_id" value="2200"/>	
</jsp:include>
</table>
<form action="process/customer_detail_payment.jsp" method="post">
<input type="hidden" name="saveState"/>
<input type="hidden" name="pageAction"/>
<input type="hidden" name="row"/>
<input type="hidden" name="link" value="process/customer_detail_payment.jsp"/>
  <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <!--DWLayoutTable-->
    <tr> 
      <td height="5" colspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="STANDARD_PAYMENT_METHOD"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><select name="pay_method_id"><%=getPMOptions(session)%>
        </select></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
	<tr>
		<td height="10" colspan="6"></td>
	</tr>
    <tr>
		<td height="30" valign="top" id="userTableContentTitles"><fmt:message key="CHECKBOX_PAYMENT_SLIP"/>:</td>
    	<td>&nbsp;</td>
	    <td><input name="payment_slip" type="checkbox" class="checkbox" value="<%=getVal("payment_slip", session)%>"<%=getChecked("payment_slip", session)%> onMouseUp="test();"></td>
	    <td id="userTableContentTitles"><fmt:message key="ALLOW_BANK"/>:</td>
	    <td>&nbsp;</td>
        <td><input name="allow_bank" type="checkbox" class="checkbox" value="<%=getVal("allow_bank", session)%>"<%=getChecked("allow_bank", session)%>></td>  
    </tr>
	<tr>
		<td height="10" colspan="6"></td>
	</tr>    
    <tr> 
      <td width="134" height="30" valign="top" id="userTableContentMainTitles"><fmt:message key="BANK_ACCOUNT_NUMBERS"/>: </td>
      <td width="33">&nbsp;</td>
      <td width="230">&nbsp;</td>
      <td width="135">&nbsp;</td>
      <td width="38">&nbsp;</td>
      <td width="230">&nbsp;</td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="BLZ"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="bank_code" value="<%=getVal("bank_code", session)%>"></td>
      <td valign="top" id="userTableContentTitles"><fmt:message key="BANK_ACCOUNT_NUMBER"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="account_number" value="<%=getVal("account_number", session)%>"></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="BANK"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="bank" value="<%=getVal("bank", session)%>"></td>
      <td valign="top" id="userTableContentTitles"><fmt:message key="IBAN"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="iban" value="<%=getVal("iban", session)%>"></td>
    </tr>
    <tr>
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="DEBIT_DATE"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input type="text" name="debit_date" value="<%=getVal("debit_date", session)%>"></td>
      <td valign="top" id="userTableContentTitles"><fmt:message key="BIC"/>:</td>
      <td>&nbsp;</td>
      <td valign="top" id="userTableContentFields"><input maxlength="20" type="text" name="bic" value="<%=getVal("bic", session)%>"></td>
    </tr>  
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="COMMENT"/>:</td>
      <td>&nbsp;</td>
      <td colspan="4" valign="top" id="userTableContentFields"><textarea name="comment"id="comment" rows="1"><%=getVal("comment", session)%></textarea></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><a onClick="javascript:return bankCheck();" href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'customer_add_new_bank'; link('process/customer_detail_payment.jsp');">
      <%=FormHelperC.underMod(session, "customer_banks")?"Modifikation übernehmen":"Hinzufügen"%>
      </a></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
<div class="sortable" id="1" style="margin-left: 10px;">
    <table width="850px" id="mainTable">
   <!--    <col width="30"><col width="30"><col width="70"><col width="70"><col width="120"><col width="120"><col width="100"><col width="180"><col width="130">
      <tr>
      <td id="accountTableHeaderContent"><fmt:message key="M"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="L"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="RECH"/></td>
	  <td id="accountTableHeaderContent"><fmt:message key="BONUS"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="BLZ"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="BANK_ACCOUNT_NUMBER"/></td>
	  <td id="accountTableHeaderContent"><fmt:message key="BANK"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="IBAN"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="COMMENT"/></td>
</tr> -->
     <col width="30"><col width="30"><col width="70"><col width="70"><col width="210"><col width="210"><col width="100"><col width="130">
      <tr>
	      <td id="accountTableHeaderContent"><fmt:message key="M"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="L"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="RECH"/></td>
		  <td id="accountTableHeaderContent"><fmt:message key="BONUS"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="IBAN"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="BIC"/></td>
		  <td id="accountTableHeaderContent"><fmt:message key="BANK"/></td>
	      <td id="accountTableHeaderContent"><fmt:message key="COMMENT"/></td>
	 </tr>
</table>
<DIV STYLE="overflow: none; width: 850px; border-left: 0px gray solid; border-bottom: 0px gray solid;
            padding:0px; margin: 0px;">
      <table border="0" cellpadding="0" cellspacing="0" width="800px" class="sortable" id="mainTable">      
      <!-- <col width="30"><col width="30"><col width="70"><col width="70"><col width="120"><col width="120"><col width="100"><col width="180"><col width="130"> -->
      <col width="30"><col width="30"><col width="70"><col width="70"><col width="210"><col width="210"><col width="100"><col width="130">
      <%=com.etixpert.evolution.gui.servlets.FormHelperC.generateBankTableRows(session, "customer_banks")%>
</table>
</DIV></DIV>
  <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <!--DWLayoutTable-->
    <tr> 
      <td width="124" height="30" valign="top" id="userTableContentMainTitles"><fmt:message key="CREDITCARDS"/>: </td>
      <td width="34">&nbsp;</td>
      <td width="210">&nbsp;</td>
      <td width="155">&nbsp;</td>
      <td width="41">&nbsp;</td>
      <td width="236">&nbsp;</td>
    </tr>
    <tr> 
      <td rowspan="2" valign="top" id="userTableContentTitles"><fmt:message key="CREDITCARD_ORG"/>:</td>
      <td height="15"></td>
      <td rowspan="2" valign="top" id="userTableContentFields"><select name="cc_org_id"><%=getCCCOptions(session)%></select></td>
      <td></td>
      <td></td>
      <td rowspan="2" valign="top" id="userTableContentFields"><fmt:message key="CC_FROM"/>&nbsp;<input type="text" name="valid_from" value="<%=getVal("valid_from", session)%>"></td>
    </tr>
    <tr> 
      <td height="15"></td>
      <td rowspan="2" valign="top" id="userTableContentTitles"><fmt:message key="VALID"/>:</td>
      <td></td>
    </tr>
    <tr> 
      <td rowspan="2" valign="top" id="userTableContentTitles"><fmt:message key="CREDITCARD_NR"/>:</td>
      <td height="15"></td>
      <td rowspan="2" valign="top" id="userTableContentFields"><input type="text" name="cc_number" value="<%=getVal("cc_number", session)%>"></td>
      <td></td>
      <td rowspan="2" valign="top" id="userTableContentFields"><fmt:message key="CC_TO"/>&nbsp;<input type="text" name="valid_to" value="<%=getVal("valid_to", session)%>"></td>
    </tr>
    <tr> 
      <td height="15"></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><fmt:message key="COMMENT"/>:</td>
      <td></td>
      <td colspan="4" valign="top" id="userTableContentFields"><textarea rows="1" id="comment" name="fully"><%=getVal("fully", session)%></textarea></td>
    </tr>
    <tr> 
      <td height="30" valign="top" id="userTableContentTitles"><a onClick="javascript:return creditCheck();" href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'customer_add_new_credit'; link('process/customer_detail_payment.jsp');">
      <%=FormHelperC.underMod(session, "customer_credits")?"Modifikation übernehmen":"Hinzufügen"%>
      </a></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>
<div class="sortable" id="1" style="margin-left: 10px;">
    <table width="800px" id="mainTable">
     <col width="30"><col width="30"><col width="170"><col width="170"><col width="135"><col width="135"><col width="130">
      <tr>
      <td id="accountTableHeaderContent"><fmt:message key="M"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="L"/></td>
	  <td id="accountTableHeaderContent"><fmt:message key="CREDITCARD_ORG"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="CREDITCARD_NR"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="CC_FROM_HEADER"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="CC_TO_HEADER"/></td>
      <td id="accountTableHeaderContent"><fmt:message key="COMMENT"/></td>
</tr>
</table>
<DIV STYLE="overflow: none; width: 820px; 
            border-left: 0px gray solid; border-bottom: 0px gray solid;
            padding:0px; margin: 0px;">
      <table border="0" cellpadding="0" cellspacing="0" width="800px" class="sortable" id="mainTable">      
     <col width="30"><col width="30"><col width="170"><col width="170"><col width="135"><col width="135"><col width="130">
 <%=com.etixpert.evolution.gui.servlets.FormHelperC.generateCreditTableRows(session, "customer_credits")%>
</table>
</DIV></DIV>
  <table width="800" border="0" cellpadding="0" cellspacing="0" id="userDetailsTable" class="normal">
    <!--DWLayoutTable-->
    <tr> 
      <td height="30">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>

