<?php echo $header; ?>
<div id="content">
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <?php if ($error_warning) { ?>
        <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <div class="box">
        <div class="heading">
            <h1><img src="view/image/total.png" alt="" /> <?php echo $heading_title; ?></h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button"><span><?php echo $button_save; ?></span></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a></div>
        </div>
        <div class="content">
            <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
                <table class="form">
                   <!--  <tr>
                        <td><?php echo $entry_total; ?></td>
                        <td><input type="text" name="loyalty_total" value="<?php //echo $loyalty_total; ?>" /></td>
                    </tr>
                    <tr>
                        <td><?php echo $entry_amount; ?></td>
                        <td><input type="text" name="loyalty_amount" value="<?php //echo $loyalty_amount; ?>" /></td>
                    </tr>
                    <tr>
                        <td><?php echo $entry_type; ?></td>
                        <td>
                            <select name="loyalty_type" id="loyalty_type">
                                <option value="F" <?//= ((//$loyalty_type == "F" ? "selected='selected'" : "")) ?>>Fixed Value</option>
                                <option value="P" <?//= (($loyalty_type == "P" ? "selected='selected'" : "")) ?>>Percentage</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><?php echo $entry_date_start; ?></td>
                        <td><input type="text" name="loyalty_date_start" id="date_start" value="<?php //echo $loyalty_date_start; ?>" /></td>
                    </tr>
                    <tr>
                        <td><?php echo $entry_date_end; ?></td>
                        <td><input type="text" name="loyalty_date_end" id="date_end" value="<?php //echo $loyalty_date_end; ?>" /></td>
                    </tr> -->
					<tr class="left">
                        <td><?php echo $entry_description; ?></td>
                        <td><input type="text" name="loyalty_description" value="<?php echo $loyalty_description; ?>" /></td>
                    
                        <td><?php echo $entry_status; ?></td>
                        <td><select name="loyalty_status">
                                <?php if ($loyalty_status) { ?>
                                    <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                                    <option value="0"><?php echo $text_disabled; ?></option>
                                <?php } else { ?>
                                    <option value="1"><?php echo $text_enabled; ?></option>
                                    <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                                <?php } ?>
                            </select></td>						
                    </tr>
                    <tr>
                        <td><?php echo $entry_daydate; ?><span class="help"><?php echo $entry_daydateinfor; ?></span></td>
                        <td><input type="text" name="loyalty_daydate" value="<?php echo $loyalty_daydate; ?>" /></td>                    
                        <td><?php echo $entry_sort_order; ?></td>
                        <td><input type="text" name="loyalty_sort_order" value="<?php echo $loyalty_sort_order; ?>" size="1" /></td>
                    </tr>
                </table>
				 <table id="discount" class="list">
            <thead>
              <tr>
                <td class="left">Select</td>
                <td class="left">Numbers of Order</td>
                <td class="left">Order Total</td>
                <td class="left">Discount Type</td>
                <td class="left">Flat Rate</td>
                <td class="right">Percentage</td>
				<td class="right">Minimum order Total</td>
                <td class="right">Start date</td>
                <td class="right">End Date</td>
                <td class="right">Status</td>
                <td></td>
              </tr>
            </thead>
            <?php $discount_row = 0; ?>
            <?php foreach ($loyalty_discounts as $loyalty_discount) { ?>
            <tbody id="discount-row<?php echo $discount_row; ?>">
              <tr>
                <td class="left"><select name="loyalty_discount[<?php echo $discount_row; ?>][loyaltyselect_id]">
                    <?php foreach ($loyalty_select as $loyalty) { ?>
                    <?php if ($loyalty['loyaltyselect_id'] == $loyalty_discount['loyaltyselect_id']) { ?>
                    <option value="<?php echo $loyalty['loyaltyselect_id']; ?>" selected="selected"><?php echo $loyalty['name']; ?></option>
                    <?php } else { ?>
                    <option value="<?php echo $loyalty['loyaltyselect_id']; ?>"><?php echo $loyalty['name']; ?></option>
                    <?php } ?>
                    <?php } ?>
                  </select></td>
                <td class="right"><input type="text" name="loyalty_discount[<?php echo $discount_row; ?>][numorder]" value="<?php echo $loyalty_discount['numorder']; ?>" size="2" /></td>
                <td class="right"><input type="text" name="loyalty_discount[<?php echo $discount_row; ?>][ordertotal]" value="<?php echo $loyalty_discount['ordertotal']; ?>" size="2" /></td>
				<td class="left"><select name="loyalty_discount[<?php echo $discount_row; ?>][discounttype]">
                    <?php foreach ($loyalty_Discountselect as $loyalty) { ?>
                    <?php if ($loyalty['discounttype'] == $loyalty_discount['discounttype']) { ?>
                    <option value="<?php echo $loyalty['discounttype']; ?>" selected="selected"><?php echo $loyalty['name']; ?></option>
                    <?php } else { ?>
                    <option value="<?php echo $loyalty['discounttype']; ?>"><?php echo $loyalty['name']; ?></option>
                    <?php } ?>
                    <?php } ?>
                  </select></td>
                <td class="right"><input size="4" type="text" name="loyalty_discount[<?php echo $discount_row; ?>][flat]" value="<?php echo $loyalty_discount['flat']; ?>" /></td>
                <td class="right"><input size="4" type="text" name="loyalty_discount[<?php echo $discount_row; ?>][percent]" value="<?php echo $loyalty_discount['percent']; ?>" /></td>
                <td class="right"><input size="4" type="text" name="loyalty_discount[<?php echo $discount_row; ?>][minorder]" value="<?php echo $loyalty_discount['minorder']; ?>" /></td>
                <td class="left"><input size="8" type="text" name="loyalty_discount[<?php echo $discount_row; ?>][date_start]" value="<?php echo $loyalty_discount['date_start']; ?>" class="date" /></td>
                <td class="left"><input size="8" type="text" name="loyalty_discount[<?php echo $discount_row; ?>][date_end]" value="<?php echo $loyalty_discount['date_end']; ?>" class="date" /></td>
				  <td class="left"><select name="loyalty_discount[<?php echo $discount_row; ?>][status]">
                <?php if ($loyalty_discount['status']) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select></td>
                <td class="left"><a onclick="$('#discount-row<?php echo $discount_row; ?>').remove();" class="button">Remove</a></td>
              </tr>
            </tbody>
            <?php $discount_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="10"></td>
                <td class="left"><a onclick="addDiscount();" class="button">Add Loyalty Discount</a></td>
              </tr>
            </tfoot>
          </table>
            </form>
        </div>
    </div>
 <script type="text/javascript"><!--
		$('.date').datepicker({dateFormat: 'yy-mm-dd'});
        $('#date_start').datepicker({dateFormat: 'yy-mm-dd'});
        $('#date_end').datepicker({dateFormat: 'yy-mm-dd'});
  //--></script>
		
 <script type="text/javascript"><!--
var discount_row = <?php echo $discount_row; ?>;
function addDiscount() {
	html  = '<tbody id="discount-row' + discount_row + '">';
	html += '  <tr>'; 
    html += '    <td class="left"><select name="loyalty_discount[' + discount_row + '][loyaltyselect_id]">';
     <?php foreach ($loyalty_select as $loyalty) { ?>
       html += '      <option value="<?php echo $loyalty['loyaltyselect_id']; ?>"><?php echo $loyalty['name']; ?></option>';
     <?php } ?>
    html += '    </select></td>';		
    html += '    <td class="right"><input type="text" name="loyalty_discount[' + discount_row + '][numorder]" value="" size="2" /></td>';
    html += '    <td class="right"><input type="text" name="loyalty_discount[' + discount_row + '][ordertotal]" value="" size="2" /></td>';
    html += '    <td class="left"><select name="loyalty_discount[' + discount_row + '][discounttype]">';
     <?php foreach ($loyalty_Discountselect as $loyalty) { ?>
     html += '      <option value="<?php echo $loyalty['discounttype']; ?>"><?php echo $loyalty['name']; ?></option>';
    <?php } ?>
    html += '    </select></td>';
	html += '    <td class="right"><input size="4" type="text" name="loyalty_discount[' + discount_row + '][flat]" value="" /></td>';
	html += '    <td class="right"><input size="4" type="text" name="loyalty_discount[' + discount_row + '][percent]" value="" /></td>';
	html += '    <td class="right"><input size="4" type="text" name="loyalty_discount[' + discount_row + '][minorder]" value="" /></td>';
    html += '    <td class="left"><input size="8" type="text" name="loyalty_discount[' + discount_row + '][date_start]" value="" class="date" /></td>';
	html += '    <td class="left"><input size="8" type="text" name="loyalty_discount[' + discount_row + '][date_end]" value="" class="date" /></td>';
	html += '    <td class="left"><select name="loyalty_discount[' + discount_row + '][status]">';
    html += '      <option value="1" selected="selected"><?php echo $text_enabled; ?></option>';
    html += '      <option value="0"><?php echo $text_disabled; ?></option>';
    html += '    </select></td>';
	html += '    <td class="left"><a onclick="$(\'#discount-row' + discount_row + '\').remove();" class="button">Remove</a></td>';
	html += '  </tr>';	
    html += '</tbody>';
	
	$('#discount tfoot').before(html);
		
	$('#discount-row' + discount_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});
	
	discount_row++;
}
//--></script> 
    <?php echo $footer; ?>