<div id="main_borders">
  <div id="main_inner_borders">
    <h2><strong>
      <?=$title?>
      </strong></h2>
       <? if ($this-> session-> flashdata('message')): ?>
    <div class='warning'>
      <?=$this-> session-> flashdata('message');?>
    </div>
    <? endif; ?>

<? if ($this->cart->contents()) { ?>
<div id="cart_tbl">
      <table class="full" border="0">
        <tr>
          <th><?=$this->lang->line('cart_qty')?></th>
          <th><?=$this->lang->line('cart_desc')?></th>
          <th><?=$this->lang->line('cart_price')?></th>
          <th><?=$this->lang->line('cart_sub')?></th>
        </tr>
        <?		$order_details = $this->MFuncs->GetOrderDetails($orderdata['id']);
		if ($order_details) {
		$total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;
    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']); 
        $product_category = $this->MFuncs->getProductCat($order_det['product_id']); ?>
        <tr>
          <td><?=$order_det['quantity']?></td>
          <td><?=$product_details['name']?></td>
          <td><?=$order_det['price']?></td>
          <td>&euro;
            <?=$order_det['price']*$order_det['quantity']?></td>
          <? $total = $total + $order_det['price']*$order_det['quantity']; ?>
          <? $weight = $weight + ($product_details['weight'] * $order_det['quantity']); ?>
          <? if ($product_category['cat_id']!='7') { ?>
          <? $bot_num = $bot_num + $order_det['quantity']; 
		  } ?>
        </tr>
        <? endforeach ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('cart_total')?>
            </strong></td>
  		  <td>&euro;<?=number_format($total, 2, '.', '')?></td>
		</tr>
<? if ($orderdata['offer_code']!=0) { ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong><?=$this->lang->line('cart_discount')?></strong></td>
 <td>&euro; <?=number_format($total*$orderdata['offer_code'], 2, '.', '')?></td>
 </tr>
 <? $total = $total - ($total*$orderdata['offer_code']); ?>
 <tr>
 <td colspan='2'> </td>
 <td><strong><?=$this->lang->line('cart_total')?></strong></td>
 <td>&euro; <?=number_format($total, 2, '.', '')?></td>
 </tr>
 <? } ?>
		<? if (($select==true) &&($sel_loc==true)) { ?>
        <? if (($orderdata['same_address']=='No') && ($orderdata['country_id']!='1')) { ?>
       <? if ($orderdata['ship_method']=='courier') { ?>
       <? 	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($orderdata['same_address']=='No') {
			$c_id = $orderdata['country_id'];
			} else { 
			$c_id = $userdata['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); ?>
        <? }?>
        <? } elseif (($orderdata['same_address']=='Yes') && ($userdata['country_id']!='1')) { ?>
       <? if ($orderdata['ship_method']=='courier') { ?>
       <? 	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($orderdata['same_address']=='No') {
			$c_id = $orderdata['country_id'];
			} else { 
			$c_id = $userdata['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); ?>
        <? }?>
        <? } else { ?>
       <? if ($orderdata['ship_method']=='courier') {
		   $pack_total = (ceil($bot_num/2))*0.53;
           if ($orderdata['ship_dest']=='attica') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 3000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.57, 2, '.', '');
			   } else {
			   //$ship_total = 3.45 + $pack_total;
			   $ship_total = 3.57;
			   $weight = $weight - 3000;
			   $i = ceil($weight/1000);
			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
			   }
		   } elseif ($orderdata['ship_dest']=='greece') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 5.90; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 10.58;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 16.48;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   } elseif ($orderdata['ship_dest']=='islands') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 8.86; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 15.87;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 24.60;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   }
		   } elseif ($orderdata['ship_method']=='day_delivery') {
        			   $ship_total = number_format(14.76, 2, '.', '');
			}
			}
		 ?>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('ship_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total?></td>
        </tr>
        <tr>
          <td colspan="2"></td>
          <td><strong>
            <?=$this->lang->line('gen_total')?>
            </strong></td>
          <td>&euro;
            <?=$ship_total + $total?></td>
        </tr>
        <? } ?>
        <? //=$sum = number_format($total, 2, '.', '');?>
        <?	} ?>
      </table>
<br />
<em><?=$this->lang->line('vat_included_cart')?></em>
</div>      
<div id="orderForm">
        <? if (($orderdata['same_address']=='No') && ($orderdata['country_id']!='1') && ($sel_loc==false) && ($select==false)) { ?>
        <? if ($weight > 20000) { ?>
        <div class="note">(*) <?=$this->lang->line('cannot_send');?></div>
        <? } else { ?>
				  <? $attributes = array('class' => 'yform','AUTOCOMPLETE'=>'off'); ?>
                  <?=form_open('page/shipping_method_abroad',$attributes); ?>
                        <fieldset>
                            <legend><?=$this->lang->line('select_shipping_method')?></legend>
                        <div class="type-check">
                               <?=form_radio('select', 'courier', FALSE); ?>
                               <?=form_label($this->lang->line('courier_delivery_abroad'))?>
                        </div>
                        </fieldset>
                        <br />
                        <p align="justify"><?=$this->lang->line('delivery_methods_costs_abroad')?></p>
        <div class="note">(*) <?=$this->lang->line('change_settings');?></div>
        <div class="buttons">
		<?=anchor("complete_order_2/false", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>

<button type="submit" class="positive"> <?=$this->lang->line('continue')?> </button></div>
 <?=form_close();?>
 <? } ?>
        <? } elseif  (($orderdata['same_address']=='Yes') && ($userdata['country_id']!='1') && ($sel_loc==false) && ($select==false)) { ?>
        <? if ($weight > 20000) { ?>
        <div class="note">(*) <?=$this->lang->line('cannot_send');?></div>
        <? } else { ?>
				  <? $attributes = array('class' => 'yform','AUTOCOMPLETE'=>'off'); ?>
                  <?=form_open('page/shipping_method_abroad',$attributes); ?>
                        <fieldset>
                            <legend><?=$this->lang->line('select_shipping_method')?></legend>
                        <div class="type-check">
                               <?=form_radio('select', 'courier', FALSE); ?>
                               <?=form_label($this->lang->line('courier_delivery_abroad'))?>
                        </div>
                        </fieldset>
                        <br />
                        <p align="justify"><?=$this->lang->line('delivery_methods_costs_abroad')?></p>
        <div class="note">(*) <?=$this->lang->line('change_settings');?></div>
        <div class="buttons">
		<?=anchor("complete_order_2/false", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>

<button type="submit" class="positive"><?=$this->lang->line('continue')?> </button></div>
 <?=form_close();?>
 <? } ?>
		<? } else { ?>
<? if (($sel_loc==false) && ($select==false)) { ?>
  <? $attributes = array('class' => 'yform','AUTOCOMPLETE'=>'off'); ?>
  <?=form_open('page/shipping_method_new',$attributes); ?>
        <fieldset>
            <legend><?=$this->lang->line('select_shipping_method')?></legend>
        <div class="type-check">
               <?=form_radio('select', 'take_over', FALSE); ?>
               <?=form_label($this->lang->line('no_delivery'))?>
		</div>
        <div class="type-check">
               <?=form_radio('select', 'courier', FALSE); ?>
               <?=form_label($this->lang->line('courier_delivery'))?>
		</div>
        <div class="type-check">
               <?=form_radio('select', 'day_delivery', FALSE); ?>
               <?=form_label($this->lang->line('day_delivery'))?>
		</div>
		</fieldset>
        <br />
        <p align="justify"><?=$this->lang->line('delivery_methods_costs')?></p>
<? } elseif (($sel_loc==true) && ($select==false)) {  ?>
   <? $attributes = array('class' => 'yform','AUTOCOMPLETE'=>'off'); ?>
  	<?=form_open('page/shipping_destination',$attributes); ?>
       <fieldset>
         <legend><?=$this->lang->line('select_destination')?></legend>
         <? echo "<p><label for='destination'></label>";
			$options = array(''=>'Select one...', 'attica' => $this->lang->line('attika'), 'greece' => $this->lang->line('greece'), 'islands' => $this->lang->line('islands'));
			echo form_dropdown('destination',$options, '') ."</p>"; ?>
		</fieldset>
<? }?>
		<? if (($select==false) &&($sel_loc==false)) { ?>
        <div class="note">(*) <?=$this->lang->line('change_settings');?></div>
        <? } ?>
        <div class="buttons">
        <? if (($select==true) &&($sel_loc==true)) { ?>
		<?=anchor("complete_order_2_2", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>

		<?=anchor("complete_order_3", $this->lang->line('continue'),array('id'=>'continue','class'=>'positive'))?>
</div>
		<? } elseif (($select==false) &&($sel_loc==true)) { ?>        
		<?=anchor("complete_order_2_2", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>

<button type="submit" class="positive"> <?=$this->lang->line('continue')?> </button></div>
 <?=form_close();?>
		<? } elseif (($select==false) &&($sel_loc==false)) { ?>        
		<?=anchor("complete_order_2/false", $this->lang->line('btn_back'),array('id'=>'back_btn','class'=>'positive'))?>

<button type="submit" class="positive"> <?=$this->lang->line('continue')?> </button></div>
 <?=form_close();?>
		<? }?>
        <? } ?>
</div><div style="clear:both"></div>
</div>
<? } else { 
redirect('home','location');
} ?>

</div>