<!--
// ******************************************************************************************
// START ORDERLIST JS FUNCS
// ******************************************************************************************
//-->

<script type="text/javascript" language="JavaScript">
<!--
{literal}

function ajax_show_payments_filter(){
  params = 'ajax_payment_filter=1{/literal}{$AJAX_PAYMENT_GET_VARS}{literal}';
  var myAjax = new Ajax.Request(
    "orders.php",
    { 
    	method: 'get', 
	parameters: params,
    	onComplete: show_payment_filter 
    }
  );
}
function show_payment_filter(originalRequest){
   $('ajaxpaymentmethods').innerHTML = originalRequest.responseText;
}
function hide_payment_filter(){
   $('ajaxpaymentmethods').innerHTML = '';
}


function count_selected_input(formname,inputname){
	var counter = 0;
	var ids = new Array();
	count_input_total = document.forms[formname].elements[inputname].length;
	for(i=0;i<count_input_total;i++){
		if(document.forms[formname].elements[inputname][i].checked == true){
			ids[ counter ] = document.forms[formname].elements[inputname][i].value;
			counter++;
		}
	}
	return ids;
}

function list_action_process(){
	selected_items = count_selected_input('change_orders','statusOID[]');
	if(selected_items.length < 1){
		document.forms['change_orders'].list_action.value = '';
		alert('{/literal}{$JS_ERROR_NO_ORDER_SELECTED}{literal}');
		return false;
	}

	switch( document.forms['change_orders'].list_action.value ){
		case 'combine':
			check_combines(selected_items);
			break;
		case 'nosend':
			check_nosend(selected_items);
			break;
		case 'calc':
			sum(selected_items);
			break;
		case 'storno':
			check_storno(selected_items);
			break;
		default:
			break;
	}
	document.forms['change_orders'].list_action.value = '';
}

function check_storno(oids) {
	oid = ''; // GET PARAMETER BASTELN
	for(i=0;i<oids.length;i++) {
		val = oids[i];
		oid += 'oID[]='+val+'&';
	}
	ok = confirm('{/literal}{$JS_CONFIRM_STORNO}{literal}');
	if(ok){
		window.location.href='{/literal}{$LINK_STORNO_PRE}{literal}&'+oid+'a=0';
	}else{
		return false;
	}
}

function check_combines(oids) {
	ok = confirm('{/literal}{$JS_CONFIRM_COMBINE}{literal}');
	if(ok){
		document.forms['change_orders'].submit();
	}else{
		return false;
	}
}

function check_nosend(oids) {
	ok = confirm('{/literal}{$JS_CONFIRM_NOSEND}{literal}');
	if(ok){
		okcom = prompt("{/literal}{$JS_PROMPT_NOSEND_COMMENT}{literal}");
		if(okcom.length > 0){
			document.forms['change_orders'].temp_comment.value = okcom;
			document.forms['change_orders'].submit();
		}else{
			alert('{/literal}{$JS_ERROR_NOSEND_COMMENT}{literal}');
		}
	}else{
		return false;
	}
}

function sum(oids) {

	total = 0;
	ship = 0;
	subtotal = 0;
	tax = 0;
	
	sum_total = 0;
	sum_ship = 0;
	sum_subtotal = 0;
	sum_tax = 0;
	
	out = '<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">';
	out += '<html {/literal}{$HTML_PARAMS}{literal}>';
	out += '<head>';
	out += '<meta http-equiv="Content-Type" content="text/html; charset={/literal}{$CHARSET}{literal}">';
	out += '<title>{/literal}{$SUM_POPUP_TITLE}{literal}</title>';
	out += '<link rel=stylesheet type=text/css href=includes/stylesheet.css>';
	out += '</head>';
	out += '<body marginwidth=0 marginheight=0 topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0 bgcolor=#FFFFFF>';
	out += '<table border=0 width=100% bgcolor=#000000 cellpadding=1 cellspacing=1>';
	out += "<tr bgcolor=#CACACA><th class=main>{/literal}{$HEADING_TITLE_SEARCH}</th><th class=main>{$ENTRY_SUB_TOTAL}</th><th class=main>{$ENTRY_TAX}</th><th class=main>{$ENTRY_SHIPPING}</th><th class=main>{$ENTRY_TOTAL}{literal}</th></tr>\r\n";
	for(i=0;i<oids.length;i++){
		act_oid = oids[i];
		el = document.forms['change_orders'].elements["ototal_"+act_oid];
		if(el.value > 0){
			total = (el.value*1);
			
			ship = 0;		
			for(b=0;b<20;b++){ // MAX 20 SHIPPINGS PRO ORDER
				els = document.forms['change_orders'].elements["oship_"+act_oid+"_"+b];
				if( els ){
					ship += (els.value*1);
					break;
				}
			}
			
			elst = document.forms['change_orders'].elements["osubtotal_"+act_oid];
			subtotal  = (elst.value*1);
			
			eltx = document.forms['change_orders'].elements["otax_"+act_oid];
			if(eltx)
				tax  = (eltx.value*1);
			else
				tax = 0;
			
			out += "<tr bgcolor=white><td align=right>"+act_oid+"</td><td align=right>"+subtotal.toFixed(2)+"</td><td align=right>"+tax.toFixed(2)+"</td><td align=right>"+ship.toFixed(2)+"</td><td align=right>"+total.toFixed(2)+"</td></tr>\r\n";
			
			sum_total += total;
			sum_ship += ship;
			sum_subtotal += subtotal;
			sum_tax += tax;
		}
	}
	out += "<tr bgcolor=yellow><td align=right class=main><b>Total:</b></td><td align=right class=main><b>"+sum_subtotal.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_tax.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_ship.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_total.toFixed(2)+"</b></td></tr>\r\n";
	out += "</table>";
	out += "<br><br><div align=center><a href='javascript:window.close();'><u>{/literal}{$CLOSE_WINDOW}{literal}</u></a></div>";
	out += '</body></html>';
	popup = window.open("","pop","width={/literal}{$POPUP_W},height={$POPUP_H}{literal},scrollbars=yes,resizable=yes");
	popup.document.write(out);
}
function filterPay(){
	var url = '{/literal}{$LINK_FILTERPAY}{literal}';
	count_total = document.forms['paymentsform'].elements['payment_method[]'].length;
	for(i=0;i<count_total;i++){
		if(document.forms['paymentsform'].elements['payment_method[]'][i].checked == true){
			payment_method = document.forms['paymentsform'].elements['payment_method[]'][i].value;
			url += '&payment_method[]='+payment_method;
		}
	}
	window.location.href=url;
}
{/literal}

//-->
</script>

<!--
// ******************************************************************************************
// END ORDERLIST JS FUNCS
// ******************************************************************************************
//-->





<table border="0" cellspacing="2" cellpadding="0" width="1000">
<tr>
	<td  width="100%" valign="top" align="center">
		<table border="0" width="100%" cellspacing="0" cellpadding="3">
		<tr>
			<td width="100%" colspan="2">


				<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td class="pageHeading" valign="top">{$HEADING_TITLE}</td>
					<td align="right">

						{if $ALLOW_ORDERS_VIEW}
     		
				     		<table border="0" cellpadding="2" cellspacing="0">
				              	{$FORM_ORDERSID}
				     		<tr>
				     			<td align="right" colspan="4" class="main">{$HEADING_TITLE_SEARCH}</td>
							<td>{$INPUT_FORM_ORDERSID}</td>
						     	<td class="main" align="right">{$SUBMIT_FORM_ORDERSID}</td>
					     	</tr>
				                </form>
						{$SEARCH_FORM}
						<tr>
						     	<td class="main">{$SEARCH_MODE_TEXT}{$INPUT_SEARCHMODE}</td>
							<td>{$INPUT_SEARCH_FORM}</td>
						     	<td class="main" align="right">{$SUBMIT_SEARCH_FORM}&nbsp;&nbsp;</td>
						</form>
					     	{$FORM_ORDERSSTATUS}
						     	<td class="main">{$HEADING_TITLE_STATUS}</td>
							<td>{$INPUT_FORM_ORDERSSTATUS}</td>
						     	<td class="main" align="right">{$SUBMIT_FORM_ORDERSSTATUS}</td>
					     	</tr>
					        </form>
					     	</table>
	     	
						{/if}

					</td>
				</tr>
				</table>

			</td>
		</tr>
		<tr class="dataTableRowSelected">
			<td class="main" colspan="2" style="height:20px;" align="center">
				<a href="{$LINK_NONGERMAN}" title="{$LINK_NONGERMAN_TEXT}"><u>{$LINK_NONGERMAN_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="{$LINK_MULTI}" title="{$LINK_MULTI_TEXT}"><u>{$LINK_MULTI_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="javascript: void( window.open('{$LINK_EXT_PRODUCTSEARCH}','popup','width={$POPUP_W},height={$POPUP_H},resizable=yes,scrollbars=yes') );" title="{$LINK_EXT_PRODUCTSEARCH_TEXT}"><u>{$LINK_EXT_PRODUCTSEARCH_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="javascript: void( window.open('{$LINK_EXT_ADDRESSSEARCH}','popup','width={$POPUP_W},height={$POPUP_H},resizable=yes,scrollbars=yes') );" title="{$LINK_EXT_ADDRESSSEARCH_TEXT}"><u>{$LINK_EXT_ADDRESSSEARCH_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="javascript: void( window.open('{$LINK_EXT_GROUPSEARCH}','popup','width={$POPUP_W},height={$POPUP_H},resizable=yes,scrollbars=yes') );" title="{$LINK_EXT_GROUPSEARCH_TEXT}"><u>{$LINK_EXT_GROUPSEARCH_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="{$LINK_NETTO}" title="{$LINK_NETTO_TEXT}"><u>{$LINK_NETTO_TEXT}</u></a>
				&nbsp;&nbsp;&nbsp;
				<a href="javascript: ajax_show_payments_filter();" title="{$LINK_PAYMENTS_TEXT}"><u>{$LINK_PAYMENTS_TEXT}</u></a>
				
			</td>
		</tr>
		<tr>
		        <td valign=top width="75%">

				<div id="ajaxpaymentmethods" style="z-index:0;position:relative;font-family:arial,helvetica,sans-serif;font-size:10px;"></div>
				{$CHANGE_ORDERS_FORM}


				{$LISTING}
				<span class="main"><b>{$TEXT_SELECTED_ORDERS_ACTION}</b> 
				<select name="list_action" onchange="list_action_process();">
				{foreach from=$LIST_ACTIONS item=action}
				<option value="{$action.id}">{$action.text}</option>
				{/foreach}
				</select>
				<input type="hidden" name="temp_comment">
			</td>
			</form>
			<td valign="top" width="25%">
				{$BOX}
			</td>
		</tr>
		<tr>
			<td class="main" align="center" style="border-top:1px solid #000000;">
		{$SPLIT}
			</td><td>&nbsp;</td>
		</table>
	</td>
</tr>
</table>

