<%@ page 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="java.net.*"%>
<%@ page import="com.etixpert.evolution.gui.servlets.elements.*"%>
<%@ page import="com.etixpert.evolution.*"%>
<%@ page import="java.sql.*"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>

<% String prefix = AboHelper.getPrefix(request); %>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link href="css/evolution.css" rel="stylesheet" type="text/css">
<script language="JavaScript">

var elementValues = new Array ();

function getElementValue (element) {
    if (element.type == "checkbox" || element.type == "radio")
        return element.checked;
    else if (element.type.indexOf("select") >= 0)
        return element.selectedIndex;
    else if (element.type == "hidden")
        return "hidden";
    else
        return element.value;
}

function saveValues (form) {
    for (var i = 0; i < form.elements.length; i++) {
        var element = form.elements[i];
        elementValues[i] = getElementValue (element);
    }
}

function hasChanged (form) {
    if (form.elements.length != elementValues.length)
        return true;

    for (var i = 0; i < form.elements.length; i++) {
        var element = form.elements[i];
        if (element.name.indexOf('art_id')!=-1 || element.name.indexOf('quantity')!=-1)
        if (getElementValue (element) != elementValues[i])
            return true;
    }

    return false;
}

function simpleLink(origLink) {
		parent.mainFrame.location = origLink;
	}

function checkAddresses() {
	if (top.mainFrame.document.forms[0].billing_postcode.value == '<PLZ>')
		top.mainFrame.document.forms[0].billing_postcode.value = '';
	if (top.mainFrame.document.forms[0].billing_city.value == '<Ort>')
		top.mainFrame.document.forms[0].billing_city.value = '';
	if (top.mainFrame.document.forms[0].billing_street.value == '<Strasse>')
		top.mainFrame.document.forms[0].billing_street.value = '';
	if (top.mainFrame.document.forms[0].delivery_postcode.value == '<PLZ>')
		top.mainFrame.document.forms[0].delivery_postcode.value = '';
	if (top.mainFrame.document.forms[0].delivery_city.value == '<Ort>')
		top.mainFrame.document.forms[0].delivery_city.value = '';
	if (top.mainFrame.document.forms[0].delivery_street.value == '<Strasse>')
		top.mainFrame.document.forms[0].delivery_street.value = '';		
	if (top.mainFrame.document.forms[0].art_id.value != '') return false;
	if (hasChanged(top.mainFrame.document.forms[0])) return false;
		return true;
}

function link(origLink, page_action){
		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 = '<%=prefix%>abo_detail.jsp';
			top.mainFrame.document.forms[0].link.value = origLink;
			top.mainFrame.document.forms[0].pageAction.value = page_action;
			top.mainFrame.document.forms[0].submit();
		}
	}
	
function showHideBankCC() {
	if (document.all['pay_method_id'].value==1) {
		 document.all['bankselect'].style.display='block';
		document.all['creditselect'].style.display='none';
 		} else if (document.all['pay_method_id'].value==2) {
		 document.all['bankselect'].style.display='none';
		 document.all['creditselect'].style.display='block';
		} else {
		 document.all['bankselect'].style.display='none';
		 document.all['creditselect'].style.display='none';
		}		
	}	
</script>
</head>

<html>	  
<%	if (session.getAttribute(prefix+"abo_error")!=null) { %>
 <body onload="alert('<%=session.getAttribute(prefix+"abo_error")%>');saveValues(document.forms[0]);" onload="showHideBankCC();">
<% session.removeAttribute(prefix+"abo_error");
 } else if (session.getAttribute(prefix+"ABO_MODIFIED")!=null) { %>
 <body onload="alert('Abonnement modifiziert'); saveValues(document.forms[0]);" onload="showHideBankCC();"> 
<% session.removeAttribute(prefix+"ABO_MODIFIED");
 } else { %>
 <body onload="showHideBankCC();saveValues(document.forms[0]);">
<% } %>
<%
	String jsp = prefix+"abo_detail.jsp";
	
	boolean[] rights = AboHelper.getRights(session, prefix, AboHelper.MASK_MODIFY);
	boolean canmod = rights[AboHelper.INDEX_MODIFY];
	
//	if (OrderHelper.getVal(session, jsp, "canmod").equals("yes")) canmod = true;
	CheckBox lengthening = new CheckBox(session, jsp, "auto_extension", "true", "automatische Verlängerung nach dem Ablauf", false);
	//lengthening.setDisabled(true);
	Map operatingTimes = new TreeMap();
	operatingTimes.put("1","01.-07.");
	operatingTimes.put("2","08.-15.");
	operatingTimes.put("3","16.-23.");
	operatingTimes.put("4","24.-31.");
	MapSelect operatingTimeSelect = new MapSelect(session, jsp, "operating_time", operatingTimes);
	//operatingTimeSelect.setDisabled(true);
	
%>
<center><h1><fmt:message key="ABO_MODIFICATION"/></h1></center>

<form name=new_order action="process/abo_detail.jsp?prefix=<%=prefix%>" method="post">	
		<input type="hidden" name="link" value="process/abo_detail.jsp?prefix=<%=prefix%>"/>
    	<input type="hidden" name="saveState"/>
    	<input type="hidden" name="pageAction"/>
    	<input type="hidden" name="pos"/>
    	<input type="hidden" name="prefix" value="<%=prefix%>"/>
    	
	
	<label for="distr_id"><fmt:message key="ROOT_ID"/>:</label>
	<input name="distr_id" class="small0" value="<%=OrderHelper.getVal(session, jsp, "distr_id")%>" readonly>
	<label for="sponsor"><fmt:message key="SPONSOR"/>:</label>
	<input name="sponsor" class="small0" value="<%=OrderHelper.getVal(session, jsp, "sponsor")%>" readonly><br>
	
	<input type="hidden" name="orderingCountry" value="<%=OrderHelper.getVal(session, jsp, "orderingCountry")%>"/>
	<input type="hidden" name="orderingLevelId" value="<%=OrderHelper.getVal(session, jsp, "orderingLevelId")%>"/>
	<input type="hidden" name="canmod" value="<%=OrderHelper.getVal(session, jsp, "canmod")%>"/>
	<input type="hidden" name="UID" value="<%=OrderHelper.getVal(session, jsp, "UID")%>"/>
	
	<input type="hidden" name="id" value="<%=session.getAttribute(prefix+"CURRENT_ABO_ID")%>"/>
	
	<label for="tel"><fmt:message key="TEL"/>:</label>
	<input name="tel" class="large" value="<%=OrderHelper.getVal(session, jsp, "tel")%>" readonly><br>

	<label for="delivery_title"><fmt:message key="DELIVERY_LEVEL_ADDRESS"/>:</label>
	<input name="delivery_title" class="little" value="<%=OrderHelper.getVal(session, jsp, "delivery_title")%>"><br>

	<label for="delivery_name"><fmt:message key="DELIVERY_NAME"/>:</label>
	<input maxlength="70" name="delivery_name" class="medium" value="<%=OrderHelper.getVal(session, jsp, "delivery_name")%>"><br>

	<label for="delivery_country_id"><fmt:message key="DELIVERY_ADDRESS"/>:</label>
	<%
		String del_country_id = OrderHelper.getVal(session, jsp, "delivery_country_id");
		String del_postcode = OrderHelper.getVal(session, jsp, "delivery_postcode");
		String del_city = OrderHelper.getVal(session, jsp, "delivery_city");
		String del_street = OrderHelper.getVal(session, jsp, "delivery_street");
		
		String del_focus = "";
		String del_city_focus = "";
		String del_street_focus = "";
		String del_country_focus = "";
		
		if (del_country_id.equals("") || del_country_id.equals("<Land>")) {
			del_country_focus = "this.value=''";
			del_country_id = "<Land>";
		}		
		if (del_postcode.equals("") || del_postcode.equals("<PLZ>")) {
			del_focus = "this.value=''";
			del_postcode = "<PLZ>";
		}
		if (del_city.equals("") || del_city.equals("<Ort>")) {
			del_city_focus = "this.value=''";
			del_city = "<Ort>";
		}
		if (del_street.equals("") || del_street.equals("<Strasse>")) {
			del_street_focus = "this.value=''";
			del_street = "<Strasse>";
		}
	%>
	<input name="delivery_country_id" maxlength="2" value="<%=del_country_id%>" class="small0" onFocus="<%=del_country_focus%>"/>
	<input maxlength="8" name="delivery_postcode" class="little" value="<%=del_postcode%>" onFocus="<%=del_focus%>"/>
	<input name="delivery_city" value="<%=del_city%>" onFocus="<%=del_city_focus%>"/>
	<input name="delivery_street" class="medium" value="<%=del_street%>" onFocus="<%=del_street_focus%>"/><br>

	
	<label for="billing_title"><fmt:message key="BILLING_LEVEL_ADDRESS"/>:</label>
	<input type="hidden" name="billing_title" class="little" value="<%=OrderHelper.getVal(session, jsp, "billing_title")%>" readonly>
	<%=OrderHelper.getVal(session, jsp, "billing_title")%><br>
	
	<label for="billing_name"><fmt:message key="BILLING_NAME"/>:</label>
	<input type="hidden" name="billing_name" class="medium" value="<%=OrderHelper.getVal(session, jsp, "billing_name")%>" readonly>
	<%=OrderHelper.getVal(session, jsp, "billing_name")%>
	<br>
	
	<label for="billing_country_id"><fmt:message key="BILLING_ADDRESS"/>:</label>
	<%
		String bill_country_id = OrderHelper.getVal(session, jsp, "billing_country_id");
		String bill_postcode = OrderHelper.getVal(session, jsp, "billing_postcode");
		String bill_city = OrderHelper.getVal(session, jsp, "billing_city");
		String bill_street = OrderHelper.getVal(session, jsp, "billing_street");
		
		String bill_focus = "";
		String bill_city_focus = "";
		String bill_street_focus = "";
		
		if (bill_postcode.equals("") || bill_postcode.equals("PLZ")) {
			bill_postcode = "<PLZ>";
		}
		if (bill_city.equals("") || bill_city.equals("<Ort>")) {
			bill_city = "<Ort>";
		}
		if (bill_street.equals("") || bill_street.equals("<Strasse>")) {
			bill_street = "<Strasse>";
		}
		
	%>
	<input type="hidden" name="billing_country_id" value="<%=bill_country_id%>" class="small0" readonly>
	<input type="hidden" name="billing_postcode" class="little" value="<%=bill_postcode%>" readonly>
	<input type="hidden" name="billing_city" value="<%=bill_city%>" readonly>
	<input type="hidden" name="billing_street" class="medium" value="<%=bill_street%>" readonly>
	<%=bill_country_id+"-"+bill_postcode+", "+bill_city+", "+bill_street%><br>
			
	<label for="pay_method_id"><fmt:message key="PAYMENT_METHOD"/>:</label>
	<select name="pay_method_id" onchange="showHideBankCC();" onfocus="showHideBankCC();">
	<%=AboHelper.getPaymentOptions(session, jsp)%>
	</select>
	<div id="bankselect" style="display:none;">
		<select name="account_id_1">
			<%=AboHelper.getAccountOptions(session, jsp, "bank")%>
		</select>
	</div>
	<div id="creditselect" style="display:none;">
		<select name="account_id_2">
			<%=AboHelper.getAccountOptions(session, jsp, "credit")%>
		</select>
	</div>
	<br>
	
	<label for="shipping_descr"><fmt:message key="SHIPPING_TYPE"/>:</label>
	<select name="shipping_descr">
		<%=OrderHelper.getShippingOptions(pageContext, jsp)%>
	</select>
	<br>
	
	<label for="comment"><fmt:message key="COMMENT"/>:</label>
	<textarea name="comment" rows="3" class="large"><%=OrderHelper.getVal(session, jsp, "comment")%></textarea>
	<br>
	<br>
    <input type="hidden" name="old_start_date"  value="<%=OrderHelper.getVal(session, jsp, "start_date")%>">
	<label for="start_date"><fmt:message key="START_DATE"/></label>
	<% if (OrderHelper.getVal(session, jsp, "delivered").equals("0")) { %>
		<input name="start_date" class="small0" value="<%=OrderHelper.getVal(session, jsp, "start_date")%>">
	<% } else { %> 
	   		<input name="start_date" class="small0" value="<%=OrderHelper.getVal(session, jsp, "start_date")%>" readonly>
	<% } %>
		
	<br>
	<input type="hidden" name="old_duration"  value="<%=OrderHelper.getVal(session, jsp, "duration")%>">
	<label for="duration"><fmt:message key="DURATION"/></label>
	<input name="duration" class="little" value="<%=OrderHelper.getVal(session, jsp, "duration")%>">
   
   	<input type="hidden" name="delivered" value="<%=OrderHelper.getVal(session, jsp, "delivered")%>"/>
	<label for="delivery_intervall">Lieferintervall (in Monaten)</label>
	<input name="delivery_intervall" class="little" value="<%=OrderHelper.getVal(session, jsp, "delivery_intervall")%>" READONLY>
 <!-- 
  <% if (OrderHelper.getVal(session, jsp, "delivered").equals("0")) { %>
      <input type="hidden" name="old_start_month" value="<%=OrderHelper.getVal(session,jsp,"old_start_month")%>"/>
      <label for="start_month"><fmt:message key="BEGIN_MONTH"/></label>
	  <input name="start_month" class="little" value="<%=OrderHelper.getVal(session, jsp, "start_month")%>"/>
	<% } %>	
 -->
	<input type="hidden" name="old_operating_time" value="<%=OrderHelper.getVal(session, jsp, "operating_time")%>"/>
	<label for="operating_time"><fmt:message key="OPERATING_TIME"/>: </label>
	<%= operatingTimeSelect.toHTML() %>
	<br>
	
	<%= lengthening.toHTML() %>
	<br/>

	<%=com.etixpert.evolution.gui.servlets.AboHelper.generateOrderDetailsHeader(pageContext, prefix+"abo_details")	%>
	<%=com.etixpert.evolution.gui.servlets.OrderHelper.generateOrderDetailsRows(session, prefix+"abo_details")%>	
	<%=com.etixpert.evolution.gui.servlets.AboHelper.generateOrderTotalRow(pageContext, prefix+"abo_details")%>	

	<br>
<% if (canmod) {%>
<div width="800" height="30" align="left" class="menu">
 &nbsp;&nbsp;&nbsp;
 <a onClick="return checkAddresses();" href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'modify_abo'; link('process/abo_detail.jsp?prefix=<%=prefix%>', 'modify_abo');"><fmt:message key="MODIFY"/></a>
 &nbsp;&nbsp;&nbsp;
 <a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'load_abo'; link('process/abo_detail.jsp?prefix=<%=prefix%>', 'load_abo');"><fmt:message key="REVERT_ORDER_TO_DB"/></a>
 </div>
 <% } %>
</form>
<body>
<html>